Skip to content

fix(#799): fail-fast the -Q quality loop on billing / rate-limit-window failures - #800

Merged
admarble merged 3 commits into
mainfrom
feature/799-fix-run-q-quality-loop-retries-after-an-out-of
Jul 24, 2026
Merged

admarble merged 3 commits into
mainfrom
feature/799-fix-run-q-quality-loop-retries-after-an-out-of

Conversation

@admarble

Copy link
Copy Markdown
Contributor

Summary

Fixes #799. The outer -Q quality loop in batch-executor.ts only failed fast on the #739 turn-cap case. A billing / "Out of credits" failure (or a window-exhausted rate limit) still spawned /loop and burned the remaining iterations — none of which could succeed while credits/window were exhausted — and the doomed retries surfaced as a misleading QA completed without a parseable verdict instead of the real cause.

Changes

Mirrors the existing haltedByCap (#739) machinery with a haltedByBilling flag driven by a shared isBillingOrWindowHalt() predicate:

  • isBillingOrWindowHalt(result) — true for a BillingError or a window-exhausted rate limit (reuses the existing isWindowExhaustedRateLimit from phase-executor.ts). Transient / metadata-absent rate limits return false and keep today's retry/loop behavior.
  • billingHaltReason(result) — surfaces the driver's real cause and appends the reset time when present, so the phase-failed event (and thus the run summary via run-renderer's failureReason) names the actual cause.
  • Loop-spawn guard extended with && !haltedByBilling; break guard is now if (haltedByCap || haltedByBilling).
  • failureCategory is billing/rate_limit — already wired via deriveFailureCategory. The run ends resumable (in_progress, no spurious AC_NOT_MET).

AC Coverage

AC Status Notes
AC-1 ✅ MET Billing halts the outer loop before /loop; no further iterations.
AC-2 ✅ MET Window-exhausted rate limit halts too; transient/metadata-absent keeps today's behavior.
AC-3 ✅ MET Failed event + summary state the real cause + resetsAt; failureCategory = billing/rate_limit.
AC-4 ✅ MET Halts before /loop → in_progress, no AC_NOT_MET; re-run resumes the link.
AC-5 ✅ MET Regression tests: billing halt, rate-limit-window variant, transient-not-halted fallback.

Testing

Risk Assessment

Closes #799

…ow failures

The outer -Q quality loop in batch-executor only halted on the #739 turn-cap
case. A billing / out-of-credits failure (or a window-exhausted rate limit)
still spawned /loop and burned the remaining iterations — none of which could
succeed — and the doomed retries surfaced as a misleading "QA completed without
a parseable verdict" instead of the real cause.

Mirror the haltedByCap (#739) machinery with a haltedByBilling flag driven by a
shared isBillingOrWindowHalt() predicate (BillingError, or a window-exhausted
rate limit via the existing isWindowExhaustedRateLimit). The failed-event now
names the real cause + reset time (billingHaltReason), and the run ends
resumable (in_progress, no spurious AC_NOT_MET) with failureCategory =
billing/rate_limit already wired via deriveFailureCategory.

- AC-1/AC-2: halt before /loop on billing and window-exhausted rate limit;
  transient/metadata-absent rate limit keeps today's behavior.
- AC-3: phase-failed + summary state the real cause; metrics category correct.
- AC-4: state stays resumable.
- AC-5: regression tests for the billing halt, the rate-limit-window variant,
  and the transient-not-halted fallback.
admarble added 2 commits July 24, 2026 08:51
QA second-look caught a real defect: for a window-exhausted rate limit the
driver already formats the reset time INTO result.error ("Rate limited —
resets at 07-24 14:32", via formatRateLimitMessage). billingHaltReason then
re-appended a second, timezone-inconsistent copy from the structuredError
metadata ("… — resets at 2026-…Z"). The original test only matched /resets at/i
so it passed despite the duplication.

Surface result.error verbatim instead — it is already the driver's canonical
"real cause + reset time" message. Drops the now-unused resetsAtToMs import.

Also strengthen the regression tests:
- rate-limit variant now asserts the exact message and exactly one "resets at"
  occurrence (locks the no-double-reset fix).
- billing test now drives a spy StateManager and asserts AC-4 concretely:
  final status is "in_progress" (resumable) and never "ready_for_merge".
…ccuracy

Spec-phase sibling site: the early spec block mirrored the #739 capped message
but not billing. It already early-returns on any failure (no /loop, no cascade),
so this is a message/fallback symmetry fix, not a behavior change — route its
non-capped failure through billingHaltReason so a billing/window spec failure
names the real cause and falls back to "Out of credits" instead of "unknown".
Adds a spec-phase billing regression test (only spec runs, failureCategory
"billing").

Docs: docs/reference/run-command.md described the rate-limit fail-fast as
skipping "all phase retries" — accurate for the inner #761 ladder but not for
the outer -Q quality loop, which cascaded before this fix. Note billing
explicitly and that the -Q loop now honors the halt (no /loop on a closed
window), matching the documented single-line "resets at <local time>" summary.
@admarble
admarble merged commit de5b7b4 into main Jul 24, 2026
5 checks passed
@admarble
admarble deleted the feature/799-fix-run-q-quality-loop-retries-after-an-out-of branch July 24, 2026 14:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(run): -Q quality loop retries after an "Out of credits" exec instead of failing fast (billing cascades into "unparseable verdict")

1 participant