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:
av
2026-08-09 19:18:43 +03:00
parent 626c2b6d2c
commit 09b9aae2eb
3 changed files with 43 additions and 6 deletions
+14 -2
View File
@@ -142,8 +142,20 @@ gnome-extensions enable claude-code-status@git.vakhrushev.me
всё ещё позволяет хуку, прочитавшему старое состояние до `Stop`, записать своё
устаревшее решение после него.
Сабагенты не показываются. Батч из восьми задач — это одна строка «работает
40 мин», и это правильная строка: пятый воркер из восьми ни о чём не просит.
Сабагенты не показываются, и это не про экономию строк. Их вызовы инструментов
**долетают** до хуков родительской сессии — как `PostToolUse` с полями
`agent_id` и `agent_type` (проверено запуском). Учитывать их нельзя: при фоновых
сабагентах основной агент заканчивает ход первым (`Stop`, то есть `waiting`), а
сабагенты продолжают работать, и их события перебили бы состояние обратно в
`busy`. Панель показывала бы «работает» у сессии, которая на самом деле ждёт
вас, — ровно та подмена, ради предотвращения которой всё и затевалось.
Поэтому любое событие с `agent_id` игнорируется. Кроме `Notification`: она
означает, что нужен человек, и это одинаково верно, в каком бы агенте ни
заклинило.
Батч из восьми задач остаётся одной строкой «работает 40 мин», и это правильная
строка: пятый воркер из восьми ни о чём не просит.
## zellij