@remnic/core 10.0.98 → 10.0.99

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 (41) hide show
  1. package/dist/access-admin-ops-surface.js +1 -1
  2. package/dist/access-cli.js +1 -1
  3. package/dist/access-extraction-force-flush.js +1 -1
  4. package/dist/access-http-briefing.js +1 -1
  5. package/dist/access-http-query.js +1 -1
  6. package/dist/access-http.js +1 -1
  7. package/dist/access-identity-continuity-surface.js +1 -1
  8. package/dist/access-lcm-surface.js +1 -1
  9. package/dist/access-mcp.js +1 -1
  10. package/dist/access-observe-write-surface.js +1 -1
  11. package/dist/access-operations-batch.js +1 -1
  12. package/dist/access-operations.js +1 -1
  13. package/dist/access-recall-concurrency.js +1 -1
  14. package/dist/access-recall-response.js +1 -1
  15. package/dist/access-recall-surface.js +1 -1
  16. package/dist/access-service.js +1 -1
  17. package/dist/{chunk-TZKK72BY.js → chunk-UBJ5RPDM.js} +2 -2
  18. package/dist/{chunk-5DGK7E4W.js → chunk-VZMRKYNR.js} +26 -3
  19. package/dist/chunk-VZMRKYNR.js.map +1 -0
  20. package/dist/cli.js +1 -1
  21. package/dist/explicit-capture.js +1 -1
  22. package/dist/index.js +1 -1
  23. package/dist/orchestration/backlog-scheduler.d.ts +6 -1
  24. package/dist/orchestration/backlog-scheduler.d.ts.map +1 -1
  25. package/dist/orchestration/backlog-scheduler.js +20 -4
  26. package/dist/orchestration/backlog-scheduler.js.map +1 -1
  27. package/dist/orchestration/buffer-drain-runner.js +2 -2
  28. package/dist/orchestration/task-exit.d.ts +15 -0
  29. package/dist/orchestration/task-exit.d.ts.map +1 -0
  30. package/dist/orchestration/turn-ingestion.d.ts +1 -7
  31. package/dist/orchestration/turn-ingestion.d.ts.map +1 -1
  32. package/dist/orchestrator.js +1 -1
  33. package/dist/recall-navigation.js +1 -1
  34. package/package.json +2 -2
  35. package/src/backlog-scheduler.test.ts +48 -0
  36. package/src/orchestration/backlog-scheduler.ts +23 -2
  37. package/src/orchestration/extraction-queue-bounded-retention.test.ts +20 -0
  38. package/src/orchestration/task-exit.ts +27 -0
  39. package/src/orchestration/turn-ingestion.ts +7 -9
  40. package/dist/chunk-5DGK7E4W.js.map +0 -1
  41. /package/dist/{chunk-TZKK72BY.js.map → chunk-UBJ5RPDM.js.map} +0 -0
package/dist/cli.js CHANGED
@@ -91,7 +91,7 @@ import {
91
91
  runWorkProductStatusCliCommand,
92
92
  runWorkProjectCliCommand,
93
93
  runWorkTaskCliCommand
94
- } from "./chunk-5DGK7E4W.js";
94
+ } from "./chunk-VZMRKYNR.js";
95
95
  import "./chunk-6P7U3HWG.js";
96
96
  import "./chunk-PQM3B54K.js";
97
97
  import "./chunk-B3DR2JBZ.js";
@@ -8,7 +8,7 @@ import {
8
8
  shouldSkipImplicitExtraction,
9
9
  stripInlineExplicitCaptureNotes,
10
10
  validateExplicitCaptureInput
11
- } from "./chunk-5DGK7E4W.js";
11
+ } from "./chunk-VZMRKYNR.js";
12
12
  import "./chunk-6P7U3HWG.js";
13
13
  import "./chunk-PQM3B54K.js";
14
14
  import "./chunk-B3DR2JBZ.js";
package/dist/index.js CHANGED
@@ -259,7 +259,7 @@ import {
259
259
  writeManifest,
260
260
  writeMeetingEpisodeMemory,
261
261
  writeTimelineState
262
- } from "./chunk-5DGK7E4W.js";
262
+ } from "./chunk-VZMRKYNR.js";
263
263
  import "./chunk-6P7U3HWG.js";
264
264
  import "./chunk-PQM3B54K.js";
265
265
  import {
@@ -68,6 +68,8 @@ export interface BacklogSchedulerOptions {
68
68
  pollMs?: number;
69
69
  retryBaseMs?: number;
70
70
  retryMaxMs?: number;
71
+ /** Bound on `stop()`'s wait for aborted drains to settle. */
72
+ stopSettleTimeoutMs?: number;
71
73
  now?: () => number;
72
74
  }
73
75
  export interface BacklogSchedulerCounters {
@@ -113,7 +115,10 @@ export declare class BacklogScheduler {
113
115
  /** Idempotent. Starts the poll timer (unref'd) and runs an initial tick. */
114
116
  start(): void;
115
117
  /** Idempotent. Stops the timer, aborts in-flight drains (their claims stay
116
- * retryable) and waits for them to settle. */
118
+ * retryable) and waits up to `stopSettleTimeoutMs` for them to settle. A
119
+ * drain that ignores abort is named in a warning and left behind: the
120
+ * caller's later shutdown phases (orchestrator flush and dispose) must
121
+ * still run before the service manager's kill. */
117
122
  stop(): Promise<void>;
118
123
  /** Bounded snapshot for ops/watchers: counters + per-key states + live sets. */
119
124
  snapshot(): BacklogSchedulerSnapshot;
@@ -1 +1 @@
1
- {"version":3,"file":"backlog-scheduler.d.ts","sourceRoot":"","sources":["../../src/orchestration/backlog-scheduler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAKH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,KAAK,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAC;AAEvF,OAAO,KAAK,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AACtF,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,mCAAmC,CAAC;AACpF,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAErE;+EAC+E;AAC/E,MAAM,WAAW,oBAAoB;IACnC,KAAK,EAAE,IAAI,CAAC,0BAA0B,EAAE,eAAe,GAAG,uBAAuB,GAAG,gBAAgB,CAAC,CAAC;IACtG,MAAM,EAAE,IAAI,CAAC,iBAAiB,EAAE,MAAM,GAAG,UAAU,GAAG,sBAAsB,GAAG,WAAW,CAAC,CAAC;IAC5F;8EAC0E;IAC1E,gBAAgB,IACZ,GAAG,CAAC,MAAM,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,aAAa,EAAE,MAAM,CAAA;KAAE,CAAC,GACrD,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,aAAa,EAAE,MAAM,CAAA;KA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iBAAiB;IAOzB;sEACkE;YACpD,MAAM;IA4BpB,sEAAsE;YACxD,cAAc;IAe5B;;oBAEgB;YACF,eAAe;IAkB7B,OAAO,CAAC,YAAY;IAwBpB,yDAAyD;IACzD,OAAO,CAAC,wBAAwB;IAchC;8EAC0E;IAC1E,OAAO,CAAC,YAAY;IAepB,OAAO,CAAC,mBAAmB;IAI3B,OAAO,CAAC,SAAS;IAMjB,OAAO,CAAC,UAAU;CAUnB;AAKD;qEACqE;AACrE,wBAAgB,oBAAoB,CAClC,YAAY,EAAE,YAAY,EAC1B,OAAO,GAAE,uBAA4B,GACpC,gBAAgB,CA8BlB"}
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  BufferDrainRunner
3
- } from "../chunk-TZKK72BY.js";
4
- import "../chunk-5DGK7E4W.js";
3
+ } from "../chunk-UBJ5RPDM.js";
4
+ import "../chunk-VZMRKYNR.js";
5
5
  import "../chunk-6P7U3HWG.js";
6
6
  import "../chunk-PQM3B54K.js";
7
7
  import "../chunk-B3DR2JBZ.js";
@@ -571,6 +571,7 @@ import { hostname } from "os";
571
571
  var DEFAULT_POLL_MS = 15e3;
572
572
  var DEFAULT_RETRY_BASE_MS = 3e4;
573
573
  var DEFAULT_RETRY_MAX_MS = 15 * 6e4;
574
+ var DEFAULT_STOP_SETTLE_TIMEOUT_MS = 3e4;
574
575
  var BacklogScheduler = class {
575
576
  deps;
576
577
  options;
@@ -596,6 +597,7 @@ var BacklogScheduler = class {
596
597
  pollMs: options.pollMs ?? DEFAULT_POLL_MS,
597
598
  retryBaseMs: options.retryBaseMs ?? DEFAULT_RETRY_BASE_MS,
598
599
  retryMaxMs: options.retryMaxMs ?? DEFAULT_RETRY_MAX_MS,
600
+ stopSettleTimeoutMs: options.stopSettleTimeoutMs ?? DEFAULT_STOP_SETTLE_TIMEOUT_MS,
599
601
  now: options.now
600
602
  };
601
603
  }
@@ -608,7 +610,10 @@ var BacklogScheduler = class {
608
610
  void this.tick();
609
611
  }
610
612
  /** Idempotent. Stops the timer, aborts in-flight drains (their claims stay
611
- * retryable) and waits for them to settle. */
613
+ * retryable) and waits up to `stopSettleTimeoutMs` for them to settle. A
614
+ * drain that ignores abort is named in a warning and left behind: the
615
+ * caller's later shutdown phases (orchestrator flush and dispose) must
616
+ * still run before the service manager's kill. */
612
617
  async stop() {
613
618
  if (this.stopped) return;
614
619
  this.stopped = true;
@@ -621,7 +626,18 @@ var BacklogScheduler = class {
621
626
  entry.controller.abort(new Error("backlog scheduler stopping"));
622
627
  aborts.push(entry.settled);
623
628
  }
624
- await Promise.allSettled(aborts);
629
+ const bound = Promise.withResolvers();
630
+ const boundTimer = setTimeout(() => bound.resolve("timeout"), this.options.stopSettleTimeoutMs);
631
+ try {
632
+ const result = await Promise.race([Promise.allSettled(aborts), bound.promise]);
633
+ if (result === "timeout") {
634
+ log.warn(
635
+ `backlog scheduler stop: ${this.inFlight.size} drain(s) ignored abort for ${this.options.stopSettleTimeoutMs}ms; continuing shutdown (stuck keys: ${[...this.inFlight.keys()].join(", ")})`
636
+ );
637
+ }
638
+ } finally {
639
+ clearTimeout(boundTimer);
640
+ }
625
641
  }
