opencode icon indicating copy to clipboard operation
opencode copied to clipboard

acp: usage_update is not sent when a turn fails

Open BambinoSK opened this issue 3 days ago • 1 comments

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

  1. Start opencode acp, then initialize and session/new.
  2. 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).
  3. The session/prompt call returns an error and no usage_update notification is sent for that turn.

BambinoSK avatar Nov 28 '26 17:11 BambinoSK

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.

fanyzp avatar Nov 28 '26 17:11 fanyzp

Hi — I'm reproducing this now and preparing a fix; I'll open a PR shortly.

four1er avatar Nov 28 '26 20:11 four1er