fix(session): invalidate snapshots before metadata write dispatch

Stop cached metadata replay before a provider write starts, including while its reply is pending or fails after applying the mutation. Keep snapshot import and export disabled until the target is reopened.

Validate failed replies, conflicting provider identity, and overlapping reads through the shared session boundary.
This commit is contained in:
morluto
2026-10-12 12:37:00 +08:00
parent 538f8cc722
commit 1c64fe3eff
4 changed files with 118 additions and 10 deletions
+3 -2
View File
@@ -588,6 +588,9 @@ export class BinarySession
if (!prepared.ok) return prepared;
const { active, capability, profile, cacheable, cached } = prepared.value;
if (cached !== undefined) return ok(cached);
// A failed reply cannot prove that a dispatched metadata write rolled back.
// Stop replay before dispatch, including reads overlapping the write.
if (capability.effects.mutatesArtifact) this.invalidateSnapshot();
const call = active.client.execute(name, arguments_, options);
const result = await call;
const profiled = bindExecutionTarget(
@@ -645,8 +648,6 @@ export class BinarySession
parameters: arguments_,
execution: execution.value,
});
} else if (profiled.ok && capability.effects.mutatesArtifact) {
this.invalidateSnapshot();
}
return execution;
}
@@ -144,9 +144,9 @@ export abstract class BinarySessionRecords {
if (this.#snapshotInvalidated)
return err(
new EvidenceIntegrityError(
"Analysis snapshots are unavailable after analysis metadata mutations",
"Analysis snapshots are unavailable because analysis metadata may have changed",
{
userMessage: `Analysis snapshots are unavailable after analysis metadata mutations. ${SNAPSHOT_MUTATION_RECOVERY}`,
userMessage: `Analysis snapshots are unavailable because analysis metadata may have changed. ${SNAPSHOT_MUTATION_RECOVERY}`,
},
),
);
@@ -177,9 +177,9 @@ export abstract class BinarySessionRecords {
if (active !== undefined && this.#snapshotInvalidated)
return err(
new EvidenceIntegrityError(
"Analysis snapshots cannot be imported after analysis metadata mutations",
"Analysis snapshots cannot be imported because analysis metadata may have changed",
{
userMessage: `Analysis snapshots cannot be imported after analysis metadata mutations. ${SNAPSHOT_MUTATION_RECOVERY}`,
userMessage: `Analysis snapshots cannot be imported because analysis metadata may have changed. ${SNAPSHOT_MUTATION_RECOVERY}`,
},
),
);