Skip to content

test(server): keep the live-cancel pool fixture quota prime off the network - #8828

Merged
lidge-jun merged 1 commit into
devfrom
fix/live-cancel-quota-prime-settle
Nov 16, 2026
Merged

lidge-jun merged 1 commit into
devfrom
fix/live-cancel-quota-prime-settle

Conversation

@lidge-jun

@lidge-jun lidge-jun commented Nov 16, 2026 •

Copy link
Copy Markdown
Owner

Summary

tests/server/server-live-cancel.test.ts failed its file-level final cleanup on dev batch run 43854382432 (job "macos 3/4", head da021e3) with background work never settled before final cleanup: codex-pool-quota-prime-startup, codex-pool-quota-prime:startup, codex-pool-quota-prime-import:pre-route. The defect is in the test, which made a real network call. The product is working as designed.

The case "a client that cancels during credential resolution releases admission before any dial" seeds a pool account with an expired access token and a fixture refresh token. It spies on accountStore.getValidCodexToken to hold the live request's credential resolution. The startup prime (src/server/index.ts) and the lazy pre-route prime (src/codex/auth-context.ts) share one single-flight pass in primeCodexPoolQuotas, which resolves tokens through getValidPoolTokenForPrime. That variable captures the original getValidCodexToken when the module loads, so the spy never reached it, and the prime POSTed the fixture refresh token to the real ChatGPT token endpoint. On a fast network the endpoint returns 401 almost at once, which explains the 15 earlier green batches. On a stalled runner network the only bound is the refresh flight's 30 s CODEX_REFRESH_FLIGHT_CEILING_MS, so all three tracked labels stay pending past the 15 s cleanup contract.

server.stop() doesn't own this work, and this PR deliberately leaves that unchanged. The prime is process-scoped and bounded (30 s refresh ceiling, 8 s WHAM timeout). The refresh flight is intentionally not cancellable by any single owner, because aborting a refresh after upstream rotates the refresh token would lose the rotated grant (see the comment above the flight in src/codex/account-store.ts).

The fix routes the prime through the existing setCodexPoolQuotaTokenResolverForTests seam with a resolver that refuses before any dial. The test then settles background work in its own finally before restoring the seam and asserts { settled: true, pending: [] }. The 15 s preload cleanup contract and its check are unchanged.

Verification

I reproduced the failure deterministically by stalling the network. A local TCP listener on 127.0.0.1:47999 accepts connections and never responds, and the runs set HTTPS_PROXY/HTTP_PROXY to it. Every run used /usr/bin/lockf -k /tmp/ocx-test.lock bun test --timeout 20000 tests/server/server-live-cancel.test.ts.

  • Before the fix (origin/dev da021e3), with the stall: the case logs background work outlived its case: codex-pool-quota-prime-startup, codex-pool-quota-prime:startup, codex-pool-quota-prime-import:pre-route, then (fail) (unnamed) [15003.28ms] with the same never settled before final cleanup error as CI. Without the stall, the original file logs [codex] pool refresh …: transient status=401, which shows the prime reaching the real token endpoint.
  • After the fix, with the stall: 2 pass, 0 fail, no outlived warning. A 10-run repeat loop with the stall gave 10 pass, 0 fail, and none of the runs logged an outlived warning.
  • After the fix, on the normal network: a 5-run loop, all 2 pass / 0 fail.
  • bun run typecheck: no type errors.
  • bun test tests/test-layout.test.ts, tests/test-layout-tooling.test.ts, tests/ci-workflows/file-size-ratchet.test.ts: all pass.

NOT RUN: bun run test (full suite; the host is under heavy load, and the task limited this work to focused single-file runs), bun run privacy:scan, the cross-platform lane=all dispatch (a batch check on dev, not per-PR), and macOS/Windows CI for this head.

Checklist

  • Scope stays focused and avoids unrelated cleanup.
  • Docs or release notes were updated when needed. (Test-only change; no docs affected.)
  • Security-sensitive changes were reviewed for secrets, auth, and unsafe defaults. (The fixture no longer sends its refresh token over the network.)

Summary by CodeRabbit

  • Tests
    • Expanded coverage for credential-resolution cancellation, verifying that canceled requests release admission before connecting and that background work settles cleanly. This improves confidence in cancellation behavior and test cleanup without changing user-facing functionality.

… network

