jinyue806 (#2622): ZCode sends its tools on /v1/chat/completions in MCP's
shape, {"name","description","inputSchema"}, with no type and no function
object. magpie relayed them as they came, and SenseNova turned every request
with tools away ("field Tools[0].Type invalid, should be set"; a flat
{"type":"function","name":…} got "function cannot be empty"). A missing
type is invalid Chat Completions for every upstream, not SenseNova only, and
the translated routes were broken too: parseChat read no name from such a
tool, so Messages and Responses upstreams were offered a tool named "".
shapeChatTools puts a tool with its name at the top (no type, or type
"function" without a function object) into {"type":"function","function":
{name, description, parameters, strict}}, parameters taken from
parameters, inputSchema or input_schema; other fields stay beside it. It
runs right after liftMessageTools at the same two choke points: handle, for
every Chat body before routing (relay, schema fixers, redaction, plugins),
and parseChat, for a body that never came through handle. A tool that has
its function, a hosted tool (any other type) and one with no name are left
alone, and a request with nothing to shape is relayed byte for byte.
Verified:
- TestChatToolInAnotherShapeIsShaped sends the reporter's curl body with
each of the four tool shapes from the report through the Chat relay,
Messages and Responses. With shapeChatTools made a no-op by hand all 12
subtests FAIL: relayed as {"name":"f","inputSchema":{…}} as it came, and
translated as {"name":"",…}. TestShapeChatToolsLeavesChatShape (byte for
byte on Chat-shaped/hosted/nameless tools; strict and cache_control kept)
FAILs on the same break. Both pass restored.
- gofmt -l: clean. go vet -tags nogui ./... for darwin, linux, windows: ok.
- Full suite at 81313b912 + this change, sandbox HOME, pinned caches:
set -o pipefail; go test -tags nogui -timeout 45m ./... : 59 packages ok
(internal/gateway 1134s, internal/provider 548s). 7 packages failed only
on "no space left on device" while the disk filled mid-run (cli
TestModelDisableCmd, library TestAgentMCPFiles, sessions
TestCodexTitleEvidenceBound, settings TestSaveConcurrent, and gui, tui,
usage which printed PASS but couldn't write testlog.txt). Rerun once
space was back (30G free): cli, gui, library, sessions, settings, tui,
usage all ok.
- Rebased onto origin/main a69cd0707 (#2611's chat call ids, chattidy):
gofmt clean, vet darwin/linux/windows on internal/gateway ok,
go test -tags nogui -timeout 45m ./internal/gateway ./internal/source:
ok (gateway 510s). No other package changed between the two bases.
- Not tried against the real SenseNova (no key here); the reporter's own
table shows {"type":"function","function":{…}} answered 200.
The "inference request is invalid ... reason=unknown retryable=false" text
in the report is not magpie's (no such string in the repo); it is the
client's wrapper of the upstream error, so nothing changed there.