Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): storage cleanup stops holding usage-limited threads too overdue to auto-resume #35397

Mergedjuliusmarmingemerged 0 commits intomain fromrefs/pull/35397/headmerged by juliusmarminge View on GitHub

juliusmarmingecommented

heldForLimitRecovery in apps/server/src/storageCleanup.ts holds an unarmed usage-limit failure while it expects the recovery worker to arm it on a later tick. It copied one of the worker's skip conditions (a reset that had already passed when the run ended) but not the other: limitRecoveryCommand never arms a failure whose reset is more than MAX_OVERDUE_ARM_MS (24h) overdue. So with autoResumeLimitedThreads on, cleanup held such a thread's worktree forever as pending work. The fix exports MAX_OVERDUE_ARM_MS from UsageLimitRecoveryWorker.ts and adds now - resetMs > MAX_OVERDUE_ARM_MS to the unarmed branch's early return, so cleanup shares the worker's cutoff instead of keeping its own copy. Already-armed recoveries are unchanged. No new regex or parser.

Fixes pingdotgg/t3code#35371

Reproduction on main

On origin/main 4e48d9e6a5, after vp i, I ran the reporter's repro.sh unchanged from the checkout root (env -u NODE_ENV sh repro.sh). It uses the real in-memory SQLite ProjectionStore, real git worktrees, the exported limitRecoveryCommand and StorageCleanup.runNow. Output: STALE {workerCommand:null, cleanup:"kept", reason:"Thread is running or has pending work", worktreeExists:true}; RECOVERY_OFF_CONTROL {cleanup:"removed", reason:"Inactive for 6 days"}; RECENT_CONTROL {workerCommand:"thread.metadata.update", cleanup:"kept"}; SETTLEMENT_CONTROL: auto-settle is null at 6 days and set at 8 days with the default 7, and stays null when it is disabled. So the worker declines to arm a failure whose reset is 5 days overdue, while cleanup keeps holding its worktree as pending work. I also added one row to the existing usage-limit table in apps/server/src/storageCleanup.test.ts: unarmed, autoResumeLimitedThreads on, reset 5 days overdue, expected idle. It fails on main (expected true, got false).

Evidence

Run the real server on each commit with fresh synthetic SQLite projections and a clean linked git worktree. Seed an unarmed usage-limit failure completed six days ago whose reset passed five days ago. Enable auto-resume and snooze, disable auto-settlement, then enable one-day inactive-worktree cleanup and call the production cleanup RPC. Both recovery candidates return no worker command.

Environment on both sides: Linux, Node 26, isolated server on loopback. Captures below are rendered server/RPC transcripts; recordings replay timestamped command output, not browser footage.

BeforeAfter
4e48d9e6a5ef5fbe5f98
Before: cleanup keeps stale worktree as pending workAfter: cleanup removes stale worktree as inactive for six days
Automatic and manual cleanup keep the directory: “Thread is running or has pending work.” Disabling auto-resume releases it in the additional control.The settings-triggered cleanup removes the directory: “Inactive for 6 days.” The subsequent explicit cleanup RPC finds it already removed.
Before recording · Captured outputAfter recording · Captured output

Seed and RPC driver · Recorder · Renderer · Reproduction instructions

AI-assisted; verified with the tests and tools listed above.

Not shown:

  • Live provider usage-limit transitions and multi-day elapsed wall time were not exercised; the production projections were seeded with synthetic historical failure events.
  • The recent-reset and settlement controls from triage were not repeated; this proof covers the stale-reset cleanup defect and the base recovery-off control.
  • Web, desktop, and mobile settings interactions were not captured; verification exercised the real server through its production HTTP and WebSocket interfaces.

Tests

Base (fix stashed): vp test run src/storageCleanup.test.ts -> 1 failed (the repro row 'never armed because its reset is days overdue', expected false to be true), 194 passed. With fix: vp test run src/storageCleanup.test.ts src/orchestration-v2/UsageLimitRecoveryWorker.test.ts -> 200 passed. vp run check:changed -> format, lint, knip, graphql, typecheck (3 packages), tests (3 files) all pass.

