Skip to content

feat(positron): presence re-publish cue for late subscribers (#118) - #1741

Merged
joelteply merged 2 commits into
canaryfrom
feat/positron-presence-resync-cue
Jul 3, 2026
Merged

joelteply merged 2 commits into
canaryfrom
feat/positron-presence-resync-cue

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

What

Closes the late-subscriber presence gap (#118). The presence emitter (positron_presence::run_presence_loop) publishes presence:updated only on a roster change (change-dedup — an idle re-render is a wasted revision bump). On a stable roster it fires once, then goes silent. Any projector (chat / wall / kanban) that (re)starts after that one-and-only publish never receives presence → it holds a roster-empty view until the roster next happens to change, so message/card authors render provisionally forever.

Fix — a presence re-publish cue (keeps single-emitter-owns-roster compression)

  • A booting presence consumer calls request_presence_resync(bus) on boot → publishes a presence:resync cue. presence:-prefixed, so the bus treats it as realtime and never coalesces it.
  • run_presence_loop now select!s over its 2s ticker and the bus receiver. A matching cue force-re-publishes the current roster (bypassing the change-dedup). Read+project+publish is factored into one emit_once helper shared by the tick (force=false) and cue (force=true) paths. Bus-closed disables the cue arm (if bus_open guard — no busy-loop) while the ticker keeps owning the roster read.
  • All three projectors — chat (positron_source::spawn), wall (run_wall_loop), kanban (run_kanban_loop), each of which folds presence:updated for author/creator/assignee resolution — cue on boot, right after subscribing rx, so the emitter's re-publish lands in their buffer.

Why room-agnostic

The cue carries no room_id: the chat projection is room-following (it doesn't know its room at boot), each per-room emitter re-asserts only its own roster on any cue, and every consumer already filters presence by room. So a broadcast cue is correct; precise per-room routing is a premature optimization for the single-room reality (add a room_id when multi-room emitters make the idle re-reads matter, not before).

Doctrine

  • Fail-loud, no fallback: the cue payload is Null (a resync requests a roster, it doesn't carry one — no fabricated payload); a roster read error in emit_once skips the emit and keeps the last roster (reader owns reconnection), never substitutes fabricated data.
  • Compression preserved: one roster reader (the emitter). The cue name lives in one place; consumers go through the request_presence_resync helper.

Tests (one mod tests, each // what this catches:)

  • resync_forces_republish_of_unchanged_roster — the idle path dedups an unchanged roster; a resync forces a re-publish anyway (the actual Build(deps-dev): Bump eslint from 9.24.0 to 9.35.0 #118 gap).
  • request_presence_resync_publishes_the_cue — the consumer-side half actually emits presence:resync.
  • Wall (8) + kanban (9) + presence (5) suites all green through the insertions.

Validated: cargo check + scoped cargo test (--features metal,accelerate), disk swept.

🤖 Generated with Claude Code

The presence emitter (`positron_presence::run_presence_loop`) publishes
`presence:updated` only when the roster *changes* — an idle re-render is
a wasted revision bump. On a stable roster it fires once, then goes
silent. A projector (chat/wall/kanban) that (re)starts *after* that
one-and-only publish never receives presence, so it holds a roster-empty
view until the roster next happens to change: card/message authors render
provisionally forever (#118).

Fix = a re-publish cue that keeps the single-emitter-owns-roster
compression:

- A booting presence CONSUMER calls `request_presence_resync(bus)` on
  boot, publishing a `presence:resync` cue (realtime `presence:` prefix →
  never coalesced).
- `run_presence_loop` now `select!`s over its 2s ticker AND the bus
  receiver; a resync cue force-re-publishes the current roster (bypassing
  the change-dedup). Read+project+publish is factored into `emit_once`
  (shared by the tick and cue paths). Bus-closed disables the cue arm
  (no busy-loop) while the ticker keeps owning the roster read.
- All three projectors (chat, wall, kanban — each folds `presence:updated`
  for author resolution) cue on boot, right after subscribing `rx` so the
  emitter's re-publish lands in their buffer.

The cue is room-agnostic: the chat projection is room-following (it does
not know its room at boot), each per-room emitter re-asserts only its own
roster, and consumers already filter presence by room — so a broadcast cue
is correct and precise per-room routing is a premature optimization for
the single-room reality.

Tests (positron_presence): a resync force-re-publishes an unchanged roster
(the idle path dedups it); `request_presence_resync` emits the cue event.
Wall (8) + kanban (9) projector suites stay green through the insertions.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
…w D1)

The adversarial review of #1741 caught that the "why room-agnostic"
comment justified the broadcast cue with "every consumer already filters
presence by room" — which is FALSE for the chat projector. Its
`apply_presence` calls `switch_room(update.room_id)`, adopting the
update's room and wiping the previously-focused room's messages + roster
(room-FOLLOWING, not room-filtering).

Under today's single emitter this is harmless (every `presence:updated`
names the same room). But the comment green-lit the multi-room case it
would actually break: a second room's emitter re-publishing on a broadcast
cue would yank the chat projector off the focused room. Correct the
comment to state the real invariant — safe only while ≤1 room has a live
emitter — and name the two multi-room fixes (room_id on the cue, or a
room guard in `apply_presence`) so the landmine is documented, not hidden.

Comment-only; no behavior change. `cargo check` clean.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
@joelteply
joelteply merged commit 78034cf into canary Jul 3, 2026
4 checks passed
@joelteply
joelteply deleted the feat/positron-presence-resync-cue branch July 3, 2026 12:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant