Repository navigation
refactor: remove vestigial /api/refresh-tokens endpoint and dead token-fetch code - #435
Conversation
…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>
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||||||||||||||||||||
tofarr
left a comment
There was a problem hiding this comment.
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_tokenhad zero callers anywhere in the codebase (the only reference was its own definition inprovider.py).- No
ProviderHandler(...)constructor call anywhere passessession_api_keyorsid— 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_objecthad exactly one caller: the deadrefresh_tokensroute itself.TokenResponsewas only consumed by the dead route and the dead_get_latest_provider_tokenmethod (DeviceTokenResponseinoauth_device.pyis an unrelated, still-used model).- The route's
service.get_latest_token()for GitHub/GitLab/Bitbucket/Forgejo just returns the in-memoryself.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: droppedMappingProxyType,Annotated,Header,ProviderHandler/PROVIDER_TOKEN_TYPE/ProviderToken,TokenResponse,get_session_api_key/get_user_id.statusis retained and still used (503/400/401/200/429 etc.). Theget_user_idreferences that remain areawait user_auth.get_user_id()(a method call), not the removed import — correct.provider.py: droppedhttpx,TokenResponse,httpx_verify_option.os,cast,quote,MappingProxyType,SecretStr, etc. are all still used elsewhere in the file.service_types.py:BaseModelandSecretStrimports 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.
|
🚀 Released in 1.63.0. |
HUMAN:
AGENT:
Why
The
GET /api/refresh-tokensroute and its only HTTP client (ProviderHandler._get_latest_provider_token) were dead code:_get_latest_provider_tokenhad zero callers anywhere in the codebase (verified via repo-wide grep).ProviderHandlerconstructor call ever passed thesession_api_keyorsidparams that fed it.service.get_latest_token()just returned the already-loaded in-memory token.TokenResponsemodel.This was surfaced while reviewing OHE-3294 (Phase 1 of the OAuth auth refactor epic OHE-3293). The issue's deliverable "(
/api/refresh-tokensupdated to read fromoauth_tokens)" was asking to rewire an endpoint that nothing actually calls. Removing the dead code first keeps the Phase 1 scope clean.Summary
GET /api/refresh-tokensroute and itscreate_provider_tokens_objecthelper (only caller was the dead route) fromserver/routes/auth.py.ProviderHandler._get_latest_provider_tokenplus theREFRESH_TOKEN_URL/session_api_key/sidconstructor params and their now-unused imports (httpx,httpx_verify_option,TokenResponse) fromopenhands/app_server/integrations/provider.py.TokenResponsemodel fromopenhands/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 -quv 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.import server.routes.auth,import openhands.app_server.integrations.provider,import openhands.app_server.integrations.service_typesall succeed.test_auth_offline_token.pyerrors (missingcreate_keycloak_user_infofixture when run without the DB conftest) exist onmaintoo -- 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
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 futureOAuthTokenStore.get_valid_access_token) is unaffected and remains the Phase 1 deliverable in OHE-3294.Enterprise server image for this PR: