fix(cross-context): keep broadcast receive after publish failure, report degraded open (R-2.3)
A tab whose BroadcastChannel postMessage failed once called closeBroadcast(), which also removed its receive listener. Publishers that broadcast successfully never write a storage pulse, so from then on the tab missed every other tab's event while reporting ACTIVE_STORAGE_FALLBACK. A tab whose BroadcastChannel failed to open had the same blind spot and the same healthy-looking status. Per D-4 there is no dual broadcast+storage publishing. Instead: - A publish failure only sets broadcastPublishFailed. Later publishes go to storage, and the channel stays open for receiving. - BROADCAST_OPEN_FAILED now yields the additive status DEGRADED_STORAGE_FALLBACK (the union lives in the adapter and is only passed through by bootstrap). A browser without BroadcastChannel at all keeps ACTIVE_STORAGE_FALLBACK, because every tab there uses storage. - A successful storage publish recomputes the status instead of forcing ACTIVE_STORAGE_FALLBACK, so it cannot hide the degraded state. Existing tests fixed: "falls back when BroadcastChannel open or publish fails" and "enters explicit local-only degradation when every transport fails" expected ACTIVE_STORAGE_FALLBACK for a tab whose channel failed to open. The ops runbook lists the new status. Verified: "keeps receiving broadcasts after its own broadcast publish fails" (received [] instead of [BROADCAST]) and the open-failure status assertion (ACTIVE_STORAGE_FALLBACK) failed before the fix and pass now. check:architecture, check:types:app, check:types:test, lint, test:component, verify:documentation pass. test:unit passes except removal-fixture, which needs generated artifacts/release files that a fresh worktree lacks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
d4f679374b
commit
a80b153163
@@ -54,7 +54,9 @@ session/account Query lifecycle, strict query policy와 Web Storage v2 lifecycle
|
||||
2. `cache.operation.failed`와 `storage.operation.failed`의 allowlisted
|
||||
operation/outcome/reason만으로 범위를 좁힌다.
|
||||
3. runtime status가 `ACTIVE_BROADCAST`, `ACTIVE_STORAGE_FALLBACK`,
|
||||
`DEGRADED_LOCAL_ONLY`, `CLOSED` 중 무엇인지 확인한다.
|
||||
`DEGRADED_STORAGE_FALLBACK`, `DEGRADED_LOCAL_ONLY`, `CLOSED` 중 무엇인지
|
||||
확인한다. `DEGRADED_STORAGE_FALLBACK`은 BroadcastChannel open에 실패한 tab이다.
|
||||
다른 tab이 broadcast로만 보낸 event를 받지 못한다.
|
||||
4. 현재 tab의 mutation 성공 후 local namespace가 stale 처리되는지 확인한다.
|
||||
5. 다른 tab의 오래된 화면이 단순 stale 표시인지, 실제 server authorization
|
||||
우회인지 분리한다. authorization 우회는 cache incident가 아니라 P1 security
|
||||
@@ -70,7 +72,7 @@ session/account Query lifecycle, strict query policy와 Web Storage v2 lifecycle
|
||||
- `BROADCAST_PUBLISH_FAILED`
|
||||
- `STORAGE_LISTENER_FAILED`
|
||||
- `STORAGE_PUBLISH_FAILED`
|
||||
- runtime status `DEGRADED_LOCAL_ONLY`
|
||||
- runtime status `DEGRADED_STORAGE_FALLBACK` 또는 `DEGRADED_LOCAL_ONLY`
|
||||
|
||||
### 확인
|
||||
|
||||
|
||||
@@ -13,6 +13,12 @@ import {
|
||||
export type CrossContextInvalidationStatus =
|
||||
| "ACTIVE_BROADCAST"
|
||||
| "ACTIVE_STORAGE_FALLBACK"
|
||||
/**
|
||||
* The browser has BroadcastChannel but this tab could not open it. Other
|
||||
* tabs publish on BroadcastChannel only, so this tab misses their events
|
||||
* while its own storage pulses still reach them.
|
||||
*/
|
||||
| "DEGRADED_STORAGE_FALLBACK"
|
||||
| "DEGRADED_LOCAL_ONLY"
|
||||
| "CLOSED";
|
||||
|
||||
@@ -176,6 +182,10 @@ export function createBrowserCrossContextInvalidation(
|
||||
let closed = false;
|
||||
let sequence = 0;
|
||||
let broadcast: BroadcastChannelFacade | undefined;
|
||||
let broadcastOpenFailed = false;
|
||||
// A failed postMessage moves publishing to storage but keeps the channel
|
||||
// open, because other tabs keep publishing on it.
|
||||
let broadcastPublishFailed = false;
|
||||
let storageListenerInstalled = false;
|
||||
let status: CrossContextInvalidationStatus = "DEGRADED_LOCAL_ONLY";
|
||||
|
||||
@@ -249,6 +259,7 @@ export function createBrowserCrossContextInvalidation(
|
||||
// Opening still falls back when provider cleanup is rejected.
|
||||
}
|
||||
}
|
||||
broadcastOpenFailed = true;
|
||||
observe({
|
||||
operation: "OPEN",
|
||||
outcome: "DEGRADED",
|
||||
@@ -261,14 +272,16 @@ export function createBrowserCrossContextInvalidation(
|
||||
function refreshStatus(): void {
|
||||
if (closed) {
|
||||
status = "CLOSED";
|
||||
} else if (broadcast) {
|
||||
} else if (broadcast && !broadcastPublishFailed) {
|
||||
status = "ACTIVE_BROADCAST";
|
||||
} else if (
|
||||
dependencies.storage &&
|
||||
dependencies.storageEvents &&
|
||||
storageListenerInstalled
|
||||
) {
|
||||
status = "ACTIVE_STORAGE_FALLBACK";
|
||||
status = broadcastOpenFailed
|
||||
? "DEGRADED_STORAGE_FALLBACK"
|
||||
: "ACTIVE_STORAGE_FALLBACK";
|
||||
} else {
|
||||
status = "DEGRADED_LOCAL_ONLY";
|
||||
}
|
||||
@@ -322,7 +335,7 @@ export function createBrowserCrossContextInvalidation(
|
||||
|
||||
sequence = candidate.sequence;
|
||||
pruneTracking(emittedAt);
|
||||
if (broadcast) {
|
||||
if (broadcast && !broadcastPublishFailed) {
|
||||
try {
|
||||
broadcast.postMessage(candidate);
|
||||
observe({
|
||||
@@ -342,7 +355,7 @@ export function createBrowserCrossContextInvalidation(
|
||||
transport: "BROADCAST",
|
||||
reason: "BROADCAST_PUBLISH_FAILED",
|
||||
});
|
||||
closeBroadcast();
|
||||
broadcastPublishFailed = true;
|
||||
refreshStatus();
|
||||
}
|
||||
}
|
||||
@@ -413,7 +426,7 @@ export function createBrowserCrossContextInvalidation(
|
||||
reason: "STORAGE_CLEANUP_FAILED",
|
||||
});
|
||||
}
|
||||
status = "ACTIVE_STORAGE_FALLBACK";
|
||||
refreshStatus();
|
||||
observe({
|
||||
operation: "PUBLISH",
|
||||
outcome: "ACCEPTED",
|
||||
|
||||
@@ -523,7 +523,9 @@ describe("browser cross-context invalidation transport", () => {
|
||||
const received = vi.fn();
|
||||
second.subscribe(received);
|
||||
|
||||
expect(second.getStatus()).toBe("ACTIVE_STORAGE_FALLBACK");
|
||||
// R-2.3. Other tabs publish on BroadcastChannel only, so a tab whose
|
||||
// channel failed to open misses their events and must not look healthy.
|
||||
expect(second.getStatus()).toBe("DEGRADED_STORAGE_FALLBACK");
|
||||
expect(first.publish({ topic: TOPIC, topicVersion: 1 })).toEqual({
|
||||
ok: true,
|
||||
transport: "STORAGE",
|
||||
@@ -534,11 +536,54 @@ describe("browser cross-context invalidation transport", () => {
|
||||
expect(firstStorage.storage.removeCount).toBe(1);
|
||||
expect(storageBus.values.has(STORAGE_PULSE_KEY)).toBe(false);
|
||||
expect(secondNetwork.channels).toHaveLength(0);
|
||||
expect(second.publish({ topic: TOPIC, topicVersion: 1 })).toEqual({
|
||||
ok: true,
|
||||
transport: "STORAGE",
|
||||
});
|
||||
expect(second.getStatus()).toBe("DEGRADED_STORAGE_FALLBACK");
|
||||
|
||||
first.close();
|
||||
second.close();
|
||||
});
|
||||
|
||||
it("keeps receiving broadcasts after its own broadcast publish fails", () => {
|
||||
const network = new FakeBroadcastNetwork();
|
||||
const storageBus = new FakeStorageBus();
|
||||
const senderStorage = storageBus.createEndpoint();
|
||||
const receiverStorage = storageBus.createEndpoint();
|
||||
const sender = createBrowserCrossContextInvalidation(
|
||||
dependencies("tab-a", {
|
||||
createBroadcastChannel: network.createChannel,
|
||||
storage: senderStorage.storage,
|
||||
storageEvents: senderStorage.target,
|
||||
}),
|
||||
);
|
||||
const receiver = createBrowserCrossContextInvalidation(
|
||||
dependencies("tab-b", {
|
||||
createBroadcastChannel: network.createChannel,
|
||||
storage: receiverStorage.storage,
|
||||
storageEvents: receiverStorage.target,
|
||||
}),
|
||||
);
|
||||
network.channels[1]!.failPost = true;
|
||||
expect(
|
||||
receiver.publish({ topic: TOPIC, topicVersion: 1 }),
|
||||
).toEqual({ ok: true, transport: "STORAGE" });
|
||||
const delivered: CrossContextInvalidationDelivery[] = [];
|
||||
receiver.subscribe((delivery) => delivered.push(delivery));
|
||||
|
||||
expect(
|
||||
sender.publish({ topic: TOPIC, topicVersion: 1 }),
|
||||
).toEqual({ ok: true, transport: "BROADCAST" });
|
||||
|
||||
expect(delivered.map(({ transport }) => transport)).toEqual([
|
||||
"BROADCAST",
|
||||
]);
|
||||
expect(receiver.getStatus()).toBe("ACTIVE_STORAGE_FALLBACK");
|
||||
sender.close();
|
||||
receiver.close();
|
||||
});
|
||||
|
||||
it("rejects storage pulses from another or unknown storage area", () => {
|
||||
const storageBus = new FakeStorageBus();
|
||||
const publisherStorage = storageBus.createEndpoint();
|
||||
@@ -599,7 +644,7 @@ describe("browser cross-context invalidation transport", () => {
|
||||
}),
|
||||
);
|
||||
|
||||
expect(runtime.getStatus()).toBe("ACTIVE_STORAGE_FALLBACK");
|
||||
expect(runtime.getStatus()).toBe("DEGRADED_STORAGE_FALLBACK");
|
||||
expect(runtime.publish({ topic: TOPIC, topicVersion: 1 })).toEqual({
|
||||
ok: false,
|
||||
reason: "TRANSPORT_UNAVAILABLE",
|
||||
|
||||
Reference in New Issue
Block a user