Repository navigation
perf(telemetry): a report reads its period, not the whole history - #1032
Merged
Merged
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VWNxk63AGKkqE8HRqHLjGp
A report with --days, --from or --to now loads only the days of its period and the day on each side, plus any monthly file one of them falls in, and settles only what it read. A report with no period reads and settles the whole ledger, as before. The copies of one call are less than a day apart (0.3 h at most over 262,631 real keys), so a call with a copy in the period has every copy in the window and folds to the same record: a fast-check property checks the bounded envelope equals the full report filtered, byte for byte. UsageLedger.load takes a test on the day instead of a set of days, so a window costs the partitions on disk, not the length of the period. One year at 3,400 calls a day: --days 7 goes from about 4.2 s to 95 ms. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VWNxk63AGKkqE8HRqHLjGp
Review round 1: shiftDay in the stored usage domain replaces three copies of the day length and its arithmetic; the failing storage and the September to November days are shared test helpers. The usage skill's envelope reference, the usage contract and the task contract say what a bounded report reads, and evidence.md records the mutation run. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VWNxk63AGKkqE8HRqHLjGp
Review round 2: say outside the observed bound only an unbounded report folds every copy, and that skipped_ledger_lines covers a month kept in one file. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VWNxk63AGKkqE8HRqHLjGp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🎯 What & why
aidd telemetry report --days 7used to read, fold and settle the whole ledger, then keep a week of it. Its cost grew with the history. A report with a period now reads only that period's days. On one year at a real rate (3,400 calls a day, 1.24M calls),--days 7goes from ~4.2 s to ~95 ms, with the same figures. Follow-up of #1001, which left report cost out of scope.🛠️ How it works
fromto the day afterto; an open side stays open (period.ts:40). A report with no period reads and settles everything, as before (report-usage-use-case.ts:66).foldUsagekeeps the minimum of a total order, so the same copies give the same winner. Attribution is per call (attribution.ts:146), so calls left out of the window change no task or ticket. Full reasoning in contract.md.--from 0001-01-01, costs the partitions on disk, not millions of set entries. Ingest passesdays.has.shiftDay(stored-usage.ts:43) replaces three copies of the day arithmetic.🧪 How to verify
cd cli && pnpm test: 6512 passed, 1 skipped.--jsonenvelope equals the full report filtered, byte for byte, and the settled ledger folds to what a full read keeps.pnpm test:mutation:telemetry: 96.2 on the final commit (floor 96). The one survivor on a changed line is equivalent.pnpm smoke: 132/0/1.node scripts/check-claude-tokens-end-to-end.cjs(and--attended):2 calls, 393 tokens, all on task demo, ticket T-1.--days 7--days 7skipped_ledger_linescounts damage in the partitions read. A bounded report does not see damage outside its window.✅ I certify
🤖 Generated with Claude Code