LEDGER-20261007-01
Token ledger keeps sessions whose transcripts are gone
Evidence
From logs/evidence/LEDGER-20261007-01/. Click a thumbnail for the full image.
Logs and data (1)
restore-summary.json · 6 kB · open
{
"task": "LEDGER-20261007-01",
"note": "Numbers at the time of the restore (2026-10-06T17:14Z); live sessions keep growing.",
"ledger": {
"committedAt3465c40": {
"generatedAt": "2026-10-05T20:44:56.652Z",
"messages": 4179,
"total_tokens": 1974468742,
"sessions": 12
},
"shrunkWorkingCopy": {
"generatedAt": "2026-10-06T16:40:34.198Z",
"messages": 380,
"total_tokens": 137043311,
"sessions": 3
},
"restored": {
"generatedAt": "2026-10-06T17:14:51.788Z",
"messages": 4393,
"total_tokens": 2022023205,
"sessions": 16,
"archivedSessions": 11,
"costUsd": 606.83,
"wallHours": 77.85,
"activeHours": 29.19,
"problems": []
},
"neverLowerThanCommitted": true
},
"sessions": [
{
"id": "17b89d51-ee31-4e5f-a08e-c8b42e73b843",
"messages": 4,
"total_tokens": 2181406,
"archived": true,
"countedIn": null,
"subagentMessages": 0
},
{
"id": "30a0bda4-10e1-4565-9753-29db161e9005",
…Tests
$ cd packages/game-data && node --test tests/ledger-tools.test.mjs$ cd packages/game-data && node --test tests/ledger-tools.test.mjsNotes
2026-10-06 17:21 UTC · Every rebuild (task-log finish/report, token-ledger --write) now merges the transcripts on disk with the previous logs/token-ledger.json and logs/tasks.json. A session whose transcript is gone stays (archived), the larger value wins per session, and totals, by-day, by-model, cost and hours never shrink and always add up (ledgerProblems). Per-task tokens keep the larger earlier value for the same or a wider window (tokensArchived). --fresh drops history; task-log restore <git-ref> recovers it. Evidence: logs/evidence/LEDGER-20261007-01/restore-summary.json
2026-10-06 17:21 UTC · Restored from 3465c40: ledger 380 -> 4,393 messages and 137,043,311 -> 2,022,023,205 tokens (committed was 4,179 / 1,974,468,742; 16 sessions, 11 archived); 204 task token fields restored, none below its committed value. Session 25ebee33 (219 messages, 83.1M tokens) is counted once: flagged countedIn efc55efd because the committed ledger held it under that archived session (efc55efd exceeds it by 12 messages at about 551k per message, and 25ebee33 ended at a 543k context). This is an inference; delete the flag in logs/token-ledger.json if wrong.
2026-10-06 17:21 UTC · Sub-agent transcripts exist: <session>/subagents/agent-<id>.jsonl plus agent-<id>.meta.json (toolUseId links to the spawn call). They carry the parent session id, so they were already inside the parent's totals; the ledger now also lists them per session (subagent). A task is attributed to the transcripts whose task-log/verify Bash calls name it, plus helpers they spawned; heredocs and node -e / python -c bodies are not claims. This task's own sub-agent transcript is that case.