The credential-resolution cancel case seeds an expired pool credential and spies on
getValidCodexToken, but the startup and pre-route quota primes use a resolver captured
at module load, so they POSTed the fixture refresh token to the real token endpoint.
On a stalled network that refresh is bounded only by its 30 s ceiling and outlived the
file's 15 s final cleanup (dev batch run 43854382432, macos 3/4).

Route the prime through setCodexPoolQuotaTokenResolverForTests so it refuses before
any dial, and settle background work before restoring the seam.
@lidge-jun
lidge-jun requested a review from Ingwannu as a code owner November 16, 2026 11:42
@lidge-jun lidge-jun added the ci:full Run the four full Ubuntu test shards on this pull request label Nov 16, 2026
@github-actions

Copy link
Copy Markdown
Contributor

✅ Deterministic PR hygiene checks passed.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-16T11:43:51.849614Z c60342c PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions github-actions Bot added the chore Maintenance, CI, tests, refactors, or build changes (not a user-facing bug or feature). label Nov 16, 2026
@coderabbitai

coderabbitai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The credential-resolution cancellation test installs a rejecting quota-prime resolver. Cleanup waits for background work to settle before restoring the resolver and token spy, then checks that no tasks remain pending.

Changes: Credential cancellation test

Layer / File(s) Summary
Resolver control and cleanup
tests/server/server-live-cancel.test.ts
The test rejects quota-prime resolution and waits up to five seconds for background work to settle before restoring the resolver and token spy. It asserts that settlement succeeded and no tasks remain pending.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Other

Merge Risk: Minimal · up to c6034

This change only adjusts a test so its quota prime no longer makes a real network request, which stops stalled networks from delaying cleanup. It has no production impact and is low risk to merge.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the test file scope (server), the test change (live-cancel pool fixture), and the mechanism (quota prime kept off the network). The raw summary and PR objectives both describe routing …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the test file scope (server), the test change (live-cancel pool fixture), and the mechanism (quota prime kept off the network). The raw summary and PR objectives both describe routing the quota prime through the test resolver seam so it refuses before dialing, which matches the title. The title is specific and accurate, though it is slightly long at 75 characters.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between da021e3 and c60342c.

Files selected for processing: 1

  • tests/server/server-live-cancel.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@lidge-jun

Copy link
Copy Markdown
Owner Author

Maintainer integration of #8828 at c60342c (owner accepted this as the fix, 2026-11-16).

This repairs the macos 3/4 failure in dev batch run 43854382432 (da021e3): server-live-cancel.test.ts final cleanup, where codex-pool-quota-prime-startup, codex-pool-quota-prime:startup and codex-pool-quota-prime-import:pre-route never settled within 15 s.

  • Cause (traced and reproduced): the case stubs accountStore.getValidCodexToken, but the startup and pre-route quota primes resolve tokens through getValidPoolTokenForPrime, which is bound at module load. They therefore POSTed the fixture refresh token to the real token endpoint, limited only by the 30 s refresh ceiling. On a normal network that is a near-instant 401. On a stalled runner network it outlives the 15 s cleanup. The product is unchanged: the prime is bounded and its refresh is deliberately not cancellable, so a rotated token is never lost.
  • Fix (test only, +14 lines): the case points the prime at a stub through the existing seam setCodexPoolQuotaTokenResolverForTests, so it refuses before any dial. It then settles background work (up to 5 s) before restoring the seam and asserts that nothing is pending. The 15 s cleanup contract is unchanged.
  • Evidence: with HTTPS_PROXY pointed at a local listener that never answers, unmodified dev reproduces CI's (unnamed) failure after 15,003 ms with the same three labels. With the fix it passes 10/10 under the stall and 5/5 on the normal network. Typecheck and the layout and size guards pass.
  • CI on this exact head: all 31 checks passed, including test 1–5/5 (ci:full) and enforce-target. assert-mergeable-review: OK.

Follow-up (owner decision): no preload network block in this round. A read-only investigation will list every test that reaches a real provider host, and an issue will follow.

@lidge-jun
lidge-jun merged commit a436278 into dev Nov 16, 2026
37 of 39 checks passed
@lidge-jun
lidge-jun deleted the fix/live-cancel-quota-prime-settle branch November 16, 2026 11:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chore Maintenance, CI, tests, refactors, or build changes (not a user-facing bug or feature). ci:full Run the four full Ubuntu test shards on this pull request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant