@remnic/core 10.0.188 → 10.0.189
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 +2 -2
- package/dist/access-cli.js +2 -2
- package/dist/access-extraction-force-flush-preempt.js +2 -2
- package/dist/access-extraction-force-flush.d.ts.map +1 -1
- package/dist/access-extraction-force-flush.js +2 -2
- package/dist/access-http-briefing.js +2 -2
- package/dist/access-http-query.js +2 -2
- package/dist/access-http.js +2 -2
- package/dist/access-identity-continuity-surface.js +2 -2
- package/dist/access-lcm-surface.js +2 -2
- package/dist/access-mcp.js +2 -2
- package/dist/access-observe-helpers.d.ts +1 -4
- package/dist/access-observe-helpers.d.ts.map +1 -1
- package/dist/access-observe-helpers.js +1 -1
- package/dist/access-observe-write-surface.d.ts +0 -4
- package/dist/access-observe-write-surface.d.ts.map +1 -1
- package/dist/access-observe-write-surface.js +2 -2
- package/dist/access-operations-batch.js +2 -2
- package/dist/access-operations.js +2 -2
- package/dist/access-recall-concurrency.js +2 -2
- package/dist/access-recall-response.js +2 -2
- package/dist/access-recall-surface.js +2 -2
- package/dist/access-service.d.ts +0 -2
- package/dist/access-service.d.ts.map +1 -1
- package/dist/access-service.js +2 -2
- package/dist/{chunk-T3XOP7TA.js → chunk-7X6EZ2QB.js} +2 -2
- package/dist/{chunk-MTKSH7HY.js → chunk-ABPOW3SX.js} +44 -74
- package/dist/chunk-ABPOW3SX.js.map +1 -0
- package/dist/{chunk-CYTTY4M2.js → chunk-OPXK5IQU.js} +47 -47
- package/dist/chunk-OPXK5IQU.js.map +1 -0
- package/dist/cli.js +2 -2
- package/dist/explicit-capture.js +2 -2
- package/dist/index.js +2 -2
- package/dist/orchestration/backlog-scheduler.js +3 -3
- package/dist/orchestration/buffer-drain-runner.js +3 -3
- package/dist/orchestration/extraction-queue-coordinator.d.ts +14 -1
- package/dist/orchestration/extraction-queue-coordinator.d.ts.map +1 -1
- package/dist/orchestrator.js +2 -2
- package/dist/recall-navigation.js +2 -2
- package/package.json +2 -2
- package/src/access-extraction-force-flush-preempt-coordinator.test.ts +71 -0
- package/src/access-extraction-force-flush.ts +20 -56
- package/src/access-observe-helpers.test.ts +71 -88
- package/src/access-observe-helpers.ts +60 -73
- package/src/access-observe-write-surface.ts +1 -22
- package/src/access-service-observe-lcm-parity.test.ts +176 -89
- package/src/access-service-observe-scope.test.ts +18 -86
- package/src/access-service.ts +0 -13
- package/src/orchestration/extraction-queue-coordinator.ts +34 -3
- package/dist/chunk-CYTTY4M2.js.map +0 -1
- package/dist/chunk-MTKSH7HY.js.map +0 -1
- /package/dist/{chunk-T3XOP7TA.js.map → chunk-7X6EZ2QB.js.map} +0 -0
|
@@ -33,6 +33,7 @@ import { EngramAccessInputError, EngramAccessService } from "./access-service.js
|
|
|
33
33
|
import { EngramAccessForbiddenError } from "./access-errors.js";
|
|
34
34
|
import { Orchestrator } from "./orchestrator.js";
|
|
35
35
|
import { ExtractionDeadlineError } from "./orchestration/extraction-run.js";
|
|
36
|
+
import { ExtractionQueueCoordinator } from "./orchestration/extraction-queue-coordinator.js";
|
|
36
37
|
import { SessionOwnershipError } from "./orchestration/session-context.js";
|
|
37
38
|
import type { EngramAccessObserveRequest, MemoryScopePlan } from "./access-service.js";
|
|
38
39
|
import {
|
|
@@ -656,55 +657,53 @@ test("#2128: a failed observe extraction is consumed after force-flush reports i
|
|
|
656
657
|
await assert.doesNotReject(() => service.extractionForceFlush({ sessionKey }));
|
|
657
658
|
});
|
|
658
659
|
|
|
659
|
-
test("#2128: force-flush deadline
|
|
660
|
+
test("#2128/COS-825: force-flush deadline stops the wait but not the pending observe extraction", async (t) => {
|
|
660
661
|
const probe = makeParityProbe({ namespacesEnabled: false } as Partial<PluginConfig>);
|
|
661
662
|
let extractionSignal: AbortSignal | undefined;
|
|
663
|
+
const { promise: pendingExtraction, resolve: resolveExtraction } = Promise.withResolvers<void>();
|
|
662
664
|
probe.orch.ingestReplayBatch = async (_turns, options = {}) => {
|
|
663
665
|
extractionSignal = options.abortSignal;
|
|
664
|
-
|
|
665
|
-
options.abortSignal?.addEventListener(
|
|
666
|
-
"abort",
|
|
667
|
-
() => reject(new Error("extraction cancelled")),
|
|
668
|
-
{ once: true },
|
|
669
|
-
);
|
|
670
|
-
options.onExtractionQueued?.(promise);
|
|
666
|
+
options.onExtractionQueued?.(pendingExtraction);
|
|
671
667
|
};
|
|
672
668
|
const service = new EngramAccessService(probe.orch);
|
|
673
|
-
const sessionKey = "deadline-
|
|
669
|
+
const sessionKey = "deadline-keeps-extraction";
|
|
674
670
|
|
|
675
671
|
await service.observe(observeRequest({ sessionKey, skipExtraction: false }));
|
|
676
|
-
|
|
672
|
+
// Mocked clock, same reason as the #2206 deadline test below: the flush
|
|
673
|
+
// deadline is a real unref'd timer in production, and a drained event loop
|
|
674
|
+
// on a loaded runner can otherwise strand the flush.
|
|
675
|
+
t.mock.timers.enable({ apis: ["setTimeout", "Date"] });
|
|
677
676
|
try {
|
|
677
|
+
const flush = service.extractionForceFlush({ sessionKey, deadlineMs: 25 });
|
|
678
|
+
await new Promise<void>((resolve) => setImmediate(resolve));
|
|
679
|
+
t.mock.timers.tick(25);
|
|
678
680
|
await assert.rejects(
|
|
679
|
-
|
|
680
|
-
sessionKey,
|
|
681
|
-
deadlineMs: 25,
|
|
682
|
-
}),
|
|
681
|
+
flush,
|
|
683
682
|
(error: unknown) =>
|
|
684
683
|
error instanceof EngramAccessInputError &&
|
|
685
684
|
error.message.includes("pending_observe_extraction"),
|
|
686
685
|
);
|
|
687
686
|
} finally {
|
|
688
|
-
|
|
687
|
+
t.mock.timers.reset();
|
|
689
688
|
}
|
|
690
|
-
|
|
689
|
+
// The queued extraction was accepted by another observe: a flush caller's
|
|
690
|
+
// own budget expiring must not cancel it (COS-825).
|
|
691
|
+
assert.equal(extractionSignal?.aborted, false);
|
|
692
|
+
resolveExtraction();
|
|
693
|
+
await pendingExtraction;
|
|
694
|
+
assert.equal((await service.extractionForceFlush({ sessionKey })).flushed, true);
|
|
691
695
|
});
|
|
692
696
|
|
|
693
|
-
test("#2128: force-flush abort
|
|
697
|
+
test("#2128/COS-825: force-flush abort stops the wait but not the pending observe extraction", async () => {
|
|
694
698
|
const probe = makeParityProbe({ namespacesEnabled: false } as Partial<PluginConfig>);
|
|
695
699
|
let extractionSignal: AbortSignal | undefined;
|
|
700
|
+
const { promise: pendingExtraction, resolve: resolveExtraction } = Promise.withResolvers<void>();
|
|
696
701
|
probe.orch.ingestReplayBatch = async (_turns, options = {}) => {
|
|
697
702
|
extractionSignal = options.abortSignal;
|
|
698
|
-
|
|
699
|
-
options.abortSignal?.addEventListener(
|
|
700
|
-
"abort",
|
|
701
|
-
() => reject(new Error("extraction cancelled")),
|
|
702
|
-
{ once: true },
|
|
703
|
-
);
|
|
704
|
-
options.onExtractionQueued?.(promise);
|
|
703
|
+
options.onExtractionQueued?.(pendingExtraction);
|
|
705
704
|
};
|
|
706
705
|
const service = new EngramAccessService(probe.orch);
|
|
707
|
-
const sessionKey = "abort-
|
|
706
|
+
const sessionKey = "abort-keeps-extraction";
|
|
708
707
|
const abortController = new AbortController();
|
|
709
708
|
|
|
710
709
|
await service.observe(observeRequest({ sessionKey, skipExtraction: false }));
|
|
@@ -718,10 +717,15 @@ test("#2128: force-flush abort signal cancels the pending observe extraction", a
|
|
|
718
717
|
flushPromise,
|
|
719
718
|
(error: unknown) => error instanceof Error && error.message === "extraction force-flush aborted",
|
|
720
719
|
);
|
|
721
|
-
|
|
720
|
+
// The queued extraction belongs to another observe: a disconnecting flush
|
|
721
|
+
// caller must not cancel it (COS-825).
|
|
722
|
+
assert.equal(extractionSignal?.aborted, false);
|
|
723
|
+
resolveExtraction();
|
|
724
|
+
await pendingExtraction;
|
|
725
|
+
assert.equal((await service.extractionForceFlush({ sessionKey })).flushed, true);
|
|
722
726
|
});
|
|
723
727
|
|
|
724
|
-
test("#2128: force-flush abort
|
|
728
|
+
test("#2128/COS-825: force-flush abort leaves every namespace barrier untouched", async () => {
|
|
725
729
|
const probe = makeParityProbe({
|
|
726
730
|
namespacePolicies: [
|
|
727
731
|
{ name: "project-a", readPrincipals: ["pi-geek"], writePrincipals: ["pi-geek"] },
|
|
@@ -733,13 +737,8 @@ test("#2128: force-flush abort only cancels the resolved namespace barrier", asy
|
|
|
733
737
|
probe.orch.ingestReplayBatch = async (_turns, options = {}) => {
|
|
734
738
|
const namespace = options.writeNamespaceOverride ?? "";
|
|
735
739
|
extractionSignals.set(namespace, options.abortSignal);
|
|
736
|
-
const { promise, resolve
|
|
740
|
+
const { promise, resolve } = Promise.withResolvers<void>();
|
|
737
741
|
extractionResolvers.set(namespace, resolve);
|
|
738
|
-
options.abortSignal?.addEventListener(
|
|
739
|
-
"abort",
|
|
740
|
-
() => reject(options.abortSignal?.reason ?? new Error("extraction cancelled")),
|
|
741
|
-
{ once: true },
|
|
742
|
-
);
|
|
743
742
|
options.onExtractionQueued?.(promise);
|
|
744
743
|
};
|
|
745
744
|
const service = new EngramAccessService(probe.orch);
|
|
@@ -779,10 +778,18 @@ test("#2128: force-flush abort only cancels the resolved namespace barrier", asy
|
|
|
779
778
|
flushA,
|
|
780
779
|
(error: unknown) => error instanceof Error && error.message === "extraction force-flush aborted",
|
|
781
780
|
);
|
|
782
|
-
|
|
781
|
+
// Neither scope's accepted extraction may be cancelled by the dead caller.
|
|
782
|
+
assert.equal(extractionSignals.get(namespaceA)?.aborted, false);
|
|
783
783
|
assert.equal(extractionSignals.get(namespaceB)?.aborted, false);
|
|
784
|
-
|
|
784
|
+
extractionResolvers.get(namespaceA)?.();
|
|
785
785
|
extractionResolvers.get(namespaceB)?.();
|
|
786
|
+
await assert.doesNotReject(() =>
|
|
787
|
+
service.extractionForceFlush({
|
|
788
|
+
sessionKey,
|
|
789
|
+
authenticatedPrincipal: "pi-geek",
|
|
790
|
+
namespace: namespaceA,
|
|
791
|
+
}),
|
|
792
|
+
);
|
|
786
793
|
await assert.doesNotReject(() =>
|
|
787
794
|
service.extractionForceFlush({
|
|
788
795
|
sessionKey,
|
|
@@ -1055,7 +1062,7 @@ test("#3140: a duration deadline reaches scope resolution and aborts it when it
|
|
|
1055
1062
|
assert.equal(probe.extractionForceFlushCalls.length, 0);
|
|
1056
1063
|
});
|
|
1057
1064
|
|
|
1058
|
-
test("#2206: abort during scope resolution
|
|
1065
|
+
test("#2206/COS-825: abort during scope resolution leaves pre-resolution observe preparations intact", async () => {
|
|
1059
1066
|
const probe = makeParityProbe(withSelfPolicyPrefix("pi-geek"));
|
|
1060
1067
|
const service = new EngramAccessService(probe.orch);
|
|
1061
1068
|
const abortController = new AbortController();
|
|
@@ -1086,6 +1093,15 @@ test("#2206: abort during scope resolution cancels pre-resolution observe prepar
|
|
|
1086
1093
|
signalFlushScopeStarted();
|
|
1087
1094
|
return new Promise<never>(() => {});
|
|
1088
1095
|
};
|
|
1096
|
+
probe.orch.ingestReplayBatch = async (turns, options = {}) => {
|
|
1097
|
+
probe.extractionCalls.push({
|
|
1098
|
+
sessionKeys: turns.map((turn) => turn.sessionKey),
|
|
1099
|
+
writeNamespaceOverride: options.writeNamespaceOverride,
|
|
1100
|
+
principalOverride: options.principalOverride,
|
|
1101
|
+
sessionOwnerPrincipal: options.sessionOwnerPrincipal,
|
|
1102
|
+
});
|
|
1103
|
+
options.onExtractionQueued?.(Promise.resolve());
|
|
1104
|
+
};
|
|
1089
1105
|
|
|
1090
1106
|
const observe = service.observe(observeRequest({
|
|
1091
1107
|
sessionKey: "pi-geek:abort-scope-resolution",
|
|
@@ -1106,13 +1122,13 @@ test("#2206: abort during scope resolution cancels pre-resolution observe prepar
|
|
|
1106
1122
|
await assert.rejects(flush, /extraction force-flush aborted/);
|
|
1107
1123
|
releaseObserveScope();
|
|
1108
1124
|
const response = await observe;
|
|
1109
|
-
//
|
|
1110
|
-
//
|
|
1111
|
-
assert.equal(response.extractionQueued,
|
|
1125
|
+
// The observe's work is its own: a dead flush caller must not cancel its
|
|
1126
|
+
// preparation, so the accepted capture still queues extraction (COS-825).
|
|
1127
|
+
assert.equal(response.extractionQueued, true);
|
|
1112
1128
|
assert.equal(probe.extractionCalls.length, 1);
|
|
1113
1129
|
});
|
|
1114
1130
|
|
|
1115
|
-
test("#2206: scope-resolution deadline
|
|
1131
|
+
test("#2206/COS-825: scope-resolution deadline leaves raw projectTag and cwd preparations intact", async (t) => {
|
|
1116
1132
|
// The deadline budget is a real, unref'd timer in production
|
|
1117
1133
|
// (session-context.ts), so a 1ms wall-clock budget can elapse BEFORE the
|
|
1118
1134
|
// flush enters the blocked scope stub on a loaded runner (assertion then
|
|
@@ -1154,6 +1170,15 @@ test("#2206: scope-resolution deadline cancels preparations by raw projectTag an
|
|
|
1154
1170
|
flushScopeStarted = true;
|
|
1155
1171
|
return new Promise<never>(() => {});
|
|
1156
1172
|
};
|
|
1173
|
+
probe.orch.ingestReplayBatch = async (turns, options = {}) => {
|
|
1174
|
+
probe.extractionCalls.push({
|
|
1175
|
+
sessionKeys: turns.map((turn) => turn.sessionKey),
|
|
1176
|
+
writeNamespaceOverride: options.writeNamespaceOverride,
|
|
1177
|
+
principalOverride: options.principalOverride,
|
|
1178
|
+
sessionOwnerPrincipal: options.sessionOwnerPrincipal,
|
|
1179
|
+
});
|
|
1180
|
+
options.onExtractionQueued?.(Promise.resolve());
|
|
1181
|
+
};
|
|
1157
1182
|
|
|
1158
1183
|
const observe = service.observe(observeRequest({
|
|
1159
1184
|
sessionKey: "pi-geek:raw-hint-deadline",
|
|
@@ -1186,9 +1211,9 @@ test("#2206: scope-resolution deadline cancels preparations by raw projectTag an
|
|
|
1186
1211
|
releaseObserveScope();
|
|
1187
1212
|
}
|
|
1188
1213
|
const response = await observe;
|
|
1189
|
-
//
|
|
1190
|
-
//
|
|
1191
|
-
assert.equal(response.extractionQueued,
|
|
1214
|
+
// The flush budget expiring is the flush's problem only: the observe's
|
|
1215
|
+
// preparation survives and its capture still queues extraction (COS-825).
|
|
1216
|
+
assert.equal(response.extractionQueued, true);
|
|
1192
1217
|
assert.equal(probe.extractionCalls.length, 1);
|
|
1193
1218
|
}
|
|
1194
1219
|
});
|
|
@@ -1229,52 +1254,6 @@ test("#2128: aborted or expired extraction force-flush never touches a buffer",
|
|
|
1229
1254
|
assert.equal(probe.extractionForceFlushCalls.length, 0);
|
|
1230
1255
|
});
|
|
1231
1256
|
|
|
1232
|
-
test("#2128: self-deps wires force-flush cancellation into the observe tracker", async () => {
|
|
1233
|
-
const probe = makeParityProbe(withSelfPolicyPrefix("pi-geek"));
|
|
1234
|
-
const service = new EngramAccessService(probe.orch);
|
|
1235
|
-
const cancellations: Array<{
|
|
1236
|
-
sessionKey: string;
|
|
1237
|
-
principal?: string;
|
|
1238
|
-
namespace?: string;
|
|
1239
|
-
}> = [];
|
|
1240
|
-
const surface = (service as unknown as {
|
|
1241
|
-
accessObserveWriteSurface: {
|
|
1242
|
-
cancelPendingObserveExtractions(
|
|
1243
|
-
sessionKey: string,
|
|
1244
|
-
principal?: string,
|
|
1245
|
-
namespace?: string,
|
|
1246
|
-
): void;
|
|
1247
|
-
};
|
|
1248
|
-
}).accessObserveWriteSurface;
|
|
1249
|
-
surface.cancelPendingObserveExtractions = (sessionKey, principal, namespace) => {
|
|
1250
|
-
cancellations.push({ sessionKey, principal, namespace });
|
|
1251
|
-
};
|
|
1252
|
-
|
|
1253
|
-
// #3140: a tiny budget elapsing while scope work is blocked still cancels
|
|
1254
|
-
// the pending observe preparations via the same deadline hook.
|
|
1255
|
-
const internals = service as unknown as {
|
|
1256
|
-
resolveMemoryScopePlan: (request: unknown) => Promise<never>;
|
|
1257
|
-
};
|
|
1258
|
-
internals.resolveMemoryScopePlan = async () => new Promise<never>(() => {});
|
|
1259
|
-
await assert.rejects(
|
|
1260
|
-
() =>
|
|
1261
|
-
service.extractionForceFlush({
|
|
1262
|
-
sessionKey: "pi-geek:cancel-hook",
|
|
1263
|
-
namespace: "pi-geek",
|
|
1264
|
-
authenticatedPrincipal: "pi-geek",
|
|
1265
|
-
deadlineMs: 1,
|
|
1266
|
-
}),
|
|
1267
|
-
(error: unknown) =>
|
|
1268
|
-
error instanceof EngramAccessInputError &&
|
|
1269
|
-
error.message === "replay extraction deadline exceeded (scope_resolution)",
|
|
1270
|
-
);
|
|
1271
|
-
assert.deepEqual(cancellations, [{
|
|
1272
|
-
sessionKey: "pi-geek:cancel-hook",
|
|
1273
|
-
principal: "pi-geek",
|
|
1274
|
-
namespace: "pi-geek",
|
|
1275
|
-
}]);
|
|
1276
|
-
});
|
|
1277
|
-
|
|
1278
1257
|
test("#2128: late extraction deadline is surfaced as an access input error", async () => {
|
|
1279
1258
|
const probe = makeParityProbe(withSelfPolicyPrefix("pi-geek"));
|
|
1280
1259
|
probe.orch.flushSession = async () => {
|
|
@@ -1295,6 +1274,114 @@ test("#2128: late extraction deadline is surfaced as an access input error", asy
|
|
|
1295
1274
|
);
|
|
1296
1275
|
});
|
|
1297
1276
|
|
|
1277
|
+
test("COS-825: a session already preempted once is waited for, not re-preempted, by the next flush", async () => {
|
|
1278
|
+
// SAFETY: { namespacesEnabled: false } is a valid PluginConfig override —
|
|
1279
|
+
// the same single-store shape every other test in this file passes.
|
|
1280
|
+
const probe = makeParityProbe({ namespacesEnabled: false } as Partial<PluginConfig>);
|
|
1281
|
+
const coordinator = new ExtractionQueueCoordinator(2);
|
|
1282
|
+
// The flush's preempt callback reads the coordinator off the orchestrator
|
|
1283
|
+
// stub at runtime; Object.assign avoids narrowing the Orchestrator type.
|
|
1284
|
+
Object.assign(probe.orch, { extractionQueueCoordinator: coordinator });
|
|
1285
|
+
const abortedKeys: string[] = [];
|
|
1286
|
+
const slot = coordinator.registerPreemptSlot("repreempt-guarded");
|
|
1287
|
+
slot.arm(() => void abortedKeys.push("repreempt-guarded"));
|
|
1288
|
+
// An earlier flush already preempted this session's running extraction once;
|
|
1289
|
+
// the slot here stands in for its retry, which must be allowed to finish.
|
|
1290
|
+
coordinator.preemptKeyed("repreempt-guarded");
|
|
1291
|
+
assert.deepEqual(abortedKeys, ["repreempt-guarded"]);
|
|
1292
|
+
|
|
1293
|
+
const { promise: pendingExtraction, resolve: resolveExtraction } = Promise.withResolvers<void>();
|
|
1294
|
+
probe.orch.ingestReplayBatch = async (_turns, options = {}) => {
|
|
1295
|
+
options.onExtractionQueued?.(pendingExtraction);
|
|
1296
|
+
};
|
|
1297
|
+
const service = new EngramAccessService(probe.orch);
|
|
1298
|
+
const sessionKey = "repreempt-guarded";
|
|
1299
|
+
await service.observe(observeRequest({ sessionKey, skipExtraction: false }));
|
|
1300
|
+
|
|
1301
|
+
const flushPromise = service.extractionForceFlush({ sessionKey, deadlineMs: 5000 });
|
|
1302
|
+
await new Promise<void>((resolve) => setImmediate(resolve));
|
|
1303
|
+
// The flush's wait admission must not kill the retried generation.
|
|
1304
|
+
assert.deepEqual(abortedKeys, ["repreempt-guarded"]);
|
|
1305
|
+
resolveExtraction();
|
|
1306
|
+
assert.equal((await flushPromise).flushed, true);
|
|
1307
|
+
assert.equal(probe.extractionForceFlushCalls.length, 1);
|
|
1308
|
+
});
|
|
1309
|
+
|
|
1310
|
+
test("COS-825: the first flush still preempts the running extraction for its own session", async () => {
|
|
1311
|
+
// SAFETY: { namespacesEnabled: false } is a valid PluginConfig override —
|
|
1312
|
+
// the same single-store shape every other test in this file passes.
|
|
1313
|
+
const probe = makeParityProbe({ namespacesEnabled: false } as Partial<PluginConfig>);
|
|
1314
|
+
const coordinator = new ExtractionQueueCoordinator(2);
|
|
1315
|
+
// The flush's preempt callback reads the coordinator off the orchestrator
|
|
1316
|
+
// stub at runtime; Object.assign avoids narrowing the Orchestrator type.
|
|
1317
|
+
Object.assign(probe.orch, { extractionQueueCoordinator: coordinator });
|
|
1318
|
+
const abortedKeys: string[] = [];
|
|
1319
|
+
const slot = coordinator.registerPreemptSlot("first-preempt");
|
|
1320
|
+
slot.arm(() => void abortedKeys.push("first-preempt"));
|
|
1321
|
+
|
|
1322
|
+
const { promise: pendingExtraction, resolve: resolveExtraction } = Promise.withResolvers<void>();
|
|
1323
|
+
probe.orch.ingestReplayBatch = async (_turns, options = {}) => {
|
|
1324
|
+
options.onExtractionQueued?.(pendingExtraction);
|
|
1325
|
+
};
|
|
1326
|
+
const service = new EngramAccessService(probe.orch);
|
|
1327
|
+
const sessionKey = "first-preempt";
|
|
1328
|
+
await service.observe(observeRequest({ sessionKey, skipExtraction: false }));
|
|
1329
|
+
|
|
1330
|
+
const flushPromise = service.extractionForceFlush({ sessionKey, deadlineMs: 5000 });
|
|
1331
|
+
await new Promise<void>((resolve) => setImmediate(resolve));
|
|
1332
|
+
// Force-flush priority is kept: the first preemption per session still fires.
|
|
1333
|
+
assert.deepEqual(abortedKeys, ["first-preempt"]);
|
|
1334
|
+
resolveExtraction();
|
|
1335
|
+
assert.equal((await flushPromise).flushed, true);
|
|
1336
|
+
});
|
|
1337
|
+
|
|
1338
|
+
test("COS-825: one dead flush caller cannot abort a deep queue of observe extractions", async () => {
|
|
1339
|
+
// SAFETY: { namespacesEnabled: false } is a valid PluginConfig override —
|
|
1340
|
+
// the same single-store shape every other test in this file passes.
|
|
1341
|
+
const probe = makeParityProbe({ namespacesEnabled: false } as Partial<PluginConfig>);
|
|
1342
|
+
const queued: Array<{
|
|
1343
|
+
promise: Promise<void>;
|
|
1344
|
+
signal: AbortSignal | undefined;
|
|
1345
|
+
resolve: () => void;
|
|
1346
|
+
}> = [];
|
|
1347
|
+
probe.orch.ingestReplayBatch = async (_turns, options = {}) => {
|
|
1348
|
+
const { promise, resolve } = Promise.withResolvers<void>();
|
|
1349
|
+
queued.push({ promise, signal: options.abortSignal, resolve });
|
|
1350
|
+
options.onExtractionQueued?.(promise);
|
|
1351
|
+
};
|
|
1352
|
+
const service = new EngramAccessService(probe.orch);
|
|
1353
|
+
const sessionKey = "deep-queue-one-cascade";
|
|
1354
|
+
|
|
1355
|
+
// The production failure shape: one force-flush call whose caller times out
|
|
1356
|
+
// used to abort EVERY generation queued under the session (thousands of
|
|
1357
|
+
// `extraction aborted (during_storage)` per call, versus ~2 preemptions,
|
|
1358
|
+
// because preemption kills only the running task while the cancel cascade
|
|
1359
|
+
// killed all queued ones).
|
|
1360
|
+
for (let index = 0; index < 50; index += 1) {
|
|
1361
|
+
await service.observe(observeRequest({ sessionKey, skipExtraction: false }));
|
|
1362
|
+
}
|
|
1363
|
+
assert.equal(queued.length, 50);
|
|
1364
|
+
|
|
1365
|
+
const abortController = new AbortController();
|
|
1366
|
+
const flushPromise = service.extractionForceFlush({
|
|
1367
|
+
sessionKey,
|
|
1368
|
+
abortSignal: abortController.signal,
|
|
1369
|
+
});
|
|
1370
|
+
await new Promise<void>((resolve) => setImmediate(resolve));
|
|
1371
|
+
abortController.abort();
|
|
1372
|
+
await assert.rejects(
|
|
1373
|
+
flushPromise,
|
|
1374
|
+
(error) => error instanceof Error && error.message === "extraction force-flush aborted",
|
|
1375
|
+
);
|
|
1376
|
+
assert.ok(
|
|
1377
|
+
queued.every((entry) => entry.signal?.aborted === false),
|
|
1378
|
+
"no queued generation may be aborted by a dead flush caller",
|
|
1379
|
+
);
|
|
1380
|
+
for (const entry of queued) entry.resolve();
|
|
1381
|
+
await Promise.all(queued.map((entry) => entry.promise));
|
|
1382
|
+
assert.equal((await service.extractionForceFlush({ sessionKey })).flushed, true);
|
|
1383
|
+
});
|
|
1384
|
+
|
|
1298
1385
|
test("#2128: force-flush scope resolution does not overwrite a concurrent observe context", async () => {
|
|
1299
1386
|
const probe = makeParityProbe(withSelfPolicyPrefix("pi-geek"));
|
|
1300
1387
|
const service = new EngramAccessService(probe.orch);
|
|
@@ -241,7 +241,7 @@ test("#2128 pending observe preparation is a force-flush barrier", async () => {
|
|
|
241
241
|
await Promise.resolve();
|
|
242
242
|
assert.equal(waited, false, "a force flush must wait while observe is still resolving scope");
|
|
243
243
|
|
|
244
|
-
tracker.track(tracker.key("session-z", "alice", "team-project"), extraction
|
|
244
|
+
tracker.track(tracker.key("session-z", "alice", "team-project"), extraction);
|
|
245
245
|
preparation.release();
|
|
246
246
|
await Promise.resolve();
|
|
247
247
|
assert.equal(waited, false, "registration must remain a barrier until extraction settles");
|
|
@@ -254,42 +254,28 @@ test("#2128 pending observe preparation is a force-flush barrier", async () => {
|
|
|
254
254
|
test("a preempted observe extraction does not block the next force-flush", async () => {
|
|
255
255
|
const tracker = new PendingObserveExtractionTracker();
|
|
256
256
|
const key = tracker.key("session-a", "alice", "default");
|
|
257
|
-
tracker.track(key, Promise.reject(preemptedExtractionError())
|
|
257
|
+
tracker.track(key, Promise.reject(preemptedExtractionError()));
|
|
258
258
|
await tracker.wait("session-a", "alice", "default");
|
|
259
259
|
// A settled failure is no longer pending: the entry is removed on ANY
|
|
260
260
|
// settle, so the next flush is neither blocked nor failed by work that
|
|
261
261
|
// already finished. (A flush overlapping the failing extraction still
|
|
262
262
|
// surfaces its error — covered in access-observe-helpers.test.ts.)
|
|
263
|
-
tracker.track(key, Promise.reject(new Error("extraction failed"))
|
|
263
|
+
tracker.track(key, Promise.reject(new Error("extraction failed")));
|
|
264
264
|
const { promise, resolve } = Promise.withResolvers<void>();
|
|
265
265
|
setImmediate(resolve);
|
|
266
266
|
await promise;
|
|
267
267
|
await tracker.wait("session-a", "alice", "default");
|
|
268
268
|
});
|
|
269
269
|
|
|
270
|
-
test("cancelling a tracked extraction with a preemption reason does not block the next flush", async () => {
|
|
271
|
-
const tracker = new PendingObserveExtractionTracker();
|
|
272
|
-
const controller = new AbortController();
|
|
273
|
-
const extraction = new Promise<void>((_resolve, reject) => {
|
|
274
|
-
controller.signal.addEventListener("abort", () => reject(controller.signal.reason), { once: true });
|
|
275
|
-
});
|
|
276
|
-
tracker.track(tracker.key("session-a", "alice", "default"), extraction, controller);
|
|
277
|
-
tracker.cancel("session-a", "alice", "default", undefined, preemptedExtractionError());
|
|
278
|
-
await tracker.wait("session-a", "alice", "default");
|
|
279
|
-
});
|
|
280
|
-
|
|
281
270
|
test("flush preemption waits for admission and does not cancel the preparation", async () => {
|
|
282
271
|
const tracker = new PendingObserveExtractionTracker();
|
|
283
272
|
const preparation = tracker.reserve("session-a");
|
|
284
|
-
const
|
|
285
|
-
|
|
286
|
-
controller.signal.addEventListener("abort", () => reject(controller.signal.reason), { once: true });
|
|
287
|
-
});
|
|
288
|
-
tracker.track(tracker.key("session-a", "alice", "default"), extraction, controller);
|
|
273
|
+
const { promise: extraction, reject } = Promise.withResolvers<void>();
|
|
274
|
+
tracker.track(tracker.key("session-a", "alice", "default"), extraction);
|
|
289
275
|
let waited = false;
|
|
290
276
|
const pending = tracker.wait(
|
|
291
277
|
"session-a", "alice", "default", undefined, undefined, undefined,
|
|
292
|
-
() =>
|
|
278
|
+
() => reject(preemptedExtractionError()),
|
|
293
279
|
).then(() => { waited = true; });
|
|
294
280
|
await Promise.resolve();
|
|
295
281
|
assert.equal(waited, false);
|
|
@@ -300,34 +286,33 @@ test("flush preemption waits for admission and does not cancel the preparation",
|
|
|
300
286
|
assert.equal(preparation.isCancelled(), false);
|
|
301
287
|
});
|
|
302
288
|
|
|
303
|
-
test("a
|
|
289
|
+
test("a stopped wait does not cancel the preparation or preempt after admission", async () => {
|
|
304
290
|
const tracker = new PendingObserveExtractionTracker();
|
|
305
291
|
const preparation = tracker.reserve("session-a");
|
|
306
292
|
let preempted = false;
|
|
307
|
-
let
|
|
293
|
+
let stop: (() => void) | undefined;
|
|
308
294
|
const pending = tracker.wait(
|
|
309
|
-
"session-a", "alice", "default", undefined, (
|
|
295
|
+
"session-a", "alice", "default", undefined, (registered) => { stop = registered; }, undefined, () => { preempted = true; },
|
|
310
296
|
);
|
|
311
297
|
await Promise.resolve();
|
|
312
|
-
|
|
298
|
+
// COS-825: the registered cancellation (a flush deadline) stops the WAIT
|
|
299
|
+
// only — the observe's preparation stays intact.
|
|
300
|
+
stop?.();
|
|
313
301
|
preparation.release();
|
|
314
302
|
await pending;
|
|
315
303
|
assert.equal(preempted, false);
|
|
316
|
-
assert.equal(preparation.isCancelled(),
|
|
304
|
+
assert.equal(preparation.isCancelled(), false);
|
|
317
305
|
});
|
|
318
306
|
|
|
319
307
|
test("flush preemption does not wait for a second queued extraction", async () => {
|
|
320
308
|
const tracker = new PendingObserveExtractionTracker();
|
|
321
|
-
const first = new AbortController();
|
|
322
|
-
const firstPromise = new Promise<void>((_resolve, reject) => {
|
|
323
|
-
first.signal.addEventListener("abort", () => reject(first.signal.reason), { once: true });
|
|
324
|
-
});
|
|
325
|
-
const secondPromise = new Promise<void>(() => {});
|
|
326
309
|
const key = tracker.key("session-a", "alice", "default");
|
|
327
|
-
|
|
328
|
-
|
|
310
|
+
const { promise: firstPromise, reject } = Promise.withResolvers<void>();
|
|
311
|
+
const secondPromise = new Promise<void>(() => {});
|
|
312
|
+
tracker.track(key, firstPromise);
|
|
313
|
+
tracker.track(key, secondPromise);
|
|
329
314
|
await tracker.wait("session-a", "alice", "default", undefined, undefined, undefined, () => {
|
|
330
|
-
|
|
315
|
+
reject(preemptedExtractionError());
|
|
331
316
|
});
|
|
332
317
|
});
|
|
333
318
|
|
|
@@ -461,59 +446,6 @@ test("#2206 unresolved preparation without a hint remains a conservative barrier
|
|
|
461
446
|
assert.equal(settled, true);
|
|
462
447
|
});
|
|
463
448
|
|
|
464
|
-
test("#2206 raw-hint cancellation only cancels matching preparations", async () => {
|
|
465
|
-
const tracker = new PendingObserveExtractionTracker();
|
|
466
|
-
const unresolved = tracker.reserve("opaque-session", "projectTag:project-a");
|
|
467
|
-
const resolved = tracker.reserve("opaque-session", "projectTag:project-a");
|
|
468
|
-
const unrelated = tracker.reserve("opaque-session", "projectTag:project-b");
|
|
469
|
-
resolved.setScope("alice", "alice-project-a");
|
|
470
|
-
let releaseExtraction!: () => void;
|
|
471
|
-
const extraction = new Promise<void>((resolve) => {
|
|
472
|
-
releaseExtraction = resolve;
|
|
473
|
-
});
|
|
474
|
-
const unrelatedController = new AbortController();
|
|
475
|
-
tracker.track(
|
|
476
|
-
tracker.key("opaque-session", "alice", "alice-project-b"),
|
|
477
|
-
extraction,
|
|
478
|
-
unrelatedController,
|
|
479
|
-
);
|
|
480
|
-
|
|
481
|
-
tracker.cancelPreparations("opaque-session", "projectTag:project-a");
|
|
482
|
-
|
|
483
|
-
assert.equal(unresolved.isCancelled(), true);
|
|
484
|
-
assert.equal(resolved.isCancelled(), true);
|
|
485
|
-
assert.equal(unrelated.isCancelled(), false);
|
|
486
|
-
assert.equal(unrelatedController.signal.aborted, false);
|
|
487
|
-
unresolved.release();
|
|
488
|
-
resolved.release();
|
|
489
|
-
unrelated.release();
|
|
490
|
-
releaseExtraction();
|
|
491
|
-
await extraction;
|
|
492
|
-
});
|
|
493
|
-
|
|
494
|
-
test("#2128 scoped observe preparation cancellation preserves another project", () => {
|
|
495
|
-
const tracker = new PendingObserveExtractionTracker();
|
|
496
|
-
const projectA = tracker.reserve("opaque-session", "projectTag:project-a");
|
|
497
|
-
const projectB = tracker.reserve("opaque-session", "projectTag:project-b");
|
|
498
|
-
|
|
499
|
-
tracker.cancel("opaque-session", undefined, "alice-project-a", "projectTag:project-a");
|
|
500
|
-
|
|
501
|
-
assert.equal(projectA.isCancelled(), true);
|
|
502
|
-
assert.equal(projectB.isCancelled(), false);
|
|
503
|
-
projectA.release();
|
|
504
|
-
projectB.release();
|
|
505
|
-
});
|
|
506
|
-
|
|
507
|
-
test("#2128 cancellation matches resolved scope despite a different request hint", () => {
|
|
508
|
-
const tracker = new PendingObserveExtractionTracker();
|
|
509
|
-
const preparation = tracker.reserve("session-z", "cwd:/workspace/project/src");
|
|
510
|
-
preparation.setScope("alice", "alice-project");
|
|
511
|
-
|
|
512
|
-
tracker.cancel("session-z", "alice", "alice-project", "projectTag:Acme/Webshop");
|
|
513
|
-
|
|
514
|
-
assert.equal(preparation.isCancelled(), true);
|
|
515
|
-
preparation.release();
|
|
516
|
-
});
|
|
517
449
|
test("#2128 concurrent scope plans do not share temporary coding context", async () => {
|
|
518
450
|
const probe = makeObserveProbe(withSelfPolicyPrefix("pi-geek"));
|
|
519
451
|
const service = new EngramAccessService(probe.orch);
|
package/src/access-service.ts
CHANGED
|
@@ -4410,19 +4410,6 @@ export class EngramAccessService extends SupportPassportAccessServiceBase {
|
|
|
4410
4410
|
): Promise<EngramAccessExtractionForceFlushResponse> {
|
|
4411
4411
|
return delegateExtractionForceFlush(this.accessObserveWriteSurface, request);
|
|
4412
4412
|
}
|
|
4413
|
-
cancelPendingObservePreparations(sessionKey: string, scopeHint?: string): void {
|
|
4414
|
-
this.accessObserveWriteSurface.cancelPendingObservePreparations(sessionKey, scopeHint);
|
|
4415
|
-
}
|
|
4416
|
-
|
|
4417
|
-
cancelPendingObserveExtractions(
|
|
4418
|
-
sessionKey: string,
|
|
4419
|
-
principal?: string,
|
|
4420
|
-
namespace?: string,
|
|
4421
|
-
scopeHint?: string,
|
|
4422
|
-
reason?: Error,
|
|
4423
|
-
): void {
|
|
4424
|
-
this.accessObserveWriteSurface.cancelPendingObserveExtractions(sessionKey, principal, namespace, scopeHint, reason);
|
|
4425
|
-
}
|
|
4426
4413
|
async lcmCompactionRecord(
|
|
4427
4414
|
request: EngramAccessLcmCompactionRecordRequest
|
|
4428
4415
|
): Promise<EngramAccessLcmCompactionRecordResponse> {
|
|
@@ -102,6 +102,16 @@ export class ExtractionQueueCoordinator {
|
|
|
102
102
|
/** Preempt slots of the currently running tasks, keyed by slot identity. */
|
|
103
103
|
private readonly preemptSlots = new Map<object, PreemptSlot>();
|
|
104
104
|
private preemptSeq = 0;
|
|
105
|
+
/**
|
|
106
|
+
* COS-825: keys whose running task was already preempted for a force-flush
|
|
107
|
+
* once. A flush preempts a session's extraction at most once per episode:
|
|
108
|
+
* the retried generation (the turns the preempted task left buffered) is
|
|
109
|
+
* waited for, never killed again, until some task for the key succeeds.
|
|
110
|
+
* This stops the livelock where every flush call killed the extraction that
|
|
111
|
+
* was about to finish and then died on its own deadline, so nothing ever
|
|
112
|
+
* completed.
|
|
113
|
+
*/
|
|
114
|
+
private readonly preemptedKeys = new Set<string>();
|
|
105
115
|
/** Running tasks per lane — the backlog share and the foreground floor. */
|
|
106
116
|
private activeBacklog = 0;
|
|
107
117
|
private activeForeground = 0;
|
|
@@ -211,16 +221,27 @@ export class ExtractionQueueCoordinator {
|
|
|
211
221
|
preemptRunning(preferredKey?: string): void {
|
|
212
222
|
const armed = Array.from(this.preemptSlots.values()).filter((slot) => slot.armed !== undefined);
|
|
213
223
|
if (armed.length === 0) return;
|
|
214
|
-
|
|
224
|
+
// COS-825: a key already preempted once is skipped as a victim — its
|
|
225
|
+
// retried work finishes instead of being killed again. An unrelated
|
|
226
|
+
// victim (slot steal) is still allowed so a flush always wins a slot.
|
|
227
|
+
const latched = preferredKey !== undefined && this.preemptedKeys.has(preferredKey);
|
|
228
|
+
const preferred = latched
|
|
229
|
+
? undefined
|
|
230
|
+
: preferredKey !== undefined
|
|
231
|
+
? armed.find((slot) => slot.key === preferredKey)
|
|
232
|
+
: undefined;
|
|
215
233
|
// Lane-aware victim choice: with no same-key slot to abort, a flush takes
|
|
216
234
|
// a foreground slot before a backlog one, so drain chunk calls survive
|
|
217
235
|
// routine force-flush preemption while the flush still always wins a slot.
|
|
218
|
-
|
|
236
|
+
let victims = armed.some((slot) => slot.backlog !== true) ? armed.filter((slot) => slot.backlog !== true) : armed;
|
|
237
|
+
if (latched) victims = victims.filter((slot) => slot.key !== preferredKey);
|
|
238
|
+
if (victims.length === 0 && !preferred) return;
|
|
219
239
|
const chosen =
|
|
220
240
|
preferred ??
|
|
221
241
|
victims.reduce((a, b) => ((b.armed?.seq ?? -1) > (a.armed?.seq ?? -1) ? b : a));
|
|
222
242
|
const abort = chosen.armed?.abort;
|
|
223
243
|
chosen.armed = undefined;
|
|
244
|
+
if (chosen.key !== undefined) this.preemptedKeys.add(chosen.key);
|
|
224
245
|
abort?.();
|
|
225
246
|
}
|
|
226
247
|
|
|
@@ -372,6 +393,9 @@ export class ExtractionQueueCoordinator {
|
|
|
372
393
|
this.preemptSlots.set(slot, { key: entry.key, backlog: entry.backlog });
|
|
373
394
|
try {
|
|
374
395
|
await entry.run(this.createPreemptHandle(slot));
|
|
396
|
+
// A completed task for the key closes the preemption episode: the next
|
|
397
|
+
// flush regains first-strike priority (COS-825).
|
|
398
|
+
if (entry.key !== undefined) this.preemptedKeys.delete(entry.key);
|
|
375
399
|
} catch (err) {
|
|
376
400
|
this.logExtractionQueueFailure(err, "task");
|
|
377
401
|
} finally {
|
|
@@ -395,14 +419,21 @@ export class ExtractionQueueCoordinator {
|
|
|
395
419
|
* `key` and abort nothing when none does. Unlike `preemptRunning` there is
|
|
396
420
|
* deliberately no newest-slot fallback - a keyed caller (force-flush on
|
|
397
421
|
* session K) must never take out an unrelated background task just
|
|
398
|
-
* because K's own extraction is not (yet) armed.
|
|
422
|
+
* because K's own extraction is not (yet) armed.
|
|
423
|
+
* COS-825: at most one preemption per key episode — once K's task has
|
|
424
|
+
* been preempted, later flushes wait for the retried work; the latch
|
|
425
|
+
* clears when a task for K succeeds. */
|
|
399
426
|
preemptKeyed(key: string): void {
|
|
427
|
+
if (this.preemptedKeys.has(key)) return;
|
|
428
|
+
let preempted = false;
|
|
400
429
|
for (const state of this.preemptSlots.values()) {
|
|
401
430
|
if (state.key !== key || state.armed === undefined) continue;
|
|
402
431
|
const abort = state.armed.abort;
|
|
403
432
|
state.armed = undefined;
|
|
433
|
+
preempted = true;
|
|
404
434
|
abort();
|
|
405
435
|
}
|
|
436
|
+
if (preempted) this.preemptedKeys.add(key);
|
|
406
437
|
}
|
|
407
438
|
|
|
408
439
|
private createPreemptHandle(slot: PreemptSlot): ExtractionPreemptHandle {
|