Send status in_progress when a tool's execution starts, so a client can time the call #6

Merged
city-root merged 1 commit from worker/claudeacp-eoz into main 2026-11-12 12:39:09 +00:00
Contributor

Sends tool_call_update with status: in_progress when a tool starts to run, not while the model is still streaming the call's input (claudeacp-eoz).

Where the moment is read from

Claude Code has no message that says a tool started. I ran the real claude (2.1.322) against the repo's fake Messages API with hooks registered and logged the order for a Write with a streamed input and for a Bash call:

  1. content_block_start / input_json_deltas (the model writing the input: seconds to minutes for a Write)
  2. the assistant message with the whole tool_use, then content_block_stop
  3. PreToolUse hook, about 2 ms later, before claude looks at rules or permissions
  4. if claude asks: can_use_tool + PermissionRequest hook, about 10 ms after the PreToolUse hook; the tool runs when it is answered with Allow
  5. PostToolUse hook, then the tool_result

tool_progress is no good as the signal: it never came for sleep 3; echo hi.

So the adapter registers PreToolUse (new claudeacp/running.go). For a call whose input is whole, it tells the client in_progress 100 ms after the hook (grace, on the agent's clock) unless a permission request or a denial came first. If claude asks, in_progress is sent when the adapter answers Allow (canUseTool), so the time the user spends deciding is not counted as run time. tool_progress still sends it, once, if nothing has.

What a client sees for a call that never executes

  • Refused by the user (permission request answered No/cancelled): pending then failed, never in_progress.
  • Denied by a rule (permission_denied): pending then failed. The denial arrives within milliseconds of the hook, so the 100 ms wait ends with the call already ended and nothing is sent.
  • Cancelled while waiting for permission or before it ran: pending then failed ("The turn was cancelled…"). Cancelled while running: in_progress then failed.
  • Server tools (server_tool_use) and the plan tools run no hook and stay pending until their result, as before.

Known limit: the 100 ms is a heuristic, since claude gives no earlier signal that it will ask. If the permission request is later than that (a very loaded machine), the call shows in_progress while the user is asked. A call that a user's own PreToolUse hook blocks shows in_progress briefly, too.

Tests

claudeacp/running_test.go holds the order of the updates for a Write with a long streamed input and for a Bash call (no in_progress before the grace passes, one after, then the result), for a call that waits for permission (allowed, refused) and for one a rule denies. TestSubagentPermission now expects the in_progress an allowed call gets. go build ./... && go vet ./... && go test -race ./... pass.

CHANGELOG entry under [Unreleased]; README lists the tool-call updates under "What's supported".

Bead: claudeacp-eoz

Sends `tool_call_update` with `status: in_progress` when a tool starts to run, not while the model is still streaming the call's input (claudeacp-eoz). ## Where the moment is read from Claude Code has no message that says a tool started. I ran the real claude (2.1.322) against the repo's fake Messages API with hooks registered and logged the order for a Write with a streamed input and for a Bash call: 1. `content_block_start` / `input_json_delta`s (the model writing the input: seconds to minutes for a Write) 2. the `assistant` message with the whole `tool_use`, then `content_block_stop` 3. **`PreToolUse` hook**, about 2 ms later, before claude looks at rules or permissions 4. if claude asks: `can_use_tool` + `PermissionRequest` hook, about 10 ms after the `PreToolUse` hook; the tool runs when it is answered with Allow 5. `PostToolUse` hook, then the `tool_result` `tool_progress` is no good as the signal: it never came for `sleep 3; echo hi`. So the adapter registers `PreToolUse` (new `claudeacp/running.go`). For a call whose input is whole, it tells the client `in_progress` 100 ms after the hook (`grace`, on the agent's clock) unless a permission request or a denial came first. If claude asks, `in_progress` is sent when the adapter answers Allow (`canUseTool`), so the time the user spends deciding is not counted as run time. `tool_progress` still sends it, once, if nothing has. ## What a client sees for a call that never executes - Refused by the user (permission request answered No/cancelled): `pending` then `failed`, never `in_progress`. - Denied by a rule (`permission_denied`): `pending` then `failed`. The denial arrives within milliseconds of the hook, so the 100 ms wait ends with the call already ended and nothing is sent. - Cancelled while waiting for permission or before it ran: `pending` then `failed` ("The turn was cancelled…"). Cancelled while running: `in_progress` then `failed`. - Server tools (`server_tool_use`) and the plan tools run no hook and stay `pending` until their result, as before. Known limit: the 100 ms is a heuristic, since claude gives no earlier signal that it will ask. If the permission request is later than that (a very loaded machine), the call shows `in_progress` while the user is asked. A call that a user's own PreToolUse hook blocks shows `in_progress` briefly, too. ## Tests `claudeacp/running_test.go` holds the order of the updates for a Write with a long streamed input and for a Bash call (no `in_progress` before the grace passes, one after, then the result), for a call that waits for permission (allowed, refused) and for one a rule denies. `TestSubagentPermission` now expects the `in_progress` an allowed call gets. `go build ./... && go vet ./... && go test -race ./...` pass. CHANGELOG entry under `[Unreleased]`; README lists the tool-call updates under "What's supported". Bead: claudeacp-eoz
Send in_progress when a tool starts to run (claudeacp-eoz)
All checks were successful
CI / Changelog (pull_request) Successful in 4s
CI / Lint (pull_request) Successful in 32s
CI / Test (pull_request) Successful in 40s
eb2b36229f
A call showed in_progress only when claude's tool_progress came, which it sends for a tool that has run a while and for some not at all, so a client that timed a call from its first update counted the model's streaming of a Write's input (minutes) as the tool's run time.

claude has no message that says a tool started. Run against a fake API, the real claude (2.1.322) sends, for a call: the assistant message with the whole input, then the PreToolUse hook, then (when it asks) can_use_tool within milliseconds, then the PostToolUse hook and the result. So the adapter registers PreToolUse and tells the client the call runs when the hook has run and no permission request or denial followed within 100 ms; a request that is allowed tells it at once. A call the user or a rule refuses never shows in_progress. tool_progress still says the tool runs, the first time.

Tests hold the order of a Write with a long streamed input and of a Bash call, a call that waits for permission (allowed and refused), and one a rule denies. TestSubagentPermission expects the in_progress an allowed call now gets.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
city-root-review left a comment

Review of eb2b36229f for claudeacp-eoz. Checks of the head: success.

Verdict

pass

Findings

  • [minor] claudeacp/question.go:59, claudeacp/permission.go:62: shown now sets asked, which turns off the grace timer. But two Allow paths return without calling s.tools.running: askUser, and canUseTool for ExitPlanMode when an option is picked (the early return s.exitPlan(...)). So an answered AskUserQuestion, and an ExitPlanMode the user accepts, go from pending straight to completed and never show in_progress. The README line says in_progress is sent when a call's tool starts to run. Both tools finish at once after the answer, so a client loses almost nothing. Either call running on those Allow paths, or name them in the README beside the server tools.

Verified

  • Requirement (claudeacp-eoz) against the change:
    • in_progress is now sent from claude's PreToolUse hook after a 100 ms wait, or when the adapter answers Allow to a permission request, and no longer while the model streams the input.
    • The PR description says where the moment is read from and what a client sees for calls that are denied, refused or cancelled.
    • The tests hold the order of the updates for a Write with a streamed input and for a Bash call, plus allowed, refused and rule-denied calls.
    • There is a CHANGELOG entry under [Unreleased] and a README line under "What's supported".
    • Nothing unrelated is changed.
  • Read the whole diff (446 lines) and the code around it: tools.go, toolcalls.go (result, denied, the removed progress), permission.go (canUseTool, shown), question.go, session.go (caughtUp, the hooks), and serve.go (after is the agent's clock).
    • The timer goroutine checks asked under the lock, and runningLocked checks started/ended, so a denial, a result or a cancel that comes before the wait ends sends nothing.
    • in_progress is sent at most once per call. Repeated tool_progress messages no longer send it again, and those updates carried nothing else.
    • The hook skips top-level plan tools, matching how they are kept off the client's list of calls.
  • Merge: origin/main (66af402) is the merge base, and the merge fast-forwards. Forge reports mergeable.
  • Ran with the city's variables removed (proved: 0):
    • go build ./... and go vet ./...: ok.
    • go test -race -shuffle=on -count=1 ./...: all packages ok.
    • go test -race -count=30 -run 'TestToolRunning|TestSubagentPermission' ./claudeacp/: ok.
    • golangci-lint v2.15.0: 0 issues.
    • The changelog checker built from mikluko/changelog at 7ec45bb (v1.6.0, the commit the workflow pins), run on the merged tree: valid=true, exit 0.
  • Not run: govulncheck (it needs the vulnerability database over the network). The head's CI run, which includes it, is green.
Review of eb2b36229fde4c9dd279653ec6cc45a286835200 for claudeacp-eoz. Checks of the head: success. ### Verdict pass ### Findings - [minor] claudeacp/question.go:59, claudeacp/permission.go:62: `shown` now sets `asked`, which turns off the grace timer. But two Allow paths return without calling `s.tools.running`: `askUser`, and `canUseTool` for `ExitPlanMode` when an option is picked (the early `return s.exitPlan(...)`). So an answered AskUserQuestion, and an ExitPlanMode the user accepts, go from `pending` straight to `completed` and never show `in_progress`. The README line says `in_progress` is sent when a call's tool starts to run. Both tools finish at once after the answer, so a client loses almost nothing. Either call `running` on those Allow paths, or name them in the README beside the server tools. ### Verified - Requirement (claudeacp-eoz) against the change: - `in_progress` is now sent from claude's `PreToolUse` hook after a 100 ms wait, or when the adapter answers Allow to a permission request, and no longer while the model streams the input. - The PR description says where the moment is read from and what a client sees for calls that are denied, refused or cancelled. - The tests hold the order of the updates for a Write with a streamed input and for a Bash call, plus allowed, refused and rule-denied calls. - There is a CHANGELOG entry under [Unreleased] and a README line under "What's supported". - Nothing unrelated is changed. - Read the whole diff (446 lines) and the code around it: `tools.go`, `toolcalls.go` (`result`, `denied`, the removed `progress`), `permission.go` (`canUseTool`, `shown`), `question.go`, `session.go` (`caughtUp`, the hooks), and `serve.go` (`after` is the agent's clock). - The timer goroutine checks `asked` under the lock, and `runningLocked` checks `started`/`ended`, so a denial, a result or a cancel that comes before the wait ends sends nothing. - `in_progress` is sent at most once per call. Repeated `tool_progress` messages no longer send it again, and those updates carried nothing else. - The hook skips top-level plan tools, matching how they are kept off the client's list of calls. - Merge: origin/main (66af402) is the merge base, and the merge fast-forwards. Forge reports mergeable. - Ran with the city's variables removed (proved: 0): - `go build ./...` and `go vet ./...`: ok. - `go test -race -shuffle=on -count=1 ./...`: all packages ok. - `go test -race -count=30 -run 'TestToolRunning|TestSubagentPermission' ./claudeacp/`: ok. - golangci-lint v2.15.0: 0 issues. - The changelog checker built from mikluko/changelog at 7ec45bb (v1.6.0, the commit the workflow pins), run on the merged tree: valid=true, exit 0. - Not run: govulncheck (it needs the vulnerability database over the network). The head's CI run, which includes it, is green.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
mikluko/claudeacp!6
No description provided.