Commit b6670d4
authored
v0.39.2: revert async on PostToolUse:Task (suspected cause of 0 task events) (#36)
Persistent symptom: hook-events.jsonl shows zero `event:"task"` rows
on every machine across many versions, even on v0.39.1 / CC 2.1.161
with 25 agents installed and subagents demonstrably dispatched
(prior `denied` events carry agent_type=code-analyzer/etc).
Investigation (this session):
- Confirmed the PostToolUse payload schema (`tool_name:"Task"`,
`tool_response` with authoritative `totalTokens`) — our read path
is correct.
- Reproduced hook-post-task locally: fed a realistic payload, it
writes the task event fine. So the handler is not broken.
- Confirmed SubagentStop carries no token data (agent_id /
agent_type / last_assistant_message only) — PostToolUse:Task is
the right channel.
- Remaining structural difference between the passing local test and
production: v0.35.0 added `async: true` to PostToolUse:Task. Under
async, Claude Code fires the hook DETACHED and does not wait. The
handler does mkdir + stat + appendFile before exit; a detached
process can be reaped before those async writes flush. Every event
that DOES land comes from a synchronous hook (Read deny blocks CC
until exit, so its write completes) — which fits the evidence.
Fix: drop `async: true` from PostToolUse:Task in both the bundled
hooks.json and the npm installer. post-task now runs synchronously so
the appendEvent write is guaranteed to complete. The ~5ms saved on a
once-per-dispatch hook is not worth losing the telemetry the last
several releases existed to produce.
post-bash KEEPS async: true — it writes no telemetry (advisory
additionalContext only), so detached execution is safe there.
This removes the one confound we control. Next: a fresh-session
subagent dispatch on v0.39.2 is the clean empirical test —
grep -c '"event":"task"' .token-pilot/hook-events.jsonl
If still 0 after a real dispatch, the cause is elsewhere (likely the
user simply not delegating in that project); if >0, async was it.
Tests: 1319/1319 pass.1 parent 2c7195c commit b6670d4
30 files changed
Lines changed: 41 additions & 33 deletions
File tree
- .claude-plugin
- agents
- hooks
- src/hooks
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
| 16 | + | |
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
| 12 | + | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
| 16 | + | |
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
| 15 | + | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
| 12 | + | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
| 16 | + | |
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| |||
0 commit comments