Populate tool_result_events archive table (#101)#118
Merged
willwashburn merged 3 commits intomainfrom Apr 26, 2026
Merged
Conversation
Wire the previously-empty `tool_result_events` table to the `ToolResultEventLine` ledger lines that PR #77 introduced, so the execution-graph data lands in `archive.sqlite` automatically during incremental builds. - `buildArchive` now handles `tool_result_event` lines via `isToolResultEventLine`, INSERT OR REPLACE keyed on the table's PK (`source`, `session_id`, `message_id`, `tool_use_id`, `event_index`). Cursor stays on `archive_state.ledger_offset_bytes` — no parallel cursor. - `rebuildArchive` replays tool-result events alongside turns / stamps / compactions; deterministic row count. - `BuildResult.toolResultEventsApplied` and `ArchiveStatus.rowCounts.toolResultEvents` surface the counts; CLI status text + `--json` and build/rebuild summary lines reflect them. - Added `idx_tool_result_events_use_id` / `_session` / `_subagent` for the obvious join paths and bumped `ARCHIVE_VERSION` to 2 so existing archives rebuild cleanly. - Tests cover round-trip from ledger to archive, idempotent rebuild, mixed-source (claude-code / codex / opencode) events, incremental tail, and dedup-safe replay. Sidecar fallback for missing `contentLength` / `contentHash` is left to a follow-up — the canonical record always carries them today. Closes #101. Refs #40, #42, #77.
The ToolResultEventRecord type has an isError field that was silently dropped during archive materialization. The tool_calls table already handles is_error — this aligns tool_result_events with the same pattern. - Add is_error INTEGER column to CREATE TABLE tool_result_events - Add is_error to the INSERT OR REPLACE column list and .run() call - Assert is_error round-trips in the ledger archive test Co-Authored-By: Will Washburn <will.washburn@gmail.com>
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
tool_result_eventsarchive table to theToolResultEventLineledger lines that PR Execution graph substrate: SessionRelationshipRecord + ToolResultEventRecord (#42) #77 introduced.buildArchivenow parses them viaisToolResultEventLineandINSERT OR REPLACEs on the table's PK (source,session_id,message_id,tool_use_id,event_index). Cursor stays onarchive_state.ledger_offset_bytes— no parallel cursor.rebuildArchivereplays tool-result events alongside turns / stamps / compactions; the row count is deterministic from a given ledger.BuildResult.toolResultEventsAppliedandArchiveStatus.rowCounts.toolResultEventsflow through toburn archive build/rebuild/status(text +--json).idx_tool_result_events_use_id/_session/_subagentfor the obvious join paths and bumpedARCHIVE_VERSIONfrom 1 to 2 so existing archives self-heal on next build.The execution-graph record already carries
contentLengthandcontentHash, so we write them straight through. Sidecar fallback for any future record that lacks them is intentionally punted to a follow-up — no record shape today omits them.Test plan
pnpm run buildpnpm run test:ts(458 pass, was 452 — +6 new)packages/ledger/src/archive.test.ts:rebuildArchiveover a single line yields one row)packages/cli/src/commands/archive.test.ts:archive status --jsonexposesrowCounts.toolResultEventsarchive statustext surface includestool_result_events: Ntool_result_eventlines continue to pass — the new code path is no-op when the array is empty.Refs
Closes #101. Refs #40, #42, #77.