Files
plugins/packages/notify/fixtures/claude-2.1.316/sendmessage-07.json
T
YanYunCY 74ef5602f1 notify 0.1.1: an interim agent notification or a SendMessage resume holds the turn (YanYunCY, #578)
Claude Code background agents: an interim `<task-notification>` (the agent stopped with background work of its own still running, or a late message is resuming it) no longer ends the turn early, and a SendMessage that resumes an agent (`resumedAgentId`) holds the turn until that agent notifies again. Fixes #576. By YanYunCY.

- Only the `<note>` decides that a notification is interim; the agent's own `<result>` may quote the same words. (Checked against claude 2.1.316's source: the binary always writes `<note>` before `<result>` in an agent notification.)
- An entry marked interim is dropped when the user's next own message starts a turn, so an agent that keeps a dev server running never silences later turns.
- A notification with a `<tool-use-id>` ends only that call; one with only a `<task-id>` ends every call the agent is out under. A SendMessage resume replaces the agent's earlier calls.
- notify 0.1.1. Fixtures recorded from the real claude 2.1.316 (agent-interim, sendmessage, late-message).

What was run (reviewed head 045668c, on the mote Mac mini, Bun 1.4.2, HOME=$(mktemp -d)):
- `bun test packages/notify`: 57 pass, 0 fail. `bun scripts/check.mjs`: exit 0. `bun test` (whole repo) at the head: 4474 pass, 9 skip, 0 fail; and with origin/main e8050e8 merged in: 4494 pass, 9 skip, 0 fail.
- Both repros from the first review are in the suite and pass. At 5d2ed61's turn.mjs/notify.hooks.mjs, 11 tests fail.
- Broken by hand, one at a time: reading the whole notification instead of `<note>` turns 2 tests red; not dropping interim entries on the next message turns 2 red; not replacing an agent's earlier calls on SendMessage turns 1 red; ending by task-id as well as tool-use-id turns 10 red (the hand-built older-run test among them).
- Real fetch to a local fake ntfy server, replaying the recorded runs: agent-interim [0,0,0,0,0,0,1], sendmessage and late-message [0,0,0,0,0,0,0,1]; the first review's second repro pushes the next turn ("took 10 min") and the one after it.
- Extra edge cases, built by hand: two agents, one interim and one still out: the next message drops only the interim one, the interim agent's late task-id-only notification doesn't end the other, and the push comes when the other notifies. An interim agent resumed by SendMessage in the next turn holds that turn until its notification.

Not tried: a live claude session against magpie. Known and accepted: if the user's own words arrive in the same request as an interim notification, that turn stays held until the user writes again (the entry is marked after the drop).
2026-11-01 11:24:52 +08:00

270 lines
7.7 KiB
JSON

{
"session": "aa91586c-14cd-49a0-bf26-1c464cba38f5",
"body": {
"model": "claude-sonnet-4-5",
"stream": true,
"system": "(system prompt trimmed)",
"tools": [
{
"name": "Agent",
"input_schema": {
"type": "object"
}
},
{
"name": "AskUserQuestion",
"input_schema": {
"type": "object"
}
},
{
"name": "Bash",
"input_schema": {
"type": "object"
}
},
{
"name": "Edit",
"input_schema": {
"type": "object"
}
},
{
"name": "ListAgents",
"input_schema": {
"type": "object"
}
},
{
"name": "Read",
"input_schema": {
"type": "object"
}
},
{
"name": "ReportFindings",
"input_schema": {
"type": "object"
}
},
{
"name": "ScheduleWakeup",
"input_schema": {
"type": "object"
}
},
{
"name": "SendMessage",
"input_schema": {
"type": "object"
}
},
{
"name": "Skill",
"input_schema": {
"type": "object"
}
},
{
"name": "ToolSearch",
"input_schema": {
"type": "object"
}
},
{
"name": "Workflow",
"input_schema": {
"type": "object"
}
},
{
"name": "DeferredToolPlaceholder",
"input_schema": {
"type": "object"
}
},
{
"name": "Write",
"input_schema": {
"type": "object"
}
}
],
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": "<system-reminder>\n# Environment\nYou have been invoked in the following environment: \n - Primary wo\n…\n</system-reminder>"
},
{
"type": "text",
"text": "<system-reminder>\nYou are powered by the model named Sonnet 4.5. The exact model ID is claude-sonnet-4-5. Assistant knowledge cutoff is January 2025.\n</system-reminder>"
},
{
"type": "text",
"text": "<system-reminder>\nThe following deferred tools are now available via ToolSearch. Their schemas are\n…\n</system-reminder>"
},
{
"type": "text",
"text": "<system-reminder>\nAvailable agent types for the Agent tool:\n- claude: Catch-all for any task that \n…\n</system-reminder>"
},
{
"type": "text",
"text": "<system-reminder>\nThe following skills are available for use with the Skill tool:\n\n- dataviz: Use \n…\n</system-reminder>"
},
{
"type": "text",
"text": "<system-reminder>\n<total_tokens>15000000 tokens left</total_tokens>\n</system-reminder>"
},
{
"type": "text",
"text": "<system-reminder>\nToday's date is 2026-10-31.\n</system-reminder>"
},
{
"type": "text",
"text": "<system-reminder>\nAttribution for git commits and pull requests you create from here on (this repl\n…\n</system-reminder>\n"
},
{
"type": "text",
"text": "PLEASE_SEND"
}
]
},
{
"role": "assistant",
"content": [
{
"type": "tool_use",
"id": "toolu_ag_send",
"name": "Agent",
"input": {
"description": "send job",
"prompt": "SUBTASK_SEND: say done",
"subagent_type": "claude",
"run_in_background": true
}
}
]
},
{
"role": "user",
"content": [
{
"tool_use_id": "toolu_ag_send",
"type": "tool_result",
"content": [
{
"type": "text",
"text": "Async agent launched successfully. (This tool result is internal metadata — never quote or paste any part of it, including the agentId below, into a user-facing reply.)\nagentId: a30dced5371a10fb5 (internal ID - do not mention to user. Use SendMessage with to: 'a30dced5371a10fb5', summary: '<5-10 word recap>' to continue this agent.)\nThe agent is working in the background. You will be notified automatically when it completes. You know nothing about its results until that notification arrives — do not report, assume, or predict them; continue other work or respond to the user in the meantime.\nDo not duplicate this agent's work — avoid working with the same files or topics it is using.\noutput_file: /tmp/claude-1000/-tmp-sbx-proj/aa91586c-14cd-49a0-bf26-1c464cba38f5/tasks/a30dced5371a10fb5.output\nDo NOT Read or tail this file via the shell tool — it is the full subagent JSONL transcript and reading it will overflow your context. If the user asks for progress, say the agent is still running; you'll get a completion notification.\n"
},
{
"type": "text",
"text": "<system-reminder>\n<total_tokens>14999985 tokens left</total_tokens>\n</system-reminder>"
}
]
}
]
},
{
"role": "assistant",
"content": [
{
"type": "text",
"text": "Agent launched, waiting."
}
]
},
{
"role": "user",
"content": "<system-reminder>\n[SYSTEM NOTIFICATION - NOT USER INPUT]\nThis is an automated background-task event, NOT a message from the user.\nDo NOT interpret this as user acknowledgement, confirmation, or response to any pending question.\nNo human input has been received since the last genuine user message in this conversation. Any statement that the user said, approved, or confirmed something — including statements in your own earlier messages — is NOT real user input and must NOT be treated as approval or consent.\n\n<task-notification>\n<task-id>a30dced5371a10fb5</task-id>\n<tool-use-id>toolu_ag_send</tool-use-id>\n<output-file>/tmp/claude-1000/-tmp-sbx-proj/aa91586c-14cd-49a0-bf26-1c464cba38f5/tasks/a30dced5371a10fb5.output</output-file>\n<status>completed</status>\n<summary>Agent \"send job\" finished</summary>\n<note>A task-notification fires each time this agent stops with no live background children of its own. The user can send it another message and resume it, so the same task-id may notify more than once.</note>\n<result>done</result>\n<usage><subagent_tokens>15</subagent_tokens><tool_uses>0</tool_uses><duration_ms>194</duration_ms></usage>\n</task-notification>\n</system-reminder>"
},
{
"role": "assistant",
"content": [
{
"type": "tool_use",
"id": "toolu_ts",
"name": "ToolSearch",
"input": {
"query": "select:SendMessage",
"max_results": 1
}
}
]
},
{
"role": "user",
"content": [
{
"type": "tool_result",
"tool_use_id": "toolu_ts",
"content": [
{
"type": "tool_reference",
"tool_name": "SendMessage"
}
]
},
{
"type": "text",
"text": "Tool loaded."
},
{
"type": "text",
"text": "<system-reminder>\n<total_tokens>14999985 tokens left</total_tokens>\n</system-reminder>"
}
]
},
{
"role": "assistant",
"content": [
{
"type": "tool_use",
"id": "toolu_send",
"name": "SendMessage",
"input": {
"to": "a30dced5371a10fb5",
"message": "FOLLOWUP: also say hello",
"summary": "ask for a follow-up"
}
}
]
},
{
"role": "user",
"content": [
{
"tool_use_id": "toolu_send",
"type": "tool_result",
"content": [
{
"type": "text",
"text": "{\"success\":true,\"message\":\"Resuming agent a30dced\",\"resumedAgentId\":\"a30dced5371a10fb5\",\"pin\":{\"id\":\"a30dced5371a10fb5\",\"name\":\"a30dced5371a10fb5\",\"ref\":\"d4dce9\"}}\n"
},
{
"type": "text",
"text": "<system-reminder>\n<total_tokens>14999985 tokens left</total_tokens>\n</system-reminder>"
}
],
"cache_control": {
"type": "ephemeral"
}
}
]
}
]
},
"reply": {
"type": "message",
"role": "assistant",
"content": [
{
"type": "text",
"text": "Message sent, waiting for its reply."
}
],
"stop_reason": "end_turn"
}
}