Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): a /compact stopped by the Claude usage limit now fails #19583

MergedScottN-PV(GitHub profile, opens in a new tab)merged 1 commit intomain fromrefs/pull/19583/headmerged by juliusmarminge View on GitHub

Problem

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 /compact that fails for another reason, such as "Not enough messages to compact.", stays completed. A provider_error there 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 new it.effect.each table replays the frames in the reporter's order: the limited /compact ends failed with class usage_limit, the compact_error text and resetAt. Three controls stay completed: a /compact that failed without a limit, a successful /compact under a rejected window, and a limited turn whose automatic compaction failed (no local_command, no terminal reason). The limited case fails with the fix reverted (the turn ends completed). The existing paused-then-completed test still passes.
  • The frame shapes come from a real claude 2.1.300 run on Linux: a /compact sends system/status frames with compact_result, and its result carries local_command: "compact", num_turns: 0 and no terminal_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 root usage_limit error. 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.ts reverted to bf8ffe81a6, 1 test fails with assertion errors: "ClaudeAdapterV2 background wake turns > fails a /compact the usage limit stopped".
  • vp fmt --check and vp lint report 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

    2. Approvability

      Verdict: Approved at e86fb75

      Macroscope's review found this PR approvable — This is a focused server bug fix that correctly classifies only usage-limited manual /compact failures, 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.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    3. Review in Change Stack →

      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.ts
      • apps/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 /compact commands, it reports a compaction_failed usage-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.ts
      The 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.ts
      When compaction failed and a local /compact result is usage-limited, the adapter returns a compaction_failed usage-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: Passed 4
      Passed Passed checks: 4 passed
      Check nameStatusExplanation
      Title checkPassedThe 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 checkPassedThe 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 checkPassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes checkPassedCheck 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
      Comment `@coderabbitai help` to get the list of available commands.
    4. juliusmarminge merged this499c9ee

    5. juliusmarminge closed this

Sign in to join this conversation.