AI-assisted; verified with the tests and tools listed above.

    1. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted

    2. Approvability

      Verdict: Approved at ef5fbe5

      Macroscope's review found this PR approvable — Cleanup now uses the recovery worker’s existing 24-hour cutoff instead of indefinitely protecting threads that cannot auto-resume. Existing cleanup policies, local-change checks, and activity safeguards still govern worktree removal.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    3. Thread transfer impact

      ✅ Thread transfer remains within every enforced ceiling.

      ProviderMetricMain baselineThis PRImpactPR ceiling
      CodexTotal thread wire5.0 KiB5.0 KiB0 B (0.0%)6.8 KiB✅
      CodexThread snapshot wire3.8 KiB3.8 KiB0 B (0.0%)4.9 KiB✅
      CodexLive turn WebSocket wire1.2 KiB1.2 KiB0 B (0.0%)2.0 KiB✅
      CodexLive turn WebSocket decoded21.5 KiB21.5 KiB0 B (0.0%)24.4 KiB✅
      CodexLive turn messages110 (0.0%)8✅
      ClaudeTotal thread wire5.0 KiB5.0 KiB0 B (0.0%)6.8 KiB✅
      ClaudeThread snapshot wire3.8 KiB3.8 KiB0 B (0.0%)4.9 KiB✅
      ClaudeLive turn WebSocket wire1.2 KiB1.2 KiB0 B (0.0%)2.0 KiB✅
      ClaudeLive turn WebSocket decoded21.9 KiB21.9 KiB0 B (0.0%)24.4 KiB✅
      ClaudeLive turn messages110 (0.0%)8✅

      Other scenarios

      All 64 scenario measurements match main.

      All 64 scenario measurements
      ProviderScenarioMetricMain baselineThis PRImpactPR ceiling
      Codexshort turn resumeWebSocket decoded10.5 KiB10.5 KiB0 B (0.0%)12.7 KiB✅
      Codexshort turn resumeWebSocket messages220 (0.0%)2✅
      Codexlong turn running, cold openHTTP decoded281.7 KiB281.7 KiB0 B (0.0%)302.7 KiB✅
      Codexlong turn running, cold openrows75750 (0.0%)75✅
      Codexlong turn running, history pageHTTP decoded92.4 KiB92.4 KiB0 B (0.0%)107.4 KiB✅
      Codexlong turn running, history pagerows75750 (0.0%)75✅
      Codexlong turn finished, cold openHTTP decoded381.5 KiB381.5 KiB0 B (0.0%)410.2 KiB✅
      Codexlong turn finished, cold openrows1511510 (0.0%)151✅
      Codexlong turn finished, socket cold openWebSocket decoded381.6 KiB381.6 KiB0 B (0.0%)410.2 KiB✅
      Codexlong turn finished, socket cold openWebSocket messages220 (0.0%)2✅
      Codexlong turn finished, socket cold openrows1511510 (0.0%)151✅
      Codexlong turn finished, work pageHTTP decoded186.2 KiB186.2 KiB0 B (0.0%)200.2 KiB✅
      Codexlong turn finished, work pagerows1501500 (0.0%)150✅
      Codexidle thread resumeWebSocket decoded65 B65 B0 B (0.0%)200 B✅
      Codexidle thread resumeWebSocket messages110 (0.0%)1✅
      Codexfleet shell snapshotHTTP decoded41.6 KiB41.6 KiB0 B (0.0%)53.7 KiB✅
      Codexfleet shell snapshotrows27270 (0.0%)27✅
      Codexfleet shell subscribeWebSocket decoded65 B65 B0 B (0.0%)200 B✅
      Codexfleet shell subscribeWebSocket messages110 (0.0%)1✅
      Codexfleet shell resume checkHTTP decoded18 B18 B0 B (0.0%)100 B✅
      Codexfleet shell resume checkrows0000✅
      Codexstale shell reloadHTTP decoded41.6 KiB41.6 KiB0 B (0.0%)53.7 KiB✅
      Codexstale shell reloadrows27270 (0.0%)27✅
      Codexstale shell resumeWebSocket decoded140 B140 B0 B (0.0%)400 B✅
      Codexstale shell resumeWebSocket messages220 (0.0%)2✅
      Codexstale todo list cold openHTTP decoded72.4 KiB72.4 KiB0 B (0.0%)83.0 KiB✅
      Codexstale todo list cold openrows75750 (0.0%)75✅
      Codexstale todo list cold opennodes220 (0.0%)4✅
      Codexstale todo list cold opensubagents220 (0.0%)4✅
      Codexstale todo list cold openplans110 (0.0%)2✅
      Codexstale todo list cold openproviderTurns110 (0.0%)2✅
      Codexstale todo list cold opencheckpoints110 (0.0%)2✅
      Claudeshort turn resumeWebSocket decoded10.6 KiB10.6 KiB0 B (0.0%)12.7 KiB✅
      Claudeshort turn resumeWebSocket messages220 (0.0%)2✅
      Claudelong turn running, cold openHTTP decoded283.3 KiB283.3 KiB0 B (0.0%)302.7 KiB✅
      Claudelong turn running, cold openrows75750 (0.0%)75✅
      Claudelong turn running, history pageHTTP decoded93.4 KiB93.4 KiB0 B (0.0%)107.4 KiB✅
      Claudelong turn running, history pagerows75750 (0.0%)75✅
      Claudelong turn finished, cold openHTTP decoded384.2 KiB384.2 KiB0 B (0.0%)410.2 KiB✅
      Claudelong turn finished, cold openrows1511510 (0.0%)151✅
      Claudelong turn finished, socket cold openWebSocket decoded384.3 KiB384.3 KiB0 B (0.0%)410.2 KiB✅
      Claudelong turn finished, socket cold openWebSocket messages220 (0.0%)2✅
      Claudelong turn finished, socket cold openrows1511510 (0.0%)151✅
      Claudelong turn finished, work pageHTTP decoded188.1 KiB188.1 KiB0 B (0.0%)200.2 KiB✅
      Claudelong turn finished, work pagerows1501500 (0.0%)150✅
      Claudeidle thread resumeWebSocket decoded66 B66 B0 B (0.0%)200 B✅
      Claudeidle thread resumeWebSocket messages110 (0.0%)1✅
      Claudefleet shell snapshotHTTP decoded42.2 KiB42.2 KiB0 B (0.0%)53.7 KiB✅
      Claudefleet shell snapshotrows27270 (0.0%)27✅
      Claudefleet shell subscribeWebSocket decoded66 B66 B0 B (0.0%)200 B✅
      Claudefleet shell subscribeWebSocket messages110 (0.0%)1✅
      Claudefleet shell resume checkHTTP decoded18 B18 B0 B (0.0%)100 B✅
      Claudefleet shell resume checkrows0000✅
      Claudestale shell reloadHTTP decoded42.2 KiB42.2 KiB0 B (0.0%)53.7 KiB✅
      Claudestale shell reloadrows27270 (0.0%)27✅
      Claudestale shell resumeWebSocket decoded140 B140 B0 B (0.0%)400 B✅
      Claudestale shell resumeWebSocket messages220 (0.0%)2✅
      Claudestale todo list cold openHTTP decoded73.4 KiB73.4 KiB0 B (0.0%)83.0 KiB✅
      Claudestale todo list cold openrows75750 (0.0%)75✅
      Claudestale todo list cold opennodes220 (0.0%)4✅
      Claudestale todo list cold opensubagents220 (0.0%)4✅
      Claudestale todo list cold openplans110 (0.0%)2✅
      Claudestale todo list cold openproviderTurns110 (0.0%)2✅
      Claudestale todo list cold opencheckpoints110 (0.0%)2✅

      Baseline: f99b283 · PR result: ef5fbe5 · Source CI: success

      Scenario and decoded snapshot size

      10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.

      • Codex decoded thread snapshot: 108.5 KiB
      • Claude decoded thread snapshot: 108.8 KiB

      Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.

    4. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Explain Change →

      No actionable comments were generated in the recent review.

      Walkthrough

      Storage cleanup now stops holding failed usage-limit threads for recovery when their reset is more than 24 hours overdue. The recovery threshold is exported for shared use, and an eligibility test covers an unarmed thread with a five-day-overdue reset.

      Changes: Usage-limit cleanup eligibility

      Layer / File(s)Summary
      Apply overdue limit to cleanup holds
      apps/server/src/orchestration-v2/UsageLimitRecoveryWorker.ts, apps/server/src/storageCleanup.ts, apps/server/src/storageCleanup.test.ts
      MAX_OVERDUE_ARM_MS is exported with its 24-hour value unchanged. heldForLimitRecovery uses this limit to reject resets that are more than 24 hours overdue. The eligibility test expects an unarmed thread with a five-day-overdue reset to be idle.

      Estimated code review effort: 2 (Simple) | ~8 minutes

      Change: Bug fix · Severity of issue fixed: Low

      Possibly related PRs

      • pingdotgg/t3code#33737: Changes heldForLimitRecovery to determine whether a usage-limit failure should block cleanup.

      Suggested labels: size:XS, bugfix

      Suggested reviewers: only21mil, maria-rcks, macroscopeapp

      Merge Risk: Minimal · up to ef5fb

      Cleanup stops holding worktrees for usage-limit failures whose reset is more than 24 hours overdue, while recent failures that can still be armed remain protected. No concrete merge-blocking risk was found.

      Pre-merge checks: Passed 4

      Check nameStatusExplanation
      Title checkPassedThe title states the primary change: storage cleanup no longer holds usage-limited threads whose reset is too overdue to auto-resume. The raw summary shows the change in storageCleanup.ts (heldForLimi…
      Linked Issues checkPassed[#35371] Requirement 1, stop holding overdue unarmed failures: The diff at head adds now - resetMs > MAX_OVERDUE_ARM_MS to the unarmed branch's early return in heldForLimitRecovery (apps/server/sr…
      Out of Scope Changes checkPassedThe code changes are limited to three files. storageCleanup.ts adds the import and the overdue condition in the unarmed early return. UsageLimitRecoveryWorker.ts changes only const to export const…
      Description checkPassedThe description follows the repository template closely. It has the Problem, Change, Scope, and Verification content. The Problem section states that heldForLimitRecovery holds an unarmed usage-limit …
      Full details: Title check

      Explanation

      The title states the primary change: storage cleanup no longer holds usage-limited threads whose reset is too overdue to auto-resume. The raw summary shows the change in storageCleanup.ts (heldForLimitRecovery early return) plus exporting MAX_OVERDUE_ARM_MS, which matches the title. The title is specific, follows conventional commit form, and is within a reasonable length. The 91-character length is slightly long but acceptable.

      Full details: Linked Issues check

      Explanation

      [#35371] Requirement 1, stop holding overdue unarmed failures: The diff at head adds now - resetMs > MAX_OVERDUE_ARM_MS to the unarmed branch's early return in heldForLimitRecovery (apps/server/src/storageCleanup.ts). Such a failure now returns false, so cleanup no longer treats its worktree as pending limit recovery. The cutoff is the same 24h value the worker uses, exported from UsageLimitRecoveryWorker.ts. Requirement 2, keep recent failures protected: the early return only fires for non-finite resets, resets at or before run completion, or resets more than 24h overdue. Recent unarmed failures still reach the autoResumeLimitedThreads || snoozeLimitedThreads check and stay held. Armed recoveries are handled by the branch above the changed code and are unchanged. Requirement 3, apply cleanup rules to stale idle worktrees with auto-resume on: the stale thread no longer blocks cleanup, so the configured rules apply. The reporter's repro output on main (cleanup 'kept' with 'Thread is running or has pending work') is consistent with this being the only blocker. The added test row covers the reported case (unarmed, auto-resume on, reset 5 days overdue, expected idle). I did not independently inspect the test file diff; the result relies on the PR description and summary for that row.

      Full details: Out of Scope Changes check

      Explanation

      The code changes are limited to three files. storageCleanup.ts adds the import and the overdue condition in the unarmed early return. UsageLimitRecoveryWorker.ts changes only const to export const for MAX_OVERDUE_ARM_MS, with no value change. storageCleanup.test.ts adds one row to the usage-limit eligibility matrix. Each change supports the objective in #35371. No unrelated refactor, feature, or behavior change appears in the diff. The PR description's pending evidence section is documentation of verification, not a code change, and it does not affect scope.

      Full details: Description check

      Explanation

      The description follows the repository template closely. It has the Problem, Change, Scope, and Verification content. The Problem section states that heldForLimitRecovery holds an unarmed usage-limit failure, and that limitRecoveryCommand never arms a failure whose reset is more than MAX_OVERDUE_ARM_MS (24h) overdue, so cleanup holds the worktree forever when autoResumeLimitedThreads is on. The Change section names the exported constant and the new early-return condition, and it says already-armed recoveries are unchanged. The Scope section links issue #35371 (pingdotgg/t3code#35371) as the bug report. The Verification section gives a reproduction on origin/main with commit hashes, before and after outputs, a new regression row that fails on main, and test commands with results (200 passed). It also lists what was not checked. Minor gaps: the template asks for a conventional commit title, and the description has no title line in the provided text, so the title cannot be checked. The description also contains a large amount of evidence material (links to recordings, driver scripts, and a renderer), which is more than the template requires. The Scope section does not explicitly say why a small fix needs no issue, but an issue is linked, so this does not apply. The Verification section also says it used the production RPC and that the environment was Linux with Node 26, which is specific.

      Finishing Touches

      Generate unit tests (beta)

      • Commit to this branch
      • Create a new PR
      • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
      Recent review info

      Run configuration

      Commits

      Reviewing files that changed from the base of the PR and between f99b2835ef0d18559a59dd954e9f564fcb43e7d3 and ef5fbe5f981055780d591ccb3ed30c5c5e6b5601.

      Files selected for processing: 3

      • apps/server/src/orchestration-v2/UsageLimitRecoveryWorker.ts
      • apps/server/src/storageCleanup.test.ts
      • apps/server/src/storageCleanup.ts

      Limit details: You’ve used all 10 included reviews currently available.

    5. juliusmarminge merged thise96c96e

    6. juliusmarminge closed this

Sign in to join this conversation.