Skip to content

[Feat] Report OpenCode setup phases and model usage in Fast turn diagnostics - #2029

Merged
mrubens merged 2 commits into
developfrom
feat/fast-turn-inference-diagnostics
Sep 2, 2026
Merged

[Feat] Report OpenCode setup phases and model usage in Fast turn diagnostics#2029
mrubens merged 2 commits into
developfrom
feat/fast-turn-inference-diagnostics

Conversation

@mrubens

@mrubens mrubens commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Why

Fast's Turn finished line lumps server spawn, session validation, and session creation into one inferenceSetupDurationMs, and says nothing about how many model requests a turn made, how big its context was, or how much inference ran after the last visible reply. On the nightly, model time to first reply is 9–21 s and the turn keeps running 10–25 s after the closeout; without these numbers there's no way to tell a slow provider from an oversized prompt or a wasted trailing request.

What

  • runNonTaskSdkPrompt times each setup phase (server lease, session validate, session create, event subscribe) and passes them to onPromptStarted. Completed-message callbacks now carry the token usage OpenCode attached to the message.
  • FastAgentTurnDiagnostics aggregates them, deduplicating the final prompt result against the event stream by message id, and adds to the log line and the fast_turn_settled telemetry event:
    • openCodeServerLeaseMs, openCodeSessionValidateMs, openCodeSessionCreateMs, openCodeEventSubscribeMs, openCodeSetupMs
    • modelRequestCount, completedModelRequestCount, firstModelResponseDurationMs, postReplyInferenceDurationMs
    • inputTokens, cacheReadTokens, cacheWriteTokens, outputTokens, reasoningTokens, maxContextTokens
    • systemPromptChars, environmentCount, integrationCount, integrationToolCount, activeTaskCount
  • Counts and durations only; no prompt, reply, or tool content is logged.

Sample (local turn)

openCodeServerLeaseMs=2020 openCodeSessionCreateMs=44 openCodeSetupMs=2065
modelRequestCount=2 firstModelResponseDurationMs=3426 postReplyInferenceDurationMs=1648
inputTokens=10897 cacheReadTokens=10624 outputTokens=37 reasoningTokens=0 maxContextTokens=10790
systemPromptChars=29388 environmentCount=4 integrationToolCount=0

Verification

  • New diagnostics test covers setup phases, request counting, token totals, dedup of the repeated final message, and the retry-attempt setup not overriding the first.
  • src/server/fast-agent and provider-usage suites: 410 tests pass. Typecheck, oxlint, knip, and pre-push clean.

…nostics

The Turn finished line lumped server spawn, session validation, and
session creation into inferenceSetupDurationMs, and said nothing about
how many model requests a turn made, how large its context was, or how
much inference ran after the last visible reply. Those are the numbers
needed to tell a slow provider from an oversized prompt.

The OpenCode prompt runner now reports per-phase setup timings through
onPromptStarted and attaches token usage to completed-message callbacks.
The diagnostics aggregate them into the log line and the settled-turn
telemetry event: server lease, session validate/create, event subscribe,
model request count, first model response latency, post-reply inference
time, input/cached/output/reasoning tokens, peak context size, system
prompt size, and integration tool count. Counts only; no prompt or reply
content.
@roomote-community

roomote-community Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

No code issues found. See task

  • fast_turn_settled omits several newly collected diagnostics from telemetry (packages/cloud-agents/src/server/fast-agent/fast-agent-turn-diagnostics.ts:410).

Reviewed 13c6275

The event now carries every count and duration the log line does:
completed model requests, cache-write tokens, each OpenCode setup phase,
and the environment, integration, and active-task counts.
@mrubens
mrubens merged commit 7bc43ac into develop Sep 2, 2026
17 checks passed
@mrubens
mrubens deleted the feat/fast-turn-inference-diagnostics branch September 2, 2026 03:36
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