You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(test): Codex usage-limit tests read the real clock — main goes red 2026-10-09 → 10-16 when the fixture's reset enters the 7-day horizon #1248
Tier: mechanical Urgency: main's test job goes red on 2026-10-09 ~01:04 local and stays red until 2026-10-16 ~01:04. Land this before then.
Problem.classifyCodexTurnFailure (src/lib/workflow/drivers/codex.ts:350) takes now: number = Date.now(). It classifies a usage-limit message as a RateLimitError when its reset time falls within CODEX_WAIT_HORIZON_MS (7 days), and as a BillingError otherwise. The fixture src/lib/workflow/drivers/__fixtures__/codex-turn-failed-usage-limit.jsonl carries the verbatim #1087 message "…try again at Oct 16th, 2026 1:04 AM." Two tests expect BillingError for it and read the real clock through evaluateCodexRun:
src/lib/workflow/batch-executor.test.ts (~:3040): "does not start a quality-loop iteration after the real Codex-mapped BillingError"
Evidence.classifyCodexTurnFailure(msg, Date.parse(d)) with the fixture message:
now
result
2026-09-30T20:00
BillingError
2026-10-08T23:00
BillingError
2026-10-09T02:00
RateLimitError
2026-10-15T12:00
RateLimitError
2026-10-16T02:00
BillingError
The #1087 PR's QA flagged this: "will fail for a seven-day window in October". It was never filed; it surfaced again in a decision-trail audit on 2026-09-30 (tracker #1236).
AC
AC-1: Both tests are independent of the wall clock. Either they pin time (for example vi.useFakeTimers() + vi.setSystemTime to a date well before the fixture's reset), or evaluateCodexRun/codexOutcome accepts an injected now that the tests set. Evidence: npx vitest run src/lib/workflow/drivers/__tests__/driver-conformance.test.ts src/lib/workflow/batch-executor.test.ts
AC-2: A test runs the fixture with now set inside the 7-day window and asserts RateLimitError, so the horizon branch is covered on purpose rather than by the calendar. Evidence: npx vitest run src/lib/workflow/drivers/codex.test.ts
AC-3: Mutation check: drop the time pin from AC-1's tests and set the system time to 2026-10-10. The BillingError cases then fail, which proves the pin is what keeps them stable. Record it with a Mutation-verified: marker. Evidence: npx vitest run src/lib/workflow/drivers/__tests__/driver-conformance.test.ts
Runner context (re-checked against main @ 5e8f0aa)
Line refs (current):
src/lib/workflow/drivers/codex.ts:350-353: classifyCodexTurnFailure(message, now = Date.now()). Horizon check at :365-366.
src/lib/workflow/drivers/codex.ts:388: evaluateCodexRun(parsed, outcome). At :419 it calls classifyCodexTurnFailure(parsed.turnFailure) with no now, so the real clock leaks in here. Production caller: :716.
src/lib/workflow/drivers/__tests__/driver-conformance.test.ts:210-219 (codexOutcome) and the case at :620-628.
src/lib/workflow/batch-executor.test.ts:3036-3056 (#1087 Codex usage-limit turn failure under -Q).
src/lib/workflow/drivers/codex.test.ts:665+. This file already pins NOW = 2026-10-01 for the direct classifyCodexTurnFailure tests, so AC-2's new case goes there.
Whole-repo grep: classifyCodexTurnFailure has one real-clock reader (evaluateCodexRun:419) and two tests that reach it through evaluateCodexRun. One producer, so a local fix is the right owner.
Either shape from AC-1 is acceptable. If you add an optional now to CodexRunOutcome and thread it through :419, keep production behaviour unchanged (default Date.now()).
Standard block:
No full npm test in exec or in QA. This applies to the qa phase too. Run only the three test files named in the ACs, plus grep -rlE 'evaluateCodexRun|classifyCodexTurnFailure|codex-turn-failed-usage-limit' --include='*.test.ts' src __tests__ scripts | xargs npx vitest run.
Commit WIP early, and always before a mutation (AC-3). Use a type-preserving mutation, since the global setup builds.
The mutation marker's failedTest must start with the test file path: src/lib/workflow/drivers/__tests__/driver-conformance.test.ts > … > ….
PR body: Closes #1248. Use only Refs for any tracker.
Any settings read must be JSONC-safe (not expected here).
⚠️AC-1: "for example" phrasing reads as open-ended, but the AC itself is an exhaustive either/or (pin the clock vs. inject now) — not flagged further; the wording is fine as written.
✅ AC-2, AC-3: Clear and testable.
Scope Assessment
Non-Goals:⚠️ Non-Goals section not found in the issue body.
Metric
Value
Status
Feature count
1
✅
AC items
3
✅
Directory spread
2
✅
Verdict:⚠️ SCOPE_WARNING — driven solely by the missing Non-Goals heading; every quantitative metric is green. Given the main-goes-red deadline (2026-10-09), not worth blocking on; flagged for completeness only.
Acceptance Criteria
AC-1: Both tests are independent of the wall clock
Verification: Unit Test Scenario: Given driver-conformance.test.ts's codexOutcome() helper and batch-executor.test.ts's inline evaluateCodexRun() call both currently omit now → When the real clock crosses 2026-10-09 ~01:04 → Then both suites currently flip from BillingError to RateLimitError and fail; after the fix, both pin an explicit now so the result is clock-independent. Assumptions: The owner's runner-context comment pre-approved threading an optional now through CodexRunOutcome rather than vi.useFakeTimers() — see Design Review Q2.
AC-2: Horizon branch covered on purpose, not by the calendar
Verification: Unit Test Scenario: Given the real codex-turn-failed-usage-limit.jsonl fixture parsed through CodexStreamParser → When evaluateCodexRun is called with now set inside the 7-day window (e.g. 2026-10-10T00:00, since the fixture's reset is 2026-10-16T01:04) → Then structuredError is a RateLimitError with metadata.resetsAt === Date(2026,9,16,1,4).getTime(). Assumptions: None — this exercises the real parse path, not just classifyCodexTurnFailure in isolation (codex.test.ts already has synthetic-message horizon tests via its at() helper; AC-2 asks specifically for "the fixture").
AC-3: Mutation check proves the pin is load-bearing
Verification: Unit Test Scenario: Given AC-1's pinned now values → When the pin is removed/overridden and the system clock is set to 2026-10-10 → Then the BillingError assertions in driver-conformance.test.ts:620 (and the batch-executor.test.ts case) fail → Restore the pin, record Mutation-verified: per the constitution's §6i marker format. Assumptions:failedTest in the marker must start with the test file path (src/lib/workflow/drivers/__tests__/driver-conformance.test.ts > ...), per the owner's comment and project_mutation_marker_failedtest_file_prefix.
Implementation Plan
Phase 1: Thread an optional now through the production path
Add now?: number to the CodexRunOutcome interface (src/lib/workflow/drivers/codex.ts:281-288). Confirmed additive/safe — grepped all 8 call sites across codex.ts, codex.test.ts, driver-conformance.test.ts, and batch-executor.test.ts; none break from an optional field.
In evaluateCodexRun's turnFailure branch (:416-420), change classifyCodexTurnFailure(parsed.turnFailure) → classifyCodexTurnFailure(parsed.turnFailure, outcome.now). The production caller (:716) never sets now, so outcome.now is undefined there and classifyCodexTurnFailure's own default parameter (now: number = Date.now()) keeps production behavior unchanged.
Phase 2: Pin the two wall-clock-dependent tests (AC-1)
driver-conformance.test.ts: give the codexOutcome() helper (:209-219) a pinned default, e.g. const PINNED_NOW = new Date(2026, 8, 1).getTime(); passed as now in the returned evaluateCodexRun(..., { ..., now: PINNED_NOW }). The existing call codexOutcome("codex-turn-failed-usage-limit.jsonl") at :623 needs no edit — it inherits the pin.
batch-executor.test.ts: add the same pinned now to the inline evaluateCodexRun(parser.end(), {...}) call (~:3049).
Phase 3: Cover the horizon branch on purpose (AC-2)
codex.test.ts: add a test — in or alongside the existing "1087: classifyCodexTurnFailure" describe block — that loads the real fixture (readFileSync + CodexStreamParser, same pattern already used in the other two files) and calls evaluateCodexRun with now inside the window (2026-10-10). Assert RateLimitError with the exact resetsAt epoch.
Phase 4: Mutation verification (AC-3)
Temporarily neutralize the Phase 2 pin (e.g. override PINNED_NOW to 2026-10-10), run npx vitest run src/lib/workflow/drivers/__tests__/driver-conformance.test.ts, confirm the BillingError case at :620 fails, restore the pin, and record the result in the PR body with the Mutation-verified: / SEQUANT_MUTATION marker.
Commands to run (per the owner's comment — no full npm test, in exec or qa):
Where does this logic belong?CodexRunOutcome/evaluateCodexRun in src/lib/workflow/drivers/codex.ts — the same module that already owns classifyCodexTurnFailure's explicit now parameter. Test-side pins live in each test file's own helper/call site.
What's the simplest correct approach? Thread an optional now through CodexRunOutcome (owner-blessed). Rejected:vi.useFakeTimers() + vi.setSystemTime() — both driver-conformance.test.ts and batch-executor.test.ts are large, multi-suite files; a global fake-timer scope risks leaking into unrelated tests in the same file and needs careful afterEach restore. An explicit, optional constructor field is localized, auditable in a diff, and mirrors a pattern the codebase already uses one layer down.
What existing pattern does this follow?codex.test.ts's own NOW constant + classifyCodexTurnFailure(msg, NOW) calls — this just extends the same explicit-clock-injection pattern one layer up through evaluateCodexRun.
What would a senior reviewer challenge? "Why grow the production-facing CodexRunOutcome interface for a test concern?" — because both the real driver (:716) and tests already construct this object inline by hand; one optional field keeps a single code path instead of a parallel test-only overload, and defaults to real-clock behavior everywhere it isn't set.
No ADR required — this is a localized test-determinism fix (mechanical tier per the issue itself), not a cross-cutting architectural decision.
Feature Quality Planning
All standard checks pass. Notable items:
Pre-existing worktree feature/1248-fix-test-codex-usage-limit-tests-read-the-real-clo exists but is clean (identical to origin/main, no commits, no uncommitted changes) — no conflict, safe to reuse.
CodexRunOutcome field addition verified additive via whole-repo grep (8 call sites, all optional-field-safe).
Open Questions
Should the pinned now constant be shared across the three touched test files (a test-utils export) instead of one literal per file? — Recommendation: keep them independent per-file literals; CODEX_WAIT_HORIZON_MS has exactly one prior commit in its history (git log -S), so cross-file coupling isn't worth it for a one-off determinism fix. Impact if wrong: a future horizon-constant change needs 2 edits instead of 1 — low cost.
Recommended Workflow
Phases: exec → qa Quality Loop: enabled Reasoning:testgen is mechanically indicated (all 3 ACs carry declared Unit Test evidence, which outranks the bug-label short-circuit per #938) but is overridden here: the AC evidence is editing the existing test files directly (pinning a clock value, adding one assertion) — there's no separate production code path to stub ahead of the tests, so a generated stub would just collide with the hand-written edits above. Quality loop stays enabled per the mechanical SCOPE_WARNING verdict, even though the only driver is the missing Non-Goals heading — cheap safety net given the fixed landing deadline.
Label Review
Current: bug Recommended: bug, planned Reason: Plan reviewed and accepted. Quality Loop: Will auto-enable (SCOPE_WARNING, missing Non-Goals heading only).
AC-1 (Unit Test): Pin now through CodexRunOutcome in both driver-conformance.test.ts's codexOutcome() helper and batch-executor.test.ts's inline evaluateCodexRun() call.
AC-2 (Unit Test): New codex.test.ts case — real fixture parsed, now inside the 7-day window, asserts RateLimitError.
AC-3 (Unit Test): Mutation check — pull the pin, set clock to 2026-10-10, confirm BillingError cases fail, restore, record Mutation-verified: marker.
Plan
Add optional now?: number to CodexRunOutcome; thread it into classifyCodexTurnFailure at codex.ts:419 (production caller at :716 unaffected — stays on Date.now()).
Pin now in both AC-1 test helpers to a fixed pre-horizon date (e.g. 2026-09-01).
Add AC-2's horizon-branch test in codex.test.ts using the real .jsonl fixture, now = 2026-10-10.
Run the mutation check from AC-3, record the marker.
Key decision: Explicit now-threading over vi.useFakeTimers() — matches the owner's comment, avoids fake-timer leakage risk in two large shared test files.
Open question: Keep the pinned-clock constants per-file rather than centralizing — fine given CODEX_WAIT_HORIZON_MS barely changes.
Workflow: exec → qa (quality loop enabled; testgen mechanically indicated but overridden — the AC evidence is the test edits, nothing else to stub).
Activity
admarble commentedon Oct 1, 2026
Runner context (re-checked against main @ 5e8f0aa)
Line refs (current):
src/lib/workflow/drivers/codex.ts:350-353:classifyCodexTurnFailure(message, now = Date.now()). Horizon check at:365-366.src/lib/workflow/drivers/codex.ts:388:evaluateCodexRun(parsed, outcome). At:419it callsclassifyCodexTurnFailure(parsed.turnFailure)with nonow, so the real clock leaks in here. Production caller::716.src/lib/workflow/drivers/__tests__/driver-conformance.test.ts:210-219(codexOutcome) and the case at:620-628.src/lib/workflow/batch-executor.test.ts:3036-3056(#1087 Codex usage-limit turn failure under -Q).src/lib/workflow/drivers/codex.test.ts:665+. This file already pinsNOW = 2026-10-01for the directclassifyCodexTurnFailuretests, so AC-2's new case goes there.Prior fixes / producers (checked with commands):
git log -S CODEX_WAIT_HORIZON_MS: one commit (5917cf8, bug(codex): usage-limit turn failures classified 'unknown' — quality loop re-runs into the same quota, --auto-wait can't engage #1087), so no earlier fix to this path.classifyCodexTurnFailurehas one real-clock reader (evaluateCodexRun:419) and two tests that reach it throughevaluateCodexRun. One producer, so a local fix is the right owner.nowtoCodexRunOutcomeand thread it through:419, keep production behaviour unchanged (defaultDate.now()).Standard block:
npm testin exec or in QA. This applies to the qa phase too. Run only the three test files named in the ACs, plusgrep -rlE 'evaluateCodexRun|classifyCodexTurnFailure|codex-turn-failed-usage-limit' --include='*.test.ts' src __tests__ scripts | xargs npx vitest run.failedTestmust start with the test file path:src/lib/workflow/drivers/__tests__/driver-conformance.test.ts > … > ….Closes #1248. Use onlyRefsfor any tracker.admarble commentedon Oct 1, 2026
Complexity: Standard (3 ACs, 2 directories)
AC Quality Check
now) — not flagged further; the wording is fine as written.✅ AC-2, AC-3: Clear and testable.
Scope Assessment
Non-Goals:⚠️ Non-Goals section not found in the issue body.
Verdict:⚠️ SCOPE_WARNING — driven solely by the missing Non-Goals heading; every quantitative metric is green. Given the
main-goes-red deadline (2026-10-09), not worth blocking on; flagged for completeness only.Acceptance Criteria
AC-1: Both tests are independent of the wall clock
Verification: Unit Test
Scenario: Given
driver-conformance.test.ts'scodexOutcome()helper andbatch-executor.test.ts's inlineevaluateCodexRun()call both currently omitnow→ When the real clock crosses 2026-10-09 ~01:04 → Then both suites currently flip fromBillingErrortoRateLimitErrorand fail; after the fix, both pin an explicitnowso the result is clock-independent.Assumptions: The owner's runner-context comment pre-approved threading an optional
nowthroughCodexRunOutcomerather thanvi.useFakeTimers()— see Design Review Q2.AC-2: Horizon branch covered on purpose, not by the calendar
Verification: Unit Test
Scenario: Given the real
codex-turn-failed-usage-limit.jsonlfixture parsed throughCodexStreamParser→ WhenevaluateCodexRunis called withnowset inside the 7-day window (e.g. 2026-10-10T00:00, since the fixture's reset is 2026-10-16T01:04) → ThenstructuredErroris aRateLimitErrorwithmetadata.resetsAt === Date(2026,9,16,1,4).getTime().Assumptions: None — this exercises the real parse path, not just
classifyCodexTurnFailurein isolation (codex.test.ts already has synthetic-message horizon tests via itsat()helper; AC-2 asks specifically for "the fixture").AC-3: Mutation check proves the pin is load-bearing
Verification: Unit Test
Scenario: Given AC-1's pinned
nowvalues → When the pin is removed/overridden and the system clock is set to 2026-10-10 → Then theBillingErrorassertions indriver-conformance.test.ts:620(and thebatch-executor.test.tscase) fail → Restore the pin, recordMutation-verified:per the constitution's §6i marker format.Assumptions:
failedTestin the marker must start with the test file path (src/lib/workflow/drivers/__tests__/driver-conformance.test.ts > ...), per the owner's comment andproject_mutation_marker_failedtest_file_prefix.Implementation Plan
Phase 1: Thread an optional
nowthrough the production pathnow?: numberto theCodexRunOutcomeinterface (src/lib/workflow/drivers/codex.ts:281-288). Confirmed additive/safe — grepped all 8 call sites acrosscodex.ts,codex.test.ts,driver-conformance.test.ts, andbatch-executor.test.ts; none break from an optional field.evaluateCodexRun'sturnFailurebranch (:416-420), changeclassifyCodexTurnFailure(parsed.turnFailure)→classifyCodexTurnFailure(parsed.turnFailure, outcome.now). The production caller (:716) never setsnow, sooutcome.nowisundefinedthere andclassifyCodexTurnFailure's own default parameter (now: number = Date.now()) keeps production behavior unchanged.Phase 2: Pin the two wall-clock-dependent tests (AC-1)
driver-conformance.test.ts: give thecodexOutcome()helper (:209-219) a pinned default, e.g.const PINNED_NOW = new Date(2026, 8, 1).getTime();passed asnowin the returnedevaluateCodexRun(..., { ..., now: PINNED_NOW }). The existing callcodexOutcome("codex-turn-failed-usage-limit.jsonl")at:623needs no edit — it inherits the pin.batch-executor.test.ts: add the same pinnednowto the inlineevaluateCodexRun(parser.end(), {...})call (~:3049).Phase 3: Cover the horizon branch on purpose (AC-2)
codex.test.ts: add a test — in or alongside the existing"1087: classifyCodexTurnFailure"describe block — that loads the real fixture (readFileSync+CodexStreamParser, same pattern already used in the other two files) and callsevaluateCodexRunwithnowinside the window (2026-10-10). AssertRateLimitErrorwith the exactresetsAtepoch.Phase 4: Mutation verification (AC-3)
PINNED_NOWto2026-10-10), runnpx vitest run src/lib/workflow/drivers/__tests__/driver-conformance.test.ts, confirm theBillingErrorcase at:620fails, restore the pin, and record the result in the PR body with theMutation-verified:/SEQUANT_MUTATIONmarker.Commands to run (per the owner's comment — no full
npm test, in exec or qa):Design Review
CodexRunOutcome/evaluateCodexRuninsrc/lib/workflow/drivers/codex.ts— the same module that already ownsclassifyCodexTurnFailure's explicitnowparameter. Test-side pins live in each test file's own helper/call site.nowthroughCodexRunOutcome(owner-blessed). Rejected:vi.useFakeTimers()+vi.setSystemTime()— bothdriver-conformance.test.tsandbatch-executor.test.tsare large, multi-suite files; a global fake-timer scope risks leaking into unrelated tests in the same file and needs carefulafterEachrestore. An explicit, optional constructor field is localized, auditable in a diff, and mirrors a pattern the codebase already uses one layer down.codex.test.ts's ownNOWconstant +classifyCodexTurnFailure(msg, NOW)calls — this just extends the same explicit-clock-injection pattern one layer up throughevaluateCodexRun.CodexRunOutcomeinterface for a test concern?" — because both the real driver (:716) and tests already construct this object inline by hand; one optional field keeps a single code path instead of a parallel test-only overload, and defaults to real-clock behavior everywhere it isn't set.No ADR required — this is a localized test-determinism fix (mechanical tier per the issue itself), not a cross-cutting architectural decision.
Feature Quality Planning
All standard checks pass. Notable items:
feature/1248-fix-test-codex-usage-limit-tests-read-the-real-cloexists but is clean (identical toorigin/main, no commits, no uncommitted changes) — no conflict, safe to reuse.CodexRunOutcomefield addition verified additive via whole-repo grep (8 call sites, all optional-field-safe).Open Questions
nowconstant be shared across the three touched test files (atest-utilsexport) instead of one literal per file? — Recommendation: keep them independent per-file literals;CODEX_WAIT_HORIZON_MShas exactly one prior commit in its history (git log -S), so cross-file coupling isn't worth it for a one-off determinism fix. Impact if wrong: a future horizon-constant change needs 2 edits instead of 1 — low cost.Recommended Workflow
Phases: exec → qa
Quality Loop: enabled
Reasoning:
testgenis mechanically indicated (all 3 ACs carry declared Unit Test evidence, which outranks thebug-label short-circuit per #938) but is overridden here: the AC evidence is editing the existing test files directly (pinning a clock value, adding one assertion) — there's no separate production code path to stub ahead of the tests, so a generated stub would just collide with the hand-written edits above. Quality loop stays enabled per the mechanicalSCOPE_WARNINGverdict, even though the only driver is the missing Non-Goals heading — cheap safety net given the fixed landing deadline.Label Review
Current: bug
Recommended: bug, planned
Reason: Plan reviewed and accepted.
Quality Loop: Will auto-enable (SCOPE_WARNING, missing Non-Goals heading only).
→
gh issue edit 1248 --add-label planned--- DRAFT GITHUB ISSUE COMMENT (PLAN) ---
Spec Plan — #1248
AC Checklist
nowthroughCodexRunOutcomein bothdriver-conformance.test.ts'scodexOutcome()helper andbatch-executor.test.ts's inlineevaluateCodexRun()call.codex.test.tscase — real fixture parsed,nowinside the 7-day window, assertsRateLimitError.BillingErrorcases fail, restore, recordMutation-verified:marker.Plan
now?: numbertoCodexRunOutcome; thread it intoclassifyCodexTurnFailureatcodex.ts:419(production caller at:716unaffected — stays onDate.now()).nowin both AC-1 test helpers to a fixed pre-horizon date (e.g. 2026-09-01).codex.test.tsusing the real.jsonlfixture,now= 2026-10-10.Key decision: Explicit
now-threading overvi.useFakeTimers()— matches the owner's comment, avoids fake-timer leakage risk in two large shared test files.Open question: Keep the pinned-clock constants per-file rather than centralizing — fine given
CODEX_WAIT_HORIZON_MSbarely changes.Workflow: exec → qa (quality loop enabled;
testgenmechanically indicated but overridden — the AC evidence is the test edits, nothing else to stub).admarble commentedon Oct 1, 2026
QA Verdict: AC_MET_BUT_NOT_A_PLUS
AC coverage: 3/3 met
Gaps:
docs(#1248): CHANGELOG entry for the clock-independent Codex usage-li…