Skip to content

Resume paired desktops and the phone from the event journal - #253

Merged
BunsDev merged 1 commit into
mainfrom
journal-resume
Oct 16, 2026
Merged

BunsDev merged 1 commit into
mainfrom
journal-resume

Conversation

@BunsDev

@BunsDev BunsDev commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

Routines Phase 0, step 1 of the routines spec: the event journal's resume endpoint, retention, and the paired sleep test. Everything stays behind MODEX_EVENT_JOURNAL=1. With the flag off, nothing changes.

What changes

Journal (event-journal.ts)

  • Each journal file has a stable id in a new meta table. A cursor from another file never resumes.
  • resume(id, cursor, { threadId }) returns the events after the cursor, read in the same step as the newest cursor. It answers "reload" when the cursor came from another file, was pruned, is ahead of the journal, or is more than 10,000 events behind.
  • subscribe() hands each written batch, with its cursors, to listeners.
  • prune() deletes rows older than 7 days and the oldest rows past 250,000. Modex runs it at startup and every hour. The pruned point is persisted, and latest() never moves back.
  • A timed flush that fails now calls onError (Modex turns the journal off) instead of throwing from a timer.

Paired desktops (desktop-host.ts, desktop-client.ts, Store app)

  • With the journal on, thread events reach paired desktops from journal flushes, each frame carrying id: <seq>. They now arrive up to 250 ms later; the local window is unchanged.
  • GET /events?journal=<id>&after=<cursor> replays what the client missed. The host reads the journal and registers the stream in one synchronous step, so no batch falls between them.
  • The client asks only a host that named its journal, so older hosts never see the query, and it drops frames at or below its cursor.
  • The Store app closes the stream on powerMonitor suspend and reopens it on resume.
  • A resumed reconnect sends host:reconnected { resumed: true }. The window refreshes its thread list and the selected thread's Changes, but keeps its transcripts instead of reloading them.
  • A replay over 4 MB reloads instead.
  • A stream is now dropped only past 8 MB of backlog, not at the first write() backpressure. That old rule could force a full reload on one large item.
  • If the journal stops, the host ends every stream so clients reconnect without it and reload.

iPhone companion (companion.ts, iOS app)

  • /v1/snapshot?threadId= includes journal: { id, cursor }, read in the same synchronous step as the transcript.
  • Given journal and after, it returns only the items that changed, with delta: true.
  • The phone merges changed items by id. It drops its cursor whenever its transcript is replaced: changing thread, reconnecting, forgetting the Mac, or the thread disappearing.

Tests

  • test/journal-resume.test.ts is the paired sleep test. It uses the scripted runner, a real journal, a real DesktopHost with a DesktopClient over TLS, and the phone's exact HTTPS requests. Turn 1 runs, both clients sleep, turn 2 runs, and both wake. The desktop must resume (not reload) and receive each item exactly once. The phone must receive only the sleep's items, and both transcripts must equal the Mac's. A second test covers a pruned cursor and a stopped journal.
  • test/event-journal.test.ts: resume rules, retention by age and rows across a restart, the 10,000-event limit, subscriptions, and the timed-flush error path.
  • CompanionModelTests.testJournalDeltasMergeIntoTheTranscriptTheyWereReadAgainst covers the phone's merge and its cursor reset on a thread switch.

Verification

  • pnpm build && pnpm test: all packages pass (desktop 1,426 passed, 0 failed), at load average ~300.
  • iOS native unit tests on an iPhone 16 Pro simulator: 44 passed, 0 failed.
  • playwright test e2e/store-desktop.spec.ts e2e/event-journal.spec.ts: 9 passed.

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

Routines Phase 0: the journal's resume endpoint, retention and the paired
sleep test.

- The journal gets a stable id, resume() (missed events, or reload when
  the cursor is from another file, pruned, ahead, or over 10,000 behind),
  flush subscriptions, hourly retention (7 days or 250,000 rows) and an
  error path for timed flushes.
- With the journal on, the desktop host feeds thread events to paired
  desktops from the journal with SSE ids. /events?journal=&after= replays
  what a reconnecting client missed in the same synchronous step that
  registers the stream. The client drops frames at or below its cursor,
  closes the stream on sleep and reopens it on wake. A resumed Store
  window refreshes its lists but keeps its transcripts.
- The companion snapshot carries the journal cursor for the selected
  thread and, given it back, returns only the items that changed. The
  iPhone app merges them by id and drops the cursor whenever its
  transcript is replaced.
- A stream is now dropped only past 8 MB of backlog, not at the first
  backpressure, so a replay or a large item no longer forces a reload.

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

vercel Bot commented Oct 16, 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 16, 2026 3:57am UTC

Request Review

@github-code-quality

Copy link
Copy Markdown

Code coverage overview

Languages: TypeScript

TypeScript / code-coverage-agent

main 5efafc4 journal-resume 2ba0fa1 +/-
61% 61% 0%
View coverage of the 6 most impacted files.
File main 5efafc4 journal-resume 2ba0fa1 +/-
apps/desktop/sr...desktop-host.ts 98% 98% 0%
apps/desktop/sr...sktop-client.ts 99% 99% 0%
apps/desktop/sr...ne/companion.ts 97% 97% 0%
apps/desktop/sr...ngine/runner.ts 99% 99% 0%
packages/core/src/agent.ts 92% 92% 0%
apps/desktop/sr...vent-journal.ts 98% 99% +1%

ℹ️ Calculations represent line coverage. Results may change as calculations are updated.

@BunsDev
BunsDev merged commit 8c4dd8c into main Oct 16, 2026
13 checks passed
@BunsDev
BunsDev deleted the journal-resume branch October 16, 2026 04:20
BunsDev added a commit that referenced this pull request Oct 19, 2026
… and the routines spec (#310)

v0.2.0 was published on 2026-10-18 (23:14Z) from the signed tag on 01b1b8a. This
follows Val's status layout (#290):

- Shipped gains a v0.2.0 row linking its release and its review.
- The 13 "On main, unreleased" items move unchanged to a new "Status summary"
  at the end of the v0.2.0 review, along with the old In flight entry. Each one
  was introduced by a commit in the tag (#248, #253, #254, #257 to #261, #263,
  #264, #266, #267, #269). The CF slices and #283's Markdown parser came after
  the tag, so they stay.
- In flight keeps a short follow-ups entry for the gates no receipt records yet:
  the independent download checks, the banner upgrade on the release Mac, and
  the Companion 0.2.0 (7) TestFlight upload.
- The routines spec and the README now say Phase 1, and most of Phase 0, ship
  from v0.2.0.

Unchanged: the website's static fallback (apps/site/release.json) and the
release evidence, which stay with the release owner. Claimed on #290.

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

This branch was successfully deployed

1 active deployment
Preview — 2ba0fa12 Deployed Oct 16, 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