Skip to content

feat(kernel): define model-usage accounting contracts - #2841

Merged
jbeda merged 6 commits into
mainfrom
impl/2663-model-usage
Nov 18, 2026
Merged

jbeda merged 6 commits into
mainfrom
impl/2663-model-usage

Conversation

@jbeda

@jbeda jbeda commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Add independent model-usage accounting to the isolated kernel, following #2793 as part of #2663 / #2659. This is best-effort showback, not chargeback. Production capture/integration remains out of scope; neither issue is closed.

  • Give each usage a history-scoped identity, immutable purpose/correlation, and a replaceable report. Reports can arrive after a run ends, decrease, be withdrawn, or be restored.
  • Preserve unknown versus explicit-zero counters, configured route/model labels, and opaque usage evidence. Replace embedded usage in responses and failure/capture evidence without changing execution lifecycle rules.
  • Validate request membership in O(1) using per-run counts. Keep snapshot capture O(1); Snapshot.Usages() explicitly scans the pinned history to join first definitions with latest reports.

See design context for the accounting boundaries.

API compatibility

No production wire/API behavior, feature identifiers, wire-major changes, or existing-client upgrades. Experimental kernel Go contracts and stored data intentionally change: removed embedded usage fields fail strict decoding under the existing session Version 1. This break was explicitly approved; there is no migration, dual reader, or compatibility alias.

Verification

Passed kernel/history-adapter/architecture race tests, standalone engine build and tests, lint, docs, API snapshots, and generation freshness. Regressions cover Submit/Load, correlation, replacement, rollback, ownership, and accounting exclusion from logical model requests; scaling benchmarks cover historical membership checks.

Full repository test/race suites and the production demo were not rerun for this isolated-kernel change.

Add history-scoped usage identities, accounting DTOs, immutable views,
and focused validation, codec, ownership, and presence tests.

This is the task-1 contract review checkpoint only. Aggregate admission,
authoring, effective inspection, and embedded-usage replacement remain
pending review.

Refs #2663, #2659

Co-authored-by: Mecatl <[email protected]>
@jbeda

jbeda commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor Author

Design context

Usage is separate from execution outcomes because accounting can arrive late, cover auxiliary work, or be corrected independently. Correlation establishes membership—not accurate attribution, complete capture, or a bill.

Each usage keeps its first definition and replaces its entire report on update; reports are not additive deltas. Missing counters mean unknown, not zero. Cache/reasoning counters are included breakdowns, not extra consumption to add to input/output totals. Route/model labels describe configured selections, not verified serving or charging identities.

Aggregate caches, rollup helpers, pricing, and production integration are deferred. Clients can consume chronological reports and maintain their own latest-per-identity accounting. Snapshot.Usages() provides an explicit read-side join without increasing snapshot-capture cost.

jbeda and others added 5 commits November 17, 2026 15:26
Flatten selected route and model labels onto usage buckets, align their
terminology with ModelBinding, and defer observed and charging identities
until concrete reporting use cases justify them.

Clarify zero Go values versus reported zero token counts, regenerate
codecs, views and API snapshots, and retain validation, ownership and
presence regression coverage.

Co-authored-by: Mecatl <[email protected]>
Keep only the established main usage purpose and document DTO reuse at authoring boundaries.

Co-authored-by: Mecatl <[email protected]>
Add passive usage admission, complete report replacement, and snapshot inspection. Remove embedded accounting from model outcomes and prove Submit/Load ownership, resource policy, and logical request isolation.

Co-authored-by: Mecatl <[email protected]>
Keep package orientation ahead of workflow and ownership details, and leave type-specific and generator contracts with their owners.

Co-authored-by: Mecatl <[email protected]>
Retain append-only per-run request counts instead of scanning history during usage admission. Clarify lifecycle and admission state contracts, document append complexity, and cover ownership and scaling.

Co-authored-by: Mecatl <[email protected]>
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