Skip to content

fix(secrets): return 404 when the user has no token for the requested provider - #1563

Draft
dylan-openhands wants to merge 1 commit into
mainfrom
dj/secrets-missing-provider-404
Draft

dylan-openhands wants to merge 1 commit into
mainfrom
dj/secrets-missing-provider-404

Conversation

@dylan-openhands

@dylan-openhands dylan-openhands commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

HUMAN:

  • A human has tested these changes.

AGENT:


Why

When a sandbox asks GET /api/v1/webhooks/secrets for a provider token the user never connected, get_latest_token hits self.provider_tokens[provider] in ProviderHandler.get_service and raises KeyError, so the endpoint returns 500 instead of its existing 404 No such provider. In prod on 1.99.0 that's ~1,100 KeyError: ProviderType.BITBUCKET 500s in 5 hours, from agent-servers retrying the lookup. They keep the SaaS 5xx monitor in alert.

Summary

  • AuthUserContext.get_latest_token returns None when the provider type has no token, which matches its str | None signature. get_secret then returns 404.

Issue Number

N/A

How to Test

pytest tests/unit/test_auth_user_context.py -k unconnected: fails with the prod KeyError before the change and passes after it.

Video/Screenshots

N/A

Type

  • Bug fix
  • Feature
  • Refactor
  • Breaking change
  • Docs / chore

Notes

The guard goes in get_latest_token, not get_service. Every other caller already treats None as "no token", and the org secret path already checks provider_type in provider_tokens before calling it.


Enterprise server image for this PR:

ghcr.io/openhands/enterprise-server:sha-568ccb3

@github-actions github-actions Bot added the type: fix A bug fix label Nov 25, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  openhands/app_server/user
  auth_user_context.py
Project Total  

This report was generated by python-coverage-comment-action

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: fix A bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant