fix(acp): drop mid-stream usage emit; OpenCode only sends usage_update at end-of-turn#760
Merged
Merged
Conversation
…e at end-of-turn PR tiann#756 added a mid-turn emit in captureUsageUpdate to surface live context usage via the web status bar. Testing against OpenCode 1.15.11 on a real session shows OpenCode emits a single usage_update per turn, within ~1ms of session/prompt resolving — never during streaming. That makes the mid-turn path dead code for OpenCode (and for any other ACP agent that follows the same pattern). It also persists a useless inputTokens:0/outputTokens:0 token_count message that gets immediately overwritten by the finalize emit, churning the session history. Drop the mid-stream emit and the activeOnUpdate plumbing it required. Keep the finalize fallback for agents that don't return a usage block on session/prompt (slash-handled turns, errored turns). The persistent "live" counter requires the agent to emit usage_update during streaming; filed upstream against anomalyco/opencode. Refs tiann#750 via [HAPI](https://hapi.run) Co-Authored-By: HAPI <noreply@hapi.run>
There was a problem hiding this comment.
Findings
None.
Summary
Review mode: initial
No issues found in the modified ACP usage handling. Residual risk: targeted test execution could not be verified in this runner because bun is unavailable.
Testing
Not run (automation): bun test cli/src/agent/backends/acp/AcpSdkBackend.test.ts failed with bun: command not found.
HAPI Bot
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.
Summary
usageemit incaptureUsageUpdateand theactiveOnUpdateplumbing that supported it.session/promptreturned nousageblock) — that still helps slash-handled or errored turns.Why
PR #756 assumed OpenCode would emit ACP
usage_updatenotifications throughout a streaming turn so the web status bar could tick live. Real-session debug logs against OpenCode 1.15.11 show otherwise:```
[15:23:38.714] usage_update raw={used:14388, size:65536}
[15:23:38.715] session/prompt response ← 1ms later
[15:23:39.086] finalize promptUsage={inputTokens:52, …}
```
OpenCode emits exactly one
usage_updateper turn, within ~1ms of thesession/promptresponse. So the mid-turn emit:inputTokens: 0 / outputTokens: 0token_countmessage that gets overwritten ~370ms later by the real one — churn in session history for zero observable gain.Removing it puts us back to the simpler state machine and leaves only the genuinely useful finalize fallback. A real live counter requires OpenCode (or any other ACP agent) to start emitting
usage_updateduring streaming; filed upstream at anomalyco/opencode.Refs #750
Test plan
🤖 Generated with Claude Code