Skip to content

Add fidelity columns to archive turns and sessions (#110)#120

Merged
willwashburn merged 2 commits intomainfrom
feat/archive-fidelity-columns-110
Apr 26, 2026
Merged

Add fidelity columns to archive turns and sessions (#110)#120
willwashburn merged 2 commits intomainfrom
feat/archive-fidelity-columns-110

Conversation

@willwashburn
Copy link
Copy Markdown
Member

@willwashburn willwashburn commented Apr 26, 2026

Summary

  • Adds attribution_fidelity, tokens_present, cost_present columns to the archive turns table, and min_fidelity + has_full_attribution rollups to sessions. Vocabulary matches TurnRecord.fidelity.class exactly (full, usage-only, partial, aggregate-only, cost-only).
  • Migration is additive — openArchive() runs idempotent ALTER TABLE … ADD COLUMN guarded by PRAGMA table_info, so existing archives forward-migrate without a rebuild and ARCHIVE_VERSION stays at 1.
  • Older lines that pre-date the upstream parser fidelity work (Codex/OpenCode pre-Codex parser: populate TurnRecord.fidelity #84/OpenCode parser: populate TurnRecord.fidelity #89) persist NULL rather than guessing — downstream queries should read NULL as "unknown". When the upstream parsers populate fidelity, the next archive build picks up the values automatically.
  • burn archive status --json now returns a fidelityHistogram (counts per attribution_fidelity, with NULL bucketed as unknown). Text-mode output is unchanged.

Test plan

  • pnpm run build passes.
  • pnpm run test:ts passes (457 tests, 5 new).
  • New ledger test covers a mixed-fidelity ledger (Claude full + Codex turn lacking fidelity + cost-only) yielding the expected per-turn attribution_fidelity and the right session-level min_fidelity (cost-only) / has_full_attribution (0).
  • New ledger test covers has_full_attribution = 1 for an all-full session and NULL when no turn carries fidelity at all.
  • New ledger test covers rebuild idempotence: row counts and fidelity histogram are stable across rebuildArchive().
  • New ledger test covers the ALTER-on-existing path: an archive built without the new columns is forward-migrated on next openArchive() without dropping data, and a subsequent build populates the new columns for new turns.
  • New CLI test covers burn archive status --json exposing fidelityHistogram.

Refs

Closes #110. Refs #40, #41, #78.

Out of scope (future follow-ups #95, #100, #105, #108): wiring consumer commands (burn compare, etc.) to filter by fidelity in SQL.

🤖 Generated with Claude Code


Open in Devin Review

Materialize TurnRecord.fidelity onto the analytics archive so SQL
consumers can filter / group by attribution quality without re-deriving
in memory.

- turns gains attribution_fidelity (FidelityClass string), tokens_present
  and cost_present.
- sessions gains min_fidelity (worst class observed across known-fidelity
  turns) and has_full_attribution (1 iff every fidelity-tagged turn is
  full).
- Older lines that pre-date the upstream parser fidelity work persist
  NULL rather than guessing.
- Migration is additive: openArchive() runs idempotent ALTER TABLE
  ADD COLUMN guarded by PRAGMA table_info, so existing archives forward-
  migrate without a rebuild and ARCHIVE_VERSION stays at 1.
- getArchiveStatus() / burn archive status --json now returns a
  fidelityHistogram (counts per attribution_fidelity value, NULL bucket
  surfaced as "unknown").

Refs #40 #41 #78. Closes #110.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 3 additional findings.

Open in Devin Review

…-columns-110

# Conflicts:
#	packages/cli/CHANGELOG.md
#	packages/ledger/CHANGELOG.md
@willwashburn willwashburn merged commit 18b6758 into main Apr 26, 2026
@willwashburn willwashburn deleted the feat/archive-fidelity-columns-110 branch April 26, 2026 17:01
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.

Add fidelity / coverage columns to archive turns and sessions

1 participant