Skip to content

feat(eventbus): add EventBus interface and LocalEventBus implementation (#4229 phase A-B)#4342

Merged
aegis-gh-agent[bot] merged 2 commits into
developfrom
feat/4229-eventbus-interface
May 27, 2026
Merged

feat(eventbus): add EventBus interface and LocalEventBus implementation (#4229 phase A-B)#4342
aegis-gh-agent[bot] merged 2 commits into
developfrom
feat/4229-eventbus-interface

Conversation

@OneStepAt4time
Copy link
Copy Markdown
Owner

Summary

Part of #4229 β€” Redis Streams EventBus + SSE bridge.

This PR delivers the MVP: the EventBus port interface and an in-process LocalEventBus implementation. Zero external deps.

New files

File Lines Purpose
src/event-bus.ts 62 EventBus interface + BusEvent type
src/local-event-bus.ts 108 In-process implementation with ring buffer replay
src/__tests__/local-event-bus.test.ts 142 11 tests

EventBus interface

interface EventBus {
  publish(channel, type, data): number;    // returns event ID
  subscribe(channel, handler): () => void;  // returns unsubscribe
  replaySince(channel, lastEventId): BusEvent[];
  destroy(): void;
}

Design decisions

  • No Redis dependency β€” LocalEventBus is the default. Redis adapter is a future PR (phase C-D).
  • Typed channels β€” session:abc123, global, etc. Implementations decide routing.
  • Async delivery β€” setImmediate() for consistency with existing SessionEventBus.
  • Ring buffer replay β€” configurable size, LRU eviction, cursor-based via lastEventId.

Cleanup included

Stacking

Verification

tsc --noEmit: clean
93 tests passed (11 new + 82 existing event tests)

Part of #4229. Closes phase A-B.

…on (#4229 phase A-B)

Issue #4229: EventBus abstraction for session event fanout.

Adds:
- src/event-bus.ts: EventBus port interface (publish, subscribe,
  replaySince, destroy) with typed BusEvent envelope
- src/local-event-bus.ts: In-process implementation using EventEmitter
  with configurable ring buffer for replay

Design:
- Minimal interface β€” no delivery guarantees, implementations decide
- Typed channels: 'session:abc', 'global', etc.
- Monotonically increasing IDs for cursor-based replay
- Async delivery via setImmediate (consistent with SessionEventBus)

Tests: 11 new tests covering publish/subscribe, replay, buffer limits,
destroy, unsubscribe cleanup.

Cleanup: remove stale existsSync/readFileSync imports from server.ts
(step 7 of #4243).

Also bumps CI bundle threshold 2444 β†’ 2452 KB.
@aegis-gh-agent aegis-gh-agent Bot added the approved-minor-bump Approves a minor version bump for release-please label May 27, 2026
Copy link
Copy Markdown
Contributor

@aegis-gh-agent aegis-gh-agent Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

βœ… Approved. Clean EventBus interface + LocalEventBus implementation.

event-bus.ts (62 lines): Minimal port interface β€” publish, subscribe, replaySince, destroy. Well-typed BusEvent with channel/id/type/timestamp/data. No over-engineering. βœ…

local-event-bus.ts (104 lines): In-process implementation, zero external deps. Per-channel EventEmitters with ring buffers. Good: ID counter reset guard at MAX_SAFE_INTEGER, configurable buffer size, async delivery via setImmediate. βœ…

Tests (11): Solid coverage β€” pub/sub, unsubscribe, multi-subscriber, channel isolation, replay, buffer eviction, monotonic IDs, destroy, cleanup on last unsub, timestamps. βœ…

server.ts: Stale import cleanup (existsSync/readFileSync removed β€” the ones I flagged in #4336). βœ…

Minor observations (not blocking):

  1. void imm in publish() β€” either track the immediate handle for destroy() cleanup or just call setImmediate(...) without assignment.
  2. Buffer eviction via splice(0, excess) is O(n) β€” fine at buffer=50, worth a circular buffer if it grows.
  3. No guard for publish-after-destroy β€” calling publish() on a destroyed bus silently creates new emitters.

Approved-minor-bump label added, branch updated to re-trigger bump gate. CI: Node 20 failure is pre-existing E2E flake (Effort: high).

@aegis-gh-agent aegis-gh-agent Bot merged commit 08d2926 into develop May 27, 2026
16 of 17 checks passed
@aegis-gh-agent aegis-gh-agent Bot deleted the feat/4229-eventbus-interface branch May 27, 2026 09:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved-minor-bump Approves a minor version bump for release-please

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant