Skip to content

[arch] Add event-bus ring buffer + replay when first late-joiner ships #129

Open

Description

@utof

Context

The desktop event bus (crates/app/src/bus.rs) currently exposes
subscribe() returning a fresh Receiver<AppEvent> with no historical
events. This works in v1 because every subscriber spawns at app launch
before any event fires.

A future shell that connects to a running backend after-the-fact (mobile
app, HTTP/WebSocket service, browser extension) would miss every event
that fired before its subscription. The original recommendation
was a 256-event ring buffer to support replay on subscribe.

Decision in v1

Skipped. Adding the buffer with no consumer ships dead code, and the
exact replay-cursor shape (per-connection seek? timestamp filter?
key-based?) is best decided by whoever first needs replay.

When to add

When a concrete late-joiner consumer ships. The implementer at that
point owns:

  1. Adding Mutex<VecDeque<AppEvent>> (capacity 256) to Bus.
  2. Pushing to the buffer in Bus::emit AFTER the broadcast.
  3. Exposing a Bus::replay() -> Vec<AppEvent> (or shape they need).
  4. Designing the cursor API based on the consumer's reconnect pattern.

The Bus rustdoc references this issue so the deferral is discoverable
from the codebase.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions