@sema-agent/core 7.61.0 → 7.63.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +840 -0
- package/dist/agents/cascade.d.ts +11 -3
- package/dist/agents/cascade.js +1 -1
- package/dist/agents/peer-held-queue.d.ts +27 -4
- package/dist/agents/peer-held-queue.js +81 -36
- package/dist/agents/peer-session-drain.js +13 -3
- package/dist/agents/subagent-transcript-placement.d.ts +23 -0
- package/dist/agents/subagent-transcript-placement.js +14 -0
- package/dist/agents/subagent.d.ts +6 -1
- package/dist/agents/subagent.js +143 -58
- package/dist/agents/suspend-guard.d.ts +38 -16
- package/dist/agents/suspend-guard.js +9 -4
- package/dist/agents/verify.js +4 -3
- package/dist/brain/route-adjudicator.js +9 -4
- package/dist/core/approval-object.js +1 -1
- package/dist/core/arg-summary.js +1 -1
- package/dist/core/ask-question.d.ts +2 -2
- package/dist/core/canonical-json.d.ts +23 -13
- package/dist/core/canonical-json.js +4 -4
- package/dist/core/checkpoint-features.d.ts +722 -0
- package/dist/core/checkpoint-features.js +98 -0
- package/dist/core/checkpoint-queries.d.ts +47 -4
- package/dist/core/checkpoint-queries.js +36 -16
- package/dist/core/checkpoint-requirements.d.ts +12 -5
- package/dist/core/checkpoint-requirements.js +11 -5
- package/dist/core/checkpoint-row-verdict.d.ts +110 -0
- package/dist/core/checkpoint-row-verdict.js +245 -0
- package/dist/core/checkpoint-store.d.ts +76 -753
- package/dist/core/checkpoint-store.js +83 -144
- package/dist/core/compliance.d.ts +6 -2
- package/dist/core/compliance.js +3 -3
- package/dist/core/engine-attestation.d.ts +1 -1
- package/dist/core/engine-notice.d.ts +38 -7
- package/dist/core/engine-notice.js +9 -2
- package/dist/core/gate-fold.js +2 -2
- package/dist/core/git-worktree-env.d.ts +62 -3
- package/dist/core/git-worktree-env.js +91 -30
- package/dist/core/governance-codes.d.ts +9 -3
- package/dist/core/governance-codes.js +16 -3
- package/dist/core/hooks.d.ts +13 -0
- package/dist/core/human-input-projection.d.ts +1 -0
- package/dist/core/human-input-projection.js +3 -0
- package/dist/core/image-admission.d.ts +1 -1
- package/dist/core/locked-config.d.ts +2 -2
- package/dist/core/mcp-host-seat.js +6 -1
- package/dist/core/memory-engine/consolidation-driver.d.ts +33 -18
- package/dist/core/memory-engine/consolidation-driver.js +99 -98
- package/dist/core/memory-engine/consolidation.d.ts +73 -10
- package/dist/core/memory-engine/consolidation.js +167 -11
- package/dist/core/memory-engine/data-plane.d.ts +8 -4
- package/dist/core/memory-engine/data-plane.js +11 -6
- package/dist/core/memory-engine/delegation-settlement.d.ts +37 -35
- package/dist/core/memory-engine/delegation-settlement.js +53 -59
- package/dist/core/memory-engine/dual-root.d.ts +12 -6
- package/dist/core/memory-engine/dual-root.js +9 -5
- package/dist/core/memory-engine/engine.d.ts +98 -35
- package/dist/core/memory-engine/engine.js +477 -380
- package/dist/core/memory-engine/entry-scan.d.ts +8 -0
- package/dist/core/memory-engine/entry-scan.js +3 -0
- package/dist/core/memory-engine/file-backend.d.ts +29 -3
- package/dist/core/memory-engine/file-backend.js +66 -35
- package/dist/core/memory-engine/index.d.ts +7 -7
- package/dist/core/memory-engine/index.js +6 -6
- package/dist/core/memory-engine/landing-admission.d.ts +5 -3
- package/dist/core/memory-engine/landing-admission.js +3 -3
- package/dist/core/memory-engine/layout.d.ts +121 -45
- package/dist/core/memory-engine/layout.js +252 -102
- package/dist/core/memory-engine/memory-backend-contract.d.ts +19 -1
- package/dist/core/memory-engine/memory-backend-contract.js +320 -0
- package/dist/core/memory-engine/memory-deployment.d.ts +31 -8
- package/dist/core/memory-engine/memory-deployment.js +26 -12
- package/dist/core/memory-engine/scope-contract.d.ts +52 -11
- package/dist/core/memory-engine/scope-contract.js +68 -19
- package/dist/core/memory-engine/session-write-home.d.ts +3 -1
- package/dist/core/memory-engine/session-write-home.js +1 -1
- package/dist/core/memory-engine/sync-client.d.ts +3 -1
- package/dist/core/memory-engine/sync-client.js +7 -0
- package/dist/core/memory-engine/sync-report.d.ts +3 -2
- package/dist/core/memory-engine/sync-report.js +6 -2
- package/dist/core/memory-engine/tools.d.ts +2 -2
- package/dist/core/memory-engine/tools.js +10 -10
- package/dist/core/memory-engine/types.d.ts +118 -19
- package/dist/core/memory-engine/types.js +1 -0
- package/dist/core/memory-vector.d.ts +1 -1
- package/dist/core/memory.d.ts +10 -10
- package/dist/core/memory.js +15 -6
- package/dist/core/mode-policy.js +1 -1
- package/dist/core/mods/classic-events.d.ts +9 -1
- package/dist/core/mods/dollar.d.ts +32 -1
- package/dist/core/mods/dollar.js +13 -1
- package/dist/core/mods/kernel/events.d.ts +11 -3
- package/dist/core/mods/kernel/events.js +13 -10
- package/dist/core/mods/lifecycle-stations.d.ts +36 -4
- package/dist/core/mods/lifecycle-stations.js +44 -9
- package/dist/core/mods/session-append.d.ts +4 -1
- package/dist/core/mods/session-append.js +7 -0
- package/dist/core/mods/session-receive.js +12 -15
- package/dist/core/mods/stations.d.ts +70 -6
- package/dist/core/mods/stations.js +144 -1
- package/dist/core/own-property-receipt.d.ts +7 -0
- package/dist/core/own-property-receipt.js +3 -0
- package/dist/core/park-selfcheck.js +2 -2
- package/dist/core/pause-registry.d.ts +2 -0
- package/dist/core/pause-registry.js +3 -0
- package/dist/core/permission-rule-consent.d.ts +10 -3
- package/dist/core/permission-rule-consent.js +37 -24
- package/dist/core/permission-rule-store.d.ts +35 -1
- package/dist/core/permission-rule-store.js +27 -8
- package/dist/core/read-only-shell.js +3 -2
- package/dist/core/read-root-candidate.js +1 -1
- package/dist/core/redaction-marks.d.ts +8 -0
- package/dist/core/redaction-marks.js +6 -0
- package/dist/core/remote-env.d.ts +12 -1
- package/dist/core/remote-env.js +3 -0
- package/dist/core/resume-startup-cause.d.ts +5 -4
- package/dist/core/runner/child-tree.d.ts +29 -3
- package/dist/core/runner/child-tree.js +39 -16
- package/dist/core/runner/compact-session.js +5 -2
- package/dist/core/runner/contracts.d.ts +36 -17
- package/dist/core/runner/delegation-owner.d.ts +43 -0
- package/dist/core/runner/delegation-owner.js +59 -0
- package/dist/core/runner/gate-exit.js +2 -2
- package/dist/core/runner/inherited-ask-grants.js +1 -1
- package/dist/core/runner/lineage-reroot-view.d.ts +56 -0
- package/dist/core/runner/lineage-reroot-view.js +108 -0
- package/dist/core/runner/memory-consolidation-driver.d.ts +6 -3
- package/dist/core/runner/memory-consolidation-driver.js +4 -4
- package/dist/core/runner/memory-consolidation-write-judge.d.ts +2 -1
- package/dist/core/runner/memory-consolidation-write-judge.js +3 -2
- package/dist/core/runner/permission-rule-lanes.d.ts +2 -1
- package/dist/core/runner/permission-rule-lanes.js +2 -2
- package/dist/core/runner/person-path-rows.d.ts +23 -3
- package/dist/core/runner/person-path-rows.js +31 -4
- package/dist/core/runner/placement-fence.d.ts +12 -0
- package/dist/core/runner/placement-fence.js +20 -6
- package/dist/core/runner/prepare-acquire-reconcile.d.ts +4 -1
- package/dist/core/runner/prepare-acquire-reconcile.js +7 -2
- package/dist/core/runner/prepare-ask-lane.js +2 -2
- package/dist/core/runner/prepare-caps-and-workflow.d.ts +5 -1
- package/dist/core/runner/prepare-caps-and-workflow.js +6 -3
- package/dist/core/runner/prepare-config-doors.d.ts +6 -6
- package/dist/core/runner/prepare-config-doors.js +3 -4
- package/dist/core/runner/prepare-execution-env.js +17 -6
- package/dist/core/runner/prepare-hands-readface.d.ts +3 -2
- package/dist/core/runner/prepare-hands-readface.js +32 -10
- package/dist/core/runner/prepare-inherited-gate.d.ts +12 -8
- package/dist/core/runner/prepare-inherited-gate.js +14 -6
- package/dist/core/runner/prepare-memory-engine-session.d.ts +2 -4
- package/dist/core/runner/prepare-memory-engine-session.js +4 -4
- package/dist/core/runner/prepare-memory.d.ts +3 -2
- package/dist/core/runner/prepare-memory.js +28 -20
- package/dist/core/runner/prepare-park-ask.js +4 -3
- package/dist/core/runner/prepare-task.js +22 -16
- package/dist/core/runner/prepare-workspace-restore.js +3 -6
- package/dist/core/runner/resume-admission.d.ts +3 -3
- package/dist/core/runner/resume-admission.js +6 -3
- package/dist/core/runner/resume-apply.d.ts +4 -0
- package/dist/core/runner/resume-apply.js +11 -4
- package/dist/core/runner/resume-checkpoint-screen.d.ts +9 -0
- package/dist/core/runner/resume-checkpoint-screen.js +4 -84
- package/dist/core/runner/run-git-lane.d.ts +2 -0
- package/dist/core/runner/run-git-lane.js +4 -1
- package/dist/core/runner/run-harness-handlers.d.ts +2 -0
- package/dist/core/runner/run-harness-handlers.js +3 -2
- package/dist/core/runner/run-leg.js +25 -8
- package/dist/core/runner/run-settle-and-teardown.js +6 -4
- package/dist/core/runner/run-stop-and-final-verify.js +2 -1
- package/dist/core/runner/run-turn-boundary.js +7 -4
- package/dist/core/runner/runtask.js +6 -6
- package/dist/core/runner/steering-preview.d.ts +9 -0
- package/dist/core/runner/steering-preview.js +5 -0
- package/dist/core/runner/stream-steer-verb.js +8 -0
- package/dist/core/runner/terminal-account.js +1 -1
- package/dist/core/runner/tool-face-overlay.js +2 -0
- package/dist/core/runner/turn-attachments.d.ts +5 -0
- package/dist/core/runner/turn-attachments.js +1 -1
- package/dist/core/runner-deps.d.ts +8 -4
- package/dist/core/secret-env.d.ts +9 -6
- package/dist/core/secret-env.js +41 -22
- package/dist/core/session-checkout.d.ts +108 -0
- package/dist/core/session-checkout.js +485 -0
- package/dist/core/session-store.d.ts +13 -5
- package/dist/core/session-store.js +28 -4
- package/dist/core/session.d.ts +29 -5
- package/dist/core/session.js +3 -0
- package/dist/core/store-contracts/checkpoint-store-contract.d.ts +6 -12
- package/dist/core/store-contracts/checkpoint-store-contract.js +73 -6
- package/dist/core/store-contracts/session-store-contract.js +61 -8
- package/dist/core/task-event.d.ts +28 -1
- package/dist/core/task-notification.d.ts +9 -1
- package/dist/core/task-notification.js +8 -1
- package/dist/core/task-registry-agent.d.ts +40 -8
- package/dist/core/task-registry-agent.js +57 -24
- package/dist/core/task-registry-shared.d.ts +33 -11
- package/dist/core/task-registry-workflow.js +4 -3
- package/dist/core/task-registry.d.ts +27 -10
- package/dist/core/task-registry.js +19 -13
- package/dist/core/task-result.d.ts +5 -5
- package/dist/core/task-spec-members.js +1 -1
- package/dist/core/task-spec.d.ts +21 -1
- package/dist/core/terminal-cause.d.ts +6 -6
- package/dist/core/tool-face.d.ts +6 -2
- package/dist/core/tool-face.js +1 -1
- package/dist/core/tool-policy.d.ts +16 -13
- package/dist/core/tool-policy.js +11 -10
- package/dist/core/tool-roster.d.ts +4 -4
- package/dist/core/tool-spec.d.ts +42 -19
- package/dist/core/types.d.ts +2 -2
- package/dist/core/types.js +1 -1
- package/dist/core/untrusted-egress.d.ts +15 -4
- package/dist/core/untrusted-egress.js +23 -22
- package/dist/core/workspace-snapshot.d.ts +3 -1
- package/dist/core/workspace-snapshot.js +1 -0
- package/dist/engine/execution-env/node-execution-env.d.ts +3 -0
- package/dist/engine/execution-env/node-execution-env.js +12 -5
- package/dist/engine/harness/types.d.ts +77 -1
- package/dist/engine/harness/types.js +108 -0
- package/dist/engine/session/import-validate.js +6 -1
- package/dist/engine/session/parent-chain-guard.d.ts +3 -3
- package/dist/engine/session/parent-chain-guard.js +1 -1
- package/dist/engine/session/path-to-root.d.ts +18 -3
- package/dist/engine/session/path-to-root.js +15 -1
- package/dist/engine/session/repo-utils.d.ts +12 -1
- package/dist/engine/session/repo-utils.js +41 -0
- package/dist/engine/session/session.d.ts +24 -1
- package/dist/engine/session/session.js +46 -2
- package/dist/engine/session/storage-base.d.ts +20 -0
- package/dist/engine/session/storage-base.js +28 -9
- package/dist/index.d.ts +16 -12
- package/dist/index.js +11 -8
- package/dist/internal/harness-types.d.ts +1 -1
- package/dist/internal/harness.d.ts +4 -3
- package/dist/internal/harness.js +3 -2
- package/dist/orchestration/run-workflow-tool.d.ts +7 -1
- package/dist/orchestration/run-workflow-tool.js +28 -11
- package/dist/orchestration/workflow-governance.d.ts +1 -1
- package/dist/orchestration/workflow.d.ts +6 -0
- package/dist/orchestration/workflow.js +5 -8
- package/dist/stores/file/checkpoint-store.d.ts +2 -0
- package/dist/stores/file/checkpoint-store.js +7 -6
- package/dist/stores/file/fs-atomic.d.ts +0 -22
- package/dist/stores/file/fs-atomic.js +0 -17
- package/dist/stores/file/index.d.ts +2 -9
- package/dist/stores/file/index.js +2 -4
- package/dist/stores/file/session-store.d.ts +13 -7
- package/dist/stores/file/session-store.js +42 -18
- package/dist/tools/fs/bash-program-position.d.ts +3 -2
- package/dist/tools/fs/bash-program-position.js +10 -10
- package/dist/tools/fs/program-read-model.d.ts +34 -10
- package/dist/tools/fs/program-read-model.js +37 -7
- package/dist/tools/fs/program-read-model.rows.js +13 -2
- package/dist/tools/fs/read-deny.d.ts +13 -1
- package/dist/tools/fs/read-deny.js +10 -2
- package/dist/tools/fs/removal-targets.js +5 -5
- package/dist/tools/fs/safety.d.ts +2 -0
- package/dist/tools/fs/safety.js +1 -1
- package/dist/tools/fs/shell-read-argv.d.ts +11 -2
- package/dist/tools/fs/shell-read-argv.js +45 -29
- package/dist/tools/fs/shell-read-bindings.d.ts +20 -2
- package/dist/tools/fs/shell-read-bindings.js +153 -69
- package/dist/tools/fs/shell-read-brace.d.ts +18 -0
- package/dist/tools/fs/shell-read-brace.js +79 -0
- package/dist/tools/fs/shell-read-check.js +29 -11
- package/dist/tools/fs/shell-read-establish.js +43 -22
- package/dist/tools/fs/shell-read-functions.js +2 -2
- package/dist/tools/fs/shell-read-judge.d.ts +11 -0
- package/dist/tools/fs/shell-read-judge.js +3 -3
- package/dist/tools/fs/shell-read-object-path.d.ts +59 -0
- package/dist/tools/fs/shell-read-object-path.js +119 -0
- package/dist/tools/fs/shell-read-plan.d.ts +18 -0
- package/dist/tools/fs/shell-read-plan.js +217 -104
- package/dist/tools/fs/shell-read-start.d.ts +76 -13
- package/dist/tools/fs/shell-read-start.js +97 -17
- package/dist/tools/fs/shell-read-word.d.ts +10 -0
- package/dist/tools/fs/shell-read-word.js +9 -5
- package/dist/tools/fs/shell-read-workdir.d.ts +54 -14
- package/dist/tools/fs/shell-read-workdir.js +103 -19
- package/dist/tools/fs/shell-read-write-targets.js +13 -8
- package/dist/tools/worktree.d.ts +3 -2
- package/dist/tools/worktree.js +7 -35
- package/package.json +3 -2
- package/test/export-surface.snapshot.json +93 -43
- package/wire-changes/core-stores-sql@7.62.0.json +30 -0
- package/wire-changes/core-stores-sql@7.63.0.json +30 -0
- package/wire-changes/core@7.62.0.json +2181 -0
- package/wire-changes/core@7.63.0.json +3523 -0
- package/wire-changes/mods-kernel@7.62.0.json +42 -0
- package/wire-changes/mods-kernel@7.63.0.json +30 -0
- package/wire-changes/primitives@7.62.0.json +30 -0
- package/wire-changes/primitives@7.63.0.json +445 -0
- package/dist/core/consolidate-scope.d.ts +0 -93
- package/dist/core/consolidate-scope.js +0 -98
- package/dist/core/credential-vocabulary.d.ts +0 -176
- package/dist/core/credential-vocabulary.js +0 -190
- package/dist/core/redaction-passes.d.ts +0 -82
- package/dist/core/redaction-passes.js +0 -377
- package/dist/core/runner/memory-consolidation.d.ts +0 -109
- package/dist/core/runner/memory-consolidation.js +0 -251
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* plan and clears the session count), so without a durable run account a process exit between two
|
|
10
10
|
* cycles would strand the work: no open plan to reconcile, no session edge to re-arm, and a naive
|
|
11
11
|
* re-entry would re-mint the whole plan at full model cost. The run row under the control plane is
|
|
12
|
-
* the resume seat: `
|
|
12
|
+
* the resume seat: `runMemoryConsolidationDriver` first looks for a PENDING run of the scope and
|
|
13
13
|
* CONTINUES it (same plan cache, same force requestId, zero new mint) — the idempotent re-entry
|
|
14
14
|
* GD-15 pins.
|
|
15
15
|
*
|
|
@@ -21,12 +21,12 @@
|
|
|
21
21
|
* auto lane's task-boundary tick), never on a background schedule of core's own.
|
|
22
22
|
*/
|
|
23
23
|
import type { EngineNotice } from "../types.js";
|
|
24
|
-
import
|
|
24
|
+
import type { MemoryGovernanceStore } from "./types.js";
|
|
25
|
+
import { type ConsolidationGateRow, CONSOLIDATION_WRITE_REFUSED_CODE, type ConsolidationRunStopReason, type MemoryConsolidationOptions } from "./consolidation.js";
|
|
25
26
|
import { type ConsolidationPlanFoldEvidence, type ConsolidationPlanSummary } from "./engine.js";
|
|
27
|
+
import { type ComplianceCapability, type CompliancePostureSeat } from "../compliance.js";
|
|
26
28
|
import type { SyntheticWriteVerdict } from "../synthetic-read-verdict.js";
|
|
27
|
-
import { mintLlmConsolidationPlan, type ConsolidationDriveCycleRow, type ConsolidationDriveEngine, type ConsolidationFoldState, type DistillerChatFn, type
|
|
28
|
-
export declare const CONSOLIDATION_DRIVER_RUNS_FILE = "distiller-runs.json";
|
|
29
|
-
export { CONSOLIDATION_DRIVER_PLANS_DIR };
|
|
29
|
+
import { mintLlmConsolidationPlan, type ConsolidationDriveCycleRow, type ConsolidationDriveEngine, type ConsolidationFoldState, type DistillerChatFn, type LlmConsolidationPlanProduct, type LlmDistillerContract } from "./distiller.js";
|
|
30
30
|
export interface ConsolidationDriverRunRow {
|
|
31
31
|
runId: string;
|
|
32
32
|
scope: string;
|
|
@@ -79,7 +79,7 @@ export interface ConsolidationDriverRunRow {
|
|
|
79
79
|
* dies with a discarded cache, and "your data never left this machine" must not become
|
|
80
80
|
* unanswerable because an unrelated guard fired. */
|
|
81
81
|
withheldNeverSent?: number;
|
|
82
|
-
/** The archived mint transcript's
|
|
82
|
+
/** The archived mint transcript's name in the consolidation store (`MemoryGovernanceStore.readMint`). */
|
|
83
83
|
planArchive?: string;
|
|
84
84
|
/** COMMITTED cycles only (the store moved): a refused/fuse-blocked/zero-delta cycle row does
|
|
85
85
|
* not count — the receipt's "committed cycle(s)" label and the incomplete notice's zero-cycle
|
|
@@ -124,26 +124,20 @@ export interface ConsolidationDriverRunRow {
|
|
|
124
124
|
/** The next moment a snapshot can pass the hard throttle (resume scheduling hint). */
|
|
125
125
|
nextEligibleAt?: number;
|
|
126
126
|
}
|
|
127
|
-
/** Host read face: the scope's latest driver run row (pending = resumable; settled = audit). */
|
|
128
|
-
export declare function readConsolidationDriverRun(controlDir: string, scope: string): ConsolidationDriverRunRow | undefined;
|
|
129
|
-
/** Archive one mint (prompts + transcript verbatim) beside the run account. The name carries the
|
|
130
|
-
* CLAIM (`attempt`): two invocations that raced onto one run each archive
|
|
131
|
-
* under their own name, so a superseded worker can never overwrite the winning transcript — the
|
|
132
|
-
* run row's `planArchive` (written under the attempt guard) names the one that counts. */
|
|
133
|
-
export declare function distillerPlanArchiveName(runId: string, attempt: number): string;
|
|
134
|
-
export declare function archiveDistillerPlan(controlDir: string, runId: string, plan: LlmConsolidationPlan, attempt?: number): string;
|
|
135
127
|
/** The engine face this verb consumes — `MemoryEngine` satisfies it structurally.
|
|
136
128
|
* (`readConsolidationPlanFoldEvidence` joined in design/376 slice ③, #436: the conservation
|
|
137
129
|
* wall's terminal witness is member-level, so the face is REQUIRED — an engine without it could
|
|
138
130
|
* only offer the store-delta counts an interleaved fold can numerically offset.) */
|
|
139
131
|
export interface ConsolidationDriverEngine extends ConsolidationDriveEngine {
|
|
140
|
-
readConsolidationGate(scope: string): ConsolidationGateRow | undefined
|
|
141
|
-
listConsolidationPlans(): ConsolidationPlanSummary[]
|
|
142
|
-
readConsolidationPlanFoldEvidence(planId: string): ConsolidationPlanFoldEvidence
|
|
132
|
+
readConsolidationGate(scope: string): Promise<ConsolidationGateRow | undefined>;
|
|
133
|
+
listConsolidationPlans(): Promise<ConsolidationPlanSummary[]>;
|
|
134
|
+
readConsolidationPlanFoldEvidence(planId: string): Promise<ConsolidationPlanFoldEvidence>;
|
|
143
135
|
readConsolidationFoldState(scope: string): Promise<ConsolidationFoldState>;
|
|
144
136
|
/** The canonical directory a commit lands the scope's products in (the write judge's early question). */
|
|
145
137
|
consolidationWriteHome(scope: string): string;
|
|
146
|
-
|
|
138
|
+
/** The store the engine keeps its consolidation state in (the run account, the mint archive and the run's
|
|
139
|
+
* announcements — its `announcements` document — are written through it). */
|
|
140
|
+
readonly governance: MemoryGovernanceStore;
|
|
147
141
|
}
|
|
148
142
|
/** One write the judge is asked about: `path` is a file (or the library directory) of `scope`'s library, absolute and canonical. */
|
|
149
143
|
export interface ConsolidationWriteTarget {
|
|
@@ -153,6 +147,24 @@ export interface ConsolidationWriteTarget {
|
|
|
153
147
|
/** The write judge's seat: one target in, the synthetic-write judge's verdict out (only `no_objection` permits the write). */
|
|
154
148
|
export type ConsolidationWriteJudge = (target: ConsolidationWriteTarget) => Promise<SyntheticWriteVerdict> | SyntheticWriteVerdict;
|
|
155
149
|
export { CONSOLIDATION_WRITE_REFUSED_CODE };
|
|
150
|
+
/**
|
|
151
|
+
* A consolidation run's compliance veto. The posture asked is the one of the scope's OWNER (`memoryScopeOwnerOf`, read
|
|
152
|
+
* under `scopeContract`): a principal's own layer asks `postureOf` with that principal; a tenant's layer and an opaque key
|
|
153
|
+
* ask it with no principal (the deployment's posture — the seat is keyed by principals). Outside the v2 contract the
|
|
154
|
+
* principal a key's spelling names is asked too, refuse-only (a stored `user:<P>` layer stays P's whichever contract a
|
|
155
|
+
* task declares). `denies` are the caller's own,
|
|
156
|
+
* added to the owner's (add-only: the Runner's automatic run passes the leg's `TaskSpec.complianceAdditionalDenies`).
|
|
157
|
+
* `memory_consolidation` among them refuses `config.compliance_denied`; a seat that throws or answers an unparseable
|
|
158
|
+
* posture refuses `config.compliance_required` (fail-closed). Both are {@link ConsolidationRefusedError}s, and nothing
|
|
159
|
+
* has been read or written.
|
|
160
|
+
*/
|
|
161
|
+
export interface ConsolidationCompliance {
|
|
162
|
+
/** The deployment's posture seat (`RunnerDeps.compliancePostureResolver`); absent ⇒ only `denies` apply. */
|
|
163
|
+
postureOf?: CompliancePostureSeat;
|
|
164
|
+
/** The scope contract the scope was minted under (`TaskSpec.memory.scopeContract`) — a required key. */
|
|
165
|
+
scopeContract: "v2" | undefined;
|
|
166
|
+
denies?: readonly ComplianceCapability[];
|
|
167
|
+
}
|
|
156
168
|
export interface RunMemoryConsolidationOptions {
|
|
157
169
|
/** The explicit model seat (design/339 §1.1: the ENGINE holds none). Build one with
|
|
158
170
|
* `openAiCompatChatSeat` or hand any JSON-only completion function. */
|
|
@@ -170,6 +182,9 @@ export interface RunMemoryConsolidationOptions {
|
|
|
170
182
|
* throw — refuses the run with `memory.consolidation_write_refused`, and nothing is written. A host that holds no rules
|
|
171
183
|
* says so by passing a judge that answers `no_objection`; an absent seat refuses, it never reads as "no rules". */
|
|
172
184
|
writeJudge: ConsolidationWriteJudge;
|
|
185
|
+
/** The compliance veto of the capability `memory_consolidation`, asked once per invocation and FIRST — before the write
|
|
186
|
+
* judge and before any read, seat, lock or model call. Absent ⇒ no posture applies (a deployment that holds none). */
|
|
187
|
+
compliance?: ConsolidationCompliance;
|
|
173
188
|
/** Audit locator recorded into the archive when the seat is endpoint-shaped. */
|
|
174
189
|
baseUrl?: string;
|
|
175
190
|
/** The frozen prompt contract; default = the product v1 (dl-3 byte-identical). A different
|
|
@@ -1,66 +1,23 @@
|
|
|
1
|
-
import { join } from "node:path";
|
|
2
1
|
import { uuidv7 } from "../../internal/harness.js";
|
|
3
|
-
import {
|
|
2
|
+
import { enqueueMemoryAnnouncement } from "./layout.js";
|
|
4
3
|
import { inlineUntrusted } from "../untrusted-text.js";
|
|
5
4
|
import { extensionWords } from "../untrusted-egress.js";
|
|
6
5
|
import { deliverEngineNotice } from "../engine-notice.js";
|
|
7
|
-
import {
|
|
6
|
+
import { CONSOLIDATION_FORCE_THROTTLE_FLOOR_MS, distillerPlanArchiveName, screenConsolidationOptions, supersessionFuseCeiling, recommendationUnconsumed, CONSOLIDATION_WRITE_REFUSED_CODE, ConsolidationRefusedError, } from "./consolidation.js";
|
|
8
7
|
import { memoryConsolidationIncompleteNotice, memoryConsolidationWithheldNotice } from "./engine.js";
|
|
9
8
|
import { asThrownError, thrownText } from "../thrown-value.js";
|
|
9
|
+
import { complianceCapabilityProblem, resolveComplianceDenies } from "../compliance.js";
|
|
10
|
+
import { memoryScopeOwnerOf } from "./scope-contract.js";
|
|
10
11
|
import { CONSOLIDATION_DRIVE_ABORT, CONSOLIDATION_SNAPSHOT_PARKED, MEMORY_DISTILLER_CONTRACT_V1, detectCleanArmVerbatimLeak, driveConsolidationToFixpoint, isAliasModelId, llmPlanDistiller, mintExposurePartitionedPlan, mintLlmConsolidationPlan, normalizedCandidateRev, } from "./distiller.js";
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
if (raw === undefined)
|
|
15
|
-
return { v: 1, scopes: {} };
|
|
16
|
-
if (typeof raw !== "object" || raw === null || raw.v !== 1 || typeof raw.scopes !== "object" || raw.scopes === null) {
|
|
17
|
-
throw new ControlPlaneCorruptError("memory consolidation driver run account has an unrecognized shape (fail-closed sidecar)");
|
|
12
|
+
async function writeDriverRun(store, row) {
|
|
13
|
+
try {
|
|
14
|
+
await store.writeRun(row);
|
|
18
15
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
16
|
+
catch (err) {
|
|
17
|
+
if (typeof err === "object" && err !== null && Reflect.get(err, "code") === "memory.consolidation_driver_superseded")
|
|
18
|
+
Reflect.set(err, CONSOLIDATION_DRIVE_ABORT, true);
|
|
19
|
+
throw err;
|
|
24
20
|
}
|
|
25
|
-
return raw;
|
|
26
|
-
}
|
|
27
|
-
export function readConsolidationDriverRun(controlDir, scope) {
|
|
28
|
-
return coerceRunsFile(readStrictSidecar(controlDir, CONSOLIDATION_DRIVER_RUNS_FILE, "memory consolidation driver run account")).scopes[scope];
|
|
29
|
-
}
|
|
30
|
-
function writeDriverRun(controlDir, row) {
|
|
31
|
-
lockedStrictUpdate(controlDir, CONSOLIDATION_DRIVER_RUNS_FILE, "memory consolidation driver run account", coerceRunsFile, (file) => {
|
|
32
|
-
const cur = file.scopes[row.scope];
|
|
33
|
-
if (cur === undefined || cur.runId !== row.runId || (cur.attempt ?? 0) !== row.attempt) {
|
|
34
|
-
const e = new Error(`memory consolidation driver run seat for scope ${JSON.stringify(row.scope)} was taken over by a newer invocation${cur !== undefined ? ` (run ${cur.runId} attempt ${cur.attempt ?? 0})` : ""} — this worker stops without settling; the newer claim owns the account.`);
|
|
35
|
-
e.code = "memory.consolidation_driver_superseded";
|
|
36
|
-
e[CONSOLIDATION_DRIVE_ABORT] = true;
|
|
37
|
-
throw e;
|
|
38
|
-
}
|
|
39
|
-
file.scopes[row.scope] = row;
|
|
40
|
-
return { next: file, result: undefined };
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
function claimDriverRun(controlDir, scope, fresh) {
|
|
44
|
-
return lockedStrictUpdate(controlDir, CONSOLIDATION_DRIVER_RUNS_FILE, "memory consolidation driver run account", coerceRunsFile, (file) => {
|
|
45
|
-
const cur = file.scopes[scope];
|
|
46
|
-
if (cur !== undefined && cur.state === "pending") {
|
|
47
|
-
cur.attempt = (cur.attempt ?? 0) + 1;
|
|
48
|
-
file.scopes[scope] = cur;
|
|
49
|
-
return { next: file, result: { row: structuredClone(cur), resumed: true } };
|
|
50
|
-
}
|
|
51
|
-
const row = fresh();
|
|
52
|
-
file.scopes[scope] = row;
|
|
53
|
-
return { next: file, result: { row: structuredClone(row), resumed: false } };
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
export function distillerPlanArchiveName(runId, attempt) {
|
|
57
|
-
return `${runId}-a${attempt}.json`;
|
|
58
|
-
}
|
|
59
|
-
export function archiveDistillerPlan(controlDir, runId, plan, attempt = 1) {
|
|
60
|
-
ensureDirExists(join(controlDir, CONSOLIDATION_DRIVER_PLANS_DIR));
|
|
61
|
-
const name = distillerPlanArchiveName(runId, attempt);
|
|
62
|
-
atomicWriteFileSync(join(controlDir, CONSOLIDATION_DRIVER_PLANS_DIR, name), `${JSON.stringify(plan, null, 2)}\n`);
|
|
63
|
-
return name;
|
|
64
21
|
}
|
|
65
22
|
export { CONSOLIDATION_WRITE_REFUSED_CODE };
|
|
66
23
|
function driverConfigRefusal(message) {
|
|
@@ -68,6 +25,49 @@ function driverConfigRefusal(message) {
|
|
|
68
25
|
e.code = "config.memory_consolidation_driver";
|
|
69
26
|
return e;
|
|
70
27
|
}
|
|
28
|
+
async function refuseUnlessCompliancePermits(compliance, scope) {
|
|
29
|
+
if (compliance === undefined)
|
|
30
|
+
return;
|
|
31
|
+
if (typeof compliance !== "object" || compliance === null || !Object.hasOwn(compliance, "scopeContract") || (compliance.scopeContract !== undefined && compliance.scopeContract !== "v2")) {
|
|
32
|
+
throw driverConfigRefusal(`runMemoryConsolidationDriver: opts.compliance must be an object whose scopeContract key is present and "v2" or undefined — the owner of the scope is read under it, and a guessed contract reads another owner.`);
|
|
33
|
+
}
|
|
34
|
+
const { postureOf, scopeContract, denies = [] } = compliance;
|
|
35
|
+
if (postureOf !== undefined && typeof postureOf !== "function")
|
|
36
|
+
throw driverConfigRefusal(`runMemoryConsolidationDriver: opts.compliance.postureOf must be a function when present (got ${typeof postureOf}).`);
|
|
37
|
+
if (!Array.isArray(denies))
|
|
38
|
+
throw driverConfigRefusal(`runMemoryConsolidationDriver: opts.compliance.denies must be an array when present.`);
|
|
39
|
+
for (const cap of denies) {
|
|
40
|
+
const problem = complianceCapabilityProblem(cap, "opts.compliance.denies");
|
|
41
|
+
if (problem !== undefined)
|
|
42
|
+
throw driverConfigRefusal(`runMemoryConsolidationDriver: ${problem}`);
|
|
43
|
+
}
|
|
44
|
+
const owners = [memoryScopeOwnerOf(scope, scopeContract)];
|
|
45
|
+
if (scopeContract !== "v2") {
|
|
46
|
+
try {
|
|
47
|
+
owners.push(memoryScopeOwnerOf(scope, "v2"));
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
const subjects = [...new Set(owners.map((o) => (o.kind === "principal" ? o.principal : undefined)))];
|
|
53
|
+
for (const subject of subjects) {
|
|
54
|
+
const ownerText = subject !== undefined ? `principal ${inlineUntrusted(subject, 80)}` : "the deployment";
|
|
55
|
+
let ownerDenies;
|
|
56
|
+
try {
|
|
57
|
+
const posture = postureOf === undefined ? undefined : ((await postureOf(subject)) ?? undefined);
|
|
58
|
+
ownerDenies = posture === undefined ? new Set() : resolveComplianceDenies(posture);
|
|
59
|
+
}
|
|
60
|
+
catch (err) {
|
|
61
|
+
throw new ConsolidationRefusedError("config.compliance_required", `memory consolidation refused for scope ${inlineUntrusted(scope, 80)}: the compliance posture of its owner (${ownerText}) could not be read (${inlineUntrusted(thrownText(err), 200)}), so every managed capability is denied fail-closed — no run was started and nothing was written.`);
|
|
62
|
+
}
|
|
63
|
+
if (ownerDenies.has("memory_consolidation")) {
|
|
64
|
+
throw new ConsolidationRefusedError("config.compliance_denied", `memory consolidation refused for scope ${inlineUntrusted(scope, 80)}: the capability "memory_consolidation" is denied by the compliance posture of its owner (${ownerText}) — no run was started and nothing was written.`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
if (denies.includes("memory_consolidation")) {
|
|
68
|
+
throw new ConsolidationRefusedError("config.compliance_denied", `memory consolidation refused for scope ${inlineUntrusted(scope, 80)}: the capability "memory_consolidation" is denied by the caller's own denies — no run was started and nothing was written.`);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
71
|
class DriverMintFailure extends Error {
|
|
72
72
|
detail;
|
|
73
73
|
constructor(detail) {
|
|
@@ -140,7 +140,7 @@ export async function runMemoryConsolidationDriver(engine, scope, opts) {
|
|
|
140
140
|
if (typeof contract?.version !== "string" || contract.version === "" || typeof contract?.grouping?.instructions !== "string" || typeof contract?.writing?.instructions !== "string") {
|
|
141
141
|
throw driverConfigRefusal("runMemoryConsolidationDriver: opts.contract does not carry the contract shape (version + grouping/writing instructions).");
|
|
142
142
|
}
|
|
143
|
-
const screened = screenConsolidationOptions(opts.consolidation ?? {}, "carry");
|
|
143
|
+
const screened = screenConsolidationOptions(opts.consolidation ?? {}, "carry", "backend");
|
|
144
144
|
const mintRepairBudget = opts.mintRepairBudget ?? 0.1;
|
|
145
145
|
const now = opts.now ?? Date.now;
|
|
146
146
|
const rawSleep = opts.sleep ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
|
|
@@ -155,7 +155,8 @@ export async function runMemoryConsolidationDriver(engine, scope, opts) {
|
|
|
155
155
|
}
|
|
156
156
|
};
|
|
157
157
|
const throttleWindowMs = Math.min(screened.minRunIntervalMs, CONSOLIDATION_FORCE_THROTTLE_FLOOR_MS);
|
|
158
|
-
const
|
|
158
|
+
const store = engine.governance;
|
|
159
|
+
await refuseUnlessCompliancePermits(opts.compliance, scope);
|
|
159
160
|
if (typeof opts.writeJudge !== "function")
|
|
160
161
|
throw driverConfigRefusal(`runMemoryConsolidationDriver needs an explicit write judge (opts.writeJudge), got ${typeof opts.writeJudge} — a run writes the library with nobody watching, so it asks the judgment a foreground write meets before it starts; an absent seat is refused, never read as "no rules apply" (a host that holds no rules passes a judge that answers no_objection).`);
|
|
161
162
|
let libraryHome;
|
|
@@ -175,7 +176,7 @@ export async function runMemoryConsolidationDriver(engine, scope, opts) {
|
|
|
175
176
|
return undefined;
|
|
176
177
|
});
|
|
177
178
|
const openFold = await engine.readConsolidationFoldState(scope);
|
|
178
|
-
const { row: run, resumed } =
|
|
179
|
+
const { row: run, resumed } = await store.claimRun(scope, () => ({
|
|
179
180
|
runId: uuidv7(),
|
|
180
181
|
scope,
|
|
181
182
|
attempt: 1,
|
|
@@ -197,9 +198,9 @@ export async function runMemoryConsolidationDriver(engine, scope, opts) {
|
|
|
197
198
|
run.contractVersion = contract.version;
|
|
198
199
|
}
|
|
199
200
|
const announceFailures = [];
|
|
200
|
-
const announce = (items) => {
|
|
201
|
+
const announce = async (items) => {
|
|
201
202
|
try {
|
|
202
|
-
enqueueMemoryAnnouncement(
|
|
203
|
+
await enqueueMemoryAnnouncement(store, { kind: "gate", scope, at: now(), items });
|
|
203
204
|
}
|
|
204
205
|
catch (err) {
|
|
205
206
|
announceFailures.push(thrownText(err));
|
|
@@ -217,44 +218,44 @@ export async function runMemoryConsolidationDriver(engine, scope, opts) {
|
|
|
217
218
|
}
|
|
218
219
|
})(opts.baseUrl);
|
|
219
220
|
const egressSeat = `${inlineUntrusted(opts.model, 80)}${egressEndpoint}`;
|
|
220
|
-
const announceMintEgress = (calls, offered, plan) => {
|
|
221
|
+
const announceMintEgress = async (calls, offered, plan) => {
|
|
221
222
|
if (calls === 0) {
|
|
222
|
-
announce([
|
|
223
|
+
await announce([
|
|
223
224
|
`memory consolidation driver run ${run.runId} for scope ${inlineUntrusted(scope, 80)} made NO model call: all ${offered} offered candidate(s) were withheld from every arm, so no memory content left this process.`,
|
|
224
225
|
]);
|
|
225
226
|
return;
|
|
226
227
|
}
|
|
227
228
|
const armLine = (plan?.minting.arms ?? []).map((a) => `${a.arm} arm ${a.candidateCount} candidate(s) in ${a.calls} call(s)`).join(", ");
|
|
228
|
-
announce([
|
|
229
|
+
await announce([
|
|
229
230
|
`memory consolidation driver run ${run.runId} for scope ${inlineUntrusted(scope, 80)} SENT memory content to the configured consolidation model: ${egressSeat} — ${armLine || `up to ${offered} candidate(s) over ${calls} call(s) (the mint failed before its per-arm split was recorded; an arm that never ran sent nothing)`}. Each candidate was rendered as its name, description and body.`,
|
|
230
231
|
]);
|
|
231
232
|
const withheld = run.withheldFromCleanArm ?? 0;
|
|
232
233
|
if (withheld > 0) {
|
|
233
234
|
const neverSent = run.withheldNeverSent ?? 0;
|
|
234
235
|
const sent = Math.max(0, withheld - neverSent);
|
|
235
|
-
announce([
|
|
236
|
+
await announce([
|
|
236
237
|
` ${withheld} externally-marked entr${withheld === 1 ? "y was" : "ies were"} withheld from the clean products' prompts.` +
|
|
237
238
|
(sent > 0 ? ` ${sent} of those ${sent === 1 ? "was" : "were"} sent to the model in a separate marked-only call.` : "") +
|
|
238
239
|
(neverSent > 0 ? ` ${neverSent} ${neverSent === 1 ? "was" : "were"} not sent to the model at all.` : ""),
|
|
239
240
|
]);
|
|
240
241
|
}
|
|
241
242
|
};
|
|
242
|
-
const settle = (outcome, drive, stopDetail) => {
|
|
243
|
+
const settle = async (outcome, drive, stopDetail) => {
|
|
243
244
|
run.state = "settled";
|
|
244
245
|
run.outcome = outcome;
|
|
245
246
|
run.settledAt = now();
|
|
246
247
|
if (stopDetail !== undefined)
|
|
247
248
|
run.stopDetail = stopDetail;
|
|
248
249
|
run.residue = run.residue ?? drive?.stop?.fuseBlocked;
|
|
249
|
-
writeDriverRun(
|
|
250
|
+
await writeDriverRun(store, run);
|
|
250
251
|
if (outcome === "converged") {
|
|
251
252
|
try {
|
|
252
|
-
|
|
253
|
-
const row =
|
|
253
|
+
await store.transact([], (tx) => {
|
|
254
|
+
const row = tx.scopes[scope];
|
|
254
255
|
if (row === undefined || !recommendationUnconsumed(row))
|
|
255
|
-
return { result: undefined };
|
|
256
|
+
return { writeGate: false, result: undefined };
|
|
256
257
|
row.lastRunAt = now();
|
|
257
|
-
return {
|
|
258
|
+
return { writeGate: true, result: undefined };
|
|
258
259
|
});
|
|
259
260
|
}
|
|
260
261
|
catch (err) {
|
|
@@ -267,14 +268,14 @@ export async function runMemoryConsolidationDriver(engine, scope, opts) {
|
|
|
267
268
|
notices.push(notice);
|
|
268
269
|
if (opts.onNotice !== undefined)
|
|
269
270
|
deliverEngineNotice(opts.onNotice, notice);
|
|
270
|
-
announce([notice.message]);
|
|
271
|
+
await announce([notice.message]);
|
|
271
272
|
}
|
|
272
273
|
if ((run.withheldFromCleanArm ?? 0) > 0) {
|
|
273
274
|
const withheldNotice = memoryConsolidationWithheldNotice({ scope, runId: run.runId, withheld: run.withheldFromCleanArm, neverSent: run.withheldNeverSent ?? 0 });
|
|
274
275
|
notices.push(withheldNotice);
|
|
275
276
|
if (opts.onNotice !== undefined)
|
|
276
277
|
deliverEngineNotice(opts.onNotice, withheldNotice);
|
|
277
|
-
announce([withheldNotice.message]);
|
|
278
|
+
await announce([withheldNotice.message]);
|
|
278
279
|
}
|
|
279
280
|
return {
|
|
280
281
|
runId: run.runId,
|
|
@@ -325,7 +326,7 @@ export async function runMemoryConsolidationDriver(engine, scope, opts) {
|
|
|
325
326
|
catch (err) {
|
|
326
327
|
if (codeOf(err) === "config.memory_consolidation_driver")
|
|
327
328
|
throw err;
|
|
328
|
-
announce([
|
|
329
|
+
await announce([
|
|
329
330
|
`memory consolidation driver run ${run.runId} for scope ${inlineUntrusted(scope, 80)} ATTEMPTED to send memory content to the configured consolidation model: ${egressSeat} — the seat threw before any answer was recorded, so whether any content reached the provider is NOT observable from here; up to ${candidates.length} candidate(s) were in flight, each rendered as its name, description and body. Treat this as a possible transmission.`,
|
|
330
331
|
]);
|
|
331
332
|
throw new DriverMintFailure(`the model seat failed during the mint: ${thrownText(err)}`);
|
|
@@ -337,7 +338,7 @@ export async function runMemoryConsolidationDriver(engine, scope, opts) {
|
|
|
337
338
|
run.usage.completionTokens += c.usage?.completionTokens ?? 0;
|
|
338
339
|
}
|
|
339
340
|
if (!minted.ok) {
|
|
340
|
-
announceMintEgress(transcript.length, candidates.length);
|
|
341
|
+
await announceMintEgress(transcript.length, candidates.length);
|
|
341
342
|
throw new DriverMintFailure(minted.reason);
|
|
342
343
|
}
|
|
343
344
|
const plan = minted.plan;
|
|
@@ -346,7 +347,7 @@ export async function runMemoryConsolidationDriver(engine, scope, opts) {
|
|
|
346
347
|
const markedServed = (plan.servedCandidates ?? []).filter((r) => r.marked).length;
|
|
347
348
|
run.withheldNeverSent = Math.max(0, plan.withheldFromCleanArm - markedServed);
|
|
348
349
|
}
|
|
349
|
-
announceMintEgress(transcript.length, candidates.length, plan);
|
|
350
|
+
await announceMintEgress(transcript.length, candidates.length, plan);
|
|
350
351
|
run.usage.retries += plan.minting.parseRepairs.retries;
|
|
351
352
|
run.usage.truncations += plan.minting.parseRepairs.lengthCapped.length;
|
|
352
353
|
run.repairs = {
|
|
@@ -367,8 +368,8 @@ export async function runMemoryConsolidationDriver(engine, scope, opts) {
|
|
|
367
368
|
const purity = detectCleanArmVerbatimLeak(plan);
|
|
368
369
|
if (purity.findings.length > 0) {
|
|
369
370
|
run.planArchive = distillerPlanArchiveName(run.runId, run.attempt);
|
|
370
|
-
writeDriverRun(
|
|
371
|
-
|
|
371
|
+
await writeDriverRun(store, run);
|
|
372
|
+
await store.archiveMint(run.runId, run.attempt, plan);
|
|
372
373
|
const where = [...new Set(purity.findings.map((f) => `#${f.productIndex}.${f.field}`))].sort();
|
|
373
374
|
throw new DriverPurityViolation(`the exposure partition's clean arm is not clean: ${purity.findings.length} verbatim marked-side byte sequence(s) surfaced in ${new Set(purity.findings.map((f) => f.productIndex)).size} product(s) that would commit UNMARKED, across ${purity.scannedProducts} scanned product(s) against ${purity.markedUniqueShingles} marked-unique shingle(s). Locations (product index into the archived plan . field): ${where.slice(0, 8).join(", ")}${where.length > 8 ? ", …" : ""}. The whole mint is discarded with zero writes; NO model-authored bytes (neither the offending text nor the product keys) are reproduced here — re-run detectCleanArmVerbatimLeak over the archived plan ${run.planArchive} for the byte-level witness.`);
|
|
374
375
|
}
|
|
@@ -379,8 +380,8 @@ export async function runMemoryConsolidationDriver(engine, scope, opts) {
|
|
|
379
380
|
...(plan.mintExposure !== undefined ? { mintExposure: plan.mintExposure } : {}),
|
|
380
381
|
...(plan.servedCandidates !== undefined ? { servedCandidates: plan.servedCandidates } : {}),
|
|
381
382
|
};
|
|
382
|
-
writeDriverRun(
|
|
383
|
-
|
|
383
|
+
await writeDriverRun(store, run);
|
|
384
|
+
await store.archiveMint(run.runId, run.attempt, plan);
|
|
384
385
|
}
|
|
385
386
|
const roster = run.planCache?.servedCandidates;
|
|
386
387
|
if (roster !== undefined && roster.length > 0) {
|
|
@@ -400,7 +401,7 @@ export async function runMemoryConsolidationDriver(engine, scope, opts) {
|
|
|
400
401
|
violations.push(`${rowR.id}: marked flag flipped since the mint (${String(rowR.marked)} -> ${String(off.marked)})`);
|
|
401
402
|
continue;
|
|
402
403
|
}
|
|
403
|
-
ownFold ??= collectRunFoldEvidence(engine, scope, run.requestId);
|
|
404
|
+
ownFold ??= await collectRunFoldEvidence(engine, scope, run.requestId);
|
|
404
405
|
if (ownFold.unreadable !== undefined)
|
|
405
406
|
continue;
|
|
406
407
|
if (!ownFold.targets.has(rowR.id))
|
|
@@ -441,7 +442,7 @@ export async function runMemoryConsolidationDriver(engine, scope, opts) {
|
|
|
441
442
|
};
|
|
442
443
|
let firstSnapshotOfNewRun = !resumed;
|
|
443
444
|
const takeSnapshot = async (_cycle) => {
|
|
444
|
-
writeDriverRun(
|
|
445
|
+
await writeDriverRun(store, run);
|
|
445
446
|
let force = !firstSnapshotOfNewRun;
|
|
446
447
|
let throttleWaits = 0;
|
|
447
448
|
let busyWaits = 0;
|
|
@@ -461,10 +462,10 @@ export async function runMemoryConsolidationDriver(engine, scope, opts) {
|
|
|
461
462
|
if (throttleWaits >= MAX_THROTTLE_WAITS_PER_SNAPSHOT)
|
|
462
463
|
throw err;
|
|
463
464
|
throttleWaits += 1;
|
|
464
|
-
const lastRunAt = engine.readConsolidationGate(scope)?.lastRunAt;
|
|
465
|
+
const lastRunAt = (await engine.readConsolidationGate(scope))?.lastRunAt;
|
|
465
466
|
const until = (lastRunAt ?? now()) + throttleWindowMs;
|
|
466
467
|
run.nextEligibleAt = until;
|
|
467
|
-
writeDriverRun(
|
|
468
|
+
await writeDriverRun(store, run);
|
|
468
469
|
const waitMs = Math.max(1, until - now());
|
|
469
470
|
await sleep(waitMs);
|
|
470
471
|
continue;
|
|
@@ -497,7 +498,7 @@ export async function runMemoryConsolidationDriver(engine, scope, opts) {
|
|
|
497
498
|
maxCycles: opts.maxCycles ?? 64,
|
|
498
499
|
takeSnapshot,
|
|
499
500
|
writeGate,
|
|
500
|
-
onCycle: (row) => {
|
|
501
|
+
onCycle: async (row) => {
|
|
501
502
|
cyclesSeen.push(row);
|
|
502
503
|
if (row.committed.products > 0 || row.committed.superseded > 0)
|
|
503
504
|
run.cyclesDone += 1;
|
|
@@ -505,21 +506,21 @@ export async function runMemoryConsolidationDriver(engine, scope, opts) {
|
|
|
505
506
|
if (row.planId !== undefined)
|
|
506
507
|
run.planIds.push(row.planId);
|
|
507
508
|
run.nextEligibleAt = now() + throttleWindowMs;
|
|
508
|
-
writeDriverRun(
|
|
509
|
+
await writeDriverRun(store, run);
|
|
509
510
|
},
|
|
510
511
|
});
|
|
511
512
|
}
|
|
512
513
|
catch (err) {
|
|
513
514
|
if (err instanceof DriverMintFailure) {
|
|
514
|
-
announce([`memory consolidation driver run ${run.runId} for scope ${inlineUntrusted(scope, 80)} FAILED before any write: ${extensionWords(err.detail, 300)}`]);
|
|
515
|
+
await announce([`memory consolidation driver run ${run.runId} for scope ${inlineUntrusted(scope, 80)} FAILED before any write: ${extensionWords(err.detail, 300)}`]);
|
|
515
516
|
return settle("driver_failed", undefined, err.detail);
|
|
516
517
|
}
|
|
517
518
|
if (err instanceof DriverPurityViolation) {
|
|
518
|
-
announce([`memory consolidation driver run ${run.runId} for scope ${inlineUntrusted(scope, 80)} REFUSED on the clean-arm purity gate (no writes): ${extensionWords(err.detail, 300)}`]);
|
|
519
|
+
await announce([`memory consolidation driver run ${run.runId} for scope ${inlineUntrusted(scope, 80)} REFUSED on the clean-arm purity gate (no writes): ${extensionWords(err.detail, 300)}`]);
|
|
519
520
|
return settle("purity_violation", undefined, err.detail);
|
|
520
521
|
}
|
|
521
522
|
if (err instanceof MintInvalidated) {
|
|
522
|
-
announce([`memory consolidation driver run ${run.runId} for scope ${inlineUntrusted(scope, 80)} MINT INVALIDATED: ${extensionWords(err.detail, 300)}`]);
|
|
523
|
+
await announce([`memory consolidation driver run ${run.runId} for scope ${inlineUntrusted(scope, 80)} MINT INVALIDATED: ${extensionWords(err.detail, 300)}`]);
|
|
523
524
|
if (run.residue === undefined && err.residue.length > 0)
|
|
524
525
|
run.residue = err.residue;
|
|
525
526
|
const partial = {
|
|
@@ -546,10 +547,10 @@ export async function runMemoryConsolidationDriver(engine, scope, opts) {
|
|
|
546
547
|
return settle("driver_failed", drive, `the drive reached a fixpoint but the account does not balance: ${plannedMembers} planned member(s), ${supersededAttested} superseded attested for this run (row account ${rowAccount}, store delta ${run.foldBaseline !== undefined ? storeAccount : "unavailable — the row predates the store anchor"}), ${residueTargets} in named residue — ${plannedMembers - accounted} member(s) left the candidate set without a fold the store attests (deleted or excluded mid-run${run.foldBaseline !== undefined ? "" : ", or folded in a window whose account write did not survive"}); their entries stand (or revive with their exclusion), and a fresh run re-mints over the current library`);
|
|
547
548
|
}
|
|
548
549
|
if (plannedIds.length > 0) {
|
|
549
|
-
const evidence = collectRunFoldEvidence(engine, scope, run.requestId);
|
|
550
|
+
const evidence = await collectRunFoldEvidence(engine, scope, run.requestId);
|
|
550
551
|
if (evidence.skipped.length > 0) {
|
|
551
552
|
const named = evidence.skipped.slice(0, 5).map((s) => `${s.planId} (${s.state})`).join(", ");
|
|
552
|
-
announce([
|
|
553
|
+
await announce([
|
|
553
554
|
`memory consolidation conservation wall for scope ${inlineUntrusted(scope, 80)}: ${evidence.skipped.length} same-scope plan file(s) answered unreadable and were SKIPPED as foreign to run ${run.runId} — they attest nothing for this run and need out-of-band repair: ${named}${evidence.skipped.length > 5 ? ", …" : ""}`,
|
|
554
555
|
]);
|
|
555
556
|
}
|
|
@@ -573,9 +574,9 @@ export async function runMemoryConsolidationDriver(engine, scope, opts) {
|
|
|
573
574
|
run.residue = [...(drive.stop?.fuseBlocked ?? []), ...driverResidue];
|
|
574
575
|
const plannedAtStop = (run.planCache?.products ?? []).some((p) => (p.inputIds?.length ?? 0) > 0);
|
|
575
576
|
if (plannedAtStop) {
|
|
576
|
-
const evidence = collectRunFoldEvidence(engine, scope, run.requestId);
|
|
577
|
+
const evidence = await collectRunFoldEvidence(engine, scope, run.requestId);
|
|
577
578
|
if (evidence.unreadable !== undefined) {
|
|
578
|
-
announce([
|
|
579
|
+
await announce([
|
|
579
580
|
`memory consolidation driver run ${run.runId} for scope ${inlineUntrusted(scope, 80)}: plan ${evidence.unreadable} — one of THIS run's own cycles — answered ${evidence.unreadableState} (control-plane damage on run-owned evidence, not a transient race); the run stops non-converged with the damage disclosed, and a fresh run re-mints over the current bytes`,
|
|
580
581
|
]);
|
|
581
582
|
}
|
|
@@ -589,16 +590,16 @@ export async function runMemoryConsolidationDriver(engine, scope, opts) {
|
|
|
589
590
|
return settle("parked", drive, stop.reason);
|
|
590
591
|
return settle("refused", drive, stop?.reason ?? "the drive stopped without a stated reason");
|
|
591
592
|
}
|
|
592
|
-
function collectRunFoldEvidence(engine, scope, requestId) {
|
|
593
|
+
async function collectRunFoldEvidence(engine, scope, requestId) {
|
|
593
594
|
const cycleId = new RegExp(`^${requestId.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}-c\\d+$`);
|
|
594
595
|
const targets = new Set();
|
|
595
596
|
const skipped = [];
|
|
596
|
-
for (const summary of engine.listConsolidationPlans()) {
|
|
597
|
+
for (const summary of await engine.listConsolidationPlans()) {
|
|
597
598
|
if (summary.corrupt === true)
|
|
598
599
|
continue;
|
|
599
600
|
if (summary.scope !== scope)
|
|
600
601
|
continue;
|
|
601
|
-
const ev = engine.readConsolidationPlanFoldEvidence(summary.planId);
|
|
602
|
+
const ev = await engine.readConsolidationPlanFoldEvidence(summary.planId);
|
|
602
603
|
if (ev.state !== "ok") {
|
|
603
604
|
if (ev.state === "corrupt" && ev.requestId !== undefined && cycleId.test(ev.requestId)) {
|
|
604
605
|
return { targets, unreadable: summary.planId, unreadableState: ev.state, skipped };
|
|
@@ -615,19 +616,19 @@ function collectRunFoldEvidence(engine, scope, requestId) {
|
|
|
615
616
|
}
|
|
616
617
|
async function recoverSeat(engine, scope, { sleep, windowMs, writeGate }) {
|
|
617
618
|
await engine.reconcileConsolidation(scope, { writeGate });
|
|
618
|
-
let seat = engine.readConsolidationGate(scope)?.openPlanId;
|
|
619
|
+
let seat = (await engine.readConsolidationGate(scope))?.openPlanId;
|
|
619
620
|
if (seat === undefined)
|
|
620
621
|
return undefined;
|
|
621
|
-
const summary = engine.listConsolidationPlans().find((p) => p.planId === seat);
|
|
622
|
+
const summary = (await engine.listConsolidationPlans()).find((p) => p.planId === seat);
|
|
622
623
|
if (summary?.corrupt === true || summary?.state === "conflict") {
|
|
623
624
|
return `plan ${seat} holds the ${JSON.stringify(scope)} seat in a ${summary.corrupt === true ? "corrupt" : "conflict"} state — resolveConsolidationPlan(planId, "retry" | "discard") is the host valve; the run parks rather than stacking a second plan on the seat`;
|
|
624
625
|
}
|
|
625
626
|
await sleep(windowMs);
|
|
626
627
|
await engine.reconcileConsolidation(scope, { writeGate });
|
|
627
|
-
seat = engine.readConsolidationGate(scope)?.openPlanId;
|
|
628
|
+
seat = (await engine.readConsolidationGate(scope))?.openPlanId;
|
|
628
629
|
if (seat === undefined)
|
|
629
630
|
return undefined;
|
|
630
|
-
const again = engine.listConsolidationPlans().find((p) => p.planId === seat);
|
|
631
|
+
const again = (await engine.listConsolidationPlans()).find((p) => p.planId === seat);
|
|
631
632
|
if (again?.corrupt === true || again?.state === "conflict") {
|
|
632
633
|
return `plan ${seat} holds the ${JSON.stringify(scope)} seat in a ${again.corrupt === true ? "corrupt" : "conflict"} state — resolveConsolidationPlan(planId, "retry" | "discard") is the host valve; the run parks rather than stacking a second plan on the seat`;
|
|
633
634
|
}
|