@remnic/core 10.0.166 → 10.0.167
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/dist/access-admin-ops-surface.js +5 -5
- package/dist/access-cli.js +5 -5
- package/dist/access-extraction-force-flush-preempt.js +5 -5
- package/dist/access-extraction-force-flush.js +5 -5
- package/dist/access-http-briefing.js +5 -5
- package/dist/access-http-query.js +5 -5
- package/dist/access-http.js +5 -5
- package/dist/access-identity-continuity-surface.js +5 -5
- package/dist/access-lcm-surface.js +5 -5
- package/dist/access-mcp.js +5 -5
- package/dist/access-observe-write-surface.js +5 -5
- package/dist/access-operations-batch.js +5 -5
- package/dist/access-operations.js +5 -5
- package/dist/access-recall-concurrency.js +5 -5
- package/dist/access-recall-response.js +5 -5
- package/dist/access-recall-surface.js +5 -5
- package/dist/access-service.js +5 -5
- package/dist/{chunk-47LDDGAL.js → chunk-5PUZV73Z.js} +2 -2
- package/dist/{chunk-7QF26EWO.js → chunk-BFPQJNFZ.js} +1 -1
- package/dist/{chunk-7QF26EWO.js.map → chunk-BFPQJNFZ.js.map} +1 -1
- package/dist/{chunk-E6EESRJ6.js → chunk-C5QYWM6F.js} +3 -3
- package/dist/{chunk-2FCZIWRI.js → chunk-IE2ZLO3R.js} +4 -4
- package/dist/{chunk-XKZBZOKV.js → chunk-JIF22AXI.js} +18 -1
- package/dist/chunk-JIF22AXI.js.map +1 -0
- package/dist/{chunk-JFZZDMEZ.js → chunk-U3BCW7GX.js} +2 -2
- package/dist/cli.js +5 -5
- package/dist/connectors/droid-mcp.d.ts +4 -3
- package/dist/connectors/droid-mcp.d.ts.map +1 -1
- package/dist/connectors/index.js +1 -1
- package/dist/explicit-capture.js +5 -5
- package/dist/extraction.js +3 -3
- package/dist/index.js +5 -5
- package/dist/memory-controller.d.ts +8 -0
- package/dist/memory-controller.d.ts.map +1 -1
- package/dist/memory-controller.js +1 -1
- package/dist/orchestration/backlog-scheduler.js +6 -6
- package/dist/orchestration/buffer-drain-runner.js +6 -6
- package/dist/orchestrator.js +5 -5
- package/dist/recall-navigation.js +5 -5
- package/dist/source-agent-qualifier.js +2 -2
- package/package.json +2 -2
- package/src/connectors/droid-mcp.test.ts +46 -0
- package/src/connectors/droid-mcp.ts +5 -5
- package/src/memory-controller.test.ts +38 -0
- package/src/memory-controller.ts +25 -2
- package/dist/chunk-XKZBZOKV.js.map +0 -1
- /package/dist/{chunk-47LDDGAL.js.map → chunk-5PUZV73Z.js.map} +0 -0
- /package/dist/{chunk-E6EESRJ6.js.map → chunk-C5QYWM6F.js.map} +0 -0
- /package/dist/{chunk-2FCZIWRI.js.map → chunk-IE2ZLO3R.js.map} +0 -0
- /package/dist/{chunk-JFZZDMEZ.js.map → chunk-U3BCW7GX.js.map} +0 -0
|
@@ -91,6 +91,16 @@ function harness(options?: {
|
|
|
91
91
|
events.push(event);
|
|
92
92
|
},
|
|
93
93
|
countShadowRecords: async () => options?.shadowRecords ?? 10,
|
|
94
|
+
trailingReceiptFailures: async () => {
|
|
95
|
+
let count = 0;
|
|
96
|
+
for (let i = events.length - 1; i >= 0; i -= 1) {
|
|
97
|
+
const event = events[i];
|
|
98
|
+
if (event.phase !== "outcome") continue;
|
|
99
|
+
if (!event.failureClass || event.failureClass === "record_failed") break;
|
|
100
|
+
count += 1;
|
|
101
|
+
}
|
|
102
|
+
return count;
|
|
103
|
+
},
|
|
94
104
|
},
|
|
95
105
|
executors:
|
|
96
106
|
options?.executors ??
|
|
@@ -245,6 +255,34 @@ test("failed receipt forces shadow on the next run", async () => {
|
|
|
245
255
|
assert.equal(second.executed, false);
|
|
246
256
|
});
|
|
247
257
|
|
|
258
|
+
test("a restarted coordinator keeps the receipt-failure demotion from recorded outcomes", async () => {
|
|
259
|
+
const h = harness({
|
|
260
|
+
executors: {
|
|
261
|
+
executeRecall: async () => ({ decisionId: "wrong-id", ok: true }),
|
|
262
|
+
},
|
|
263
|
+
});
|
|
264
|
+
const first = await new MemoryControllerCoordinator(h.deps).run({ prompt: RECALL_PROMPT });
|
|
265
|
+
assert.equal(first.executed, false);
|
|
266
|
+
|
|
267
|
+
const restarted = await new MemoryControllerCoordinator(h.deps).run({ prompt: RECALL_PROMPT });
|
|
268
|
+
assert.equal(restarted.effectiveMode, "shadow");
|
|
269
|
+
assert.ok(restarted.demotionReasons.includes("recent_receipt_failures"));
|
|
270
|
+
assert.equal(restarted.executed, false);
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
test("an unreadable receipt-failure history keeps the gate closed", async () => {
|
|
274
|
+
const h = harness();
|
|
275
|
+
h.deps.recorder = {
|
|
276
|
+
...h.deps.recorder!,
|
|
277
|
+
trailingReceiptFailures: async () => {
|
|
278
|
+
throw new Error("history unavailable");
|
|
279
|
+
},
|
|
280
|
+
};
|
|
281
|
+
const result = await new MemoryControllerCoordinator(h.deps).run({ prompt: RECALL_PROMPT });
|
|
282
|
+
assert.equal(result.effectiveMode, "shadow");
|
|
283
|
+
assert.ok(result.demotionReasons.includes("recent_receipt_failures"));
|
|
284
|
+
});
|
|
285
|
+
|
|
248
286
|
test("executor error or missing executor records a failure class and demotes next run", async () => {
|
|
249
287
|
const h = harness({
|
|
250
288
|
executors: {
|
package/src/memory-controller.ts
CHANGED
|
@@ -99,6 +99,12 @@ export interface MemoryControllerRecorder {
|
|
|
99
99
|
record(event: MemoryControllerEvent): Promise<void>;
|
|
100
100
|
/** Prior shadow choice records; active promotion requires shadow history. */
|
|
101
101
|
countShadowRecords(): Promise<number>;
|
|
102
|
+
/**
|
|
103
|
+
* Failed outcomes (executor_error, bad_receipt, no_executor) at the end of
|
|
104
|
+
* the recorded stream, newest first, stopping at the first success. A new
|
|
105
|
+
* coordinator seeds its receipt-failure gate from this count.
|
|
106
|
+
*/
|
|
107
|
+
trailingReceiptFailures?(): Promise<number>;
|
|
102
108
|
}
|
|
103
109
|
|
|
104
110
|
export interface MemoryControllerConfig {
|
|
@@ -338,6 +344,7 @@ export class MemoryControllerCoordinator {
|
|
|
338
344
|
private readonly deps: MemoryControllerDeps;
|
|
339
345
|
private readonly clock: () => Date;
|
|
340
346
|
private consecutiveReceiptFailures = 0;
|
|
347
|
+
private receiptFailuresSeeded = false;
|
|
341
348
|
|
|
342
349
|
constructor(deps: MemoryControllerDeps) {
|
|
343
350
|
this.deps = deps;
|
|
@@ -379,6 +386,7 @@ export class MemoryControllerCoordinator {
|
|
|
379
386
|
let demotionReasons: string[] = [];
|
|
380
387
|
let effectiveMode = requestedMode;
|
|
381
388
|
if (requestedMode === "active") {
|
|
389
|
+
await this.seedReceiptFailures();
|
|
382
390
|
demotionReasons = await evaluateActiveGates({
|
|
383
391
|
config: this.deps.config,
|
|
384
392
|
reportReader: this.deps.reportReader,
|
|
@@ -527,6 +535,23 @@ export class MemoryControllerCoordinator {
|
|
|
527
535
|
}
|
|
528
536
|
}
|
|
529
537
|
|
|
538
|
+
private async seedReceiptFailures(): Promise<void> {
|
|
539
|
+
if (this.receiptFailuresSeeded) return;
|
|
540
|
+
this.receiptFailuresSeeded = true;
|
|
541
|
+
const reader = this.deps.recorder?.trailingReceiptFailures;
|
|
542
|
+
if (!reader) return;
|
|
543
|
+
let recorded: number;
|
|
544
|
+
try {
|
|
545
|
+
recorded = await reader.call(this.deps.recorder);
|
|
546
|
+
} catch {
|
|
547
|
+
// Unknown receipt health keeps the gate closed.
|
|
548
|
+
recorded = 1;
|
|
549
|
+
}
|
|
550
|
+
if (Number.isFinite(recorded) && recorded > this.consecutiveReceiptFailures) {
|
|
551
|
+
this.consecutiveReceiptFailures = recorded;
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
|
|
530
555
|
private async recordOutcome(event: MemoryControllerEvent): Promise<void> {
|
|
531
556
|
if (!this.deps.recorder) return;
|
|
532
557
|
await this.deps.recorder.record(event);
|
|
@@ -543,5 +568,3 @@ function isValidReceipt(receipt: unknown, decisionId: string): boolean {
|
|
|
543
568
|
);
|
|
544
569
|
}
|
|
545
570
|
|
|
546
|
-
// ponytail: consecutiveReceiptFailures is per-instance, not persisted; persist
|
|
547
|
-
// with the recorder if coordinator restarts must carry receipt health forward.
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/memory-controller.ts"],"sourcesContent":["import { createHash, randomUUID } from \"node:crypto\";\nimport { planRecallMode } from \"./intent.js\";\nimport { evaluateMemoryActionPolicy } from \"./memory-action-policy.js\";\nimport type { RuntimePolicyValues } from \"./policy-runtime.js\";\nimport type { UtilityRuntimeValues } from \"./utility-runtime.js\";\nimport type { MemoryActionEligibilityContext, MemoryActionType, RecallPlanMode } from \"./types.js\";\n\n/**\n * Gated unified memory controller (#2348).\n *\n * One state enters, one choice leaves. Host-free: every effectful collaborator\n * (adapters, executors, report reader, recorder, telemetry, clock) is injected.\n * The coordinator creates no store and claims no counterfactual lift.\n */\n\nexport type MemoryControllerMode = \"off\" | \"shadow\" | \"active\";\n\nexport type MemoryControllerActionFamily = \"persistent_memory\" | \"recall\" | \"active_context\" | \"no_op\";\n\n/** #2347 adapter seam: the host supplies plans, core only picks one. */\nexport interface ActiveContextMessage {\n id: string;\n text: string;\n}\n\nexport interface ActiveContextPlan {\n transform: \"SUMMARY\" | \"FILTER\";\n messageIds: string[];\n planId: string;\n}\n\nexport interface ActiveContextAdapter {\n plan(messages: ActiveContextMessage[]): ActiveContextPlan | null;\n}\n\n/** #2345 report + #2346 paired-seed evidence, read through one port. */\nexport interface MemoryControllerEvidenceReport {\n status: \"pass\" | \"fail\";\n version: string;\n configHash: string;\n generatedAt: string;\n /** sha256 over the canonical report fields; recomputed on verification. */\n reportHash: string;\n}\n\nexport interface MemoryControllerPairedSeedEvidence {\n status: \"pass\" | \"fail\";\n seedCount: number;\n generatedAt: string;\n}\n\nexport interface MemoryControllerEvidence {\n report: MemoryControllerEvidenceReport;\n pairedSeed: MemoryControllerPairedSeedEvidence;\n}\n\nexport interface MemoryControllerReportReader {\n read(): Promise<MemoryControllerEvidence | null>;\n}\n\nexport interface MemoryControllerReceipt {\n decisionId: string;\n ok: boolean;\n detail?: string;\n}\n\nexport interface MemoryControllerExecutors {\n executePersistentMemory?(input: {\n decisionId: string;\n action: MemoryActionType;\n eligibility: MemoryActionEligibilityContext;\n stateHash: string;\n }): Promise<MemoryControllerReceipt>;\n executeRecall?(input: { decisionId: string; mode: RecallPlanMode }): Promise<MemoryControllerReceipt>;\n executeActiveContext?(input: {\n decisionId: string;\n plan: ActiveContextPlan;\n }): Promise<MemoryControllerReceipt>;\n}\n\nexport interface MemoryControllerEvent {\n schemaVersion: 1;\n phase: \"choice\" | \"outcome\";\n decisionId: string;\n timestamp: string;\n requestedMode: MemoryControllerMode;\n effectiveMode: MemoryControllerMode;\n stateHash: string;\n choice: MemoryControllerChoice;\n scores: Record<MemoryControllerActionFamily, number>;\n executed: boolean;\n reviewOnly?: boolean;\n demotionReasons?: string[];\n failureClass?: \"record_failed\" | \"executor_error\" | \"bad_receipt\" | \"no_executor\";\n receipt?: MemoryControllerReceipt;\n}\n\nexport interface MemoryControllerRecorder {\n record(event: MemoryControllerEvent): Promise<void>;\n /** Prior shadow choice records; active promotion requires shadow history. */\n countShadowRecords(): Promise<number>;\n}\n\nexport interface MemoryControllerConfig {\n mode: MemoryControllerMode;\n /** Expected #2345 report schema version. */\n reportVersion: string;\n /** Evidence older than this is stale and forces shadow. */\n evidenceMaxAgeMs: number;\n /** Paired-seed arms must cover at least this many seeds (#2346). */\n minPairedSeeds: number;\n /** Active promotion requires at least this many prior shadow records. */\n shadowMinRecords: number;\n}\n\nexport interface MemoryControllerState {\n prompt: string;\n persistentMemoryCandidate?: {\n action: MemoryActionType;\n eligibility: MemoryActionEligibilityContext;\n };\n contextMessages?: ActiveContextMessage[];\n /** 0..1 host-measured context pressure. */\n contextPressure?: number;\n}\n\nexport type MemoryControllerChoice =\n | { family: \"persistent_memory\"; action: MemoryActionType; eligibility: MemoryActionEligibilityContext }\n | { family: \"recall\"; mode: RecallPlanMode }\n | { family: \"active_context\"; plan: ActiveContextPlan }\n | { family: \"no_op\" };\n\nexport interface MemoryControllerRunResult {\n decisionId: string;\n requestedMode: MemoryControllerMode;\n effectiveMode: MemoryControllerMode;\n stateHash: string;\n choice: MemoryControllerChoice;\n scores: Record<MemoryControllerActionFamily, number>;\n executed: boolean;\n reviewOnly: boolean;\n recorded: boolean;\n receipt?: MemoryControllerReceipt;\n demotionReasons: string[];\n}\n\nexport interface MemoryControllerDeps {\n config: MemoryControllerConfig;\n reportReader?: MemoryControllerReportReader;\n recorder?: MemoryControllerRecorder;\n executors?: MemoryControllerExecutors;\n activeContextAdapter?: ActiveContextAdapter;\n policyRuntime?: { loadRuntimeValues(): Promise<RuntimePolicyValues | null> };\n readUtilityRuntime?: () => Promise<UtilityRuntimeValues | null>;\n telemetry?: (event: MemoryControllerEvent) => void;\n clock?: () => Date;\n}\n\nconst NO_OP_FLOOR = 0.35;\n/** `discard` (and any destructive change) stays review-only in active mode. */\nconst REVIEW_ONLY_ACTIONS: Partial<Record<MemoryActionType, true>> = { discard: true };\n\nexport function controllerConfigHash(config: MemoryControllerConfig): string {\n return sha256(\n JSON.stringify({\n mode: config.mode,\n reportVersion: config.reportVersion,\n evidenceMaxAgeMs: config.evidenceMaxAgeMs,\n minPairedSeeds: config.minPairedSeeds,\n shadowMinRecords: config.shadowMinRecords,\n })\n );\n}\n\nexport function hashControllerState(state: MemoryControllerState): string {\n return sha256(\n JSON.stringify({\n prompt: state.prompt,\n persistentMemoryCandidate: state.persistentMemoryCandidate ?? null,\n contextMessages: state.contextMessages ?? null,\n contextPressure: state.contextPressure ?? null,\n })\n );\n}\n\n/** Canonical #2345 report hash; producers sign with this, the controller verifies. */\nexport function computeEvidenceReportHash(fields: {\n status: MemoryControllerEvidenceReport[\"status\"];\n version: string;\n configHash: string;\n generatedAt: string;\n}): string {\n return sha256(JSON.stringify(fields));\n}\n\n/** Verifies the #2345 report hash over its canonical fields. */\nexport function verifyEvidenceReport(report: MemoryControllerEvidenceReport): boolean {\n return (\n computeEvidenceReportHash({\n status: report.status,\n version: report.version,\n configHash: report.configHash,\n generatedAt: report.generatedAt,\n }) === report.reportHash\n );\n}\n\nfunction sha256(input: string): string {\n return createHash(\"sha256\").update(input).digest(\"hex\");\n}\n\nfunction clampScore(value: number): number {\n if (!Number.isFinite(value)) return Number.NaN;\n return Math.max(0, Math.min(1, value));\n}\n\n/**\n * Bad scores fail closed to `no_op`.\n */\nexport function chooseAction(input: {\n state: MemoryControllerState;\n activeContextAdapter?: ActiveContextAdapter;\n runtimeValues?: RuntimePolicyValues | null;\n utilityValues?: UtilityRuntimeValues | null;\n}): { choice: MemoryControllerChoice; scores: Record<MemoryControllerActionFamily, number> } {\n const { state, activeContextAdapter, runtimeValues, utilityValues } = input;\n\n // recall: current recall path.\n const recallMode = planRecallMode(state.prompt ?? \"\");\n const recallScore =\n recallMode === \"no_recall\" ? 0 : recallMode === \"minimal\" ? 0.4 : 0.6 + 0.2 * (runtimeValues?.recencyWeight ?? 0);\n\n // persistent_memory: current action path + policy.\n let persistentScore = 0;\n const candidate = state.persistentMemoryCandidate;\n if (candidate) {\n const policy = evaluateMemoryActionPolicy({\n action: candidate.action,\n eligibility: candidate.eligibility,\n options: { actionsEnabled: true, maxCompressionTokensPerHour: Number.POSITIVE_INFINITY },\n });\n if (policy.decision === \"allow\") {\n persistentScore = 0.4 + 0.4 * (candidate.eligibility.confidence ?? 0);\n } else if (policy.decision === \"defer\") {\n persistentScore = 0.2;\n }\n // Utility runtime may suppress the persistent family.\n if (utilityValues && utilityValues.rankingSuppressMultiplier > 1) {\n persistentScore *= 1 / utilityValues.rankingSuppressMultiplier;\n }\n }\n\n // active_context: current context path through the #2347 adapter.\n let contextScore = 0;\n let contextPlan: ActiveContextPlan | null = null;\n const pressure = state.contextPressure;\n if (activeContextAdapter && typeof pressure === \"number\" && Number.isFinite(pressure) && pressure > 0.5) {\n contextPlan = activeContextAdapter.plan(state.contextMessages ?? []);\n if (contextPlan && contextPlan.messageIds.length > 0) {\n contextScore = 0.3 + 0.5 * Math.max(0, Math.min(1, pressure));\n }\n }\n\n const scores: Record<MemoryControllerActionFamily, number> = {\n recall: clampScore(recallScore),\n persistent_memory: clampScore(persistentScore),\n active_context: clampScore(contextScore),\n no_op: NO_OP_FLOOR,\n };\n\n // Bad scores fail closed.\n if (Object.values(scores).some((score) => !Number.isFinite(score) || score < 0 || score > 1)) {\n return { choice: { family: \"no_op\" }, scores };\n }\n\n let choice: MemoryControllerChoice = { family: \"no_op\" };\n let best = scores.no_op;\n if (scores.recall > best) {\n best = scores.recall;\n choice = { family: \"recall\", mode: recallMode };\n }\n if (scores.persistent_memory > best) {\n best = scores.persistent_memory;\n choice = {\n family: \"persistent_memory\",\n action: candidate!.action,\n eligibility: candidate!.eligibility,\n };\n }\n if (scores.active_context > best) {\n choice = { family: \"active_context\", plan: contextPlan! };\n }\n return { choice, scores };\n}\n\n/** Returns the demotion reasons when active-mode gates fail; empty means go. */\nexport async function evaluateActiveGates(input: {\n config: MemoryControllerConfig;\n reportReader?: MemoryControllerReportReader;\n recorder?: MemoryControllerRecorder;\n consecutiveReceiptFailures: number;\n now: Date;\n}): Promise<string[]> {\n const { config, reportReader, recorder, consecutiveReceiptFailures, now } = input;\n const reasons: string[] = [];\n\n if (!reportReader) return [\"no_report_reader\"];\n\n const evidence = await reportReader.read();\n if (!evidence) return [\"no_evidence\"];\n\n const { report, pairedSeed } = evidence;\n if (report.status !== \"pass\") reasons.push(\"report_not_passing\");\n if (report.version !== config.reportVersion) reasons.push(\"report_version_mismatch\");\n if (report.configHash !== controllerConfigHash(config)) reasons.push(\"report_config_unbound\");\n if (!verifyEvidenceReport(report)) reasons.push(\"report_hash_invalid\");\n const reportGeneratedAt = Date.parse(report.generatedAt);\n if (!Number.isFinite(reportGeneratedAt) || now.getTime() - reportGeneratedAt > config.evidenceMaxAgeMs) {\n reasons.push(\"report_stale\");\n }\n\n if (pairedSeed.status !== \"pass\") reasons.push(\"paired_seed_not_passing\");\n if (pairedSeed.seedCount < config.minPairedSeeds) reasons.push(\"paired_seed_count_low\");\n const seedGeneratedAt = Date.parse(pairedSeed.generatedAt);\n if (!Number.isFinite(seedGeneratedAt) || now.getTime() - seedGeneratedAt > config.evidenceMaxAgeMs) {\n reasons.push(\"paired_seed_stale\");\n }\n\n const shadowRecords = recorder ? await recorder.countShadowRecords() : 0;\n if (shadowRecords < config.shadowMinRecords) reasons.push(\"shadow_history_insufficient\");\n\n if (consecutiveReceiptFailures > 0) reasons.push(\"recent_receipt_failures\");\n\n return reasons;\n}\n\nexport class MemoryControllerCoordinator {\n private readonly deps: MemoryControllerDeps;\n private readonly clock: () => Date;\n private consecutiveReceiptFailures = 0;\n\n constructor(deps: MemoryControllerDeps) {\n this.deps = deps;\n this.clock = deps.clock ?? (() => new Date());\n }\n\n async run(state: MemoryControllerState): Promise<MemoryControllerRunResult> {\n const decisionId = randomUUID();\n const stateHash = hashControllerState(state);\n const requestedMode = this.deps.config.mode;\n\n // off: no choice, no read, no write, no call.\n if (requestedMode === \"off\") {\n return {\n decisionId,\n requestedMode,\n effectiveMode: \"off\",\n stateHash,\n choice: { family: \"no_op\" },\n scores: { persistent_memory: 0, recall: 0, active_context: 0, no_op: 0 },\n executed: false,\n reviewOnly: false,\n recorded: false,\n demotionReasons: [\"mode_off\"],\n };\n }\n\n const [runtimeValues, utilityValues] = await Promise.all([\n this.deps.policyRuntime?.loadRuntimeValues() ?? null,\n this.deps.readUtilityRuntime?.() ?? null,\n ]);\n const { choice, scores } = chooseAction({\n state,\n activeContextAdapter: this.deps.activeContextAdapter,\n runtimeValues,\n utilityValues,\n });\n\n let demotionReasons: string[] = [];\n let effectiveMode = requestedMode;\n if (requestedMode === \"active\") {\n demotionReasons = await evaluateActiveGates({\n config: this.deps.config,\n reportReader: this.deps.reportReader,\n recorder: this.deps.recorder,\n consecutiveReceiptFailures: this.consecutiveReceiptFailures,\n now: this.clock(),\n });\n if (demotionReasons.length > 0) effectiveMode = \"shadow\";\n }\n\n const baseEvent: MemoryControllerEvent = {\n schemaVersion: 1,\n phase: \"choice\",\n decisionId,\n timestamp: this.clock().toISOString(),\n requestedMode,\n effectiveMode,\n stateHash,\n choice,\n scores,\n executed: false,\n ...(demotionReasons.length > 0 ? { demotionReasons } : {}),\n };\n\n // Shadow records before any active dispatch.\n let recorded = false;\n if (this.deps.recorder) {\n try {\n await this.deps.recorder.record(baseEvent);\n this.deps.telemetry?.(baseEvent);\n recorded = true;\n } catch {\n // Bad recorder stops work: no dispatch, no outcome event.\n return {\n decisionId,\n requestedMode,\n effectiveMode,\n stateHash,\n choice,\n scores,\n executed: false,\n reviewOnly: false,\n recorded: false,\n demotionReasons: [...demotionReasons, \"record_failed\"],\n };\n }\n }\n\n if (effectiveMode !== \"active\") {\n return {\n decisionId,\n requestedMode,\n effectiveMode,\n stateHash,\n choice,\n scores,\n executed: false,\n reviewOnly: false,\n recorded,\n demotionReasons,\n };\n }\n\n // First active scope: reversible actions only.\n if (choice.family === \"persistent_memory\" && REVIEW_ONLY_ACTIONS[choice.action]) {\n const event: MemoryControllerEvent = {\n ...baseEvent,\n phase: \"outcome\",\n reviewOnly: true,\n demotionReasons: [\"review_only_action\"],\n };\n await this.recordOutcome(event);\n return {\n decisionId,\n requestedMode,\n effectiveMode,\n stateHash,\n choice,\n scores,\n executed: false,\n reviewOnly: true,\n recorded,\n demotionReasons,\n };\n }\n\n const receipt = await this.dispatch(choice, stateHash, decisionId, baseEvent);\n return {\n decisionId,\n requestedMode,\n effectiveMode,\n stateHash,\n choice,\n scores,\n executed: receipt?.ok === true,\n reviewOnly: false,\n recorded,\n ...(receipt ? { receipt } : {}),\n demotionReasons,\n };\n }\n\n private async dispatch(\n choice: MemoryControllerChoice,\n stateHash: string,\n decisionId: string,\n baseEvent: MemoryControllerEvent\n ): Promise<MemoryControllerReceipt | undefined> {\n const executors = this.deps.executors ?? {};\n try {\n let receipt: MemoryControllerReceipt | undefined;\n if (choice.family === \"persistent_memory\") {\n if (!executors.executePersistentMemory) throw new Error(\"no_executor:persistent_memory\");\n receipt = await executors.executePersistentMemory({\n decisionId,\n action: choice.action,\n eligibility: choice.eligibility,\n stateHash,\n });\n } else if (choice.family === \"recall\") {\n if (!executors.executeRecall) throw new Error(\"no_executor:recall\");\n receipt = await executors.executeRecall({ decisionId, mode: choice.mode });\n } else if (choice.family === \"active_context\") {\n if (!executors.executeActiveContext) throw new Error(\"no_executor:active_context\");\n receipt = await executors.executeActiveContext({ decisionId, plan: choice.plan });\n } else {\n // no_op executed trivially; no executor call.\n receipt = { decisionId, ok: true };\n }\n if (!isValidReceipt(receipt, decisionId)) {\n this.consecutiveReceiptFailures += 1;\n await this.recordOutcome({ ...baseEvent, phase: \"outcome\", failureClass: \"bad_receipt\" });\n return undefined;\n }\n this.consecutiveReceiptFailures = 0;\n await this.recordOutcome({ ...baseEvent, phase: \"outcome\", executed: receipt.ok, receipt });\n return receipt;\n } catch (error) {\n this.consecutiveReceiptFailures += 1;\n await this.recordOutcome({\n ...baseEvent,\n phase: \"outcome\",\n failureClass: (error as Error)?.message?.startsWith(\"no_executor:\") ? \"no_executor\" : \"executor_error\",\n });\n return undefined;\n }\n }\n\n private async recordOutcome(event: MemoryControllerEvent): Promise<void> {\n if (!this.deps.recorder) return;\n await this.deps.recorder.record(event);\n this.deps.telemetry?.(event);\n }\n}\n\nfunction isValidReceipt(receipt: unknown, decisionId: string): boolean {\n return (\n typeof receipt === \"object\" &&\n receipt !== null &&\n (receipt as MemoryControllerReceipt).decisionId === decisionId &&\n typeof (receipt as MemoryControllerReceipt).ok === \"boolean\"\n );\n}\n\n// ponytail: consecutiveReceiptFailures is per-instance, not persisted; persist\n// with the recorder if coordinator restarts must carry receipt health forward.\n"],"mappings":";;;;;;;;AAAA,SAAS,YAAY,kBAAkB;AA8JvC,IAAM,cAAc;AAEpB,IAAM,sBAA+D,EAAE,SAAS,KAAK;AAE9E,SAAS,qBAAqB,QAAwC;AAC3E,SAAO;AAAA,IACL,KAAK,UAAU;AAAA,MACb,MAAM,OAAO;AAAA,MACb,eAAe,OAAO;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