626
642
  /** Bounded snapshot for ops/watchers: counters + per-key states + live sets. */
627
643
  snapshot() {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/orchestration/backlog-scheduler.ts"],"sourcesContent":["/**\n * Daemon-owned extraction backlog scheduler.\n *\n * ONE bounded in-process loop that owns ALL persisted extraction backlog:\n * at startup (existing drain claims + buffered sessions), on every poll tick\n * (new persisted work), and by retrying keys that are still pending — with\n * bounded memory (per-key COUNTS only; candidate scans never retain turn\n * payloads) and bounded outstanding work (the extraction queue's own\n * maxConcurrency gates submissions, so live foreground work keeps its share\n * of the queue).\n *\n * Claim authority: an existing claim — including an EMPTY ack tombstone — is\n * authoritative over the live buffer's in-memory copy. A tombstoned key is\n * never re-claimed or counted as work; new ingress consumes the tombstone\n * through the native save handover, which is what makes the key a candidate\n * again. Claim creation is fenced: the key is reserved synchronously on the\n * extraction queue BEFORE the async claim decision, so a queued live task for\n * the same key cannot start past the claimed-session gate until the decision\n * settles; live capture continues via the native merge-into-claim protocol.\n *\n * Failed, deferred, or policy-denied outcomes keep their turns durable in the\n * claim and re-submit after backoff (exponential from `retryBaseMs` to\n * `retryMaxMs`, reset by progress; denials wait the full max) — never a busy\n * retry. `stop()` aborts in-flight drains at their chunk boundary and leaves\n * every claim retryable; a restarted daemon's scheduler adopts them.\n */\n\nimport { randomUUID } from \"node:crypto\";\nimport { hostname } from \"node:os\";\nimport { log } from \"../logger.js\";\nimport type { Orchestrator } from \"../orchestrator.js\";\nimport type { BufferDrainClaims, DrainLease } from \"../storage/buffer-drain-claims.js\";\nimport { BufferDrainRunner } from \"./buffer-drain-runner.js\";\nimport type { DrainRunnerEvent, DrainSessionOutcome } from \"./buffer-drain-runner.js\";\nimport type { ExtractionQueueCoordinator } from \"./extraction-queue-coordinator.js\";\nimport type { ProviderBreakerSnapshot } from \"./provider-breaker.js\";\n\n/** What the scheduler needs from its host (structurally satisfied by the\n * orchestrator wiring); injectable so tests drive ticks deterministically. */\nexport interface BacklogSchedulerDeps {\n queue: Pick<ExtractionQueueCoordinator, \"tryReserveKey\" | \"releaseKeyReservation\" | \"maxConcurrency\">;\n claims: Pick<BufferDrainClaims, \"list\" | \"listPage\" | \"claimFromSessionFile\" | \"isClaimed\">;\n /** Live per-key pending counts (counts only — never turn payloads). May be\n * async: hosts with a lazily-loaded buffer load it here (idempotent). */\n liveBufferCounts():\n | Map<string, { turns: number; retainedTurns: number }>\n | Promise<Map<string, { turns: number; retainedTurns: number }>>;\n /** Create a fresh lease for a unique owner token. */\n lease(ownerId: string): DrainLease;\n /** Drain one key to quiescence (BufferDrainRunner.drainSession). */\n drainKey(\n key: string,\n options: { ownerId: string; signal: AbortSignal; onEvent?: (event: DrainRunnerEvent) => void }\n ): Promise<DrainSessionOutcome>;\n /** Shared provider circuit-breaker snapshot (the same instance the run\n * coordinator gates attempts on). While OPEN inside its cooldown window\n * the scheduler skips submission entirely — claims stay durable, and the\n * breaker's single half-open probe (one attempt through once the window\n * lapses) keeps recovery automatic. Optional: hosts without a breaker\n * never skip. */\n breakerSnapshot?(): ProviderBreakerSnapshot;\n /** Test seam: monotonic-ish clock for backoff windows. */\n now?(): number;\n}\n\nexport interface BacklogSchedulerOptions {\n /** Optional label prefix; each scheduler instance adds a unique token. */\n ownerId?: string;\n /** Scan cadence in ms (startup + new-work + retry checks). */\n pollMs?: number;\n retryBaseMs?: number;\n retryMaxMs?: number;\n now?: () => number;\n}\n\nexport interface BacklogSchedulerCounters {\n /** Keys submitted to the drain (claimed or adopted) this process lifetime. */\n claimed: number;\n /** Outcomes with genuinely empty claims (durable outputs preceded ack). */\n processed: number;\n /** Sum of durable outputs (memories + entities) across processed drains. */\n durableOutputs: number;\n /** Re-submissions after a failed/deferred/denied outcome. */\n retried: number;\n denied: { keys: number; turns: number };\n failed: number;\n}\n\nexport type BacklogKeyState = \"inflight\" | \"backoff\" | \"denied\";\n\nexport interface BacklogKeySnapshot {\n key: string;\n state: BacklogKeyState;\n turnsRemaining?: number;\n reason?: string;\n}\n\nexport interface BacklogSchedulerSnapshot {\n counters: BacklogSchedulerCounters;\n inFlight: string[];\n reservedKeys: string[];\n keys: BacklogKeySnapshot[];\n}\n\ninterface KeyState {\n state: BacklogKeyState;\n nextAttemptMs: number;\n /** Last observed remaining turns; progress resets the backoff exponent. */\n turnsRemaining: number;\n reason?: string;\n backoffExponent: number;\n}\n\nconst DEFAULT_POLL_MS = 15_000;\nconst DEFAULT_RETRY_BASE_MS = 30_000;\nconst DEFAULT_RETRY_MAX_MS = 15 * 60_000;\n\nexport class BacklogScheduler {\n private readonly deps: BacklogSchedulerDeps;\n private readonly options: Required<Omit<BacklogSchedulerOptions, \"now\">> & Pick<BacklogSchedulerOptions, \"now\">;\n private readonly keys = new Map<string, KeyState>();\n private readonly inFlight = new Map<string, { controller: AbortController; settled: Promise<void> }>();\n private readonly reserved = new Set<string>();\n private readonly counters: BacklogSchedulerCounters = {\n claimed: 0,\n processed: 0,\n durableOutputs: 0,\n retried: 0,\n denied: { keys: 0, turns: 0 },\n failed: 0,\n };\n private claimCursor: string | undefined;\n private timer: ReturnType<typeof setInterval> | undefined;\n private ticking = false;\n private stopped = true;\n\n constructor(deps: BacklogSchedulerDeps, options: BacklogSchedulerOptions = {}) {\n this.deps = deps;\n this.options = {\n ownerId: `${options.ownerId ?? \"daemon-drain\"}-${randomUUID()}`,\n pollMs: options.pollMs ?? DEFAULT_POLL_MS,\n retryBaseMs: options.retryBaseMs ?? DEFAULT_RETRY_BASE_MS,\n retryMaxMs: options.retryMaxMs ?? DEFAULT_RETRY_MAX_MS,\n now: options.now,\n };\n }\n\n /** Idempotent. Starts the poll timer (unref'd) and runs an initial tick. */\n start(): void {\n if (!this.stopped) return;\n this.stopped = false;\n this.timer = setInterval(() => void this.tick(), this.options.pollMs);\n this.timer.unref?.();\n void this.tick();\n }\n\n /** Idempotent. Stops the timer, aborts in-flight drains (their claims stay\n * retryable) and waits for them to settle. */\n async stop(): Promise<void> {\n if (this.stopped) return;\n this.stopped = true;\n if (this.timer) {\n clearInterval(this.timer);\n this.timer = undefined;\n }\n const aborts: Promise<void>[] = [];\n for (const entry of this.inFlight.values()) {\n entry.controller.abort(new Error(\"backlog scheduler stopping\"));\n aborts.push(entry.settled);\n }\n await Promise.allSettled(aborts);\n }\n\n /** Bounded snapshot for ops/watchers: counters + per-key states + live sets. */\n snapshot(): BacklogSchedulerSnapshot {\n return {\n counters: {\n claimed: this.counters.claimed,\n processed: this.counters.processed,\n durableOutputs: this.counters.durableOutputs,\n retried: this.counters.retried,\n denied: { ...this.counters.denied },\n failed: this.counters.failed,\n },\n inFlight: [...this.inFlight.keys()],\n reservedKeys: [...this.reserved],\n keys: [...this.keys.entries()].map(([key, state]) => ({\n key,\n state: state.state,\n turnsRemaining: state.turnsRemaining,\n reason: state.reason,\n })),\n };\n }\n\n /** One scan+submit pass (tests drive this instead of the timer). Waits out\n * any in-progress tick first so the pass always actually scans. */\n async tickForTest(): Promise<void> {\n // setImmediate: yields to the event loop so pending I/O (a slow first\n // scan) can finish; a microtask spin would starve it.\n while (this.ticking) await new Promise((resolve) => setImmediate(resolve));\n await this.tick();\n }\n\n /** Await the settle (slot release) of everything currently in flight,\n * optionally excluding one still-gated key (tests). */\n async settleForTest(exclude?: string): Promise<void> {\n for (;;) {\n const pending = [...this.inFlight.entries()].filter(([key]) => key !== exclude).map(([, entry]) => entry.settled);\n if (pending.length === 0) return;\n await Promise.allSettled(pending);\n }\n }\n\n private now(): number {\n return this.options.now?.() ?? Date.now();\n }\n\n private async tick(): Promise<void> {\n if (this.ticking || this.stopped) return;\n this.ticking = true;\n const cursorBeforeTick = this.claimCursor;\n try {\n // Fast bail: a breaker already open must not pay discovery I/O\n // (listPage reads and parses claim bodies on every poll). The\n // submitCandidates guard below still catches a breaker that opens\n // while discovery awaits.\n const breakerBeforeDiscovery = this.deps.breakerSnapshot?.();\n if (\n breakerBeforeDiscovery &&\n breakerBeforeDiscovery.state === \"open\" &&\n this.now() < breakerBeforeDiscovery.openUntilMs\n ) {\n return;\n }\n // stop() may land while discovery's I/O is pending: re-check before\n // submitting anything, and again per candidate.\n // A discovery failure (EACCES/EIO on the claims dir) must not reject\n // into a detached timer callback: it would be an unhandled rejection\n // that terminates the server. Log, skip this pass, retry next poll.\n let candidates: { key: string; needsClaim: boolean }[];\n try {\n candidates = await this.discoverCandidates();\n } catch (err) {\n // Discovery may have listed a page before it failed: the page cursor\n // already moved, so restore it — otherwise those claims wait for the\n // cursor to wrap instead of the next poll.\n this.claimCursor = cursorBeforeTick;\n log.warn(\n `backlog drain: discovery failed; retrying next poll: ${err instanceof Error ? err.message : String(err)}`\n );\n return;\n }\n if (this.stopped) return;\n const dropped = this.submitCandidates(candidates);\n // The concurrency bound stopped submission mid-page: rewind the page\n // cursor so the unsubmitted claims are re-listed on the next tick\n // (already-submitted ones are gated by inFlight and key backoff).\n if (dropped) this.claimCursor = cursorBeforeTick;\n } finally {\n this.ticking = false;\n }\n }\n\n /** Bounded discovery: ONE page of existing claims with pending turns */\n private async discoverCandidates(): Promise<{ key: string; needsClaim: boolean }[]> {\n const out: { key: string; needsClaim: boolean }[] = [];\n const seen = new Set<string>();\n const pageLimit = Math.max(this.submissionLimit() * 4, 16);\n const page = await this.deps.claims.listPage(this.claimCursor, pageLimit);\n for (const listed of page.entries) {\n seen.add(listed.key);\n out.push({ key: listed.key, needsClaim: false });\n }\n this.claimCursor = page.nextCursor;\n for (const [key, counts] of await this.deps.liveBufferCounts()) {\n if (counts.turns + counts.retainedTurns <= 0) continue;\n if (seen.has(key) || this.deps.claims.isClaimed(key)) continue;\n seen.add(key);\n out.push({ key, needsClaim: true });\n }\n return out;\n }\n\n /** Submission bound: the queue's own concurrency limit, read with the\n * documented \"0 disables\" contract — a zero limit submits nothing. */\n private submissionLimit(): number {\n if (this.deps.queue.maxConcurrency <= 0) return 0;\n return this.deps.queue.maxConcurrency;\n }\n\n /** Submit discovery candidates within the queue's concurrency bound. */\n private submitCandidates(candidates: { key: string; needsClaim: boolean }[]): boolean {\n // Breaker-open churn guard: a full attempt reads the claim, rebuilds the\n // buffer/coordinator and re-renders chunks before the breaker fails it\n // fast — pure heap pressure per poll during a provider stall. Skip while\n // the window is open; once it lapses, submissions resume and the\n // breaker's half-open probe runs as usual.\n const breaker = this.deps.breakerSnapshot?.();\n if (breaker && breaker.state === \"open\" && this.now() < breaker.openUntilMs) {\n return true;\n }\n let dropped = false;\n for (const candidate of candidates) {\n if (this.stopped || this.inFlight.size >= this.submissionLimit()) {\n dropped = true;\n break;\n }\n if (!this.candidateEligible(candidate)) continue;\n // Fence the claim decision: reserve the key synchronously BEFORE the\n // async rename so no queued task for it can pass the claimed gate in\n // the meantime. Release happens when the decision settles.\n if (candidate.needsClaim) {\n if (!this.deps.queue.tryReserveKey(candidate.key)) continue;\n this.reserved.add(candidate.key);\n }\n void this.submit(candidate.key, candidate.needsClaim);\n }\n return dropped;\n }\n\n /** inFlight is the authority for \"already submitted\" — key state only\n * exists once an outcome landed (backoff/denied gating below). */\n private candidateEligible(candidate: { key: string; needsClaim: boolean }): boolean {\n if (this.stopped || this.inFlight.size >= this.submissionLimit()) return false;\n if (this.inFlight.has(candidate.key)) return false;\n const state = this.keys.get(candidate.key);\n return !(state && this.now() < state.nextAttemptMs);\n }\n\n /** Claim (when needed), then drain one key; the reservation spans the async\n * claim decision, the queue entry carries the key afterwards. */\n private async submit(key: string, needsClaim: boolean): Promise<void> {\n const controller = new AbortController();\n const { promise: settled, resolve: settle } = Promise.withResolvers<void>();\n this.inFlight.set(key, { controller, settled });\n try {\n if (!(await this.claimForSubmit(key, needsClaim, this.options.ownerId))) return;\n // Stopped between the claim decision and the task: leave the claim\n // with its lease (it expires; the next start adopts) — never drain.\n if (this.stopped) return;\n await this.drainClaimedKey(key, controller.signal, this.options.ownerId);\n } catch (err) {\n // Claim/drain failures are scheduler-level: the claim content is\n // untouched — count failed and back off (never an unhandled rejection\n // in the detached submission).\n this.counters.failed += 1;\n const message = err instanceof Error ? err.message : String(err);\n // SAFETY: a thrown non-Error (incl. null) carries no retry hint; the\n // optional chain reads the hint off Error throws only.\n this.setBackoff(key, (err as { turnsRemaining?: number } | null | undefined)?.turnsRemaining ?? 0, message);\n log.warn(`backlog drain: ${key} submission failed: ${message}`);\n } finally {\n this.inFlight.delete(key);\n this.reserved.delete(key);\n this.deps.queue.releaseKeyReservation(key);\n settle();\n }\n }\n\n /** after all — the key goes quiet without a task. \"claimed\": ours. */\n private async claimForSubmit(key: string, needsClaim: boolean, ownerId: string): Promise<boolean> {\n if (!needsClaim) return true;\n try {\n const outcome = await this.deps.claims.claimFromSessionFile(key, this.deps.lease(ownerId));\n if (outcome === \"empty\") {\n this.keys.delete(key);\n return false;\n }\n return true;\n } finally {\n this.reserved.delete(key);\n this.deps.queue.releaseKeyReservation(key);\n }\n }\n\n /** Drain one claimed key. drainKey reports failures as outcomes; a thrown\n * error still means the claim content is intact — count it failed and\n * back off. */\n private async drainClaimedKey(key: string, signal: AbortSignal, ownerId: string): Promise<void> {\n this.counters.claimed += 1;\n try {\n const outcome = await this.deps.drainKey(key, {\n ownerId,\n signal,\n });\n this.applyOutcome(key, outcome);\n } catch (err) {\n this.counters.failed += 1;\n const message = err instanceof Error ? err.message : String(err);\n // SAFETY: a thrown non-Error (incl. null) carries no retry hint; the\n // optional chain reads the hint off Error throws only.\n this.setBackoff(key, (err as { turnsRemaining?: number } | null | undefined)?.turnsRemaining ?? 0, message);\n log.warn(`backlog drain: ${key} threw: ${message}`);\n }\n }\n\n private applyOutcome(key: string, outcome: DrainSessionOutcome): void {\n const deniedTurns = outcome.denied?.reduce((sum, entry) => sum + entry.turns, 0) ?? 0;\n const previous = this.keys.get(key);\n const progressed = outcome.turnsRemaining < (previous?.turnsRemaining ?? Number.POSITIVE_INFINITY);\n if (outcome.status === \"drained\") {\n // The claim is now an empty tombstone: authoritative, nothing pending.\n // New ingress consumes it via the native save path and re-candidates.\n this.keys.delete(key);\n this.counters.processed += 1;\n this.counters.durableOutputs += outcome.durableOutputCount;\n log.info(\n `backlog drain: ${key} drained (${outcome.turnsAtStart} turn(s), ${outcome.durableOutputCount} durable output(s))`\n );\n return;\n }\n this.recordNonDrainedCounters(previous, outcome, deniedTurns);\n const denied = deniedTurns > 0 && outcome.turnsRemaining > 0;\n this.keys.set(key, this.nextKeyState(previous, outcome, denied, progressed));\n log.info(\n `backlog drain: ${key} ${outcome.status} (${outcome.turnsRemaining} turn(s) remaining` +\n `${denied ? `, denied: ${deniedTurns}` : \"\"}${outcome.reason ? `, ${outcome.reason}` : \"\"})`\n );\n }\n\n /** Denied backlog counters for a non-drained outcome. */\n private recordNonDrainedCounters(\n previous: KeyState | undefined,\n outcome: DrainSessionOutcome,\n deniedTurns: number\n ): void {\n if (deniedTurns > 0) {\n this.counters.denied.keys += 1;\n this.counters.denied.turns += deniedTurns;\n }\n if (outcome.status === \"failed\") this.counters.failed += 1;\n else if (previous !== undefined && (previous.state === \"backoff\" || previous.state === \"denied\"))\n this.counters.retried += 1;\n }\n\n /** The post-drain key state: denial waits the full max window (its content\n * is valid but currently unauthorized); progress resets the exponent. */\n private nextKeyState(\n previous: KeyState | undefined,\n outcome: DrainSessionOutcome,\n denied: boolean,\n progressed: boolean\n ): KeyState {\n return {\n state: denied ? \"denied\" : \"backoff\",\n nextAttemptMs: this.now() + this.backoffMs(previous, progressed && !denied),\n turnsRemaining: outcome.turnsRemaining,\n reason: outcome.reason,\n backoffExponent: this.nextBackoffExponent(denied, progressed, previous),\n };\n }\n\n private nextBackoffExponent(denied: boolean, progressed: boolean, previous: KeyState | undefined): number {\n return denied || !progressed ? (previous?.backoffExponent ?? 0) + 1 : 0;\n }\n\n private backoffMs(previous: KeyState | undefined, progressed: boolean): number {\n if (previous?.state === \"denied\") return this.options.retryMaxMs;\n const exponent = progressed ? 0 : (previous?.backoffExponent ?? 0) + 1;\n return Math.min(this.options.retryBaseMs * 2 ** exponent, this.options.retryMaxMs);\n }\n\n private setBackoff(key: string, turnsRemaining: number, reason: string): void {\n const previous = this.keys.get(key);\n this.keys.set(key, {\n state: \"backoff\",\n nextAttemptMs: this.now() + this.backoffMs(previous, false),\n turnsRemaining,\n reason,\n backoffExponent: (previous?.backoffExponent ?? 0) + 1,\n });\n }\n}\n\n/** Lease lifetime for claims the scheduler takes (matches the runner default). */\nconst SCHEDULER_LEASE_MS = 120_000;\n\n/** Wire the scheduler to an orchestrator's own queue, claim store, live buffer\n * counts and drain runner — the daemon's single ownership point. */\nexport function wireBacklogScheduler(\n orchestrator: Orchestrator,\n options: BacklogSchedulerOptions = {}\n): BacklogScheduler {\n const runner = new BufferDrainRunner(orchestrator);\n return new BacklogScheduler(\n {\n queue: orchestrator.extractionQueueCoordinator,\n claims: orchestrator.storage.bufferDrainClaims(),\n liveBufferCounts: async () => {\n // The daemon's buffer may be lazy: ensure the persisted state is in\n // memory before counting (load is guarded/idempotent).\n await orchestrator.buffer.load();\n return orchestrator.buffer.entryCounts();\n },\n lease: (ownerId) => {\n const now = new Date().toISOString();\n return {\n ownerId,\n pid: process.pid,\n host: hostname(),\n acquiredAt: now,\n heartbeatAt: now,\n leaseMs: SCHEDULER_LEASE_MS,\n };\n },\n drainKey: (key, drainOptions) => runner.drainSession(key, drainOptions),\n // The orchestrator's one shared provider breaker (foreground and every\n // claim-backed drain accumulate toward the same threshold).\n breakerSnapshot: () => orchestrator.getExtractionResilienceStatus().breaker,\n },\n options\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,SAAS,kBAAkB;AAC3B,SAAS,gBAAgB;AAqFzB,IAAM,kBAAkB;AACxB,IAAM,wBAAwB;AAC9B,IAAM,uBAAuB,KAAK;AAE3B,IAAM,mBAAN,MAAuB;AAAA,EACX;AAAA,EACA;AAAA,EACA,OAAO,oBAAI,IAAsB;AAAA,EACjC,WAAW,oBAAI,IAAqE;AAAA,EACpF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BAA8B,EAAE;AAAA,IACtE;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../../src/orchestration/backlog-scheduler.ts"],"sourcesContent":["/**\n * Daemon-owned extraction backlog scheduler.\n *\n * ONE bounded in-process loop that owns ALL persisted extraction backlog:\n * at startup (existing drain claims + buffered sessions), on every poll tick\n * (new persisted work), and by retrying keys that are still pending — with\n * bounded memory (per-key COUNTS only; candidate scans never retain turn\n * payloads) and bounded outstanding work (the extraction queue's own\n * maxConcurrency gates submissions, so live foreground work keeps its share\n * of the queue).\n *\n * Claim authority: an existing claim — including an EMPTY ack tombstone — is\n * authoritative over the live buffer's in-memory copy. A tombstoned key is\n * never re-claimed or counted as work; new ingress consumes the tombstone\n * through the native save handover, which is what makes the key a candidate\n * again. Claim creation is fenced: the key is reserved synchronously on the\n * extraction queue BEFORE the async claim decision, so a queued live task for\n * the same key cannot start past the claimed-session gate until the decision\n * settles; live capture continues via the native merge-into-claim protocol.\n *\n * Failed, deferred, or policy-denied outcomes keep their turns durable in the\n * claim and re-submit after backoff (exponential from `retryBaseMs` to\n * `retryMaxMs`, reset by progress; denials wait the full max) — never a busy\n * retry. `stop()` aborts in-flight drains at their chunk boundary and leaves\n * every claim retryable; a restarted daemon's scheduler adopts them.\n */\n\nimport { randomUUID } from \"node:crypto\";\nimport { hostname } from \"node:os\";\nimport { log } from \"../logger.js\";\nimport type { Orchestrator } from \"../orchestrator.js\";\nimport type { BufferDrainClaims, DrainLease } from \"../storage/buffer-drain-claims.js\";\nimport { BufferDrainRunner } from \"./buffer-drain-runner.js\";\nimport type { DrainRunnerEvent, DrainSessionOutcome } from \"./buffer-drain-runner.js\";\nimport type { ExtractionQueueCoordinator } from \"./extraction-queue-coordinator.js\";\nimport type { ProviderBreakerSnapshot } from \"./provider-breaker.js\";\n\n/** What the scheduler needs from its host (structurally satisfied by the\n * orchestrator wiring); injectable so tests drive ticks deterministically. */\nexport interface BacklogSchedulerDeps {\n queue: Pick<ExtractionQueueCoordinator, \"tryReserveKey\" | \"releaseKeyReservation\" | \"maxConcurrency\">;\n claims: Pick<BufferDrainClaims, \"list\" | \"listPage\" | \"claimFromSessionFile\" | \"isClaimed\">;\n /** Live per-key pending counts (counts only — never turn payloads). May be\n * async: hosts with a lazily-loaded buffer load it here (idempotent). */\n liveBufferCounts():\n | Map<string, { turns: number; retainedTurns: number }>\n | Promise<Map<string, { turns: number; retainedTurns: number }>>;\n /** Create a fresh lease for a unique owner token. */\n lease(ownerId: string): DrainLease;\n /** Drain one key to quiescence (BufferDrainRunner.drainSession). */\n drainKey(\n key: string,\n options: { ownerId: string; signal: AbortSignal; onEvent?: (event: DrainRunnerEvent) => void }\n ): Promise<DrainSessionOutcome>;\n /** Shared provider circuit-breaker snapshot (the same instance the run\n * coordinator gates attempts on). While OPEN inside its cooldown window\n * the scheduler skips submission entirely — claims stay durable, and the\n * breaker's single half-open probe (one attempt through once the window\n * lapses) keeps recovery automatic. Optional: hosts without a breaker\n * never skip. */\n breakerSnapshot?(): ProviderBreakerSnapshot;\n /** Test seam: monotonic-ish clock for backoff windows. */\n now?(): number;\n}\n\nexport interface BacklogSchedulerOptions {\n /** Optional label prefix; each scheduler instance adds a unique token. */\n ownerId?: string;\n /** Scan cadence in ms (startup + new-work + retry checks). */\n pollMs?: number;\n retryBaseMs?: number;\n retryMaxMs?: number;\n /** Bound on `stop()`'s wait for aborted drains to settle. */\n stopSettleTimeoutMs?: number;\n now?: () => number;\n}\n\nexport interface BacklogSchedulerCounters {\n /** Keys submitted to the drain (claimed or adopted) this process lifetime. */\n claimed: number;\n /** Outcomes with genuinely empty claims (durable outputs preceded ack). */\n processed: number;\n /** Sum of durable outputs (memories + entities) across processed drains. */\n durableOutputs: number;\n /** Re-submissions after a failed/deferred/denied outcome. */\n retried: number;\n denied: { keys: number; turns: number };\n failed: number;\n}\n\nexport type BacklogKeyState = \"inflight\" | \"backoff\" | \"denied\";\n\nexport interface BacklogKeySnapshot {\n key: string;\n state: BacklogKeyState;\n turnsRemaining?: number;\n reason?: string;\n}\n\nexport interface BacklogSchedulerSnapshot {\n counters: BacklogSchedulerCounters;\n inFlight: string[];\n reservedKeys: string[];\n keys: BacklogKeySnapshot[];\n}\n\ninterface KeyState {\n state: BacklogKeyState;\n nextAttemptMs: number;\n /** Last observed remaining turns; progress resets the backoff exponent. */\n turnsRemaining: number;\n reason?: string;\n backoffExponent: number;\n}\n\nconst DEFAULT_POLL_MS = 15_000;\nconst DEFAULT_RETRY_BASE_MS = 30_000;\nconst DEFAULT_RETRY_MAX_MS = 15 * 60_000;\n// Aborted drains normally settle within seconds (a chunk boundary); this only\n// bounds the pathological case, well inside the daemon's stop budget.\nconst DEFAULT_STOP_SETTLE_TIMEOUT_MS = 30_000;\n\nexport class BacklogScheduler {\n private readonly deps: BacklogSchedulerDeps;\n private readonly options: Required<Omit<BacklogSchedulerOptions, \"now\">> & Pick<BacklogSchedulerOptions, \"now\">;\n private readonly keys = new Map<string, KeyState>();\n private readonly inFlight = new Map<string, { controller: AbortController; settled: Promise<void> }>();\n private readonly reserved = new Set<string>();\n private readonly counters: BacklogSchedulerCounters = {\n claimed: 0,\n processed: 0,\n durableOutputs: 0,\n retried: 0,\n denied: { keys: 0, turns: 0 },\n failed: 0,\n };\n private claimCursor: string | undefined;\n private timer: ReturnType<typeof setInterval> | undefined;\n private ticking = false;\n private stopped = true;\n\n constructor(deps: BacklogSchedulerDeps, options: BacklogSchedulerOptions = {}) {\n this.deps = deps;\n this.options = {\n ownerId: `${options.ownerId ?? \"daemon-drain\"}-${randomUUID()}`,\n pollMs: options.pollMs ?? DEFAULT_POLL_MS,\n retryBaseMs: options.retryBaseMs ?? DEFAULT_RETRY_BASE_MS,\n retryMaxMs: options.retryMaxMs ?? DEFAULT_RETRY_MAX_MS,\n stopSettleTimeoutMs: options.stopSettleTimeoutMs ?? DEFAULT_STOP_SETTLE_TIMEOUT_MS,\n now: options.now,\n };\n }\n\n /** Idempotent. Starts the poll timer (unref'd) and runs an initial tick. */\n start(): void {\n if (!this.stopped) return;\n this.stopped = false;\n this.timer = setInterval(() => void this.tick(), this.options.pollMs);\n this.timer.unref?.();\n void this.tick();\n }\n\n /** Idempotent. Stops the timer, aborts in-flight drains (their claims stay\n * retryable) and waits up to `stopSettleTimeoutMs` for them to settle. A\n * drain that ignores abort is named in a warning and left behind: the\n * caller's later shutdown phases (orchestrator flush and dispose) must\n * still run before the service manager's kill. */\n async stop(): Promise<void> {\n if (this.stopped) return;\n this.stopped = true;\n if (this.timer) {\n clearInterval(this.timer);\n this.timer = undefined;\n }\n const aborts: Promise<void>[] = [];\n for (const entry of this.inFlight.values()) {\n entry.controller.abort(new Error(\"backlog scheduler stopping\"));\n aborts.push(entry.settled);\n }\n const bound = Promise.withResolvers<\"timeout\">();\n const boundTimer = setTimeout(() => bound.resolve(\"timeout\"), this.options.stopSettleTimeoutMs);\n try {\n const result = await Promise.race([Promise.allSettled(aborts), bound.promise]);\n if (result === \"timeout\") {\n log.warn(\n `backlog scheduler stop: ${this.inFlight.size} drain(s) ignored abort for ${this.options.stopSettleTimeoutMs}ms; ` +\n `continuing shutdown (stuck keys: ${[...this.inFlight.keys()].join(\", \")})`,\n );\n }\n } finally {\n clearTimeout(boundTimer);\n }\n }\n\n /** Bounded snapshot for ops/watchers: counters + per-key states + live sets. */\n snapshot(): BacklogSchedulerSnapshot {\n return {\n counters: {\n claimed: this.counters.claimed,\n processed: this.counters.processed,\n durableOutputs: this.counters.durableOutputs,\n retried: this.counters.retried,\n denied: { ...this.counters.denied },\n failed: this.counters.failed,\n },\n inFlight: [...this.inFlight.keys()],\n reservedKeys: [...this.reserved],\n keys: [...this.keys.entries()].map(([key, state]) => ({\n key,\n state: state.state,\n turnsRemaining: state.turnsRemaining,\n reason: state.reason,\n })),\n };\n }\n\n /** One scan+submit pass (tests drive this instead of the timer). Waits out\n * any in-progress tick first so the pass always actually scans. */\n async tickForTest(): Promise<void> {\n // setImmediate: yields to the event loop so pending I/O (a slow first\n // scan) can finish; a microtask spin would starve it.\n while (this.ticking) await new Promise((resolve) => setImmediate(resolve));\n await this.tick();\n }\n\n /** Await the settle (slot release) of everything currently in flight,\n * optionally excluding one still-gated key (tests). */\n async settleForTest(exclude?: string): Promise<void> {\n for (;;) {\n const pending = [...this.inFlight.entries()].filter(([key]) => key !== exclude).map(([, entry]) => entry.settled);\n if (pending.length === 0) return;\n await Promise.allSettled(pending);\n }\n }\n\n private now(): number {\n return this.options.now?.() ?? Date.now();\n }\n\n private async tick(): Promise<void> {\n if (this.ticking || this.stopped) return;\n this.ticking = true;\n const cursorBeforeTick = this.claimCursor;\n try {\n // Fast bail: a breaker already open must not pay discovery I/O\n // (listPage reads and parses claim bodies on every poll). The\n // submitCandidates guard below still catches a breaker that opens\n // while discovery awaits.\n const breakerBeforeDiscovery = this.deps.breakerSnapshot?.();\n if (\n breakerBeforeDiscovery &&\n breakerBeforeDiscovery.state === \"open\" &&\n this.now() < breakerBeforeDiscovery.openUntilMs\n ) {\n return;\n }\n // stop() may land while discovery's I/O is pending: re-check before\n // submitting anything, and again per candidate.\n // A discovery failure (EACCES/EIO on the claims dir) must not reject\n // into a detached timer callback: it would be an unhandled rejection\n // that terminates the server. Log, skip this pass, retry next poll.\n let candidates: { key: string; needsClaim: boolean }[];\n try {\n candidates = await this.discoverCandidates();\n } catch (err) {\n // Discovery may have listed a page before it failed: the page cursor\n // already moved, so restore it — otherwise those claims wait for the\n // cursor to wrap instead of the next poll.\n this.claimCursor = cursorBeforeTick;\n log.warn(\n `backlog drain: discovery failed; retrying next poll: ${err instanceof Error ? err.message : String(err)}`\n );\n return;\n }\n if (this.stopped) return;\n const dropped = this.submitCandidates(candidates);\n // The concurrency bound stopped submission mid-page: rewind the page\n // cursor so the unsubmitted claims are re-listed on the next tick\n // (already-submitted ones are gated by inFlight and key backoff).\n if (dropped) this.claimCursor = cursorBeforeTick;\n } finally {\n this.ticking = false;\n }\n }\n\n /** Bounded discovery: ONE page of existing claims with pending turns */\n private async discoverCandidates(): Promise<{ key: string; needsClaim: boolean }[]> {\n const out: { key: string; needsClaim: boolean }[] = [];\n const seen = new Set<string>();\n const pageLimit = Math.max(this.submissionLimit() * 4, 16);\n const page = await this.deps.claims.listPage(this.claimCursor, pageLimit);\n for (const listed of page.entries) {\n seen.add(listed.key);\n out.push({ key: listed.key, needsClaim: false });\n }\n this.claimCursor = page.nextCursor;\n for (const [key, counts] of await this.deps.liveBufferCounts()) {\n if (counts.turns + counts.retainedTurns <= 0) continue;\n if (seen.has(key) || this.deps.claims.isClaimed(key)) continue;\n seen.add(key);\n out.push({ key, needsClaim: true });\n }\n return out;\n }\n\n /** Submission bound: the queue's own concurrency limit, read with the\n * documented \"0 disables\" contract — a zero limit submits nothing. */\n private submissionLimit(): number {\n if (this.deps.queue.maxConcurrency <= 0) return 0;\n return this.deps.queue.maxConcurrency;\n }\n\n /** Submit discovery candidates within the queue's concurrency bound. */\n private submitCandidates(candidates: { key: string; needsClaim: boolean }[]): boolean {\n // Breaker-open churn guard: a full attempt reads the claim, rebuilds the\n // buffer/coordinator and re-renders chunks before the breaker fails it\n // fast — pure heap pressure per poll during a provider stall. Skip while\n // the window is open; once it lapses, submissions resume and the\n // breaker's half-open probe runs as usual.\n const breaker = this.deps.breakerSnapshot?.();\n if (breaker && breaker.state === \"open\" && this.now() < breaker.openUntilMs) {\n return true;\n }\n let dropped = false;\n for (const candidate of candidates) {\n if (this.stopped || this.inFlight.size >= this.submissionLimit()) {\n dropped = true;\n break;\n }\n if (!this.candidateEligible(candidate)) continue;\n // Fence the claim decision: reserve the key synchronously BEFORE the\n // async rename so no queued task for it can pass the claimed gate in\n // the meantime. Release happens when the decision settles.\n if (candidate.needsClaim) {\n if (!this.deps.queue.tryReserveKey(candidate.key)) continue;\n this.reserved.add(candidate.key);\n }\n void this.submit(candidate.key, candidate.needsClaim);\n }\n return dropped;\n }\n\n /** inFlight is the authority for \"already submitted\" — key state only\n * exists once an outcome landed (backoff/denied gating below). */\n private candidateEligible(candidate: { key: string; needsClaim: boolean }): boolean {\n if (this.stopped || this.inFlight.size >= this.submissionLimit()) return false;\n if (this.inFlight.has(candidate.key)) return false;\n const state = this.keys.get(candidate.key);\n return !(state && this.now() < state.nextAttemptMs);\n }\n\n /** Claim (when needed), then drain one key; the reservation spans the async\n * claim decision, the queue entry carries the key afterwards. */\n private async submit(key: string, needsClaim: boolean): Promise<void> {\n const controller = new AbortController();\n const { promise: settled, resolve: settle } = Promise.withResolvers<void>();\n this.inFlight.set(key, { controller, settled });\n try {\n if (!(await this.claimForSubmit(key, needsClaim, this.options.ownerId))) return;\n // Stopped between the claim decision and the task: leave the claim\n // with its lease (it expires; the next start adopts) — never drain.\n if (this.stopped) return;\n await this.drainClaimedKey(key, controller.signal, this.options.ownerId);\n } catch (err) {\n // Claim/drain failures are scheduler-level: the claim content is\n // untouched — count failed and back off (never an unhandled rejection\n // in the detached submission).\n this.counters.failed += 1;\n const message = err instanceof Error ? err.message : String(err);\n // SAFETY: a thrown non-Error (incl. null) carries no retry hint; the\n // optional chain reads the hint off Error throws only.\n this.setBackoff(key, (err as { turnsRemaining?: number } | null | undefined)?.turnsRemaining ?? 0, message);\n log.warn(`backlog drain: ${key} submission failed: ${message}`);\n } finally {\n this.inFlight.delete(key);\n this.reserved.delete(key);\n this.deps.queue.releaseKeyReservation(key);\n settle();\n }\n }\n\n /** after all — the key goes quiet without a task. \"claimed\": ours. */\n private async claimForSubmit(key: string, needsClaim: boolean, ownerId: string): Promise<boolean> {\n if (!needsClaim) return true;\n try {\n const outcome = await this.deps.claims.claimFromSessionFile(key, this.deps.lease(ownerId));\n if (outcome === \"empty\") {\n this.keys.delete(key);\n return false;\n }\n return true;\n } finally {\n this.reserved.delete(key);\n this.deps.queue.releaseKeyReservation(key);\n }\n }\n\n /** Drain one claimed key. drainKey reports failures as outcomes; a thrown\n * error still means the claim content is intact — count it failed and\n * back off. */\n private async drainClaimedKey(key: string, signal: AbortSignal, ownerId: string): Promise<void> {\n this.counters.claimed += 1;\n try {\n const outcome = await this.deps.drainKey(key, {\n ownerId,\n signal,\n });\n this.applyOutcome(key, outcome);\n } catch (err) {\n this.counters.failed += 1;\n const message = err instanceof Error ? err.message : String(err);\n // SAFETY: a thrown non-Error (incl. null) carries no retry hint; the\n // optional chain reads the hint off Error throws only.\n this.setBackoff(key, (err as { turnsRemaining?: number } | null | undefined)?.turnsRemaining ?? 0, message);\n log.warn(`backlog drain: ${key} threw: ${message}`);\n }\n }\n\n private applyOutcome(key: string, outcome: DrainSessionOutcome): void {\n const deniedTurns = outcome.denied?.reduce((sum, entry) => sum + entry.turns, 0) ?? 0;\n const previous = this.keys.get(key);\n const progressed = outcome.turnsRemaining < (previous?.turnsRemaining ?? Number.POSITIVE_INFINITY);\n if (outcome.status === \"drained\") {\n // The claim is now an empty tombstone: authoritative, nothing pending.\n // New ingress consumes it via the native save path and re-candidates.\n this.keys.delete(key);\n this.counters.processed += 1;\n this.counters.durableOutputs += outcome.durableOutputCount;\n log.info(\n `backlog drain: ${key} drained (${outcome.turnsAtStart} turn(s), ${outcome.durableOutputCount} durable output(s))`\n );\n return;\n }\n this.recordNonDrainedCounters(previous, outcome, deniedTurns);\n const denied = deniedTurns > 0 && outcome.turnsRemaining > 0;\n this.keys.set(key, this.nextKeyState(previous, outcome, denied, progressed));\n log.info(\n `backlog drain: ${key} ${outcome.status} (${outcome.turnsRemaining} turn(s) remaining` +\n `${denied ? `, denied: ${deniedTurns}` : \"\"}${outcome.reason ? `, ${outcome.reason}` : \"\"})`\n );\n }\n\n /** Denied backlog counters for a non-drained outcome. */\n private recordNonDrainedCounters(\n previous: KeyState | undefined,\n outcome: DrainSessionOutcome,\n deniedTurns: number\n ): void {\n if (deniedTurns > 0) {\n this.counters.denied.keys += 1;\n this.counters.denied.turns += deniedTurns;\n }\n if (outcome.status === \"failed\") this.counters.failed += 1;\n else if (previous !== undefined && (previous.state === \"backoff\" || previous.state === \"denied\"))\n this.counters.retried += 1;\n }\n\n /** The post-drain key state: denial waits the full max window (its content\n * is valid but currently unauthorized); progress resets the exponent. */\n private nextKeyState(\n previous: KeyState | undefined,\n outcome: DrainSessionOutcome,\n denied: boolean,\n progressed: boolean\n ): KeyState {\n return {\n state: denied ? \"denied\" : \"backoff\",\n nextAttemptMs: this.now() + this.backoffMs(previous, progressed && !denied),\n turnsRemaining: outcome.turnsRemaining,\n reason: outcome.reason,\n backoffExponent: this.nextBackoffExponent(denied, progressed, previous),\n };\n }\n\n private nextBackoffExponent(denied: boolean, progressed: boolean, previous: KeyState | undefined): number {\n return denied || !progressed ? (previous?.backoffExponent ?? 0) + 1 : 0;\n }\n\n private backoffMs(previous: KeyState | undefined, progressed: boolean): number {\n if (previous?.state === \"denied\") return this.options.retryMaxMs;\n const exponent = progressed ? 0 : (previous?.backoffExponent ?? 0) + 1;\n return Math.min(this.options.retryBaseMs * 2 ** exponent, this.options.retryMaxMs);\n }\n\n private setBackoff(key: string, turnsRemaining: number, reason: string): void {\n const previous = this.keys.get(key);\n this.keys.set(key, {\n state: \"backoff\",\n nextAttemptMs: this.now() + this.backoffMs(previous, false),\n turnsRemaining,\n reason,\n backoffExponent: (previous?.backoffExponent ?? 0) + 1,\n });\n }\n}\n\n/** Lease lifetime for claims the scheduler takes (matches the runner default). */\nconst SCHEDULER_LEASE_MS = 120_000;\n\n/** Wire the scheduler to an orchestrator's own queue, claim store, live buffer\n * counts and drain runner — the daemon's single ownership point. */\nexport function wireBacklogScheduler(\n orchestrator: Orchestrator,\n options: BacklogSchedulerOptions = {}\n): BacklogScheduler {\n const runner = new BufferDrainRunner(orchestrator);\n return new BacklogScheduler(\n {\n queue: orchestrator.extractionQueueCoordinator,\n claims: orchestrator.storage.bufferDrainClaims(),\n liveBufferCounts: async () => {\n // The daemon's buffer may be lazy: ensure the persisted state is in\n // memory before counting (load is guarded/idempotent).\n await orchestrator.buffer.load();\n return orchestrator.buffer.entryCounts();\n },\n lease: (ownerId) => {\n const now = new Date().toISOString();\n return {\n ownerId,\n pid: process.pid,\n host: hostname(),\n acquiredAt: now,\n heartbeatAt: now,\n leaseMs: SCHEDULER_LEASE_MS,\n };\n },\n drainKey: (key, drainOptions) => runner.drainSession(key, drainOptions),\n // The orchestrator's one shared provider breaker (foreground and every\n // claim-backed drain accumulate toward the same threshold).\n breakerSnapshot: () => orchestrator.getExtractionResilienceStatus().breaker,\n },\n options\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,SAAS,kBAAkB;AAC3B,SAAS,gBAAgB;AAuFzB,IAAM,kBAAkB;AACxB,IAAM,wBAAwB;AAC9B,IAAM,uBAAuB,KAAK;AAGlC,IAAM,iCAAiC;AAEhC,IAAM,mBAAN,MAAuB;AAAA,EACX;AAAA,EACA;AAAA,EACA,OAAO,oBAAI,IAAsB;AAAA,EACjC,WAAW,oBAAI,IAAqE;AAAA,EACpF,WAAW,oBAAI,IAAY;AAAA,EAC3B,WAAqC;AAAA,IACpD,SAAS;AAAA,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AAkB,YAAY;AAG5B,cAAM,aAAa,OAAO,KAAK;AAC/B,eAAO,aAAa,OAAO,YAAY;AAAA,MACzC;AAAA,MACA,OAAO,CAAC,YAAY;AAClB,cAAM,OAAM,oBAAI,KAAK,GAAE,YAAY;AACnC,eAAO;AAAA,UACL;AAAA,UACA,KAAK,QAAQ;AAAA,UACb,MAAM,SAAS;AAAA,UACf,YAAY;AAAA,UACZ,aAAa;AAAA,UACb,SAAS;AAAA,QACX;AAAA,MACF;AAAA,MACA,UAAU,CAAC,KAAK,iBAAiB,OAAO,aAAa,KAAK,YAAY;AAAA;AAAA;AAAA,MAGtE,iBAAiB,MAAM,aAAa,8BAA8B,EAAE;AAAA,IACtE;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  BufferDrainRunner,
3
3
  ClaimBufferStorage
4
- } from "../chunk-TZKK72BY.js";
5
- import "../chunk-5DGK7E4W.js";
4
+ } from "../chunk-UBJ5RPDM.js";
5
+ import "../chunk-VZMRKYNR.js";
6
6
  import "../chunk-6P7U3HWG.js";
