[Fix] Costs miss Fast mode inference usage - #1630
Merged
Merged
Conversation
Contributor
|
No new commits since the last review. See task
Reviewed 61ad44d |
Contributor
Author
|
Fixed the remaining long-lived event-stream wait in 9ac3ba9: the final-event barrier now expires after one second, clears its waiter, and runs the bounded current-turn fallback. Regression coverage uses a non-terminating stream that omits the final event. Targeted tests pass (98), package typecheck and touched-file checks pass, and the full pre-push gates pass. |
mrubens
marked this pull request as ready for review
August 25, 2026 13:18
mrubens
requested review from
brunobergher,
daniel-lxs and
mrubens
as code owners
August 25, 2026 13:18
- Bound and cancel fallback reconciliation calls: session.messages and session.children now carry an abort signal linked to the prompt's controller plus a 5s reconciliation deadline, so a wedged OpenCode server can no longer stall the reply or hold the leased server. - Discover child sessions for the fallback via session.children instead of event-stream bookkeeping, so a mid-turn stream failure cannot hide subagent usage, and bound them to sessions created in the current turn so a warm shared conversation's historical usage is never re-recorded under the current requester. - Warn when the final message has no parent id and intermediate parent usage cannot be reconciled. - Drain in-flight usage recordings in the prompt finally block so event- driven writes settle on error paths too and late recordings cannot outlive the call. - Hoist the event-monitor gate into needsEventMonitor so the subscribe and race sites cannot drift.
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.
What changed
non-task:<source>:<session>:<message>idempotency key and original participant ownership.Why this change was made
Fast mode previously recorded only the final parent response. Intermediate parent turns and advisor/judge sessions incurred inference cost but were omitted from
llm_usage_events, causing Costs analytics to undercount Fast usage.Impact
Costs now includes the complete successful Fast turn without rewriting historical usage ownership or doing work proportional to the warm conversation's lifetime. OpenCode 1.18.10's
AssistantMessage/message.updatedcontract does not expose a stable provider request or generation identifier, so this PR does not guess one from untyped part metadata. The precise reconciliation follow-up is to expose that identifier in OpenCode's assistant-message event contract, then persist it in usage-event details (or dedicated columns if it becomes a query key) for matching against OpenRouter generation exports.Validation