Skip to content

Record thread events in an opt-in event journal - #206

Merged
BunsDev merged 2 commits into
mainfrom
event-journal
Oct 14, 2026
Merged

BunsDev merged 2 commits into
mainfrom
event-journal

Conversation

@BunsDev

@BunsDev BunsDev commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

This is the first slice of Routines Phase 0: an opt-in event journal, as specified in the routines spec. It records thread events in node:sqlite with a durable cursor, written alongside the existing storage behind a flag. state.json and the per-thread files stay authoritative; nothing reads the journal to decide app state. It's off by default.

What

  • engine/event-journal.ts:
    • EventJournal appends every ThreadEvent (item, item_update, status, thread) with a monotonic seq cursor that survives restarts. It uses SQLite in WAL mode with no native module; node:sqlite works in Electron 44 (Node 24.21, SQLite 3.53.4).
    • Writes are batched every 250 ms and flushed on quit. Within a batch, an item's later updates merge into its pending row, and the newest status or thread event replaces the earlier one. A streamed reply therefore costs about one row per batch instead of one per token, and replay is unchanged.
    • since(cursor, { threadId, limit }) pages events, and replayItems() folds them the way the runner applies them.
  • src/main/index.ts: with MODEX_EVENT_JOURNAL=1, main records each event it already sends to the window and the paired companion, into app/events.sqlite. If the journal can't open or a write fails, it's logged and turned off for that run; turns and state files are unaffected. The journal is closed in drainServices.
  • Docs: a new docs/event-journal.md, a progress note in the routines spec, and docs/status.md.

Exit test: replay equals the transcript

  • test/event-journal.test.ts records a real two-turn ThreadRunner session (mock backend with thinking, streaming, a shell tool and apply_patch) through the journal. Replaying it equals the persisted transcript, and so does folding the raw event stream.
  • The same file covers cursors surviving a reopen, the merge rules matching events applied in order, thread filtering, page limits, and a closed journal ignoring late events.
  • e2e/event-journal.spec.ts launches the real app with the flag on, runs a thread and quits. Reopening events.sqlite from the test process replays exactly the saved threads/<id>.json. With the flag off, no journal file is created.

Verification

  • npm run build, npm run typecheck and npm test pass: 1,430 unit tests, 1,414 passed, 16 skipped, 0 failed.
  • The new e2e file passes, 2 of 2.

Not yet

The resume endpoint (desktop and companion fetch after their last cursor), the paired desktop-and-phone sleep test, and retention. These are listed in docs/event-journal.md.

Routines Phase 0 needs an event journal: thread events in node:sqlite
with a durable cursor, written alongside the existing storage behind a
flag. state.json and the per-thread files stay authoritative.

- EventJournal (engine/event-journal.ts) appends every ThreadEvent with
  a monotonic seq. Writes are batched every 250 ms and flushed on quit.
  Within a batch, an item's later updates merge into its pending row and
  the newest status or thread event replaces the earlier one. A streamed
  reply therefore costs about one row per batch, and replay is
  unchanged. since(cursor) pages events, and replayItems() folds them
  the way the runner applies them.
- Main records each event it sends to the window and the companion when
  MODEX_EVENT_JOURNAL=1 (app/events.sqlite). A journal failure turns the
  journal off and never touches a turn. Off by default.
- Exit test: a real scripted runner session, and a real app session in
  e2e, replay from the journal to exactly their saved transcripts.
  Cursors survive reopening, and the merge rules equal applying events
  in order.

The resume endpoint, the paired sleep test and retention come next
(docs/event-journal.md).

Coven-Harness: Claude Code / claude-opus-5-5
@vercel

vercel Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
modex Ready Ready Preview Oct 14, 2026 9:57pm UTC

Request Review

This branch was successfully deployed

1 active deployment
Preview — 28fca16f Deployed Oct 14, 2026 by vercel[bot]
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.

1 participant