Skip to content

fix(server): finished Claude delegates release their process - #34934

Merged
juliusmarminge merged 3 commits into
mainfrom
factory/issue-26413
Nov 12, 2026
Merged

juliusmarminge merged 3 commits into
mainfrom
factory/issue-26413

Conversation

@juliusmarminge

@juliusmarminge juliusmarminge commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

Both review items are correct and describe the same gap: delegatedTaskProgress reports result_available even while unawaited background command/monitor tasks are running (backgroundWorkHoldsCompletion treats them as non-blocking by design), so the early detach killed a delegate's dev server or watcher, which Claude ends with its process. releaseFinishedDelegateSessions now also returns without detaching when any of the child's provider threads has non-empty pendingBackgroundTasks, leaving release to ProviderSessionManager's idle timer and its hasPendingBackgroundWork pin, as on main. A finished delegate with no background work is still released as soon as its result is recorded. Test: the existing DelegatedCompletionDelivery case became an it.effect.each with two rows: no background work (session released) and an unawaited background command (session kept). Each row uses its own IDs because the file's rows share one database. The background row fails without the new guard ('expected +0 to equal 1') and passes with it. No regex or parser added.

Fixes #26413

Reproduction on main

Commit 6ba3de7 (origin/main), worktree ~/wt/factory-issue-26413-triage. Ran T3CODE_DEV_SEED=0 vp run dev, which gave a fresh database (server port 16164). Added a scratch git project with t3 project add. Ran t3 thread start --provider claudeAgent --model claude-haiku-5-5 --wait <project> "Use the T3 delegate_task tool exactly once to start a child task on provider claudeAgent with model claude-haiku-5-5 whose task is: 'Reply with the single word DONE.' ...". The parent called delegate_task and the child thread ran once: requested at 07:06:59Z, run status completed at 07:07:10.7Z. The parent got the result 'DONE' and its own run completed at 07:07:14Z. Afterwards the child's provider session stayed ready in orchestration_v2_projection_provider_sessions, and its claude process (child of the dev server, about 245 MB RSS) was still alive 93 s after the run completed. Nothing settles the child or queues a release for it. A background watcher on that PID was still waiting at hand-off, so the full 30-minute lifetime was not observed in this run. The code path matches it: DEFAULT_IDLE_TIMEOUT_MS = 30 * 60 * 1000 in ProviderSessionManager.ts:62, applied at :468, and no caller passes idleTimeoutMs. The settle path that releases early was not re-tested. Cleanup was not finished at hand-off: dev server PID 25436, its 3 claude children, the watcher, the worktree and /tmp/factory-issue-26413-triage are still in place.

Evidence

Run the real server on each commit with a fresh database and synthetic project. Start one parent that delegates a single 'Reply with the single word DONE.' task, waits for its result, and starts no background work. Observe child-bound processes for 90 seconds after the parent finishes.

Before After
dbfbe3993f e7a121b977
Before: completed delegate retains Claude and MCP descendants After: completed delegate has no live child processes
Before recording After recording

Base retained approximately 216 MiB in Claude alone, plus MCP descendants, through the observation window. Head released the observed child process approximately one second after completion. Both parents received DONE. The session projection still reads ready on both commits.

Driver · Environment details · Before samples · After samples

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

Not shown:

  • The full 30-minute idle timeout was not observed; base retention was observed for 90 seconds after parent completion.
  • Retention for delegates with pending background tasks, follow-up races, and shared multi-thread provider sessions was not exercised.
  • The provider-session projection remains ready on head despite process release; this proof establishes OS process cleanup, not projection-status correction.

Tests

vp test run src/orchestration-v2/DelegatedCompletionDelivery.test.ts -t "provider history handoff": 2 passed (background row fails with the guard stashed: 'expected +0 to equal 1'); vp test run on DelegatedCompletionDelivery, RemoteDelegatedTask, SubagentProjection, Orchestrator.control-reads, ThreadStop, OrchestratorMcpToolkit.integration, TaskCancelUsageLimit.integration, TaskCancelNativeSubagent.integration, SteeringCompletion.integration, OrchestratorMcpService, RestartContinuation, peer/RemoteDelegation: 12 files, 370 tests passed; vp run check:changed: format, lint, knip, graphql, typecheck (3 packages), tests (5 files, 90 tests) all pass.

Not in this change

  • Failed, cancelled and interrupted delegates are also released once their result is recorded (fix(server): release a finished delegated child's provider session at once #31466 released only completed ones); the brief asks for release when the child's single run has finished, and finalize already holds back runs that wait on a restart continuation.
  • After a detach, the orchestration_v2_projection_provider_sessions row keeps its last status (e.g. 'ready'); only the binding is removed. The settle and archive detaches behave the same way.
  • The 30-minute DEFAULT_IDLE_TIMEOUT_MS for ordinary threads ([Bug]: Each open Muse thread holds ~1 GB (agent + full MCP set) after its turn ends #30148, feat(server): make idle agent release configurable #25624) is unchanged.
  • The triage step's leftovers (dev server PID 25436, its claude children, a watcher, ~/wt/factory-issue-26413-triage and /tmp/factory-issue-26413-triage) belong to another step and were not touched.
  • A delegate that finished with background work now waits for the existing idle timer and its pending-work pin (up to 4 hours), as on main; the brief did not ask to release it once that work ends.
  • The test file diff is large only because the case became an it.effect.each and was reindented; its assertions are otherwise unchanged.

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

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M 30-99 changed lines (additions + deletions). vouch:trusted Author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Finished Claude delegate_task sessions keep their claude process and MCP servers for 30 minutes, so delegate-heavy runs exhaust RAM

1 participant