AI Agents SDE Task Viewer
      • Context
      • Plan
      • Prd
  1. Home
  2. AgentSDE
  3. agent-core
  4. gh-443
  5. plan
  6. plan.md
plan.md(3.1 KB)· Apr 13, 2026· 2 min read
  • Summary
  • Files
  • Steps
  • Verification
  • Risks

Plan — AW-7: Create EventBusService abstraction backed by Redis#

Summary#

Create a @Global() EventBusModule with EventBusService that wraps Redis pub/sub for typed, cross-process event delivery. Uses the existing ioredis dependency and REDIS_HOST/REDIS_PORT/REDIS_DB config. Runs alongside EventEmitter2 — no existing code is changed.

Files#

FileActionDescription
src/event-bus/event-bus.events.tscreateTyped event map: event name → payload interface for all 6 events
src/event-bus/event-bus.service.tscreateEventBusService — pub/sub client, emit(), on(), onModuleDestroy()
src/event-bus/event-bus.module.tscreate@Global() module: provides two ioredis clients (pub + sub), exports service
src/event-bus/index.tscreateBarrel export
src/event-bus/event-bus.service.spec.tscreateUnit tests: emit → Redis publish, handler invocation, multi-handler, error isolation
src/app.module.tsmodifyImport EventBusModule

Steps#

  1. Define typed event map — Create event-bus.events.ts with EventMap interface mapping each event name (task.updated, task.stuck, job.created, job.completed, job.failed, artefacts.synced) to its payload type. Derive payload shapes from current emit sites in task-state.service.ts, watchdog.service.ts, sqlite-job-queue.ts, phase-router.service.ts.
  2. Implement EventBusService — Create service with two ioredis clients (pub for publishing, sub for subscribing). Channel prefix: agentsde:events:. emit<K>(event, payload) serializes to JSON and publishes on pub client; catches errors, logs, and swallows. on<K>(event, handler) subscribes on sub client and dispatches to registered handlers. Multiple handlers per event supported. Handler errors caught individually. onModuleDestroy() quits both clients.
  3. Create EventBusModule — @Global() NestJS module. Factory-provides two ioredis clients from ConfigService (REDIS_HOST, REDIS_PORT, REDIS_DB). Follow the pattern in src/health/health.module.ts. Export EventBusService.
  4. Register in AppModule — Add EventBusModule to imports in src/app.module.ts.
  5. Write unit tests — Test cases: (a) emit() calls pub.publish() with correct channel and serialized payload, (b) on() handler receives deserialized payload on message, (c) multiple handlers all invoked, (d) error in one handler does not prevent others, (e) emit() swallows Redis errors and logs, (f) onModuleDestroy() quits both clients.
  6. Build and lint verification — Run npm run build and npm run lint to confirm zero errors.

Verification#

  • npm run build passes without errors
  • npm run test passes — all new and existing tests green
  • npm run lint passes with zero warnings

Risks#

  • Redis unavailability during emit: Mitigated by design — emit() catches all errors and logs without throwing. Pipeline advancement is driven by the job queue, not events.
  • Channel naming collision: Prefix agentsde:events: scopes channels to this application; documented in the event map.
ContextPrd