Skip to content

feat(opencode): show round usage metadata - #1668

Open
junmo-kim wants to merge 2 commits into
tiann:mainfrom
junmo-kim:feat/opencode-round-metadata
Open

feat(opencode): show round usage metadata#1668
junmo-kim wants to merge 2 commits into
tiann:mainfrom
junmo-kim:feat/opencode-round-metadata

Conversation

@junmo-kim

@junmo-kim junmo-kim commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Problem

OpenCode previously exposed only the final ACP usage row to the UI. Tool-loop calls, compaction summaries, and synthetic continuations could therefore be omitted from the response metadata popover.

Solution

This change snapshots OpenCode persisted message IDs before each prompt, fetches the post-prompt delta, and aggregates every valid assistant row by provider/model. It sends an HAPI-owned round-summary carrier before ready and reuses the existing response-group metadata popover. Malformed data, duplicate IDs, unavailable APIs, parse failures, timeouts, and aborted requests fail closed by omitting only the summary.

Screenshots

Desktop (1440×1000) Mobile (390×844)
OpenCode Big Pickle round usage metadata on desktop OpenCode Big Pickle round usage metadata on mobile

Tests

  • Added CLI coverage for snapshot Abort/Switch, the fetch-plus-JSON deadline, duplicate IDs, strict aggregation, and carrier ordering.
  • Added Web coverage for strict carrier normalization, persisted wire grouping, tool-only responses, late metadata reconciliation, and legacy compatibility.
  • bun typecheck
  • bun run test
  • bun run build
  • git diff --check
  • Manually verified actual OpenCode 1.18.21 ACP with opencode/big-pickle end-to-end on desktop and mobile viewports, including a two-step tool loop and summary-before-ready ordering.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Findings

  • [Major] Keep telemetry off the prompt critical path — captureOpencodeRoundSnapshot() performs a full /message fetch and JSON parse before session.onThinkingChange(true) and backend.prompt(). Its deadline is 1 second, so a slow/unavailable OpenCode HTTP API delays every user prompt by up to a second; because the endpoint returns the complete history, the work also grows with session length. Evidence: cli/src/opencode/opencodeRemoteLauncher.ts:627, cli/src/opencode/utils/opencodeRoundSummary.ts:81, cli/src/opencode/utils/opencodeRoundSummary.ts:90.
    Suggested fix:
    private nextRoundSnapshot: OpencodeRoundSnapshot | null = null
    
    const roundSnapshot = this.nextRoundSnapshot
        ?? await captureOpencodeRoundSnapshot({ baseUrl, sessionId: acpSessionId, signal })
    this.nextRoundSnapshot = null
    
    // Return the validated post-fetch ID snapshot alongside the optional summary.
    const result = await fetchOpencodeRoundSummary({ ...options, snapshot: roundSnapshot })
    if (result) {
        this.nextRoundSnapshot = result.snapshot
        if (result.summary) this.handleAgentMessage({ type: 'round_summary', summary: result.summary })
    }

Summary

  • Review mode: initial
  • One major performance regression found in the OpenCode prompt path.

Testing

  • Not run (automation). GitHub test, integration, and drift-gate checks pass.
  • Add a launcher regression test proving a second prompt reuses the prior post-fetch snapshot and does not wait on another pre-prompt full-history request.

HAPI Bot

Comment thread cli/src/opencode/opencodeRemoteLauncher.ts Outdated

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Findings

  • No high-confidence issues found in the latest diff.

Summary
Review mode: follow-up after new commits

The prior Major finding is addressed: the launcher now reuses the validated post-fetch snapshot for subsequent prompts and invalidates it before explicit compaction. Residual risk remains around compatibility with OpenCode's internal message API; the implementation fails closed by omitting metadata.

Testing

  • Local tests not run: Bun is unavailable in the review environment.
  • GitHub test, integration, and fixture drift-gate checks pass.
  • git diff --check passes.

HAPI Bot

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