fix(codex): persist terminal pool reauth causes and surface stored verdicts - #5222
Conversation
…e stored auth causes
…es outrank bare marks A memory-only reauth mark carries no cause of its own, so poolAccountDto no longer names refresh_failed on its behalf: projectCodexAccountHealth then falls back to the persisted verdict, letting a stored http_status:401/403 surface as unauthorized/forbidden while the mark is still present. Terminal refresh failures found during quota probes (revoked/expired grants) are now persisted through markCodexAccountValidationFailed with terminal: true, the same verdict the token guardian writes - the in-memory mark dies with the process, and only the stored verdict keeps a cached listing from calling the dead grant healthy after a restart. Applied in both recoverPoolQuotaFrom401 and fetchFreshPoolAccountQuota. Tests: the deferred-validation matrix now expects the stored http status cause whether or not the in-memory mark survives; the pool-reauth-cause helper gains persisted-verdict and restart-simulation assertions for the dead-grant path.
|
Note Currently processing new changes in this PR. This may take a few minutes, please wait... ⚙️ Run configurationConfiguration used: Repository: lidge-jun/opencodex/.coderabbit.yaml Review profile: ASSERTIVE Plan: Advanced Run ID: 📒 Files selected for processing (6)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
⏳ DRAFT
What to do
Review readiness checklist
0/4 boxes ticked. Automatic draft conversion failed (token cannot change draft status). Please convert this pull request to a draft manually. The required |
리뷰 · 우선순위 30 / 80이 PR은 #5191 리뷰에서 고치라고 한 두 가지를 넣습니다. #5191은 스쿼시 #5199로 토큰 서버가 5xx를 주면 이제 재로그인을 요구하지 않습니다. 갱신 토큰이 거절되거나 만료된 경우만 src/codex/account-usability.ts:104 - 요청에 쓸 계정을 고를 때는 메모리 표시와 검증 대기만 봅니다. 파일의 메인테이너의 판단이 필요한 지점 고르기도 목록과 같이 막을지 정해 주세요. 토큰 가디언이 적어 둔 판정도 고르기는 원래 안 봅니다. 이 PR이 사용량 조회에서도 같은 판정을 남기면, 목록과 실제 선택이 어긋나는 계정이 늘어납니다.
너의 추천
이 댓글은 grok-bot이 작성했습니다 |
Motivation
Follow-up to #5191, whose change was carried into
devby the #5199 squash (09698b9b3a). The squash was taken from that PR's original commit, so the fixes made for its first review — and the further scope its second review recommended — never landed ondev:fetchFreshPoolAccountQuotastill reportsneedsReauth+refresh_failedfor everyTokenRefreshError, so a transient token-endpoint 5xx quarantines a healthy account ([Bug]: a time-valid stored Codex pool token is quarantined on the first Responses 401 #2887), while a genuinely dead grant is never marked and flips back to healthy on the next cached listing.projectCodexAccountHealthflattens a storedhttp_status:401/http_status:403verification failure torefresh_failed;unauthorized/forbiddennever surface.refresh_failed, which outranks the stored verdict inside the projection until the mark is cleared.Description
fetchFreshPoolAccountQuotaemitsrefresh_failedonly for terminal refresh failures viaisTerminalCodexPoolRefreshFailure(revoked/expired grant or missing credential); transient/unknownerrors returnneedsReauth: falselike the 401-recovery path, and terminal failures callmarkAccountNeedsReauthso the cause survives quota caching.projectCodexAccountHealthsurfaces a stored verification failure's own cause when the caller gives no reason:http_status:401->unauthorized,http_status:403->forbidden.poolAccountDtono longer names a reason on behalf of a memory-only mark, so a stored 401/403 verdict surfaces while the mark is still present rather than only after it is cleared.revoked/expired) observed inrecoverPoolQuotaFrom401andfetchFreshPoolAccountQuotaare persisted viamarkCodexAccountValidationFailedwithterminal: true— the same verdict the token guardian writes — so a restart cannot flip a dead grant back to healthy.health.reason, the dead-grant mark surviving a cached listing, the persistedrefresh_revokedterminal verdict, a restart-simulated listing, and a transient 5xx producing no reauth;projectCodexAccountHealthgains storedhttp_status:401/403cases.Tests
bun test tests/codex-integration/codex-auth-api.test.ts— 343 pass, 0 failbun test tests/oauth/oauth-health.test.ts— 24 pass, 0 failbun x tsc --noEmit— cleanReview readiness checklist
This PR stays in draft until every box below is ticked. Tick all four boxes once the requirements are met:
All CI tests are green on my local testing.
I pushed my PR to the latest dev commit.
I resolved all correct Codex and CodeRabbit findings.
My PR is ready for review.