@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.
Files changed (52) hide show
  1. package/dist/access-admin-ops-surface.js +2 -2
  2. package/dist/access-cli.js +2 -2
  3. package/dist/access-extraction-force-flush-preempt.js +2 -2
  4. package/dist/access-extraction-force-flush.d.ts.map +1 -1
  5. package/dist/access-extraction-force-flush.js +2 -2
  6. package/dist/access-http-briefing.js +2 -2
  7. package/dist/access-http-query.js +2 -2
  8. package/dist/access-http.js +2 -2
  9. package/dist/access-identity-continuity-surface.js +2 -2
  10. package/dist/access-lcm-surface.js +2 -2
  11. package/dist/access-mcp.js +2 -2
  12. package/dist/access-observe-helpers.d.ts +1 -4
  13. package/dist/access-observe-helpers.d.ts.map +1 -1
  14. package/dist/access-observe-helpers.js +1 -1
  15. package/dist/access-observe-write-surface.d.ts +0 -4
  16. package/dist/access-observe-write-surface.d.ts.map +1 -1
  17. package/dist/access-observe-write-surface.js +2 -2
  18. package/dist/access-operations-batch.js +2 -2
  19. package/dist/access-operations.js +2 -2
  20. package/dist/access-recall-concurrency.js +2 -2
  21. package/dist/access-recall-response.js +2 -2
  22. package/dist/access-recall-surface.js +2 -2
  23. package/dist/access-service.d.ts +0 -2
  24. package/dist/access-service.d.ts.map +1 -1
  25. package/dist/access-service.js +2 -2
  26. package/dist/{chunk-T3XOP7TA.js → chunk-7X6EZ2QB.js} +2 -2
  27. package/dist/{chunk-MTKSH7HY.js → chunk-ABPOW3SX.js} +44 -74
  28. package/dist/chunk-ABPOW3SX.js.map +1 -0
  29. package/dist/{chunk-CYTTY4M2.js → chunk-OPXK5IQU.js} +47 -47
  30. package/dist/chunk-OPXK5IQU.js.map +1 -0
  31. package/dist/cli.js +2 -2
  32. package/dist/explicit-capture.js +2 -2
  33. package/dist/index.js +2 -2
  34. package/dist/orchestration/backlog-scheduler.js +3 -3
  35. package/dist/orchestration/buffer-drain-runner.js +3 -3
  36. package/dist/orchestration/extraction-queue-coordinator.d.ts +14 -1
  37. package/dist/orchestration/extraction-queue-coordinator.d.ts.map +1 -1
  38. package/dist/orchestrator.js +2 -2
  39. package/dist/recall-navigation.js +2 -2
  40. package/package.json +2 -2
  41. package/src/access-extraction-force-flush-preempt-coordinator.test.ts +71 -0
  42. package/src/access-extraction-force-flush.ts +20 -56
  43. package/src/access-observe-helpers.test.ts +71 -88
  44. package/src/access-observe-helpers.ts +60 -73
  45. package/src/access-observe-write-surface.ts +1 -22
  46. package/src/access-service-observe-lcm-parity.test.ts +176 -89
  47. package/src/access-service-observe-scope.test.ts +18 -86
  48. package/src/access-service.ts +0 -13
  49. package/src/orchestration/extraction-queue-coordinator.ts +34 -3
  50. package/dist/chunk-CYTTY4M2.js.map +0 -1
  51. package/dist/chunk-MTKSH7HY.js.map +0 -1
  52. /package/dist/{chunk-T3XOP7TA.js.map → chunk-7X6EZ2QB.js.map} +0 -0