7
7
  import "../chunk-PQM3B54K.js";
8
8
  import "../chunk-B3DR2JBZ.js";
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Exit-once bookkeeping for a queued extraction task (`onTaskExit`).
3
+ *
4
+ * A task settled (abort, queue deadline) before its closure ever ran has
5
+ * nothing to exit, so `settled()` reports exit at once; a claim-lease owner
6
+ * waiting on the exit is then not held behind an unrelated running extraction.
7
+ * A closure that did start reports exit when it finishes. Either way the
8
+ * callback fires exactly once.
9
+ */
10
+ export declare function createTaskExit(onExit?: () => void): {
11
+ start: () => void;
12
+ settled: () => void;
13
+ report: () => void;
14
+ };
15
+ //# sourceMappingURL=task-exit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"task-exit.d.ts","sourceRoot":"","sources":["../../src/orchestration/task-exit.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,MAAM,CAAC,EAAE,MAAM,IAAI;;;kBAG7B,IAAI;EAcxB"}
@@ -219,13 +219,7 @@ export declare class TurnIngestionCoordinator {
219
219
  abortSignal?: AbortSignal;
220
220
  /** Automatic buffered work only. Replay and import must not set this. */
221
221
  preemptable?: boolean;
222
- /**
223
- * Invoked when the queued closure has FULLY exited (after settlement).
224
- * Settlement can fire before the closure exits — e.g. an abort listener
225
- * settles while persistence is still in flight — so callers that
226
- * release resources on settlement (claim leases) can use this to wait
227
- * for the actual task exit first.
228
- */
222
+ /** Fires once when the task is done: closure exited, or settled before it started. */
229
223
  onTaskExit?: () => void;
230
224
  /** Fail-closed force-flush only. Not implied by failOnExtractionFailure. */
231
225
  preemptRunning?: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"turn-ingestion.d.ts","sourceRoot":"","sources":["../../src/orchestration/turn-ingestion.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAIH,OAAO,EAAE,WAAW,EAAuB,MAAM,cAAc,CAAC;AAChE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAE1D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AAI7E,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EAAE,0BAA0B,EAAE,MAAM,mCAAmC,CAAC;AAC/E,OAAO,EAEL,wBAAwB,EACxB,KAAK,mBAAmB,EACzB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,KAAK,UAAU,EAA6B,MAAM,oBAAoB,CAAC;AAChF,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AAEpE,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAC;AAKvF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AK,CAAC,EAAE,OAAO,EACf,MAAM,CAAC,EAAE,mBAAmB,KACzB,IAAI,CAAC;QACV,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,WAAW,CAAC,EAAE,WAAW,CAAC;QAC1B,yEAAyE;QACzE,WAAW,CAAC,EAAE,OAAO,CAAC;QACtB,sFAAsF;QACtF,UAAU,CAAC,EAAE,MAAM,IAAI,CAAC;QACxB,4EAA4E;QAC5E,cAAc,CAAC,EAAE,OAAO,CAAC;QACzB,sBAAsB,CAAC,EAAE,MAAM,CAAC;QAChC;;;;WAIG;QACH,iBAAiB,CAAC,EAAE,MAAM,CAAC;QAC3B,qBAAqB,CAAC,EAAE,wBAAwB,GAAG,IAAI,CAAC;QACxD,wEAAwE;QACxE,SAAS,CAAC,EAAE,8BAA8B,CAAC;KACvC,GACL,OAAO,CAAC,IAAI,CAAC;IAmShB;;;;;;;;;OASG;IACG,8BAA8B,CAClC,KAAK,EAAE,SAAS,UAAU,EAAE,EAC5B,IAAI,EAAE;QACJ,UAAU,EAAE,MAAM,CAAC;QACnB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,SAAS,EAAE,MAAM,CAAC;QAClB,SAAS,EAAE,MAAM,CAAC;QAClB,aAAa,EAAE,OAAO,CAAC;QACvB,WAAW,CAAC,EAAE,WAAW,CAAC;KAC3B,GACA,OAAO,CAAC,IAAI,CAAC;CAkEjB;AAED,sFAAsF;AACtF,MAAM,MAAM,wBAAwB,GAAG,UAAU,CAAC,wBAAwB,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC"}
@@ -6,7 +6,7 @@ import {
6
6
  mergeGraphExpandedResults,
7
7
  qmdStartupCollectionChecksWithTimeout,
8
8
  resolveEffectiveIdentityInjectionMode
9
- } from "./chunk-5DGK7E4W.js";
9
+ } from "./chunk-VZMRKYNR.js";
10
10
  import "./chunk-6P7U3HWG.js";
