gateway: a late Claude Code call tells the client after 500ms, not 1s

In Claude Code's interactive mode a call of a client's tool waits callFirst
for its message in the transcript before the call tells the client itself.
Measured on a real account (a probe build logging the time from the MCP call
to the transcript's tool_use), a message written before its call was read
118 to 162ms after the call came in, 8 calls of 8. 500ms leaves it room and
halves what a late message costs.

Run: go test -race -count=3 -run 'TestClaudeTUI|TestSubscription'
./internal/gateway on mote, ok. Real account (claude-haiku-5-5, sandbox
HOME, interactive TUI): 9 runs of the one/two/text scenarios, all ok, every
call told once with its own id; 1 took the late path, none fell back to -p.
Not tried: sonnet/opus, Linux.
This commit is contained in:
yetone
2026-10-31 04:35:16 +08:00
parent e647a1fd54
commit 9d4a4bfd3f
2 changed files with 7 additions and 3 deletions
@@ -121,7 +121,8 @@ answered: on a real account, 4 runs of 8 wrote it after its MCP call
returned. The call can only be answered by the client, which hasn't been
told of it. So in an interactive run, `mcpCall` hands each call to the
reader (`run.onCall`). Not shown from the transcript within `callFirst`
(1s), the call is a reply of its own: a message with that one `tool_use`
(500ms; a message written before its call is read 118 to 162ms after
it), the call is a reply of its own: a message with that one `tool_use`
(Claude Code makes its MCP calls one at a time, a message's parallel
calls too). The first message written after such a call is the one that
made it. Its rows are left out (`lateID`), and its usage is told with the
+5 -2
View File
@@ -2847,8 +2847,11 @@ var unstreamedQuiet = 300 * time.Millisecond
// callFirst is how long a call of a client's tool in Claude Code's
// interactive mode waits for its message in the transcript before the call
// tells the client itself (readOutput).
var callFirst = time.Second
// tells the client itself (readOutput). A message written before its call
// was read 118 to 162ms after the call came in (8 calls on a real account),
// so half a second leaves it room and makes a late message cost half as
// long as it did at 1s.
var callFirst = 500 * time.Millisecond
type cliUsage struct {
Input int `json:"input_tokens"`