fix(release): share one reload-once guard between chunk and boot recovery (Q-6.9-9)
Chunk recovery kept its own guard: marker keyed by the release pair, no TTL, trusted write().ok. Round 1 fixed the boot guard (key-independent marker within a TTL, read-back check) but the chunk copy still reloaded on every failure when replicas alternated A->B, B->A. platform/release gains createReloadOnceGuard (the round-1 boot rule, now with a refusal reason); createReleaseMismatchRecovery wraps it with unchanged boot semantics (marker within TTL blocks regardless of key, markCoherentBoot clears), and decideChunkRecovery uses it over its own CHUNK_RELOAD_GUARD key, keeping its reason vocabulary. Application -> platform is allowed by .dependency-cruiser.json; platform may not import application, so the guard lives in platform. Behavior change (chunk only): a second reload within the TTL is refused even for a different release pair, and a marker that does not read back is guard-write-failed. tests/component/context-route-gateway.test.tsx used a preferences stub that dropped writes; it now persists them. Verified: tests/unit/chunk-recovery.test.ts characterization (read/write failure, same pair, invariants) green before the change; alternating pair test RED before, green after. Boot tests unchanged and green; FE-RB-002 drill PASS; test:integration PASS; all gates PASS. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
e119eb667a
commit
40659de7ec
@@ -1,3 +1,4 @@
|
||||
import { createReloadOnceGuard } from "../../platform/release/release-mismatch-recovery.ts";
|
||||
import type { StoragePort } from "../ports/storage-port.ts";
|
||||
|
||||
const RECOVERABLE_KINDS = new Set(["CHUNK_LOAD_FAILURE", "DEPLOY_MISMATCH"]);
|
||||
@@ -35,17 +36,25 @@ export function decideChunkRecovery(
|
||||
const releasePair =
|
||||
`${input.currentBuildId}/${input.currentReleaseId}` +
|
||||
`->${input.activeBuildId}/${input.activeReleaseId}`;
|
||||
const guard = input.storage.read("CHUNK_RELOAD_GUARD");
|
||||
if (!guard.ok) {
|
||||
return { action: "support", reason: "guard-read-failed" };
|
||||
}
|
||||
if (guard.value === releasePair) {
|
||||
return { action: "support", reason: "reload-already-attempted" };
|
||||
}
|
||||
|
||||
const recorded = input.storage.write("CHUNK_RELOAD_GUARD", releasePair);
|
||||
if (!recorded.ok) {
|
||||
return { action: "support", reason: "guard-write-failed" };
|
||||
}
|
||||
return { action: "reload-once", releasePair };
|
||||
// Q-6.9-9. The boot reload guard's rule: at most one automatic reload per
|
||||
// marker TTL, whatever the pair. A pair-keyed marker let replicas that
|
||||
// alternate A/B reload on every chunk failure.
|
||||
const decision = createReloadOnceGuard({
|
||||
read() {
|
||||
const guard = input.storage.read("CHUNK_RELOAD_GUARD");
|
||||
if (!guard.ok) throw new Error("chunk reload guard is unreadable");
|
||||
return typeof guard.value === "string" ? guard.value : null;
|
||||
},
|
||||
write(value) {
|
||||
if (!input.storage.write("CHUNK_RELOAD_GUARD", value).ok) {
|
||||
throw new Error("chunk reload guard was not persisted");
|
||||
}
|
||||
},
|
||||
clear() {
|
||||
input.storage.remove("CHUNK_RELOAD_GUARD");
|
||||
},
|
||||
}).decide(releasePair);
|
||||
return decision === "reload-once"
|
||||
? { action: "reload-once", releasePair }
|
||||
: { action: "support", reason: decision };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user