Ignore subagent work, not subagent notifications
A subagent's tool calls do reach the parent session's hooks: measured, a PostToolUse arrives carrying agent_id and agent_type. Only Stop was guarded against that, and Stop was the case that mattered least. With background subagents the ordering is the harmful one. The main agent ends its turn first, so Stop lands and the session reads "waiting"; the subagents keep working, and their PostToolUse arrives afterwards and puts the session back to "busy". The panel then says a session is working when its input line is free and it is waiting for you -- the precise confusion this indicator exists to prevent, and reported from a live session doing exactly that. Every event carrying agent_id is now ignored. Synchronous subagents lose nothing: the main agent is mid-turn, so its own earlier events already say "busy". Notification is deliberately exempt. It means a human is needed, and that is as true when the agent that got stuck is a subagent -- ignoring it would leave a session silently blocked. Covered both ways in the hook tests, and checked once against a real subagent event captured from a live run rather than a hand-written one.
This commit is contained in:
@@ -60,9 +60,24 @@ before=$(field event_ts)
|
||||
emit "$(ev Notification '"notification_type":"idle_prompt","message":"waiting for input"')"
|
||||
check "idle_prompt while waiting does not rewrite" "$before" "$(field event_ts)"
|
||||
|
||||
# Subagent activity must not touch the state. The background case is the one
|
||||
# that bites: the main agent has already stopped, so a subagent's tool call
|
||||
# arriving afterwards would claim the session is working when it is waiting.
|
||||
emit "$(ev Stop '"agent_id":"sub-1"')"
|
||||
check "subagent Stop ignored" "waiting" "$(field state)"
|
||||
|
||||
emit "$(ev PostToolUse '"tool_name":"Bash","agent_id":"sub-1","agent_type":"general-purpose"')"
|
||||
check "background subagent does not un-wait the session" "waiting" "$(field state)"
|
||||
|
||||
# ...but a subagent that gets stuck still needs a human, so its notification
|
||||
# must come through.
|
||||
emit "$(ev Notification '"notification_type":"permission_prompt","message":"x","agent_id":"sub-1"')"
|
||||
check "subagent permission prompt still blocks" "blocked" "$(field state)"
|
||||
emit "$(ev PostToolUse '"tool_name":"Bash"')"
|
||||
check "main agent tool call clears it again" "busy" "$(field state)"
|
||||
emit "$(ev Stop)"
|
||||
check "back to waiting" "waiting" "$(field state)"
|
||||
|
||||
# Deliberately checked from "busy": compaction raises SessionStart mid-turn,
|
||||
# and taking it at face value would drop a working session back to waiting.
|
||||
emit "$(ev UserPromptSubmit '"prompt":"go"')"
|
||||
|
||||
Reference in New Issue
Block a user