fix(server): storage cleanup stops holding usage-limited threads too overdue to auto-resume #35397
main fromrefs/pull/35397/head·merged by juliusmarminge View on GitHubheldForLimitRecovery 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.
| Before | After |
|---|---|
| 4e48d9e6a5 | ef5fbe5f98 |
![]() | ![]() |
| 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 output | After 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
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XS
Approvability#
Verdict: Approved at
ef5fbe5Macroscope'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).Thread transfer impact#
✅ Thread transfer remains within every enforced ceiling.
Provider Metric Main baseline This PR Impact PR ceiling Codex Total thread wire 5.0 KiB 5.0 KiB 0 B (0.0%) 6.8 KiB ✅ Codex Thread snapshot wire 3.8 KiB 3.8 KiB 0 B (0.0%) 4.9 KiB ✅ Codex Live turn WebSocket wire 1.2 KiB 1.2 KiB 0 B (0.0%) 2.0 KiB ✅ Codex Live turn WebSocket decoded 21.5 KiB 21.5 KiB 0 B (0.0%) 24.4 KiB ✅ Codex Live turn messages 1 1 0 (0.0%) 8 ✅ Claude Total thread wire 5.0 KiB 5.0 KiB 0 B (0.0%) 6.8 KiB ✅ Claude Thread snapshot wire 3.8 KiB 3.8 KiB 0 B (0.0%) 4.9 KiB ✅ Claude Live turn WebSocket wire 1.2 KiB 1.2 KiB 0 B (0.0%) 2.0 KiB ✅ Claude Live turn WebSocket decoded 21.9 KiB 21.9 KiB 0 B (0.0%) 24.4 KiB ✅ Claude Live turn messages 1 1 0 (0.0%) 8 ✅ Other scenarios#
All 64 scenario measurements match
main.All 64 scenario measurements
Provider Scenario Metric Main baseline This PR Impact PR ceiling Codex short turn resumeWebSocket decoded10.5 KiB 10.5 KiB 0 B (0.0%) 12.7 KiB ✅ Codex short turn resumeWebSocket messages2 2 0 (0.0%) 2 ✅ Codex long turn running, cold openHTTP decoded281.7 KiB 281.7 KiB 0 B (0.0%) 302.7 KiB ✅ Codex long turn running, cold openrows75 75 0 (0.0%) 75 ✅ Codex long turn running, history pageHTTP decoded92.4 KiB 92.4 KiB 0 B (0.0%) 107.4 KiB ✅ Codex long turn running, history pagerows75 75 0 (0.0%) 75 ✅ Codex long turn finished, cold openHTTP decoded381.5 KiB 381.5 KiB 0 B (0.0%) 410.2 KiB ✅ Codex long turn finished, cold openrows151 151 0 (0.0%) 151 ✅ Codex long turn finished, socket cold openWebSocket decoded381.6 KiB 381.6 KiB 0 B (0.0%) 410.2 KiB ✅ Codex long turn finished, socket cold openWebSocket messages2 2 0 (0.0%) 2 ✅ Codex long turn finished, socket cold openrows151 151 0 (0.0%) 151 ✅ Codex long turn finished, work pageHTTP decoded186.2 KiB 186.2 KiB 0 B (0.0%) 200.2 KiB ✅ Codex long turn finished, work pagerows150 150 0 (0.0%) 150 ✅ Codex idle thread resumeWebSocket decoded65 B 65 B 0 B (0.0%) 200 B ✅ Codex idle thread resumeWebSocket messages1 1 0 (0.0%) 1 ✅ Codex fleet shell snapshotHTTP decoded41.6 KiB 41.6 KiB 0 B (0.0%) 53.7 KiB ✅ Codex fleet shell snapshotrows27 27 0 (0.0%) 27 ✅ Codex fleet shell subscribeWebSocket decoded65 B 65 B 0 B (0.0%) 200 B ✅ Codex fleet shell subscribeWebSocket messages1 1 0 (0.0%) 1 ✅ Codex fleet shell resume checkHTTP decoded18 B 18 B 0 B (0.0%) 100 B ✅ Codex fleet shell resume checkrows0 0 0 0 ✅ Codex stale shell reloadHTTP decoded41.6 KiB 41.6 KiB 0 B (0.0%) 53.7 KiB ✅ Codex stale shell reloadrows27 27 0 (0.0%) 27 ✅ Codex stale shell resumeWebSocket decoded140 B 140 B 0 B (0.0%) 400 B ✅ Codex stale shell resumeWebSocket messages2 2 0 (0.0%) 2 ✅ Codex stale todo list cold openHTTP decoded72.4 KiB 72.4 KiB 0 B (0.0%) 83.0 KiB ✅ Codex stale todo list cold openrows75 75 0 (0.0%) 75 ✅ Codex stale todo list cold opennodes2 2 0 (0.0%) 4 ✅ Codex stale todo list cold opensubagents2 2 0 (0.0%) 4 ✅ Codex stale todo list cold openplans1 1 0 (0.0%) 2 ✅ Codex stale todo list cold openproviderTurns1 1 0 (0.0%) 2 ✅ Codex stale todo list cold opencheckpoints1 1 0 (0.0%) 2 ✅ Claude short turn resumeWebSocket decoded10.6 KiB 10.6 KiB 0 B (0.0%) 12.7 KiB ✅ Claude short turn resumeWebSocket messages2 2 0 (0.0%) 2 ✅ Claude long turn running, cold openHTTP decoded283.3 KiB 283.3 KiB 0 B (0.0%) 302.7 KiB ✅ Claude long turn running, cold openrows75 75 0 (0.0%) 75 ✅ Claude long turn running, history pageHTTP decoded93.4 KiB 93.4 KiB 0 B (0.0%) 107.4 KiB ✅ Claude long turn running, history pagerows75 75 0 (0.0%) 75 ✅ Claude long turn finished, cold openHTTP decoded384.2 KiB 384.2 KiB 0 B (0.0%) 410.2 KiB ✅ Claude long turn finished, cold openrows151 151 0 (0.0%) 151 ✅ Claude long turn finished, socket cold openWebSocket decoded384.3 KiB 384.3 KiB 0 B (0.0%) 410.2 KiB ✅ Claude long turn finished, socket cold openWebSocket messages2 2 0 (0.0%) 2 ✅ Claude long turn finished, socket cold openrows151 151 0 (0.0%) 151 ✅ Claude long turn finished, work pageHTTP decoded188.1 KiB 188.1 KiB 0 B (0.0%) 200.2 KiB ✅ Claude long turn finished, work pagerows150 150 0 (0.0%) 150 ✅ Claude idle thread resumeWebSocket decoded66 B 66 B 0 B (0.0%) 200 B ✅ Claude idle thread resumeWebSocket messages1 1 0 (0.0%) 1 ✅ Claude fleet shell snapshotHTTP decoded42.2 KiB 42.2 KiB 0 B (0.0%) 53.7 KiB ✅ Claude fleet shell snapshotrows27 27 0 (0.0%) 27 ✅ Claude fleet shell subscribeWebSocket decoded66 B 66 B 0 B (0.0%) 200 B ✅ Claude fleet shell subscribeWebSocket messages1 1 0 (0.0%) 1 ✅ Claude fleet shell resume checkHTTP decoded18 B 18 B 0 B (0.0%) 100 B ✅ Claude fleet shell resume checkrows0 0 0 0 ✅ Claude stale shell reloadHTTP decoded42.2 KiB 42.2 KiB 0 B (0.0%) 53.7 KiB ✅ Claude stale shell reloadrows27 27 0 (0.0%) 27 ✅ Claude stale shell resumeWebSocket decoded140 B 140 B 0 B (0.0%) 400 B ✅ Claude stale shell resumeWebSocket messages2 2 0 (0.0%) 2 ✅ Claude stale todo list cold openHTTP decoded73.4 KiB 73.4 KiB 0 B (0.0%) 83.0 KiB ✅ Claude stale todo list cold openrows75 75 0 (0.0%) 75 ✅ Claude stale todo list cold opennodes2 2 0 (0.0%) 4 ✅ Claude stale todo list cold opensubagents2 2 0 (0.0%) 4 ✅ Claude stale todo list cold openplans1 1 0 (0.0%) 2 ✅ Claude stale todo list cold openproviderTurns1 1 0 (0.0%) 2 ✅ Claude stale todo list cold opencheckpoints1 1 0 (0.0%) 2 ✅ Baseline:
f99b283· PR result:ef5fbe5· Source CI: successScenario 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.
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.tsMAX_OVERDUE_ARM_MSis exported with its 24-hour value unchanged.heldForLimitRecoveryuses 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
heldForLimitRecoveryto determine whether a usage-limit failure should block cleanup.
Suggested labels:
size:XS,bugfixSuggested reviewers:
only21mil,maria-rcks,macroscopeapp - pingdotgg/t3code#33737: Changes
Merge Risk:
Minimal · up toef5fb-
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:
4-
Check name Status Explanation Title check 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 (heldForLimi… Linked Issues check [ #35371] Requirement 1, stop holding overdue unarmed failures: The diff at head addsnow - resetMs > MAX_OVERDUE_ARM_MSto the unarmed branch's early return inheldForLimitRecovery(apps/server/sr…Out of Scope Changes check 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 consttoexport const…Description check 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 … 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 addsnow - resetMs > MAX_OVERDUE_ARM_MSto the unarmed branch's early return inheldForLimitRecovery(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 theautoResumeLimitedThreads || snoozeLimitedThreadscheck 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
consttoexport constfor 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-
- Source mode: Auto
- Repository: pingdotgg/t3code
- Branch: factory/issue-35371
- File: .coderabbit.config.ts
- Commit: ef5fbe5
- Layers: Repository TS config
- Review profile: CHILL
- Plan: Team
- Run ID:
225adbf7-a1ba-4970-b942-1552c3267fa3
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.tsapps/server/src/storageCleanup.test.tsapps/server/src/storageCleanup.ts
Limit details: You’ve used all 10 included reviews currently available.
-
-
juliusmarminge merged thise96c96e
juliusmarminge closed this
Sign in to join this conversation.


macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes