Repository navigation
fix: classify a subagent from its spawn event so the held prompt waits for it - #461
Merged
Merged
Conversation
…s for it On 4.0 the first event for a subagent is its spawn (SubagentSpawned, a generic session.updated carrying childSessionId and no taskKind); the kind only rides the task event that follows. The listener froze the kind at first sight, so every real subagent task stayed kindless for good and the held-prompt chain read "nothing outstanding": session/prompt returned while the agent was still running (live: prompt at t+9.3s, the card completed at t+15s). The V2 face already classified this way (kindOf, #459); the V1 listener now does the same, and a later sighting that names the kind re-classifies the same tracked task.
Dopetaiga
added a commit
to Dopetaiga/zcode-acp
that referenced
this pull request
Dec 1, 2026
…ng#461); resultText from the output file instead of the notification turn Second review round (2026-12-01): - Rebased onto william0wang#461 (fix/subagent-task-kind): on 4.0 a subagent's first event is SubagentSpawned (childSessionId, NO taskKind), so every taskKind === "subagent" predicate stayed false on a real backend — pendingBackgroundWork answered subagentsOutstanding:false for a RUNNING agent and no card could ever carry a result. My liveness composition now rides william0wang#461's isSubagentTask (a present taskKind wins, else a childSessionId means subagent) over v2TaskOutcome(rawStatus). - The result-text capture machinery is DROPPED per review: the notification turn's text is the PARENT model's commentary about the result, not the result (the agent's output lands in the file the terminal event names). A terminal subagent card now reads that file (best-effort, 64 KiB tail, surrogate-safe 4096-char clamp) into _meta.backgroundTask.resultText — no notification turn, no queue, no seal, no attribution guess; bash keeps its outputTail path. - The stall-guard and subagentResultExpected nits are moot with the capture gone. - Tests: spawn-first classification end-to-end (mint → kind backfill → terminal → file resultText), outputPath file resultText (+ missing file degrades cleanly), spawn-shape outstanding probe; capture tests removed with the machinery. Gates: typecheck clean, lint 0 errors, full suite at parity with the base failure set (pre-existing Windows-env-dependent files).
Dopetaiga
added a commit
to Dopetaiga/zcode-acp
that referenced
this pull request
Dec 1, 2026
…ng#461); resultText from the output file instead of the notification turn Second review round (2026-12-01): - Rebased onto william0wang#461 (fix/subagent-task-kind): on 4.0 a subagent's first event is SubagentSpawned (childSessionId, NO taskKind), so every taskKind === "subagent" predicate stayed false on a real backend — pendingBackgroundWork answered subagentsOutstanding:false for a RUNNING agent and no card could ever carry a result. My liveness composition now rides william0wang#461's isSubagentTask (a present taskKind wins, else a childSessionId means subagent) over v2TaskOutcome(rawStatus). - The result-text capture machinery is DROPPED per review: the notification turn's text is the PARENT model's commentary about the result, not the result (the agent's output lands in the file the terminal event names). A terminal subagent card now reads that file (best-effort, 64 KiB tail, surrogate-safe 4096-char clamp) into _meta.backgroundTask.resultText — no notification turn, no queue, no seal, no attribution guess; bash keeps its outputTail path. - The stall-guard and subagentResultExpected nits are moot with the capture gone. - Tests: spawn-first classification end-to-end (mint → kind backfill → terminal → file resultText), outputPath file resultText (+ missing file degrades cleanly), spawn-shape outstanding probe; capture tests removed with the machinery. Gates: typecheck clean, lint 0 errors, full suite at parity with the base failure set (pre-existing Windows-env-dependent files).
william0wang
pushed a commit
that referenced
this pull request
Dec 1, 2026
…ignal (#453) * fix: classify subagents from their spawn event (rebased on #461); resultText from the output file instead of the notification turn Second review round (2026-12-01): - Rebased onto #461 (fix/subagent-task-kind): on 4.0 a subagent's first event is SubagentSpawned (childSessionId, NO taskKind), so every taskKind === "subagent" predicate stayed false on a real backend — pendingBackgroundWork answered subagentsOutstanding:false for a RUNNING agent and no card could ever carry a result. My liveness composition now rides #461's isSubagentTask (a present taskKind wins, else a childSessionId means subagent) over v2TaskOutcome(rawStatus). - The result-text capture machinery is DROPPED per review: the notification turn's text is the PARENT model's commentary about the result, not the result (the agent's output lands in the file the terminal event names). A terminal subagent card now reads that file (best-effort, 64 KiB tail, surrogate-safe 4096-char clamp) into _meta.backgroundTask.resultText — no notification turn, no queue, no seal, no attribution guess; bash keeps its outputTail path. - The stall-guard and subagentResultExpected nits are moot with the capture gone. - Tests: spawn-first classification end-to-end (mint → kind backfill → terminal → file resultText), outputPath file resultText (+ missing file degrades cleanly), spawn-shape outstanding probe; capture tests removed with the machinery. Gates: typecheck clean, lint 0 errors, full suite at parity with the base failure set (pre-existing Windows-env-dependent files). * fix: read the subagent result file from offset 0 (16 KiB bound) Review approval follow-up (non-blocking, done now): output.txt holds only the run's final message (writeCompletedAgentArtifacts joins the text blocks and overwrites on a resumed run), so a 16 KiB head-read from offset 0 covers any 4096-char resultText and removes the two artifacts the 64 KiB tail read could produce — a mid-file stretch when the file outgrew the window, and a possible U+FFFD seam when the tail start landed inside a multi-byte character. Also documents that a CANCELLED-family task's file carries the stopped-state message: hosts key "finished" off the status, never off the presence of a resultText.
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
On 4.0, the first event a subagent produces is its spawn —
SubagentSpawned, a genericsession.updatedcarryingchildSessionIdand notaskKind(subagent/runner.ts:353-369; the child is ready before the Agent call returns). The kind only rides the task event that follows.BackgroundTaskListenerfrozetaskKindat first sight, so every real subagent task stayed kindless for good, and everytaskKind !== "subagent"check read "not a subagent":subagentWorkOutstanding()→session/promptreturned while the agent was still running;outstandingSubagentCallIds()→ no card refresh;markOutstandingSubagentsTerminal()→ the safety net never fired.The V2 face already classifies by
childSessionIdfor a kindless payload (kindOf, #459). This brings the V1 listener to the same rule and, additionally, re-classifies a tracked task when a later sighting names its kind.Change
src/handlers/background-tasks.tsisSubagentTask(task):taskKind === "subagent", or notaskKindand achildSessionId. A presenttaskKindalways wins.TrackedTask.childSessionIdstored at all three mint sites.onTaskStatusbackfillstaskKind/childSessionIdon every sighting, before any early return.isSubagentTask.Verification
tests/background-tasks.test.ts: 7 cases on the real 4.0 order (spawn → task event), kind-first, kindless-without-child, explicit non-subagent kind with a child id, late-named kind, safety net. Reverse-checked: dropping thechildSessionIdfallback fails 2, dropping the backfill fails 1.session/promptresolved at t+9.3s with the last agent card completing at t+15.1s; after: prompt at t+11.0s / t+14.3s, cards done at t+7.6s / t+10.5s (prompt waits for the cards, two runs). Frames:.zcode/scratch/v2-probes/live/out/frames-held.jsonl.Found while reviewing #453, whose
_zcode/pendingBackgroundWorkand result-text capture both key ontaskKind === "subagent"and therefore read empty on a real backend; that PR should rebase onto this.