GeezerVison is showing github.com — fix(server): Claude session crons no longer die with the idle session by juliusmarminge · Pull Request #36324 · pingdotgg/t3code
Conversation
Cause: a Claude session cron (CronCreate, /loop) lives only inside the CLI process, and ProviderSessionManager.releaseIfStillIdle closed that process after the 30-minute idle timeout because nothing counted a pending cron as a reason to stay, so a job due later never ran. Fix, rebuilt from origin/main as one commit (the first attempt's branch was not continued): ClaudeAdapterV2 registers an SDK Stop hook, the only place the CLI reports session_crons, and returns { continue: true } so it changes nothing for Claude or for Stop hooks from settings. The count is kept on the live query context (per CLI process) rather than in a per-native-thread map. A new optional ProviderAdapterV2SessionRuntime probe, hasScheduledWork, is true while the live, non-stopping process holds a count above zero; releaseIfStillIdle defers the idle release on it and skips the maxIdlePinMs cap for it, since a scheduled job is silent until it fires. It is separate from hasPendingBackgroundWork, so a cron never blocks a model, mode or provider change. The finding the reviewers could not settle (a stale Stop snapshot pinning an empty process with no cap) is addressed by a two-step count: the Stop hook only writes reported, and the next result frame either adopts it into held (clean success) or sets held to 0 (any error result, such as a 429 after a Stop hook resumed the turn and the cron was deleted). A result with no Stop before it (a task-notification lifecycle result) leaves the count alone. Because the count lives on the process context, an interrupt, close, transport error or query replacement forgets it without separate clearing code, which replaces the earlier attempt's clears in startTurn, finalizeActiveTurnAfterQueryExit and resetBackgroundTaskStateForNativeThreadProcess. Taken from the pull request after checking: the hooks passthrough in makeClaudeQueryOptions, the hasScheduledWork contract field, the ProviderSessionManager change and its test. Tests: one adapter test walks pending cron -> failed turn after a Stop snapshot -> pending again -> none, and asserts the cron does not count as background work; I confirmed it fails ('a failed turn must not hold on the Stop snapshot it outlived: expected true to be false') when the failed-result clear is removed. One ProviderSessionManager test shows scheduled work outliving the pin cap and releasing once it is gone. Known limit: a turn that fails while a cron is still pending drops the hold, so that cron can still be lost at the idle timeout as on main; the Stop hook gives no way to tell that case from a deleted cron. Not verified in the real app this round: the fix was checked with unit tests only, no 30-minute idle run. No open pull request existed for the pushed branch, so nothing was watched.
Supersedes #23636. The change is @juliusmarminge's; their commits are kept.
Reproduction on main
In a Claude thread in the desktop or web app, ask Claude to use CronCreate for a one-shot job about 40 minutes ahead that appends the UTC date to a workspace file. Confirm the job with CronList, then leave the thread idle while keeping the host and T3 server running. After the due time, inspect the file and thread: main releases the otherwise idle session before the deadline and the file remains absent; this change retains the process and the scheduled turn writes the file. These steps were read from the supplied evidence, not executed.
Evidence
Being captured: before and after in the real app. This section is filled in before the pull request can merge.
Tests
vp test run src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts src/orchestration-v2/ProviderSessionManager.test.ts (apps/server): 2 files, 480 tests passed. vp run check:changed: format, lint, knip, graphql, typecheck (27 packages) and test (3 files, 482 tests) all pass. Negative check: with the failed-result clear removed, the new adapter test fails; restored before commit.
Not in this change
- Replacing the Claude process between turns (a model, permission-policy or MCP change that cannot be applied live) still drops session crons silently, as on main; crons deliberately do not block that replacement.
- A turn that ends in a failed result while a cron is still pending drops the idle hold, so that cron can be lost at the idle timeout as on main.
- Crons do not survive a server restart or an explicit session stop; issue [Bug]: /schedule or CronCreate jobs only live inside the Claude process not in a T3code thread #13439's wider ask (jobs that live in the T3 thread rather than the Claude process) is not covered.
- The pull request's hasHooks field in the logged query options and its makeClaudeQueryOptions hooks-merge test were left out: logging noise and callback wiring, not the fix.
- The pull request description is outdated (it describes the 4-hour cap as still applying and the count as kept across failed turns); the pipeline should write the new one from this summary.
Who did the work
- Written by Claude Fable 5.2, in Claude Code
- Reviewed by GPT-6.1 Sol, in Codex, and by Claude Opus 5.5, each on its own
- Proof captured by GPT-6.1 Sol and checked by Claude Opus 5.5
Run by the t3code factory in T3 Code.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
A Claude thread that schedules a session cron (CronCreate, /loop) lost the
job when it was due more than 30 minutes after the thread went idle: the
cron lives only in the CLI process, and the idle release closed it because
nothing counted a pending cron as a reason to stay.
The adapter now registers an SDK Stop hook, the only place the CLI reports
session crons, and holds the count per live process. A new session runtime
probe, hasScheduledWork, defers the idle release while that count is above
zero, without the idle pin cap: a scheduled job is silent until it fires.
A Stop snapshot is adopted only by the clean result that follows it. A Stop
hook from settings can resume the turn, so a turn that then fails (usage
limit, overload) drops the count instead of holding an empty process with
no cap. The count belongs to the process, so an interrupt, a close or a
replacement forgets it too.
Fixes #13439
Co-Authored-By: Claude Fable 5.2 <[email protected]>
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 resume |
WebSocket decoded |
10.5 KiB |
10.5 KiB |
0 B (0.0%) |
12.7 KiB |
✅ |
| Codex |
short turn resume |
WebSocket messages |
2 |
2 |
0 (0.0%) |
2 |
✅ |
| Codex |
long turn running, cold open |
HTTP decoded |
281.7 KiB |
281.7 KiB |
0 B (0.0%) |
302.7 KiB |
✅ |
| Codex |
long turn running, cold open |
rows |
75 |
75 |
0 (0.0%) |
75 |
✅ |
| Codex |
long turn running, history page |
HTTP decoded |
92.4 KiB |
92.4 KiB |
0 B (0.0%) |
107.4 KiB |
✅ |
| Codex |
long turn running, history page |
rows |
75 |
75 |
0 (0.0%) |
75 |
✅ |
| Codex |
long turn finished, cold open |
HTTP decoded |
381.5 KiB |
381.5 KiB |
0 B (0.0%) |
410.2 KiB |
✅ |
| Codex |
long turn finished, cold open |
rows |
151 |
151 |
0 (0.0%) |
151 |
✅ |
| Codex |
long turn finished, socket cold open |
WebSocket decoded |
381.6 KiB |
381.6 KiB |
0 B (0.0%) |
410.2 KiB |
✅ |
| Codex |
long turn finished, socket cold open |
WebSocket messages |
2 |
2 |
0 (0.0%) |
2 |
✅ |
| Codex |
long turn finished, socket cold open |
rows |
151 |
151 |
0 (0.0%) |
151 |
✅ |
| Codex |
long turn finished, work page |
HTTP decoded |
186.2 KiB |
186.2 KiB |
0 B (0.0%) |
200.2 KiB |
✅ |
| Codex |
long turn finished, work page |
rows |
150 |
150 |
0 (0.0%) |
150 |
✅ |
| Codex |
idle thread resume |
WebSocket decoded |
65 B |
65 B |
0 B (0.0%) |
200 B |
✅ |
| Codex |
idle thread resume |
WebSocket messages |
1 |
1 |
0 (0.0%) |
1 |
✅ |
| Codex |
fleet shell snapshot |
HTTP decoded |
42.4 KiB |
42.4 KiB |
0 B (0.0%) |
53.7 KiB |
✅ |
| Codex |
fleet shell snapshot |
rows |
27 |
27 |
0 (0.0%) |
27 |
✅ |
| Codex |
fleet shell subscribe |
WebSocket decoded |
65 B |
65 B |
0 B (0.0%) |
200 B |
✅ |
| Codex |
fleet shell subscribe |
WebSocket messages |
1 |
1 |
0 (0.0%) |
1 |
✅ |
| Codex |
fleet shell resume check |
HTTP decoded |
18 B |
18 B |
0 B (0.0%) |
100 B |
✅ |
| Codex |
fleet shell resume check |
rows |
0 |
0 |
0 |
0 |
✅ |
| Codex |
stale shell reload |
HTTP decoded |
42.4 KiB |
42.4 KiB |
0 B (0.0%) |
53.7 KiB |
✅ |
| Codex |
stale shell reload |
rows |
27 |
27 |
0 (0.0%) |
27 |
✅ |
| Codex |
stale shell resume |
WebSocket decoded |
140 B |
140 B |
0 B (0.0%) |
400 B |
✅ |
| Codex |
stale shell resume |
WebSocket messages |
2 |
2 |
0 (0.0%) |
2 |
✅ |
| Codex |
stale todo list cold open |
HTTP decoded |
72.4 KiB |
72.4 KiB |
0 B (0.0%) |
83.0 KiB |
✅ |
| Codex |
stale todo list cold open |
rows |
75 |
75 |
0 (0.0%) |
75 |
✅ |
| Codex |
stale todo list cold open |
nodes |
2 |
2 |
0 (0.0%) |
4 |
✅ |
| Codex |
stale todo list cold open |
subagents |
2 |
2 |
0 (0.0%) |
4 |
✅ |
| Codex |
stale todo list cold open |
plans |
1 |
1 |
0 (0.0%) |
2 |
✅ |
| Codex |
stale todo list cold open |
providerTurns |
1 |
1 |
0 (0.0%) |
2 |
✅ |
| Codex |
stale todo list cold open |
checkpoints |
1 |
1 |
0 (0.0%) |
2 |
✅ |
| Claude |
short turn resume |
WebSocket decoded |
10.6 KiB |
10.6 KiB |
0 B (0.0%) |
12.7 KiB |
✅ |
| Claude |
short turn resume |
WebSocket messages |
2 |
2 |
0 (0.0%) |
2 |
✅ |
| Claude |
long turn running, cold open |
HTTP decoded |
283.3 KiB |
283.3 KiB |
0 B (0.0%) |
302.7 KiB |
✅ |
| Claude |
long turn running, cold open |
rows |
75 |
75 |
0 (0.0%) |
75 |
✅ |
| Claude |
long turn running, history page |
HTTP decoded |
93.4 KiB |
93.4 KiB |
0 B (0.0%) |
107.4 KiB |
✅ |
| Claude |
long turn running, history page |
rows |
75 |
75 |
0 (0.0%) |
75 |
✅ |
| Claude |
long turn finished, cold open |
HTTP decoded |
384.2 KiB |
384.2 KiB |
0 B (0.0%) |
410.2 KiB |
✅ |
| Claude |
long turn finished, cold open |
rows |
151 |
151 |
0 (0.0%) |
151 |
✅ |
| Claude |
long turn finished, socket cold open |
WebSocket decoded |
384.3 KiB |
384.3 KiB |
0 B (0.0%) |
410.2 KiB |
✅ |
| Claude |
long turn finished, socket cold open |
WebSocket messages |
2 |
2 |
0 (0.0%) |
2 |
✅ |
| Claude |
long turn finished, socket cold open |
rows |
151 |
151 |
0 (0.0%) |
151 |
✅ |
| Claude |
long turn finished, work page |
HTTP decoded |
188.1 KiB |
188.1 KiB |
0 B (0.0%) |
200.2 KiB |
✅ |
| Claude |
long turn finished, work page |
rows |
150 |
150 |
0 (0.0%) |
150 |
✅ |
| Claude |
idle thread resume |
WebSocket decoded |
66 B |
66 B |
0 B (0.0%) |
200 B |
✅ |
| Claude |
idle thread resume |
WebSocket messages |
1 |
1 |
0 (0.0%) |
1 |
✅ |
| Claude |
fleet shell snapshot |
HTTP decoded |
43.0 KiB |
43.0 KiB |
0 B (0.0%) |
53.7 KiB |
✅ |
| Claude |
fleet shell snapshot |
rows |
27 |
27 |
0 (0.0%) |
27 |
✅ |
| Claude |
fleet shell subscribe |
WebSocket decoded |
66 B |
66 B |
0 B (0.0%) |
200 B |
✅ |
| Claude |
fleet shell subscribe |
WebSocket messages |
1 |
1 |
0 (0.0%) |
1 |
✅ |
| Claude |
fleet shell resume check |
HTTP decoded |
18 B |
18 B |
0 B (0.0%) |
100 B |
✅ |
| Claude |
fleet shell resume check |
rows |
0 |
0 |
0 |
0 |
✅ |
| Claude |
stale shell reload |
HTTP decoded |
43.0 KiB |
43.0 KiB |
0 B (0.0%) |
53.7 KiB |
✅ |
| Claude |
stale shell reload |
rows |
27 |
27 |
0 (0.0%) |
27 |
✅ |
| Claude |
stale shell resume |
WebSocket decoded |
140 B |
140 B |
0 B (0.0%) |
400 B |
✅ |
| Claude |
stale shell resume |
WebSocket messages |
2 |
2 |
0 (0.0%) |
2 |
✅ |
| Claude |
stale todo list cold open |
HTTP decoded |
73.4 KiB |
73.4 KiB |
0 B (0.0%) |
83.0 KiB |
✅ |
| Claude |
stale todo list cold open |
rows |
75 |
75 |
0 (0.0%) |
75 |
✅ |
| Claude |
stale todo list cold open |
nodes |
2 |
2 |
0 (0.0%) |
4 |
✅ |
| Claude |
stale todo list cold open |
subagents |
2 |
2 |
0 (0.0%) |
4 |
✅ |
| Claude |
stale todo list cold open |
plans |
1 |
1 |
0 (0.0%) |
2 |
✅ |
| Claude |
stale todo list cold open |
providerTurns |
1 |
1 |
0 (0.0%) |
2 |
✅ |
| Claude |
stale todo list cold open |
checkpoints |
1 |
1 |
0 (0.0%) |
2 |
✅ |
Baseline: c83e78f · PR result: 3df76b4 · 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.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Approvability
Verdict: Approved at 3df76b4
Macroscope's review found this PR approvable — Keeps Claude sessions alive while explicitly scheduled crons remain, preventing idle cleanup from killing those jobs. Sessions without scheduled work retain existing idle behavior, and explicit release remains available.
You can add or adjust custom eligibility rules. Learn more.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
The automated pipeline stopped on this pull request and will not merge it:
the fix is written and reviewed, but proving it needs something no worker has:
- Permanent blocker: the manual reproduction needs an available real Claude account/session supporting CronCreate and Stop-hook session_crons; the VM brief lists first-party Claude OAuth as unavailable. Replay uses generic ACP and cannot substitute for this provider-specific behavior.
- Pending-cron retention through the idle deadline, scheduled file creation, and normal idle cleanup after cancellation remain unverified on both commits.
It stays open for a person to finish or close.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|

No actionable comments were generated in the recent review.
Walkthrough
-
The Claude adapter tracks cron jobs reported by Stop hooks and exposes scheduled work through the provider runtime. The provider session manager uses that state to keep idle sessions pinned beyond the configured cap.
Changes: Scheduled work lifecycle
| Layer / File(s) |
Summary |
Track and expose scheduled cron work packages/provider-core/src/server/ProviderAdapter.ts, apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts, apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts |
The provider runtime adds an optional hasScheduledWork effect. The Claude adapter records cron counts from Stop hooks, retains counts after successful results, and clears them after errors. Tests cover clean, failed, and empty-cron turns. |
Keep idle sessions pinned for scheduled work apps/server/src/orchestration-v2/ProviderSessionManager.ts, apps/server/src/orchestration-v2/ProviderSessionManager.test.ts |
Idle checks now probe scheduled work. Sessions remain pinned while scheduled work exists, regardless of the idle-pin cap. The test verifies the session expires after scheduled work ends and another idle interval passes. |
Estimated code review effort: 3 (Moderate) | ~20 minutes
Change: Bug fix
Sequence Diagram(s)
sequenceDiagram
participant ClaudeAdapterV2
participant ProviderAdapterV2SessionRuntime
participant ProviderSessionManager
ClaudeAdapterV2->>ProviderAdapterV2SessionRuntime: Exposes hasScheduledWork
ProviderSessionManager->>ProviderAdapterV2SessionRuntime: Probes hasScheduledWork
ProviderAdapterV2SessionRuntime-->>ProviderSessionManager: Returns scheduled-work state
ProviderSessionManager->>ProviderSessionManager: Keeps the session pinned when scheduled work exists
Loading
Suggested reviewers: t3dotgg, yash-singh1, shivamhwp
Merge Risk: Minimal · up to 3df76
-
This change keeps Claude sessions with pending scheduled crons from being released while idle, without affecting model, mode or provider switches. No concrete defect was established. One narrow ordering edge case, in which a failed turn followed immediately by a queued turn could drop the cron hold, could not be checked against the SDK. Real-app behavior was also not exercised. The merge risk is minimal.
Pre-merge checks: 4
-
| Check name |
Status |
Explanation |
| Title check |
 |
The title names the main change: Claude session crons no longer end when the idle session is released. It follows the conventional commit form and matches the objectives, which describe the hasSchedul… |
| Description check |
 |
The description covers the problem, the change, scope (it links the superseded PR and issue #13439, and a bug-fix scope), and verification (named tests, a negative check, and the limits). It follows t… |
| 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. |
Full details: Title check
-
Explanation
The title names the main change: Claude session crons no longer end when the idle session is released. It follows the conventional commit form and matches the objectives, which describe the hasScheduledWork probe and the defer-on-cron release logic.
Full details: Description check
-
Explanation
The description covers the problem, the change, scope (it links the superseded PR and issue #13439, and a bug-fix scope), and verification (named tests, a negative check, and the limits). It follows the template's sections. The Evidence section is a placeholder that says it will be filled before merge, and the description admits it is outdated in one place. These gaps need fixing before merge, but the description is mostly complete.
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
Usage-based review receipt
Note This review was completed with usage-based billing: files reviewed beyond your plan's included limits are billed at $0.25/file. View usage-based billing.
Recent review info
-
Run configuration
-
Commits
-
Reviewing files that changed from the base of the PR and between c83e78f and 3df76b4.
Files selected for processing: 5
-
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts
apps/server/src/orchestration-v2/ProviderSessionManager.test.ts
apps/server/src/orchestration-v2/ProviderSessionManager.ts
packages/provider-core/src/server/ProviderAdapter.ts
Limit details: You’ve used all 10 included reviews currently available.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This branch has not been deployed
No deployments
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Labels
size:M
30-99 changed lines (additions + deletions).
vouch:trusted
Author is trusted by repo permissions or the VOUCHED list.
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|