@@ -80,7 +80,7 @@ var PendingObserveExtractionTracker = class {
80
80
  key(sessionKey, principal, namespace) {
81
81
  return `${sessionKey}\0${principal ?? ""}\0${namespace ?? ""}`;
82
82
  }
83
- track(key, extraction, controller) {
83
+ track(key, extraction) {
84
84
  const previous = this.entries.get(key);
85
85
  const promise = previous ? Promise.allSettled([previous.promise, extraction]).then((results) => {
86
86
  const rejected = results.find(
@@ -88,9 +88,7 @@ var PendingObserveExtractionTracker = class {
88
88
  );
89
89
  if (rejected) throw rejected.reason;
90
90
  }) : extraction;
91
- const controllers = previous?.controllers ?? /* @__PURE__ */ new Set();
92
- controllers.add(controller);
93
- const entry = { promise, running: previous?.running ?? extraction, controllers };
91
+ const entry = { promise, running: previous?.running ?? extraction };
94
92
  this.entries.set(key, entry);
95
93
  void promise.then(() => {
96
94
  if (this.entries.get(key) === entry) this.entries.delete(key);
@@ -98,69 +96,71 @@ var PendingObserveExtractionTracker = class {
98
96
  if (this.entries.get(key) === entry) this.entries.delete(key);
99
97
  });
100
98
  }
101
- cancelPreparations(sessionKey, scopeHint) {
102
- for (const reservation of this.preparations.get(sessionKey) ?? []) {
103
- if (scopeHint !== void 0 && reservation.scopeHint !== void 0 && reservation.scopeHint !== scopeHint) {
104
- continue;
105
- }
106
- reservation.cancelled = true;
107
- }
108
- }
109
- cancel(sessionKey, principal, namespace, scopeHint, reason) {
110
- for (const reservation of this.preparations.get(sessionKey) ?? []) {
111
- if (!preparationMatchesScope(reservation, principal, namespace, scopeHint)) continue;
112
- reservation.cancelled = true;
113
- }
114
- this.abortTracked(sessionKey, principal, namespace, reason);
115
- }
116
- abortTracked(sessionKey, principal, namespace, reason) {
117
- for (const [key, entry] of this.entries) {
118
- const [entrySessionKey, entryPrincipal, entryNamespace] = key.split("\0");
119
- if (entrySessionKey !== sessionKey || principal !== void 0 && entryPrincipal !== (principal ?? "") || namespace !== void 0 && entryNamespace !== (namespace ?? "")) continue;
120
- for (const controller of [...entry.controllers]) controller.abort(reason);
121
- }
122
- }
123
99
  async wait(sessionKey, principal, namespace, abortSignal, registerCancellation, scopeHint, preemptAfterAdmission) {
124
100
  const key = this.key(sessionKey, principal, namespace);
125
- let cancelled = abortSignal?.aborted === true;
126
- const abortTracked = () => {
127
- cancelled = true;
128
- this.cancel(sessionKey, principal, namespace, scopeHint);
101
+ let stopped = abortSignal?.aborted === true;
102
+ const { promise: stoppedPromise, resolve: stopWaiting } = Promise.withResolvers();
103
+ const stop = () => {
104
+ if (stopped) return;
105
+ stopped = true;
106
+ stopWaiting();
107
+ };
108
+ let abortHandler;
109
+ if (abortSignal) {
110
+ abortHandler = () => stop();
111
+ abortSignal.addEventListener("abort", abortHandler, { once: true });
112
+ }
113
+ registerCancellation?.(stop);
114
+ const raceSettle = async (work) => {
115
+ try {
116
+ await Promise.race([work, stoppedPromise]);
117
+ } catch (error) {
118
+ return { kind: "rejected", error };
119
+ }
120
+ return stopped ? { kind: "stopped" } : { kind: "settled" };
129
121
  };
130
- registerCancellation?.(abortTracked);
131
- abortSignal?.addEventListener("abort", abortTracked, { once: true });
132
122
  try {
133
- await this.waitForPreparations(sessionKey, principal, namespace, scopeHint);
134
- if (cancelled || abortSignal?.aborted) return;
123
+ await Promise.race([
124
+ this.waitForPreparations(sessionKey, principal, namespace, scopeHint),
125
+ stoppedPromise
126
+ ]);
127
+ if (stopped) return;
135
128
  if (preemptAfterAdmission) {
136
129
  preemptAfterAdmission();
137
130
  const running = this.entries.get(key)?.running;
138
131
  if (!running) return;
139
- try {
140
- await running;
141
- } catch (error) {
132
+ const outcome = await raceSettle(running);
133
+ if (outcome.kind === "stopped") return;
134
+ if (outcome.kind === "rejected") {
142
135
  if (this.entries.get(key)?.running === running) this.entries.delete(key);
143
- if (!(error instanceof Error && isPreemptedExtraction(error))) throw error;
136
+ if (!(outcome.error instanceof Error && isPreemptedExtraction(outcome.error))) {
137
+ throw outcome.error;
138
+ }
144
139
  }
145
140
  return;
146
141
  }
147
142
  while (true) {
148
143
  const entry = this.entries.get(key);
149
144
  if (!entry) return;
150
- try {
151
- await entry.promise;
152
- } catch (error) {
153
- if (this.entries.get(key) !== entry) continue;
154
- this.entries.delete(key);
155
- if (error instanceof Error && isPreemptedExtraction(error)) return;
156
- throw error;
145
+ const outcome = await raceSettle(entry.promise);
146
+ if (outcome.kind === "stopped") return;
147
+ if (outcome.kind === "rejected") {
148
+ if (!(outcome.error instanceof Error && isPreemptedExtraction(outcome.error))) {
149
+ if (this.entries.get(key) === void 0) {
150
+ this.entries.delete(key);
151
+ throw outcome.error;
152
+ }
153
+ continue;
154
+ }
155
+ if (this.entries.get(key) === entry) this.entries.delete(key);
156
+ return;
157
157
  }
158
158
  if (this.entries.get(key) !== entry) continue;
159
159
  this.entries.delete(key);
160
160
  return;
161
161
  }
162
162
  } finally {
163
- abortSignal?.removeEventListener("abort", abortTracked);
163
+ if (abortHandler && abortSignal) abortSignal.removeEventListener("abort", abortHandler);
164
164
  }
165
165
  }
166
166
  };
@@ -169,4 +169,4 @@ export {
169
169
  pendingObserveScopeHint,
170
170
  PendingObserveExtractionTracker
171
171
  };
172
- //# sourceMappingURL=chunk-CYTTY4M2.js.map
172
+ //# sourceMappingURL=chunk-OPXK5IQU.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/access-observe-helpers.ts"],"sourcesContent":["import { isPreemptedExtraction } from \"./abort-error.js\";\n\ntype PendingObservePreparation = {\n cancelled: boolean;\n scopeHint?: string;\n principal?: string;\n namespace?: string;\n scopeResolved: boolean;\n resolvedScopeFences: Array<{ principal?: string; namespace?: string }>;\n released: Promise<void>;\n release: () => void;\n};\n\nfunction resolvedScopesMatch(\n left: { principal?: string; namespace?: string },\n right: { principal?: string; namespace?: string },\n): boolean {\n return left.principal === right.principal && left.namespace === right.namespace;\n}\n\nfunction preparationMatchesScope(\n reservation: PendingObservePreparation,\n principal: string | undefined,\n namespace: string | undefined,\n scopeHint: string | undefined,\n): boolean {\n if (reservation.scopeResolved) {\n return resolvedScopesMatch(reservation, { principal, namespace });\n }\n return reservation.scopeHint === undefined || scopeHint === undefined || reservation.scopeHint === scopeHint;\n}\n\nexport type PendingObservePreparationHandle = {\n isCancelled(): boolean;\n setScope(principal?: string, namespace?: string): void;\n release(): void;\n};\n\nexport function pendingObserveScopeHint(options: {\n namespace?: string;\n projectTag?: string;\n cwd?: string;\n}): string | undefined {\n const namespace = options.namespace?.trim();\n if (namespace) return `namespace:${namespace}`;\n const projectTag = options.projectTag?.trim();\n if (projectTag) return `projectTag:${projectTag}`;\n const cwd = options.cwd?.trim();\n return cwd ? `cwd:${cwd}` : undefined;\n}\n\ntype PendingObserveExtraction = {\n promise: Promise<void>;\n running: Promise<void>;\n};\n\nexport class PendingObserveExtractionTracker {\n private readonly entries = new Map<string, PendingObserveExtraction>();\n private readonly preparations = new Map<string, Set<PendingObservePreparation>>();\n\n reserve(sessionKey: string, scopeHint?: string): PendingObservePreparationHandle {\n let released = false;\n let resolveReleased: () => void = () => {};\n const reservation: PendingObservePreparation = {\n cancelled: false,\n scopeResolved: false,\n resolvedScopeFences: [],\n scopeHint,\n released: new Promise<void>((resolve) => {\n resolveReleased = resolve;\n }),\n release: () => {\n if (released) return;\n released = true;\n const entries = this.preparations.get(sessionKey);\n entries?.delete(reservation);\n if (entries?.size === 0) this.preparations.delete(sessionKey);\n resolveReleased();\n },\n };\n const entries = this.preparations.get(sessionKey) ?? new Set<PendingObservePreparation>();\n entries.add(reservation);\n this.preparations.set(sessionKey, entries);\n return {\n isCancelled: () => reservation.cancelled,\n setScope: (principal, namespace) => {\n reservation.principal = principal;\n reservation.namespace = namespace;\n reservation.scopeResolved = true;\n if (reservation.resolvedScopeFences.some((fence) => resolvedScopesMatch(reservation, fence))) {\n reservation.cancelled = true;\n }\n },\n release: reservation.release,\n };\n }\n\n private async waitForPreparations(\n sessionKey: string,\n principal: string | undefined,\n namespace: string | undefined,\n scopeHint: string | undefined,\n ): Promise<void> {\n while (true) {\n const reservations = [...(this.preparations.get(sessionKey) ?? [])];\n for (const reservation of reservations) {\n if (\n !reservation.cancelled &&\n !reservation.scopeResolved &&\n !preparationMatchesScope(reservation, principal, namespace, scopeHint) &&\n !reservation.resolvedScopeFences.some((fence) =>\n resolvedScopesMatch(fence, { principal, namespace }),\n )\n ) {\n reservation.resolvedScopeFences.push({ principal, namespace });\n }\n }\n const pending = reservations.filter(\n (reservation) =>\n !reservation.cancelled && preparationMatchesScope(reservation, principal, namespace, scopeHint),\n );\n if (pending.length === 0) return;\n await Promise.all(pending.map((reservation) => reservation.released));\n }\n }\n\n\n key(sessionKey: string, principal: string | undefined, namespace: string | undefined): string {\n return `${sessionKey}\\u0000${principal ?? \"\"}\\u0000${namespace ?? \"\"}`;\n }\n\n track(key: string, extraction: Promise<void>): void {\n const previous = this.entries.get(key);\n const promise = previous\n ? Promise.allSettled([previous.promise, extraction]).then((results) => {\n const rejected = results.find(\n (result): result is PromiseRejectedResult =>\n result.status === \"rejected\" &&\n !(result.reason instanceof Error && isPreemptedExtraction(result.reason)),\n );\n if (rejected) throw rejected.reason;\n })\n : extraction;\n const entry = { promise, running: previous?.running ?? extraction };\n this.entries.set(key, entry);\n // Any settle (success OR rejection — preemption is just one rejection\n // kind) ends the pending entry; leaving a settled failure tracked wedged\n // the key and chained later observes onto a dead promise.\n void promise\n .then(() => {\n if (this.entries.get(key) === entry) this.entries.delete(key);\n })\n .catch(() => {\n if (this.entries.get(key) === entry) this.entries.delete(key);\n });\n }\n\n async wait(\n sessionKey: string,\n principal: string | undefined,\n namespace: string | undefined,\n abortSignal?: AbortSignal,\n registerCancellation?: (cancel: () => void) => void,\n scopeHint?: string,\n preemptAfterAdmission?: () => void,\n ): Promise<void> {\n const key = this.key(sessionKey, principal, namespace);\n // COS-825: a dead force-flush caller (abort or deadline) stops only its\n // own WAIT. The tracked extractions were accepted by other observes and\n // keep running to completion — stopping must never cancel them.\n let stopped = abortSignal?.aborted === true;\n const { promise: stoppedPromise, resolve: stopWaiting } = Promise.withResolvers<void>();\n const stop = (): void => {\n if (stopped) return;\n stopped = true;\n stopWaiting();\n };\n let abortHandler: (() => void) | undefined;\n if (abortSignal) {\n abortHandler = () => stop();\n abortSignal.addEventListener(\"abort\", abortHandler, { once: true });\n }\n registerCancellation?.(stop);\n // The outcome is TAGGED at the reaction site: a rejection must reach the\n // caller even when the tracker's own settle handler deletes the entry\n // first (a bare `Promise.race` loses that race to the deletion).\n type SettleOutcome =\n | { kind: \"stopped\" }\n | { kind: \"settled\" }\n | { kind: \"rejected\"; error: unknown };\n const raceSettle = async (work: Promise<void>): Promise<SettleOutcome> => {\n try {\n await Promise.race([work, stoppedPromise]);\n } catch (error) {\n return { kind: \"rejected\", error };\n }\n return stopped ? { kind: \"stopped\" } : { kind: \"settled\" };\n };\n try {\n await Promise.race([\n this.waitForPreparations(sessionKey, principal, namespace, scopeHint),\n stoppedPromise,\n ]);\n if (stopped) return;\n if (preemptAfterAdmission) {\n preemptAfterAdmission();\n const running = this.entries.get(key)?.running;\n if (!running) return;\n const outcome = await raceSettle(running);\n if (outcome.kind === \"stopped\") return;\n if (outcome.kind === \"rejected\") {\n if (this.entries.get(key)?.running === running) this.entries.delete(key);\n if (!(outcome.error instanceof Error && isPreemptedExtraction(outcome.error))) {\n throw outcome.error;\n }\n }\n return;\n }\n while (true) {\n const entry = this.entries.get(key);\n if (!entry) return;\n const outcome = await raceSettle(entry.promise);\n if (outcome.kind === \"stopped\") return;\n if (outcome.kind === \"rejected\") {\n if (!(outcome.error instanceof Error && isPreemptedExtraction(outcome.error))) {\n // A replaced entry means a newer generation owns the wait; a\n // REMOVED entry means this generation settled — its failure is\n // ours to surface.\n if (this.entries.get(key) === undefined) {\n this.entries.delete(key);\n throw outcome.error;\n }\n continue;\n }\n if (this.entries.get(key) === entry) this.entries.delete(key);\n return;\n }\n if (this.entries.get(key) !== entry) continue;\n this.entries.delete(key);\n return;\n }\n } finally {\n if (abortHandler && abortSignal) abortSignal.removeEventListener(\"abort\", abortHandler);\n }\n }\n}\n"],"mappings":";;;;;AAaA,SAAS,oBACP,MACA,OACS;AACT,SAAO,KAAK,cAAc,MAAM,aAAa,KAAK,cAAc,MAAM;AACxE;AAEA,SAAS,wBACP,aACA,WACA,WACA,WACS;AACT,MAAI,YAAY,eAAe;AAC7B,WAAO,oBAAoB,aAAa,EAAE,WAAW,UAAU,CAAC;AAAA,EAClE;AACA,SAAO,YAAY,cAAc,UAAa,cAAc,UAAa,YAAY,cAAc;AACrG;AAQO,SAAS,wBAAwB,SAIjB;AACrB,QAAM,YAAY,QAAQ,WAAW,KAAK;AAC1C,MAAI,UAAW,QAAO,aAAa,SAAS;AAC5C,QAAM,aAAa,QAAQ,YAAY,KAAK;AAC5C,MAAI,WAAY,QAAO,cAAc,UAAU;AAC/C,QAAM,MAAM,QAAQ,KAAK,KAAK;AAC9B,SAAO,MAAM,OAAO,GAAG,KAAK;AAC9B;AAOO,IAAM,kCAAN,MAAsC;AAAA,EAC1B,UAAU,oBAAI,IAAsC;AAAA,EACpD,eAAe,oBAAI,IAA4C;AAAA,EAEhF,QAAQ,YAAoB,WAAqD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C,YAAI,QAAQ,SAAS,YAAY;AAC/B,cAAI,EAAE,QAAQ,iBAAiB,SAAS,sBAAsB,QAAQ,KAAK,IAAI;AAI7E,gBAAI,KAAK,QAAQ,IAAI,GAAG,MAAM,QAAW;AACvC,mBAAK,QAAQ,OAAO,GAAG;AACvB,oBAAM,QAAQ;AAAA,YAChB;AACA;AAAA,UACF;AACA,cAAI,KAAK,QAAQ,IAAI,GAAG,MAAM,MAAO,MAAK,QAAQ,OAAO,GAAG;AAC5D;AAAA,QACF;AACA,YAAI,KAAK,QAAQ,IAAI,GAAG,MAAM,MAAO;AACrC,aAAK,QAAQ,OAAO,GAAG;AACvB;AAAA,MACF;AAAA,IACF,UAAE;AACA,UAAI,gBAAgB,YAAa,aAAY,oBAAoB,SAAS,YAAY;AAAA,IACxF;AAAA,EACF;AACF;","names":["entries"]}
package/dist/cli.js CHANGED
@@ -91,7 +91,7 @@ import {
91
91
  runWorkProductStatusCliCommand,
92
92
  runWorkProjectCliCommand,
93
93
  runWorkTaskCliCommand
94
- } from "./chunk-MTKSH7HY.js";
94
+ } from "./chunk-ABPOW3SX.js";
95
95
  import "./chunk-GOZXQNIM.js";
96
96
  import "./chunk-PQM3B54K.js";
97
97
  import "./chunk-7KTORRIK.js";
@@ -590,7 +590,7 @@ import "./chunk-IDYYGOOQ.js";
590
590
  import "./chunk-ZQUVBZI4.js";
591
591
  import "./chunk-VBQ3FIS2.js";
592
592
  import "./chunk-QKDXO4FD.js";
593
- import "./chunk-CYTTY4M2.js";
593
+ import "./chunk-OPXK5IQU.js";
594
594
  import "./chunk-L3E7MLMK.js";
595
595
  import "./chunk-MLNDSATI.js";
596
596
  import "./chunk-Z64TS5V4.js";
@@ -8,7 +8,7 @@ import {
8
8
  shouldSkipImplicitExtraction,
9
9
  stripInlineExplicitCaptureNotes,
10
10
  validateExplicitCaptureInput
11
- } from "./chunk-MTKSH7HY.js";
11
+ } from "./chunk-ABPOW3SX.js";
12
12
  import "./chunk-GOZXQNIM.js";
13
13
  import "./chunk-PQM3B54K.js";
14
14
  import "./chunk-7KTORRIK.js";
@@ -507,7 +507,7 @@ import "./chunk-IDYYGOOQ.js";
507
507
  import "./chunk-ZQUVBZI4.js";
508
508
  import "./chunk-VBQ3FIS2.js";
509
509
  import "./chunk-QKDXO4FD.js";
510
- import "./chunk-CYTTY4M2.js";
510
+ import "./chunk-OPXK5IQU.js";
511
511
  import "./chunk-L3E7MLMK.js";
512
512
  import "./chunk-MLNDSATI.js";
513
513
  import "./chunk-Z64TS5V4.js";
package/dist/index.js CHANGED
@@ -259,7 +259,7 @@ import {
259
259
  writeManifest,
260
260
  writeMeetingEpisodeMemory,
261
261
  writeTimelineState
262
- } from "./chunk-MTKSH7HY.js";
262
+ } from "./chunk-ABPOW3SX.js";
263
263
  import "./chunk-GOZXQNIM.js";
264
264
  import "./chunk-PQM3B54K.js";
265
265
  import {
@@ -1689,7 +1689,7 @@ import {
1689
1689
  searchWithGenericExclusion
1690
1690
  } from "./chunk-VBQ3FIS2.js";
1691
1691
  import "./chunk-QKDXO4FD.js";
1692
- import "./chunk-CYTTY4M2.js";
1692
+ import "./chunk-OPXK5IQU.js";
1693
1693
  import "./chunk-L3E7MLMK.js";
1694
1694
  import "./chunk-MLNDSATI.js";
1695
1695
  import "./chunk-Z64TS5V4.js";
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  BufferDrainRunner
3
- } from "../chunk-T3XOP7TA.js";
4
- import "../chunk-MTKSH7HY.js";
3
+ } from "../chunk-7X6EZ2QB.js";
4
+ import "../chunk-ABPOW3SX.js";
5
5
  import "../chunk-GOZXQNIM.js";
6
6
  import "../chunk-PQM3B54K.js";
7
7
  import "../chunk-7KTORRIK.js";
@@ -502,7 +502,7 @@ import "../chunk-IDYYGOOQ.js";
502
502
  import "../chunk-ZQUVBZI4.js";
503
503
  import "../chunk-VBQ3FIS2.js";
504
504
  import "../chunk-QKDXO4FD.js";
505
- import "../chunk-CYTTY4M2.js";
505
+ import "../chunk-OPXK5IQU.js";
506
506
  import "../chunk-L3E7MLMK.js";
507
507
  import "../chunk-MLNDSATI.js";
508
508
  import "../chunk-Z64TS5V4.js";
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  BufferDrainRunner,
3
3
  ClaimBufferStorage
4
- } from "../chunk-T3XOP7TA.js";
5
- import "../chunk-MTKSH7HY.js";
4
+ } from "../chunk-7X6EZ2QB.js";
5
+ import "../chunk-ABPOW3SX.js";
6
6
  import "../chunk-GOZXQNIM.js";
