@remnic/core 10.0.188 → 10.0.190

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
@@ -2,18 +2,17 @@ import assert from "node:assert/strict";
2
2
  import { spawn } from "node:child_process";
3
3
  import { fileURLToPath } from "node:url";
4
4
  /**
5
- * PendingObserveExtractionTracker settle hygiene — issue: `track`'s settle
6
- * callback only removed the pending entry when the extraction SUCCEEDED or
7
- * was rejected with a preemption error. Any other rejection (a real
8
- * extraction failure) left the entry — and its ever-growing `controllers`
9
- * Set — in the map forever: the next observe for the key chained onto a
10
- * dead promise and every later `cancel` walked stale controllers.
5
+ * PendingObserveExtractionTracker settle hygiene + COS-825 wait contract.
11
6
  *
12
- * The fix deletes the entry on ANY settle (fulfillment or rejection) while
13
- * it is still the current entry. `wait`'s own overlap semantics are
14
- * unchanged: a flush that overlaps a failing extraction still surfaces the
15
- * error; only waits that arrive AFTER the extraction settled stop seeing
16
- * stale failures.
7
+ * Settle hygiene: `track`'s settle callback removes the pending entry on ANY
8
+ * settle (fulfillment or rejection) while it is still the current entry, so
9
+ * a settled failure never wedges the key and overlapping stalled tracks stay
10
+ * bounded.
11
+ *
12
+ * COS-825 wait contract: `wait` observes its caller's abort signal and the
13
+ * registered cancellation ONLY to stop waiting. A dead force-flush caller
14
+ * must never cancel the tracked extractions — they were accepted by other
15
+ * observes and keep running.
17
16
  */
18
17
  import test from "node:test";
19
18
 
@@ -26,10 +25,20 @@ function settle(): Promise<void> {
26
25
  return promise;
27
26
  }
28
27
 
