fix(realtime): refuse recovery once its quiescence ends in DRAINING (R-4.1)

runRecovery() checked lifecycle === "DRAINING" only on entry. After
`await quiescence` it re-checked closed/abort/scope but not DRAINING, so an
effect that timed out while the recovery waited left the stream DRAINING and
the recovery still called the authority, committed a new resume state and
cleared recoveryRequired while the abandoned effect kept running (the
RT-RR-01/02 case).

The post-quiescence check now also fails with CLOSED/RECOVER when the stream
is DRAINING, without calling the authority.

Test: "fails a recovery whose effect quiescence ends in DRAINING" in
stream-coordinator.test.ts. RED before the fix: the recovery resolved
{ ok: true } (authority called and committed). After: CLOSED, authority not
called, no resume state; once the late effect settles the stream is OPEN and
STALE.

Gates: check:architecture, check:types:app, check:types:test, lint,
test:component pass. test:unit passes except removal-fixture.test.ts, which
needs generated artifacts/release evidence absent from this fresh worktree
(unrelated).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
DongHyeonka
2026-09-24 12:19:48 +09:00
co-authored by Claude Opus 5.5
parent 87a45893d6
commit a6553e67bd
2 changed files with 55 additions and 1 deletions
+3 -1
View File
@@ -707,7 +707,9 @@ export function createRealtimeStreamCoordinator(
if (!calledFromCurrentJob) {
await quiescence;
}
if (closed || state.closed) {
// RT-RR-01. The effect this recovery waited on can time out and keep
// running; recovering beside it would let its late write win.
if (closed || state.closed || state.lifecycle === "DRAINING") {
state.freshness = "UNKNOWN";
return realtimeFailure("CLOSED", "RECOVER");
}