Skip to content

[Fix] Fast mode underreports inference costs during multi-agent turns - #1632

Closed
roomote-roomote[bot] wants to merge 1 commit into
developfrom
fix/fast-inference-usage-23iajwo9y9edo
Closed

[Fix] Fast mode underreports inference costs during multi-agent turns#1632
roomote-roomote[bot] wants to merge 1 commit into
developfrom
fix/fast-inference-usage-23iajwo9y9edo

Conversation

@roomote-roomote

Copy link
Copy Markdown
Contributor

​Opened on behalf of @mrubens. Follow up by mentioning @roomote-roomote, in the web UI, or in Slack.

What changed

  • Persist completed intermediate Fast parent messages and completed advisor/judge child-session messages from OpenCode events.
  • Reconcile the current Fast session tree before releasing the OpenCode server lease so delayed or missed completion events still reach llm_usage_events.
  • Reuse stable non-task:<source>:<session>:<message> keys, preserving user, source, optional task, provider, model, agent, token, and cost attribution through idempotent upserts.
  • Cover live events, reconciliation, duplicate keys, production Fast attribution, and Costs analytics inclusion with focused regression tests.

Why this change was made

Fast previously persisted only the final parent prompt result. Intermediate parent model calls and advisor/judge sessions could therefore be billed by the provider without appearing in Roomote Costs analytics.

Impact

Fast multi-step and multi-agent turns now produce complete non-task inference cost rows, including user attribution and the expected fast_agent source. Existing standard-task accounting and the database schema are unchanged.

OpenCode 1.18.10 does not expose an upstream OpenRouter request or generation identifier on assistant-message or step-finish events. Exact row-level provider reconciliation remains a focused follow-up: when the SDK exposes that identifier, persist it in the existing usage details or pricingMetadata fields without adding another usage table.

@roomote-community

roomote-community Bot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

1 issue outstanding. See task

  • packages/cloud-agents/src/server/non-task-provider-usage.ts:981 does not reconcile completed child usage when the parent Fast prompt fails.

Reviewed 9e85a31

@mrubens mrubens closed this Aug 25, 2026

await recordNonTaskOpenCodeUsage(params, model, promptResult.data.info);

if (options.onSubagentSessionReady) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reconciliation only runs after the parent prompt succeeds. If Fast delegates to an advisor/judge, their completion events are missed, and the parent then returns an error or times out, control jumps to the outer catch before this block and none of the completed child usage is recovered. Those failed turns still incur provider cost, so move reconciliation into a finally/error-safe path (while retaining the original prompt error) and add a regression case for a failed parent after a completed child.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant