@remnic/core 10.0.184 → 10.0.186

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 (61) hide show
  1. package/dist/access-admin-ops-surface.js +6 -6
  2. package/dist/access-cli.js +6 -6
  3. package/dist/access-extraction-force-flush-preempt.js +6 -6
  4. package/dist/access-extraction-force-flush.js +6 -6
  5. package/dist/access-http-briefing.js +6 -6
  6. package/dist/access-http-query.js +6 -6
  7. package/dist/access-http.js +6 -6
  8. package/dist/access-identity-continuity-surface.js +6 -6
  9. package/dist/access-lcm-surface.js +6 -6
  10. package/dist/access-mcp.js +6 -6
  11. package/dist/access-observe-write-surface.js +6 -6
  12. package/dist/access-operations-batch.js +6 -6
  13. package/dist/access-operations.js +6 -6
  14. package/dist/access-recall-concurrency.js +6 -6
  15. package/dist/access-recall-response.js +6 -6
  16. package/dist/access-recall-surface.js +6 -6
  17. package/dist/access-service.js +6 -6
  18. package/dist/active-recall.js +1 -1
  19. package/dist/{auto-sync-24ATHF7G.js → auto-sync-OOEY2FSA.js} +3 -3
  20. package/dist/{chunk-WCED4XID.js → chunk-3GD5SFDT.js} +2 -2
  21. package/dist/{chunk-OELN4JIO.js → chunk-A3HLZMHD.js} +2 -2
  22. package/dist/{chunk-KUCMDUEZ.js → chunk-DYZDFOBX.js} +1 -1
  23. package/dist/chunk-DYZDFOBX.js.map +1 -0
  24. package/dist/{chunk-YTBBH5YH.js → chunk-LALPM2DN.js} +49 -12
  25. package/dist/chunk-LALPM2DN.js.map +1 -0
  26. package/dist/{chunk-DCEJRGAT.js → chunk-N2PXVLV3.js} +2 -2
  27. package/dist/{chunk-WGNAJEDV.js → chunk-NU5JRN3A.js} +2 -2
  28. package/dist/{chunk-4NVYPWMJ.js → chunk-QSVWIKNY.js} +7 -7
  29. package/dist/chunk-QSVWIKNY.js.map +1 -0
  30. package/dist/cli.js +6 -6
  31. package/dist/config.js +1 -1
  32. package/dist/explicit-capture.js +6 -6
  33. package/dist/extraction-judge.d.ts +4 -3
  34. package/dist/extraction-judge.d.ts.map +1 -1
  35. package/dist/extraction-judge.js +1 -1
  36. package/dist/index.js +6 -6
  37. package/dist/operator-toolkit.js +2 -2
  38. package/dist/orchestration/backlog-scheduler.js +7 -7
  39. package/dist/orchestration/buffer-drain-runner.js +7 -7
  40. package/dist/orchestration/extraction-queue-coordinator.d.ts +20 -0
  41. package/dist/orchestration/extraction-queue-coordinator.d.ts.map +1 -1
  42. package/dist/orchestration/turn-ingestion.d.ts.map +1 -1
  43. package/dist/orchestrator.js +6 -6
  44. package/dist/recall-navigation.js +6 -6
  45. package/dist/resume-bundles.js +2 -2
  46. package/package.json +2 -2
  47. package/src/config.test.ts +3 -3
  48. package/src/config.ts +6 -6
  49. package/src/extraction-judge-chain.test.ts +2 -2
  50. package/src/extraction-judge.ts +4 -3
  51. package/src/orchestration/extraction-queue-coordinator.ts +64 -3
  52. package/src/orchestration/extraction-queue-lane-bias.test.ts +185 -0
  53. package/src/orchestration/turn-ingestion.ts +7 -1
  54. package/dist/chunk-4NVYPWMJ.js.map +0 -1
  55. package/dist/chunk-KUCMDUEZ.js.map +0 -1
  56. package/dist/chunk-YTBBH5YH.js.map +0 -1
  57. /package/dist/{auto-sync-24ATHF7G.js.map → auto-sync-OOEY2FSA.js.map} +0 -0
  58. /package/dist/{chunk-WCED4XID.js.map → chunk-3GD5SFDT.js.map} +0 -0
  59. /package/dist/{chunk-OELN4JIO.js.map → chunk-A3HLZMHD.js.map} +0 -0
  60. /package/dist/{chunk-DCEJRGAT.js.map → chunk-N2PXVLV3.js.map} +0 -0
  61. /package/dist/{chunk-WGNAJEDV.js.map → chunk-NU5JRN3A.js.map} +0 -0
