Repository navigation
feat(kernel): define model-usage accounting contracts - #2841
Conversation
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]>
Design contextUsage 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. |
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]>
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.
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.