Skip to content

fix(statistics): stop coercing unreported tokens to a measured zero - #55

Open
efirvida wants to merge 1 commit into
upstream/statistics-26-billable-bounded-collectionfrom
upstream/statistics-27-token-availability
Open

efirvida wants to merge 1 commit into
upstream/statistics-26-billable-bounded-collectionfrom
upstream/statistics-27-token-availability

Conversation

@efirvida

@efirvida efirvida commented Oct 1, 2026

Copy link
Copy Markdown
Owner

Chain Context

Field Value
Chain per-session statistics module (upstream Gentleman-Programming#1583)
Tracker upstream/statistics-tracker → upstream integration PR Gentleman-Programming#1627 (draft)
Position 27 of 27
Base upstream/statistics-26-billable-bounded-collection
Depends on #54
Follow-up None — last slice
Review budget 244 / 400
Starts at upstream/statistics-26-billable-bounded-collection
Ends with fix(statistics): stop coercing unreported tokens to a measured zero

Chain Overview

upstream/main
 └── upstream/statistics-tracker (root, integration PR #1627)
      └── … slices 1..26 … (##54 is the immediate parent)
           └── 📍 upstream/statistics-27-token-availability
                └── … slices 28..27 …

Scope

  • Includes: fix(statistics): stop coercing unreported tokens to a measured zero
  • Excludes: every other slice. A polluted diff against upstream/statistics-26-billable-bounded-collection is a branching bug, not a scope surprise.

Verification

Focused and affected suites are green on this slice; tests and docs for this unit ship with it.

The no-coercion rule that cost already satisfies never reached tokens: a
usage payload with an empty or partial counter set summed to 0 and the
aggregate reported that figure as measured. Measured evidence on a real
profile: 163 of 163 subagent records on one provider family carry
tokens 0, indistinguishable from a reported zero.

Carry the same availability state cost uses, one layer at a time:

- SessionUsageRecord gains `tokensComplete`; absent means complete for a
  legacy record, a reported all-zero set stays complete.
- parseTranscriptLine reads each counter through a finite reader and
  records a missing counter instead of inventing a measured zero. A
  stored line states the flag explicitly so an incomplete record
  survives the round trip; the task dir scan is unchanged.
- The aggregate folds that state the way it folds cost: one absent
  record makes the token figure partial for good, and every breakdown
  inherits it.
- UsageEvent carries `tokensComplete` and TaskRecord accumulates it with
  `accumulateTaskTokens`, the exact counterpart of `accumulateTaskCost`.
  An all-zero or empty usage is "not reported", matching childTokens:
  the SDK injects zeros, so zero is not presence evidence.
- The panel marks a partial token figure with the `+` the legend already
  documents, and the contract states the rule.

Where a counter is missing the sum remains the known lower bound; it is
the provenance flag that keeps it honest. Verified: 68 focused tests and
259 affected-suite tests green, typecheck at the 187-diagnostic baseline
with no regressions.
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