Skip to content

fix(statistics): clamp delegated counts, exact task cost, monotonic ordering - #32

Open
efirvida wants to merge 3 commits into
upstream/statistics-03-delegated-cost-transportfrom
upstream/statistics-04-delegated-cost-review-fixes
Open

efirvida wants to merge 3 commits into
upstream/statistics-03-delegated-cost-transportfrom
upstream/statistics-04-delegated-cost-review-fixes

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 4 of 27
Base upstream/statistics-03-delegated-cost-transport
Depends on #31
Follow-up upstream/statistics-04-delegated-cost-review-fixes (slice 5)
Review budget 177 / 400
Starts at upstream/statistics-03-delegated-cost-transport
Ends with fix(statistics): clamp delegated counts, exact task cost, monotonic ordering

Chain Overview

upstream/main
 └── upstream/statistics-tracker (root, integration PR #1627)
      └── … slices 1..3 … (##31 is the immediate parent)
           └── 📍 upstream/statistics-04-delegated-cost-review-fixes
                └── … slices 5..27 …

Scope

  • Includes: fix(statistics): clamp delegated counts, exact task cost, monotonic ordering
  • Excludes: every other slice. A polluted diff against upstream/statistics-03-delegated-cost-transport 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.

…cost

CodeRabbit review response:
- accumulateTaskCost keeps each step on the integer nano-USD grid, so
  repeated nine-decimal deltas no longer drift (agents-runner's cost
  assertion updated from 0.30000000000000004 to the exact 0.3).
- The publisher clamps the delegated event's diagnostic counts to the
  payload bound, so a session with more than 4096 retained tasks still
  publishes instead of silently dropping the total.
- The shell ignores an out-of-order delegated event (older at) so a
  stale publish can never replace a newer total.
- Added docstrings across the touched usage/delegated seams.
The ordering guard compared payload.at (Date.now()), so a backward wall-clock
adjustment could make a newer total look stale. The publisher now stamps each
event with a monotonic seq and the shell orders by it; at stays diagnostic only.
Tests updated.
A transcript reports cost split by input, output, cacheRead and cacheWrite,
and a billing report needs that split without re-deriving it. Add
`UsageCostBreakdown` as an optional, additive field on the canonical
`SessionUsageRecord`; each component carries its own reported/absent
provenance exactly as the total already does, so an absent component is
never read as a reported zero.

I3 (issue #3), part of the session statistics epic (#1).
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