@@ -50,15 +50,28 @@ export interface ExtractionQueueEnqueueOptions {
50
50
  front?: boolean;
51
51
  /** Buffer/session key. Tasks sharing a key never run concurrently. */
52
52
  key?: string;
53
+ /**
54
+ * Backlog/drain task: preferred up to `concurrency - FOREGROUND_FLOOR`
55
+ * concurrent slots whenever foreground work is also queued, so large
56
+ * claimed backlogs fill each call's prompt budget while live sessions
57
+ * keep a guaranteed floor share. The last slot is kept open for a
58
+ * fail-closed flush: a backlog task never fills it even with no
59
+ * foreground work queued.
60
+ */
61
+ backlog?: boolean;
53
62
  }
54
63
 
55
64
  interface QueueEntry {
56
65
  run: ExtractionQueueTask;
57
66
  key?: string;
67
+ backlog?: boolean;
68
+ /** Set by enqueue({ front: true }): jumps the queue ahead of lane bias. */
69
+ front?: boolean;
58
70
  }
59
71
 
60
72
  interface PreemptSlot {
61
73
  key?: string;
74
+ backlog?: boolean;
62
75
  armed?: { abort: () => void; seq: number };
63
76
  }
64
77
 
@@ -89,6 +102,15 @@ export class ExtractionQueueCoordinator {
89
102
  /** Preempt slots of the currently running tasks, keyed by slot identity. */
90
103
  private readonly preemptSlots = new Map<object, PreemptSlot>();
91
104
  private preemptSeq = 0;
105
+ /** Running tasks per lane — the backlog share and the foreground floor. */
106
+ private activeBacklog = 0;
107
+ private activeForeground = 0;
108
+ /**
109
+ * Slots kept available for foreground (non-backlog) tasks while backlog
110
+ * work also waits. A floor of one keeps live sessions extracting even at
111
+ * full backlog pressure; backlog tasks fill the rest.
112
+ */
113
+ private static readonly FOREGROUND_FLOOR = 1;
92
114
  /** Resolves the processor's park while a new task arrives mid-drain. */
93
115
  private wake?: () => void;
94
116
 
@@ -120,7 +142,7 @@ export class ExtractionQueueCoordinator {
120
142
  enqueue(task: ExtractionQueueTask, options?: ExtractionQueueEnqueueOptions): boolean {
121
143
  if (!this.accepting) return false;
122
144
  const key = options?.key;
123
- const entry: QueueEntry = { run: task, key };
145
+ const entry: QueueEntry = { run: task, key, backlog: options?.backlog, front: options?.front };
124
146
  if (options?.front) {
125
147
  this.preemptRunning(options.key);
126
148
  this.queue.unshift(entry);
@@ -184,9 +206,13 @@ export class ExtractionQueueCoordinator {
184
206
  const armed = Array.from(this.preemptSlots.values()).filter((slot) => slot.armed !== undefined);
185
207
  if (armed.length === 0) return;
186
208
  const preferred = preferredKey !== undefined ? armed.find((slot) => slot.key === preferredKey) : undefined;
209
+ // Lane-aware victim choice: with no same-key slot to abort, a flush takes
210
+ // a foreground slot before a backlog one, so drain chunk calls survive
211
+ // routine force-flush preemption while the flush still always wins a slot.
212
+ const victims = armed.some((slot) => slot.backlog !== true) ? armed.filter((slot) => slot.backlog !== true) : armed;
187
213
  const chosen =
188
214
  preferred ??
189
- armed.reduce((a, b) => ((b.armed?.seq ?? -1) > (a.armed?.seq ?? -1) ? b : a));
215
+ victims.reduce((a, b) => ((b.armed?.seq ?? -1) > (a.armed?.seq ?? -1) ? b : a));
190
216
  const abort = chosen.armed?.abort;
191
217
  chosen.armed = undefined;
192
218
  abort?.();
@@ -291,11 +317,44 @@ export class ExtractionQueueCoordinator {
291
317
 
292
318
  /** Take the next queue entry whose key is not already running or reserved (FIFO within a key). */
293
319
  private takeRunnable(): QueueEntry | undefined {
320
+ // Front tasks jump the queue ahead of lane bias: a fail-closed force
321
+ // flush must start before any queued backlog work, even when the
322
+ // foreground floor is open. Same-key and reserved-key checks stay in
323
+ // takeFirstMatching, so a front flush still waits for its own running
324
+ // call rather than preempting it from the selection pass.
325
+ if (this.queue[0]?.front === true) {
326
+ const front = this.takeFirstMatching((entry) => entry.front === true);
327
+ if (front) return front;
328
+ }
329
+ // Lane bias: foreground keeps a floor of FOREGROUND_FLOOR slots while
330
+ // backlog work also waits, so a claimed backlog can never crowd live
331
+ // sessions out entirely; backlog tasks then fill every remaining slot.
332
+ // Backlog never holds the last slot, so a fail-closed flush always
333
+ // finds either a free slot or a foreground victim and never preempts an
334
+ // armed drain call. (A pick-time-only cap leaks: backlog armed to the
335
+ // full count stays armed when the foreground task finishes.) Either
336
+ // lane may still use all slots when the other has work to fill them.
337
+ if (this.activeForeground < ExtractionQueueCoordinator.FOREGROUND_FLOOR) {
338
+ const foreground = this.takeFirstMatching((entry) => entry.backlog !== true);
339
+ if (foreground) return foreground;
340
+ }
341
+ if (this.activeBacklog < Math.max(this.concurrency - 1, 1)) {
342
+ const backlog = this.takeFirstMatching((entry) => entry.backlog === true);
343
+ if (backlog) return backlog;
344
+ }
345
+ return this.takeFirstMatching((entry) => entry.backlog !== true);
346
+ }
347
+
348
+ /** First queue entry satisfying `match` whose key is free to run. */
349
+ private takeFirstMatching(match: (entry: QueueEntry) => boolean): QueueEntry | undefined {
294
350
  for (let index = 0; index < this.queue.length; index += 1) {
295
351
  const entry = this.queue[index];
352
+ if (!match(entry)) continue;
296
353
  if (entry.key !== undefined && (this.activeKeys.has(entry.key) || this.reservedKeys.has(entry.key))) continue;
297
354
  this.queue.splice(index, 1);
298
355
  if (entry.key !== undefined) this.activeKeys.add(entry.key);
356
+ if (entry.backlog === true) this.activeBacklog += 1;
357
+ else this.activeForeground += 1;
299
358
  return entry;
300
359
  }
301
360
  return undefined;
@@ -304,13 +363,15 @@ export class ExtractionQueueCoordinator {
304
363
  /** Run one entry with its own preempt slot; failures are classified + logged. */
305
364
  private async runEntry(entry: QueueEntry): Promise<void> {
306
365
  const slot: PreemptSlot = {};
307
- this.preemptSlots.set(slot, { key: entry.key });
366
+ this.preemptSlots.set(slot, { key: entry.key, backlog: entry.backlog });
308
367
  try {
309
368
  await entry.run(this.createPreemptHandle(slot));
310
369
  } catch (err) {
311
370
  this.logExtractionQueueFailure(err, "task");
312
371
  } finally {
313
372
  this.preemptSlots.delete(slot);
373
+ if (entry.backlog === true) this.activeBacklog -= 1;
374
+ else this.activeForeground -= 1;
314
375
  if (entry.key !== undefined) this.activeKeys.delete(entry.key);
315
376
  }
316
377
  }
@@ -0,0 +1,185 @@
1
+ import assert from "node:assert/strict";
2
+ import test from "node:test";
3
+
4
+ import { ExtractionQueueCoordinator } from "./extraction-queue-coordinator.js";
5
+
6
+ const tick = () => new Promise<void>((resolve) => setImmediate(resolve));
7
+
8
+ /**
9
+ * Lane bias (backlog priority + foreground floor): claimed-backlog drain
10
+ * tasks fill every slot past the foreground floor whenever both lanes wait,
11
+ * while live foreground work can never be fully crowded out.
12
+ */
13
+
14
+ /** One blocked task per enqueue; `started` records which lane began. */
15
+ function harness(concurrency: number) {
16
+ const queue = new ExtractionQueueCoordinator(concurrency);
17
+ const started: string[] = [];
18
+ const resolvers = new Map<string, () => void>();
19
+ const enqueue = (lane: "fg" | "bg", tag: string) =>
20
+ queue.enqueue(async () => {
21
+ started.push(tag);
22
+ await new Promise<void>((resolve) => resolvers.set(tag, resolve));
23
+ }, { backlog: lane === "bg" });
24
+ const release = (tag: string) => {
25
+ resolvers.get(tag)?.();
26
+ resolvers.delete(tag);
27
+ };
28
+ const releaseAll = () => {
29
+ for (const tag of [...resolvers.keys()]) release(tag);
30
+ };
31
+ return { queue, started, enqueue, release, releaseAll };
32
+ }
33
+
34
+ test("backlog fills every slot past the one-slot foreground floor", async () => {
35
+ const h = harness(4);
36
+ // Interleave lanes on enqueue: selection order, not arrival order, decides.
37
+ h.enqueue("fg", "f1");
38
+ h.enqueue("bg", "b1");
39
+ h.enqueue("fg", "f2");
40
+ h.enqueue("bg", "b2");
41
+ h.enqueue("bg", "b3");
42
+ h.enqueue("bg", "b4");
43
+ h.enqueue("fg", "f3");
44
+ h.enqueue("bg", "b5");
45
+ await tick();
46
+ assert.deepEqual(h.started.sort(), ["b1", "b2", "b3", "f1"],
47
+ "3 backlog + 1 foreground: the floor holds under full backlog pressure");
48
+ // A settling backlog slot refills with backlog, not the waiting foreground.
49
+ h.releaseAll();
50
+ for (let i = 0; i < 20 && h.started.length < 8; i += 1) await tick();
51
+ assert.deepEqual(h.started.sort(), ["b1", "b2", "b3", "b4", "b5", "f1", "f2", "f3"],
52
+ "every queued task settles once released — the bias delays, never drops");
53
+ });
54
+
55
+ test("the foreground floor applies per slot at any concurrency", async () => {
56
+ const h = harness(2);
57
+ h.enqueue("bg", "b1");
58
+ h.enqueue("bg", "b2");
59
+ h.enqueue("bg", "b3");
60
+ h.enqueue("fg", "f1");
61
+ h.enqueue("fg", "f2");
62
+ await tick();
63
+ assert.deepEqual(h.started.sort(), ["b1", "f1"],
64
+ "concurrency 2: one slot to each lane while both wait");
65
+ });
66
+
67
+ test("backlog alone leaves the last slot free for a flush", async () => {
68
+ const h = harness(4);
69
+ h.enqueue("bg", "b1");
70
+ h.enqueue("bg", "b2");
71
+ h.enqueue("bg", "b3");
72
+ h.enqueue("bg", "b4");
73
+ await tick();
74
+ assert.deepEqual(h.started, ["b1", "b2", "b3"],
75
+ "one slot stays open so a fail-closed flush need not preempt");
76
+ // A foreground (flush-path) arrival takes the free slot, not a victim.
77
+ h.enqueue("fg", "f1");
78
+ await tick();
79
+ assert.deepEqual(h.started, ["b1", "b2", "b3", "f1"]);
80
+ // While any foreground runs, backlog may again fill every other slot.
81
+ h.enqueue("bg", "b5");
82
+ await tick();
83
+ assert.deepEqual(h.started, ["b1", "b2", "b3", "f1"],
84
+ "no free slot while all four are armed");
85
+ // Releasing the foreground task must NOT let queued backlog take the
86
+ // freed last slot — the reserve survives foreground completion.
87
+ h.release("f1");
88
+ await tick();
89
+ assert.deepEqual(h.started, ["b1", "b2", "b3", "f1"],
90
+ "the fourth slot stays open after foreground settles");
91
+ h.releaseAll();
92
+ });
93
+
94
+ test("force-flush preemption takes a foreground victim before a backlog one", async () => {
95
+ const queue = new ExtractionQueueCoordinator(2);
96
+ const aborted: string[] = [];
97
+ const enqueue = (lane: "fg" | "bg", tag: string) =>
98
+ queue.enqueue(async (preempt) => {
99
+ preempt?.arm(() => aborted.push(tag));
100
+ await new Promise<void>(() => {}); // never settles
101
+ }, { backlog: lane === "bg" });
102
+ enqueue("bg", "b1");
103
+ enqueue("fg", "f1");
104
+ await tick();
105
+ // Both slots armed: the flush has no same-key match and must pick a victim.
106
+ queue.preemptRunning("unrelated-key");
107
+ await tick();
108
+ assert.deepEqual(aborted, ["f1"],
109
+ "the foreground slot dies first — backlog chunk calls survive routine flushes");
110
+ });
111
+
112
+ test("a same-key armed backlog slot still loses to the flush", async () => {
113
+ const queue = new ExtractionQueueCoordinator(2);
114
+ const aborted: string[] = [];
115
+ queue.enqueue(async (preempt) => {
116
+ preempt?.arm(() => aborted.push("bg"));
117
+ await new Promise<void>(() => {});
118
+ }, { backlog: true, key: "k1" });
119
+ await tick();
120
+ queue.preemptRunning("k1");
121
+ await tick();
122
+ assert.deepEqual(aborted, ["bg"],
123
+ "same-key correctness beats the lane preference");
124
+ });
125
+
126
+ test("foreground keeps all slots when no backlog work is queued", async () => {
127
+ const h = harness(4);
128
+ h.enqueue("fg", "f1");
129
+ h.enqueue("fg", "f2");
130
+ h.enqueue("fg", "f3");
131
+ await tick();
132
+ assert.deepEqual(h.started, ["f1", "f2", "f3"],
133
+ "foreground-only traffic is unaffected by the lane tag");
134
+ h.releaseAll();
135
+ });
136
+
137
+ test("a front flush starts before queued backlog work", async () => {
138
+ const queue = new ExtractionQueueCoordinator(2);
139
+ const started: string[] = [];
140
+ const resolvers = new Map<string, () => void>();
141
+ const enqueue = (tag: string, options?: { backlog?: boolean; front?: boolean; key?: string }) =>
142
+ queue.enqueue(async () => {
143
+ started.push(tag);
144
+ await new Promise<void>((resolve) => resolvers.set(tag, resolve));
145
+ }, options);
146
+ const release = (tag: string) => resolvers.get(tag)?.();
147
+ enqueue("fg", { key: "fg" });
148
+ enqueue("hold", { key: "hold" });
149
+ await tick();
150
+ enqueue("bl", { backlog: true, key: "bl" });
151
+ enqueue("flush", { front: true, key: "flush" });
152
+ // Both slots are full until hold ends. Releasing it is what lets the
153
+ // front flush start; the queued backlog must not take that slot.
154
+ release("hold");
155
+ await tick();
156
+ assert.deepEqual(started, ["fg", "hold", "flush"],
157
+ "front flush must run before queued backlog: actual " + started.join(","));
158
+ for (const tag of [...resolvers.keys()]) release(tag);
159
+ });
160
+
161
+ test("a front flush starts before queued backlog work (CodeRabbit Major, pure-backlog)", async () => {
162
+ const queue = new ExtractionQueueCoordinator(2);
163
+ const started: string[] = [];
164
+ const resolvers = new Map<string, () => void>();
165
+ const enqueue = (tag: string, options?: { backlog?: boolean; front?: boolean; key?: string }) =>
166
+ queue.enqueue(async () => {
167
+ started.push(tag);
168
+ await new Promise<void>((resolve) => resolvers.set(tag, resolve));
169
+ }, options);
170
+ const release = (tag: string) => resolvers.get(tag)?.();
171
+ enqueue("bl", { backlog: true, key: "bl" });
172
+ enqueue("bl2", { backlog: true, key: "bl2" });
173
+ enqueue("bl3", { backlog: true, key: "bl3" });
174
+ await tick();
175
+ // The fail-closed flush lands at the head after the backlog is queued.
176
+ enqueue("flush", { front: true, key: "flush" });
177
+ await tick();
178
+ // The flush must start before queued backlog work even with the foreground
179
+ // floor open (the lane check previously denied the front flag).
180
+ assert.deepEqual(started, ["bl", "flush"],
181
+ "front flush starts ahead of queued backlog work");
182
+ release("bl");
183
+ release("bl2");
184
+ release("flush");
185
+ });
@@ -1013,7 +1013,13 @@ export class TurnIngestionCoordinator {
1013
1013
  if (sharingNode) this.snapshotSharing.release(sharingNode);
1014
1014
  exit.report();
1015
1015
  }
1016
- }, { front: options.preemptRunning === true, key: bufferKey });
1016
+ }, {
1017
+ front: options.preemptRunning === true,
1018
+ key: bufferKey,
1019
+ // Claim/drain tasks (options.execution carries the claim-backed buffer)
1020
+ // take the backlog lane: biased to fill all-but-foreground-floor slots.
1021
+ backlog: options.execution !== undefined,
1022
+ });
1017
1023
  if (!accepted) {
1018
1024
  if (sharingNode) this.snapshotSharing.release(sharingNode);
1019
1025
  settleTask(new Error("extraction queue is stopped"));