Repository navigation
fix(free-tier): restore official tool names and drop ghost tool calls - #166
Merged
jasonxu114514 merged 1 commit intoNov 5, 2026
Merged
Conversation
A shaped free-tier body appends the lane's official tool set (shell, grep, glob, read, task, …) and the official system prompt names those tools. Models follow it and call `shell` / `grep` / `glob`, but the downstream client never declared those names, so Claude Code answers "No such tool available: shell". The same happens to mangled wire names (`clit_…`, `clnt_…`) and to leftover tool calls such as `d4e3b...`, which were forwarded verbatim and then imitated on later turns. Response mapping now resolves an official name to the client tool the client actually declared (`shell`/`bash` → `Bash`, `read` → `Read`, `edit` → `Edit`, `task`/`subagent` → `Agent`, `question` → `AskUserQuestion`, …). When the client declared no equivalent, the name stays unchanged instead of being guessed. Request history is sanitised for Anthropic, Chat and Responses: a call whose name is neither declared nor equivalent to a declared tool is removed together with its paired result (tool_use_id / tool_call_id / call_id), an official name with a declared equivalent is rewritten to that tool's wire name, and a named tool_choice pointing at a removed tool is dropped. Chat stream rewriting no longer treats a name as complete just because the same delta carries an `arguments` field. While the accumulated name is still a prefix of a known wire name the arguments are held back and released with the resolved name, or flushed verbatim at finish_reason / EOF, so a name split over chunks cannot leak a partial or wire name to the client. Verified in a scratch copy against a captured Claude Code request: shell, bash, read, edit, write and webfetch resolve to the declared client tools while `clit_…`/`clnt_…` pass through untouched and undeclared official names are not mapped; history sanitisation leaves zero orphan tool results across 586 tool blocks; a split name with interleaved arguments emits `Read` with intact arguments and a single-frame call is unchanged. gofmt, go vet and go build pass. Co-Authored-By: Claude Code <noreply@anthropic.com>
froyoandroid
added a commit
to froyoandroid/opencode2api
that referenced
this pull request
Nov 10, 2026
…e WARP egress embargo Upstream shipped the same jasonxu114514#165 fix independently (jasonxu114514#166) and did it more completely: Responses-protocol coverage, paired-result removal keyed on tool_call_id / tool_use_id / call_id, a named tool_choice dropped with the call it names, and Chat name fragments whose arguments arrive in the same delta now held back until the name resolves. Took theirs whole and dropped our narrower alias table and history pass. Three conflicts, all resolved toward upstream except where our work adds a layer upstream lacks: - warp/pool.go: upstream's penalizeFor honours the upstream Retry-After and adds HasUntriedActive. Kept both, and the quota embargo now takes that Retry-After as its window instead of a fixed ten minutes, so an egress is skipped for exactly as long as the upstream asked. - protocol/stream.go: upstream's pendingArguments buffering replaces our simpler name-hold. Kept it, and re-added the tool-call id synthesis on top: a call whose fragments carry no id still gets one, minted once and repeated, because a strict OpenAI client aborts the turn otherwise. - gateway/pool.go: both sides added CursorForOffset; dropped ours. Our CursorFor had been rewired to delegate to it, which recursed once the duplicate went -- restored upstream's body. go build, go vet, gofmt and all six test packages pass.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Shaped free-tier bodies put two sets of tool names on the wire: the renamed client tools (
clint_<digest>) and the appended official set (shell,grep,glob,read,task, …). Only the first set was understood on the way back, so any official tool the model picked, any mangled digest name (clit_…,clnt_…), and any ghost call left in history reached the client verbatim and becameError: No such tool available: ….This PR teaches the response and history paths about the names the gateway itself sends.
shell/bash→Bash,read→Read,edit→Edit,write→Write,webfetch→WebFetch,websearch→WebSearch,skill→Skill,glob→Glob,grep→Grep,task/subagent→Agent,question→AskUserQuestion,todowrite→TodoWrite,patch→Patch. When the client declared no equivalent the name is left alone instead of being guessed.tool_use_id/tool_call_id/call_id); an official name with a declared equivalent is rewritten to that tool's wire name; a namedtool_choicepointing at a removed tool is dropped.argumentsfield. While the accumulated name is still a prefix of a known wire name, the arguments are held back and released together with the resolved name, or flushed verbatim atfinish_reason/ EOF.Digest naming, the official system prompt, the appended official set, and 429/403 classification are untouched.
Why not just drop the official set?
That would remove the
shellclass at the source and is the better end state, but #163/PR #161 showed the free tier's gate is sensitive to body shape, and dropping the set needs an upstream replay against a captured Claude Code request to prove the429does not return. That replay costs free quota and IP reputation, so it is left for a follow-up rather than folded into this fix.Verification
Run in a scratch copy of
2bf547cagainst a captured Claude Code request (Anthropic/v1/messages→ Chat) shaped throughPrepareRequest+prepareAnonymousBody:Resolve("shell")→Bash;"bash"/"read"/"edit"/"write"/"webfetch"map likewiseclint_9b9a8d05a7ec→Readunchangedclit_9b9a8d05a7ec/clnt_9b9a8d05a7ecstay unchangedGrep/Glob→ those names are not inventedclit_…andshell: mangled call and its result removed, official call rewritten toclint_d1e9567da9a8, zero orphantoolmessagestool_resultacross 586 tool blocks"name":"Read"and arguments{"x":1}Also run in the repo:
gofmt -l .(empty),go vet ./...(clean),go build -trimpath ./cmd/opencode2api(clean),git diff --check(clean).Not verified, and deliberately so: whether the client accepts the official tool's extra argument fields when its own schema is narrower (
shellcarries optionalbackground/workdir;task/subagentdiffer fromAgent). Only the name is rewritten; arguments are passed through as the model produced them. No upstream replay was run.No
_test.gois added — the released tree is kept test-free per2bf547c; the probes above live only in a scratch copy.Related
Follows #163 / PR #161. Closes #165.
🤖 Generated with Claude Code