Skip to content

Populate tool_result_events archive table (#101)#118

Merged
willwashburn merged 3 commits intomainfrom
feat/archive-tool-result-events-101
Apr 26, 2026
Merged

Populate tool_result_events archive table (#101)#118
willwashburn merged 3 commits intomainfrom
feat/archive-tool-result-events-101

Conversation

@willwashburn
Copy link
Copy Markdown
Member

@willwashburn willwashburn commented Apr 26, 2026

Summary

  • Wire the previously-empty tool_result_events archive table to the ToolResultEventLine ledger lines that PR Execution graph substrate: SessionRelationshipRecord + ToolResultEventRecord (#42) #77 introduced. buildArchive now parses them via isToolResultEventLine and INSERT OR REPLACEs 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; the row count is deterministic from a given ledger.
  • New BuildResult.toolResultEventsApplied and ArchiveStatus.rowCounts.toolResultEvents flow through to burn archive build / rebuild / status (text + --json).
  • Added idx_tool_result_events_use_id / _session / _subagent for the obvious join paths and bumped ARCHIVE_VERSION from 1 to 2 so existing archives self-heal on next build.

The execution-graph record already carries contentLength and contentHash, 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 build
  • pnpm run test:ts (458 pass, was 452 — +6 new)
  • New ledger tests in packages/ledger/src/archive.test.ts:
    • round-trip from ledger to archive (all columns asserted)
    • rebuild-from-zero is deterministic + idempotent
    • mixed-source events (claude-code / codex / opencode) all land
    • incremental tail picks up newly-appended events
    • dedup-safe replay (rebuildArchive over a single line yields one row)
  • New CLI test in packages/cli/src/commands/archive.test.ts:
    • archive status --json exposes rowCounts.toolResultEvents
    • archive status text surface includes tool_result_events: N
  • Existing tests for ledgers without any tool_result_event lines continue to pass — the new code path is no-op when the array is empty.

Refs

Closes #101. Refs #40, #42, #77.


Open in Devin Review

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.
devin-ai-integration[bot]

This comment was marked as resolved.

devin-ai-integration Bot and others added 2 commits April 26, 2026 01:53
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>
@willwashburn willwashburn merged commit f3e4b3e into main Apr 26, 2026
@willwashburn willwashburn deleted the feat/archive-tool-result-events-101 branch April 26, 2026 17:24
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.

Populate tool_result_events archive table from execution-graph + content sidecar

1 participant