7
7
  import "../chunk-PQM3B54K.js";
8
8
  import "../chunk-7KTORRIK.js";
@@ -501,7 +501,7 @@ import "../chunk-IDYYGOOQ.js";
501
501
  import "../chunk-ZQUVBZI4.js";
502
502
  import "../chunk-VBQ3FIS2.js";
503
503
  import "../chunk-QKDXO4FD.js";
504
- import "../chunk-CYTTY4M2.js";
504
+ import "../chunk-OPXK5IQU.js";
505
505
  import "../chunk-L3E7MLMK.js";
506
506
  import "../chunk-MLNDSATI.js";
507
507
  import "../chunk-Z64TS5V4.js";
@@ -81,6 +81,16 @@ export declare class ExtractionQueueCoordinator {
81
81
  /** Preempt slots of the currently running tasks, keyed by slot identity. */
82
82
  private readonly preemptSlots;
83
83
  private preemptSeq;
84
+ /**
85
+ * COS-825: keys whose running task was already preempted for a force-flush
86
+ * once. A flush preempts a session's extraction at most once per episode:
87
+ * the retried generation (the turns the preempted task left buffered) is
88
+ * waited for, never killed again, until some task for the key succeeds.
89
+ * This stops the livelock where every flush call killed the extraction that
90
+ * was about to finish and then died on its own deadline, so nothing ever
91
+ * completed.
92
+ */
93
+ private readonly preemptedKeys;
84
94
  /** Running tasks per lane — the backlog share and the foreground floor. */
85
95
  private activeBacklog;
86
96
  private activeForeground;
@@ -155,7 +165,10 @@ export declare class ExtractionQueueCoordinator {
155
165
  * `key` and abort nothing when none does. Unlike `preemptRunning` there is
156
166
  * deliberately no newest-slot fallback - a keyed caller (force-flush on
157
167
  * session K) must never take out an unrelated background task just
158
- * because K's own extraction is not (yet) armed. */
168
+ * because K's own extraction is not (yet) armed.
169
+ * COS-825: at most one preemption per key episode — once K's task has
170
+ * been preempted, later flushes wait for the retried work; the latch
171
+ * clears when a task for K succeeds. */
159
172
  preemptKeyed(key: string): void;
160
173
  private createPreemptHandle;
161
174
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"extraction-queue-coordinator.d.ts","sourceRoot":"","sources":["../../src/orchestration/extraction-queue-coordinator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAKH;mEACmE;AACnE,MAAM,WAAW,uBAAuB;IACtC,uEAAuE;IACvE,GAAG,CAAC,KAAK,EAAE,MAAM,IAAI,GAAG,IAAI,CAAC;IAC7B,mDAAmD;IACnD,MAAM,IAAI,IAAI,CAAC;CAChB;AAED,2EAA2E;AAC3E,MAAM,MAAM,mBAAmB,GAAG,CAAC,OAAO,CAAC,EAAE,uBAAuB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAEvF,MAAM,WAAW,6BAA6B;IAC5C,2EAA2E;IAC3E,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,sEAAsE;IACtE,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;;;;;;OAOG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAgBD;;;GAGG;AACH,qBAAa,0BAA0B;IACrC,qFAAqF;IACrF,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IACrC;;;OAGG;IACH,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAoB;IAC1C,mDAAmD;IACnD,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,SAAS,CAAQ;IACzB,qEAAqE;IACrE,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAqB;IAChD;;;;;OAKG;IACH,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAqB;IAClD,4EAA4E;IAC5E,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAkC;IAC/D,OAAO,CAAC,UAAU,CAAK;I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pB,qEAAqE;IACrE,OAAO,CAAC,iBAAiB;IAczB,iFAAiF;YACnE,QAAQ;IAetB;;gDAE4C;IAC5C,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,uBAAuB;IAMzD;;;;yDAIqD;IACrD,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAS/B,OAAO,CAAC,mBAAmB;IAa3B;;;;;;;;;;;;;;;;OAgBG;IACH,yBAAyB,CACvB,GAAG,EAAE,OAAO,EACZ,MAAM,EAAE,MAAM,GAAG,WAAW,GAC3B,IAAI;IAgBP;;;;;OAKG;IACG,WAAW,CAAC,SAAS,GAAE,MAAe,GAAG,OAAO,CAAC,OAAO,CAAC;IAoB/D;;;;OAIG;IACH,OAAO,CAAC,IAAI,EAAE,mBAAmB,EAAE,OAAO,CAAC,EAAE;QAAE,GAAG,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI;IAKpE,+EAA+E;IAC/E,KAAK,IAAI,mBAAmB,GAAG,SAAS;IAIxC;;;;OAIG;IACH,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI;CAG3C"}
1
+ {"version":3,"file":"extraction-queue-coordinator.d.ts","sourceRoot":"","sources":["../../src/orchestration/extraction-queue-coordinator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAKH;mEACmE;AACnE,MAAM,WAAW,uBAAuB;IACtC,uEAAuE;IACvE,GAAG,CAAC,KAAK,EAAE,MAAM,IAAI,GAAG,IAAI,CAAC;IAC7B,mDAAmD;IACnD,MAAM,IAAI,IAAI,CAAC;CAChB;AAED,2EAA2E;AAC3E,MAAM,MAAM,mBAAmB,GAAG,CAAC,OAAO,CAAC,EAAE,uBAAuB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAEvF,MAAM,WAAW,6BAA6B;IAC5C,2EAA2E;IAC3E,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,sEAAsE;IACtE,GAAG,C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IACH,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI;CAG3C"}
@@ -6,7 +6,7 @@ import {
6
6
  mergeGraphExpandedResults,
7
7
  qmdStartupCollectionChecksWithTimeout,
8
8
  resolveEffectiveIdentityInjectionMode
9
- } from "./chunk-MTKSH7HY.js";
9
+ } from "./chunk-ABPOW3SX.js";
10
10
  import "./chunk-GOZXQNIM.js";
11
11
  import "./chunk-PQM3B54K.js";
12
12
  import "./chunk-7KTORRIK.js";
@@ -548,7 +548,7 @@ import "./chunk-IDYYGOOQ.js";
548
548
  import "./chunk-ZQUVBZI4.js";
549
549
  import "./chunk-VBQ3FIS2.js";
550
550
  import "./chunk-QKDXO4FD.js";
551
- import "./chunk-CYTTY4M2.js";
551
+ import "./chunk-OPXK5IQU.js";
552
552
  import "./chunk-L3E7MLMK.js";
553
553
  import "./chunk-MLNDSATI.js";
554
554
  import "./chunk-Z64TS5V4.js";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  runRecallNavigation
3
- } from "./chunk-MTKSH7HY.js";
3
+ } from "./chunk-ABPOW3SX.js";
4
4
  import "./chunk-GOZXQNIM.js";
