@sema-agent/core 7.64.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 +317 -0
- package/dist/agents/peer-held-queue.js +1 -1
- package/dist/agents/peer-idle.js +1 -1
- package/dist/agents/peer-session-drain.js +3 -3
- package/dist/agents/subagent.js +5 -2
- package/dist/core/auto-promote.d.ts +3 -2
- package/dist/core/background-agent-store.d.ts +7 -0
- package/dist/core/checkpoint-store.d.ts +2 -3
- package/dist/core/context-settings.d.ts +1 -2
- package/dist/core/context-settings.js +1 -1
- package/dist/core/engine-attestation.d.ts +2 -2
- package/dist/core/engine-notice.d.ts +13 -1
- package/dist/core/engine-notice.js +3 -1
- package/dist/core/file-history-store.d.ts +2 -2
- package/dist/core/file-history-store.js +0 -4
- package/dist/core/gate-fold.js +3 -1
- package/dist/core/governance-codes.d.ts +6 -4
- package/dist/core/governance-codes.js +4 -3
- package/dist/core/leg-identity.d.ts +18 -2
- package/dist/core/leg-identity.js +5 -7
- package/dist/core/mailbox-store.d.ts +1 -1
- package/dist/core/memory-engine/consolidation.d.ts +10 -4
- package/dist/core/memory-engine/consolidation.js +11 -1
- package/dist/core/memory-engine/control-objects.d.ts +36 -3
- package/dist/core/memory-engine/control-objects.js +134 -12
- package/dist/core/memory-engine/control-plane-adoption.d.ts +5 -2
- package/dist/core/memory-engine/control-plane-adoption.js +5 -3
- package/dist/core/memory-engine/delegation-settlement.d.ts +59 -42
- package/dist/core/memory-engine/delegation-settlement.js +175 -202
- package/dist/core/memory-engine/dual-root.d.ts +3 -2
- package/dist/core/memory-engine/dual-root.js +5 -1
- package/dist/core/memory-engine/engine.d.ts +16 -10
- package/dist/core/memory-engine/engine.js +138 -145
- package/dist/core/memory-engine/file-backend.d.ts +17 -11
- package/dist/core/memory-engine/file-backend.js +53 -103
- package/dist/core/memory-engine/layout.d.ts +129 -49
- package/dist/core/memory-engine/layout.js +202 -82
- 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.js +5 -4
- package/dist/core/memory-engine/memory-deployment.d.ts +1 -1
- package/dist/core/memory-engine/origin-clearance.js +1 -5
- 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 +16 -10
- 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/permission-rule-consent.d.ts +49 -18
- package/dist/core/permission-rule-consent.js +59 -38
- package/dist/core/permission-rule-store.d.ts +24 -14
- package/dist/core/retention.d.ts +2 -7
- package/dist/core/retention.js +0 -1
- package/dist/core/runner/classifier-ladder.d.ts +3 -1
- package/dist/core/runner/classifier-ladder.js +2 -2
- package/dist/core/runner/contracts.d.ts +9 -9
- package/dist/core/runner/delegation-owner.d.ts +0 -8
- package/dist/core/runner/delegation-owner.js +1 -3
- package/dist/core/runner/prepare-gate-stations.d.ts +8 -5
- package/dist/core/runner/prepare-gate-stations.js +13 -5
- package/dist/core/runner/prepare-memory-engine-session.js +1 -1
- package/dist/core/runner/prepare-memory.js +9 -9
- package/dist/core/runner/prepare-policy-chain.js +11 -3
- package/dist/core/runner/prepare-task.d.ts +5 -1
- package/dist/core/runner/prepare-task.js +3 -3
- package/dist/core/runner/run-notification-lane.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/secret-env.d.ts +2 -2
- package/dist/core/secret-env.js +6 -20
- package/dist/core/session-store.d.ts +6 -6
- package/dist/core/session-store.js +3 -3
- package/dist/core/store-contracts/background-agent-store-contract.js +13 -0
- package/dist/core/task-notification.d.ts +35 -8
- package/dist/core/task-notification.js +31 -13
- package/dist/core/task-registry-agent.js +1 -0
- package/dist/core/task-registry-shared.d.ts +4 -0
- package/dist/core/tool-errors.d.ts +3 -3
- package/dist/core/tool-spec.d.ts +7 -7
- package/dist/core/write-protect.d.ts +16 -0
- package/dist/core/write-protect.js +10 -0
- package/dist/engine/session/repo-utils.d.ts +14 -4
- package/dist/engine/session/repo-utils.js +5 -4
- package/dist/index.d.ts +6 -6
- package/dist/index.js +6 -6
- 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/index.d.ts +1 -15
- package/dist/stores/file/index.js +1 -15
- package/dist/stores/file/permission-rule-store.d.ts +12 -1
- package/dist/stores/file/permission-rule-store.js +31 -4
- package/dist/stores/file/session-store.js +1 -1
- package/package.json +2 -2
- package/test/export-surface.snapshot.json +9 -73
- package/wire-changes/core-stores-sql@7.65.0.json +30 -0
- package/wire-changes/core@7.65.0.json +1650 -0
- package/wire-changes/mods-kernel@7.65.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
|
@@ -25,7 +25,8 @@ export type ErasedBinding = {
|
|
|
25
25
|
* - `projection` — the entry's files under its scope home (bound path + every census copy);
|
|
26
26
|
* - `shadow` — the control plane's committed copy;
|
|
27
27
|
* - `indexLine` — MEMORY.md pointer lines (name + description) naming a deleted projection path;
|
|
28
|
-
* - `quarantineCopy` — quarantine
|
|
28
|
+
* - `quarantineCopy` — the governance store's `quarantine` objects whose frontmatter id is the erased id (an object the
|
|
29
|
+
* lane could not read to tell is counted as remaining and named by `unreadable`);
|
|
29
30
|
* - `planArchive` / `planWorkbook` — the consolidation plane's mint archive and plan workbook;
|
|
30
31
|
* - `evidenceBinding` — evidence-chain rows that still spell the entry's slug;
|
|
31
32
|
* - `backendDerived` — anything a backend derives privately (vectors, summaries).
|
|
@@ -33,10 +34,14 @@ export type ErasedBinding = {
|
|
|
33
34
|
export declare const ERASURE_CARRIER_CLASSES: readonly ["projection", "shadow", "indexLine", "quarantineCopy", "planArchive", "planWorkbook", "evidenceBinding", "backendDerived"];
|
|
34
35
|
export type ErasureCarrierClass = (typeof ERASURE_CARRIER_CLASSES)[number];
|
|
35
36
|
/** One carrier class's answer: what this call removed and what is known to remain, or `unverified`
|
|
36
|
-
* when the answering lane cannot read that class (which never reads as clean).
|
|
37
|
+
* when the answering lane cannot read that class (which never reads as clean). `unreadable`, when a
|
|
38
|
+
* class answers it, is how many of `remaining` are carriers the lane could not read to tell whether
|
|
39
|
+
* they hold an erased entry — counted as remaining, never as clean (the `quarantineCopy` class answers
|
|
40
|
+
* it on both lanes). */
|
|
37
41
|
export type ErasureCarrierAnswer = {
|
|
38
42
|
removed: number;
|
|
39
43
|
remaining: number;
|
|
44
|
+
unreadable?: number;
|
|
40
45
|
} | {
|
|
41
46
|
unverified: true;
|
|
42
47
|
};
|
|
@@ -156,8 +161,10 @@ export interface MemoryErasureAttestation {
|
|
|
156
161
|
* delete rows, and move / migration-bind rows) — the append-only chain keeps them, so they keep
|
|
157
162
|
* the request `partial` and a replay cannot clear them. */
|
|
158
163
|
carriers: Record<ErasureCarrierClass, ErasureCarrierAnswer>;
|
|
159
|
-
/** Quarantine
|
|
160
|
-
* the quarantine read; a store-level count that does not decide `status`.
|
|
164
|
+
/** Quarantine objects read whose bytes name no entry id (fragments / non-entry shapes) — the honest
|
|
165
|
+
* bound of the quarantine read; a store-level count that does not decide `status`. An object that
|
|
166
|
+
* could not be read at all is not counted here: it is `carriers.quarantineCopy.remaining`
|
|
167
|
+
* (named by its `unreadable`). */
|
|
161
168
|
quarantineUnattributed: ErasureCountAnswer;
|
|
162
169
|
/** Committed entries outside the selection whose consolidation lineage names an erased id (they
|
|
163
170
|
* may restate it) — counted, not erased; their closure is the caller's to compute. */
|
|
@@ -587,7 +594,7 @@ export declare class FileMemoryEngineBackend implements MemoryBackend {
|
|
|
587
594
|
* read-back verification). Idempotent on an existing marker. Throws when the marker cannot be
|
|
588
595
|
* proven on disk — the caller (the heal) must then ABORT with the chain untouched: truncating
|
|
589
596
|
* first would reopen the exact window this marker closes ("chain reads complete, no marker"
|
|
590
|
-
* after an out-of-band tear). */
|
|
597
|
+
* after an out-of-band tear). `fragmentName` is the `quarantine` object the torn fragment was kept as. */
|
|
591
598
|
private mintChainDegradedMarker;
|
|
592
599
|
/** backlog #270 — make a just-created control-plane directory ENTRY power-loss durable: open the
|
|
593
600
|
* control-plane root and fsync it. Fail-closed on failure: the one caller (the marker mint) must
|
|
@@ -1097,12 +1104,6 @@ export declare class FileMemoryEngineBackend implements MemoryBackend {
|
|
|
1097
1104
|
private journalSweepRow;
|
|
1098
1105
|
/** Write the journal's sweep-record row ({@link journalSweepRow}; idempotent — a union). */
|
|
1099
1106
|
private recordJournalSweep;
|
|
1100
|
-
/** Delete every quarantine file whose frontmatter id is in `ids` (a quarantined copy is a copy of the
|
|
1101
|
-
* entry). Runs under the erasure's lock after its commit; a file that cannot be removed stays
|
|
1102
|
-
* counted as `remaining` and a replay retries it. Files no id can be read from are counted, not
|
|
1103
|
-
* touched. An unreadable quarantine directory refuses the attestation (the deletions themselves
|
|
1104
|
-
* are committed; a replay converges). */
|
|
1105
|
-
private eraseQuarantineCopiesLocked;
|
|
1106
1107
|
/** Does the control-plane directory `name` hold any entry? ENOENT ⇒ no; any other read failure ⇒
|
|
1107
1108
|
* yes (an unreadable directory may hold anything). */
|
|
1108
1109
|
private controlDirHoldsAnything;
|
|
@@ -1197,6 +1198,11 @@ export declare class FileMemoryEngineBackend implements MemoryBackend {
|
|
|
1197
1198
|
* held by every caller, so the exclusive create cannot race in-process; a cross-process EEXIST
|
|
1198
1199
|
* loser adopts the winner's identity. Corrupt/unreadable identity is fail-closed. */
|
|
1199
1200
|
private storeIdentityLocked;
|
|
1201
|
+
/** The pollution objects as the export's roster reads them: this store's own (`this.governance` is the File store over
|
|
1202
|
+
* `controlPlaneRoot`), through its damage-visible view ({@link standingControlObjectsOf}, the erasure's count reads the
|
|
1203
|
+
* same view) — a marker slot that stands as no object (a directory, a dangling link) is on the roster as its
|
|
1204
|
+
* fail-closed record, never dropped from a bundle (the reading adoption and the strays reader take). */
|
|
1205
|
+
private pollutionRosterObjects;
|
|
1200
1206
|
/** One consistency fingerprint over the three ENGINE governance faces (challenge ledger, lineage
|
|
1201
1207
|
* ledger, pollution markers) — raw bytes, journal included. The two strict sidecars' JOURNAL
|
|
1202
1208
|
* reads are wrapped FAIL-CLOSED here (§4-6): the shared strict reader folds a journal read
|
|
@@ -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";
|
|
@@ -624,6 +625,7 @@ export class FileMemoryEngineBackend {
|
|
|
624
625
|
this.assertRootAnchored();
|
|
625
626
|
ensureDirExists(dir);
|
|
626
627
|
ensureDirExists(this.controlPlaneRoot);
|
|
628
|
+
probeControlPlaneLinks(this.controlPlaneRoot);
|
|
627
629
|
this.recoverJournal({ unlocked: true });
|
|
628
630
|
try {
|
|
629
631
|
this.loadLedger();
|
|
@@ -913,7 +915,7 @@ export class FileMemoryEngineBackend {
|
|
|
913
915
|
chainDegradedMarkerPresent() {
|
|
914
916
|
return readControlFileOrAbsent(join(this.controlPlaneRoot, CHAIN_DEGRADED_FILE), "evidence-chain degradation marker") !== undefined;
|
|
915
917
|
}
|
|
916
|
-
mintChainDegradedMarker(
|
|
918
|
+
mintChainDegradedMarker(fragmentName) {
|
|
917
919
|
const path = join(this.controlPlaneRoot, CHAIN_DEGRADED_FILE);
|
|
918
920
|
let fd;
|
|
919
921
|
try {
|
|
@@ -927,7 +929,7 @@ export class FileMemoryEngineBackend {
|
|
|
927
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)`);
|
|
928
930
|
}
|
|
929
931
|
try {
|
|
930
|
-
writeAllSync(fd, `${JSON.stringify({ at: this.now(), ...(
|
|
932
|
+
writeAllSync(fd, `${JSON.stringify({ at: this.now(), ...(fragmentName !== undefined ? { fragment: fragmentName } : {}) }, null, 2)}\n`);
|
|
931
933
|
fsyncSync(fd);
|
|
932
934
|
}
|
|
933
935
|
finally {
|
|
@@ -993,17 +995,23 @@ export class FileMemoryEngineBackend {
|
|
|
993
995
|
const outOfBand = !journalHasPendingEvidence;
|
|
994
996
|
if (fenceToken !== undefined)
|
|
995
997
|
this.assertTxnLockOwnership(fenceToken);
|
|
996
|
-
let
|
|
998
|
+
let fragmentName;
|
|
997
999
|
try {
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
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
|
+
}
|
|
1001
1007
|
}
|
|
1002
1008
|
catch {
|
|
1003
|
-
|
|
1009
|
+
fragmentName = undefined;
|
|
1004
1010
|
}
|
|
1011
|
+
if (fragmentName === undefined)
|
|
1012
|
+
throw new ControlPlaneCorruptError(`transfer evidence log has a torn tail that could not be quarantined: ${path}`);
|
|
1005
1013
|
if (outOfBand)
|
|
1006
|
-
this.mintChainDegradedMarker(
|
|
1014
|
+
this.mintChainDegradedMarker(fragmentName);
|
|
1007
1015
|
this.chainHealProbe?.();
|
|
1008
1016
|
if (fenceToken !== undefined)
|
|
1009
1017
|
this.assertTxnLockOwnership(fenceToken);
|
|
@@ -1449,7 +1457,7 @@ export class FileMemoryEngineBackend {
|
|
|
1449
1457
|
}
|
|
1450
1458
|
containInboundReject(finding, absPath, text, entryId, committed) {
|
|
1451
1459
|
this.inboundFindings.push(finding);
|
|
1452
|
-
const q =
|
|
1460
|
+
const q = clearContainedPath(absPath, text, captureIntoFileQuarantine(this.controlPlaneRoot, absPath, text, this.now));
|
|
1453
1461
|
const shadowText = committed !== undefined ? this.readCommittedShadow(entryId) : undefined;
|
|
1454
1462
|
let restoredShadow = false;
|
|
1455
1463
|
if (shadowText !== undefined) {
|
|
@@ -2550,38 +2558,6 @@ export class FileMemoryEngineBackend {
|
|
|
2550
2558
|
if (row !== undefined)
|
|
2551
2559
|
recordErasureSweep(this.controlPlaneRoot, row.req, row.paths);
|
|
2552
2560
|
}
|
|
2553
|
-
eraseQuarantineCopiesLocked(ids) {
|
|
2554
|
-
const qDir = join(this.controlPlaneRoot, QUARANTINE_DIR);
|
|
2555
|
-
let names = [];
|
|
2556
|
-
try {
|
|
2557
|
-
names = readdirSync(qDir);
|
|
2558
|
-
}
|
|
2559
|
-
catch (err) {
|
|
2560
|
-
if (err.code !== "ENOENT") {
|
|
2561
|
-
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)`);
|
|
2562
|
-
}
|
|
2563
|
-
}
|
|
2564
|
-
const out = { removed: 0, remaining: 0, unattributed: 0 };
|
|
2565
|
-
for (const name of names.sort()) {
|
|
2566
|
-
const path = join(qDir, name);
|
|
2567
|
-
const text = readSafe(path);
|
|
2568
|
-
const qid = text === undefined ? undefined : parseEntryFile(text).id;
|
|
2569
|
-
if (qid === undefined) {
|
|
2570
|
-
out.unattributed++;
|
|
2571
|
-
continue;
|
|
2572
|
-
}
|
|
2573
|
-
if (!ids.has(qid))
|
|
2574
|
-
continue;
|
|
2575
|
-
try {
|
|
2576
|
-
rmSync(path, { force: true });
|
|
2577
|
-
out.removed++;
|
|
2578
|
-
}
|
|
2579
|
-
catch {
|
|
2580
|
-
out.remaining++;
|
|
2581
|
-
}
|
|
2582
|
-
}
|
|
2583
|
-
return out;
|
|
2584
|
-
}
|
|
2585
2561
|
controlDirHoldsAnything(name) {
|
|
2586
2562
|
try {
|
|
2587
2563
|
return readdirSync(join(this.controlPlaneRoot, name)).length > 0;
|
|
@@ -2830,7 +2806,7 @@ export class FileMemoryEngineBackend {
|
|
|
2830
2806
|
e.sessions = [...new Set([...e.sessions, ...lateSessions])].sort();
|
|
2831
2807
|
}
|
|
2832
2808
|
const resolvedSet = new Set(resolvedIds);
|
|
2833
|
-
const quarantine = this.
|
|
2809
|
+
const quarantine = await eraseQuarantineCopies(standingControlObjectsOf(this.governance), resolvedSet);
|
|
2834
2810
|
const att = {
|
|
2835
2811
|
v: 2,
|
|
2836
2812
|
requestId,
|
|
@@ -2850,7 +2826,7 @@ export class FileMemoryEngineBackend {
|
|
|
2850
2826
|
projection: { removed: erased.reduce((n, e) => n + e.projectionsRemoved, 0), remaining: 0 },
|
|
2851
2827
|
shadow: { removed: ops.filter((op) => op.kind === "shadow-delete").length, remaining: 0 },
|
|
2852
2828
|
indexLine: readErasureSweep(this.controlPlaneRoot, this.directoryRoot, requestId).length > 0 ? { unverified: true } : { removed: 0, remaining: 0 },
|
|
2853
|
-
quarantineCopy: { removed: quarantine.removed, remaining: quarantine.remaining },
|
|
2829
|
+
quarantineCopy: { removed: quarantine.removed, remaining: quarantine.remaining, unreadable: quarantine.unreadable },
|
|
2854
2830
|
planArchive: this.controlDirHoldsAnything(CONSOLIDATION_DRIVER_PLANS_DIR) ? { unverified: true } : { removed: 0, remaining: 0 },
|
|
2855
2831
|
planWorkbook: this.controlDirHoldsAnything(CONSOLIDATION_PLANS_DIR) ? { unverified: true } : { removed: 0, remaining: 0 },
|
|
2856
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 },
|
|
@@ -3139,6 +3115,9 @@ export class FileMemoryEngineBackend {
|
|
|
3139
3115
|
}
|
|
3140
3116
|
return storeId;
|
|
3141
3117
|
}
|
|
3118
|
+
pollutionRosterObjects() {
|
|
3119
|
+
return standingControlObjectsOf(this.governance);
|
|
3120
|
+
}
|
|
3142
3121
|
exportGovernanceFingerprint() {
|
|
3143
3122
|
const h = createHash("sha256");
|
|
3144
3123
|
const feed = (label, text) => {
|
|
@@ -3155,23 +3134,14 @@ export class FileMemoryEngineBackend {
|
|
|
3155
3134
|
}
|
|
3156
3135
|
feed(`${file}.journal`, journalRaw ?? "<absent>");
|
|
3157
3136
|
}
|
|
3158
|
-
const
|
|
3159
|
-
let names = [];
|
|
3160
|
-
try {
|
|
3161
|
-
names = readdirSync(dir).sort();
|
|
3162
|
-
}
|
|
3163
|
-
catch (err) {
|
|
3164
|
-
if (err.code !== "ENOENT") {
|
|
3165
|
-
throw new ControlPlaneCorruptError(`session pollution markers could not be enumerated for export (${err.code ?? "io error"}) at ${dir} — fail-closed`, { cause: err });
|
|
3166
|
-
}
|
|
3167
|
-
}
|
|
3168
|
-
for (const name of names) {
|
|
3137
|
+
for (const name of standingFileControlObjectNames(this.controlPlaneRoot, "pollution")) {
|
|
3169
3138
|
let text;
|
|
3170
3139
|
try {
|
|
3171
|
-
|
|
3140
|
+
const bytes = getFileControlObject(this.controlPlaneRoot, "pollution", name);
|
|
3141
|
+
text = bytes === undefined ? "<absent>" : new TextDecoder().decode(bytes);
|
|
3172
3142
|
}
|
|
3173
3143
|
catch (err) {
|
|
3174
|
-
text = `<unreadable:${err
|
|
3144
|
+
text = `<unreadable:${fileControlObjectFaultCode(err) ?? "io error"}>`;
|
|
3175
3145
|
}
|
|
3176
3146
|
feed(`pollution/${name}`, text);
|
|
3177
3147
|
}
|
|
@@ -3281,20 +3251,24 @@ export class FileMemoryEngineBackend {
|
|
|
3281
3251
|
return { custody, unsliceable };
|
|
3282
3252
|
}
|
|
3283
3253
|
enumerateQuarantineFor(ids) {
|
|
3284
|
-
|
|
3285
|
-
let names = [];
|
|
3254
|
+
let names;
|
|
3286
3255
|
try {
|
|
3287
|
-
names =
|
|
3256
|
+
names = standingFileControlObjectNames(this.controlPlaneRoot, "quarantine");
|
|
3288
3257
|
}
|
|
3289
3258
|
catch (err) {
|
|
3290
|
-
|
|
3291
|
-
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`);
|
|
3292
|
-
}
|
|
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 });
|
|
3293
3260
|
}
|
|
3294
3261
|
const quarantined = [];
|
|
3295
3262
|
let quarantineOpaque = 0;
|
|
3296
|
-
for (const name of names
|
|
3297
|
-
|
|
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
|
+
}
|
|
3298
3272
|
if (text === undefined) {
|
|
3299
3273
|
quarantineOpaque++;
|
|
3300
3274
|
continue;
|
|
@@ -3328,7 +3302,7 @@ export class FileMemoryEngineBackend {
|
|
|
3328
3302
|
const before = this.exportGovernanceFingerprint();
|
|
3329
3303
|
const lineageRec = await readLineageRecord(this.governance);
|
|
3330
3304
|
const challenges = await readChallengeEvents(this.governance);
|
|
3331
|
-
const polluted = listSessionPollution(this.
|
|
3305
|
+
const polluted = await listSessionPollution(this.pollutionRosterObjects());
|
|
3332
3306
|
const chainRows = this.readExportChainRowsPure();
|
|
3333
3307
|
await this.exportFaceProbe?.(round);
|
|
3334
3308
|
const after = this.exportGovernanceFingerprint();
|
|
@@ -3502,11 +3476,11 @@ export class FileMemoryEngineBackend {
|
|
|
3502
3476
|
this.recoverJournal({ token: lock.token });
|
|
3503
3477
|
this.adoptLayoutLocked(lock.token);
|
|
3504
3478
|
this.migrateLockedIfNeeded(lock.token);
|
|
3505
|
-
const ctl = this.controlPlaneRoot;
|
|
3506
3479
|
const txnId = importLatchTxnId(bundleHash);
|
|
3507
|
-
const
|
|
3508
|
-
const
|
|
3509
|
-
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);
|
|
3510
3484
|
let report;
|
|
3511
3485
|
try {
|
|
3512
3486
|
const parsed = JSON.parse(receiptRaw);
|
|
@@ -3542,9 +3516,9 @@ export class FileMemoryEngineBackend {
|
|
|
3542
3516
|
report = rep;
|
|
3543
3517
|
}
|
|
3544
3518
|
catch {
|
|
3545
|
-
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)`);
|
|
3546
3520
|
}
|
|
3547
|
-
await releaseImportLatch(this.governance,
|
|
3521
|
+
await releaseImportLatch(this.governance, txnId);
|
|
3548
3522
|
return report;
|
|
3549
3523
|
}
|
|
3550
3524
|
const digest = this.deletedIdsDigestLocked();
|
|
@@ -3668,39 +3642,15 @@ export class FileMemoryEngineBackend {
|
|
|
3668
3642
|
reason: `challenged: the contributing session was marked polluted`,
|
|
3669
3643
|
challengedRev: c.lastRev,
|
|
3670
3644
|
})));
|
|
3671
|
-
const outcome = importSessionPollution(
|
|
3645
|
+
const outcome = await importSessionPollution(this.governance, p.sessionId, { at: p.at, reason: p.reason, ...(p.cause !== undefined ? { cause: p.cause } : {}) });
|
|
3672
3646
|
if (outcome === "divergent")
|
|
3673
3647
|
report.pollutionDivergence.push({ sessionId: p.sessionId, kept: "destination" });
|
|
3674
3648
|
}
|
|
3675
|
-
|
|
3676
|
-
if (
|
|
3677
|
-
throw new ControlPlaneCorruptError(`bundle import completion receipt appeared mid-import
|
|
3678
|
-
}
|
|
3679
|
-
const staged = join(ctl, IMPORT_RECEIPTS_DIR, `.stage-${bundleHash}-${randomUUID().slice(0, 8)}`);
|
|
3680
|
-
const fd = openSync(staged, "wx", 0o600);
|
|
3681
|
-
try {
|
|
3682
|
-
writeAllSync(fd, `${JSON.stringify({ v: 1, bundleHash, at: this.now(), report }, null, 2)}\n`);
|
|
3683
|
-
fsyncSync(fd);
|
|
3684
|
-
}
|
|
3685
|
-
finally {
|
|
3686
|
-
closeSync(fd);
|
|
3687
|
-
}
|
|
3688
|
-
try {
|
|
3689
|
-
linkSync(staged, receiptPath);
|
|
3690
|
-
rmSync(staged, { force: true });
|
|
3691
|
-
}
|
|
3692
|
-
catch (err) {
|
|
3693
|
-
try {
|
|
3694
|
-
rmSync(staged, { force: true });
|
|
3695
|
-
}
|
|
3696
|
-
catch {
|
|
3697
|
-
}
|
|
3698
|
-
if (err.code === "EEXIST") {
|
|
3699
|
-
throw new ControlPlaneCorruptError(`bundle import completion receipt appeared mid-import at ${receiptPath} — refusing to overwrite it (fail-closed)`);
|
|
3700
|
-
}
|
|
3701
|
-
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)`);
|
|
3702
3652
|
}
|
|
3703
|
-
await releaseImportLatch(this.governance,
|
|
3653
|
+
await releaseImportLatch(this.governance, txnId);
|
|
3704
3654
|
return report;
|
|
3705
3655
|
}
|
|
3706
3656
|
catch (err) {
|