@sema-agent/core 7.62.0 → 7.63.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (193) hide show
  1. package/CHANGELOG.md +528 -0
  2. package/dist/agents/subagent-transcript-placement.d.ts +23 -0
  3. package/dist/agents/subagent-transcript-placement.js +14 -0
  4. package/dist/agents/subagent.js +82 -51
  5. package/dist/brain/route-adjudicator.js +9 -4
  6. package/dist/core/approval-object.js +1 -1
  7. package/dist/core/arg-summary.js +1 -1
  8. package/dist/core/ask-question.d.ts +2 -2
  9. package/dist/core/canonical-json.d.ts +23 -13
  10. package/dist/core/canonical-json.js +4 -4
  11. package/dist/core/checkpoint-queries.d.ts +47 -4
  12. package/dist/core/checkpoint-queries.js +36 -16
  13. package/dist/core/checkpoint-requirements.d.ts +3 -3
  14. package/dist/core/checkpoint-requirements.js +2 -1
  15. package/dist/core/checkpoint-row-verdict.d.ts +15 -4
  16. package/dist/core/checkpoint-row-verdict.js +22 -2
  17. package/dist/core/checkpoint-store.d.ts +23 -10
  18. package/dist/core/checkpoint-store.js +45 -4
  19. package/dist/core/compliance.d.ts +6 -2
  20. package/dist/core/compliance.js +3 -3
  21. package/dist/core/engine-attestation.d.ts +1 -1
  22. package/dist/core/engine-notice.d.ts +19 -4
  23. package/dist/core/git-worktree-env.d.ts +62 -3
  24. package/dist/core/git-worktree-env.js +91 -30
  25. package/dist/core/governance-codes.d.ts +7 -3
  26. package/dist/core/governance-codes.js +13 -3
  27. package/dist/core/memory-engine/consolidation-driver.d.ts +32 -17
  28. package/dist/core/memory-engine/consolidation-driver.js +99 -98
  29. package/dist/core/memory-engine/consolidation.d.ts +73 -10
  30. package/dist/core/memory-engine/consolidation.js +167 -11
  31. package/dist/core/memory-engine/data-plane.d.ts +8 -4
  32. package/dist/core/memory-engine/data-plane.js +11 -6
  33. package/dist/core/memory-engine/delegation-settlement.d.ts +37 -35
  34. package/dist/core/memory-engine/delegation-settlement.js +53 -59
  35. package/dist/core/memory-engine/dual-root.d.ts +12 -6
  36. package/dist/core/memory-engine/dual-root.js +9 -5
  37. package/dist/core/memory-engine/engine.d.ts +98 -35
  38. package/dist/core/memory-engine/engine.js +477 -380
  39. package/dist/core/memory-engine/entry-scan.d.ts +8 -0
  40. package/dist/core/memory-engine/entry-scan.js +3 -0
  41. package/dist/core/memory-engine/file-backend.d.ts +29 -3
  42. package/dist/core/memory-engine/file-backend.js +66 -35
  43. package/dist/core/memory-engine/index.d.ts +7 -7
  44. package/dist/core/memory-engine/index.js +6 -6
  45. package/dist/core/memory-engine/landing-admission.d.ts +5 -3
  46. package/dist/core/memory-engine/landing-admission.js +3 -3
  47. package/dist/core/memory-engine/layout.d.ts +121 -45
  48. package/dist/core/memory-engine/layout.js +252 -102
  49. package/dist/core/memory-engine/memory-backend-contract.d.ts +19 -1
  50. package/dist/core/memory-engine/memory-backend-contract.js +320 -0
  51. package/dist/core/memory-engine/memory-deployment.d.ts +31 -8
  52. package/dist/core/memory-engine/memory-deployment.js +26 -12
  53. package/dist/core/memory-engine/scope-contract.d.ts +52 -11
  54. package/dist/core/memory-engine/scope-contract.js +68 -19
  55. package/dist/core/memory-engine/session-write-home.d.ts +3 -1
  56. package/dist/core/memory-engine/session-write-home.js +1 -1
  57. package/dist/core/memory-engine/sync-client.d.ts +3 -1
  58. package/dist/core/memory-engine/sync-client.js +7 -0
  59. package/dist/core/memory-engine/sync-report.d.ts +3 -2
  60. package/dist/core/memory-engine/sync-report.js +6 -2
  61. package/dist/core/memory-engine/tools.d.ts +2 -2
  62. package/dist/core/memory-engine/tools.js +10 -10
  63. package/dist/core/memory-engine/types.d.ts +118 -19
  64. package/dist/core/memory-engine/types.js +1 -0
  65. package/dist/core/memory.js +15 -6
  66. package/dist/core/mods/stations.d.ts +20 -1
  67. package/dist/core/mods/stations.js +21 -2
  68. package/dist/core/park-selfcheck.js +2 -2
  69. package/dist/core/pause-registry.d.ts +2 -0
  70. package/dist/core/pause-registry.js +3 -0
  71. package/dist/core/permission-rule-consent.d.ts +10 -3
  72. package/dist/core/permission-rule-consent.js +37 -24
  73. package/dist/core/permission-rule-store.d.ts +35 -1
  74. package/dist/core/permission-rule-store.js +27 -8
  75. package/dist/core/read-only-shell.js +3 -2
  76. package/dist/core/redaction-marks.d.ts +8 -0
  77. package/dist/core/redaction-marks.js +6 -0
  78. package/dist/core/remote-env.d.ts +12 -1
  79. package/dist/core/remote-env.js +3 -0
  80. package/dist/core/runner/child-tree.d.ts +29 -3
  81. package/dist/core/runner/child-tree.js +39 -16
  82. package/dist/core/runner/contracts.d.ts +18 -9
  83. package/dist/core/runner/gate-exit.js +2 -2
  84. package/dist/core/runner/inherited-ask-grants.js +1 -1
  85. package/dist/core/runner/memory-consolidation-driver.d.ts +6 -3
  86. package/dist/core/runner/memory-consolidation-driver.js +4 -4
  87. package/dist/core/runner/memory-consolidation-write-judge.d.ts +2 -1
  88. package/dist/core/runner/memory-consolidation-write-judge.js +3 -2
  89. package/dist/core/runner/person-path-rows.d.ts +8 -3
  90. package/dist/core/runner/person-path-rows.js +5 -1
  91. package/dist/core/runner/placement-fence.d.ts +12 -0
  92. package/dist/core/runner/placement-fence.js +20 -6
  93. package/dist/core/runner/prepare-ask-lane.js +2 -2
  94. package/dist/core/runner/prepare-caps-and-workflow.d.ts +4 -1
  95. package/dist/core/runner/prepare-caps-and-workflow.js +5 -2
  96. package/dist/core/runner/prepare-execution-env.js +17 -6
  97. package/dist/core/runner/prepare-hands-readface.d.ts +2 -1
  98. package/dist/core/runner/prepare-hands-readface.js +4 -3
  99. package/dist/core/runner/prepare-inherited-gate.d.ts +10 -8
  100. package/dist/core/runner/prepare-inherited-gate.js +8 -4
  101. package/dist/core/runner/prepare-memory-engine-session.d.ts +2 -4
  102. package/dist/core/runner/prepare-memory-engine-session.js +4 -4
  103. package/dist/core/runner/prepare-memory.d.ts +3 -2
  104. package/dist/core/runner/prepare-memory.js +28 -20
  105. package/dist/core/runner/prepare-park-ask.js +4 -3
  106. package/dist/core/runner/prepare-task.js +15 -12
  107. package/dist/core/runner/prepare-workspace-restore.js +3 -6
  108. package/dist/core/runner/run-leg.js +1 -1
  109. package/dist/core/runner/run-settle-and-teardown.js +3 -2
  110. package/dist/core/runner/terminal-account.js +1 -1
  111. package/dist/core/runner-deps.d.ts +6 -2
  112. package/dist/core/secret-env.d.ts +1 -1
  113. package/dist/core/secret-env.js +4 -4
  114. package/dist/core/session-checkout.d.ts +108 -0
  115. package/dist/core/session-checkout.js +485 -0
  116. package/dist/core/session-store.d.ts +12 -4
  117. package/dist/core/session-store.js +23 -3
  118. package/dist/core/session.d.ts +16 -2
  119. package/dist/core/session.js +3 -0
  120. package/dist/core/store-contracts/checkpoint-store-contract.d.ts +0 -12
  121. package/dist/core/store-contracts/checkpoint-store-contract.js +6 -7
  122. package/dist/core/store-contracts/session-store-contract.js +39 -0
  123. package/dist/core/task-event.d.ts +21 -0
  124. package/dist/core/task-notification.d.ts +9 -1
  125. package/dist/core/task-notification.js +6 -0
  126. package/dist/core/task-registry-agent.d.ts +14 -2
  127. package/dist/core/task-registry-agent.js +45 -19
  128. package/dist/core/task-registry-shared.d.ts +26 -11
  129. package/dist/core/task-registry.d.ts +15 -9
  130. package/dist/core/task-registry.js +9 -10
  131. package/dist/core/task-spec-members.js +1 -1
  132. package/dist/core/task-spec.d.ts +20 -0
  133. package/dist/core/tool-policy.d.ts +14 -12
  134. package/dist/core/tool-policy.js +11 -10
  135. package/dist/core/tool-spec.d.ts +38 -19
  136. package/dist/core/types.d.ts +1 -1
  137. package/dist/core/untrusted-egress.d.ts +15 -4
  138. package/dist/core/untrusted-egress.js +23 -22
  139. package/dist/core/workspace-snapshot.d.ts +3 -1
  140. package/dist/core/workspace-snapshot.js +1 -0
  141. package/dist/engine/harness/types.d.ts +66 -1
  142. package/dist/engine/harness/types.js +108 -0
  143. package/dist/engine/session/import-validate.js +6 -1
  144. package/dist/engine/session/session.d.ts +24 -1
  145. package/dist/engine/session/session.js +45 -1
  146. package/dist/index.d.ts +7 -4
  147. package/dist/index.js +7 -4
  148. package/dist/internal/harness-types.d.ts +1 -1
  149. package/dist/orchestration/run-workflow-tool.d.ts +4 -1
  150. package/dist/orchestration/run-workflow-tool.js +1 -0
  151. package/dist/orchestration/workflow.d.ts +3 -0
  152. package/dist/orchestration/workflow.js +3 -1
  153. package/dist/stores/file/session-store.js +2 -1
  154. package/dist/tools/fs/bash-program-position.js +3 -3
  155. package/dist/tools/fs/program-read-model.d.ts +34 -10
  156. package/dist/tools/fs/program-read-model.js +37 -7
  157. package/dist/tools/fs/program-read-model.rows.js +13 -2
  158. package/dist/tools/fs/read-deny.d.ts +13 -1
  159. package/dist/tools/fs/read-deny.js +10 -2
  160. package/dist/tools/fs/removal-targets.js +3 -3
  161. package/dist/tools/fs/safety.d.ts +2 -0
  162. package/dist/tools/fs/safety.js +1 -1
  163. package/dist/tools/fs/shell-read-argv.d.ts +8 -1
  164. package/dist/tools/fs/shell-read-argv.js +34 -29
  165. package/dist/tools/fs/shell-read-bindings.d.ts +2 -0
  166. package/dist/tools/fs/shell-read-bindings.js +5 -1
  167. package/dist/tools/fs/shell-read-brace.d.ts +18 -0
  168. package/dist/tools/fs/shell-read-brace.js +79 -0
  169. package/dist/tools/fs/shell-read-check.js +10 -8
  170. package/dist/tools/fs/shell-read-establish.js +23 -16
  171. package/dist/tools/fs/shell-read-judge.d.ts +11 -0
  172. package/dist/tools/fs/shell-read-judge.js +3 -3
  173. package/dist/tools/fs/shell-read-plan.d.ts +10 -0
  174. package/dist/tools/fs/shell-read-plan.js +189 -93
  175. package/dist/tools/fs/shell-read-start.d.ts +19 -9
  176. package/dist/tools/fs/shell-read-start.js +20 -12
  177. package/dist/tools/fs/shell-read-word.d.ts +10 -0
  178. package/dist/tools/fs/shell-read-word.js +9 -5
  179. package/dist/tools/fs/shell-read-workdir.d.ts +26 -7
  180. package/dist/tools/fs/shell-read-workdir.js +73 -12
  181. package/dist/tools/fs/shell-read-write-targets.js +13 -8
  182. package/dist/tools/worktree.d.ts +3 -2
  183. package/dist/tools/worktree.js +7 -35
  184. package/package.json +3 -2
  185. package/test/export-surface.snapshot.json +73 -11
  186. package/wire-changes/core-stores-sql@7.63.0.json +30 -0
  187. package/wire-changes/core@7.63.0.json +3523 -0
  188. package/wire-changes/mods-kernel@7.63.0.json +30 -0
  189. package/wire-changes/primitives@7.63.0.json +445 -0
  190. package/dist/core/credential-vocabulary.d.ts +0 -176
  191. package/dist/core/credential-vocabulary.js +0 -190
  192. package/dist/core/redaction-passes.d.ts +0 -82
  193. package/dist/core/redaction-passes.js +0 -377
