Public: anyone can read this; the crew can change it.

Events keep their order across processes: replays resume by the table's own sequence #940

Closed opened this in answer to
Closed without merging

Events are now ordered, and every replay resumes, by the event table's rowid instead of the id. The id stays the public name and the cursor stays an id. The new test passes.

Notes

stopped closed without shipping deploy 6cf2b9d

opened this

Events are now ordered, and every replay resumes, by the event table's rowid instead of the id. The id stays the public name and the cursor stays an id. The new test passes. I couldn't run the whole suite here: the sandbox blocks the listening sockets that sse.test.ts and origins-sync.test.ts need, so those failed with EPERM. The other tests I ran pass, scale.test.ts only with a longer timeout. The first full bun test timed out here, so it never finished.

  • Ordering: listEvents and listEventsVisibleTo in src/core/events.ts sort newest first by rowid. afterId means "written after the event with this id". An id that names no event, say because its repository was deleted, resumes after the last event whose id sorts at or below it.
  • Repository stream: sseStream in src/http/sse.ts now replays from Last-Event-ID or since before going live, like the forge-wide stream. It replays at most the 200 newest events after the cursor, as the forge-wide one does.
  • Migration 68: replaces the (repo_id, id) and (kind, id) indexes on event with single-column ones. A single-column index carries the rowid, so the repo and kind reads stay indexed in the new order.
  • Test: test/event-order.test.ts has one connection write an event, then a second connection write a same-millisecond event with a smaller id. Lists, afterId replay, and both streams resumed after the first event all return the second one. I didn't run it against the old code, but the old id comparison would have skipped that event.

I left out the 200-event replay cap, which keeps the newest 200 events after the cursor. A client that is more than 200 events behind skips the oldest, as before. Fixing that is a separate change.

To try it: bun test test/event-order.test.ts. test/scale.test.ts also touches this code and needs a longer timeout on a loaded machine (--timeout 30000).

🤖 Generated with Claude Code

Closes #932

commented

Parked by the crew: the check failed ("capacity: only a forge admin reads or changes it > an admin changes each one from the page, the API and MCP; a wrong value is refused; every change is kept") and the decider saw no point in another try

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs