@sema-agent/core 7.63.0 → 7.65.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.
- package/CHANGELOG.md +725 -0
- package/dist/agents/cc-peer-directory.js +1 -0
- package/dist/agents/cc-peer-wire.d.ts +4 -0
- package/dist/agents/cc-peer-wire.js +1 -0
- package/dist/agents/cc-uds-peer-channel.js +5 -0
- package/dist/agents/cross-session-judge.d.ts +3 -1
- package/dist/agents/cross-session-judge.js +4 -1
- package/dist/agents/peer-directory.d.ts +8 -0
- package/dist/agents/peer-directory.js +4 -0
- package/dist/agents/peer-held-queue.d.ts +9 -3
- package/dist/agents/peer-held-queue.js +12 -9
- package/dist/agents/peer-idle.d.ts +20 -1
- package/dist/agents/peer-idle.js +23 -12
- package/dist/agents/peer-notice-route.d.ts +16 -5
- package/dist/agents/peer-notice-route.js +11 -9
- package/dist/agents/peer-notices.d.ts +25 -8
- package/dist/agents/peer-notices.js +6 -1
- package/dist/agents/peer-session-drain.d.ts +32 -6
- package/dist/agents/peer-session-drain.js +100 -26
- package/dist/agents/send-message-tool.d.ts +7 -0
- package/dist/agents/send-message-tool.js +18 -6
- package/dist/agents/subagent.js +25 -5
- package/dist/core/allow-entry.d.ts +4 -0
- package/dist/core/ask-origin.d.ts +1 -1
- package/dist/core/ask-origin.js +2 -2
- package/dist/core/ask-unresolvable-notice.d.ts +13 -4
- package/dist/core/ask-unresolvable-notice.js +10 -3
- package/dist/core/auto-compaction.d.ts +7 -5
- package/dist/core/auto-promote.d.ts +3 -2
- package/dist/core/background-agent-store.d.ts +14 -0
- package/dist/core/background-agent-store.js +3 -0
- package/dist/core/checkpoint-queries.d.ts +9 -6
- package/dist/core/checkpoint-queries.js +8 -3
- package/dist/core/checkpoint-store.d.ts +7 -4
- package/dist/core/context-settings.d.ts +39 -9
- package/dist/core/context-settings.js +32 -10
- package/dist/core/engine-attestation.d.ts +26 -6
- package/dist/core/engine-attestation.js +5 -1
- package/dist/core/engine-notice.d.ts +37 -2
- package/dist/core/engine-notice.js +3 -1
- package/dist/core/extension-requester.d.ts +9 -0
- package/dist/core/extension-requester.js +7 -0
- package/dist/core/file-history-store.d.ts +30 -2
- package/dist/core/file-history-store.js +48 -9
- package/dist/core/fs-write-gate-policy.js +1 -1
- package/dist/core/gate-fold.js +5 -1
- package/dist/core/gate-lanes.js +2 -0
- package/dist/core/gate-outcome.d.ts +39 -2
- package/dist/core/gate-outcome.js +20 -1
- package/dist/core/governance-codes.d.ts +8 -4
- package/dist/core/governance-codes.js +8 -3
- package/dist/core/leg-identity.d.ts +35 -1
- package/dist/core/leg-identity.js +10 -0
- package/dist/core/mailbox-store.d.ts +39 -4
- package/dist/core/mailbox-store.js +14 -2
- package/dist/core/memory-engine/consolidation.d.ts +13 -6
- package/dist/core/memory-engine/consolidation.js +26 -0
- package/dist/core/memory-engine/control-objects.d.ts +58 -0
- package/dist/core/memory-engine/control-objects.js +273 -0
- package/dist/core/memory-engine/control-plane-adoption.d.ts +51 -0
- package/dist/core/memory-engine/control-plane-adoption.js +161 -0
- package/dist/core/memory-engine/delegation-settlement.d.ts +73 -40
- package/dist/core/memory-engine/delegation-settlement.js +271 -107
- package/dist/core/memory-engine/dual-root.d.ts +3 -2
- package/dist/core/memory-engine/dual-root.js +7 -3
- package/dist/core/memory-engine/engine.d.ts +54 -33
- package/dist/core/memory-engine/engine.js +150 -157
- package/dist/core/memory-engine/file-backend.d.ts +58 -76
- package/dist/core/memory-engine/file-backend.js +111 -268
- package/dist/core/memory-engine/index.d.ts +3 -2
- package/dist/core/memory-engine/index.js +2 -1
- package/dist/core/memory-engine/layout.d.ts +135 -50
- package/dist/core/memory-engine/layout.js +214 -89
- package/dist/core/memory-engine/memory-age.d.ts +12 -0
- package/dist/core/memory-engine/memory-age.js +17 -0
- package/dist/core/memory-engine/memory-backend-contract.d.ts +10 -3
- package/dist/core/memory-engine/memory-backend-contract.js +159 -2
- package/dist/core/memory-engine/memory-deployment.d.ts +12 -4
- package/dist/core/memory-engine/memory-deployment.js +31 -6
- package/dist/core/memory-engine/origin-clearance.d.ts +12 -3
- package/dist/core/memory-engine/origin-clearance.js +64 -9
- package/dist/core/memory-engine/session-write-home.d.ts +34 -1
- package/dist/core/memory-engine/session-write-home.js +37 -10
- package/dist/core/memory-engine/tools.d.ts +2 -2
- package/dist/core/memory-engine/tools.js +7 -7
- package/dist/core/memory-engine/types.d.ts +55 -12
- package/dist/core/memory-engine/types.js +2 -1
- package/dist/core/memory-vector.d.ts +6 -14
- package/dist/core/memory.d.ts +0 -462
- package/dist/core/memory.js +0 -333
- package/dist/core/mode-policy.js +3 -3
- package/dist/core/mods/agent-stations.d.ts +18 -0
- package/dist/core/mods/agent-stations.js +8 -6
- package/dist/core/mods/extension-call.d.ts +4 -0
- package/dist/core/mods/extension-call.js +8 -0
- package/dist/core/mods/tool-call.js +3 -4
- package/dist/core/parent-spec-seat.d.ts +2 -2
- package/dist/core/peer-channel.d.ts +5 -0
- package/dist/core/permission-rule-consent.d.ts +64 -22
- package/dist/core/permission-rule-consent.js +106 -58
- package/dist/core/permission-rule-store.d.ts +56 -21
- package/dist/core/permission-rule-store.js +2 -0
- package/dist/core/refusal-echo.d.ts +20 -0
- package/dist/core/refusal-echo.js +33 -0
- package/dist/core/retention.d.ts +175 -10
- package/dist/core/retention.js +44 -0
- package/dist/core/retired-keys.d.ts +5 -0
- package/dist/core/retired-keys.js +3 -0
- package/dist/core/rule-offer-read.d.ts +0 -4
- package/dist/core/rule-offer-read.js +2 -18
- package/dist/core/runner/classifier-ladder.d.ts +10 -2
- package/dist/core/runner/classifier-ladder.js +4 -2
- package/dist/core/runner/compact-session.js +10 -7
- package/dist/core/runner/compaction-call-options.d.ts +7 -7
- package/dist/core/runner/compaction-call-options.js +3 -2
- package/dist/core/runner/contracts.d.ts +28 -9
- package/dist/core/runner/delegation-owner.d.ts +2 -3
- package/dist/core/runner/delegation-owner.js +2 -1
- package/dist/core/runner/gate-exit.d.ts +6 -0
- package/dist/core/runner/gate-exit.js +11 -2
- package/dist/core/runner/memory-consolidation-driver.d.ts +4 -2
- package/dist/core/runner/memory-consolidation-driver.js +8 -5
- package/dist/core/runner/prepare-ask-lane.js +3 -3
- package/dist/core/runner/prepare-caps-and-workflow.d.ts +3 -1
- package/dist/core/runner/prepare-caps-and-workflow.js +2 -2
- package/dist/core/runner/prepare-config-doors.js +4 -0
- package/dist/core/runner/prepare-delegation-surface.d.ts +3 -0
- package/dist/core/runner/prepare-delegation-surface.js +2 -2
- package/dist/core/runner/prepare-gate-stations.d.ts +8 -0
- package/dist/core/runner/prepare-gate-stations.js +15 -7
- package/dist/core/runner/prepare-hands-readface.js +1 -1
- package/dist/core/runner/prepare-inherited-gate.d.ts +3 -1
- package/dist/core/runner/prepare-inherited-gate.js +4 -2
- package/dist/core/runner/prepare-memory-engine-session.js +1 -1
- package/dist/core/runner/prepare-memory.d.ts +4 -0
- package/dist/core/runner/prepare-memory.js +22 -28
- package/dist/core/runner/prepare-policy-chain.js +18 -10
- package/dist/core/runner/prepare-prompt-inputs.js +1 -1
- package/dist/core/runner/prepare-task.d.ts +5 -1
- package/dist/core/runner/prepare-task.js +16 -11
- package/dist/core/runner/prepare-wiring-manifest.d.ts +3 -1
- package/dist/core/runner/prepare-wiring-manifest.js +3 -2
- package/dist/core/runner/resume-admission.d.ts +2 -2
- package/dist/core/runner/resume-admission.js +2 -23
- package/dist/core/runner/role-resolution-table.d.ts +98 -0
- package/dist/core/runner/role-resolution-table.js +62 -0
- package/dist/core/runner/run-compaction-machinery.js +2 -2
- package/dist/core/runner/run-identity-wiring.js +12 -9
- package/dist/core/runner/run-leg.js +8 -4
- package/dist/core/runner/run-notification-lane.js +23 -23
- package/dist/core/runner/run-recovery-lanes.js +3 -3
- package/dist/core/runner/run-terminal-adoption.js +1 -1
- package/dist/core/runner/run-turn-boundary.js +14 -15
- package/dist/core/runner/runtask.js +1 -1
- package/dist/core/runner/sub-agent-deny-lists.d.ts +19 -0
- package/dist/core/runner/sub-agent-deny-lists.js +25 -0
- package/dist/core/runner/tool-occurrence.d.ts +4 -2
- package/dist/core/runner/tool-occurrence.js +2 -2
- package/dist/core/runner-deps.d.ts +1 -1
- package/dist/core/secret-env.d.ts +2 -2
- package/dist/core/secret-env.js +6 -20
- package/dist/core/session-checkout.d.ts +63 -3
- package/dist/core/session-checkout.js +152 -58
- package/dist/core/session-store.d.ts +6 -6
- package/dist/core/session-store.js +3 -3
- package/dist/core/shell-read-silence.js +8 -0
- package/dist/core/store-contracts/background-agent-store-contract.js +13 -0
- package/dist/core/store-contracts/peer-directory-contract.js +8 -1
- package/dist/core/task-event.d.ts +9 -5
- package/dist/core/task-notification.d.ts +137 -31
- package/dist/core/task-notification.js +198 -100
- package/dist/core/task-registry-agent.d.ts +11 -0
- package/dist/core/task-registry-agent.js +12 -3
- package/dist/core/task-registry-shared.d.ts +11 -0
- package/dist/core/task-registry.d.ts +18 -0
- package/dist/core/task-registry.js +27 -8
- package/dist/core/task-spec.d.ts +7 -2
- package/dist/core/tool-errors.d.ts +17 -9
- package/dist/core/tool-errors.js +1 -1
- package/dist/core/tool-policy.d.ts +18 -1
- package/dist/core/tool-policy.js +16 -7
- package/dist/core/tool-result-store.d.ts +20 -0
- package/dist/core/tool-spec.d.ts +10 -6
- package/dist/core/trace.d.ts +3 -2
- package/dist/core/workflow-journal-store.d.ts +11 -0
- package/dist/core/workflow-journal-store.js +7 -0
- package/dist/core/workflow-run-store.d.ts +9 -0
- package/dist/core/workflow-run-store.js +6 -0
- package/dist/core/write-protect.d.ts +16 -0
- package/dist/core/write-protect.js +10 -0
- package/dist/engine/compaction/compaction.d.ts +2 -1
- package/dist/engine/harness/types.d.ts +1 -0
- package/dist/engine/session/repo-utils.d.ts +14 -4
- package/dist/engine/session/repo-utils.js +5 -4
- package/dist/engine/session/session.d.ts +7 -1
- package/dist/engine/session/session.js +5 -2
- package/dist/index.d.ts +13 -11
- package/dist/index.js +13 -11
- package/dist/orchestration/run-workflow-tool.d.ts +4 -0
- package/dist/orchestration/run-workflow-tool.js +7 -0
- package/dist/orchestration/workflow-types.d.ts +2 -1
- package/dist/orchestration/workflow.d.ts +3 -0
- package/dist/orchestration/workflow.js +2 -1
- package/dist/prompts/default.d.ts +1 -2
- package/dist/scenarios/full-body.d.ts +1 -1
- package/dist/stores/file/adoption/adopt.d.ts +1 -1
- package/dist/stores/file/checkpoint-store.d.ts +6 -0
- package/dist/stores/file/checkpoint-store.js +4 -1
- package/dist/stores/file/file-history-store.d.ts +13 -0
- package/dist/stores/file/file-history-store.js +75 -13
- package/dist/stores/file/index.d.ts +12 -16
- package/dist/stores/file/index.js +7 -25
- package/dist/stores/file/permission-rule-store.d.ts +34 -0
- package/dist/stores/file/permission-rule-store.js +104 -9
- package/dist/stores/file/session-store.js +1 -1
- package/dist/stores/file/tool-result-store.d.ts +14 -0
- package/dist/stores/file/tool-result-store.js +39 -2
- package/dist/stores/file/workflow-journal-store.d.ts +4 -0
- package/dist/stores/file/workflow-journal-store.js +17 -0
- package/dist/stores/file/workflow-run-store.d.ts +3 -0
- package/dist/stores/file/workflow-run-store.js +15 -0
- package/dist/tools/fs/read-deny.d.ts +15 -2
- package/dist/tools/fs/read-deny.js +10 -2
- package/dist/tools/fs/shell-read-check.d.ts +8 -2
- package/dist/tools/fs/shell-read-check.js +7 -7
- package/package.json +2 -2
- package/test/export-surface.snapshot.json +71 -73
- package/wire-changes/core-stores-sql@7.64.0.json +30 -0
- package/wire-changes/core-stores-sql@7.65.0.json +30 -0
- package/wire-changes/core@7.64.0.json +2653 -0
- package/wire-changes/core@7.65.0.json +1650 -0
- package/wire-changes/mods-kernel@7.64.0.json +30 -0
- package/wire-changes/mods-kernel@7.65.0.json +30 -0
- package/wire-changes/primitives@7.64.0.json +30 -0
- package/wire-changes/primitives@7.65.0.json +337 -0
- package/dist/core/memory-recall.d.ts +0 -208
- package/dist/core/memory-recall.js +0 -136
- package/dist/stores/file/memory-store.d.ts +0 -124
- package/dist/stores/file/memory-store.js +0 -353
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { fstatSync,
|
|
1
|
+
import { fstatSync, lstatSync, mkdirSync, readdirSync, readFileSync, renameSync, rmSync, statSync, openSync, fsyncSync, closeSync } from "node:fs";
|
|
2
2
|
import { createHash, randomUUID } from "node:crypto";
|
|
3
3
|
import { dirname, join, relative } from "node:path";
|
|
4
4
|
import { canonicalJsonStringify } from "../canonical-json.js";
|
|
@@ -9,9 +9,10 @@ import { ambiguousOriginRepresentation, committedDistilledOf, committedOriginOf,
|
|
|
9
9
|
import { convertV1SidecarKeys } from "./delegation-settlement.js";
|
|
10
10
|
import { layerObservationLookup, observedDivergenceNotice } from "./layer-observations.js";
|
|
11
11
|
import { DEFAULT_MAX_ENTRY_DEPTH, MEMORY_INDEX_FILENAME, carriesEntry, scanEntryFiles } from "./entry-scan.js";
|
|
12
|
-
import { ControlPlaneCorruptError, CURSORS_FILE,
|
|
12
|
+
import { ControlPlaneCorruptError, CURSORS_FILE, STRICT_CONTROL_PLANE_LEDGERS, fileGovernanceDocOf, importReceiptName, appendChallengeEvents, atomicWriteFileSync, clearContainedPath, eraseQuarantineCopies, quarantineCaptureName, captureAndClearLineageForEntries, adoptRootScopeLayout, anchorStoreRoot, effectiveControlRootOf, ensureDirExists, LEDGER_FILE, sayAnnounceFailure, enqueueMemoryAnnouncement, importLatchTxnId, importLineageCommitted, importSessionPollution, isContainedIn, lockedStrictUpdate, readStrictSidecar, permissionRemedyOf, withPermissionRemedy, lineageContributionsOfSession, listSessionPollution, readChallengeEvents, readLineageRecord, registerScope, registeredScopes, releaseImportLatch, layoutNeedsAdoption, scopeDirFor, scopeDirName, scopeRegistryShape, stageImportLatch, landsOutsideStore, storeActRefusal, storeRootMovedRefusal, writeAllSync, STORE_JOURNAL_FILE, ERASURE_SWEEP_RECORD_FILE, ERASURE_SWEEP_RECORD_WHAT, coerceErasureSweepRecord, erasureSweepOwedAt, erasureSweepRecordPathOf, STORE_TXN_LOCK_DIR, TXN_LOCK_STALE_MS, acquireStoreTxnLock, assertStoreTxnLockOwnership, renewStoreTxnLock, tryStoreTxnLock, } from "./layout.js";
|
|
13
13
|
import { screenInboundEntries } from "./data-plane.js";
|
|
14
|
-
import { CONSOLIDATION_DRIVER_PLANS_DIR, CONSOLIDATION_PLANS_DIR, fileGovernanceStore } from "./consolidation.js";
|
|
14
|
+
import { CONSOLIDATION_DRIVER_PLANS_DIR, CONSOLIDATION_PLANS_DIR, fileGovernanceStore, standingControlObjectsOf } from "./consolidation.js";
|
|
15
|
+
import { captureIntoFileQuarantine, fileControlObjectFaultCode, getFileControlObject, probeControlPlaneLinks, putFileControlObjectOnce, standingFileControlObjectNames } from "./control-objects.js";
|
|
15
16
|
import { canonicalExpectedScopes, expectedScopesInvalid, firstOutsideExpectedScopes } from "./export-bundle.js";
|
|
16
17
|
import { scanMemoryFileName, scanMemoryWrite } from "./scan.js";
|
|
17
18
|
import { admittingLandings, cutPerLanding, LandingsNeedAdmission, requireLandingsAdmitted } from "./landing-admission.js";
|
|
@@ -169,7 +170,6 @@ class AuditSnapshotContendedError extends Error {
|
|
|
169
170
|
class AuditObservationUnstableError extends Error {
|
|
170
171
|
}
|
|
171
172
|
const LEDGER_SCHEMA_VERSION = 2;
|
|
172
|
-
const LEDGER_V1_BACKUP_FILE = "revs.v1.json.bak";
|
|
173
173
|
const TRANSFERS_FILE = "transfers.jsonl";
|
|
174
174
|
const CHAIN_DEGRADED_FILE = "transfers.chain-degraded.json";
|
|
175
175
|
const SHADOW_DIR = "shadow";
|
|
@@ -281,33 +281,22 @@ function parseJournal(raw, jp) {
|
|
|
281
281
|
throw new ControlPlaneCorruptError(`transaction journal is unparseable: ${jp}`);
|
|
282
282
|
}
|
|
283
283
|
}
|
|
284
|
+
const V1_LEDGER_FORM_REFUSED = "the pre-binding v1 form (a bare id → rev map), which this engine does not read — open the store once with an engine at or below 7.63.0, whose locked migration upgrades it to the v2 envelope";
|
|
284
285
|
function journalLedgerSnapshot(journal, jp) {
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
return { form: "v2", rows: validateLedgerRowsV2(env.rows, jp), extras };
|
|
300
|
-
}
|
|
301
|
-
const map = journal.ledger;
|
|
302
|
-
if (!map || typeof map !== "object" || Array.isArray(map))
|
|
303
|
-
throw new ControlPlaneCorruptError(`transaction journal ledger snapshot has the wrong shape: ${jp}`);
|
|
304
|
-
const rows = Object.create(null);
|
|
305
|
-
for (const [id, rev] of Object.entries(map)) {
|
|
306
|
-
if (typeof rev !== "string")
|
|
307
|
-
throw new ControlPlaneCorruptError(`transaction journal v1 ledger snapshot entry ${JSON.stringify(id)} is not a string: ${jp}`);
|
|
308
|
-
rows[id] = { rev };
|
|
309
|
-
}
|
|
310
|
-
return { form: "v1", rows };
|
|
286
|
+
if (journal.ledger !== undefined) {
|
|
287
|
+
throw new ControlPlaneCorruptError(`transaction journal carries its ledger snapshot in ${V1_LEDGER_FORM_REFUSED}: ${jp}`);
|
|
288
|
+
}
|
|
289
|
+
const env = journal.ledger2;
|
|
290
|
+
if (env === undefined)
|
|
291
|
+
throw new ControlPlaneCorruptError(`transaction journal has no ledger snapshot (wrong shape): ${jp}`);
|
|
292
|
+
if (!env || typeof env !== "object" || Array.isArray(env) || env.v !== LEDGER_SCHEMA_VERSION) {
|
|
293
|
+
throw new ControlPlaneCorruptError(`transaction journal ledger2 snapshot has the wrong shape: ${jp}`);
|
|
294
|
+
}
|
|
295
|
+
const extras = {};
|
|
296
|
+
for (const [k, val] of Object.entries(env))
|
|
297
|
+
if (k !== "v" && k !== "rows")
|
|
298
|
+
extras[k] = val;
|
|
299
|
+
return { rows: validateLedgerRowsV2(env.rows, jp), extras };
|
|
311
300
|
}
|
|
312
301
|
function parseLedgerText(raw, path) {
|
|
313
302
|
let parsed;
|
|
@@ -321,33 +310,26 @@ function parseLedgerText(raw, path) {
|
|
|
321
310
|
throw new ControlPlaneCorruptError(`committed-rev ledger has the wrong shape: ${path}`);
|
|
322
311
|
}
|
|
323
312
|
const rec = parsed;
|
|
324
|
-
if ("v" in rec) {
|
|
325
|
-
|
|
326
|
-
if (typeof v !== "number" || !Number.isInteger(v)) {
|
|
327
|
-
throw new ControlPlaneCorruptError(`committed-rev ledger schema version is not an integer: ${path}`);
|
|
328
|
-
}
|
|
329
|
-
if (v > LEDGER_SCHEMA_VERSION) {
|
|
330
|
-
throw new ControlPlaneCorruptError(`committed-rev ledger schema v${v} is newer than this engine supports (v${LEDGER_SCHEMA_VERSION}) — refusing to reinterpret it: ${path}`);
|
|
331
|
-
}
|
|
332
|
-
if (v !== LEDGER_SCHEMA_VERSION) {
|
|
333
|
-
throw new ControlPlaneCorruptError(`committed-rev ledger has an unknown enveloped schema v${v}: ${path}`);
|
|
334
|
-
}
|
|
335
|
-
const rows = validateLedgerRowsV2(rec.rows, path);
|
|
336
|
-
const envelopeExtras = {};
|
|
337
|
-
for (const [k, val] of Object.entries(rec)) {
|
|
338
|
-
if (k !== "v" && k !== "rows")
|
|
339
|
-
envelopeExtras[k] = val;
|
|
340
|
-
}
|
|
341
|
-
return { form: "v2", rows, envelopeExtras };
|
|
313
|
+
if (!("v" in rec)) {
|
|
314
|
+
throw new ControlPlaneCorruptError(`committed-rev ledger has no schema version: it is ${V1_LEDGER_FORM_REFUSED}: ${path}`);
|
|
342
315
|
}
|
|
343
|
-
const
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
316
|
+
const v = rec.v;
|
|
317
|
+
if (typeof v !== "number" || !Number.isInteger(v)) {
|
|
318
|
+
throw new ControlPlaneCorruptError(`committed-rev ledger schema version is not an integer: ${path}`);
|
|
319
|
+
}
|
|
320
|
+
if (v > LEDGER_SCHEMA_VERSION) {
|
|
321
|
+
throw new ControlPlaneCorruptError(`committed-rev ledger schema v${v} is newer than this engine supports (v${LEDGER_SCHEMA_VERSION}) — refusing to reinterpret it: ${path}`);
|
|
349
322
|
}
|
|
350
|
-
|
|
323
|
+
if (v !== LEDGER_SCHEMA_VERSION) {
|
|
324
|
+
throw new ControlPlaneCorruptError(`committed-rev ledger has an unknown enveloped schema v${v}: ${path}`);
|
|
325
|
+
}
|
|
326
|
+
const rows = validateLedgerRowsV2(rec.rows, path);
|
|
327
|
+
const envelopeExtras = {};
|
|
328
|
+
for (const [k, val] of Object.entries(rec)) {
|
|
329
|
+
if (k !== "v" && k !== "rows")
|
|
330
|
+
envelopeExtras[k] = val;
|
|
331
|
+
}
|
|
332
|
+
return { rows, envelopeExtras };
|
|
351
333
|
}
|
|
352
334
|
function ledgerFormOnDisk(controlDir) {
|
|
353
335
|
const path = join(controlDir, LEDGER_FILE);
|
|
@@ -355,7 +337,8 @@ function ledgerFormOnDisk(controlDir) {
|
|
|
355
337
|
if (raw === undefined)
|
|
356
338
|
return "absent";
|
|
357
339
|
try {
|
|
358
|
-
|
|
340
|
+
parseLedgerText(raw, path);
|
|
341
|
+
return "v2";
|
|
359
342
|
}
|
|
360
343
|
catch (err) {
|
|
361
344
|
if (err instanceof ControlPlaneCorruptError)
|
|
@@ -622,8 +605,6 @@ export class FileMemoryEngineBackend {
|
|
|
622
605
|
onIncident;
|
|
623
606
|
ledger;
|
|
624
607
|
envelopeExtras;
|
|
625
|
-
persistedSchemaVersion;
|
|
626
|
-
announcedV1Compat = false;
|
|
627
608
|
unboundRowsKnown = false;
|
|
628
609
|
adoptionNoticeKeys = new Set();
|
|
629
610
|
transfersAppendFault;
|
|
@@ -644,13 +625,14 @@ export class FileMemoryEngineBackend {
|
|
|
644
625
|
this.assertRootAnchored();
|
|
645
626
|
ensureDirExists(dir);
|
|
646
627
|
ensureDirExists(this.controlPlaneRoot);
|
|
628
|
+
probeControlPlaneLinks(this.controlPlaneRoot);
|
|
647
629
|
this.recoverJournal({ unlocked: true });
|
|
648
630
|
try {
|
|
649
631
|
this.loadLedger();
|
|
650
632
|
}
|
|
651
633
|
catch {
|
|
652
634
|
}
|
|
653
|
-
if (this.
|
|
635
|
+
if (this.ledger !== undefined && hasUnboundRows(this.ledger)) {
|
|
654
636
|
let layoutDerivesPaths = false;
|
|
655
637
|
try {
|
|
656
638
|
const shape = scopeRegistryShape(this.controlPlaneRoot);
|
|
@@ -705,10 +687,9 @@ export class FileMemoryEngineBackend {
|
|
|
705
687
|
this.ledger = undefined;
|
|
706
688
|
this.loadLedger();
|
|
707
689
|
registeredScopes(this.controlPlaneRoot);
|
|
708
|
-
if (
|
|
690
|
+
if (hasUnboundRows(this.loadLedger()))
|
|
709
691
|
this.tryOpportunisticMigrate();
|
|
710
|
-
|
|
711
|
-
this.announceUnboundRows(this.loadLedger());
|
|
692
|
+
this.announceUnboundRows(this.loadLedger());
|
|
712
693
|
}
|
|
713
694
|
drainInboundFindings() {
|
|
714
695
|
const out = this.inboundFindings;
|
|
@@ -728,37 +709,21 @@ export class FileMemoryEngineBackend {
|
|
|
728
709
|
const raw = readControlFileOrAbsent(path, "committed-rev ledger");
|
|
729
710
|
if (raw === undefined) {
|
|
730
711
|
this.ledger = Object.create(null);
|
|
731
|
-
this.persistedSchemaVersion = "v2";
|
|
732
712
|
this.unboundRowsKnown = false;
|
|
733
713
|
return this.ledger;
|
|
734
714
|
}
|
|
735
715
|
const parsed = parseLedgerText(raw, path);
|
|
736
716
|
this.ledger = parsed.rows;
|
|
737
717
|
this.envelopeExtras = parsed.envelopeExtras;
|
|
738
|
-
this.persistedSchemaVersion = parsed.form;
|
|
739
718
|
this.unboundRowsKnown = hasUnboundRows(parsed.rows);
|
|
740
|
-
if (parsed.form === "v1" && !this.announcedV1Compat) {
|
|
741
|
-
this.announcedV1Compat = true;
|
|
742
|
-
this.enqueueExternalItems("every-scope", ["memory ledger v1-compat active — v2 binding guarantees not yet in force (the migration runs at the next uncontended entry)"]);
|
|
743
|
-
}
|
|
744
719
|
return this.ledger;
|
|
745
720
|
}
|
|
746
721
|
saveLedger() {
|
|
747
722
|
if (!this.ledger)
|
|
748
723
|
return;
|
|
749
|
-
if (this.persistedSchemaVersion !== "v2") {
|
|
750
|
-
throw new ControlPlaneCorruptError("committed-rev ledger write refused: the on-disk ledger is still schema v1 and the migration has not run (mutations must migrate first)");
|
|
751
|
-
}
|
|
752
724
|
atomicWriteFileSync(join(this.controlPlaneRoot, LEDGER_FILE), `${JSON.stringify(ledgerEnvelope(this.ledger, this.envelopeExtras), null, 2)}\n`);
|
|
753
725
|
this.unboundRowsKnown = hasUnboundRows(this.ledger);
|
|
754
726
|
}
|
|
755
|
-
persistLedgerV1(rows) {
|
|
756
|
-
const map = Object.create(null);
|
|
757
|
-
for (const [id, row] of rowsEntries(rows))
|
|
758
|
-
map[id] = row.rev;
|
|
759
|
-
atomicWriteFileSync(join(this.controlPlaneRoot, LEDGER_FILE), `${JSON.stringify(map, null, 2)}\n`);
|
|
760
|
-
this.unboundRowsKnown = Object.keys(map).length > 0;
|
|
761
|
-
}
|
|
762
727
|
enqueueExternalItems(to, items, opts) {
|
|
763
728
|
if (items.length === 0 && opts?.supersedesPrefix === undefined)
|
|
764
729
|
return;
|
|
@@ -889,28 +854,6 @@ export class FileMemoryEngineBackend {
|
|
|
889
854
|
}
|
|
890
855
|
return { complete, byId, distilledFrom };
|
|
891
856
|
}
|
|
892
|
-
writeV1BackupOnce() {
|
|
893
|
-
const raw = readControlFileOrAbsent(join(this.controlPlaneRoot, LEDGER_FILE), "committed-rev ledger");
|
|
894
|
-
if (raw === undefined)
|
|
895
|
-
throw new ControlPlaneCorruptError(`committed-rev ledger vanished under the migration lock: ${join(this.controlPlaneRoot, LEDGER_FILE)}`);
|
|
896
|
-
const bak = join(this.controlPlaneRoot, LEDGER_V1_BACKUP_FILE);
|
|
897
|
-
let fd;
|
|
898
|
-
try {
|
|
899
|
-
fd = openSync(bak, "wx", 0o600);
|
|
900
|
-
}
|
|
901
|
-
catch (err) {
|
|
902
|
-
if (err.code === "EEXIST")
|
|
903
|
-
return;
|
|
904
|
-
throw err;
|
|
905
|
-
}
|
|
906
|
-
try {
|
|
907
|
-
writeAllSync(fd, raw);
|
|
908
|
-
fsyncSync(fd);
|
|
909
|
-
}
|
|
910
|
-
finally {
|
|
911
|
-
closeSync(fd);
|
|
912
|
-
}
|
|
913
|
-
}
|
|
914
857
|
tryAcquireTxnLockSync() {
|
|
915
858
|
return tryStoreTxnLock(this.controlPlaneRoot, { now: this.now });
|
|
916
859
|
}
|
|
@@ -930,21 +873,19 @@ export class FileMemoryEngineBackend {
|
|
|
930
873
|
migrateLockedIfNeeded(lockToken) {
|
|
931
874
|
this.ledger = undefined;
|
|
932
875
|
const rows = this.loadLedger();
|
|
933
|
-
if (
|
|
876
|
+
if (!hasUnboundRows(rows))
|
|
934
877
|
return;
|
|
935
|
-
const fullMigration = this.persistedSchemaVersion === "v1";
|
|
936
878
|
const census = this.censusProjectionsLocked();
|
|
937
879
|
if (!census.complete) {
|
|
938
|
-
this.announceAdoptionNotice("migration-incomplete", "every-scope",
|
|
880
|
+
this.announceAdoptionNotice("migration-incomplete", "every-scope", "memory ledger unbound-row convergence abandoned this pass — the projection census could not read every scope (bindings derived from a partial view could be wrong); it retries at the next entry");
|
|
939
881
|
return;
|
|
940
882
|
}
|
|
941
883
|
const now = this.now();
|
|
942
884
|
const next = Object.create(null);
|
|
943
885
|
const bound = [];
|
|
944
|
-
const unbound = [];
|
|
945
886
|
const events = [];
|
|
946
887
|
for (const [id, row] of rowsEntries(rows)) {
|
|
947
|
-
if (
|
|
888
|
+
if (rowsBinding(rows, id) !== undefined) {
|
|
948
889
|
next[id] = { ...row };
|
|
949
890
|
continue;
|
|
950
891
|
}
|
|
@@ -953,40 +894,28 @@ export class FileMemoryEngineBackend {
|
|
|
953
894
|
if (projections.length === 1 && sole !== undefined) {
|
|
954
895
|
next[id] = { ...row, scope: sole.scope, slug: sole.slug };
|
|
955
896
|
bound.push(id);
|
|
956
|
-
|
|
957
|
-
events.push({ ev: randomUUID(), channel: "migration-bind", id, to: sole, at: now });
|
|
897
|
+
events.push({ ev: randomUUID(), channel: "migration-bind", id, to: sole, at: now });
|
|
958
898
|
}
|
|
959
899
|
else {
|
|
960
900
|
next[id] = { ...row };
|
|
961
|
-
unbound.push(`${id} (${projections.length} projection(s))`);
|
|
962
901
|
}
|
|
963
902
|
}
|
|
964
|
-
if (
|
|
965
|
-
this.writeV1BackupOnce();
|
|
966
|
-
events.push({ ev: randomUUID(), channel: "migration", boundRows: bound.length, unboundRows: unbound.length, at: now });
|
|
967
|
-
}
|
|
968
|
-
else if (bound.length === 0) {
|
|
903
|
+
if (bound.length === 0)
|
|
969
904
|
return;
|
|
970
|
-
}
|
|
971
905
|
this.assertTxnLockOwnership(lockToken);
|
|
972
906
|
this.precheckTransfersAppendable();
|
|
973
907
|
const journal = { txn: `${Date.now()}-migrate`, ops: [], ledger2: ledgerEnvelope(next, this.envelopeExtras), transfers: events };
|
|
974
908
|
atomicWriteFileSync(join(this.controlPlaneRoot, STORE_JOURNAL_FILE), JSON.stringify(journal));
|
|
975
909
|
this.ledger = next;
|
|
976
|
-
this.persistedSchemaVersion = "v2";
|
|
977
910
|
this.saveLedger();
|
|
978
911
|
this.appendTransfers(events);
|
|
979
912
|
rmSync(join(this.controlPlaneRoot, STORE_JOURNAL_FILE), { force: true });
|
|
980
|
-
this.enqueueExternalItems("operator", [
|
|
981
|
-
fullMigration
|
|
982
|
-
? `memory ledger upgraded to v2 (${bound.length} row(s) bound, ${unbound.length} unbound${unbound.length > 0 ? `: ${unbound.slice(0, 8).join(", ")}${unbound.length > 8 ? ", …" : ""}` : ""})`
|
|
983
|
-
: `memory ledger unbound row(s) converged to bound: ${bound.slice(0, 8).join(", ")}${bound.length > 8 ? ", …" : ""}`,
|
|
984
|
-
]);
|
|
913
|
+
this.enqueueExternalItems("operator", [`memory ledger unbound row(s) converged to bound: ${bound.slice(0, 8).join(", ")}${bound.length > 8 ? ", …" : ""}`]);
|
|
985
914
|
}
|
|
986
915
|
chainDegradedMarkerPresent() {
|
|
987
916
|
return readControlFileOrAbsent(join(this.controlPlaneRoot, CHAIN_DEGRADED_FILE), "evidence-chain degradation marker") !== undefined;
|
|
988
917
|
}
|
|
989
|
-
mintChainDegradedMarker(
|
|
918
|
+
mintChainDegradedMarker(fragmentName) {
|
|
990
919
|
const path = join(this.controlPlaneRoot, CHAIN_DEGRADED_FILE);
|
|
991
920
|
let fd;
|
|
992
921
|
try {
|
|
@@ -1000,7 +929,7 @@ export class FileMemoryEngineBackend {
|
|
|
1000
929
|
throw new ControlPlaneCorruptError(`evidence-chain degradation marker could not be created at ${path} (${err.code ?? "io error"}) — heal aborted, the chain is unchanged (fail-closed)`);
|
|
1001
930
|
}
|
|
1002
931
|
try {
|
|
1003
|
-
writeAllSync(fd, `${JSON.stringify({ at: this.now(), ...(
|
|
932
|
+
writeAllSync(fd, `${JSON.stringify({ at: this.now(), ...(fragmentName !== undefined ? { fragment: fragmentName } : {}) }, null, 2)}\n`);
|
|
1004
933
|
fsyncSync(fd);
|
|
1005
934
|
}
|
|
1006
935
|
finally {
|
|
@@ -1066,17 +995,23 @@ export class FileMemoryEngineBackend {
|
|
|
1066
995
|
const outOfBand = !journalHasPendingEvidence;
|
|
1067
996
|
if (fenceToken !== undefined)
|
|
1068
997
|
this.assertTxnLockOwnership(fenceToken);
|
|
1069
|
-
let
|
|
998
|
+
let fragmentName;
|
|
1070
999
|
try {
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1000
|
+
const base = `transfers-torn-tail-${this.now()}.fragment`;
|
|
1001
|
+
const bytes = new TextEncoder().encode(line);
|
|
1002
|
+
for (let attempt = 0; fragmentName === undefined && attempt <= 10; attempt++) {
|
|
1003
|
+
const name = quarantineCaptureName(base, attempt);
|
|
1004
|
+
if (putFileControlObjectOnce(this.controlPlaneRoot, "quarantine", name, bytes) === "created")
|
|
1005
|
+
fragmentName = name;
|
|
1006
|
+
}
|
|
1074
1007
|
}
|
|
1075
1008
|
catch {
|
|
1076
|
-
|
|
1009
|
+
fragmentName = undefined;
|
|
1077
1010
|
}
|
|
1011
|
+
if (fragmentName === undefined)
|
|
1012
|
+
throw new ControlPlaneCorruptError(`transfer evidence log has a torn tail that could not be quarantined: ${path}`);
|
|
1078
1013
|
if (outOfBand)
|
|
1079
|
-
this.mintChainDegradedMarker(
|
|
1014
|
+
this.mintChainDegradedMarker(fragmentName);
|
|
1080
1015
|
this.chainHealProbe?.();
|
|
1081
1016
|
if (fenceToken !== undefined)
|
|
1082
1017
|
this.assertTxnLockOwnership(fenceToken);
|
|
@@ -1184,8 +1119,7 @@ export class FileMemoryEngineBackend {
|
|
|
1184
1119
|
const raw = readControlFileOrAbsent(join(this.controlPlaneRoot, LEDGER_FILE), "committed-rev ledger");
|
|
1185
1120
|
if (raw === undefined)
|
|
1186
1121
|
return Object.create(null);
|
|
1187
|
-
|
|
1188
|
-
return parsed.form === "v2" ? parsed.rows : Object.create(null);
|
|
1122
|
+
return parseLedgerText(raw, join(this.controlPlaneRoot, LEDGER_FILE)).rows;
|
|
1189
1123
|
}
|
|
1190
1124
|
catch (err) {
|
|
1191
1125
|
const code = err.code ?? (err instanceof ControlPlaneCorruptError ? "corrupt" : "io error");
|
|
@@ -1263,18 +1197,7 @@ export class FileMemoryEngineBackend {
|
|
|
1263
1197
|
const raw = readControlFileOrAbsent(jp, "transaction journal");
|
|
1264
1198
|
if (raw !== undefined) {
|
|
1265
1199
|
const journal = parseJournal(raw, jp);
|
|
1266
|
-
const { rows: snapshotRows, extras: snapshotExtras
|
|
1267
|
-
if (snapshotForm === "v1") {
|
|
1268
|
-
try {
|
|
1269
|
-
if (ledgerFormOnDisk(this.controlPlaneRoot) === "v2") {
|
|
1270
|
-
this.enqueueExternalItems("every-scope", [
|
|
1271
|
-
"memory ledger: recovering a v1-format journal over a v2 ledger — a pre-v2 process wrote AFTER this store migrated (mixed-version deployment window). Retire old readers/writers before further writes; see the v2 rollback runbook.",
|
|
1272
|
-
]);
|
|
1273
|
-
}
|
|
1274
|
-
}
|
|
1275
|
-
catch {
|
|
1276
|
-
}
|
|
1277
|
-
}
|
|
1200
|
+
const { rows: snapshotRows, extras: snapshotExtras } = journalLedgerSnapshot(journal, jp);
|
|
1278
1201
|
for (const op of journal.ops) {
|
|
1279
1202
|
const invalid = journalOpInvalid(op, this.directoryRoot);
|
|
1280
1203
|
if (invalid !== undefined) {
|
|
@@ -1301,8 +1224,6 @@ export class FileMemoryEngineBackend {
|
|
|
1301
1224
|
journalEvs.set(e.ev, canonical);
|
|
1302
1225
|
journalChainForms.set(e.ev, canonicalJsonStringify(chainFormOf(e)));
|
|
1303
1226
|
}
|
|
1304
|
-
if (snapshotForm === "v1")
|
|
1305
|
-
throw new ControlPlaneCorruptError(`transaction journal carries transfers with a v1 snapshot (impossible form): ${jp}`);
|
|
1306
1227
|
if (journalEvs.size > 0) {
|
|
1307
1228
|
for (const row of this.readTransferChain(fenceToken)) {
|
|
1308
1229
|
const j = journalEvs.get(row.ev);
|
|
@@ -1459,19 +1380,11 @@ export class FileMemoryEngineBackend {
|
|
|
1459
1380
|
}
|
|
1460
1381
|
this.recoveryCommitProbe?.();
|
|
1461
1382
|
this.assertTxnLockOwnership(fenceToken);
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
this.recordJournalSweep(journal);
|
|
1468
|
-
this.appendTransfers(journal.transfers ?? []);
|
|
1469
|
-
}
|
|
1470
|
-
else {
|
|
1471
|
-
this.ledger = snapshotRows;
|
|
1472
|
-
this.persistedSchemaVersion = "v1";
|
|
1473
|
-
this.persistLedgerV1(snapshotRows);
|
|
1474
|
-
}
|
|
1383
|
+
this.ledger = snapshotRows;
|
|
1384
|
+
this.envelopeExtras = snapshotExtras;
|
|
1385
|
+
this.saveLedger();
|
|
1386
|
+
this.recordJournalSweep(journal);
|
|
1387
|
+
this.appendTransfers(journal.transfers ?? []);
|
|
1475
1388
|
if (typeof journal.txn === "string") {
|
|
1476
1389
|
this.closeJournalIfOurs(journal.txn);
|
|
1477
1390
|
}
|
|
@@ -1544,7 +1457,7 @@ export class FileMemoryEngineBackend {
|
|
|
1544
1457
|
}
|
|
1545
1458
|
containInboundReject(finding, absPath, text, entryId, committed) {
|
|
1546
1459
|
this.inboundFindings.push(finding);
|
|
1547
|
-
const q =
|
|
1460
|
+
const q = clearContainedPath(absPath, text, captureIntoFileQuarantine(this.controlPlaneRoot, absPath, text, this.now));
|
|
1548
1461
|
const shadowText = committed !== undefined ? this.readCommittedShadow(entryId) : undefined;
|
|
1549
1462
|
let restoredShadow = false;
|
|
1550
1463
|
if (shadowText !== undefined) {
|
|
@@ -1585,7 +1498,7 @@ export class FileMemoryEngineBackend {
|
|
|
1585
1498
|
if (memo !== undefined)
|
|
1586
1499
|
return memo;
|
|
1587
1500
|
}
|
|
1588
|
-
if (this.
|
|
1501
|
+
if (this.unboundRowsKnown)
|
|
1589
1502
|
this.tryOpportunisticMigrate();
|
|
1590
1503
|
const dir = this.scopeDir(scope);
|
|
1591
1504
|
const files = scanEntryFiles(dir);
|
|
@@ -1937,7 +1850,7 @@ export class FileMemoryEngineBackend {
|
|
|
1937
1850
|
restrictedIdlessScope;
|
|
1938
1851
|
restrictedIdlessBaseline;
|
|
1939
1852
|
readScopeCommitted(scope, audit) {
|
|
1940
|
-
if (this.
|
|
1853
|
+
if (this.unboundRowsKnown)
|
|
1941
1854
|
this.tryOpportunisticMigrate();
|
|
1942
1855
|
const dir = this.scopeDir(scope);
|
|
1943
1856
|
const files = scanEntryFiles(dir, {
|
|
@@ -2132,11 +2045,10 @@ export class FileMemoryEngineBackend {
|
|
|
2132
2045
|
this.readScopeCommitted(scope, true);
|
|
2133
2046
|
const idlessBaseline = opts?.idlessWriteScope !== undefined && opts.idlessWriteScope === this.restrictedIdlessScope ? this.restrictedIdlessBaseline : undefined;
|
|
2134
2047
|
const idlessScope = idlessBaseline !== undefined ? opts?.idlessWriteScope : undefined;
|
|
2135
|
-
if (
|
|
2048
|
+
if (hasUnboundRows(this.loadLedger()))
|
|
2136
2049
|
this.tryOpportunisticMigrate();
|
|
2137
2050
|
const rows = { ...this.loadLedger() };
|
|
2138
|
-
|
|
2139
|
-
this.announceUnboundRows(rows);
|
|
2051
|
+
this.announceUnboundRows(rows);
|
|
2140
2052
|
const present = new Map();
|
|
2141
2053
|
let complete = true;
|
|
2142
2054
|
for (const scope of Object.keys(registeredScopes(this.controlPlaneRoot))) {
|
|
@@ -2646,38 +2558,6 @@ export class FileMemoryEngineBackend {
|
|
|
2646
2558
|
if (row !== undefined)
|
|
2647
2559
|
recordErasureSweep(this.controlPlaneRoot, row.req, row.paths);
|
|
2648
2560
|
}
|
|
2649
|
-
eraseQuarantineCopiesLocked(ids) {
|
|
2650
|
-
const qDir = join(this.controlPlaneRoot, QUARANTINE_DIR);
|
|
2651
|
-
let names = [];
|
|
2652
|
-
try {
|
|
2653
|
-
names = readdirSync(qDir);
|
|
2654
|
-
}
|
|
2655
|
-
catch (err) {
|
|
2656
|
-
if (err.code !== "ENOENT") {
|
|
2657
|
-
throw new ControlPlaneCorruptError(`erasure residual enumeration failed: the quarantine dir could not be read (${err.code ?? "io error"}) at ${qDir} — the attestation must not silently claim an empty residual set; retry after the filesystem fault clears (the deletions themselves are committed and a replay converges)`);
|
|
2658
|
-
}
|
|
2659
|
-
}
|
|
2660
|
-
const out = { removed: 0, remaining: 0, unattributed: 0 };
|
|
2661
|
-
for (const name of names.sort()) {
|
|
2662
|
-
const path = join(qDir, name);
|
|
2663
|
-
const text = readSafe(path);
|
|
2664
|
-
const qid = text === undefined ? undefined : parseEntryFile(text).id;
|
|
2665
|
-
if (qid === undefined) {
|
|
2666
|
-
out.unattributed++;
|
|
2667
|
-
continue;
|
|
2668
|
-
}
|
|
2669
|
-
if (!ids.has(qid))
|
|
2670
|
-
continue;
|
|
2671
|
-
try {
|
|
2672
|
-
rmSync(path, { force: true });
|
|
2673
|
-
out.removed++;
|
|
2674
|
-
}
|
|
2675
|
-
catch {
|
|
2676
|
-
out.remaining++;
|
|
2677
|
-
}
|
|
2678
|
-
}
|
|
2679
|
-
return out;
|
|
2680
|
-
}
|
|
2681
2561
|
controlDirHoldsAnything(name) {
|
|
2682
2562
|
try {
|
|
2683
2563
|
return readdirSync(join(this.controlPlaneRoot, name)).length > 0;
|
|
@@ -2926,7 +2806,7 @@ export class FileMemoryEngineBackend {
|
|
|
2926
2806
|
e.sessions = [...new Set([...e.sessions, ...lateSessions])].sort();
|
|
2927
2807
|
}
|
|
2928
2808
|
const resolvedSet = new Set(resolvedIds);
|
|
2929
|
-
const quarantine = this.
|
|
2809
|
+
const quarantine = await eraseQuarantineCopies(standingControlObjectsOf(this.governance), resolvedSet);
|
|
2930
2810
|
const att = {
|
|
2931
2811
|
v: 2,
|
|
2932
2812
|
requestId,
|
|
@@ -2946,7 +2826,7 @@ export class FileMemoryEngineBackend {
|
|
|
2946
2826
|
projection: { removed: erased.reduce((n, e) => n + e.projectionsRemoved, 0), remaining: 0 },
|
|
2947
2827
|
shadow: { removed: ops.filter((op) => op.kind === "shadow-delete").length, remaining: 0 },
|
|
2948
2828
|
indexLine: readErasureSweep(this.controlPlaneRoot, this.directoryRoot, requestId).length > 0 ? { unverified: true } : { removed: 0, remaining: 0 },
|
|
2949
|
-
quarantineCopy: { removed: quarantine.removed, remaining: quarantine.remaining },
|
|
2829
|
+
quarantineCopy: { removed: quarantine.removed, remaining: quarantine.remaining, unreadable: quarantine.unreadable },
|
|
2950
2830
|
planArchive: this.controlDirHoldsAnything(CONSOLIDATION_DRIVER_PLANS_DIR) ? { unverified: true } : { removed: 0, remaining: 0 },
|
|
2951
2831
|
planWorkbook: this.controlDirHoldsAnything(CONSOLIDATION_PLANS_DIR) ? { unverified: true } : { removed: 0, remaining: 0 },
|
|
2952
2832
|
evidenceBinding: { removed: 0, remaining: chain.filter((r) => typeof r.parsed.id === "string" && resolvedSet.has(r.parsed.id) && (spellsSlug(r.parsed.from) || spellsSlug(r.parsed.to))).length },
|
|
@@ -2979,13 +2859,7 @@ export class FileMemoryEngineBackend {
|
|
|
2979
2859
|
const raw = readControlFileOrAbsent(path, "committed-rev ledger");
|
|
2980
2860
|
if (raw === undefined)
|
|
2981
2861
|
return { raw, rows: Object.create(null) };
|
|
2982
|
-
|
|
2983
|
-
if (parsed.form === "v1") {
|
|
2984
|
-
throw new Error(`memory audit read refused: the committed-rev ledger at ${path} is still schema v1 (pre-binding) — ` +
|
|
2985
|
-
`migrate first (the store migrates itself at its next uncontended write/read entry or checkControlPlane); ` +
|
|
2986
|
-
`an audit read never triggers the migration`);
|
|
2987
|
-
}
|
|
2988
|
-
return { raw, rows: parsed.rows };
|
|
2862
|
+
return { raw, rows: parseLedgerText(raw, path).rows };
|
|
2989
2863
|
}
|
|
2990
2864
|
async auditStable(read) {
|
|
2991
2865
|
for (let attempt = 0; attempt < FileMemoryEngineBackend.AUDIT_FENCE_ATTEMPTS; attempt++) {
|
|
@@ -3132,7 +3006,7 @@ export class FileMemoryEngineBackend {
|
|
|
3132
3006
|
const ledgerRaw = readControlFileOrAbsent(join(this.controlPlaneRoot, LEDGER_FILE), "committed-rev ledger");
|
|
3133
3007
|
if (ledgerRaw !== undefined) {
|
|
3134
3008
|
const parsed = parseLedgerText(ledgerRaw, join(this.controlPlaneRoot, LEDGER_FILE));
|
|
3135
|
-
if (
|
|
3009
|
+
if (Object.prototype.hasOwnProperty.call(parsed.rows, id) && parsed.rows[id]?.prev !== undefined) {
|
|
3136
3010
|
out.state = "damaged";
|
|
3137
3011
|
}
|
|
3138
3012
|
}
|
|
@@ -3241,12 +3115,15 @@ export class FileMemoryEngineBackend {
|
|
|
3241
3115
|
}
|
|
3242
3116
|
return storeId;
|
|
3243
3117
|
}
|
|
3118
|
+
pollutionRosterObjects() {
|
|
3119
|
+
return standingControlObjectsOf(this.governance);
|
|
3120
|
+
}
|
|
3244
3121
|
exportGovernanceFingerprint() {
|
|
3245
3122
|
const h = createHash("sha256");
|
|
3246
3123
|
const feed = (label, text) => {
|
|
3247
3124
|
h.update(JSON.stringify([label, text]));
|
|
3248
3125
|
};
|
|
3249
|
-
for (const file of
|
|
3126
|
+
for (const file of STRICT_CONTROL_PLANE_LEDGERS.map((ledger) => fileGovernanceDocOf(ledger).file)) {
|
|
3250
3127
|
feed(file, readControlFileOrAbsent(join(this.controlPlaneRoot, file), `${file} (export fence)`) ?? "<absent>");
|
|
3251
3128
|
let journalRaw;
|
|
3252
3129
|
try {
|
|
@@ -3257,23 +3134,14 @@ export class FileMemoryEngineBackend {
|
|
|
3257
3134
|
}
|
|
3258
3135
|
feed(`${file}.journal`, journalRaw ?? "<absent>");
|
|
3259
3136
|
}
|
|
3260
|
-
const
|
|
3261
|
-
let names = [];
|
|
3262
|
-
try {
|
|
3263
|
-
names = readdirSync(dir).sort();
|
|
3264
|
-
}
|
|
3265
|
-
catch (err) {
|
|
3266
|
-
if (err.code !== "ENOENT") {
|
|
3267
|
-
throw new ControlPlaneCorruptError(`session pollution markers could not be enumerated for export (${err.code ?? "io error"}) at ${dir} — fail-closed`, { cause: err });
|
|
3268
|
-
}
|
|
3269
|
-
}
|
|
3270
|
-
for (const name of names) {
|
|
3137
|
+
for (const name of standingFileControlObjectNames(this.controlPlaneRoot, "pollution")) {
|
|
3271
3138
|
let text;
|
|
3272
3139
|
try {
|
|
3273
|
-
|
|
3140
|
+
const bytes = getFileControlObject(this.controlPlaneRoot, "pollution", name);
|
|
3141
|
+
text = bytes === undefined ? "<absent>" : new TextDecoder().decode(bytes);
|
|
3274
3142
|
}
|
|
3275
3143
|
catch (err) {
|
|
3276
|
-
text = `<unreadable:${err
|
|
3144
|
+
text = `<unreadable:${fileControlObjectFaultCode(err) ?? "io error"}>`;
|
|
3277
3145
|
}
|
|
3278
3146
|
feed(`pollution/${name}`, text);
|
|
3279
3147
|
}
|
|
@@ -3383,20 +3251,24 @@ export class FileMemoryEngineBackend {
|
|
|
3383
3251
|
return { custody, unsliceable };
|
|
3384
3252
|
}
|
|
3385
3253
|
enumerateQuarantineFor(ids) {
|
|
3386
|
-
|
|
3387
|
-
let names = [];
|
|
3254
|
+
let names;
|
|
3388
3255
|
try {
|
|
3389
|
-
names =
|
|
3256
|
+
names = standingFileControlObjectNames(this.controlPlaneRoot, "quarantine");
|
|
3390
3257
|
}
|
|
3391
3258
|
catch (err) {
|
|
3392
|
-
|
|
3393
|
-
throw new ControlPlaneCorruptError(`export residual enumeration failed: the quarantine dir could not be read (${err.code ?? "io error"}) at ${qDir} — a bundle must not silently claim an empty residual set`);
|
|
3394
|
-
}
|
|
3259
|
+
throw new ControlPlaneCorruptError(`export residual enumeration failed: the quarantine objects could not be listed (${fileControlObjectFaultCode(err) ?? "io error"}) — a bundle must not silently claim an empty residual set`, { cause: err });
|
|
3395
3260
|
}
|
|
3396
3261
|
const quarantined = [];
|
|
3397
3262
|
let quarantineOpaque = 0;
|
|
3398
|
-
for (const name of names
|
|
3399
|
-
|
|
3263
|
+
for (const name of names) {
|
|
3264
|
+
let text;
|
|
3265
|
+
try {
|
|
3266
|
+
const bytes = getFileControlObject(this.controlPlaneRoot, "quarantine", name);
|
|
3267
|
+
text = bytes === undefined ? undefined : new TextDecoder().decode(bytes);
|
|
3268
|
+
}
|
|
3269
|
+
catch {
|
|
3270
|
+
text = undefined;
|
|
3271
|
+
}
|
|
3400
3272
|
if (text === undefined) {
|
|
3401
3273
|
quarantineOpaque++;
|
|
3402
3274
|
continue;
|
|
@@ -3420,9 +3292,6 @@ export class FileMemoryEngineBackend {
|
|
|
3420
3292
|
this.recoverJournal({ token: lock.token });
|
|
3421
3293
|
this.adoptLayoutLocked(lock.token);
|
|
3422
3294
|
const rows = this.loadLedger();
|
|
3423
|
-
if (this.persistedSchemaVersion !== "v2") {
|
|
3424
|
-
throw erasureCodedError("memory export refused: the committed-rev ledger is still schema v1 (pre-binding) — the store migrates itself at its next write/read entry or checkControlPlane; an export never triggers the migration", FileMemoryEngineBackend.EXPORT_INCOMPLETE);
|
|
3425
|
-
}
|
|
3426
3295
|
if (this.chainDegradedMarkerPresent()) {
|
|
3427
3296
|
throw erasureCodedError("memory export refused: the custody chain carries the durable degradation marker (transfers.chain-degraded.json) — evidence rows were lost to an out-of-band tear and a bundle cannot testify to a complete deletion history; resolve the marker deliberately before exporting", FileMemoryEngineBackend.EXPORT_INCOMPLETE);
|
|
3428
3297
|
}
|
|
@@ -3433,7 +3302,7 @@ export class FileMemoryEngineBackend {
|
|
|
3433
3302
|
const before = this.exportGovernanceFingerprint();
|
|
3434
3303
|
const lineageRec = await readLineageRecord(this.governance);
|
|
3435
3304
|
const challenges = await readChallengeEvents(this.governance);
|
|
3436
|
-
const polluted = listSessionPollution(this.
|
|
3305
|
+
const polluted = await listSessionPollution(this.pollutionRosterObjects());
|
|
3437
3306
|
const chainRows = this.readExportChainRowsPure();
|
|
3438
3307
|
await this.exportFaceProbe?.(round);
|
|
3439
3308
|
const after = this.exportGovernanceFingerprint();
|
|
@@ -3504,8 +3373,6 @@ export class FileMemoryEngineBackend {
|
|
|
3504
3373
|
this.recoverJournal({ token: lock.token });
|
|
3505
3374
|
this.adoptLayoutLocked(lock.token);
|
|
3506
3375
|
const rows = this.loadLedger();
|
|
3507
|
-
if (this.persistedSchemaVersion !== "v2")
|
|
3508
|
-
return { custody: [], unbound: [], complete: false, unsliceableCustody: 0, reason: "the committed-rev ledger is still schema v1 (migrate first)" };
|
|
3509
3376
|
if (this.chainDegradedMarkerPresent()) {
|
|
3510
3377
|
return { custody: [], unbound: [], complete: false, unsliceableCustody: 0, reason: "the custody chain carries the durable degradation marker (transfers.chain-degraded.json) — evidence rows were lost to an out-of-band tear" };
|
|
3511
3378
|
}
|
|
@@ -3609,11 +3476,11 @@ export class FileMemoryEngineBackend {
|
|
|
3609
3476
|
this.recoverJournal({ token: lock.token });
|
|
3610
3477
|
this.adoptLayoutLocked(lock.token);
|
|
3611
3478
|
this.migrateLockedIfNeeded(lock.token);
|
|
3612
|
-
const ctl = this.controlPlaneRoot;
|
|
3613
3479
|
const txnId = importLatchTxnId(bundleHash);
|
|
3614
|
-
const
|
|
3615
|
-
const
|
|
3616
|
-
if (
|
|
3480
|
+
const receiptName = importReceiptName(bundleHash);
|
|
3481
|
+
const receiptBytes = await this.governance.getObject("import-receipt", receiptName);
|
|
3482
|
+
if (receiptBytes !== undefined) {
|
|
3483
|
+
const receiptRaw = new TextDecoder().decode(receiptBytes);
|
|
3617
3484
|
let report;
|
|
3618
3485
|
try {
|
|
3619
3486
|
const parsed = JSON.parse(receiptRaw);
|
|
@@ -3649,9 +3516,9 @@ export class FileMemoryEngineBackend {
|
|
|
3649
3516
|
report = rep;
|
|
3650
3517
|
}
|
|
3651
3518
|
catch {
|
|
3652
|
-
throw new ControlPlaneCorruptError(`bundle import completion receipt is unreadable/malformed
|
|
3519
|
+
throw new ControlPlaneCorruptError(`bundle import completion receipt ${receiptName} is unreadable/malformed — it cannot prove completion and cannot be re-minted; repair or remove it deliberately (fail-closed)`);
|
|
3653
3520
|
}
|
|
3654
|
-
await releaseImportLatch(this.governance,
|
|
3521
|
+
await releaseImportLatch(this.governance, txnId);
|
|
3655
3522
|
return report;
|
|
3656
3523
|
}
|
|
3657
3524
|
const digest = this.deletedIdsDigestLocked();
|
|
@@ -3775,39 +3642,15 @@ export class FileMemoryEngineBackend {
|
|
|
3775
3642
|
reason: `challenged: the contributing session was marked polluted`,
|
|
3776
3643
|
challengedRev: c.lastRev,
|
|
3777
3644
|
})));
|
|
3778
|
-
const outcome = importSessionPollution(
|
|
3645
|
+
const outcome = await importSessionPollution(this.governance, p.sessionId, { at: p.at, reason: p.reason, ...(p.cause !== undefined ? { cause: p.cause } : {}) });
|
|
3779
3646
|
if (outcome === "divergent")
|
|
3780
3647
|
report.pollutionDivergence.push({ sessionId: p.sessionId, kept: "destination" });
|
|
3781
3648
|
}
|
|
3782
|
-
|
|
3783
|
-
if (
|
|
3784
|
-
throw new ControlPlaneCorruptError(`bundle import completion receipt appeared mid-import
|
|
3785
|
-
}
|
|
3786
|
-
const staged = join(ctl, IMPORT_RECEIPTS_DIR, `.stage-${bundleHash}-${randomUUID().slice(0, 8)}`);
|
|
3787
|
-
const fd = openSync(staged, "wx", 0o600);
|
|
3788
|
-
try {
|
|
3789
|
-
writeAllSync(fd, `${JSON.stringify({ v: 1, bundleHash, at: this.now(), report }, null, 2)}\n`);
|
|
3790
|
-
fsyncSync(fd);
|
|
3791
|
-
}
|
|
3792
|
-
finally {
|
|
3793
|
-
closeSync(fd);
|
|
3794
|
-
}
|
|
3795
|
-
try {
|
|
3796
|
-
linkSync(staged, receiptPath);
|
|
3797
|
-
rmSync(staged, { force: true });
|
|
3798
|
-
}
|
|
3799
|
-
catch (err) {
|
|
3800
|
-
try {
|
|
3801
|
-
rmSync(staged, { force: true });
|
|
3802
|
-
}
|
|
3803
|
-
catch {
|
|
3804
|
-
}
|
|
3805
|
-
if (err.code === "EEXIST") {
|
|
3806
|
-
throw new ControlPlaneCorruptError(`bundle import completion receipt appeared mid-import at ${receiptPath} — refusing to overwrite it (fail-closed)`);
|
|
3807
|
-
}
|
|
3808
|
-
throw err;
|
|
3649
|
+
const published = await this.governance.putObject("import-receipt", receiptName, new TextEncoder().encode(`${JSON.stringify({ v: 1, bundleHash, at: this.now(), report }, null, 2)}\n`));
|
|
3650
|
+
if (published === "existed") {
|
|
3651
|
+
throw new ControlPlaneCorruptError(`bundle import completion receipt ${receiptName} appeared mid-import — refusing to overwrite it (fail-closed)`);
|
|
3809
3652
|
}
|
|
3810
|
-
await releaseImportLatch(this.governance,
|
|
3653
|
+
await releaseImportLatch(this.governance, txnId);
|
|
3811
3654
|
return report;
|
|
3812
3655
|
}
|
|
3813
3656
|
catch (err) {
|