refactor(maestro): collapse the daemon's double event fan-out #43

Merged
naps62-yolo merged 1 commits from lithuanians into main 2026-08-22 14:00:02 +01:00
Collaborator

A background task, a second broadcast channel and a whole module existed to remap SessionEvent onto CatalogEvent one variant at a time. SessionManager now emits CatalogEvent directly.

Deleted: local_events.rs, the publisher task, the LocalEventBus channel, enum SessionEvent, LocalApiState::events, and the duplicate capacity constant — events_capacity was declared twice, in session.rs and local_events.rs, for one logical stream.

Lag semantics get better, not just simpler. There were two lag points:

  1. the publisher task falling behind the manager, which broadcast a single Lagged to every connected client;
  2. each WS subscriber falling behind the bus.

Only (2) survives, and pump_events already handled it. A slow client now makes only itself resync instead of forcing a full refetch on everyone.

Also adds the first daemon-level tests for WS /api/events — the review noted it had none. Two cases: the Snapshot-then-deltas contract, and that a subscriber connecting late gets a Snapshot of current state rather than an empty one. The subscribe-before-snapshot ordering was previously described only in a comment.

Net −20 lines, and one fewer place for an event to get stuck.

Verification
cargo fmt --all -- --check                   ok
cargo clippy --all-targets -- -D warnings    0
cargo test --all                             300 passed, 0 failed

Count is 300 rather than 301 because the three LocalEventBus unit tests went with the module; two richer WS tests replaced them.

Fourth of nine from the architecture review (#40, #41, #42 merged).

A background task, a second broadcast channel and a whole module existed to remap `SessionEvent` onto `CatalogEvent` one variant at a time. `SessionManager` now emits `CatalogEvent` directly. Deleted: `local_events.rs`, the publisher task, the `LocalEventBus` channel, `enum SessionEvent`, `LocalApiState::events`, and the duplicate capacity constant — `events_capacity` was declared twice, in `session.rs` and `local_events.rs`, for one logical stream. **Lag semantics get better, not just simpler.** There were two lag points: 1. the publisher task falling behind the manager, which broadcast a single `Lagged` to *every* connected client; 2. each WS subscriber falling behind the bus. Only (2) survives, and `pump_events` already handled it. A slow client now makes only itself resync instead of forcing a full refetch on everyone. Also adds the first daemon-level tests for `WS /api/events` — the review noted it had none. Two cases: the Snapshot-then-deltas contract, and that a subscriber connecting late gets a Snapshot of current state rather than an empty one. The subscribe-before-snapshot ordering was previously described only in a comment. Net −20 lines, and one fewer place for an event to get stuck. <details> <summary>Verification</summary> ``` cargo fmt --all -- --check ok cargo clippy --all-targets -- -D warnings 0 cargo test --all 300 passed, 0 failed ``` Count is 300 rather than 301 because the three `LocalEventBus` unit tests went with the module; two richer WS tests replaced them. </details> Fourth of nine from the architecture review (#40, #41, #42 merged).
naps62-yolo added 1 commit 2026-08-22 13:37:32 +01:00
refactor(maestro): collapse the daemon's double event fan-out
ci / rust (pull_request) Successful in 3m18s
ci / rust (push) Successful in 2m5s
db44650a17
A background task, a second broadcast channel and a whole module existed
to remap SessionEvent onto CatalogEvent one variant at a time.
SessionManager now emits CatalogEvent directly.

Deletes local_events.rs, the publisher task, the LocalEventBus channel,
enum SessionEvent, LocalApiState::events, and the duplicate capacity
constant — events_capacity was declared twice for one logical stream.

Lag semantics improve. There were two lag points: the publisher falling
behind the manager, which broadcast one Lagged to every client, and each
WS subscriber falling behind the bus. Only the per-subscriber one is left,
which pump_events already handled — a slow client now makes only itself
resync.

Adds the first daemon-level tests for WS /api/events: the Snapshot-then-
deltas contract, and that a late subscriber gets a Snapshot of current
state. Both were described only in a comment.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
naps62-yolo left a comment
Author
Collaborator

No findings.

No findings. <!-- agent-meta: {"model":"gpt-5.6"} -->
naps62-yolo merged commit db44650a17 into main 2026-08-22 14:00:02 +01:00
naps62-yolo deleted branch lithuanians 2026-08-22 14:00:02 +01:00
This repo is archived. You cannot comment on pull requests.