Repository navigation
Description
Problem
CodexDriver wraps every turn.failed as a generic SequantError (src/lib/workflow/drivers/codex.ts:323), so quota exhaustion is indistinguishable from any other turn failure. #1060 gate run 2 hit the ChatGPT free-plan limit mid-exec:
codex turn failed: You've hit your usage limit. Upgrade to Plus to continue using Codex (…), or try again at Oct 16th, 2026 1:04 AM.
The run log recorded errorContext: {category: "unknown", errorType: "SequantError", isRetryable: false, errorMetadata: {code: "turn-failed"}}. The spec-requested quality loop then ran loop, which failed on the same message 4.7s later. --auto-wait (#804) and the #592 billing skip key off RateLimitError/BillingError, so neither can engage for a Codex phase either.
The Claude driver already maps these signals to typed errors (claude-code.ts, createRateLimitError); this is the Codex counterpart.
Signal available
- The
turn.failedmessage text (You've hit your usage limit, with a reset time). - The rollout JSONL's
token_count.rate_limitscarriesused_percent,window_minutes,resets_at(reached 99% just before the failure in run 2). Whether the same object reaches thecodex exec --jsonstream the driver parses is unverified — check before relying on it.
Acceptance criteria
- AC-1: a
turn.failedwhose message is the usage-limit text yieldsstructuredErrorof classBillingErrorwhen the reset is beyond the run's wait horizon, carrying the reset time in metadata - AC-2: a transient throttle (429-style)
turn.failedyieldsRateLimitError(retryable) - AC-3: any other
turn.failedstill yields the genericSequantErrorwith codeturn-failed - AC-4: with the phase failing on a
BillingError, the batch executor does not start a quality-loop iteration (fixture from run 2's message) - AC-5: fixtures use the verbatim run-2 message; AC-1 and AC-4 are mutation-verified per CLAUDE.md §Testing
Release-graph plan — guard-2026-09 (2026-09-20)
Graph: guard-2026-09 Tier: mechanical Wave: 3
May touch: src/lib/workflow/drivers/codex.ts (turn.failed mapping), src/lib/workflow/drivers/codex.test.ts, src/lib/workflow/drivers/__fixtures__/ (the run-2 message lands there under #1096 AC-3; reuse it), src/lib/workflow/batch-executor.test.ts (AC-4 case only), CHANGELOG.md
The npm run build && npm test AC is verified by the runner from a clean shell after the PR opens (PLAN I-1); the agent runs only the test files its ACs name. Mutation markers use failedTest starting with the test file path (I-4). #1096 AC-3 is the failing test for AC-1/AC-2; this issue makes it pass. OQ-3 (does codex exec --json carry rate_limits?) is answered in the PR body; the message-text mapping does not depend on it.
Activity
admarble commentedon Sep 20, 2026
Runner context — guard-2026-09 wave 2 launch, 2026-09-20. Base:
origin/mainatbef0ac98(all seven wave-1 PRs merged: #1086 scrub, #1104 marker docs, #1053, #1106 ownership gate, #1095 parsers, #1096 conformance suite, #1070 failing verdicts post). These rules override the exec AND qa skills' defaults for this run:npm testin the worktree — this applies to the qa phase too. Under concurrent phase agents that one call exceeds the 30-minute no-progress wall and the phase is killed (three wave-1 phases died this way). Verify each AC by its own command; run only the test files the ACs name. The runner runs the full suite once per PR from a clean shell and records it on the PR.<!-- SEQUANT_MUTATION: {"ac":"AC-N","mutation":"<what you deleted>","failedTest":"<test file path> > <describe> > <case>"} -->in the PR body.failedTestMUST start with the test file path. RunparseMutationMarkerson your body before opening the PR. Commit before mutating.timeout.git commit -m "...", noCo-Authored-By. Push the branch and open the PR yourself (one wave-1 exec forgot). Never rebase or force-push after pushing. One AC per line in the PR body, idsAC-Nonly.Issue-specific: Pulled forward from wave 3: #1096 is merged. Its conformance suite marks the codex usage-limit and throttle cases
it.fails— flip them toitinsrc/lib/workflow/drivers/__tests__/driver-conformance.test.ts(that file is in scope for that one change) and record the AC-1 mutation against it; reuse the fixtures indrivers/__fixtures__/(verbatim run-2 message already there).batch-executor.test.tsis shared with #1069: add your AC-4 case in ONE newdescribe("#1087 …")block appended at the end and touch nothing else there.admarble commentedon Sep 20, 2026
Complexity: Standard (5 ACs, 3 directories)
AC Quality Check
autoWaitMinutes(evaluateCodexRun(parsed, outcome)andAgentExecutionConfigcarry no wait budget). Resolved in Open Question 1: a fixed driver-side horizon.codex-turn-failed-rate-limit.jsonl) is reconstructed, not captured (PROVENANCE.md). The plan enumerates the patterns in Phase 1.Scope Assessment
Non-Goals:⚠️ No Non-Goals section. Inferred from the graph plan's "May touch" list: no opencode classification, no
rate_limitsplumbing, no change to batch-executor logic (AC-4 is a test only).turn.failedclassification)drivers/,drivers/__tests__/,workflow/)Verdict: ✅ SCOPE_OK
Acceptance Criteria
AC-1: usage-limit
turn.failed→BillingError(reset beyond horizon), reset time in metadataVerification: Unit Test
Scenario: Given the verbatim run-2 stream (
codex-turn-failed-usage-limit.jsonl) → WhenevaluateCodexRunruns → ThenstructuredErroris aBillingError,isRetryable === false, andmetadata.resetsAtText=Oct 16th, 2026 1:04 AM(plusmetadata.resetsAtin epoch ms when parseable).Assumptions: The reset text is local-time and human-formatted; only one capture exists. An unparseable or absent reset must still yield
BillingError(fail closed) withresetsAtTextonly.AC-2: transient throttle → retryable
RateLimitErrorVerification: Unit Test
Scenario: Given
codex-turn-failed-rate-limit.jsonl→ WhenevaluateCodexRunruns → ThenstructuredErroris aRateLimitError,isRetryable === true.Assumptions: The wording after
rate limit exceeded:is reconstructed. Match the prefix codex itself emits, plus429/too many requests, not the invented detail.AC-3: other
turn.failed→ genericSequantError, codeturn-failedVerification: Unit Test
Scenario: Given
codex-turn-failed-unrecognized.jsonl→ Then the error is neitherBillingErrornorRateLimitErrorandmetadata.code === "turn-failed". Already green in the conformance suite; it must stay green (regression guard for over-broad regexes).AC-4: no quality-loop iteration after a
BillingErrorphase failureVerification: Integration Test
Scenario: Given
-QwithmaxIterations > 1and an exec phase whose result isevaluateCodexRun(<run-2 fixture>)(the real mapping, not a hand-builtBillingError) → WhenrunIssueWithLoggingruns → Then exec is dispatched once andloopis never dispatched.Assumptions: The executor half (
isBillingHalt→haltedByBilling,batch-executor.ts:1910) already exists (#799) and is tested with synthetic errors atbatch-executor.test.ts:776. AC-4's new value is pinning the composition: the real Codex-mapped error reaches that guard.AC-5: verbatim fixtures; AC-1 and AC-4 mutation-verified
Verification: Unit Test + Manual (PR body marker)
Scenario: Reuse
__fixtures__/codex-turn-failed-usage-limit.jsonl(byte-identical to run-2stdoutTail[48..49]). Mutation records use theSEQUANT_MUTATIONformat withfailedTeststarting with the test file path.Implementation Plan
Phase 1: Classifier in the driver (
src/lib/workflow/drivers/codex.ts)classifyCodexTurnFailure(message, now = Date.now()): SequantError, called from theparsed.turnFailurebranch ofevaluateCodexRun(codex.ts:323)./hit your usage limit/i→ usage-limit path. Extract the text aftertry again at, strip the ordinal suffix (16th→16), parse as local time.CODEX_WAIT_HORIZON_MS(7 days, mirroring theseven_dayallowlist inerrors.ts) →RateLimitErrorwithresetsAt(ms), so--auto-waitcan engage viashouldAutoWaitForReset.BillingErrorwithresetsAtTextand, when parsed,resetsAt. Fail closed, as Five-hour window exhaustion is misclassified as terminal billing, so --auto-wait is inert on subscription plans #860 does./rate limit (exceeded|reached)|\b429\b|too many requests/i→RateLimitError, noresetsAt(metadata-absent takes the transient backoff path, feat: detect rate-limit failures mid-chain and halt cleanly instead of timeout-cascading #761 AC-9).SequantError.metadata.code = "turn-failed"on every branch, so anything keyed on the code keeps working.error.message/fail()string is unchanged:codex turn failed: <message>.Phase 2: Tests (parallel-safe after Phase 1)
drivers/__tests__/driver-conformance.test.ts: deletepending: "#1087"from the two codex cases (only that change in the file).drivers/codex.test.ts: unit tests forclassifyCodexTurnFailurecovering the horizon boundary (6d23h vs 7d1h, with injectednow), the past reset, no reset, an unparseable reset, the ordinal suffix, both AC-2 wordings, and the AC-3 fall-through.batch-executor.test.ts: append ONEdescribe("#1087 …")at the end (shared with bug(qa): the qa phase rebases an already-pushed branch onto main, forcing a force-push to land it #1069, touch nothing else). DriverunIssueWithLoggingwith an exec result built from the run-2 fixture. Assert one exec dispatch, zeroloopdispatches,haltedByBillingsurfaced.Phase 3: Verify and record
driver-conformance,codex.test.ts,batch-executor.test.ts). No fullnpm test(runner context). Add aCHANGELOG.mdentry.SequantError. The conformance caseerrors map the verbatim #1087 usage-limit …must fail.#1087batch-executor case must fail, because it loops intoloop. This confirms the test exercises the real mapping and not a stub.SEQUANT_MUTATIONmarkers with the full test file path first.Design Review
evaluateCodexRun), the counterpart ofClaudeCodeDriver.buildStructuredError. The executor already keys on the typed classes (isBillingHalt,isWindowHalt), so no executor change is needed.autoWaitMinutesintoAgentExecutionConfig. It would touch the driver interface for every driver and is outside "May touch".autoWaitMinutesstays the final dial inshouldAutoWaitForReset.createRateLimitError/isBillingFailure(Five-hour window exhaustion is misclassified as terminal billing, so --auto-wait is inert on subscription plans #860): recognized window allowlist, everything else fails closed toBillingError.RateLimitErrorwhen AC-1 only namesBillingError?" Because the issue title says auto-wait must be able to engage, and a within-horizon reset is a pause, not a wallet failure. Both halt the quality loop (isWindowHaltfor reset > 5 min), so AC-4 holds either way. See OQ-1.Feature Quality Planning
All standard checks pass. Notable items:
errorevent (codex-turn-failed-usage-limit.jsonlline 3). Theparsed.errorsbranch (codex.ts:331, codestream-error) is generic. With aturn.failedpresent the first branch wins, so the fixture is covered. A run that emits only theerrorevent and exits non-zero would still be classified generic. Proposed as OQ-2; not silently widened.AUTO_WAIT_MAX_WAITS = 2, so an early wake costs one more rejection at worst.OQ-3 (rate_limits in the exec JSON stream)
Partial evidence only: the run-2 log's 50-line
stdoutTailhas norate_limitsortoken_count. That tail is only the last lines and is not conclusive for earlier events. Resolve in the PR by scanning a full livecodex exec --jsonstream with the existingcodex.live.integration.test.tsharness, if credentials allow; otherwise state "not observed in the tail; unverified". The message-text mapping does not depend on it.Open Questions
RateLimitErrorwithresetsAtfor ≤ 7 days, so--auto-waitcan engage; the issue title names that as a goal. Impact if wrong: a within-horizon reset halts instead of waiting. Simpler fallback: alwaysBillingErrorwith reset metadata, sinceresetsAtstill lands in metadata.errorevent (noturn.failed)? Recommendation: yes, by routingparsed.errorsthrough the same classifier. It is a few lines in the same function, but it widens AC-3's "any other" surface. Impact if skipped: a stream that dies after theerrorevent without aturn.failedstays "unknown".seven_day). Run 2's Oct 16 reset is ~26 days out, so it isBillingError. Impact if wrong: only the boundary cases move.Recommended Workflow
Phases: exec → qa
Quality Loop: disabled
Reasoning: Bug fix with the failing tests already stubbed by #1096 (
pending), so testgen adds nothing. Mechanical tier, one driver file, three test files. No UI, no security surface. Runner rules apply: no fullnpm test, mutation markers with the file path first, stop at the PR.Label Review
Current: bug
Recommended: bug, planned
Reason: Confirms scope; no complexity labels warranted.
Quality Loop: Won't auto-enable (SCOPE_OK, 5 ACs).
admarble commentedon Sep 20, 2026
QA Verdict: AC_MET_BUT_NOT_A_PLUS
AC coverage: 5/11 met
Gaps:
Suggestions:
nowthroughevaluateCodexRun(it already exists onclassifyCodexTurnFailure) and havecodexOutcome/ the batch-executor case pass a frozen timestamp. That removes the clock dependency without touching the fixture.chore(#1087): merge origin/main
fix(#1087): classify Codex usage-limit and throttle turn failures as …
docs(codex): note typed usage-limit failures (#1087) and link the dri…
docs(codex): reference page and troubleshooting, changelog backfill, …