fix(server): a /compact stopped by the Claude usage limit now fails #19583
main fromrefs/pull/19583/head·merged by juliusmarminge View on GitHubProblem#
When the Claude usage limit stops a /compact, Claude still ends the command with a success result (subtype: "success", is_error: false). T3 stored that run as completed. The usage-limit queue guard (usageLimitBlockedRun) only holds the queue after a failed run, so a message already queued with Mod+Enter started right away and failed on the same limit.
The reporter's provider log and database (comment) show the sequence: a rejected five_hour rate-limit event with resetsAt, a status frame with compact_result: "failed", a success result, the compaction run stored completed, and the queued run starting 56 ms later and failing on the limit.
Change#
ClaudeAdapterV2 remembers when a status frame in the current turn reports compact_result: "failed". When the turn's result is a /compact (local_command: "compact") and the adapter's existing usage-limit check holds (a rejected window still blocking at the result, or a rate-limit error from Claude), the turn ends failed with a usage_limit failure, Claude's compact_error text, and the reset time from the rate-limit events. That failed run with a root usage_limit error is the state the existing guard checks.
Left unchanged on purpose:
- A
/compactthat fails for another reason, such as "Not enough messages to compact.", stayscompleted. Aprovider_errorthere would hold the queue too, and holding it for a compaction that had nothing to do would be worse than today. - An automatic compaction inside a normal turn is not affected: the new branch needs a result with
local_command: "compact". A normal turn the limit blocks already fails through its terminal reason.
Scope and approval#
Refs #19327. Triage (comment) moved the request to Ideas and said: "If you can show from a live run that Mod+Enter (queue) also starts right away and cancels the resume, comment with logs, because that would go against the documented queue behavior." The reporter's logs show a message queued with Mod+Enter starting after a failed /compact.
This fixes a usage-limited /compact being stored as completed, which let a queued message run into the limit. It does not hold a new Send until the reset or change the continuation text, because triage moved those to Ideas. Auto-resume cancellation is not established in the logs and is not changed here. The change is a small, focused fix to the documented queue behavior triage described, not a change to it.
Verification#
Server only; the UI renders the stored run status and queue.
apps/server:vp test run src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts. A newit.effect.eachtable replays the frames in the reporter's order: the limited/compactendsfailedwith classusage_limit, thecompact_errortext andresetAt. Three controls staycompleted: a/compactthat failed without a limit, a successful/compactunder a rejected window, and a limited turn whose automatic compaction failed (nolocal_command, no terminal reason). The limited case fails with the fix reverted (the turn endscompleted). The existing paused-then-completed test still passes.- The frame shapes come from a real
claude2.1.300 run on Linux: a/compactsendssystem/statusframes withcompact_result, and its result carrieslocal_command: "compact",num_turns: 0and noterminal_reason. - The queue step is existing behavior:
runtimeLayer.test.ts"handles a queued message after a usage_limit failure" shows a queued run staying queued after a failed run with a rootusage_limiterror. That test passes on this branch. No new end-to-end test drives a queued message through the Claude adapter. - 484 tests pass in
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts,apps/server/src/orchestration-v2/runtimeLayer.test.ts,apps/server/src/orchestration-v2/testkit/ClaudeReplayFixtures.integration.test.ts,apps/server/src/orchestration-v2/testkit/OrchestratorReplayFixtures.integration.test.ts. - With
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.tsreverted tobf8ffe81a6, 1 test fails with assertion errors: "ClaudeAdapterV2 background wake turns > fails a /compact the usage limit stopped". vp fmt --checkandvp lintreport no errors and no new warnings on the 2 changed TS files.- Typecheck passes for
t3.
Not run against a live Claude usage limit; the limit case is a frame replay.
Model: Claude Opus 5.5, Claude Fable 5.1 (review), GPT-6-Astra (review). Harness: Claude Code, Codex.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
Approvability#
Verdict: Approved at
e86fb75Macroscope's review found this PR approvable — This is a focused server bug fix that correctly classifies only usage-limited manual
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules)./compactfailures, while preserving existing behavior for automatic, successful, and unrelated compactions. The accompanying replay tests cover the new case and its key controls without introducing schema, deployment, default, or static-analysis changes.No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
-
⚙️ Run configuration
-
- Configuration used: Path: .coderabbit.config.ts
- Review profile: CHILL
- Plan: Advanced
- Run ID:
86a84aae-1b9d-414f-be29-99254ddc2d39
📥 Commits
-
Reviewing files that changed from the base of the PR and between bf8ffe81a63c82d3de5fbaa9991fd5f30034a452 and e86fb7524769a2c58c544a247b8e93f18f0a56b8.
📒 Files selected for processing: 2
-
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.tsapps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
-
📝 Walkthrough
-
The Claude adapter now records compaction failures from status frames. For usage-limited results from local
/compactcommands, it reports acompaction_failedusage-limit error when compaction failed. Tests cover failed and successful manual and automatic compaction scenarios.Changes: Claude compaction handling
Layer / File(s) Summary Track compaction failure
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.tsThe active turn stores an optional compaction error message. Status frames update or clear the recorded failure, and each new turn initializes it to null.Classify compact results
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts,apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.tsWhen compaction failed and a local /compactresult is usage-limited, the adapter returns acompaction_failedusage-limit failure. Tests cover failed and successful manual and automatic compaction outcomes.Priority: ➖ Normal
Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix
Suggested reviewers:
juliusmarminge
Merge Risk: ⚪ Minimal · up to
e86fb-
This change makes a usage-limited /compact fail as intended, so queued messages no longer start against the same limit. No merge-blocking risk was found.
Security architecture risk: ⚪ Minimal · up to
e86fb-
The change restores the existing queue pause after a usage-limited compaction. The reviewed change adds no access or permissions, and no introduced or worsened security issue was identified.
Retained concerns No architecture-level concerns identified.
Security review details
-
Security Blast Radius
- inferred — The changed control effect is confined to the affected thread's run outcome and queued work. The inspected change introduces no additional tool authority, credential access, or cross-thread operation.
Trust Boundaries and Controls
- observed — A failed compaction status alone cannot trigger the new failure branch. The result must identify local compact and satisfy the existing usage-limit checks, which exclude authentication failure and incompatible result reasons. Queue start and explicit queue resume continue to enforce the existing root usage-limit guard.
Resilience and Maintainability Implications
- observed — Interruption retains precedence over compaction-derived failure, and steered abort results retain their continuation path. Centralized terminal cleanup clears active-turn ownership; retained completed contexts support subagent attribution rather than reuse for new-turn result classification.
-
Pre-merge checks:
4-
Passed checks: 4 passed-
Check name Status Explanation Title check The title "fix(server): a /compact stopped by the Claude usage limit now fails" matches the main change. The diff makes a usage-limited /compact end as failed instead of completed, so the queue guard … Description check The description follows the template. It covers Problem, Change, Scope and approval, and Verification. The Problem section gives the reproduction sequence and log evidence. The Change section explains… Linked Issues check Check skipped because no linked issues were found for this pull request. Out of Scope Changes check Check skipped because no linked issues were found for this pull request.
-
✨ Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
-
juliusmarminge merged this499c9ee
juliusmarminge closed this
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes