Files
magpie/docs
yetone 5b14ebf49a gateway: a Claude subscription run is told the user's words after a tool result as theirs, not the tool's (#1878)
JinJieBeWater found that Claude Code's AgentSummary label request ("Describe
your most recent action in 3-5 words. Do not use tools.", sent as a text
block after the sub-agent's last tool_result) reached the inner Claude as
tool output, so it went on with the task instead of answering the label.

Two paths had it:

- renderParts (a run started anew, or a resumed turn) wrote the text right
  after the tool's last line. A text or file part after a tool result in the
  same message now closes it with "[end of tool result id=…]" and is marked
  "[user message]". A result followed by nothing or by another result is
  told as before, so existing prompts and their cache prefix don't change.
- match folded the text into the last result, and continueWith handed it to
  Claude Code as the MCP result. It no longer folds; saidWithResults takes
  the words, and continueWith writes them to Claude Code's stdin as a user
  message before handing the results over, waiting for Claude Code's
  command_lifecycle "queued" for that uuid (2s at most). Claude Code then
  tells its model the message with the result as one the user sent while it
  worked, in the same turn.

Going on in the run, rather than starting a new one for such requests, keeps
the cache prefix (#1716/#1717) and #872's mid-turn messages, which use the
same shape. #872's text is now queued as the user's instead of appended to
the result. Words in a message that holds images (pi-ai's "Attached
image(s) from tool result:" captions) still fold into the result, decided by
the message's parts, not its text. A tool whose output says "Do not use
tools." keeps it inside its result. The fork test's fake Claude now models
mid-turn absorption the way Claude Code does.

Run: gofmt -l; go vet on darwin, linux (-tags nogui), windows for
./internal/gateway; go test -tags nogui ./internal/gateway/ -count=1 green;
-race -count=3 on the new tests. Broken by hand, each red: no end marker;
an end marker after every result; the words not passed to continueWith; the
old fold into the result; the words queued after the result is handed over.
Real Claude Code 2.1.296 driven through the gateway in a sandbox HOME
against a local mock of Anthropic: on continuation the next request's
tool_result holds "SOURCE_LAST_LINE" then the "user sent a new message
while you were working" reminder with the label request; on a new run the
prompt holds the closed result and "[user message]".

Not run: the owner's real Claude subscription (its credentials are in the
Keychain, off-limits here), so the real model's answer to the label isn't
seen; Windows tests; the full ./... suite.
2026-10-13 07:44:34 +08:00
..