Migrate burn summary to archive query (#82)#129
Merged
willwashburn merged 3 commits intomainfrom Apr 27, 2026
Merged
Conversation
Replaces the per-invocation `queryAll` ledger walk with `queryAllFromArchive` that issues SQL against `archive.sqlite`. Filters lower to indexed `WHERE` clauses; tool calls are bulk-hydrated; subagent-tree and `--by-subagent-type` modes consume the same archive-derived turn slice. JSON + text output stays parity-identical against the legacy reader for the load-bearing blocks (`byModel`, `totalCost`, `fidelity`). Two escape hatches preserve the old behavior: `--no-archive` flag and `RELAYBURN_ARCHIVE=0` env var both revert to `queryAll`. If the archive build/read throws (corrupt sqlite, schema mismatch we couldn't recover from cleanly), the command transparently falls back to the streaming reader and surfaces the reason on stderr — the archive can never wedge `burn summary`. Tests cover parity (text + JSON), auto-build behavior, both fallback paths, and the new `archive-query` reader (filters, tool-call hydration, fidelity class round-trip, subagent block hydration). Closes #82, refs #40, #78.
Resolve conflicts between #82 (summary from archive) and #97 (MCP from archive). Both PRs added a read-side helper to packages/ledger/src/archive-query.ts under different names; keep both: - queryAllFromArchive (this PR) — full EnrichedTurn shape with synthesized fidelity. Used by burn summary's archive hot path. - queryTurnsFromArchive (main, from #97) — same shape minus fidelity synthesis. Used by the MCP tool handlers. Both share buildSelect, loadToolCallsForKeys, and rowToEnrichedTurn, with fidelity skipped via an opts flag for queryTurnsFromArchive. Address Devin review on #129: subagent.description archive parity (packages/ledger/pull/129#discussion_r3144029656). - Add subagent_description TEXT column to the turns table (additive migration via ensureColumn — ARCHIVE_VERSION stays at 2). - writeTurn persists t.subagent?.description. - archive-query rowToEnrichedTurn populates subagent.description on the way back out, so burn summary --subagent-tree --json no longer silently drops the field on the default archive path. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
After merging origin/main (which carried the 0.30.0 release), the queryAllFromArchive / archiveAvailable bullet for #82 ended up filed under the already-released 0.27.0 section. Move it back to [Unreleased] where unreleased work belongs. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
willwashburn
added a commit
that referenced
this pull request
Apr 27, 2026
…hive-88 Resolve [Unreleased] CHANGELOG conflict in packages/analyze: keep the compareFromArchive (#88) entry under [Unreleased] alongside the new 0.27.0 release block from main. Also fix unescaped backticks in packages/ledger/src/archive.ts (introduced on main via the #129 merge) — the SCHEMA_SQL template literal contained `burn summary --subagent-tree --json` in a SQL comment, which prematurely closed the literal and broke `tsc`. Replaced with single quotes inside the comment so the schema string parses cleanly. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2 tasks
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.
Summary
burn summarynow reads fromarchive.sqliteon the hot path. After the per-invocationingestAll, it callsbuildArchive()(cheap incremental tail scan) and thenqueryAllFromArchive(query)instead of streaming the canonicalledger.jsonl. Filters lower to indexedWHEREclauses onturns; tool calls are bulk-hydrated keyed on(source, session_id, message_id). Subagent-tree (--subagent-tree) and--by-subagent-typemodes consume the same archive-derived turn slice.queryAllFromArchive(query)+archiveAvailable()in@relayburn/ledger, returning the sameEnrichedTurn[]shape asqueryAllso consumers can swap implementations without touching their aggregation code. Fidelity is reconstructed from the persistedattribution_fidelity/tokens_present/cost_presentcolumns (Add fidelity / coverage columns to archiveturnsandsessions#110) plus class-implied coverage defaults — class equality is the load-bearing parity contract.--no-archiveflag and theRELAYBURN_ARCHIVE=0env var both revert toqueryAll. If the archive throws (corrupt sqlite, schema mismatch we couldn't recover from cleanly), the command transparently falls back to the streaming reader and surfaces the reason on stderr — the archive can never wedgeburn summary.Test plan
pnpm run test:ts— full workspace, 520 tests pass.archive-query.test.ts— parity for unfiltered queries,project+ workflow filters,sincewindow; tool-call + subagent + fidelity hydration; empty-result path;archiveAvailable()lifecycle.summary.test.ts—--jsonparity between archive and ledger paths, text-mode parity (preamble-stripped), auto-build ofarchive.sqliteon first run,--no-archiveflag does not build,RELAYBURN_ARCHIVE=0does not build.~/.relayburn/ledger.jsonl:burn summary --since 7dandburn summary --since 7d --no-archiveproduce matchingbyModel/totalCostblocks.Refs
Closes #82, refs #40, #78.
Generated with Claude Code