GeezerVison is showing github.com — fix(server): release a finished delegated child's provider session at once by Pyseph · Pull Request #31466 · pingdotgg/t3code
Conversation
Pyseph
commented
Nov 5, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
Problem
A delegate_task child thread usually runs once and is never settled, but its provider session stays alive for the full 30 minute idle timeout (DEFAULT_IDLE_TIMEOUT_MS, ProviderSessionManager.ts). For Claude that session is one claude process plus all of the user's MCP servers (supportsMultipleProviderThreadsPerSession: false). Delegate-heavy workflows therefore keep one idle process tree per delegate started in the last 30 minutes. Reported in #26413 (18 claude.exe trees on a 16 GB machine, 12 of them finished delegates, about 5 GB freed by killing them); #30148 reports the same standing cost for ordinary open threads, which this PR does not change.
Scale on one Windows PC (11-12 live Claude sessions under T3 Code, two samples 17 minutes apart): each session costs about 0.86-0.94 GB (claude.exe 650-750 MB plus about 180 MB of MCP children, up to about 1.1 GB for older sessions or heavier MCP sets); 9 of 11 sessions used under 0.5 s CPU per 30 s. Idle sessions do not shrink, and the larger ones are the longest-lived.
Change
When a delegated child's run completes and its result is recorded for the parent (finalizeAppOwnedSubagentTask, same transaction as the result events), the Orchestrator queues a new outbox effect, provider-session.release-finished-delegate, on the child thread. Only a completed outcome queues it (not failed, cancelled or interrupted runs). The effect calls a new ProviderSessionManager.releaseFinishedDelegate, which releases the child's session only if all of these hold when it runs:
- the session is a one-process-per-thread session attached to this thread only (shared Codex-style processes keep their own per-thread unload);
- the thread is a
subagent child and delegatedTaskProgress reports result_available: no active or queued run, held or not, no running subagent, no pending completion delivery, no background task holding completion;
- no turn is busy and the adapter's
hasPendingBackgroundWork is false (this covers buffered wake messages and running native subagents);
- no activity since the check began (
onlyIfIdleGeneration, the same guard the idle timer uses), and the session is still the one that was checked (onlyIfRuntime: a session opened meanwhile reuses the id and restarts the generation count).
If any check fails or the thread cannot be read, nothing happens and the normal 30 minute timer still applies. A release that fails is logged rather than retried, because the live entry is already gone, retryReleaseRecords owns the record, and a retrying effect would hold up the child's later effects. The release uses the existing releaseEntry path with reason idle_timeout, so session records, MCP credential cleanup and metrics are unchanged. A message to the child afterwards (the parent's follow-up, or the user) opens a new session through the same path as after any idle release. The 30 minute default for ordinary threads and the 4 hour background-work pin are untouched.
The effect is process-bound (listed in PROCESS_BOUND_EFFECT_TYPES): after a server restart there is no session left to release, so a pending one is cancelled rather than replayed.
Behaviour differences, stated plainly:
- A finished delegate's process is gone within milliseconds of the result being recorded instead of 30 minutes later. A follow-up to the same child within those 30 minutes now pays a session start (spawn, MCP registration, transcript resume) where it used to reuse the warm process.
- Failed, cancelled and interrupted delegates keep the 30 minute behaviour.
- New outbox effect type in the persisted schema (older builds cannot decode a pending row of this type after a downgrade).
- This does not address feat(server): make idle agent release configurable #25624 (a configurable idle timeout); the two compose.
Scope and approval
#26413 isn't triaged, and I'm not claiming the "very small, focused fix" exception: this changes lifecycle behaviour, because a warm session is dropped earlier, and it adds an outbox effect type. On 2026-11-04 I commented on the issue with the measured cost and this branch, and asked which direction you'd want. There's no maintainer reply yet, so I'm opening the PR so the direction can be judged on the code. The alternatives are a shorter idle timeout for delegate threads only, or relying on #25624, and if you prefer one of those I'm happy to close this or adapt it.
Related: #26413, #30148 (ordinary threads, not addressed), #25624 (open PR, configurable timeout), #16917 (Codex per-thread unload), #15173 (a parent released while waiting on a delegate; this change only touches finished children).
Verification
Measurement notes: https://gist.github.com/Pyseph/3a6801b14d2909a7ba8b01aab9173cf0
Run with Node 26.12.1 on Windows 11:
ProviderSessionManager.test.ts, DelegatedCompletionDelivery.test.ts, EffectWorker.test.ts, ThreadManagementService.test.ts, ProviderTurnControlService.test.ts, FoundationPersistence.test.ts, ThreadStop.test.ts: 212 tests pass. Delegate-related integration files (Orchestrator.control-reads, RemoteDelegatedTask, ClaudeAutomaticDelivery.integration, BackgroundWorkStop.integration, SubagentProjection): 44 pass. Server tsc --noEmit, vp lint and vp fmt --check on the changed files are clean. At the current head, with the last two guards in: ProviderSessionManager.test.ts, DelegatedCompletionDelivery.test.ts, EffectWorker.test.ts, ProviderRuntimeRecoveryService.test.ts, 127 tests pass, and the server typecheck is clean.
- New tests: a finished delegated child's session is released with no clock advance (60 minute idle timeout configured), its projected status is
stopped, and a follow-up open starts a second session; the session is kept for an ordinary thread, a delegate whose run is still running, a delegate with a queued follow-up, a delegate with a held follow-up, and a delegate with pending background work; a session opened under the same id while the checks run is left alone; in the orchestrator suite a completed child queues the effect and a cancelled child does not.
- On main (source changes stashed, tests kept) the release test and the orchestrator test fail (
releaseFinishedDelegate is not a function; no effect row). The "keeps" tests also fail there, but only because the method does not exist, so on main they show nothing about the kept cases. The held follow-up and replacement tests each failed on this branch before their fixes, so those two do show their case.
- Measurement with the manager's fake provider, where each fake session spawns a real idle
node process as a stand-in for claude.exe (about 51 MB each, so absolute memory is not Claude's), 6 delegated sessions with completed runs, 10 runs per variant (2 invocations x 5 reps, alternating main and branch):
- main: 6 of 6 processes alive 1.5 s after the runs complete (10 of 10 runs, about 306 MB total); alive until the idle timer, verified on the virtual clock: 6 alive at 29:59, 0 at 30:00.
- branch: 6 alive before; 0 alive after
releaseFinishedDelegate, median 20.5 ms (min 11, max 30) from the call until all 6 processes exited; about 304 MB released.
- At this PC's 0.86-0.94 GB per Claude session, the same 6 finished delegates would hold about 5.2-5.6 GB for up to 30 minutes on main.
- Not measured: the real Claude adapter and a real
delegate_task run end to end, outbox worker latency between the result being recorded and the effect running, and any wall-clock cost of the next follow-up's session start (spawn plus MCP registration, up to the 90 s registration timeout).
Claude Sonnet 5.5 in T3 Code (Claude Code harness).
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
… once
A delegate_task child usually runs once and is never settled, yet its provider session (one claude process plus its MCP servers) stays up for the 30 minute idle timeout. When a delegated child's run completes and its result is recorded, queue an effect that releases the child's one-process-per-thread session if nothing can resume it: no run or queued follow-up, no subagent or background task, no pending wake message. A later message to the child opens a new session as usual. The idle timeout for other threads is unchanged.
Approvability
Verdict: Approved at 5e79b4b
Macroscope's review found this PR approvable — Completed delegated children release their dedicated provider sessions sooner instead of waiting for the idle timeout. Completion and activity guards preserve sessions that still have work, while shared processes are excluded.
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.
A pending provider-session.release-finished-delegate is cancelled after a restart, like the other process-bound effects, so the pinned list includes it.
coderabbitai
Bot
commented
Nov 5, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
|

Note
Reviews paused
It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.
Use the following commands to manage reviews:
@coderabbitai resume to resume automatic reviews.
@coderabbitai review to trigger a single review.
Use the checkboxes below for quick actions:
- Resume reviews
- Trigger review
No actionable comments were generated in the recent review.
Walkthrough
-
Completed delegated child runs now enqueue a provider-session release effect. The effect worker calls the provider session manager, which checks delegated-task state and remaining work before releasing an eligible session.
Changes: Delegated session release
| Layer / File(s) |
Summary |
Release eligibility and session handling apps/server/src/orchestration-v2/ProviderSessionManager.ts, apps/server/src/orchestration-v2/ProviderSessionManager.test.ts |
The manager adds releaseFinishedDelegate. It checks delegation status, run activity, pending background work, and session attachment before release. Tests cover eligible release, conditions that prevent release, and a replacement session opened during release. |
Queue and execute release effects apps/server/src/orchestration-v2/EffectOutbox.ts, apps/server/src/orchestration-v2/Orchestrator.ts, apps/server/src/orchestration-v2/EffectWorker.ts, apps/server/src/orchestration-v2/DelegatedCompletionDelivery.test.ts, apps/server/src/orchestration-v2/ProviderRuntimeRecoveryService.test.ts, apps/server/src/orchestration-v2/EffectWorker.test.ts, apps/server/src/orchestration-v2/ProviderTurnControlService.test.ts, apps/server/src/orchestration-v2/ThreadManagementService.test.ts |
Completed child runs enqueue a release effect; other terminal outcomes do not. The worker calls the manager and wraps failures as effect execution errors. Recovery tests check effect queuing and cancellation. Test doubles implement the new manager operation. |
Estimated code review effort: 3 (Moderate) | ~25 minutes
Change: Bug fix
Sequence Diagram(s)
sequenceDiagram
participant Orchestrator
participant EffectOutbox
participant EffectWorker
participant ProviderSessionManager
Orchestrator->>EffectOutbox: Queue release effect for completed child
EffectWorker->>ProviderSessionManager: Release finished delegate session
Loading
Possibly related issues
- pingdotgg/t3code#26413 — Reports that completed Claude delegate children keep their provider processes for 30 minutes. This change queues release after a completed delegated run when release conditions hold.
Suggested reviewers: juliusmarminge, t3dotgg
Merge Risk: Low · previous review 407dd
-
A follow-up queued at the same time as release may need to reopen its provider session. This is a bounded overhead risk rather than a demonstrated loss of work, so the change is mergeable with owner awareness.
Pre-merge checks: 4
-
| Check name |
Status |
Explanation |
| Title check |
 |
The title "fix(server): release a finished delegated child's provider session at once" follows the conventional commit format and names the main change. The changeset adds a releaseFinishedDelegate … |
| Description check |
 |
The description follows the repository template's sections: Problem, Change, Scope and approval, and Verification. The Problem section states the cause and gives a reproduction and measurement (#26413… |
| 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 "fix(server): release a finished delegated child's provider session at once" follows the conventional commit format and names the main change. The changeset adds a releaseFinishedDelegate path that releases a completed delegate's provider session when its result is recorded, instead of waiting for the 30-minute idle timeout. The title is specific and accurate, so it passes.
Full details: Description check
-
Explanation
The description follows the repository template's sections: Problem, Change, Scope and approval, and Verification. The Problem section states the cause and gives a reproduction and measurement (#26413, per-session memory cost). The Change section explains the outbox effect, the release guards, and the behaviour differences. Scope and approval explains why the 'very small, focused fix' exception does not apply, and links the related issues. Verification lists the test files run, the new tests, a before/after comparison on main, and the items not measured. The description is thorough and complete, so it passes. The template's trailing agent-model line is present ("Claude Sonnet 5.5 in T3 Code"), and the description does not contain a formal template comment block, which is acceptable.
Finishing Touches
-
Generate unit tests (beta)
-
- 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 93af514 and 407ddf0.
Files selected for processing: 2
-
apps/server/src/orchestration-v2/ProviderSessionManager.test.ts
apps/server/src/orchestration-v2/ProviderSessionManager.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
… effects
The release runs as an outbox effect on the child thread, and a pending effect blocks later effects on that thread, so a failed release made a follow-up wait for the retry of an optional cleanup. The retry can't help either: the live entry is already gone and retryReleaseRecords owns the record. Log and swallow the failure, like the other release paths.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
delegatedTaskProgress ignores held queued runs, which is right for its own purpose, but a held follow-up still needs this session when its queue resumes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
…alone
The checks yield, and a session opened meanwhile takes the same id and restarts the idle generation, so the generation alone can match a session the checks never looked at. Match the runtime as well.
|
Strong +1 from us. We rely heavily on delegate_task. On 9 Nov 2026, claude.exe processes under one nightly t3.exe grew from 23 (10.51 GiB) to 37 (16.43 GiB) in about two hours, and new processes kept appearing throughout. Releasing finished children straight away is the right default, and it probably covers a large share of that growth. It doesn't apply to long-running parent or recurring threads that never finish, which is why we've separately proposed an optional concurrent-session cap as a backstop: #33413
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
AI-assisted; verified with the tests and tools listed above.
…ted release effect
A runtime that cannot reload its native conversation keeps its session for the idle window, as
the linked-environment release already does. The release now runs from the committed
completion event instead of a new outbox effect type, which an older server could claim but not
decode, leaving the child's later effects blocked.
AI-assisted; verified with the tests and tools listed above.
Evidence
Run each commit as a real isolated T3 server on Linux with the same synthetic project and three stdio MCP servers per Claude session. Ask a parent to create three short delegate_task children, wait for their results without settling them, observe process retention, then ask Child 1 to recall its earlier marker.
| Before |
After |
| b3fdf2b10f |
1fda925c57 |
 |
 |
| Full before recording |
Full after recording |
| Completed children retain approximately 793 MiB combined RSS. Follow-up reuses PID 78971. |
Completed children release their process trees within approximately two sampled seconds. Follow-up starts PID 81574 instead of original PID 79088 and recalls ORANGE-31466. |
Images are frames from the recordings. Both recordings show actual elapsed time, process IDs and RSS from Linux /proc, alongside read-only app run/result projections. Child threads remain open throughout.

Reproduction driver, synthetic seed, renderer, sampled data and transcripts.
AI-assisted; verified with the tests and tools listed above.
Not shown:
- Did not wait the full 30-minute base idle timeout; the recordings establish retention after completion and prompt release on head.
- Did not exercise pending background work, queued follow-ups, nested active delegates, non-resumable runtimes, or other providers.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
This PR conflicts with main. Rebase it or merge main into it. If it still conflicts after 7 days with no activity, it will be closed automatically.
See the conflict window.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Superseded by #34934, which landed the same release on main (releaseFinishedDelegateSessions, Fixes #26413), so I'm closing this rather than rebasing it into a second mechanism.
Two guards from this branch aren't in the merged version, in case they matter:
- A child whose follow-up is queued but held (
queueHeld) is still released, because delegatedTaskProgress ignores held runs. The follow-up then starts a new session.
- A runtime with
canResumeAfterRestart === false is released too, so a later follow-up to that child can't recover the conversation.
I can open a small follow-up for either one if you want it.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Labels
needs-rebase
Conflicts with its base branch. Closes after 7 days with no activity.
size:M
30-99 changed lines (additions + deletions).
vouch:unvouched
Author is not yet trusted in 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.
|