universe
soul.demarkus.io:6309/demarkus-library/plans/pulse-convergence.md proposed reader meta

· reload

Pulse convergence across replicas (issue #129)

Recent activity drops writes that land during a pod's watch gap, and each replica keeps its own list. The fix rebuilds the list from the server's own change log instead of from what each pod happened to hear. Decided 2026-12-03: an upstream change plus a library change, not a catalog backfill.

Cause

Confirmed against the 2026-12-03 sighting.

  • FollowChanges records only Activity(), which excludes Resync. A gap's writes reach the caches as a resync, but never reach the pulse.
  • Gap 1: an MCP subscription's acknowledgement carries no cursor. A quiet world's stream reopens cursorless, and mcpwatch owes a resync.
  • Gap 2: a pod with no lendable bearer for a world has no watch on it until a reader's read lands on that pod (WorldSource → ErrNoReader).
  • Restart: the log starts empty.
  • Order: Pulse.At is when the pod heard the write, so replicas order differently even with the same set.

Why not the catalog backfill

  • It needs a borrowed bearer, and a lookup as that reader can list identity-scoped documents to other readers. The watch sees public paths only (ADR 0047 decision 10).
  • The lookup carries no time, version, agent or user, so it needs one versions read per hit. It also misses archives.

Upstream (demarkus)

  1. Event write time. Add at (RFC 3339 UTC, OPTIONAL) to the WATCH event block, and demarkus.io/at on the MCP binding.
    • changefeed.Event.At.
    • bucketstore takes it from slotEntry.Modified, so every knowledge replica reports the same time.
    • filestore takes it from the commit, and the journal persists it.
    • The fanout and the gateway forward it.
  2. Backlog on a cursorless subscribe. Add backlog: <n> on WATCH, or demarkus.io/backlog (URI → n) on MCP.
    • It is valid only without since; with since it is bad-request.
    • Delivery starts up to n events before the head, as far as the server retains. coalesce applies.
  3. MCP position. A subscription that asked for a backlog gets one control notification after it, demarkus.io/status: ok plus demarkus.io/cursor, so the stream holds a cursor even in a quiet world.
    • It is opt-in through the backlog key, because old mcpwatch clients treat an unknown status as an end.
    • mcpwatch takes it as the stream cursor and passes nothing to the consumer.
  4. Client: fetch.WatchRequest.Backlog and mcpwatch.Request.Backlog. Both decode at.

Library

  • domain.Change.At comes from the event. Pulse.At uses the write time, or the time heard when the event has none.
  • Feed sets Backlog on a cursorless open only; a reopen resumes from its cursor.
  • pulseLog.record keeps the log ordered by At and dedups by path, keeping the newest. An older replayed event never replaces a newer one.
  • Result: every replica holds the newest pulseCap writes from the same server log, in the same order, after a restart too.

Remaining loss

  • A gap older than the server's retention (bucketstore checkpoint, or the 4096-event ring) still resyncs. Those writes are not activity anyone sees as recent.

Status

  • 2026-12-03: plan only. Library branch fix/pulse-backfill is created, with no code yet.

Build notes

Built 2026-12-03 (ADR 0013). Changes from the plan:

  • The MCP acknowledgement goes out before the backlog, not after it. Its cursor is where the backlog starts, which the QUIC ack also names. A client cut mid-backlog replays from there.
  • demarkus.io/backlog: 0 asks for the acknowledgement alone.
  • The server clamps the backlog to one ring's worth and to what the ring or store backlog reaches. If the backlog is out of reach at attach, the watch starts at the head; it never resyncs.
  • The pulse dedups by path in arrival order, because a world's feed is in sequence, so no At check is needed. It orders by At, then world, then path.
  • Added Pulse.Heard: the live graph's cursor stays pod-local µs, since a whole-second write time would drop same-second writes and ones that land just before a drawing.
  • Archive at is the document's last write time (the bucket slot has no commit time). See ADR 0013 Consequences.

Verified:

  • demarkus: protocol, changefeed, fanout, handler (both backends), filestore, bucketstore, client fetch/mcpwatch, and the gateway, including TestHelperBacklogPlacesAQuietStream, the gap-1 case end to end.
  • Library: gate green against a scratch go.work, helm 46/46, browser live-graph test green.
  • Mutations caught: backlog fallback, Reach clamps, gateway ack, client backlog meta, pulse order, tie-break, graph cursor.

End-to-end check (QUIC mode, 2026-12-03)

Setup: a branch-built server on a scratch world (6399) and two branch-built library instances, A and B. No pulse list differed at any step.

  • A started after 3 writes and listed all 3 from the backlog, with their real write times. Before this change a fresh pod listed nothing.
  • Writes while B was down: two in the same second, and an append. When B started, its list was identical to A's. The append moved its document to the top, and the same-second pair ordered by path.
  • An archive and a publish while A was down: after A restarted, both lists were identical and included both.
  • A live write with both running: identical lists.
  • The logs showed no warnings or resyncs.
  • Seen live: the archive is listed at the document's last write time (15:35:29), not the archive time (about 15:36:01). The time shown next to "archived" is therefore wrong, as well as its sort position. This confirms ADR 0013's open consequence.
  • Not exercised: broker/MCP mode (covered by the gateway's mcpwatch tests).
trail
  1. universe universe
  2. soul.demarkus.io:6309 pulse-convergence