@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,8 +1,9 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { existsSync, linkSync, lstatSync, readFileSync, readdirSync, renameSync, unlinkSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
4
|
+
import { appendChallengeEvents, claimStaging, fileGovernanceDocOf, isSameFile, lockedStrictUpdate, mintStagingName, readStrictSidecar, stagingNamePattern, v1MemoryPathKeyResolver, lineageContributionsOfSession, markSessionPolluted, readProjectionDebts, readSessionPollution, putControlObjectOnce, ControlPlaneCorruptError } from "./layout.js";
|
|
5
5
|
import { thrownText } from "../thrown-value.js";
|
|
6
|
+
import { fileControlObjectDirOf, fileControlObjectFaultCode } from "./control-objects.js";
|
|
6
7
|
function reqStr(v) {
|
|
7
8
|
return typeof v === "string" && v.length > 0;
|
|
8
9
|
}
|
|
@@ -189,7 +190,7 @@ export async function expireOverdueSettlements(docs, input) {
|
|
|
189
190
|
await settleDelegation(docs, { settleId: s.row.settleId, status: "expired", now: input.now });
|
|
190
191
|
return overdue.map((s) => s.row.settleId);
|
|
191
192
|
}
|
|
192
|
-
export async function replayExternalSettlementEffects(docs,
|
|
193
|
+
export async function replayExternalSettlementEffects(docs, input) {
|
|
193
194
|
const applied = [];
|
|
194
195
|
const folded = (await effectiveSettlements(docs)).filter((s) => s.effective === "external" && s.terminalEventId !== undefined);
|
|
195
196
|
if (folded.length === 0)
|
|
@@ -199,7 +200,7 @@ export async function replayExternalSettlementEffects(docs, controlDir, input) {
|
|
|
199
200
|
if (rec.effects[s.row.settleId] === s.terminalEventId)
|
|
200
201
|
continue;
|
|
201
202
|
const sessionId = s.row.sessionId;
|
|
202
|
-
const outcome = markSessionPolluted(
|
|
203
|
+
const outcome = await markSessionPolluted(docs, sessionId, "a delegated child of this session settled external after launch (delegation settlement account)", input.now, "observed");
|
|
203
204
|
if (outcome === "unpersisted")
|
|
204
205
|
continue;
|
|
205
206
|
try {
|
|
@@ -298,7 +299,11 @@ function convertSessionAccounts(read, controlDir) {
|
|
|
298
299
|
}
|
|
299
300
|
export function convertV1SidecarKeys(controlDir) {
|
|
300
301
|
readProjectionDebts(controlDir);
|
|
301
|
-
|
|
302
|
+
const holds = readStrictSidecar(controlDir, HOLDS_FILE, HOLDS_WHAT);
|
|
303
|
+
if (holdsOnDiskAreV1(holds))
|
|
304
|
+
lockedStrictUpdate(controlDir, HOLDS_FILE, HOLDS_WHAT, coerceHolds, (again) => ({ next: again, result: undefined }));
|
|
305
|
+
else
|
|
306
|
+
coerceHolds(holds);
|
|
302
307
|
const accounts = fileGovernanceDocOf("session-accounts");
|
|
303
308
|
if (coerceSessionAccounts(readStrictSidecar(controlDir, accounts.file, accounts.what)).version !== 2) {
|
|
304
309
|
lockedStrictUpdate(controlDir, accounts.file, accounts.what, coerceSessionAccounts, (again) => {
|
|
@@ -428,8 +433,9 @@ export async function resolveSessionAccountRecord(docs, controlDir, input) {
|
|
|
428
433
|
return { next: rec, result: undefined };
|
|
429
434
|
});
|
|
430
435
|
}
|
|
431
|
-
export const HOLDS_FILE = "holds.
|
|
432
|
-
|
|
436
|
+
export const HOLDS_FILE = fileGovernanceDocOf("holds").file;
|
|
437
|
+
const HOLDS_WHAT = fileGovernanceDocOf("holds").what;
|
|
438
|
+
export const HOLD_DIR = fileControlObjectDirOf("hold");
|
|
433
439
|
const HOLD_STATUSES = new Set(["capturing", "held", "released", "disposed"]);
|
|
434
440
|
const HOLD_TERMINALS = new Set(["dirty", "expired", "conflict", "discarded", "capture_lost"]);
|
|
435
441
|
function coerceHolds(raw) {
|
|
@@ -482,11 +488,11 @@ function coerceHolds(raw) {
|
|
|
482
488
|
function holdsOnDiskAreV1(raw) {
|
|
483
489
|
return typeof raw === "object" && raw !== null && raw.version === 1;
|
|
484
490
|
}
|
|
485
|
-
export function readHolds(
|
|
486
|
-
const raw =
|
|
491
|
+
export async function readHolds(docs) {
|
|
492
|
+
const raw = await docs.readDoc("holds");
|
|
487
493
|
if (!holdsOnDiskAreV1(raw))
|
|
488
494
|
return coerceHolds(raw).rows;
|
|
489
|
-
return
|
|
495
|
+
return docs.updateDoc("holds", coerceHolds, (again) => ({ next: again, result: again.rows }));
|
|
490
496
|
}
|
|
491
497
|
function sha256(buf) {
|
|
492
498
|
return createHash("sha256").update(buf).digest("hex");
|
|
@@ -501,41 +507,56 @@ function dropStaging(claimedPath) {
|
|
|
501
507
|
export function stagingPathBeside(absPath, stagingName) {
|
|
502
508
|
return join(dirname(absPath), stagingName);
|
|
503
509
|
}
|
|
504
|
-
function
|
|
510
|
+
async function heldBytesAt(objects, kind, name, digest) {
|
|
511
|
+
let bytes;
|
|
505
512
|
try {
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
513
|
+
bytes = await objects.getObject(kind, name);
|
|
514
|
+
}
|
|
515
|
+
catch {
|
|
516
|
+
return "other";
|
|
517
|
+
}
|
|
518
|
+
if (bytes === undefined)
|
|
519
|
+
return "absent";
|
|
520
|
+
return sha256(Buffer.from(bytes)) === digest ? "holds" : "other";
|
|
521
|
+
}
|
|
522
|
+
async function holdCustodyVerified(objects, captureName, bytes) {
|
|
523
|
+
try {
|
|
524
|
+
await putControlObjectOnce(objects, "hold", captureName, bytes);
|
|
515
525
|
}
|
|
516
526
|
catch {
|
|
517
527
|
return false;
|
|
518
528
|
}
|
|
529
|
+
return (await heldBytesAt(objects, "hold", captureName, sha256(bytes))) === "holds";
|
|
519
530
|
}
|
|
520
|
-
export function
|
|
531
|
+
export async function retireStagingToObject(objects, claimedPath, kind, name, refusedAt) {
|
|
521
532
|
const unsettled = (why) => ({ settled: false, at: `${claimedPath} (${why})` });
|
|
522
533
|
let bytes;
|
|
523
534
|
try {
|
|
524
535
|
bytes = readFileSync(claimedPath);
|
|
525
|
-
ensureDirExists(custodyDir);
|
|
526
536
|
}
|
|
527
537
|
catch {
|
|
528
538
|
return unsettled("the staged bytes could not be read into the control plane");
|
|
529
539
|
}
|
|
530
|
-
|
|
540
|
+
try {
|
|
541
|
+
if ((await putControlObjectOnce(objects, kind, name, bytes)) !== "created")
|
|
542
|
+
return unsettled(`a control-plane ${kind} object named ${name} already stands`);
|
|
543
|
+
const back = await objects.getObject(kind, name);
|
|
544
|
+
if (back === undefined || sha256(Buffer.from(back)) !== sha256(bytes))
|
|
545
|
+
return unsettled("the control-plane custody copy could not be read back");
|
|
546
|
+
}
|
|
547
|
+
catch {
|
|
531
548
|
return unsettled("the control-plane custody copy could not be written");
|
|
549
|
+
}
|
|
550
|
+
const refused = refusedAt();
|
|
551
|
+
if (refused !== undefined)
|
|
552
|
+
return unsettled(`a copy reached the control plane; this one was not removed: ${refused}`);
|
|
532
553
|
try {
|
|
533
554
|
unlinkSync(claimedPath);
|
|
534
555
|
}
|
|
535
556
|
catch {
|
|
536
557
|
return unsettled("a copy reached the control plane; this one could not be removed");
|
|
537
558
|
}
|
|
538
|
-
return { settled: true, at: `${
|
|
559
|
+
return { settled: true, at: `${kind} object ${name} in the memory control plane` };
|
|
539
560
|
}
|
|
540
561
|
export function noReplaceRestore(stagingPath, destPath) {
|
|
541
562
|
try {
|
|
@@ -565,24 +586,23 @@ export function noReplaceRestore(stagingPath, destPath) {
|
|
|
565
586
|
}
|
|
566
587
|
return "restored";
|
|
567
588
|
}
|
|
568
|
-
export function openInstructionHold(
|
|
589
|
+
export async function openInstructionHold(store, input) {
|
|
569
590
|
const holdId = `hold-${input.now()}-${createHash("sha256").update(`${input.sessionId}\n${input.rel}\n${input.content}`).digest("hex").slice(0, 12)}`;
|
|
570
591
|
const buf = Buffer.from(input.content, "utf8");
|
|
571
592
|
const digest = sha256(buf);
|
|
572
593
|
const captureName = `${holdId}.md`;
|
|
573
|
-
const holdDir = join(controlDir, HOLD_DIR);
|
|
574
594
|
let thirdWriterStrandedAt;
|
|
575
|
-
const refuse = (rawReason, terminal) => {
|
|
595
|
+
const refuse = async (rawReason, terminal) => {
|
|
576
596
|
const reason = thirdWriterStrandedAt === undefined ? rawReason : `${rawReason}; a concurrent writer's bytes are preserved at ${thirdWriterStrandedAt}`;
|
|
577
597
|
try {
|
|
578
|
-
disposeHold(
|
|
598
|
+
await disposeHold(store, { holdId, terminal });
|
|
579
599
|
}
|
|
580
600
|
catch {
|
|
581
601
|
}
|
|
582
602
|
return { ok: false, holdId, reason };
|
|
583
603
|
};
|
|
584
604
|
try {
|
|
585
|
-
|
|
605
|
+
await store.updateDoc("holds", coerceHolds, (rec) => {
|
|
586
606
|
if (rec.rows.some((r) => r.holdId === holdId))
|
|
587
607
|
return { result: undefined };
|
|
588
608
|
rec.rows.push({
|
|
@@ -606,15 +626,12 @@ export function openInstructionHold(controlDir, input) {
|
|
|
606
626
|
catch (err) {
|
|
607
627
|
return { ok: false, reason: `hold ledger refused: ${thrownText(err)}` };
|
|
608
628
|
}
|
|
609
|
-
|
|
610
|
-
ensureDirExists(holdDir);
|
|
611
|
-
}
|
|
612
|
-
catch (err) {
|
|
613
|
-
return refuse(`hold capture failed: ${thrownText(err)}`, "capture_lost");
|
|
614
|
-
}
|
|
615
|
-
if (!writeCustodyVerified(join(holdDir, captureName), buf)) {
|
|
629
|
+
if (!(await holdCustodyVerified(store, captureName, buf))) {
|
|
616
630
|
return refuse("hold capture verification failed (the custody copy could not be written, made durable, or hashed back to the captured digest)", "capture_lost");
|
|
617
631
|
}
|
|
632
|
+
const refused = input.actRefused(input.absPath, "holding an instruction-form file");
|
|
633
|
+
if (refused !== undefined)
|
|
634
|
+
return refuse(`hold removal refused: ${refused}`, "discarded");
|
|
618
635
|
const stagingName = mintStagingName(holdId, input.now);
|
|
619
636
|
const stagingPath = stagingPathBeside(input.absPath, stagingName);
|
|
620
637
|
try {
|
|
@@ -637,14 +654,14 @@ export function openInstructionHold(controlDir, input) {
|
|
|
637
654
|
else {
|
|
638
655
|
const restore = noReplaceRestore(claimedPath, input.absPath);
|
|
639
656
|
if (restore !== "restored") {
|
|
640
|
-
const retired =
|
|
657
|
+
const retired = await retireStagingToObject(store, claimedPath, "hold", stagingName, () => input.actRefused(claimedPath, "removing a hold's staged copy"));
|
|
641
658
|
if (restore === "stranded" || !retired.settled)
|
|
642
659
|
thirdWriterStrandedAt = retired.at;
|
|
643
660
|
}
|
|
644
661
|
}
|
|
645
662
|
}
|
|
646
663
|
try {
|
|
647
|
-
|
|
664
|
+
await store.updateDoc("holds", coerceHolds, (rec) => {
|
|
648
665
|
const row = rec.rows.find((r) => r.holdId === holdId);
|
|
649
666
|
if (row === undefined || row.status !== "capturing")
|
|
650
667
|
return { result: undefined };
|
|
@@ -657,12 +674,14 @@ export function openInstructionHold(controlDir, input) {
|
|
|
657
674
|
}
|
|
658
675
|
return { ok: true, holdId, ...(thirdWriterStrandedAt !== undefined ? { thirdWriterStrandedAt } : {}) };
|
|
659
676
|
}
|
|
660
|
-
export function reconcileHolds(
|
|
661
|
-
const holdDir = join(controlDir, HOLD_DIR);
|
|
677
|
+
export async function reconcileHolds(store, input) {
|
|
662
678
|
const discloseStranded = (holdId, scope, rel, at) => {
|
|
663
679
|
input.onStranded(scope, `instruction hold ${holdId}: a concurrent writer's bytes for ${JSON.stringify(rel)} could not be restored onto the plane — they are preserved at ${at} for host recovery`);
|
|
664
680
|
};
|
|
665
|
-
const finishRemoval = (row, plane) => {
|
|
681
|
+
const finishRemoval = async (row, plane) => {
|
|
682
|
+
const refused = input.actRefused(plane, "removing a held file from the plane");
|
|
683
|
+
if (refused !== undefined)
|
|
684
|
+
throw new Error(refused);
|
|
666
685
|
const stagingName = mintStagingName(row.holdId, input.now);
|
|
667
686
|
renameSync(plane, stagingPathBeside(plane, stagingName));
|
|
668
687
|
const staging = claimStaging(stagingPathBeside(plane, stagingName));
|
|
@@ -673,7 +692,7 @@ export function reconcileHolds(controlDir, input) {
|
|
|
673
692
|
const restore = noReplaceRestore(staging, plane);
|
|
674
693
|
if (restore === "restored")
|
|
675
694
|
return;
|
|
676
|
-
const retired =
|
|
695
|
+
const retired = await retireStagingToObject(store, staging, "hold", stagingName, () => input.actRefused(staging, "removing a hold's staged copy"));
|
|
677
696
|
if (restore === "stranded" || !retired.settled)
|
|
678
697
|
discloseStranded(row.holdId, row.scope, row.rel, retired.at);
|
|
679
698
|
};
|
|
@@ -692,7 +711,7 @@ export function reconcileHolds(controlDir, input) {
|
|
|
692
711
|
seatListing.set(seatDir, names);
|
|
693
712
|
return names;
|
|
694
713
|
};
|
|
695
|
-
const sweepStagingGenerations = (row, plane, custody) => {
|
|
714
|
+
const sweepStagingGenerations = async (row, plane, custody) => {
|
|
696
715
|
const seatDir = dirname(plane);
|
|
697
716
|
const pattern = stagingNamePattern(row.holdId);
|
|
698
717
|
let seat;
|
|
@@ -705,6 +724,8 @@ export function reconcileHolds(controlDir, input) {
|
|
|
705
724
|
for (const name of listSeat(seatDir)) {
|
|
706
725
|
if (!pattern.test(name))
|
|
707
726
|
continue;
|
|
727
|
+
if (input.actRefused(join(seatDir, name), "recovering a hold's staged copy") !== undefined)
|
|
728
|
+
continue;
|
|
708
729
|
const staged = claimStaging(join(seatDir, name));
|
|
709
730
|
let bytes;
|
|
710
731
|
try {
|
|
@@ -716,47 +737,44 @@ export function reconcileHolds(controlDir, input) {
|
|
|
716
737
|
continue;
|
|
717
738
|
}
|
|
718
739
|
if (sha256(bytes) === row.contentDigest) {
|
|
719
|
-
if (custody === "holds"
|
|
740
|
+
if (custody === "holds") {
|
|
720
741
|
dropStaging(staged);
|
|
721
742
|
continue;
|
|
722
743
|
}
|
|
744
|
+
if (custody === "absent" && (await holdCustodyVerified(store, row.captureName, bytes))) {
|
|
745
|
+
if (input.actRefused(staged, "recovering a hold's staged copy") === undefined)
|
|
746
|
+
dropStaging(staged);
|
|
747
|
+
continue;
|
|
748
|
+
}
|
|
723
749
|
}
|
|
724
750
|
const onSeat = seat !== undefined && isSameFile(staged, seat);
|
|
725
|
-
const retired =
|
|
751
|
+
const retired = await retireStagingToObject(store, staged, "hold", name, () => input.actRefused(staged, "removing a hold's staged copy"));
|
|
726
752
|
if (!(onSeat && retired.settled && isSameFile(plane, seat)))
|
|
727
753
|
discloseStranded(row.holdId, row.scope, row.rel, retired.at);
|
|
728
754
|
}
|
|
729
755
|
};
|
|
730
|
-
const
|
|
756
|
+
const ledger = await readHolds(store);
|
|
757
|
+
const rows = ledger.filter((r) => r.status === "capturing");
|
|
731
758
|
for (const row of rows) {
|
|
732
|
-
|
|
733
|
-
let custodyBytes;
|
|
759
|
+
let custodyState = await heldBytesAt(store, "hold", row.captureName, row.contentDigest);
|
|
734
760
|
try {
|
|
735
|
-
|
|
736
|
-
}
|
|
737
|
-
catch {
|
|
738
|
-
custodyBytes = undefined;
|
|
739
|
-
}
|
|
740
|
-
const custodyState = custodyBytes === undefined ? "absent" : sha256(custodyBytes) === row.contentDigest ? "holds" : "mismatch";
|
|
741
|
-
try {
|
|
742
|
-
sweepStagingGenerations(row, join(input.homeOf(row.scope), row.rel), custodyState);
|
|
761
|
+
await sweepStagingGenerations(row, join(input.homeOf(row.scope), row.rel), custodyState);
|
|
743
762
|
}
|
|
744
763
|
catch {
|
|
745
764
|
}
|
|
765
|
+
if (custodyState === "absent")
|
|
766
|
+
custodyState = await heldBytesAt(store, "hold", row.captureName, row.contentDigest);
|
|
746
767
|
let terminalLost = false;
|
|
747
|
-
if (
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
}
|
|
758
|
-
catch {
|
|
759
|
-
}
|
|
768
|
+
if (custodyState === "other") {
|
|
769
|
+
terminalLost = true;
|
|
770
|
+
}
|
|
771
|
+
else if (custodyState === "holds") {
|
|
772
|
+
const plane = join(input.homeOf(row.scope), row.rel);
|
|
773
|
+
if (existsSync(plane)) {
|
|
774
|
+
try {
|
|
775
|
+
await finishRemoval(row, plane);
|
|
776
|
+
}
|
|
777
|
+
catch {
|
|
760
778
|
}
|
|
761
779
|
}
|
|
762
780
|
}
|
|
@@ -766,10 +784,9 @@ export function reconcileHolds(controlDir, input) {
|
|
|
766
784
|
const bytes = readFileSync(plane);
|
|
767
785
|
if (sha256(bytes) === row.contentDigest) {
|
|
768
786
|
try {
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
finishRemoval(row, plane);
|
|
787
|
+
if (!(await holdCustodyVerified(store, row.captureName, bytes)))
|
|
788
|
+
throw new Error("the custody copy could not be written or read back");
|
|
789
|
+
await finishRemoval(row, plane);
|
|
773
790
|
}
|
|
774
791
|
catch {
|
|
775
792
|
terminalLost = true;
|
|
@@ -783,7 +800,7 @@ export function reconcileHolds(controlDir, input) {
|
|
|
783
800
|
terminalLost = true;
|
|
784
801
|
}
|
|
785
802
|
}
|
|
786
|
-
|
|
803
|
+
await store.updateDoc("holds", coerceHolds, (rec) => {
|
|
787
804
|
const r = rec.rows.find((x) => x.holdId === row.holdId);
|
|
788
805
|
if (r === undefined || r.status !== "capturing")
|
|
789
806
|
return { result: undefined };
|
|
@@ -797,36 +814,183 @@ export function reconcileHolds(controlDir, input) {
|
|
|
797
814
|
return { next: rec, result: undefined };
|
|
798
815
|
});
|
|
799
816
|
}
|
|
817
|
+
let custodyNames;
|
|
818
|
+
try {
|
|
819
|
+
custodyNames = new Set(await store.listObjects("hold"));
|
|
820
|
+
}
|
|
821
|
+
catch {
|
|
822
|
+
custodyNames = new Set();
|
|
823
|
+
}
|
|
824
|
+
for (const row of ledger) {
|
|
825
|
+
const quarantineName = row.disposition?.quarantineName;
|
|
826
|
+
if (row.status !== "disposed" || quarantineName === undefined || !custodyNames.has(row.captureName))
|
|
827
|
+
continue;
|
|
828
|
+
try {
|
|
829
|
+
const moved = await moveCustodyToSeat(store, row, quarantineName);
|
|
830
|
+
if (moved.at === "custody") {
|
|
831
|
+
input.onStranded(row.scope, `instruction hold ${row.holdId} (disposed, ${row.disposition.terminal}): its custody bytes could not be moved to the quarantine seat ${quarantineName} (${moved.code}) — they stay at the custody seat (hold object ${row.captureName} in the memory control plane) for host recovery, and the move is retried at every harvest`);
|
|
832
|
+
}
|
|
833
|
+
}
|
|
834
|
+
catch (err) {
|
|
835
|
+
input.onStranded(row.scope, `instruction hold ${row.holdId} (disposed, ${row.disposition.terminal}): ${thrownText(err)}`);
|
|
836
|
+
}
|
|
837
|
+
}
|
|
838
|
+
await adoptOrphanedQuarantineBytes(store, ledger);
|
|
800
839
|
}
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
const row = rows.find((r) => r.holdId === input.holdId);
|
|
804
|
-
if (row === undefined || row.status === "disposed" || row.status === "released")
|
|
805
|
-
return { ok: false };
|
|
806
|
-
const custody = join(controlDir, HOLD_DIR, row.captureName);
|
|
807
|
-
const quarantineName = `${input.now()}-hold-${row.captureName}`;
|
|
808
|
-
const qDir = join(controlDir, QUARANTINE_DIR);
|
|
809
|
-
let moved = false;
|
|
840
|
+
async function adoptOrphanedQuarantineBytes(store, snapshot) {
|
|
841
|
+
let listing;
|
|
810
842
|
try {
|
|
811
|
-
|
|
812
|
-
renameSync(custody, join(qDir, quarantineName));
|
|
813
|
-
moved = true;
|
|
843
|
+
listing = (await store.listObjects("quarantine")).filter((n) => n.includes("-hold-") && safeBasename(n));
|
|
814
844
|
}
|
|
815
845
|
catch {
|
|
816
|
-
|
|
846
|
+
return;
|
|
817
847
|
}
|
|
818
|
-
|
|
848
|
+
const seats = new Set();
|
|
849
|
+
for (const r of snapshot)
|
|
850
|
+
if (r.disposition?.quarantineName !== undefined)
|
|
851
|
+
seats.add(r.disposition.quarantineName);
|
|
852
|
+
if (listing.every((n) => seats.has(n)))
|
|
853
|
+
return;
|
|
854
|
+
const standsAt = async (kind, name) => {
|
|
855
|
+
try {
|
|
856
|
+
return (await store.getObject(kind, name)) !== undefined;
|
|
857
|
+
}
|
|
858
|
+
catch {
|
|
859
|
+
return true;
|
|
860
|
+
}
|
|
861
|
+
};
|
|
862
|
+
const digests = new Map();
|
|
863
|
+
for (const n of listing) {
|
|
864
|
+
if (seats.has(n))
|
|
865
|
+
continue;
|
|
866
|
+
try {
|
|
867
|
+
const bytes = await store.getObject("quarantine", n);
|
|
868
|
+
digests.set(n, bytes === undefined ? undefined : sha256(Buffer.from(bytes)));
|
|
869
|
+
}
|
|
870
|
+
catch {
|
|
871
|
+
digests.set(n, undefined);
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
const custodyStands = new Map();
|
|
875
|
+
const seatStands = new Map();
|
|
876
|
+
for (const r of snapshot) {
|
|
877
|
+
custodyStands.set(r.holdId, await standsAt("hold", r.captureName));
|
|
878
|
+
const seat = r.disposition?.quarantineName;
|
|
879
|
+
if (seat !== undefined && !seatStands.has(seat))
|
|
880
|
+
seatStands.set(seat, await standsAt("quarantine", seat));
|
|
881
|
+
}
|
|
882
|
+
const moves = await store.updateDoc("holds", coerceHolds, (rec) => {
|
|
883
|
+
const claimed = new Set();
|
|
884
|
+
for (const r of rec.rows)
|
|
885
|
+
if (r.disposition?.quarantineName !== undefined)
|
|
886
|
+
claimed.add(r.disposition.quarantineName);
|
|
887
|
+
const digestOf = (name) => digests.get(name);
|
|
888
|
+
const wants = (r) => {
|
|
889
|
+
const custody = custodyStands.get(r.holdId);
|
|
890
|
+
if (custody !== false)
|
|
891
|
+
return false;
|
|
892
|
+
if (r.status === "held")
|
|
893
|
+
return true;
|
|
894
|
+
if (r.status !== "disposed")
|
|
895
|
+
return false;
|
|
896
|
+
const seat = r.disposition?.quarantineName;
|
|
897
|
+
return seat === undefined || seatStands.get(seat) === false;
|
|
898
|
+
};
|
|
899
|
+
const endsWithCapture = (name, r) => name.endsWith(`-hold-${r.captureName}`);
|
|
900
|
+
const reservedForOther = (name) => rec.rows.some((r) => endsWithCapture(name, r));
|
|
901
|
+
const wanting = rec.rows.filter(wants);
|
|
902
|
+
const found = new Map();
|
|
903
|
+
for (const r of wanting) {
|
|
904
|
+
const f = listing.find((n) => !claimed.has(n) && endsWithCapture(n, r) && digestOf(n) === r.contentDigest);
|
|
905
|
+
if (f !== undefined) {
|
|
906
|
+
found.set(r, f);
|
|
907
|
+
claimed.add(f);
|
|
908
|
+
}
|
|
909
|
+
}
|
|
910
|
+
for (const r of wanting) {
|
|
911
|
+
if (found.has(r))
|
|
912
|
+
continue;
|
|
913
|
+
const f = listing.find((n) => !claimed.has(n) && !reservedForOther(n) && digestOf(n) === r.contentDigest);
|
|
914
|
+
if (f !== undefined) {
|
|
915
|
+
found.set(r, f);
|
|
916
|
+
claimed.add(f);
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
let changed = false;
|
|
920
|
+
const back = [];
|
|
921
|
+
for (const [r, f] of found) {
|
|
922
|
+
if (r.status === "disposed") {
|
|
923
|
+
r.disposition = { ...r.disposition, quarantineName: f };
|
|
924
|
+
changed = true;
|
|
925
|
+
continue;
|
|
926
|
+
}
|
|
927
|
+
back.push({ file: f, captureName: r.captureName });
|
|
928
|
+
}
|
|
929
|
+
return changed ? { next: rec, result: back } : { result: back };
|
|
930
|
+
});
|
|
931
|
+
for (const m of moves) {
|
|
932
|
+
try {
|
|
933
|
+
await store.moveObject({ kind: "quarantine", name: m.file }, { kind: "hold", name: m.captureName });
|
|
934
|
+
}
|
|
935
|
+
catch {
|
|
936
|
+
}
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
export function holdQuarantineNameOf(row) {
|
|
940
|
+
return `${row.contentDigest.slice(0, 16)}-hold-${row.captureName}`;
|
|
941
|
+
}
|
|
942
|
+
function foreignSeatRefusal(holdId, seatName) {
|
|
943
|
+
return new ControlPlaneCorruptError(`memory instruction hold ${holdId}: the quarantine seat ${seatName} is occupied by something that is not the hold's captured bytes — refusing to replace or adopt it (fail-closed; inspect or remove it, and the next harvest converges)`);
|
|
944
|
+
}
|
|
945
|
+
async function moveCustodyToSeat(objects, row, seatName) {
|
|
946
|
+
if ((await heldBytesAt(objects, "quarantine", seatName, row.contentDigest)) === "other")
|
|
947
|
+
throw foreignSeatRefusal(row.holdId, seatName);
|
|
948
|
+
try {
|
|
949
|
+
await objects.moveObject({ kind: "hold", name: row.captureName }, { kind: "quarantine", name: seatName });
|
|
950
|
+
return { at: "seat" };
|
|
951
|
+
}
|
|
952
|
+
catch (err) {
|
|
953
|
+
const seat = await heldBytesAt(objects, "quarantine", seatName, row.contentDigest);
|
|
954
|
+
if (seat === "other")
|
|
955
|
+
throw foreignSeatRefusal(row.holdId, seatName);
|
|
956
|
+
const custody = await heldBytesAt(objects, "hold", row.captureName, row.contentDigest);
|
|
957
|
+
if (custody === "absent")
|
|
958
|
+
return seat === "holds" ? { at: "seat" } : { at: "none" };
|
|
959
|
+
if (seat === "holds" && custody === "other")
|
|
960
|
+
return { at: "seat" };
|
|
961
|
+
return { at: "custody", code: fileControlObjectFaultCode(err) ?? "move refused" };
|
|
962
|
+
}
|
|
963
|
+
}
|
|
964
|
+
export async function disposeHold(store, input) {
|
|
965
|
+
const row = (await readHolds(store)).find((r) => r.holdId === input.holdId);
|
|
966
|
+
if (row === undefined || row.status === "disposed" || row.status === "released")
|
|
967
|
+
return { ok: false };
|
|
968
|
+
const quarantineName = holdQuarantineNameOf(row);
|
|
969
|
+
if (!safeBasename(quarantineName)) {
|
|
970
|
+
throw new ControlPlaneCorruptError(`memory instruction hold ${row.holdId}: its digest and capture name do not make a safe quarantine file name — refusing (fail-closed)`);
|
|
971
|
+
}
|
|
972
|
+
const custodyHere = (await heldBytesAt(store, "hold", row.captureName, row.contentDigest)) !== "absent";
|
|
973
|
+
const seatState = await heldBytesAt(store, "quarantine", quarantineName, row.contentDigest);
|
|
974
|
+
const verdict = await store.updateDoc("holds", coerceHolds, (rec) => {
|
|
819
975
|
const r = rec.rows.find((x) => x.holdId === input.holdId);
|
|
820
976
|
if (r === undefined || r.status === "disposed" || r.status === "released")
|
|
821
977
|
return { result: undefined };
|
|
978
|
+
const named = seatState === "holds" || (custodyHere && seatState === "absent");
|
|
822
979
|
r.status = "disposed";
|
|
823
|
-
r.disposition = { terminal: input.terminal, ...(
|
|
824
|
-
return { next: rec, result:
|
|
980
|
+
r.disposition = { terminal: input.terminal, ...(named ? { quarantineName } : {}) };
|
|
981
|
+
return { next: rec, result: { named, refused: custodyHere && seatState === "other" } };
|
|
825
982
|
});
|
|
826
|
-
|
|
983
|
+
if (verdict === undefined)
|
|
984
|
+
return { ok: false };
|
|
985
|
+
if (verdict.refused)
|
|
986
|
+
throw foreignSeatRefusal(row.holdId, quarantineName);
|
|
987
|
+
if (!verdict.named)
|
|
988
|
+
return { ok: true };
|
|
989
|
+
const moved = await moveCustodyToSeat(store, row, quarantineName);
|
|
990
|
+
return { ok: true, ...(moved.at === "seat" ? { quarantineName } : {}) };
|
|
827
991
|
}
|
|
828
|
-
export function markHoldReleased(
|
|
829
|
-
const captureName =
|
|
992
|
+
export async function markHoldReleased(store, input) {
|
|
993
|
+
const captureName = await store.updateDoc("holds", coerceHolds, (rec) => {
|
|
830
994
|
const r = rec.rows.find((x) => x.holdId === input.holdId);
|
|
831
995
|
if (r === undefined || (r.status !== "held" && !(r.status === "disposed" && r.disposition?.terminal === "expired")))
|
|
832
996
|
return { result: undefined };
|
|
@@ -838,12 +1002,12 @@ export function markHoldReleased(controlDir, input) {
|
|
|
838
1002
|
if (captureName === undefined)
|
|
839
1003
|
return;
|
|
840
1004
|
try {
|
|
841
|
-
|
|
1005
|
+
await store.deleteObject("hold", captureName);
|
|
842
1006
|
}
|
|
843
1007
|
catch {
|
|
844
1008
|
}
|
|
845
1009
|
}
|
|
846
|
-
export function resolveHoldRecord(
|
|
1010
|
+
export async function resolveHoldRecord(docs, input) {
|
|
847
1011
|
if (typeof input.requestId !== "string" || input.requestId.length === 0) {
|
|
848
1012
|
const e = new Error("resolveHold requires a non-empty requestId (the audit attribution of who resolved) — refused, never defaulted.");
|
|
849
1013
|
e.code = "memory.hold_resolve_unattributed";
|
|
@@ -854,7 +1018,7 @@ export function resolveHoldRecord(controlDir, input) {
|
|
|
854
1018
|
e.code = "memory.hold_resolve_invalid";
|
|
855
1019
|
throw e;
|
|
856
1020
|
}
|
|
857
|
-
|
|
1021
|
+
await docs.updateDoc("holds", coerceHolds, (rec) => {
|
|
858
1022
|
const r = rec.rows.find((x) => x.holdId === input.holdId);
|
|
859
1023
|
if (r === undefined) {
|
|
860
1024
|
const e = new Error(`resolveHold: unknown holdId ${JSON.stringify(input.holdId)}`);
|
|
@@ -877,8 +1041,8 @@ export function resolveHoldRecord(controlDir, input) {
|
|
|
877
1041
|
return { next: rec, result: undefined };
|
|
878
1042
|
});
|
|
879
1043
|
}
|
|
880
|
-
export function clearHoldResolution(
|
|
881
|
-
|
|
1044
|
+
export async function clearHoldResolution(docs, input) {
|
|
1045
|
+
await docs.updateDoc("holds", coerceHolds, (rec) => {
|
|
882
1046
|
const r = rec.rows.find((x) => x.holdId === input.holdId);
|
|
883
1047
|
if (r === undefined || r.resolved === undefined || r.resolvedAt !== input.ifResolvedAt)
|
|
884
1048
|
return { result: undefined };
|
|
@@ -887,21 +1051,21 @@ export function clearHoldResolution(controlDir, input) {
|
|
|
887
1051
|
return { next: rec, result: undefined };
|
|
888
1052
|
});
|
|
889
1053
|
}
|
|
890
|
-
export function readHoldCustody(
|
|
891
|
-
const seats = [
|
|
892
|
-
for (const
|
|
1054
|
+
export async function readHoldCustody(objects, row) {
|
|
1055
|
+
const seats = [["hold", row.captureName], ...(row.disposition?.quarantineName !== undefined ? [["quarantine", row.disposition.quarantineName]] : [])];
|
|
1056
|
+
for (const [kind, name] of seats) {
|
|
893
1057
|
try {
|
|
894
|
-
const bytes =
|
|
895
|
-
if (sha256(bytes) === row.contentDigest)
|
|
896
|
-
return bytes.toString("utf8");
|
|
1058
|
+
const bytes = await objects.getObject(kind, name);
|
|
1059
|
+
if (bytes !== undefined && sha256(Buffer.from(bytes)) === row.contentDigest)
|
|
1060
|
+
return Buffer.from(bytes).toString("utf8");
|
|
897
1061
|
}
|
|
898
1062
|
catch {
|
|
899
1063
|
}
|
|
900
1064
|
}
|
|
901
1065
|
return undefined;
|
|
902
1066
|
}
|
|
903
|
-
export async function sessionBlocksCleanRelease(docs,
|
|
904
|
-
if (readSessionPollution(
|
|
1067
|
+
export async function sessionBlocksCleanRelease(docs, sessionId) {
|
|
1068
|
+
if ((await readSessionPollution(docs, sessionId)) !== undefined)
|
|
905
1069
|
return true;
|
|
906
1070
|
return (await sessionSettlements(docs, sessionId)).some((s) => s.effective !== "clean" && s.effective !== "void");
|
|
907
1071
|
}
|
|
@@ -118,8 +118,9 @@ export declare function mergeHarvestReports(a: HarvestReport, b: HarvestReport):
|
|
|
118
118
|
* otherwise, and carries `historyUnknown` when either store that resolved it could not judge its history;
|
|
119
119
|
* - `evidenceCapability` is `"journal"` only when both are; `custodyState` is the worse of the two
|
|
120
120
|
* (`damaged` ≻ `capability-absent` ≻ `complete`);
|
|
121
|
-
* - each carrier class adds `removed` / `remaining
|
|
122
|
-
* missing); `quarantineUnattributed` / `derivedEntries` add their
|
|
121
|
+
* - each carrier class adds `removed` / `remaining` (and `unreadable` when both stores answer it), and is
|
|
122
|
+
* `unverified` when either store's answer is (or is missing); `quarantineUnattributed` / `derivedEntries` add their
|
|
123
|
+
* counts the same way; `replay` is
|
|
123
124
|
* `"converges"` only when both are; `propagation` stays `"local-store-only"` (every store merged is local).
|
|
124
125
|
*/
|
|
125
126
|
export declare function mergeErasureAttestations(a: MemoryErasureAttestation, b: MemoryErasureAttestation): MemoryErasureAttestation;
|
|
@@ -89,14 +89,14 @@ export function mergeInjections(project, personal) {
|
|
|
89
89
|
const indexParts = [project.index, personal.index].filter((s) => Boolean(s && s.trim()));
|
|
90
90
|
const announcements = [...(project.announcements ?? []), ...(personal.announcements ?? [])];
|
|
91
91
|
const announceParts = [project.announceBlock, personal.announceBlock].filter((s) => Boolean(s && s.trim()));
|
|
92
|
-
const blockParts = [instruction || readOnlyNotice, ...indexParts
|
|
92
|
+
const blockParts = [instruction || readOnlyNotice, ...indexParts];
|
|
93
93
|
const indexSeed = project.indexSeed ?? personal.indexSeed;
|
|
94
94
|
return {
|
|
95
95
|
instruction,
|
|
96
96
|
...(readOnlyNotice !== undefined ? { readOnlyNotice } : {}),
|
|
97
97
|
...(indexParts.length > 0 ? { index: indexParts.join("\n\n") } : {}),
|
|
98
98
|
...(announcements.length > 0 ? { announcements } : {}),
|
|
99
|
-
...(announceParts.length > 0 ? { announceBlock: announceParts.join("\n
|
|
99
|
+
...(announceParts.length > 0 ? { announceBlock: announceParts.join("\n") } : {}),
|
|
100
100
|
...(indexSeed !== undefined ? { indexSeed } : {}),
|
|
101
101
|
block: blockParts.filter((s) => s && s.trim()).join("\n\n"),
|
|
102
102
|
};
|
|
@@ -161,7 +161,11 @@ export function mergeErasureAttestations(a, b) {
|
|
|
161
161
|
notFound.set(row.id, unknown ? { id: row.id, historyUnknown: true } : { id: row.id });
|
|
162
162
|
}
|
|
163
163
|
const answered = (x) => typeof x === "object" && x !== null && typeof x.removed === "number" && typeof x.remaining === "number";
|
|
164
|
-
const
|
|
164
|
+
const unreadable = (x, y) => {
|
|
165
|
+
const [p, q] = [Reflect.get(x, "unreadable"), Reflect.get(y, "unreadable")];
|
|
166
|
+
return typeof p === "number" && typeof q === "number" ? { unreadable: p + q } : {};
|
|
167
|
+
};
|
|
168
|
+
const carrier = (x, y) => (answered(x) && answered(y) ? { removed: x.removed + y.removed, remaining: x.remaining + y.remaining, ...unreadable(x, y) } : { unverified: true });
|
|
165
169
|
const counted = (x) => typeof x === "object" && x !== null && typeof x.count === "number";
|
|
166
170
|
const count = (x, y) => (counted(x) && counted(y) ? { count: x.count + y.count } : { unverified: true });
|
|
167
171
|
const custodyRank = { complete: 0, "capability-absent": 1, damaged: 2 };
|