@@ -1,4 +1,4 @@
1
- import type { MemoryBackend } from "./types.js";
1
+ import { type MemoryBackend, type MemoryGovernanceDocName, type MemoryGovernanceStore } from "./types.js";
2
2
  export interface MemoryBackendContractHooks {
3
3
  make: () => Promise<MemoryBackend> | MemoryBackend;
4
4
  /** A second backend instance over the SAME storage as the given one (cross-instance CAS cases). */
@@ -28,6 +28,24 @@ export interface MemoryBackendContractHooks {
28
28
  }
29
29
  /** Run the full conformance suite. Throws (assert) on the first violated contract clause. */
30
30
  export declare function memoryBackendContract(hooks: MemoryBackendContractHooks): Promise<void>;
31
+ export interface MemoryGovernanceStoreContractHooks {
32
+ /** A FRESH, EMPTY store per case. */
33
+ make: () => Promise<MemoryGovernanceStore> | MemoryGovernanceStore;
34
+ /** Leave `store`'s record of `record` malformed in its own storage (bytes that are not the record's shape — for a
35
+ * governance document, bytes that do not parse): the fail-closed cases read it back and must be refused, never read
36
+ * as an empty record. */
37
+ corrupt: (store: MemoryGovernanceStore, record: "gate" | "intents" | "run" | MemoryGovernanceDocName) => Promise<void> | void;
38
+ /** Wrap each case (vitest `it`, …). Default: run sequentially. */
39
+ runAssertion?: (name: string, fn: () => Promise<void>) => void | Promise<void>;
40
+ }
41
+ /**
42
+ * The consolidation store conformance suite (`MemoryBackend.governance`): what an engine relies on when it keeps its
43
+ * consolidation state in a store — a missing record reads empty and a malformed one is refused, a transaction's reads
44
+ * and writes are not interleaved by another's (the plan owner fence and the seat CAS), the run claim's newer writer
45
+ * wins and the older one stops, and a mint archive can be written, read and erased. Runner-agnostic (node:assert);
46
+ * throws on the first violated clause.
47
+ */
48
+ export declare function memoryGovernanceStoreContract(hooks: MemoryGovernanceStoreContractHooks): Promise<void>;
31
49
  /** Cross-backend value equivalence: same fixture ⇒ IDENTICAL (id, slug, score) search projections on
32
50
  * two backends (File vs Pg lexical floor must not drift — assertMemoryValueEquivalence precedent).
33
51
  * mtimeMs/sizeBytes are backend-native (fs stat vs column) and deliberately not compared. */
@@ -1,5 +1,7 @@
1
1
  import assert from "node:assert";
2
2
  import { computeEntryRev } from "./frontmatter.js";
3
+ import { MEMORY_GOVERNANCE_DOC_NAMES } from "./types.js";
4
+ import { ControlPlaneCorruptError } from "./layout.js";
3
5
  function entry(id, scope, slug, body, fm = {}) {
4
6
  const e = { id, scope, slug, frontmatter: { ...fm }, body, rev: "" };
5
7
  e.rev = computeEntryRev(e);
@@ -36,6 +38,15 @@ export async function memoryBackendContract(hooks) {
36
38
  assert.strictEqual((await b.listHeaders([])).length, 0);
37
39
  assert.strictEqual((await b.listHeaders(["nope"])).length, 0);
38
40
  });
41
+ defer("search answers only the scopes asked — a query naming s1 never returns an s2 entry", async () => {
42
+ const b = await hooks.make();
43
+ await b.applyPatches([
44
+ { op: "add", id: "id-sfence1-01", entry: entry("id-sfence1-01", "s1", "lantern-one", "lantern harbor signal") },
45
+ { op: "add", id: "id-sfence2-01", entry: entry("id-sfence2-01", "s2", "lantern-two", "lantern harbor signal") },
46
+ ]);
47
+ assert.deepStrictEqual((await b.search("lantern harbor", ["s1"])).map((h) => h.id), ["id-sfence1-01"], "only the s1 entry answers a query naming s1");
48
+ assert.deepStrictEqual((await b.search("lantern harbor", ["s2"])).map((h) => h.id), ["id-sfence2-01"], "control: the s2 entry is findable, and answers only a query naming s2");
49
+ });
39
50
  defer("getByIds silently skips unknown ids", async () => {
40
51
  const b = await hooks.make();
41
52
  await b.applyPatches([{ op: "add", id: "id-known-01", entry: entry("id-known-01", "s1", "known", "kb") }]);
@@ -71,6 +82,25 @@ export async function memoryBackendContract(hooks) {
71
82
  const got = await b.getByIds(["id-cas-0001"]);
72
83
  assert.strictEqual(got[0].body.replace(/\s+$/, ""), "v2", "the CAS winner's content must survive");
73
84
  });
85
+ defer("update with a STALE baseRev conflicts even when its new bytes equal the committed bytes", async () => {
86
+ const b = await hooks.make();
87
+ const v1 = entry("id-casbyte-01", "s1", "note", "v1");
88
+ await b.applyPatches([{ op: "add", id: v1.id, entry: v1 }]);
89
+ const v2 = entry("id-casbyte-01", "s1", "note", "v2");
90
+ await b.applyPatches([{ op: "update", id: "id-casbyte-01", entry: v2, baseRev: v1.rev }]);
91
+ const same = entry("id-casbyte-01", "s1", "note", "v2");
92
+ assert.strictEqual(same.rev, v2.rev, "the fixture: the stale writer's rev equals the committed rev");
93
+ const rep = await b.applyPatches([{ op: "update", id: "id-casbyte-01", entry: same, baseRev: v1.rev }]);
94
+ assert.strictEqual(rep.applied.length, 0, "a stale baseRev applies nothing, whatever its bytes are");
95
+ assert.strictEqual(rep.conflicts.length, 1);
96
+ assert.strictEqual(rep.conflicts[0].id, "id-casbyte-01");
97
+ assert.strictEqual(rep.conflicts[0].baseRev, v1.rev);
98
+ assert.strictEqual(rep.conflicts[0].currentRev, v2.rev, "the conflict names the committed rev");
99
+ const got = await b.getByIds(["id-casbyte-01"]);
100
+ assert.strictEqual(got.length, 1);
101
+ assert.strictEqual(got[0].rev, v2.rev, "the committed state does not move");
102
+ assert.strictEqual(got[0].body.replace(/\s+$/, ""), "v2");
103
+ });
74
104
  defer("delete removes the entry; unknown-id update/delete are conflicts", async () => {
75
105
  const b = await hooks.make();
76
106
  const e = entry("id-del-0001", "s1", "gone", "bye");
@@ -85,6 +115,44 @@ export async function memoryBackendContract(hooks) {
85
115
  assert.strictEqual(rep2.applied.length, 0);
86
116
  assert.strictEqual(rep2.conflicts.length, 2);
87
117
  });
118
+ defer("a delete leaves the entry in no read face — listHeaders, getByIds and search are all empty of it", async () => {
119
+ const b = await hooks.make();
120
+ const gone = entry("id-faces-gone1", "s1", "faces-gone", "quartz zebra marker");
121
+ const kept = entry("id-faces-kept1", "s1", "faces-kept", "quartz zebra marker too");
122
+ await b.applyPatches([
123
+ { op: "add", id: gone.id, entry: gone },
124
+ { op: "add", id: kept.id, entry: kept },
125
+ ]);
126
+ const ids = async () => ({
127
+ headers: (await b.listHeaders(["s1"])).map((h) => h.id).sort(),
128
+ got: (await b.getByIds([gone.id, kept.id])).map((x) => x.id).sort(),
129
+ hits: (await b.search("quartz zebra", ["s1"])).map((h) => h.id).sort(),
130
+ });
131
+ const both = [gone.id, kept.id].sort();
132
+ assert.deepStrictEqual(await ids(), { headers: both, got: both, hits: both }, "control: before the delete every face serves both entries");
133
+ const rep = await b.applyPatches([{ op: "delete", id: gone.id, baseRev: gone.rev }]);
134
+ assert.deepStrictEqual(rep.conflicts, []);
135
+ assert.deepStrictEqual(await ids(), { headers: [kept.id], got: [kept.id], hits: [kept.id] }, "after the delete no face serves the deleted entry");
136
+ });
137
+ defer("an evidenced erase leaves the entry in no read face — listHeaders, getByIds and search (optional seat)", async () => {
138
+ const b = await hooks.make();
139
+ const seat = b.eraseWithEvidence;
140
+ if (typeof seat !== "function")
141
+ return;
142
+ const erase = seat;
143
+ const gone = entry("id-efaces-gone1", "s1", "efaces-gone", "quartz zebra marker");
144
+ const kept = entry("id-efaces-kept1", "s1", "efaces-kept", "quartz zebra marker too");
145
+ await b.applyPatches([
146
+ { op: "add", id: gone.id, entry: gone },
147
+ { op: "add", id: kept.id, entry: kept },
148
+ ]);
149
+ assert.deepStrictEqual((await b.search("quartz zebra", ["s1"])).map((h) => h.id).sort(), [gone.id, kept.id].sort(), "control: the search face serves both entries before the erase");
150
+ const att = await erase.call(b, { requestId: "req-faces-1", select: { ids: [gone.id] } });
151
+ assert.deepStrictEqual(att.erased.map((r) => r.id), [gone.id]);
152
+ assert.deepStrictEqual((await b.listHeaders(["s1"])).map((h) => h.id), [kept.id], "listHeaders no longer lists the erased entry");
153
+ assert.deepStrictEqual((await b.getByIds([gone.id, kept.id])).map((x) => x.id), [kept.id], "getByIds no longer returns the erased entry");
154
+ assert.deepStrictEqual((await b.search("quartz zebra", ["s1"])).map((h) => h.id), [kept.id], "search no longer returns the erased entry");
155
+ });
88
156
  defer("at most ONE non-delete op per id per batch — the later one conflicts", async () => {
89
157
  const b = await hooks.make();
90
158
  const a1 = entry("id-dup-0001", "s1", "one", "first");
@@ -865,6 +933,258 @@ export async function memoryBackendContract(hooks) {
865
933
  for (const [name, fn] of cases)
866
934
  await run(name, fn);
867
935
  }
936
+ function governancePlan(planId, over = {}) {
937
+ return { v: 1, planId, scope: "s1", requestId: "req-1", createdAt: 1, epoch: 0, visibleMarked: false, products: [], productStates: {}, directed: [], intents: [], state: "open", audit: [], ...over };
938
+ }
939
+ function governanceRun(scope, runId, over = {}) {
940
+ return {
941
+ runId,
942
+ scope,
943
+ attempt: 1,
944
+ requestId: `run-${runId}`,
945
+ contractVersion: "v1",
946
+ model: "m",
947
+ startedAt: 1,
948
+ state: "pending",
949
+ cyclesDone: 0,
950
+ entriesSuperseded: 0,
951
+ planIds: [],
952
+ usage: { calls: 0, promptTokens: 0, completionTokens: 0, retries: 0, truncations: 0 },
953
+ repairs: { hallucinatedMembers: 0, duplicateMembers: 0, nonIntegerMembers: 0, emptyGroups: 0, oversizeGroups: 0 },
954
+ writeFailures: [],
955
+ ...over,
956
+ };
957
+ }
958
+ async function rejectsCoded(p, code, what) {
959
+ let err;
960
+ try {
961
+ await p;
962
+ }
963
+ catch (e) {
964
+ err = e;
965
+ }
966
+ assert.ok(err !== undefined, `${what}: expected a refusal, got an answer`);
967
+ const field = (key) => (typeof err === "object" && err !== null ? Reflect.get(err, key) : undefined);
968
+ const got = field("code") ?? field("name");
969
+ if (typeof code === "string")
970
+ assert.strictEqual(got, code, `${what}: refused with ${String(got)}`);
971
+ else
972
+ assert.match(String(got), code, `${what}: refused with ${String(got)}`);
973
+ }
974
+ export async function memoryGovernanceStoreContract(hooks) {
975
+ const cases = [];
976
+ const defer = (name, fn) => cases.push([name, fn]);
977
+ defer("a record never written reads absent / empty — never corrupt", async () => {
978
+ const s = await hooks.make();
979
+ assert.deepStrictEqual(await s.readGate(), {});
980
+ assert.deepStrictEqual(await s.readPlan("plan-absent-0001"), { state: "absent" });
981
+ assert.deepStrictEqual(await s.listPlanIds(), []);
982
+ assert.deepStrictEqual(await s.readIntents(), {});
983
+ assert.strictEqual(await s.readRun("s1"), undefined);
984
+ assert.strictEqual(await s.readMint("0190aaaa-run-a1.json"), undefined);
985
+ assert.strictEqual(await s.eraseMint("0190aaaa-run-a1.json"), false);
986
+ });
987
+ for (const record of ["gate", "intents", "run"]) {
988
+ defer(`a malformed ${record} record is refused (fail-closed), never read as empty`, async () => {
989
+ const s = await hooks.make();
990
+ await hooks.corrupt(s, record);
991
+ const read = record === "gate" ? s.readGate() : record === "intents" ? s.readIntents() : s.readRun("s1");
992
+ await rejectsCoded(read, /ControlPlaneCorruptError|corrupt/i, `${record} read over a malformed record`);
993
+ if (record === "gate")
994
+ await rejectsCoded(s.transact([], () => ({ writeGate: true, result: undefined })), /ControlPlaneCorruptError|corrupt/i, "a transaction over a malformed gate");
995
+ });
996
+ }
997
+ defer("a transaction's row and plan writes land after it returns; a throw inside it writes nothing", async () => {
998
+ const s = await hooks.make();
999
+ await assert.rejects(s.transact(["plan-txn-00001"], (tx) => {
1000
+ tx.scopes["s1"] = { sessions: { count: 1, ring: ["a"] }, epoch: 0, openPlanId: "plan-txn-00001" };
1001
+ tx.writePlan(governancePlan("plan-txn-00001"));
1002
+ throw new Error("abort");
1003
+ }), /abort/);
1004
+ assert.deepStrictEqual(await s.readGate(), {});
1005
+ assert.deepStrictEqual(await s.readPlan("plan-txn-00001"), { state: "absent" });
1006
+ const answer = await s.transact(["plan-txn-00001"], (tx) => {
1007
+ assert.deepStrictEqual(tx.plan("plan-txn-00001"), { state: "absent" });
1008
+ tx.scopes["s1"] = { sessions: { count: 1, ring: ["a"] }, epoch: 0, openPlanId: "plan-txn-00001" };
1009
+ tx.writePlan(governancePlan("plan-txn-00001"));
1010
+ return { writeGate: true, result: "done" };
1011
+ });
1012
+ assert.strictEqual(answer, "done");
1013
+ assert.strictEqual((await s.readGate())["s1"]?.openPlanId, "plan-txn-00001");
1014
+ const read = await s.readPlan("plan-txn-00001");
1015
+ assert.strictEqual(read.state, "ok");
1016
+ assert.deepStrictEqual(await s.listPlanIds(), ["plan-txn-00001"]);
1017
+ await s.transact(["plan-txn-00001"], (tx) => {
1018
+ tx.scopes["s1"].epoch = 99;
1019
+ tx.writePlan(governancePlan("plan-txn-00001", { state: "applying" }));
1020
+ return { writeGate: false, result: undefined };
1021
+ });
1022
+ assert.strictEqual((await s.readGate())["s1"]?.epoch, 0);
1023
+ const after = await s.readPlan("plan-txn-00001");
1024
+ assert.ok(after.state === "ok" && after.plan.state === "applying");
1025
+ });
1026
+ defer("takeover cannot land between a transaction's owner read and its plan write (the owner fence)", async () => {
1027
+ const s = await hooks.make();
1028
+ await s.transact([], (tx) => {
1029
+ tx.writePlan(governancePlan("plan-fence-0001", { applier: "first" }));
1030
+ return { writeGate: false, result: undefined };
1031
+ });
1032
+ const holder = (me) => s.transact(["plan-fence-0001"], (tx) => {
1033
+ const cur = tx.plan("plan-fence-0001");
1034
+ if (cur.state !== "ok" || cur.plan.applier !== "first")
1035
+ return { writeGate: false, result: false };
1036
+ tx.writePlan({ ...cur.plan, applier: me });
1037
+ return { writeGate: false, result: true };
1038
+ });
1039
+ const won = await Promise.all([holder("A"), holder("B"), holder("C")]);
1040
+ assert.strictEqual(won.filter(Boolean).length, 1, `exactly one holder may take the plan over the applier it read (got ${JSON.stringify(won)})`);
1041
+ const final = await s.readPlan("plan-fence-0001");
1042
+ assert.ok(final.state === "ok" && final.plan.applier === ["A", "B", "C"][won.indexOf(true)]);
1043
+ });
1044
+ defer("the seat CAS: of racing claims on one scope's row exactly one wins", async () => {
1045
+ const s = await hooks.make();
1046
+ const claim = (planId) => s.transact([], (tx) => {
1047
+ const row = tx.scopes["s1"] ?? { sessions: { count: 0, ring: [] }, epoch: 0 };
1048
+ if (row.openPlanId !== undefined)
1049
+ return { writeGate: false, result: false };
1050
+ row.openPlanId = planId;
1051
+ tx.scopes["s1"] = row;
1052
+ return { writeGate: true, result: true };
1053
+ });
1054
+ const won = await Promise.all(["plan-cas-00001", "plan-cas-00002", "plan-cas-00003", "plan-cas-00004"].map(claim));
1055
+ assert.strictEqual(won.filter(Boolean).length, 1);
1056
+ });
1057
+ defer("the run claim: a pending run is resumed with its attempt bumped; the superseded writer is refused and writes nothing", async () => {
1058
+ const s = await hooks.make();
1059
+ const opened = await s.claimRun("s1", () => governanceRun("s1", "0190aaaa-run1"));
1060
+ assert.strictEqual(opened.resumed, false);
1061
+ assert.strictEqual(opened.row.attempt, 1);
1062
+ const resumed = await s.claimRun("s1", () => governanceRun("s1", "0190aaaa-other"));
1063
+ assert.strictEqual(resumed.resumed, true);
1064
+ assert.strictEqual(resumed.row.runId, "0190aaaa-run1");
1065
+ assert.strictEqual(resumed.row.attempt, 2);
1066
+ await rejectsCoded(s.writeRun({ ...opened.row, cyclesDone: 7 }), "memory.consolidation_driver_superseded", "the attempt-1 writer after the attempt-2 claim");
1067
+ assert.strictEqual((await s.readRun("s1"))?.cyclesDone, 0);
1068
+ await s.writeRun({ ...resumed.row, cyclesDone: 3, state: "settled" });
1069
+ assert.strictEqual((await s.readRun("s1"))?.cyclesDone, 3);
1070
+ const fresh = await s.claimRun("s1", () => governanceRun("s1", "0190aaaa-run2"));
1071
+ assert.strictEqual(fresh.resumed, false, "a settled run is not resumed: the claim opens a new one");
1072
+ assert.strictEqual(fresh.row.runId, "0190aaaa-run2");
1073
+ });
1074
+ defer("intent credentials are idempotent on requestId: the standing row wins", async () => {
1075
+ const s = await hooks.make();
1076
+ const row = { requestId: "intent-1", state: "settled", planId: "plan-int-00001", at: 1, patches: [] };
1077
+ assert.deepStrictEqual(await s.recordIntents([row]), ["intent-1"]);
1078
+ assert.deepStrictEqual(await s.recordIntents([{ ...row, state: "abandoned", planId: "plan-int-00002" }]), []);
1079
+ assert.strictEqual((await s.readIntents())["intent-1"]?.planId, "plan-int-00001");
1080
+ });
1081
+ defer("a discarded plan moves to custody: its bytes kept, out of the workbook", async () => {
1082
+ const s = await hooks.make();
1083
+ await s.transact([], (tx) => {
1084
+ tx.writePlan(governancePlan("plan-qtn-00001"));
1085
+ return { writeGate: false, result: undefined };
1086
+ });
1087
+ const custody = await s.quarantinePlan("plan-qtn-00001");
1088
+ assert.ok(typeof custody === "string" && custody.length > 0);
1089
+ assert.deepStrictEqual(await s.listPlanIds(), []);
1090
+ assert.deepStrictEqual(await s.readPlan("plan-qtn-00001"), { state: "absent" });
1091
+ assert.strictEqual(await s.quarantinePlan("plan-qtn-00001"), undefined);
1092
+ });
1093
+ defer("a mint archive is written, read back verbatim and erased (gone, not moved)", async () => {
1094
+ const s = await hooks.make();
1095
+ const plan = JSON.parse('{"kind":"llm-consolidation-plan","contractVersion":"v1","model":"m","maxInputsPerProduct":4,"products":[],"transcript":[{"role":"user","content":"the shown library"}]}');
1096
+ const name = await s.archiveMint("0190aaaa-run1", 2, plan);
1097
+ assert.deepStrictEqual(await s.readMint(name), plan);
1098
+ assert.strictEqual(await s.eraseMint(name), true);
1099
+ assert.strictEqual(await s.readMint(name), undefined);
1100
+ assert.strictEqual(await s.eraseMint(name), false);
1101
+ });
1102
+ const judgeDoc = (raw) => {
1103
+ if (raw === undefined)
1104
+ return { v: 1, owner: "", n: 0 };
1105
+ if (typeof raw !== "object" || raw === null || Reflect.get(raw, "v") !== 1)
1106
+ throw new ControlPlaneCorruptError("governance document has the wrong shape");
1107
+ return raw;
1108
+ };
1109
+ defer("every governance document never written reads undefined, and its first update is handed undefined", async () => {
1110
+ const s = await hooks.make();
1111
+ for (const name of MEMORY_GOVERNANCE_DOC_NAMES) {
1112
+ assert.strictEqual(await s.readDoc(name), undefined, `${name} before any write`);
1113
+ let handed = "not called";
1114
+ await s.updateDoc(name, (raw) => {
1115
+ handed = raw;
1116
+ return judgeDoc(raw);
1117
+ }, () => ({ result: undefined }));
1118
+ assert.strictEqual(handed, undefined, `${name}: coerce sees the never-written document as undefined`);
1119
+ assert.strictEqual(await s.readDoc(name), undefined, `${name}: an update that answers no \`next\` writes nothing`);
1120
+ }
1121
+ });
1122
+ defer("each governance document is its own: a write lands under its name only, and read back is what was written", async () => {
1123
+ const s = await hooks.make();
1124
+ for (const name of MEMORY_GOVERNANCE_DOC_NAMES) {
1125
+ const result = await s.updateDoc(name, judgeDoc, (cur) => ({ next: { ...cur, owner: name, n: cur.n + 1 }, result: `wrote ${name}` }));
1126
+ assert.strictEqual(result, `wrote ${name}`, `${name}: updateDoc answers fn's result`);
1127
+ }
1128
+ for (const name of MEMORY_GOVERNANCE_DOC_NAMES) {
1129
+ assert.deepStrictEqual(await s.readDoc(name), { v: 1, owner: name, n: 1 }, `${name} read back (no alias, no lost write)`);
1130
+ }
1131
+ });
1132
+ defer("a governance document's answers are copies: changing what was read, or the object handed back as next, changes nothing stored", async () => {
1133
+ const s = await hooks.make();
1134
+ const next = { v: 1, owner: "copy", n: 1 };
1135
+ await s.updateDoc("session-accounts", judgeDoc, () => ({ next, result: undefined }));
1136
+ next.n = 99;
1137
+ const read = (await s.readDoc("session-accounts"));
1138
+ assert.deepStrictEqual(read, { v: 1, owner: "copy", n: 1 }, "the stored document is not the caller's object");
1139
+ read.n = 42;
1140
+ let handed;
1141
+ await s.updateDoc("session-accounts", judgeDoc, (cur) => {
1142
+ handed = cur;
1143
+ return { result: undefined };
1144
+ });
1145
+ assert.strictEqual(handed?.n, 1, "a read answer is not the stored document");
1146
+ assert.deepStrictEqual(await s.readDoc("session-accounts"), { v: 1, owner: "copy", n: 1 });
1147
+ });
1148
+ defer("a throw in coerce or in fn writes nothing and propagates unchanged", async () => {
1149
+ const s = await hooks.make();
1150
+ await s.updateDoc("lineage", judgeDoc, (cur) => ({ next: { ...cur, owner: "kept", n: 1 }, result: undefined }));
1151
+ await assert.rejects(s.updateDoc("lineage", judgeDoc, () => {
1152
+ throw new Error("fn-abort");
1153
+ }), /fn-abort/);
1154
+ await assert.rejects(s.updateDoc("lineage", () => {
1155
+ throw new Error("coerce-abort");
1156
+ }, () => ({ next: { v: 1, owner: "never", n: 9 }, result: undefined })), /coerce-abort/);
1157
+ assert.deepStrictEqual(await s.readDoc("lineage"), { v: 1, owner: "kept", n: 1 });
1158
+ });
1159
+ for (const name of MEMORY_GOVERNANCE_DOC_NAMES) {
1160
+ defer(`a malformed ${name} document is refused (fail-closed) by both faces, never read as missing`, async () => {
1161
+ const s = await hooks.make();
1162
+ await hooks.corrupt(s, name);
1163
+ await rejectsCoded(s.readDoc(name), /ControlPlaneCorruptError|corrupt/i, `${name} read over a malformed document`);
1164
+ let called = false;
1165
+ await rejectsCoded(s.updateDoc(name, (raw) => {
1166
+ called = true;
1167
+ return judgeDoc(raw);
1168
+ }, (cur) => ({ next: cur, result: undefined })), /ControlPlaneCorruptError|corrupt/i, `${name} update over a malformed document`);
1169
+ assert.strictEqual(called, false, `${name}: an unparseable document never reaches coerce as if it were missing`);
1170
+ });
1171
+ }
1172
+ defer("racing updates of one governance document serialize: none is lost, on every document at once", async () => {
1173
+ const s = await hooks.make();
1174
+ const racers = 8;
1175
+ await Promise.all(MEMORY_GOVERNANCE_DOC_NAMES.flatMap((name) => Array.from({ length: racers }, () => s.updateDoc(name, judgeDoc, (cur) => ({ next: { ...cur, owner: name, n: cur.n + 1 }, result: undefined })))));
1176
+ for (const name of MEMORY_GOVERNANCE_DOC_NAMES)
1177
+ assert.deepStrictEqual(await s.readDoc(name), { v: 1, owner: name, n: racers }, `${name}: ${racers} racing updates all landed`);
1178
+ });
1179
+ defer("a name outside the governance documents is refused, never given storage of its own", async () => {
1180
+ const s = await hooks.make();
1181
+ await assert.rejects(s.readDoc("lineage.json"));
1182
+ await assert.rejects(s.updateDoc("__proto__", judgeDoc, (cur) => ({ next: cur, result: undefined })));
1183
+ });
1184
+ const run = hooks.runAssertion ?? (async (_name, fn) => fn());
1185
+ for (const [name, fn] of cases)
1186
+ await run(name, fn);
1187
+ }
868
1188
  export async function assertMemoryBackendSearchEquivalence(a, b) {
869
1189
  const fixture = [
870
1190
  entry("id-eq-0001", "s1", "notes-alpha", "alpha beta gamma delta", { name: "Alpha notes", description: "about alpha" }),
@@ -6,9 +6,12 @@ import type { MemoryBackend } from "./types.js";
6
6
  * judgment across stores and the executions it admits run as one critical section. */
7
7
  export declare const MEMORY_DEPLOYMENT_ERASURE_LOCK_DIR = ".memory-erasure-judge";
8
8
  export interface MemoryDeploymentInput {
9
- /** The deployment's backend — the instance given as `RunnerDeps.memoryBackend`. It must own its control
10
- * plane (`controlPlaneRoot`, a non-empty string): a backend without one keeps a session's memory facts in
11
- * per-project control planes no deployment-wide reading can name, and is refused (`config.memory_scope_key`). */
9
+ /** The deployment's backend — the instance given as `RunnerDeps.memoryBackend`. It must publish its own control
10
+ * plane (`controlPlaneRoot`): the scope registry and the capture records a session's memory status reads live
11
+ * there, and a backend without one keeps them in per-project control planes no deployment-wide reading can name —
12
+ * refused (`config.memory_scope_key`). This is the deployment's own question, not consolidation's
13
+ * (`memoryGovernanceDurability`). A backend that carries only `governance` stays refused here: its session accounts
14
+ * ride its store, its scope registry and capture records do not. */
12
15
  backend: MemoryBackend;
13
16
  /** The value given as `RunnerDeps.memoryEngineDir` — a required key, judged as `resolveMemoryScopeStore`
14
17
  * judges it (`undefined` written out reads the Runner's same fallback). */
@@ -42,16 +45,36 @@ export interface DeploymentSessionMemoryStatus extends Pick<SessionMemoryStatus,
42
45
  * answer exactly as its engine gave it. The folded keys are read from these rows; a store whose answer made a
43
46
  * folded key absent is the row whose key is absent; a store-bound key (`writeHome`, the directory of the
44
47
  * session's write home IN that store) is answered here only. A store that could not be opened answers
45
- * `{ optOutSource: "fault" }` (every source unreadable). */
48
+ * `{ optOutSource: "fault" }` (every source unreadable). With the host's capture record carrier
49
+ * (`memoryCaptureRecordStore`) the personal plane of a directory-pinned deployment also has a row while its
50
+ * store is not in the set, whenever its engine answers a capture fact for the session — a standing record or a
51
+ * fault (`optOutSource` present): that carrier keeps the record off the mount, where the set cannot see it. */
46
52
  planes: ReadonlyArray<{
47
53
  readonly plane: "project" | "personal";
48
54
  readonly status: SessionMemoryStatus;
49
55
  }>;
50
56
  }
51
57
  export interface MemoryDeployment {
52
- /** The deployment's stores, read at each call: the project plane (the deployment's backend), then — on a
53
- * directory-pinned deployment — the personal plane's store once its mount exists under the engine root
54
- * (opened on first use and kept). A store this face opened for a request stays in the set. */
58
+ /**
59
+ * The deployment's stores, read from the disk at each call: the project plane (the deployment's backend), then —
60
+ * on a directory-pinned deployment — the personal plane's store when a write left a record on its mount (the
61
+ * store opened on first use and kept as an engine instance, never as a reason to stay in the set).
62
+ *
63
+ * @contract memory.deployment.store_set — on a directory-pinned deployment the personal plane's store is in the
64
+ * set exactly when its mount holds a record: a file under `<engine root>/personal/.engine` or
65
+ * `<engine root>/personal/memory` other than the named artifacts an open or a read leaves, matched at that place
66
+ * and by that name only (`*` = any rest of the name): control plane top level, files `root-anchor.json` ·
67
+ * `scopes.json` · `scopes.json.journal` · `.tmp-*`; control plane top level, directories as whole trees
68
+ * `root-anchor.json.lock` · `scopes.json.lock` · `txn.lock` · `root-anchor.json.lock.stale-*` ·
69
+ * `scopes.json.lock.stale-*` · `txn.lock.stale-*`; memory directory top level, files `.casefold-probe-*`. A
70
+ * directory that cannot be read, for any reason but absence (a link that leads nowhere, at it or above it, is no
71
+ * absence), counts as holding one, and so does an anchor, a scope registry or a registry journal that stands there
72
+ * damaged (a link, no regular file, unreadable, not JSON or out of shape). Opening, reading and a refused request
73
+ * add no store, and every deployment object over one engine root answers the same. A store in the set that cannot be
74
+ * opened is not a store of the list: the call throws `ControlPlaneCorruptError` (a bare system error is carried by one
75
+ * that names its errno, the original as its `cause`), and the session status answers that plane
76
+ * `optOutSource: "fault"`.
77
+ */
55
78
  stores(): readonly MemoryDeploymentStore[];
56
79
  /**
57
80
  * Erase across the deployment — the input and the receipt of `MemoryEngine.eraseMemoryEntries`, judged as one
@@ -105,6 +128,6 @@ export interface MemoryDeployment {
105
128
  */
106
129
  export declare function foldSessionMemoryStatuses(statuses: readonly SessionMemoryStatus[]): Pick<SessionMemoryStatus, FoldedStatusKey>;
107
130
  /** The deployment-wide memory face over `input` (see {@link MemoryDeployment}). Input keys are judged as
108
- * `resolveMemoryScopeStore` judges them; a backend without its own control plane is refused. */
131
+ * `resolveMemoryScopeStore` judges them; a backend whose control-plane state is replica-local is refused. */
109
132
  export declare function createMemoryDeployment(input: MemoryDeploymentInput): MemoryDeployment;
110
133
  export {};
@@ -1,10 +1,10 @@
1
- import { lstatSync } from "node:fs";
2
1
  import { join } from "node:path";
3
2
  import { MemoryEngine } from "./engine.js";
4
3
  import { derivePersonalControlDir, derivePersonalMemoryDir, directoryPinOf, judgeMemoryStoreSeat, memoryPlaneStore, memoryScopePlaneOf, mergeErasureAttestations, refuseMemoryStoreInput } from "./dual-root.js";
5
- import { acquireStoreTxnLock, assertStoreTxnLockOwnership, ControlPlaneCorruptError, renewStoreTxnLock, resolveMemoryEngineRoot, TXN_LOCK_STALE_MS } from "./layout.js";
4
+ import { acquireStoreTxnLock, assertStoreTxnLockOwnership, ControlPlaneCorruptError, renewStoreTxnLock, resolveMemoryEngineRoot, storeHoldsRecord, TXN_LOCK_STALE_MS } from "./layout.js";
6
5
  import { captureErasureInput, erasureRequestInvalid, erasureSelectHash } from "./file-backend.js";
7
6
  import { canonicalExpectedScopes } from "./export-bundle.js";
7
+ import { thrownLabel, thrownText } from "../thrown-value.js";
8
8
  const FACE = "createMemoryDeployment";
9
9
  export const MEMORY_DEPLOYMENT_ERASURE_LOCK_DIR = ".memory-erasure-judge";
10
10
  const STATUS_KEYS_DECIDED = true;
@@ -44,7 +44,7 @@ export function createMemoryDeployment(input) {
44
44
  return typeof root === "string" && root !== "" ? root : undefined;
45
45
  };
46
46
  if (controlOf(backend) === undefined) {
47
- refuseMemoryStoreInput(FACE, "the backend owns no control plane (controlPlaneRoot) — a session's memory facts then live in per-project control planes no deployment-wide reading can name", backend);
47
+ refuseMemoryStoreInput(FACE, "the backend publishes no control plane (controlPlaneRoot) — a session's memory facts then live in per-project control planes no deployment-wide reading can name", backend);
48
48
  }
49
49
  const engineRoot = resolveMemoryEngineRoot(input.memoryEngineDir);
50
50
  const pinned = directoryPinOf(backend) !== undefined;
@@ -60,16 +60,18 @@ export function createMemoryDeployment(input) {
60
60
  };
61
61
  const project = seatOf("project", backend);
62
62
  let personal;
63
- const personalStore = () => (personal ??= seatOf("personal", memoryPlaneStore("personal", backend, engineRoot, onIncident)));
64
- const personalMountExists = () => [derivePersonalMemoryDir(engineRoot), derivePersonalControlDir(engineRoot)].some((p) => {
63
+ const personalStore = () => {
64
+ if (personal !== undefined)
65
+ return personal;
65
66
  try {
66
- return lstatSync(p, { throwIfNoEntry: false }) !== undefined;
67
+ personal = seatOf("personal", memoryPlaneStore("personal", backend, engineRoot, onIncident));
67
68
  }
68
- catch {
69
- return true;
69
+ catch (err) {
70
+ throw personalOpenFault(err, derivePersonalMemoryDir(engineRoot));
70
71
  }
71
- });
72
- const hasPersonalStore = () => pinned && (personal !== undefined || personalMountExists());
72
+ return personal;
73
+ };
74
+ const hasPersonalStore = () => pinned && storeHoldsRecord(derivePersonalMemoryDir(engineRoot), derivePersonalControlDir(engineRoot));
73
75
  const stores = () => (hasPersonalStore() ? [project, personalStore()] : [project]);
74
76
  const storeOfPlane = (plane) => (plane === "personal" && pinned ? personalStore() : project);
75
77
  const planeOf = (scope) => memoryScopePlaneOf(FACE, scope, scopeContract);
@@ -153,7 +155,8 @@ export function createMemoryDeployment(input) {
153
155
  },
154
156
  async sessionMemoryStatus(sessionId) {
155
157
  const planes = [{ plane: "project", status: await project.engine.sessionMemoryStatus(sessionId) }];
156
- if (hasPersonalStore()) {
158
+ const inSet = hasPersonalStore();
159
+ if (inSet || (pinned && memoryCaptureRecordStore !== undefined)) {
157
160
  let seat;
158
161
  try {
159
162
  seat = personalStore();
@@ -161,7 +164,9 @@ export function createMemoryDeployment(input) {
161
164
  catch {
162
165
  seat = undefined;
163
166
  }
164
- planes.push({ plane: "personal", status: seat !== undefined ? await seat.engine.sessionMemoryStatus(sessionId) : { optOutSource: "fault" } });
167
+ const status = seat !== undefined ? await seat.engine.sessionMemoryStatus(sessionId) : { optOutSource: "fault" };
168
+ if (inSet || status.optOutSource !== undefined)
169
+ planes.push({ plane: "personal", status });
165
170
  }
166
171
  return { ...foldSessionMemoryStatuses(planes.map((p) => p.status)), planes };
167
172
  },
@@ -175,6 +180,15 @@ async function anchorOf(store, requestId) {
175
180
  return undefined;
176
181
  throw coded("eraseMemoryEntries: another store of this deployment has an erasure-evidence face but no anchor read (erasureAnchorOf), so whether it already executed this requestId cannot be judged — nothing was deleted", "memory.erasure_evidence_unavailable");
177
182
  }
183
+ const ERRNO_CODE = /^E[A-Z0-9]+$/;
184
+ function personalOpenFault(err, mount) {
185
+ if (err instanceof ControlPlaneCorruptError)
186
+ return err;
187
+ const code = err?.code;
188
+ if (typeof code === "string" && !ERRNO_CODE.test(code))
189
+ return err;
190
+ return new ControlPlaneCorruptError(`the personal plane's memory store at ${mount} could not be opened (${typeof code === "string" ? code : thrownLabel(err)}): ${thrownText(err)}`, { cause: err });
191
+ }
178
192
  function coded(message, code) {
179
193
  const e = new Error(message);
180
194
  e.code = code;