Skip to content

refactor: remove vestigial /api/refresh-tokens endpoint and dead token-fetch code - #435

Merged
tofarr merged 2 commits into
mainfrom
ohe-3294/remove-vestigial-refresh-tokens-endpoint
Sep 22, 2026
Merged

tofarr merged 2 commits into
mainfrom
ohe-3294/remove-vestigial-refresh-tokens-endpoint

Conversation

@tofarr

@tofarr tofarr commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

HUMAN:

  • A human has tested these changes.

AGENT:

This PR was created by an AI agent (OpenHands) on behalf of the user.


Why

The GET /api/refresh-tokens route and its only HTTP client (ProviderHandler._get_latest_provider_token) were dead code:

  • _get_latest_provider_token had zero callers anywhere in the codebase (verified via repo-wide grep).
  • No ProviderHandler constructor call ever passed the session_api_key or sid params that fed it.
  • For GitHub/GitLab/Bitbucket/Forgejo the route did not actually refresh anything — service.get_latest_token() just returned the already-loaded in-memory token.
  • No tests referenced the route, the method, or the TokenResponse model.

This was surfaced while reviewing OHE-3294 (Phase 1 of the OAuth auth refactor epic OHE-3293). The issue's deliverable "(/api/refresh-tokens updated to read from oauth_tokens)" was asking to rewire an endpoint that nothing actually calls. Removing the dead code first keeps the Phase 1 scope clean.

Summary

  • Removed the dead GET /api/refresh-tokens route and its create_provider_tokens_object helper (only caller was the dead route) from server/routes/auth.py.
  • Removed ProviderHandler._get_latest_provider_token plus the REFRESH_TOKEN_URL / session_api_key / sid constructor params and their now-unused imports (httpx, httpx_verify_option, TokenResponse) from openhands/app_server/integrations/provider.py.
  • Removed the TokenResponse model from openhands/app_server/integrations/service_types.py (only consumers were the two pieces above).

Net: 3 files changed, +2 / -97 lines, pure deletion.

Issue Number

OHE-3294 (and epic OHE-3293).

How to Test

  • uv run pytest tests/unit/integrations/test_provider_immutability.py tests/unit/integrations/test_provider_get_user.py tests/unit/server/routes/test_oauth_device.py -q
    • All pass (17 + 22 tests). No test referenced any removed symbol.
  • uv run pre-commit run --config ./dev_config/python/.pre-commit-config.yaml --files <changed files> -- ruff, ruff-format, mypy, and trailing-whitespace hooks all pass.
  • Verified import server.routes.auth, import openhands.app_server.integrations.provider, import openhands.app_server.integrations.service_types all succeed.
  • Confirmed the 2 pre-existing test_auth_offline_token.py errors (missing create_keycloak_user_info fixture when run without the DB conftest) exist on main too -- not introduced by this PR.

Could not run the full unit suite because it requires a Docker-backed Postgres testcontainer (unavailable in this environment); the CI run on GitHub will cover it.

Video/Screenshots

N/A -- pure backend dead-code removal, no UI.

Type

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

Notes

No behavior change for any existing user -- the removed endpoint was unreachable in practice (its only consumer was never called). The real in-process token refresh path (AuthTokenStore / the future OAuthTokenStore.get_valid_access_token) is unaffected and remains the Phase 1 deliverable in OHE-3294.


Enterprise server image for this PR:

ghcr.io/openhands/enterprise-server:sha-f86c582

…n-fetch code

The GET /api/refresh-tokens route and its only HTTP client
(ProviderHandler._get_latest_provider_token) were dead code:

- _get_latest_provider_token had zero callers anywhere in the codebase
  (verified via repo-wide grep).
- No ProviderHandler constructor call passed the session_api_key or sid
  params that fed it.
- For GitHub/GitLab/Bitbucket/Forgejo the route did not actually refresh
  anything — service.get_latest_token() just returned the in-memory token.
- No tests referenced the route, the method, or the TokenResponse model.

