Skip to content

record model attempts without changing selected turn usage - #437

Merged
xandreeddev merged 2 commits into
mainfrom
model-call-usage
Oct 31, 2026
Merged

xandreeddev merged 2 commits into
mainfrom
model-call-usage

Conversation

@xandreeddev

Copy link
Copy Markdown
Owner

What

Model-call accounting now retains retries, discarded responses, interrupted streams and helper completions with the actual invoked model and unknown, partial or final reported usage. Stored format 9 adds model.called; the public APIs add CurrentModelCallRecorder, recordCompletion, turnModelCallsOf and turnBilledUsageOf. Selected run and turn usage keeps its existing meaning.

The recorder flushes before retry or Agent tool admission, keeps one terminal acknowledgment per attempt, and preserves recording failures across SDK boundaries. Turn-owned telemetry includes bootstrap and late-finalizer helpers, reports coverage and unpriced calls, and avoids counting selected usage twice. UtilityCompletion.model optionally exposes the actual selection. Released journal fixtures and golden prompts remain compatible; only the current unreleased fixture is refreshed.

Checks

  • Full source suite: 3,024 passed, 4 expected skips, 0 failures.
  • Typecheck, Foundry checks and demo, package build, strict packed verification, stable generated docs and website checks.
  • Packed Node and Bun consumers: 16 retry/accounting scenarios, 13 raw-failure/accounting scenarios, six recorder conformance checks, and helper/finalizer pricing with selected 38 versus billed 114 tokens.
  • Required proxy suites on Bun 1.3.6: 46 passed, 2 expected skips, 0 failures.

These key-free fixtures establish framework and protocol behavior. Reported subtotals, unknown usage and terminal-only crash gaps do not establish an exact provider invoice.

Persist terminal model.called facts for real dispatches, including retries, helpers, discarded completions and interrupted streams. Preserve actual model selections and unknown, partial or final reported usage while keeping selected run and turn totals unchanged.

Keep recording durable through bootstrap and late helpers, retain one acknowledgment per attempt and stop replay after recording failures. Price the call ledger through turn-owned telemetry, add its conformance kit and readers, and advance the stored format to 9 while retaining released journal compatibility.
Name recordCompletion's TurnError through core's own session module so the emitted declaration does not infer an SDK dependency through its re-export. The annotation leaves the generated runtime code unchanged.
@xandreeddev
xandreeddev merged commit a94dc5a into main Oct 31, 2026
1 check passed
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