Repository navigation
Description
Summary
When sequant run … -Q (quality loop) hits an "Out of credits" / billing failure during a phase, the outer quality loop does not fail fast — it spawns /loop and retries the phase for the remaining iterations, none of which can succeed (there are no credits). The retries then surface as misleading QA completed without a parseable verdict errors, so a billing stop is reported to the user as a QA problem.
This was observed on a real chain run (sequant run 109 111 112 113 --chain -Q): #111 passed cleanly, then #112 failed like this:
✘ #112 exec Out of credits
▸ #112 loop
✔ #112 loop 2m 23s
▸ #112 exec (attempt 2/3) ✔ 52s
▸ #112 qa (attempt 2/3) ✘ QA completed without a parseable verdict
▸ #112 loop
✔ #112 loop 2m 12s
▸ #112 exec (attempt 3/3) ✔ 1m 45s
▸ #112 qa (attempt 3/3) ✘ QA completed without a parseable verdict
SUMMARY · #112 ✘ failed · QA completed without a parseable verdict
The run's actual halt cause was Out of credits on the very first exec; everything after it is wasted wall-clock and a mislabeled failure.
Root cause
src/lib/workflow/batch-executor.ts:1051:
if (useQualityLoop && iteration < maxIterations && !result.capped) {
// spawn /loop, then continue to the next outer iterationThe outer quality loop only fails-fast on the #739 turn-cap case (!result.capped). It has no equivalent halt for a billing / window-exhausted-rate-limit failure, even though the signal is already present in scope: the failure branch at batch-executor.ts:1040 has result.structuredError, which is a BillingError for out-of-credits (see error-classifier.ts:53-58, errorTypeToCategory → "billing"). deriveFailureCategory(phaseResults) (batch-executor.ts:440) already computes exactly this category elsewhere in the file.
Why #761/#732 didn't cover this: #732 surfaced the structured billing/credits signal from the driver, and #761 added billing/rate-limit skips inside a single phase's retry ladder (phase-executor.ts:~923 "the billing skip (#732)") plus the MCP-fallback gate. But the outer -Q quality loop in batch-executor.ts was never taught to consult that signal — so a billing failure that halts the inner retries still triggers an outer /loop + phase re-run.
Expected behavior
A billing / out-of-credits failure (and a window-exhausted rate limit, i.e. isWindowExhaustedRateLimit) should halt the outer quality loop immediately — the same "surface + halt, user resumes" treatment the turn-cap path (#739) already gets — and the run summary / phase-failed line should state the real cause (Out of credits / rate-limited, with resetsAt when present) instead of cascading into QA completed without a parseable verdict.
Acceptance Criteria
- AC-1 In
batch-executor.ts, when a phase fails with a billing structured error (result.structuredError instanceof BillingError, orderiveFailureCategory="billing"), the outer quality loop halts immediately — no/loopspawn, no further iterations — mirroring the existinghaltedByCap(feat(orchestrator): preserve partial output for turn-capped phases in phase-executor #739) pattern (e.g. ahaltedByBillingflag / shared "halt, don't loop" predicate). - AC-2 Same fail-fast for a window-exhausted rate limit (reuse
isWindowExhaustedRateLimitfromphase-executor.ts) so a closed-window throttle doesn't burn iterations either. A metadata-absent / transient rate limit keeps today's behavior. - AC-3 The phase-failed event and run summary state the real cause (
Out of credits/ rate-limited +resetsAtwhen available) rather than a downstreamQA completed without a parseable verdict. ThefailureCategoryrecorded in metrics isbilling/rate_limitaccordingly (already wired viaderiveFailureCategory). - AC-4 The issue's state ends resumable (not a spurious hard
AC_NOT_MET), so re-running the same command resumes the link once credits/window are restored — consistent with the feat: resume a partially-completed chain from its last good link #760 resume contract. - AC-5 Regression test: a mocked exec phase returning a
BillingErrorunder-Qhalts after the first attempt (assert: no secondexec/loopattempt, halt reason names billing). Add the rate-limit-window variant.
Notes
- Chain mode already halts on the first failed link, so once the loop fails-fast on billing the chain stops cleanly at that link — the fix is purely about not wasting the 2 doomed retries and not mislabeling the cause.
- Related: feat(driver): surface structured rate-limit/credits errors from SDK message stream (replaces #592 fallback noise) #732 (structured credits/rate-limit signal), feat: detect rate-limit failures mid-chain and halt cleanly instead of timeout-cascading #761 (in-phase billing/rate-limit fail-fast + MCP gate). This closes the outer-quality-loop gap those left open.
Activity
admarble commentedon Jul 24, 2026
Plan Complete — #799
Complexity: Standard (5 ACs, 1 primary directory:
src/lib/workflow/)AC Checklist
BillingError/deriveFailureCategory === "billing") halts the outer-Qquality loop immediately — no/loopspawn, no further iterations — mirroringhaltedByCap(feat(orchestrator): preserve partial output for turn-capped phases in phase-executor #739).isWindowExhaustedRateLimit). Metadata-absent/transient rate limit keeps today's behavior.Out of credits/ rate-limited +resetsAt), not a downstreamQA completed without a parseable verdict.failureCategory=billing/rate_limit(already viaderiveFailureCategory).AC_NOT_MET); re-run resumes the link once credits/window restored (feat: resume a partially-completed chain from its last good link #760 contract).BillingErrorunder-Qhalts after first attempt (no 2nd exec/loop; halt reason names billing). Add rate-limit-window variant.Implementation Plan
File:
src/lib/workflow/batch-executor.ts(mirror thehaltedByCap#739 machinery)BillingErrorfrom../errors.jsandisWindowExhaustedRateLimitfrom./phase-executor.js.isHaltNotLoopFailure(result)(billing OR window-exhausted rate limit) or ahaltedByBillingflag declared next tohaltedByCap(line ~843).haltedByBilling = true(alongsideif (result.capped) haltedByCap = true).!result.capped→ also&& !haltedByBillingso no/loopspawns.if (haltedByCap || haltedByBilling) break;.result.error ?? "Out of credits"(appendresetsAtfor rate limit) instead of the generic reason.deriveFailureCategoryalready yields the correct metrics category — no metrics change needed.in_progressfinalStatus (resumable); halting before/loopavoids the spuriousAC_NOT_METverdict. No extra state flag required.Design Review
batch-executor.ts— the one place feat(orchestrator): preserve partial output for turn-capped phases in phase-executor #739's cap-halt lives and where the feat(driver): surface structured rate-limit/credits errors from SDK message stream (replaces #592 fallback noise) #732 billing signal was never consulted.structuredError,isWindowExhaustedRateLimit); no new classification. MirrorhaltedByCapexactly rather than inventing a new halt mechanism.-Qloop gap those left open.Verification
BillingError/ window-exhaustedRateLimitErrorunder-Q).Recommended Workflow
Phases: exec → qa (no
test— backend/CLI, no UI labels). Quality Loop: enabled.admarble commentedon Jul 24, 2026
/fullsolve Complete — #799
Status: READY_FOR_MERGE
Summary
The outer
-Qquality loop now fails fast on a billing / out-of-credits failure or a window-exhausted rate limit — mirroring the #739 turn-cap halt — instead of spawning/loopfor doomed retries that mislabeled the cause asQA completed without a parseable verdict.AC Coverage — 5/5 MET
/loop.resetsAt;failureCategory=billing/rate_limit.in_progress, no spuriousAC_NOT_MET).Quality
batch-executor.test.ts55 ✓ (4 new),phase-executor.test.ts138 ✓tsc --noEmit,eslint,npm run build: cleanIterations
phase-executor.js)PR: #800
fix(#799): stop billingHaltReason doubling the reset time
admarble commentedon Jul 24, 2026
QA second-look — one real gap fixed
Adversarial re-read after the first PASS found a defect the structured pass missed:
billingHaltReasondoubled the reset time. For a window-exhausted rate limit, the driver already formats the reset time intoresult.error("Rate limited — resets at 07-24 14:32", local time, viaformatRateLimitMessage). The helper then re-appended a second, timezone-inconsistent copy fromstructuredError.metadata(" — resets at 2026-…Z"). The first test only matched/resets at/i, so it passed despite the duplication.Fixed in
9005620: surfaceresult.errorverbatim (already the canonical "cause + reset time"); dropped the redundantresetsAtToMsappend. Regression tests tightened to assert the exact message + exactly oneresets at, and AC-4 now asserts the real state write (in_progress, neverready_for_merge).Noted non-gap (no fix): the early spec-phase block handles
cappedas a #739 sibling but not billing. It's outside the outer-Qquality loop and can't cascade (no/loopretry there), so it's out of AC scope — a spec-phase "Out of credits" already surfacesresult.errorcorrectly. Flagging for visibility only.fix(#799): close remaining gaps — spec-phase billing symmetry + doc a…
admarble commentedon Jul 24, 2026
All gaps closed
Following the QA second-look, every identified gap is now fixed (PR #800, all CI green):
billingHaltReasonre-appended a reset time the driver already formats intoresult.error. Now surfacesresult.errorverbatim; test asserts the exact message + exactly oneresets at.StateManagerand asserts final statusin_progress, neverready_for_merge.billingHaltReason(mirroring the feat(orchestrator): preserve partial output for turn-capped phases in phase-executor #739 capped message it already had). Behavior was already correct (early-returns, no cascade); this is message/fallback symmetry + a spec-phase billing regression test.docs/reference/run-command.mddescribed the rate-limit fail-fast as skipping "all phase retries" (true for the inner feat: detect rate-limit failures mid-chain and halt cleanly instead of timeout-cascading #761 ladder, not the outer-Qloop pre-fix). Now notes billing explicitly and that the-Qloop honors the halt.Final: 194 tests pass ·
tsc/eslint/buildclean · 5/5 CI checks SUCCESS.fix(#799): fail-fast the -Q quality loop on billing / rate-limit-wind…
test(#782): guard the #799 sibling site; correct an overclaimed MCP e…
test(#782): validate #761 AC-9 — real window rejections carry rateLim…
feat(#804): --auto-wait — continue a rate-limited run when the window…