Repository navigation
feat: add response_size_bytes metric to chatd - #29816
Conversation
Docs previewCheck off each page once it's been reviewed. If a page changes in a later push, its checkbox clears automatically so it gets a fresh look. Pages not yet wired into the docs navigation aren't listed here. |
| } | ||
| return AssistantOutcome{}, wrappedErr | ||
| } | ||
| opts.Metrics.ResponseSizeBytes.WithLabelValues(provider, modelName).Observe(float64(result.responseBytes)) |
There was a problem hiding this comment.
since we're recording after the error check, we are technically missing response bytes if the response was interrupted, for whatever reason. Could we record them all?
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7c43e36733
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| } | ||
|
|
||
| case fantasy.StreamPartTypeToolInputDelta: | ||
| result.responseBytes += len(part.Delta) |
There was a problem hiding this comment.
Count boundary deltas in tool-input sizes
When a provider places tool-input bytes in tool_input_start or tool_input_end, this only increments the metric for tool_input_delta, so tool-heavy responses are undercounted. This is a supported stream shape exercised in coderd/x/chatd/chatdebug/model_normalization_internal_test.go:179-184, where both boundary events carry distinct argument chunks; count part.Delta for all three incremental tool-input event types without counting the final ToolCall summary again.
Useful? React with 👍 / 👎.
| } | ||
| return AssistantOutcome{}, wrappedErr | ||
| } | ||
| opts.Metrics.ResponseSizeBytes.WithLabelValues(provider, modelName).Observe(float64(result.responseBytes)) |
There was a problem hiding this comment.
Record bytes from failed streaming attempts
When a stream emits text, reasoning, or tool-input chunks and then returns an error, processStepStream returns the accumulated byte count but the error branch above exits before this observation. Those bytes crossed the model boundary and the documented per-LLM-request histogram should include them; otherwise _sum underreports output throughput and _count no longer corresponds to requests during provider failures or retries.
Useful? React with 👍 / 👎.
e75bc9d to
f276efb
Compare
|
@ethanndickson updated both the observation location (before potential errors) as well as the counting of result bytes for additional results that were missed before. For the latter, the current expected behaviour is really just checked via the newest test, and I left a comment to that effect as well. |
| // Counts Delta on every part type. This relies on providers keeping | ||
| // summary data, such as ToolCall input, out of Delta. Only | ||
| // TestGenerateAssistant_ResponseSizeBytesByPartType checks this, so | ||
| // update it when adding new part types. | ||
| result.responseBytes += len(part.Delta) |
There was a problem hiding this comment.
| // Counts Delta on every part type. This relies on providers keeping | |
| // summary data, such as ToolCall input, out of Delta. Only | |
| // TestGenerateAssistant_ResponseSizeBytesByPartType checks this, so | |
| // update it when adding new part types. | |
| result.responseBytes += len(part.Delta) | |
| result.responseBytes += len(part.Delta) |
agent yap
Add a coderd_chatd_response_size_bytes histogram recording the byte size of streamed model response content (assistant text, reasoning, and tool-call input deltas) per LLM request, labeled by provider and model. Together with the existing prompt_size_bytes and tool_result_size_bytes histograms, this completes the coderd<->LLM input/output byte throughput picture (rate(..._sum) gives bytes/s). Bytes are accumulated from stream content deltas and recorded once per step, mirroring prompt_size_bytes. Generated with Coder Agents.
…processing fails Observe response size before handling stream errors so responses that fail partway are still counted.
…deltas Count Delta on every stream part so tool input bytes on tool_input_start and tool_input_end are included. The ToolCall summary is not counted since it repeats the streamed tool input.
f276efb to
e4b87b4
Compare
What
Add a
coderd_chatd_response_size_byteshistogram recording the byte size of streamed model response content (assistant text, reasoning, and tool-call input deltas) per LLM request, labeled byproviderandmodel.Why
We had
prompt_size_bytes(input) andtool_result_size_bytesbut nothing for model output, so there was no way to measure output throughput of the chat system. With this metric, the coderd↔LLM input/output byte throughput is fully covered:rate(coderd_chatd_prompt_size_bytes_sum[5m])rate(coderd_chatd_response_size_bytes_sum[5m])A histogram (rather than a counter) keeps it consistent with the existing size metrics and gives both throughput (
_sum) and per-response size distribution.Implementation
TextDelta,ReasoningStart/ReasoningDelta,ToolInputDelta) inprocessStepStreamand recorded once per step, at the same call site asprompt_size_bytes.prompt_size_bytes), not HTTP/SSE wire framing.tool_result_size_bytes).Tests
metrics_test.go: registration + NopMetrics coverage.chatd_test.go(TestActiveServer_RecordsGenerationMetrics): asserts the metric is recorded with a positive sum on a streamed response.Opened by Coder Agents on behalf of @cstyan.