5
5
  import "./chunk-PQM3B54K.js";
6
6
  import "./chunk-7KTORRIK.js";
@@ -499,7 +499,7 @@ import "./chunk-IDYYGOOQ.js";
499
499
  import "./chunk-ZQUVBZI4.js";
500
500
  import "./chunk-VBQ3FIS2.js";
501
501
  import "./chunk-QKDXO4FD.js";
502
- import "./chunk-CYTTY4M2.js";
502
+ import "./chunk-OPXK5IQU.js";
503
503
  import "./chunk-L3E7MLMK.js";
504
504
  import "./chunk-MLNDSATI.js";
505
505
  import "./chunk-Z64TS5V4.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remnic/core",
3
- "version": "10.0.188",
3
+ "version": "10.0.189",
4
4
  "description": "Framework-agnostic Remnic memory engine — orchestrator, storage, extraction, search, trust zones",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -3416,7 +3416,7 @@
3416
3416
  "core"
3417
3417
  ],
3418
3418
  "peerDependencies": {
3419
- "@remnic/coding-graph": "^10.0.188"
3419
+ "@remnic/coding-graph": "^10.0.189"
3420
3420
  },
3421
3421
  "peerDependenciesMeta": {
3422
3422
  "@remnic/coding-graph": {
@@ -58,3 +58,74 @@ test("preemptRunning keeps the newest-slot fallback for keyless calls", () => {
58
58
  assert.deepEqual(first.aborted, []);
59
59
  assert.deepEqual(second.aborted, ["sess-b"]);
60
60
  });
61
+
62
+ test("preemptKeyed latches a key: the retried generation is not re-preempted", () => {
63
+ const coordinator = new ExtractionQueueCoordinator();
64
+ const first: Capture = { key: "sess-a", aborted: [] };
65
+ captureSlot(coordinator, first, "sess-a");
66
+ coordinator.preemptKeyed("sess-a");
67
+ assert.deepEqual(first.aborted, ["sess-a"]);
68
+
69
+ // The retry arms a fresh slot; a second flush must let it finish (COS-825
70
+ // preemption livelock: repeated flushes killed every retried generation).
71
+ const retried: Capture = { key: "sess-a", aborted: [] };
72
+ captureSlot(coordinator, retried, "sess-a");
73
+ coordinator.preemptKeyed("sess-a");
74
+ assert.deepEqual(retried.aborted, [], "a key already preempted once must not be preempted again");
75
+ });
76
+
77
+ test("a successful task for the key clears the latch and restores flush priority", async () => {
78
+ const coordinator = new ExtractionQueueCoordinator();
79
+ const first: Capture = { key: "sess-a", aborted: [] };
80
+ captureSlot(coordinator, first, "sess-a");
81
+ coordinator.preemptKeyed("sess-a");
82
+ assert.deepEqual(first.aborted, ["sess-a"]);
83
+
84
+ const { promise: gate, resolve: release } = Promise.withResolvers<void>();
85
+ coordinator.enqueue(() => gate, { key: "sess-a" });
86
+ release();
87
+ assert.equal(await coordinator.waitForIdle(2000), true);
88
+
89
+ const next: Capture = { key: "sess-a", aborted: [] };
90
+ captureSlot(coordinator, next, "sess-a");
91
+ coordinator.preemptKeyed("sess-a");
92
+ assert.deepEqual(next.aborted, ["sess-a"], "a completed episode resets priority");
93
+ });
94
+
95
+ test("preemptRunning skips a latched same-key victim but still steals an unrelated slot", () => {
96
+ const coordinator = new ExtractionQueueCoordinator();
97
+ const first: Capture = { key: "sess-a", aborted: [] };
98
+ captureSlot(coordinator, first, "sess-a");
99
+ coordinator.preemptKeyed("sess-a");
100
+ assert.deepEqual(first.aborted, ["sess-a"]);
101
+
102
+ const retried: Capture = { key: "sess-a", aborted: [] };
103
+ const other: Capture = { key: "sess-b", aborted: [] };
104
+ captureSlot(coordinator, retried, "sess-a");
105
+ captureSlot(coordinator, other, "sess-b");
106
+ coordinator.preemptRunning("sess-a");
107
+ assert.deepEqual(retried.aborted, [], "latched same-key slot must survive the flush's slot steal");
108
+ assert.deepEqual(other.aborted, ["sess-b"], "unrelated slot steal keeps flush priority");
109
+ });
110
+
111
+ test("keyless preemptRunning latches the victim's key too", () => {
112
+ const coordinator = new ExtractionQueueCoordinator();
113
+ const victim: Capture = { key: "sess-a", aborted: [] };
114
+ captureSlot(coordinator, victim, "sess-a");
115
+ coordinator.preemptRunning();
116
+ assert.deepEqual(victim.aborted, ["sess-a"]);
117
+
118
+ const retried: Capture = { key: "sess-a", aborted: [] };
119
+ captureSlot(coordinator, retried, "sess-a");
120
+ coordinator.preemptKeyed("sess-a");
121
+ assert.deepEqual(retried.aborted, []);
122
+ });
123
+
124
+ test("preemptKeyed with no armed match does not latch the key", () => {
125
+ const coordinator = new ExtractionQueueCoordinator();
126
+ coordinator.preemptKeyed("sess-a");
127
+ const later: Capture = { key: "sess-a", aborted: [] };
128
+ captureSlot(coordinator, later, "sess-a");
129
+ coordinator.preemptKeyed("sess-a");
130
+ assert.deepEqual(later.aborted, ["sess-a"], "nothing was preempted, so priority is intact");
131
+ });
@@ -69,67 +69,32 @@ export async function extractionForceFlush(
69
69
  committed = true;
70
70
  request.onCommitted?.();
71
71
  };
72
- let abortHandler: (() => void) | undefined;
73
72
 
73
+ // COS-825: a force-flush caller going away (client abort or deadline) stops
74
+ // only the flush's OWN wait and drain. Extractions already queued by other
75
+ // observes are accepted work — they keep running and clear their own turns,
76
+ // so a disconnecting or timed-out flush caller can never stall the backlog.
74
77
  const reservationScopeHint = pendingObserveScopeHint(request);
75
- const cancelBeforeScopeResolution = (): void => {
76
- const explicitNamespace = request.namespace?.trim();
77
- if (explicitNamespace) {
78
- deps.cancelPendingObserveExtractions?.(
79
- request.sessionKey,
80
- authenticatedPrincipal ?? sessionPrincipal,
81
- explicitNamespace,
82
- reservationScopeHint,
83
- );
84
- return;
85
- }
86
- if (reservationScopeHint !== undefined) {
87
- deps.cancelPendingObservePreparations?.(request.sessionKey, reservationScopeHint);
88
- return;
89
- }
90
- if (!namespacesEnabled) {
91
- deps.cancelPendingObserveExtractions?.(request.sessionKey);
92
- }
93
- };
94
78
 
95
79
  try {
96
- let scope: MemoryScopePlan;
97
- try {
98
- scope = await awaitSessionFlushPhase(
99
- () => deps.resolveMemoryScopePlan(request),
100
- {
101
- abortSignal: request.abortSignal,
102
- extractionDeadlineMs: deadlineAt,
103
- reason: "access_force_flush",
104
- deadlineStage: "scope_resolution",
105
- onDeadline: cancelBeforeScopeResolution,
106
- },
107
- );
108
- } catch (error) {
109
- if (request.abortSignal?.aborted) cancelBeforeScopeResolution();
110
- throw error;
111
- }
112
- const cancelScopedPendingObserveExtractions = (): void => {
113
- deps.cancelPendingObserveExtractions?.(
114
- request.sessionKey,
115
- scope.principal,
116
- scope.writeNamespace,
117
- reservationScopeHint,
118
- );
119
- };
120
- if (request.abortSignal?.aborted) cancelScopedPendingObserveExtractions();
80
+ const scope: MemoryScopePlan = await awaitSessionFlushPhase(
81
+ () => deps.resolveMemoryScopePlan(request),
82
+ {
83
+ abortSignal: request.abortSignal,
84
+ extractionDeadlineMs: deadlineAt,
85
+ reason: "access_force_flush",
86
+ deadlineStage: "scope_resolution",
87
+ },
88
+ );
121
89
  throwIfAborted(request.abortSignal, "extraction force-flush aborted");
122
90
  if (deadlineAt !== undefined && deadlineAt <= Date.now()) {
123
- cancelScopedPendingObserveExtractions();
124
91
  throw new EngramAccessInputError("extraction force-flush deadline exceeded before buffer drain");
125
92
  }
126
- abortHandler = cancelScopedPendingObserveExtractions;
127
- request.abortSignal?.addEventListener("abort", abortHandler, { once: true });
128
93
  // #3251: wait for in-flight observe extractions BEFORE draining —
129
94
  // drain-first could queue the same accepted turns twice. Scoped key, so
130
95
  // never waits on another scope.
131
96
  if (waitForPendingObserveExtraction) {
132
- let cancelPendingObserveExtraction: (() => void) | undefined;
97
+ let stopWaitingForPending: (() => void) | undefined;
133
98
  await awaitSessionFlushPhase(
134
99
  () =>
135
100
  waitForPendingObserveExtraction(
@@ -137,8 +102,8 @@ export async function extractionForceFlush(
137
102
  scope.principal,
138
103
  scope.writeNamespace,
139
104
  request.abortSignal,
140
- (cancel) => {
141
- cancelPendingObserveExtraction = cancel;
105
+ (stop) => {
106
+ stopWaitingForPending = stop;
142
107
  },
143
108
  reservationScopeHint,
144
109
  ),
@@ -147,9 +112,9 @@ export async function extractionForceFlush(
147
112
  extractionDeadlineMs: deadlineAt,
148
113
  reason: "access_force_flush",
149
114
  deadlineStage: "pending_observe_extraction",
115
+ // The flush budget stops the WAIT; the queued extractions continue.
150
116
  onDeadline: () => {
151
- cancelScopedPendingObserveExtractions();
152
- cancelPendingObserveExtraction?.();
117
+ stopWaitingForPending?.();
153
118
  },
154
119
  }
155
120
  );
@@ -175,9 +140,10 @@ export async function extractionForceFlush(
175
140
  extractionDeadlineMs: deadlineAt,
176
141
  reason: "access_force_flush",
177
142
  deadlineStage: "buffer_drain",
143
+ // The flush budget aborts its OWN drain; queued observe extractions
144
+ // keep running (COS-825).
178
145
  onDeadline: () => {
179
146
  drainAbort.abort();
180
- cancelScopedPendingObserveExtractions();
181
147
  },
182
148
  }
183
149
  );
@@ -234,7 +200,5 @@ export async function extractionForceFlush(
234
200
  throw new EngramAccessInputError(error.message);
235
201
  }
236
202
  throw error;
237
- } finally {
238
- if (abortHandler) request.abortSignal?.removeEventListener("abort", abortHandler);
239
203
  }
240
204
  }