Skip to content

feat(observability): record how long each model call took and how often it was retried - #229

Merged
goldbarth merged 1 commit into
mainfrom
feat/128-call-duration-retries
Sep 22, 2026
Merged

goldbarth merged 1 commit into
mainfrom
feat/128-call-duration-retries

Conversation

@goldbarth

@goldbarth goldbarth commented Sep 22, 2026 •

Copy link
Copy Markdown
Owner

Closes #128

  • Time per call, per operation, per run: ChatModel times every model call, retries included, and the pipeline times the run from reading history to the last model call. The summary shows each operation's total and its longest call - one slow call and uniformly slow calls call for different fixes - and the run's total next to its tokens.
  • Retries counted from the wire, for every provider: both provider SDKs retry on their own through the HttpClient they are given. A DelegatingHandler under each client (ModelRequestCountingHandler) reports every request to a counter that flows with the call's async context (Core/Llm/ModelCallAttempts); requests beyond the first are retries. No provider type is named in the domain, and a client Chartula did not build reports nothing, which reads as not observed, never as zero.
  • Failed calls recorded, not lost: a call that throws is recorded as failed with its time and requests, then rethrown. Its time counts, it is kept out of calls (which counts answers) and out of the unreported-usage lower bound.
  • SDK timeouts unchanged: the supplied HttpClient has an infinite timeout, as the SDKs' own clients do (checked by reflection); both SDKs still enforce their own timeout through it (checked with a slow stub: OpenAI NetworkTimeout and Anthropic Timeout both fire at 1 s).
  • LlmCall record: IRunMetrics.RecordLlmCall takes one record (tokens, duration, attempts, failed) instead of loose counts, so the next usage fields (reasoning and cached tokens) are additions, not signature changes.
  • Run record: failedCalls, durationSeconds, longestCallSeconds, retries (left out when not observed) per operation, and durationSeconds for the run. Additive under schemaVersion: 1; a record written before reads with zeros.
  • Docs: run-metrics.md (new "When a run was slow"), run-record.md. parked removed from [Feature] Record the duration and the retries of every model call in the run metrics #128.

Verified end to end: the release binary against a local OpenAI-compatible fake that answers the first request with 503 and the next after 1.5 s:

  Rephrasing:       1 call, 6,000 in / 20 out, 1.7 s
  Total:            6,020 tokens in 4.6 s
  Retries:          1 (rephrasing 1)

Tests: ModelCallTimingTests (late answer, failed call, retries from reported requests, not observed without a transport), ModelRequestCountingTests (real Anthropic and OpenAI SDKs retrying once through the handler, first-time answer is 0 not unknown, infinite client timeout), RunMetricsTests, RunReportFormatterTests, RunRecordJsonSerializerTests (fields, omission, older records), ReleasePipelineMetricsTests (run duration); full suite 715 passing, build and dotnet format clean.

@goldbarth
goldbarth merged commit cc6efce into main Sep 22, 2026
4 checks passed
@goldbarth
goldbarth deleted the feat/128-call-duration-retries branch September 22, 2026 15:47
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.

[Feature] Record the duration and the retries of every model call in the run metrics

1 participant