Removing this dead code simplifies the auth surface ahead of the OAuth
refactor (OHE-3293/OHE-3294), where the real in-process token refresh
path (OAuthTokenStore.get_valid_access_token) is the Phase 1 deliverable.

Removed:
- GET /api/refresh-tokens route (server/routes/auth.py)
- create_provider_tokens_object helper (only caller was the dead route)
- ProviderHandler._get_latest_provider_token + REFRESH_TOKEN_URL /
  session_api_key / sid constructor params and their now-unused imports
- TokenResponse model (only consumers were the two pieces above)

Co-authored-by: openhands <openhands@all-hands.dev>
@github-actions github-actions Bot added the type: refactor Code refactoring label Sep 17, 2026
@github-actions

github-actions Bot commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  openhands/app_server/integrations
  provider.py 185-186
  service_types.py
  server/routes
  auth.py
Project Total  

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

@tofarr tofarr left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review — refactor: remove vestigial /api/refresh-tokens endpoint and dead token-fetch code

I independently verified every claim in the PR description against origin/main:

Dead-code claims — confirmed:

  • _get_latest_provider_token had zero callers anywhere in the codebase (the only reference was its own definition in provider.py).
  • No ProviderHandler(...) constructor call anywhere passes session_api_key or sid — so even the route's own client never had the inputs it needed to actually hit the endpoint. The params were dead on arrival.
  • create_provider_tokens_object had exactly one caller: the dead refresh_tokens route itself.
  • TokenResponse was only consumed by the dead route and the dead _get_latest_provider_token method (DeviceTokenResponse in oauth_device.py is an unrelated, still-used model).
  • The route's service.get_latest_token() for GitHub/GitLab/Bitbucket/Forgejo just returns the in-memory self.token — no actual refresh, so the endpoint was a no-op in practice.

Import hygiene — clean. All now-unused imports were correctly removed and the remaining ones are still used:

  • server/routes/auth.py: dropped MappingProxyType, Annotated, Header, ProviderHandler/PROVIDER_TOKEN_TYPE/ProviderToken, TokenResponse, get_session_api_key/get_user_id. status is retained and still used (503/400/401/200/429 etc.). The get_user_id references that remain are await user_auth.get_user_id() (a method call), not the removed import — correct.
  • provider.py: dropped httpx, TokenResponse, httpx_verify_option. os, cast, quote, MappingProxyType, SecretStr, etc. are all still used elsewhere in the file.
  • service_types.py: BaseModel and SecretStr imports remain because other models (SuggestedTask, Branch, Repository, GitService.__init__, ...) still use them.

Risk: None for existing users — the removed endpoint was unreachable in practice (its only consumer was never called, and the params to call it were never passed). The real token-refresh path (AuthTokenStore / the future OAuthTokenStore.get_valid_access_token) is untouched.

CI: All checks green — Python Tests (3.12), Lint python, Lint frontend, builds, coverage (94.59% of new statements covered). Pure deletion (+2 / −97 across 3 files).

Template compliance: ✅ Why / Summary / Issue Number (OHE-3294, epic OHE-3293) / How to Test / Type (Refactor) all present and appropriate.

Verdict: Approve. This is a clean, well-scoped dead-code removal that keeps the OHE-3294 Phase 1 scope honest.

This review was performed by an AI agent (OpenHands) on behalf of the reviewer.

@hieptl hieptl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! 🙏

@tofarr
tofarr merged commit b50f3c5 into main Sep 22, 2026
16 checks passed
@tofarr
tofarr deleted the ohe-3294/remove-vestigial-refresh-tokens-endpoint branch September 22, 2026 10:48
@openhands-release-bot openhands-release-bot Bot added the released: 1.63.0 Shipped in 1.63.0 label Sep 22, 2026
@openhands-release-bot

Copy link
Copy Markdown
Contributor

🚀 Released in 1.63.0.

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

Labels

released: 1.63.0 Shipped in 1.63.0 type: refactor Code refactoring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants