fix(api): map upstream GitHub 401s to 400/502 UPSTREAM_AUTH_FAILED (#734) - #808
Conversation
) A bad or revoked GitHub PAT surfaced as this API's own 401, which the web UI's axios interceptor treats as session expiry (clearToken + redirect to /login) — entering an invalid PAT logged the user out of CodeFRAME itself. - New ErrorCodes.UPSTREAM_AUTH_FAILED - connect: InvalidTokenError -> 400 (bad client-supplied PAT) - issues/import/_map_github_error: InvalidTokenError -> 502 - pr_v2: _github_error_http() helper remaps GitHub 401 -> 502 at all 8 verbatim status-propagation sites; other statuses unchanged
|
Warning Review limit reachedYou’ve reached a temporary PR review limit under our Fair Usage Limits Policy. Next review available in: 27 minutes Your organization has reached its usage spending cap. Adjust your spending cap in the billing tab. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (7)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
Code Review: fix(api) upstream GitHub 401s to 400/502 UPSTREAM_AUTH_FAILEDOverviewWell-targeted, semantically clean fix. The upstream 401 leak was a real UX hazard and the fix is confined to exactly the right layers. The 400-vs-502 split for Strengths
One Test Coverage GapThe parametrized suite in The PR says "all 6 previously-uncovered pr_v2 endpoints" -- if ("GET", "/api/v2/pr/history", None),This is the only functional gap I found. Minor Notes (non-blocking)
SummaryThe fix is correct, the helper extraction is clean, and the test suite is solid except for the missing Verdict: Approve pending the |
|
Follow-up to my prior review: the diff is unchanged, so my prior feedback still stands. Only outstanding item: Everything else — 400/502 semantic split, DRY helper, test naming, |
Addresses claude-review feedback on PR #808: get_pr_history also routes through _github_error_http and now has the same 401->502 regression test.
|
Correction to my prior two reviews. Both previous comments flagged ("GET", "/api/v2/pr/history", None),All 8 The PR is clean. The 400/502 semantic split, the DRY helper, the |
Final Triage Summary (PR #808)Cutoff: 2026-07-04T17:03:58Z (last push before triage) → updated 17:11:23Z after fix push New findings since PR open: 3 (all from claude-review bot) Fixed
Skipped (with justification)
Notes
|
Summary
Implements #734: [P1.7] Don't return upstream GitHub 401s as this API's 401 (forces web-UI logout)
A bad or revoked GitHub PAT previously surfaced as this API's own 401. The web UI's axios interceptor treats any 401 as CodeFRAME session expiry (
clearToken()+ redirect to/login), so entering an invalid PAT — or having a stored one revoked — logged the user out of CodeFRAME itself.ErrorCodes.UPSTREAM_AUTH_FAILED(codeframe/ui/response_models.py), documented as never carried on a 401.github_integrations_v2.py:connectmapsInvalidTokenError→ 400UPSTREAM_AUTH_FAILED(the PAT is bad client input in this request);get_issuesand_map_github_error(import path) map it → 502UPSTREAM_AUTH_FAILED(the stored credential died upstream).pr_v2.py: new shared_github_error_http()helper used at all 8 formerstatus_code=e.status_codesites — a GitHub 401 is rewritten to 502UPSTREAM_AUTH_FAILED; every other upstream status still propagates verbatim (404/405 special cases untouched).Acceptance Criteria
UPSTREAM_AUTH_FAILED), never raw 401 on authenticated routes.Test Plan
tests/ui/test_pr_v2_upstream_auth.py)tests/ui/suite passing (517 tests) + CI subset (tests/ --ignore=tests/e2e -m "not lifecycle")ruff checkcleancodeframe/ui/codex review— "consistently remap upstream GitHub 401/InvalidTokenError cases to non-401 responses… no correctness or security regression"Known Limitations / Intentionally Deferred
cfCLI (pr_commands.py) still prints raw GitHub status codes to the console — the CLI has no logout-on-401 behavior, so this is cosmetic and out of scope.InvalidTokenErroris intentional: 400 when the bad PAT arrives in the request body (connect), 502 when a previously-stored PAT is rejected upstream.Implementation Notes
Plan was self-authored (no plan comment on the issue); no deviations.
Closes #734