11
11
  import "./chunk-PQM3B54K.js";
12
12
  import "./chunk-B3DR2JBZ.js";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  runRecallNavigation
3
- } from "./chunk-5DGK7E4W.js";
3
+ } from "./chunk-VZMRKYNR.js";
4
4
  import "./chunk-6P7U3HWG.js";
5
5
  import "./chunk-PQM3B54K.js";
6
6
  import "./chunk-B3DR2JBZ.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remnic/core",
3
- "version": "10.0.98",
3
+ "version": "10.0.99",
4
4
  "description": "Framework-agnostic Remnic memory engine — orchestrator, storage, extraction, search, trust zones",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -3386,7 +3386,7 @@
3386
3386
  "core"
3387
3387
  ],
3388
3388
  "peerDependencies": {
3389
- "@remnic/coding-graph": "^10.0.98"
3389
+ "@remnic/coding-graph": "^10.0.99"
3390
3390
  },
3391
3391
  "peerDependenciesMeta": {
3392
3392
  "@remnic/coding-graph": {
@@ -12,6 +12,7 @@ import assert from "node:assert/strict";
12
12
  import test from "node:test";
13
13
 
14
14
  import { hostname } from "node:os";
15
+ import { log } from "./logger.js";
15
16
  import {
16
17
  BacklogScheduler,
17
18
  type BacklogSchedulerDeps,
@@ -390,6 +391,53 @@ test("the in-flight bound is the queue's own maxConcurrency", async () => {
390
391
  }
391
392
  });
392
393
 
394
+ test("stop returns within its settle bound and names a drain that ignores abort", async () => {
395
+ const queue = new ExtractionQueueCoordinator(1);
396
+ const state: StubState = {
397
+ counts: new Map([["stuck-key", { turns: 3, retainedTurns: 0 }]]),
398
+ claimed: new Set(),
399
+ claimTurns: new Map(),
400
+ claimedThisRun: new Set(),
401
+ outcomes: [],
402
+ drained: [],
403
+ };
404
+ const entered = Promise.withResolvers<void>();
405
+ const forever = new Promise<DrainSessionOutcome>(() => {});
406
+ const scheduler = new BacklogScheduler(
407
+ {
408
+ ...makeDeps(state, queue),
409
+ // Ignores options.signal entirely: the shape that held a daemon stop
410
+ // until the 700 s systemd kill.
411
+ drainKey: async () => {
412
+ entered.resolve();
413
+ return forever;
414
+ },
415
+ },
416
+ { pollMs: 3_600_000, stopSettleTimeoutMs: 50 }
417
+ );
418
+ const warnings: string[] = [];
419
+ const originalWarn = log.warn;
420
+ log.warn = (msg: string) => {
421
+ warnings.push(msg);
422
+ };
423
+ try {
424
+ scheduler.start();
425
+ await scheduler.tickForTest();
426
+ await entered.promise;
427
+ const outcome = await Promise.race([
428
+ scheduler.stop().then(() => "returned"),
429
+ new Promise<string>((resolve) => setTimeout(() => resolve("hung"), 2_000)),
430
+ ]);
431
+ assert.equal(outcome, "returned", "stop must not wait forever on a drain that ignores abort");
432
+ assert.ok(
433
+ warnings.some((w) => w.includes("stuck-key")),
434
+ `the stuck key is named in a warning: ${JSON.stringify(warnings)}`
435
+ );
436
+ } finally {
437
+ log.warn = originalWarn;
438
+ }
439
+ });
440
+
393
441
  test("stop aborts in-flight drains; a fresh start resumes the still-claimed backlog", async () => {
394
442
  const queue = new ExtractionQueueCoordinator(1);
395
443
  const state: StubState = {
@@ -70,6 +70,8 @@ export interface BacklogSchedulerOptions {
70
70
  pollMs?: number;
71
71
  retryBaseMs?: number;
72
72
  retryMaxMs?: number;
73
+ /** Bound on `stop()`'s wait for aborted drains to settle. */
74
+ stopSettleTimeoutMs?: number;
73
75
  now?: () => number;
74
76
  }
75
77
 
@@ -114,6 +116,9 @@ interface KeyState {
114
116
  const DEFAULT_POLL_MS = 15_000;
115
117
  const DEFAULT_RETRY_BASE_MS = 30_000;
116
118
  const DEFAULT_RETRY_MAX_MS = 15 * 60_000;
119
+ // Aborted drains normally settle within seconds (a chunk boundary); this only
120
+ // bounds the pathological case, well inside the daemon's stop budget.
121
+ const DEFAULT_STOP_SETTLE_TIMEOUT_MS = 30_000;
117
122
 
118
123
  export class BacklogScheduler {
119
124
  private readonly deps: BacklogSchedulerDeps;
@@ -141,6 +146,7 @@ export class BacklogScheduler {
141
146
  pollMs: options.pollMs ?? DEFAULT_POLL_MS,
142
147
  retryBaseMs: options.retryBaseMs ?? DEFAULT_RETRY_BASE_MS,
143
148
  retryMaxMs: options.retryMaxMs ?? DEFAULT_RETRY_MAX_MS,
149
+ stopSettleTimeoutMs: options.stopSettleTimeoutMs ?? DEFAULT_STOP_SETTLE_TIMEOUT_MS,
144
150
  now: options.now,
145
151
  };
146
152
  }
@@ -155,7 +161,10 @@ export class BacklogScheduler {
155
161
  }
156
162
 
157
163
  /** Idempotent. Stops the timer, aborts in-flight drains (their claims stay
158
- * retryable) and waits for them to settle. */
164
+ * retryable) and waits up to `stopSettleTimeoutMs` for them to settle. A
165
+ * drain that ignores abort is named in a warning and left behind: the
166
+ * caller's later shutdown phases (orchestrator flush and dispose) must
167
+ * still run before the service manager's kill. */
159
168
  async stop(): Promise<void> {
160
169
  if (this.stopped) return;
161
170
  this.stopped = true;
@@ -168,7 +177,19 @@ export class BacklogScheduler {
168
177
  entry.controller.abort(new Error("backlog scheduler stopping"));
169
178
  aborts.push(entry.settled);
170
179
  }
171
- await Promise.allSettled(aborts);
180
+ const bound = Promise.withResolvers<"timeout">();
181
+ const boundTimer = setTimeout(() => bound.resolve("timeout"), this.options.stopSettleTimeoutMs);
182
+ try {
183
+ const result = await Promise.race([Promise.allSettled(aborts), bound.promise]);
184
+ if (result === "timeout") {
185
+ log.warn(
186
+ `backlog scheduler stop: ${this.inFlight.size} drain(s) ignored abort for ${this.options.stopSettleTimeoutMs}ms; ` +
187
+ `continuing shutdown (stuck keys: ${[...this.inFlight.keys()].join(", ")})`,
188
+ );
189
+ }
190
+ } finally {
191
+ clearTimeout(boundTimer);
192
+ }
172
193
  }
173
194
 
174
195
  /** Bounded snapshot for ops/watchers: counters + per-key states + live sets. */
@@ -299,6 +299,26 @@ test("abort while queued: settled task starts, skips extraction, queue drains",
299
299
  assert.equal(settled.length, 1, "queued task settles exactly once from the abort");
300
300
  });
301
301
 
302
+ test("abort while queued: onTaskExit fires at once, not after the queue head finishes", async () => {
303
+ const h = makeHarness();
304
+ const controller = new AbortController();
305
+ // Occupies the single worker; the drain stays blocked until release().
306
+ await h.coordinator.processTurn("user", "running", "k");
307
+ let exited = 0;
308
+ await h.coordinator.queueBufferedExtraction([makeTurn("queued then aborted")], "trigger_mode", {
309
+ bufferKey: "k",
310
+ preemptable: true,
311
+ abortSignal: controller.signal,
312
+ onTaskExit: () => { exited += 1; },
313
+ });
314
+ controller.abort();
315
+ // A claim-lease owner waiting on this exit must not be held by an unrelated
316
+ // running extraction: nothing of this task ever ran.
317
+ assert.equal(exited, 1, "queued task that never started reports exit on abort");
318
+ await h.release();
319
+ assert.equal(exited, 1, "the later no-op closure run does not report a second exit");
320
+ });
321
+
302
322
  test("sharing bound: distinct reference slots equal the union, not the snapshot sum", async () => {
303
323
  const h = makeHarness();
304
324
  const turns = 30;
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Exit-once bookkeeping for a queued extraction task (`onTaskExit`).
3
+ *
4
+ * A task settled (abort, queue deadline) before its closure ever ran has
5
+ * nothing to exit, so `settled()` reports exit at once; a claim-lease owner
6
+ * waiting on the exit is then not held behind an unrelated running extraction.
7
+ * A closure that did start reports exit when it finishes. Either way the
8
+ * callback fires exactly once.
9
+ */
10
+ export function createTaskExit(onExit?: () => void) {
11
+ let started = false;
12
+ let reported = false;
13
+ const report = (): void => {
14
+ if (reported) return;
15
+ reported = true;
16
+ onExit?.();
17
+ };
18
+ return {
19
+ start: () => {
20
+ started = true;
21
+ },
22
+ settled: () => {
23
+ if (!started) report();
24
+ },
25
+ report,
26
+ };
27
+ }
@@ -60,6 +60,7 @@ import {
60
60
  // The class lives in ../buffer-admission.js next to BufferAdmissionRefusedError;
61
61
  // re-exported here so existing importers keep their import path.
62
62
  import { ReplayAdmissionRefusedError, StorageTargetRequiredError } from "../buffer-admission.js";
63
+ import { createTaskExit } from "./task-exit.js";
63
64
  export { ReplayAdmissionRefusedError, StorageTargetRequiredError };
64
65
 
65
66
  export interface TurnIngestionDeps {
@@ -798,13 +799,7 @@ export class TurnIngestionCoordinator {
798
799
  abortSignal?: AbortSignal;
799
800
  /** Automatic buffered work only. Replay and import must not set this. */
800
801
  preemptable?: boolean;
801
- /**
802
- * Invoked when the queued closure has FULLY exited (after settlement).
803
- * Settlement can fire before the closure exits — e.g. an abort listener
804
- * settles while persistence is still in flight — so callers that
805
- * release resources on settlement (claim leases) can use this to wait
806
- * for the actual task exit first.
807
- */
802
+ /** Fires once when the task is done: closure exited, or settled before it started. */
808
803
  onTaskExit?: () => void;
809
804
  /** Fail-closed force-flush only. Not implied by failOnExtractionFailure. */
810
805
  preemptRunning?: boolean;
@@ -845,6 +840,7 @@ export class TurnIngestionCoordinator {
845
840
  : undefined;
846
841
  let timeout: ReturnType<typeof setTimeout> | undefined;
847
842
  let settled = false;
843
+ const exit = createTaskExit(options.onTaskExit);
848
844
  const clearQueueWaitTimer = (): void => {
849
845
  if (timeout) {
850
846
  clearTimeout(timeout);
@@ -867,6 +863,7 @@ export class TurnIngestionCoordinator {
867
863
  clearQueueWaitTimer();
868
864
  clearAbortListener();
869
865
  options.onTaskSettled?.(error, result);
866
+ exit.settled();
870
867
  return true;
871
868
  };
872
869
  if (options.abortSignal) {
@@ -910,6 +907,7 @@ export class TurnIngestionCoordinator {
910
907
  const queuedTurnsSource: { chain: SnapshotChain } | { direct: BufferTurn[] } =
911
908
  sharingNode ? { chain: sharingNode } : { direct: turnsToExtract };
912
909
  const accepted = this.deps.extractionQueueCoordinator.enqueue(async (preemptHandle) => {
910
+ exit.start();
913
911
  try {
914
912
  await this.deps.extractionQueueCoordinator.runPreemptable(preemptHandle, preemptable, options.abortSignal, async (abortSignal) => {
915
913
  if (settled) return;
@@ -1094,13 +1092,13 @@ export class TurnIngestionCoordinator {
1094
1092
  });
1095
1093
  } finally {
1096
1094
  if (sharingNode) this.snapshotSharing.release(sharingNode);
1097
- options.onTaskExit?.();
1095
+ exit.report();
1098
1096
  }
1099
1097
  }, { front: options.preemptRunning === true, key: bufferKey });
1100
1098
  if (!accepted) {
1101
1099
  if (sharingNode) this.snapshotSharing.release(sharingNode);
1102
1100
  settleTask(new Error("extraction queue is stopped"));
1103
- options.onTaskExit?.();
1101
+ exit.report();
1104
1102
  return;
1105
1103
  }
1106
1104