Skip to content

fix(#860): classify live five-hour windows as waitable, not terminal billing - #893

Merged
admarble merged 3 commits into
mainfrom
feature/860-waitable-window-classification
Aug 4, 2026
Merged

admarble merged 3 commits into
mainfrom
feature/860-waitable-window-classification

Conversation

@admarble

@admarble admarble commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Narrows isBillingFailure instead of inverting it: overageDisabledReason: "out_of_credits" alongside a recognized window type (five_hour / seven_day* prefix allowlist) and a future resetsAt now classifies as a retryable RateLimitError — a window that reopens, not a wallet failure — so --auto-wait (feat(run): --auto-wait — continue a rate-limited run when the window resets instead of halting #804) can finally fire on the only payload shape real subscription runs produce. errorCode: "credits_required", past/missing resets, and unrecognized shapes all remain terminal (fail closed).
  • Guards the driver's billing_error downgrade: buildStructuredError no longer strips a waitable window's metadata when the assistant separately reports the bare billing_error enum.
  • Makes non-TTY waits visible (AC-6): the -q heartbeat emits an append-only line naming the wake time every 5 minutes, and the default-mode NonTTY renderer announces the wait once and names the wake time in its 60s heartbeat — fixing two latent bugs (a spurious ✘ failure line per 15s waiting tick, and waiting ticks silencing the heartbeat by resetting its idle clock).
  • Commits the evidence: all 26 captured payloads (22 ad-motion + 4 matcha-maps) with provenance in __tests__/fixtures/rate-limit-payloads-860.json + docs/incidents/860/captures/README.md. Raw stdoutTail transcripts deliberately excluded (unrelated-project content).
  • AC-7 decision recorded: keep the in-process wait; durable halt-and-resume filed as feat(run): durable halt-and-resume for waitable rate-limit windows — write resumeAt, release the lock, survive reboots #892 (docs/investigations/auto-wait-vs-halt-resume-860.md).

AC Verification

AC Status Evidence
AC-1 live window → waitable ✅ errors.ts narrowing; 26/26 fixtures assert RateLimitError while live
AC-2 credits_required / no future reset → terminal, same message ✅ short-circuit + tests; end-to-end replay halts in 1 attempt
AC-3 unrecognized shape fails closed ✅ allowlist tests incl. rateLimitType: "overage"
AC-4 26 fixtures committed, terminal fixtures still terminal ✅ fixture file + count/shape/classification gate tests
AC-5 auto-wait fires end-to-end on window replay, not on credits replay ✅ executePhaseWithRetry replays in auto-wait.test.ts
AC-6 periodic non-TTY progress naming wake time ✅ heartbeat.ts + run-renderer.ts + 9 new display tests
AC-7 wait-vs-halt decision recorded ✅ decision doc; follow-up #892

Mutation verification (gate-test rule)

  1. Fixture payload deleted → exactly the 2 count-gate tests fail ✅
  2. five_hour removed from allowlist → 10 tests fail across errors/auto-wait/driver suites ✅
  3. Non-TTY heartbeat notice branch disabled → exactly the 3 notice tests fail ✅
  4. NonTTY renderer waiting handling reverted → exactly the 3 renderer tests fail (incl. the ✘-suppression guard) ✅

Test plan

  • npm run build, npm run lint clean
  • Full suite: 4845 passed / 231 files
  • QA review on the issue: READY_FOR_MERGE (7/7 ACs met)

Fixes #860

🤖 Generated with Claude Code

…billing

Narrow isBillingFailure: overageDisabledReason=out_of_credits alongside a
recognized window type (five_hour / seven_day*) and a FUTURE resetsAt is a
window that reopens, not a wallet failure — it now becomes a retryable
RateLimitError so --auto-wait (#804) can act on it. errorCode=credits_required
stays terminal even beside window evidence; missing/past resetsAt and
unrecognized window types fail closed to the terminal path (AC-2/AC-3).
Retention (isRateLimitFailureInfo) deliberately keeps the raw markers so no
failure event is dropped.

Driver: the billing_error assistant-enum downgrade no longer fires when the
rate_limit_event carries waitable-window evidence — the bare enum has no
metadata and would re-inert auto-wait.

AC-6 observability for non-TTY waits:
- LivenessHeartbeat (-q mode) emits an append-only line naming the wake time
  every 5 minutes (was TTY-gated; a background wait was silent for hours).
- NonTTYRenderer (default mode) announces the wait once, names the wake time
  in its 60s heartbeat, and no longer prints a spurious ✘ failure line per
  15s waiting tick; waiting ticks no longer reset the heartbeat idle clock.

Evidence: all 26 captured payloads (22 ad-motion + 4 matcha-maps) committed
with provenance as __tests__/fixtures/rate-limit-payloads-860.json (raw
stdoutTail transcripts deliberately not committed — unrelated project
content); fixture-driven tests assert waitable-while-live and
terminal-once-aged, plus end-to-end replay through executePhaseWithRetry.
AC-7 decision (keep in-process wait, file halt-and-resume follow-up) recorded
in docs/investigations/auto-wait-vs-halt-resume-860.md.

Gates: build ✓ lint ✓ full suite 4845 passed / 231 files ✓

Fixes #860
…window-classification

# Conflicts:
#	CHANGELOG.md
…CP wait visibility, real-clock coverage

Hardening pass over the classification fix, closing every gap named in review:

- Informational statuses (allowed/allowed_warning) are never waitable: a
  stale near-limit warning misattributed to an unrelated failure costs an
  immediate halt, not a 5h sleep. Absent status stays waitable — the 26
  captures carry no status field.
- unrecognizedWindowHint: when a payload is terminal ONLY because its window
  type is unrecognized, the halt message names the rejected type, so
  Anthropic vocabulary drift is diagnosable from a run log instead of
  silently reading as a wallet failure.
- Driver billing_error counter-exception narrowed to the full captured shape
  (waitable window + out_of_credits). A pure throttle beside a billing enum
  keeps the #732 billing-wins rule.
- MCP/orchestrator wait visibility: withActivityHook emits throttled
  SEQUANT_PROGRESS waiting lines (once/min) naming the wake time — each line
  also resets the MCP inactivity timeout that would otherwise kill a
  legitimate pause as "no progress" (absolute 2h ceiling still applies);
  parseProgressLine/formatProgressMessage understand the new event; the wait
  is persisted to issue state (autoWait.wakeAt + phase, via
  StateManager.updateAutoWait) and surfaced by sequant status and the MCP
  status tool, refreshing lastActivity and the state.json mtime liveness
  proxy.
- seven_day + out_of_credits semantics pinned by explicit tests and the
  captures README now records that combination as allowlisted-by-judgment,
  not evidence.
- Real-clock smoke tests: waitForWindowReset and performAutoWait run against
  real setTimeout/Date.now (300ms scale) — tick chunking, prompt abort, and
  ledger accounting exercised with no injected timers.

Gates: build + lint clean, full suite 4883 passed / 232 files.

Refs #860 #892
@admarble

admarble commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

Gap-hardening pass (ecfee024)

Follow-up commit closing every residual gap named in review (+815/−26 across 17 files):

  1. Real-clock coverage — waitForWindowReset and performAutoWait now also run against real setTimeout/Date.now (300ms scale, no injected timers): tick chunking, prompt abort, ledger accounting. The irreducible remainder — a literal 5-hour production wait — is validated the first time a real run hits the cap.
  2. MCP/orchestrator wait visibility — withActivityHook emits throttled (1/min) SEQUANT_PROGRESS waiting lines naming the wake time; each line resets the MCP inactivity timeout that would otherwise kill a legitimate pause as "no progress" (the transport's absolute 2h ceiling still applies — recorded in the decision doc; full 5h waits remain CLI-or-feat(run): durable halt-and-resume for waitable rate-limit windows — write resumeAt, release the lock, survive reboots #892 territory). The wait is also persisted to issue state (autoWait.wakeAt + paused phase) and surfaced by sequant status and the MCP status tool, so a paused issue reads "⏸ resuming at 07:01" instead of hours-stale in-progress.
  3. Vocabulary-drift telemetry — when a payload is terminal only because its window type is unrecognized, the halt message now names the rejected type (unrecognizedWindowHint): Out of credits (unrecognized window type "X" with a future reset — treated as terminal …). Missing rateLimitType deliberately emits no hint (absence isn't drift evidence).
  4. seven_day + out_of_credits — pinned by explicit tests (waitable live / terminal aged / date-qualified message) and documented in the captures README as allowlisted-by-judgment, not evidence.
  5. Informational-status guard — status: allowed/allowed_warning is never waitable: a stale near-limit warning misattributed to an unrelated failure costs an immediate halt (pre-Five-hour window exhaustion is misclassified as terminal billing, so --auto-wait is inert on subscription plans #860 cost), never a 5h sleep. Absent status stays waitable — the 26 captures carry no status field.
  6. Driver counter-exception narrowed to the evidenced shape — the billing_error downgrade now only yields when the event carries the full captured shape (waitable window plus out_of_credits); a pure throttle beside a billing enum keeps the feat(driver): surface structured rate-limit/credits errors from SDK message stream (replaces #592 fallback noise) #732 billing-wins rule.

Gates: build ✓ lint ✓ full suite 4883 passed / 232 files ✓
Mutation verification: status guard removed → exactly the 2 status tests fail; hint neutered → exactly the 2 hint tests fail; driver guard widened → exactly the new driver test fails; orchestrator emission disabled → exactly the 3 emission tests fail. All restored.

@admarble
admarble merged commit 30fd204 into main Aug 4, 2026
5 checks passed
@admarble
admarble deleted the feature/860-waitable-window-classification branch August 4, 2026 05:47
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.

Five-hour window exhaustion is misclassified as terminal billing, so --auto-wait is inert on subscription plans

1 participant