fix(subagent): reap orchestration-dispatched sub-agent handles#6333
Merged
Conversation
bug-ops
enabled auto-merge (squash)
July 16, 2026 18:42
SubAgentManager::collect() was only ever invoked from the interactive /agent polling path, never from the orchestration dispatch loop (run_scheduler_loop). Every plan-executed sub-agent leaked its handle and never wrote a final TranscriptMeta sidecar. A naive ordering fix is not sufficient: status_tx flips to Completed before the corresponding TaskEvent is even enqueued, and SchedulerAction::Verify is never emitted for Failed outcomes or when verify_completeness is disabled, so a Verify-only reap would still leak most terminal tasks. Decouple grounding trace reads from handle residency instead: SubAgentManager::transcript_path_for() resolves the transcript path from config alone, with no dependency on the handle still being tracked. build_tool_trace_for_task and resolve_whole_plan_trace_paths both now use it, so reaping handles can no longer silently degrade verifier grounding to fail-open None. Agent::collect_finished_subagents() reaps every Completed/Failed/Canceled handle once per scheduler tick. Update specs/009-orchestration/spec.md to reflect that grounding no longer depends on residency.
bug-ops
force-pushed
the
fix/6288-subagent-collect-dispatch
branch
from
July 16, 2026 18:48
bb349a5 to
c4f0e8f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
SubAgentManager::collect()was only ever invoked from the interactive/agentpolling path (
poll_subagents()), never from the orchestration dispatch loop(
run_scheduler_loop). Every plan-executed sub-agent leaked its handle and neverwrote a final
TranscriptMetasidecar.A naive ordering fix (call
collect()right after the verifier reads the trace)is not sufficient:
status_txflips toCompletedbefore the correspondingTaskEventis even enqueued, andSchedulerAction::Verifyis never emitted forFailedoutcomes or whenverify_completenessis disabled, so a Verify-only reapwould still leak most terminal tasks.
Instead, grounding trace reads are decoupled from handle residency:
SubAgentManager::transcript_path_for()resolves the transcript path fromconfig alone, independent of whether the handle is still tracked.
build_tool_trace_for_taskandresolve_whole_plan_trace_paths(whole-plangrounding, a related residency hazard found during implementation) both now
use it, so reaping can no longer silently degrade verifier grounding to
fail-open
None.Agent::collect_finished_subagents()reaps everyCompleted/Failed/Canceledhandle once per scheduler tick.
specs/009-orchestration/spec.mdupdated to reflect that grounding no longerdepends on handle residency.
Closes #6288
Test plan
cargo +nightly fmt --check— cleancargo clippy --profile ci --workspace --all-targets --features "desktop,ide,server,chat,pdf,scheduler,testing" -- -D warnings— cleancargo nextest run --config-file .github/nextest.toml --workspace --features "desktop,ide,server,chat,pdf,scheduler" --lib --bins— 13808 passed, 0 failedRUSTFLAGS="-D warnings" RUSTDOCFLAGS="--deny rustdoc::broken_intra_doc_links" cargo doc --no-deps --workspace --features "desktop,ide,server,chat,pdf,scheduler"— cleancargo test --doc -p zeph-subagent— clean, including newtranscript_path_fordoctestNone-manager no-op,Canceled-state reapgitleaks protect --staged— clean