28
+ function rejectable() {
29
+ const { promise, reject } = Promise.withResolvers<void>();
30
+ return { promise, reject };
31
+ }
32
+
33
+ function stalled(): Promise<void> {
34
+ const { promise } = Promise.withResolvers<void>();
35
+ return promise;
36
+ }
37
+
29
38
  test("a settled non-preempted rejection clears the pending entry", async () => {
30
39
  const tracker = new PendingObserveExtractionTracker();
31
40
  const key = tracker.key("session-a", "alice", "default");
32
- tracker.track(key, Promise.reject(new Error("extraction failed")), new AbortController());
41
+ tracker.track(key, Promise.reject(new Error("extraction failed")));
33
42
  await settle();
34
43
 
35
44
  // The entry is gone: the next wait finds nothing pending and returns
@@ -40,7 +49,7 @@ test("a settled non-preempted rejection clears the pending entry", async () => {
40
49
  test("a settled success clears the pending entry for the next observe", async () => {
41
50
  const tracker = new PendingObserveExtractionTracker();
42
51
  const key = tracker.key("session-a", "alice", "default");
43
- tracker.track(key, Promise.resolve(), new AbortController());
52
+ tracker.track(key, Promise.resolve());
44
53
  await settle();
45
54
  await tracker.wait("session-a", "alice", "default");
46
55
  });
@@ -48,8 +57,8 @@ test("a settled success clears the pending entry for the next observe", async ()
48
57
  test("a chained non-preempted rejection clears the chained entry", async () => {
49
58
  const tracker = new PendingObserveExtractionTracker();
50
59
  const key = tracker.key("session-a", "alice", "default");
51
- tracker.track(key, Promise.resolve(), new AbortController());
52
- tracker.track(key, Promise.reject(new Error("second failed")), new AbortController());
60
+ tracker.track(key, Promise.resolve());
61
+ tracker.track(key, Promise.reject(new Error("second failed")));
53
62
  await settle();
54
63
  await tracker.wait("session-a", "alice", "default");
55
64
  });
@@ -57,7 +66,7 @@ test("a chained non-preempted rejection clears the chained entry", async () => {
57
66
  test("a preempted rejection still clears the pending entry", async () => {
58
67
  const tracker = new PendingObserveExtractionTracker();
59
68
  const key = tracker.key("session-a", "alice", "default");
60
- tracker.track(key, Promise.reject(preemptedExtractionError()), new AbortController());
69
+ tracker.track(key, Promise.reject(preemptedExtractionError()));
61
70
  await settle();
62
71
  await tracker.wait("session-a", "alice", "default");
63
72
  });
@@ -65,8 +74,8 @@ test("a preempted rejection still clears the pending entry", async () => {
65
74
  test("a wait overlapping a failing extraction still surfaces the error", async () => {
66
75
  const tracker = new PendingObserveExtractionTracker();
67
76
  const key = tracker.key("session-a", "alice", "default");
68
- const { promise: extraction, reject } = Promise.withResolvers<void>();
69
- tracker.track(key, extraction, new AbortController());
77
+ const { promise: extraction, reject } = rejectable();
78
+ tracker.track(key, extraction);
70
79
  const waiter = assert.rejects(() => tracker.wait("session-a", "alice", "default"), /extraction failed/);
71
80
  await Promise.resolve();
72
81
  reject(new Error("extraction failed"));
@@ -74,30 +83,14 @@ test("a wait overlapping a failing extraction still surfaces the error", async (
74
83
  });
75
84
 
76
85
  /**
77
- * Controller retention — issue: `track` copied every prior controller of the
78
- * key into a fresh Set per tracked extraction, and never-settling promise
79
- * chains keep every generation reachable, so overlapping stalled tracks grew
80
- * quadratically (HeapRepro: ~543MB at 6000 tracks; measured 212.8MB at 4000
81
- * pre-fix vs 4.2MB with the shared per-key set). The fix reuses one Set per
82
- * key; `abortTracked` iterates a snapshot so a reentrant `track` fired from
83
- * an abort listener keeps prior semantics (not aborted by the in-flight
84
- * pass, iteration terminates).
86
+ * Heap retention across overlapping stalled tracks (COS-825 follow-up of the
87
+ * controller-set fix): the tracker keeps ONE merged promise per key, and any
88
+ * settle deletes the entry, so retained heap stays flat. The child process
89
+ * with --expose-gc keeps CI free of gc hooks in the main tree.
85
90
  */
86
- function stalled(): Promise<void> {
87
- const { promise } = Promise.withResolvers<void>();
88
- return promise;
89
- }
90
-
91
- function rejectingAfter(controller: AbortController): Promise<void> {
92
- const { promise, reject } = Promise.withResolvers<void>();
93
- controller.signal.addEventListener("abort", () => reject(controller.signal.reason), { once: true });
94
- return promise;
95
- }
96
-
97
91
  // Runs the retention loop in one short-lived child process with --expose-gc,
98
92
  // so CI exercises it without exposing gc to the whole test tree. The
99
- // assertion keeps a wide margin (4.2MB measured post-fix vs 212.8MB pre-fix
100
- // at the same track count), not a fixed runner heap limit.
93
+ // assertion keeps a wide margin, not a fixed runner heap limit.
101
94
  function drain(stream: NodeJS.ReadableStream): Promise<string> {
102
95
  return new Promise((resolve) => {
103
96
  const chunks: string[] = [];
@@ -122,7 +115,7 @@ gc();
122
115
  const before = process.memoryUsage().heapUsed;
123
116
  const tracker = new PendingObserveExtractionTracker();
124
117
  const key = tracker.key("session-a", "alice", "default");
125
- for (let i = 0; i < 4000; i++) tracker.track(key, new Promise(() => {}), new AbortController());
118
+ for (let i = 0; i < 4000; i++) tracker.track(key, new Promise(() => {}));
126
119
  gc();
127
120
  console.log(JSON.stringify(process.memoryUsage().heapUsed - before));`,
128
121
  trackerSource,
@@ -144,65 +137,55 @@ test("retained heap stays bounded across overlapping stalled tracks", { timeout:
144
137
  const retained = await retainedHeapInChild();
145
138
  assert.ok(
146
139
  retained < 32 * 1024 * 1024,
147
- `retained ${(retained / 1048576).toFixed(1)}MB for 4000 tracks; quadratic controller-set copies keep dead generations alive`,
140
+ `retained ${(retained / 1048576).toFixed(1)}MB for 4000 tracks; per-key entries must not grow quadratically`,
148
141
  );
149
142
  });
150
143
 
151
- test("cancel still aborts every distinct controller across overlapping tracks", () => {
144
+ test("wait stops without cancelling tracked extractions when its abort signal fires", async () => {
152
145
  const tracker = new PendingObserveExtractionTracker();
153
146
  const key = tracker.key("session-a", "alice", "default");
154
- const controllers = Array.from({ length: 50 }, () => new AbortController());
155
- for (const controller of controllers) {
156
- tracker.track(key, stalled(), controller);
157
- }
158
- tracker.cancel("session-a", "alice", "default");
159
- for (const controller of controllers) {
160
- assert.ok(controller.signal.aborted, "every tracked controller must be aborted");
161
- }
147
+ const { promise: extraction, resolve } = Promise.withResolvers<void>();
148
+ tracker.track(key, extraction);
149
+ const abortController = new AbortController();
150
+ const waiter = tracker.wait("session-a", "alice", "default", abortController.signal);
151
+ await Promise.resolve();
152
+ abortController.abort();
153
+ // Returns promptly — it does NOT wait behind the still-running extraction,
154
+ // and it does not cancel or settle it (COS-825).
155
+ await waiter;
156
+ resolve();
157
+ await extraction;
158
+ await settle();
159
+ // The extraction settled cleanly and the entry cleared: no cancellation
160
+ // leaked into the accepted work.
161
+ await tracker.wait("session-a", "alice", "default");
162
162
  });
163
163
 
164
- test("a controller admitted by a reentrant track during cancel is not aborted by that pass", () => {
164
+ test("wait stops via the registered cancellation without cancelling tracked extractions", async () => {
165
165
  const tracker = new PendingObserveExtractionTracker();
166
166
  const key = tracker.key("session-a", "alice", "default");
167
- const first = new AbortController();
168
- const reentrant = new AbortController();
169
- first.signal.addEventListener(
170
- "abort",
171
- () => {
172
- tracker.track(key, stalled(), reentrant);
173
- },
174
- { once: true },
175
- );
176
- tracker.track(key, stalled(), first);
177
- tracker.cancel("session-a", "alice", "default");
178
- assert.ok(first.signal.aborted);
179
- assert.equal(reentrant.signal.aborted, false, "prior behavior: the in-flight abort pass must not abort later admissions");
180
- });
181
-
182
- test("each key aborts and cleans up in isolation", { timeout: 2000 }, async () => {
183
- const tracker = new PendingObserveExtractionTracker();
184
- const keyA = tracker.key("session-a", "alice", "default");
185
- const keyB = tracker.key("session-b", "bob", "default");
186
- const controllerA = new AbortController();
187
- const controllerB = new AbortController();
188
- tracker.track(keyA, rejectingAfter(controllerA), controllerA);
189
- tracker.track(keyB, stalled(), controllerB);
190
- tracker.cancel("session-a", "alice", "default");
191
- assert.ok(controllerA.signal.aborted);
192
- assert.equal(controllerB.signal.aborted, false);
167
+ const { promise: extraction, resolve } = Promise.withResolvers<void>();
168
+ tracker.track(key, extraction);
169
+ // The flush deadline path registers a stop and calls it; nothing else.
170
+ const { promise: stopRegistered, resolve: resolveStop } = Promise.withResolvers<() => void>();
171
+ const waiter = tracker.wait("session-a", "alice", "default", undefined, (stop) => resolveStop(stop));
172
+ const stop = await stopRegistered;
173
+ stop();
174
+ await waiter;
175
+ resolve();
176
+ await extraction;
193
177
  await settle();
194
178
  await tracker.wait("session-a", "alice", "default");
195
179
  });
196
180
 
197
- test("an aborted chain entry settles once every generation settles and cleans up", { timeout: 2000 }, async () => {
181
+ test("an entry settles once every generation settles and cleans up", { timeout: 2000 }, async () => {
198
182
  const tracker = new PendingObserveExtractionTracker();
199
183
  const key = tracker.key("session-a", "alice", "default");
200
- const first = new AbortController();
201
- tracker.track(key, rejectingAfter(first), first);
202
- const second = new AbortController();
184
+ const { promise: first, reject } = rejectable();
185
+ tracker.track(key, first);
203
186
  const { promise: secondExtraction, resolve } = Promise.withResolvers<void>();
204
- tracker.track(key, secondExtraction, second);
205
- first.abort(preemptedExtractionError());
187
+ tracker.track(key, secondExtraction);
188
+ reject(preemptedExtractionError());
206
189
  resolve();
207
190
  await settle();
208
191
  await tracker.wait("session-a", "alice", "default");
@@ -211,18 +194,18 @@ test("an aborted chain entry settles once every generation settles and cleans up
211
194
  test("wait surfaces a chained non-preempted rejection", async () => {
212
195
  const tracker = new PendingObserveExtractionTracker();
213
196
  const key = tracker.key("session-a", "alice", "default");
214
- tracker.track(key, Promise.resolve(), new AbortController());
215
- tracker.track(key, Promise.reject(new Error("extraction failed")), new AbortController());
197
+ tracker.track(key, Promise.resolve());
198
+ tracker.track(key, Promise.reject(new Error("extraction failed")));
216
199
  await assert.rejects(tracker.wait("session-a", "alice", "default"), /extraction failed/);
217
200
  });
218
201
 
219
202
  test("a wait overlapping a preempted rejection returns without throwing", { timeout: 2000 }, async () => {
220
203
  const tracker = new PendingObserveExtractionTracker();
221
204
  const key = tracker.key("session-a", "alice", "default");
222
- const controller = new AbortController();
223
- tracker.track(key, rejectingAfter(controller), controller);
205
+ const { promise: extraction, reject } = rejectable();
206
+ tracker.track(key, extraction);
224
207
  const waiter = tracker.wait("session-a", "alice", "default");
225
208
  await Promise.resolve();
226
- controller.abort(preemptedExtractionError());
209
+ reject(preemptedExtractionError());
227
210
  await waiter;
228
211
  });
@@ -52,7 +52,6 @@ export function pendingObserveScopeHint(options: {
52
52
  type PendingObserveExtraction = {
53
53
  promise: Promise<void>;
54
54
  running: Promise<void>;
55
- controllers: Set<AbortController>;
56
55
  };
57
56
 
58
57
  export class PendingObserveExtractionTracker {
@@ -130,7 +129,7 @@ export class PendingObserveExtractionTracker {
130
129
  return `${sessionKey}\u0000${principal ?? ""}\u0000${namespace ?? ""}`;
131
130
  }
132
131
 
133
- track(key: string, extraction: Promise<void>, controller: AbortController): void {
132
+ track(key: string, extraction: Promise<void>): void {
134
133
  const previous = this.entries.get(key);
135
134
  const promise = previous
136
135
  ? Promise.allSettled([previous.promise, extraction]).then((results) => {
@@ -142,13 +141,11 @@ export class PendingObserveExtractionTracker {
142
141
  if (rejected) throw rejected.reason;
143
142
  })
144
143
  : extraction;
145
- const controllers = previous?.controllers ?? new Set<AbortController>();
146
- controllers.add(controller);
147
- const entry = { promise, running: previous?.running ?? extraction, controllers };
144
+ const entry = { promise, running: previous?.running ?? extraction };
148
145
  this.entries.set(key, entry);
149
146
  // Any settle (success OR rejection — preemption is just one rejection
150
147
  // kind) ends the pending entry; leaving a settled failure tracked wedged
151
- // the key and kept every controller ever registered for it alive.
148
+ // the key and chained later observes onto a dead promise.
152
149
  void promise
153
150
  .then(() => {
154
151
  if (this.entries.get(key) === entry) this.entries.delete(key);
@@ -158,53 +155,6 @@ export class PendingObserveExtractionTracker {
158
155
  });
159
156
  }
160
157
 
161
- cancelPreparations(sessionKey: string, scopeHint?: string): void {
162
- for (const reservation of this.preparations.get(sessionKey) ?? []) {
163
- if (
164
- scopeHint !== undefined &&
165
- reservation.scopeHint !== undefined &&
166
- reservation.scopeHint !== scopeHint
167
- ) {
168
- continue;
169
- }
170
- reservation.cancelled = true;
171
- }
172
- }
173
-
174
- cancel(
175
- sessionKey: string,
176
- principal?: string,
177
- namespace?: string,
178
- scopeHint?: string,
179
- reason?: Error,
180
- ): void {
181
- for (const reservation of this.preparations.get(sessionKey) ?? []) {
182
- if (!preparationMatchesScope(reservation, principal, namespace, scopeHint)) continue;
183
- reservation.cancelled = true;
184
- }
185
-
186
- this.abortTracked(sessionKey, principal, namespace, reason);
187
- }
188
-
189
- private abortTracked(
190
- sessionKey: string,
191
- principal: string | undefined,
192
- namespace: string | undefined,
193
- reason?: Error,
194
- ): void {
195
- for (const [key, entry] of this.entries) {
196
- const [entrySessionKey, entryPrincipal, entryNamespace] = key.split("\u0000");
197
- if (
198
- entrySessionKey !== sessionKey ||
199
- (principal !== undefined && entryPrincipal !== (principal ?? "")) ||
200
- (namespace !== undefined && entryNamespace !== (namespace ?? ""))
201
- ) continue;
202
- // Snapshot: an abort listener may track() synchronously; iterating the
203
- // shared live set would abort that new admission or never terminate.
204
- for (const controller of [...entry.controllers]) controller.abort(reason);
205
- }
206
- }
207
-
208
158
  async wait(
209
159
  sessionKey: string,
210
160
  principal: string | undefined,
@@ -215,45 +165,82 @@ export class PendingObserveExtractionTracker {
215
165
  preemptAfterAdmission?: () => void,
216
166
  ): Promise<void> {
217
167
  const key = this.key(sessionKey, principal, namespace);
218
- let cancelled = abortSignal?.aborted === true;
219
- const abortTracked = (): void => {
220
- cancelled = true;
221
- this.cancel(sessionKey, principal, namespace, scopeHint);
168
+ // COS-825: a dead force-flush caller (abort or deadline) stops only its
169
+ // own WAIT. The tracked extractions were accepted by other observes and
170
+ // keep running to completion — stopping must never cancel them.
171
+ let stopped = abortSignal?.aborted === true;
172
+ const { promise: stoppedPromise, resolve: stopWaiting } = Promise.withResolvers<void>();
173
+ const stop = (): void => {
174
+ if (stopped) return;
175
+ stopped = true;
176
+ stopWaiting();
177
+ };
178
+ let abortHandler: (() => void) | undefined;
179
+ if (abortSignal) {
180
+ abortHandler = () => stop();
181
+ abortSignal.addEventListener("abort", abortHandler, { once: true });
182
+ }
183
+ registerCancellation?.(stop);
184
+ // The outcome is TAGGED at the reaction site: a rejection must reach the
185
+ // caller even when the tracker's own settle handler deletes the entry
186
+ // first (a bare `Promise.race` loses that race to the deletion).
187
+ type SettleOutcome =
188
+ | { kind: "stopped" }
189
+ | { kind: "settled" }
190
+ | { kind: "rejected"; error: unknown };
191
+ const raceSettle = async (work: Promise<void>): Promise<SettleOutcome> => {
192
+ try {
193
+ await Promise.race([work, stoppedPromise]);
194
+ } catch (error) {
195
+ return { kind: "rejected", error };
196
+ }
197
+ return stopped ? { kind: "stopped" } : { kind: "settled" };
222
198
  };
223
- registerCancellation?.(abortTracked);
224
- abortSignal?.addEventListener("abort", abortTracked, { once: true });
225
199
  try {
226
- await this.waitForPreparations(sessionKey, principal, namespace, scopeHint);
227
- if (cancelled || abortSignal?.aborted) return;
200
+ await Promise.race([
201
+ this.waitForPreparations(sessionKey, principal, namespace, scopeHint),
202
+ stoppedPromise,
203
+ ]);
204
+ if (stopped) return;
228
205
  if (preemptAfterAdmission) {
229
206
  preemptAfterAdmission();
230
207
  const running = this.entries.get(key)?.running;
231
208
  if (!running) return;
232
- try {
233
- await running;
234
- } catch (error) {
209
+ const outcome = await raceSettle(running);
210
+ if (outcome.kind === "stopped") return;
211
+ if (outcome.kind === "rejected") {
235
212
  if (this.entries.get(key)?.running === running) this.entries.delete(key);
236
- if (!(error instanceof Error && isPreemptedExtraction(error))) throw error;
213
+ if (!(outcome.error instanceof Error && isPreemptedExtraction(outcome.error))) {
214
+ throw outcome.error;
215
+ }
237
216
  }
238
217
  return;
239
218
  }
240
219
  while (true) {
241
220
  const entry = this.entries.get(key);
242
221
  if (!entry) return;
243
- try {
244
- await entry.promise;
245
- } catch (error) {
246
- if (this.entries.get(key) !== entry) continue;
247
- this.entries.delete(key);
248
- if (error instanceof Error && isPreemptedExtraction(error)) return;
249
- throw error;
222
+ const outcome = await raceSettle(entry.promise);
223
+ if (outcome.kind === "stopped") return;
224
+ if (outcome.kind === "rejected") {
225
+ if (!(outcome.error instanceof Error && isPreemptedExtraction(outcome.error))) {
226
+ // A replaced entry means a newer generation owns the wait; a
227
+ // REMOVED entry means this generation settled — its failure is
228
+ // ours to surface.
229
+ if (this.entries.get(key) === undefined) {
230
+ this.entries.delete(key);
231
+ throw outcome.error;
232
+ }
233
+ continue;
234
+ }
235
+ if (this.entries.get(key) === entry) this.entries.delete(key);
236
+ return;
250
237
  }
251
238
  if (this.entries.get(key) !== entry) continue;
252
239
  this.entries.delete(key);
253
240
  return;
254
241
  }
255
242
  } finally {
256
- abortSignal?.removeEventListener("abort", abortTracked);
243
+ if (abortHandler && abortSignal) abortSignal.removeEventListener("abort", abortHandler);
257
244
  }
258
245
  }
259
246
  }
@@ -121,14 +121,6 @@ export interface AccessObserveWriteSurfaceDeps {
121
121
  authenticatedPrincipal?: string;
122
122
  }
123
123
  ): Promise<MemoryScopePlan>;
124
- cancelPendingObservePreparations?(sessionKey: string, scopeHint?: string): void;
125
- cancelPendingObserveExtractions?(
126
- sessionKey: string,
127
- principal?: string,
128
- namespace?: string,
129
- scopeHint?: string,
130
- reason?: Error,
131
- ): void;
132
124
  resolveReadableNamespace(namespace: string | undefined, principal?: string): string;
133
125
  validateWriteCandidate(
134
126
  request: EngramAccessMemoryStoreRequest | EngramAccessSuggestionSubmitRequest,
@@ -146,19 +138,6 @@ export class AccessObserveWriteSurface {
146
138
  private readonly pendingObserveExtractions = new PendingObserveExtractionTracker();
147
139
  private readonly observeTranscriptPersister = new ObserveTranscriptPersister();
148
140
 
149
- public cancelPendingObservePreparations(sessionKey: string, scopeHint?: string): void {
150
- this.pendingObserveExtractions.cancelPreparations(sessionKey, scopeHint);
151
- }
152
-
153
- public cancelPendingObserveExtractions(
154
- sessionKey: string,
155
- principal?: string,
156
- namespace?: string,
157
- scopeHint?: string,
158
- reason?: Error,
159
- ): void {
160
- this.pendingObserveExtractions.cancel(sessionKey, principal, namespace, scopeHint, reason);
161
- }
162
141
  constructor(private readonly deps: AccessObserveWriteSurfaceDeps) {}
163
142
 
164
143
  private quarantineStore(): WriteQuarantineStore {
@@ -898,7 +877,7 @@ export class AccessObserveWriteSurface {
898
877
  extraction.catch((err) => {
899
878
  log.error(`access-observe background extraction failed: ${err}`);
900
879
  });
901
- this.pendingObserveExtractions.track(trackedExtractionKey, extraction, observeAbortController);
880
+ this.pendingObserveExtractions.track(trackedExtractionKey, extraction);
902
881
  extractionQueued = true;
903
882
  };
904
883
  }