fix(09): WR-01 defer outbox drain emit to a microtask so a throwing listener cannot corrupt the enqueue route response

This commit is contained in:
Lucas Berger
2026-06-12 20:50:21 -04:00
parent 1bc1f134a7
commit 8307a7b713
+10 -2
View File
@@ -23,10 +23,18 @@ const emitter = new EventEmitter();
/**
* Fire a drain signal after a successful outbox enqueue commit.
* Synchronous and fire-and-forget — never awaited (D-04).
* Fire-and-forget — never awaited (D-04).
*
* WR-01: the emit is deferred to a microtask so the registered listener
* (scheduleOutboxDrain) never runs on the enqueue caller's stack. EventEmitter.emit
* dispatches listeners synchronously; without this defer, any synchronous throw in
* the listener chain would propagate back into the route handler's try/catch and
* surface a misleading 503 for an enqueue that actually committed. Deferring keeps
* the documented decoupling honest: a misbehaving listener can never corrupt the
* route response.
*/
export function signalOutboxDrain(): void {
emitter.emit('drain');
queueMicrotask(() => emitter.emit('drain'));
}
/**