Pi 1.2.0 with supportsMidConvoToolAdditions sends a tool it adds
mid-conversation as {"role":"system","tools":[...]} with no content and
keeps top-level tools as they were. parseChat read only top-level tools
and the Chat relay sent the message on as it came, so the tool could be
called on no route, and the tools-only message became an empty part of
the system text ("</cwd>\n\n\n\nUpdated ...").
liftMessageTools (message_tools.go) moves message tools into the
request's tools. handle does it for every Chat body, before serveAgent,
so the Chat relay, schema fixers, redaction, the prompt shown and
routing all see them; parseChat does it too for a body that never came
through handle. Each tool joins once by name and the first definition
wins (top-level, then the earliest message's), as liftAdditionalTools
and a tool_addition in withoutDeferredTools do. A system or developer
message that carried only tools is left out; one with content keeps
its place without tools. Message order is unchanged: the in-place
system message / inline-tools beta part of #2322 is not in this commit.
6312af989 (#2338, inline-only tool_addition joins tools) is not on
origin/main a1f7b8c13, so this builds on neither; the rule matches it.
Tests, from deephbz's literal Pi 1.2.0 request (last comment on #2322):
TestPiAddedToolReachesEveryRoute (Chat relayed to an OpenAI-compatible
upstream, Messages, Responses, Gemini, Codex), TestPiAddedToolOffered-
ToClaudeCode (the Claude subscription bridge's MCP tools.json, a fake
claude; skipped on Windows), TestMessageToolsFirstDefinitionWins.
Run (sandbox HOME, -tags nogui -p 1):
- go test ./internal/gateway -run 'TestPiAddedTool|TestMessageTools|
Chat|Messages|AdditionalTools|Lite|Deferred|ExtraBody|Gemini|
CodexAccessPrograms|Developer|ThinkingEffort|Kimi|DeepSeek|ClaudeRun|
ClaudeSubscription|Strict|Prompt' -count=1: ok (75.8s)
- broken by hand: liftMessageTools a no-op -> every route subtest, the
bridge test and FirstDefinitionWins red (tools [lookup_pantry], empty
system relayed, "\n\n\n\n" in the system text); only handle's lift
removed -> chat relayed red; only parseChat's lift removed -> the
bridge test and FirstDefinitionWins red.
- gofmt -l internal/gateway: clean; go vet -tags nogui ./internal/gateway
for GOOS=darwin, linux, windows: clean.
Not run: other packages, the full suite. Not tried with a real Pi or a
real upstream.
Full suite: SUITE_LINE