Skip to content

refactor(telemetry): simplest, deterministic, true - #1054

Merged
blafourcade merged 11 commits into
nextfrom
refactor/telemetry-simplest-true
Oct 17, 2026
Merged

blafourcade merged 11 commits into
nextfrom
refactor/telemetry-simplest-true

Conversation

@blafourcade

Copy link
Copy Markdown
Contributor

🎯 What & why

Simplifies the R1 telemetry code under one rule: the simplest design that stays deterministic and true. A Claude Code call with no requestId (0 of 265,472 usage lines measured, Claude Code 2.1.232 to 2.1.302; 0 of 512,820 before) is no longer stored. It is counted in coverage.left_out.requestless, so the code that kept such calls folded across days is deleted. The local-path guard becomes line-based. The process rule is written once.

🛠️ How it works

  • One predicate, isRequestless (claude-transcript-usage.ts): a Claude Code key naming its own session, as this version (msg:session) or cli-v5.5.0 (msg:session:time) wrote it.
    • Ingest: the call is left out, hashed by tool, message and session (ingest-usage-use-case.ts).
    • Migration: one pass over the whole ledger moves what an earlier version stored into left-out.txt before its rewrite (stored-usage-migration.ts).
    • Every read: parseStoredUsage does not accept such a line. One an older CLI writes after the migration is kept as found and counted in run.skipped_ledger_lines, like any line this version does not accept. It is not a figure, so left_out never depends on the days a report reads.
  • Deleted: isKeyedBySession, the full-ledger read in storeCalls, legacy-usage-key.ts (re-keying), the window's second bound, the older-CLI limit rows, the window property's exemption, the tests that existed only for them.
  • Guard (check-no-local-paths.js): no array pass, no 64 KB cap, no offset-to-line search, no sort. Multi-line structures, and arrays of ids, are not parsed. The key-then-UUID form stayed: "any UUID on the key's line" flagged 46 tracked lines.
  • Rule merged into "Before the code" (coding-assertions.md).

Lines: +383 / −412, net −29; without the task folder, +279 / −412, net −133. Bundle: 716,561 → 717,130 bytes (+569).

🧪 How to verify

  • cd cli && npx vitest run tests/contexts/telemetry/application/report/report-window.property.integration.test.ts: a bounded report's figures (totals, rows, coverage) equal the full ledger's filtered, requestless and timestamped lines in the generator, no exemption.
  • cd cli && npx vitest run tests/contexts/telemetry/application/legacy/stored-usage-migration.property.integration.test.ts: a migrated store equals one fresh ingest byte for byte, left-out.txt included.
  • node scripts/check-no-local-paths.js --all: 0.
  • Evidence, red runs and mutation: evidence.md.

⚠️ Heads-up

  • coverage.left_out gains requestless, an addition allowed in envelope v2.
  • A request-id line an older CLI appends after the upgrade out of time order is read right, but not rewritten into canonical order. That was already the case before this PR, and it is unchanged.
  • Mutation survivor kept: usage-ledger-adapter.ts:90, the re-id unsettled mark, reachable only by an older CLI writing earlier ids after the upgrade.

🔗 Linked issue

None. Follows the R1 telemetry audit: simplest, deterministic, true.

✅ I certify

  • I DO CERTIFY I READ EACH LINE OF THE PULL REQUEST BECAUSE I AM A SOFTWARE ENGINEER, NOT A AI PUPPY.

🤖 Generated with Claude Code

https://claude.ai/code/session_01VWNxk63AGKkqE8HRqHLjGp

blafourcade and others added 11 commits October 17, 2026 19:38
A call whose transcript record carries no requestId is no longer stored.
It is counted in left_out under its own reason, requestless, hashed by
tool, message id and session. One predicate applies where a call enters:
at ingest, and at every ledger read, so a line an earlier or an older CLI
stored leaves the ledger at the next write of its day and is counted then.

Measured again: 0 requestless usage lines of 265,472 (Claude Code
2.1.232 to 2.1.302), after 0 of 512,820 before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VWNxk63AGKkqE8HRqHLjGp
No call without a request id is stored any more, so the ledger no longer
needs to read every day for one, re-key cli-v5.5.0's timestamped keys, or
state a limit for the copies an older CLI writes after the migration. The
window property holds with no exemption.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VWNxk63AGKkqE8HRqHLjGp
The guard no longer parses arrays of session ids across lines: no cap,
no offset-to-line search, no sort. Every path pattern, the dash slug, the
session key, the session-file name, the placeholder-id rule and the
allowlist stay. Multi-line structures are not parsed, as its header says.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VWNxk63AGKkqE8HRqHLjGp
Merged into the test-first rule rather than added beside it: an input
never observed is stated as a limit, a review finding about one is closed
by that limit, and of two fixes the one that deletes wins.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VWNxk63AGKkqE8HRqHLjGp
The ledger read drops such a call too, so only the ingest result and the
bytes right after an ingest tell the two apart: a mutant skipping the
ingest check survived every other test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VWNxk63AGKkqE8HRqHLjGp
Only transcripts and the migration's one pass over the ledger add to
left_out.requestless, so the count no longer depends on the days a report
reads. A line an older CLI writes after the migration is a line this
version does not accept: kept as found, counted in skipped_ledger_lines.
The window property compares the figures of the envelope, run excluded,
with requestless lines in its generator and no exemption.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VWNxk63AGKkqE8HRqHLjGp
…nts the review named

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VWNxk63AGKkqE8HRqHLjGp
@blafourcade
blafourcade marked this pull request as ready for review October 17, 2026 18:53
@blafourcade
blafourcade requested a review from a team as a code owner October 17, 2026 18:53
@blafourcade
blafourcade merged commit 856a8b3 into next Oct 17, 2026
61 checks passed
@blafourcade
blafourcade deleted the refactor/telemetry-simplest-true branch October 17, 2026 18:54
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