acp: usage_update is not sent when a turn fails
Description
Over ACP, when a prompt turn ends in an error (provider error, rate limit, auth), opencode replies with the error but never sends usage_update. Usage from the turn's earlier steps, and from the failed step when the provider reports tokens, never reaches the client, so ACP clients undercount context and cost. Successful, cancelled and content-filtered turns do send it.
The adapter already counts these tokens (session.step.failed is folded into the turn usage). In settle in packages/cli/src/acp/turn.ts, the failure returns before sendUsageUpdate runs. packages/cli-rs/crates/acp/src/turn.rs has the same order. Sending the usage update before returning the error would fix it; the error response itself can't carry PromptResponse.usage.
Related but different: #66734 asks for usage at session start and after each model call.
Plugins
None
OpenCode version
2.4.2, still present on dev
Steps to reproduce
- Start
opencode acp, theninitializeandsession/new. - Send a prompt that makes at least one tool call, then fails on a later model call (e.g. the provider returns a rate limit or 500).
- The
session/promptcall returns an error and nousage_updatenotification is sent for that turn.
confirmed — reproduced it with a wire test: a turn with a completed step (171 tokens) followed by a step that fails with a provider rate-limit error returns the error and never sends usage_update. the failure path in settle (packages/cli/src/acp/turn.ts) returns before sendUsageUpdate runs, so the tokens from the earlier step never reach the client. same order in packages/cli-rs/crates/acp/src/turn.rs. working on a fix.
Hi — I'm reproducing this now and preparing a fix; I'll open a PR shortly.