[Feat] Report OpenCode setup phases and model usage in Fast turn diagnostics - #2029
Merged
Conversation
…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.
Contributor
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.
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.
Why
Fast's
Turn finishedline lumps server spawn, session validation, and session creation into oneinferenceSetupDurationMs, 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
runNonTaskSdkPrompttimes each setup phase (server lease, session validate, session create, event subscribe) and passes them toonPromptStarted. Completed-message callbacks now carry the token usage OpenCode attached to the message.FastAgentTurnDiagnosticsaggregates them, deduplicating the final prompt result against the event stream by message id, and adds to the log line and thefast_turn_settledtelemetry event:openCodeServerLeaseMs,openCodeSessionValidateMs,openCodeSessionCreateMs,openCodeEventSubscribeMs,openCodeSetupMsmodelRequestCount,completedModelRequestCount,firstModelResponseDurationMs,postReplyInferenceDurationMsinputTokens,cacheReadTokens,cacheWriteTokens,outputTokens,reasoningTokens,maxContextTokenssystemPromptChars,environmentCount,integrationCount,integrationToolCount,activeTaskCountSample (local turn)
Verification
src/server/fast-agentand provider-usage suites: 410 tests pass. Typecheck, oxlint, knip, and pre-push clean.