@remnic/core 9.3.640 → 9.3.642

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 (231) hide show
  1. package/dist/access-cli.js +16 -16
  2. package/dist/access-http.d.ts +5 -5
  3. package/dist/access-http.js +9 -9
  4. package/dist/access-mcp.d.ts +5 -5
  5. package/dist/access-mcp.js +8 -8
  6. package/dist/{access-service-jyYute38.d.ts → access-service-DFXIlGvZ.d.ts} +2 -2
  7. package/dist/access-service.d.ts +5 -5
  8. package/dist/access-service.js +7 -7
  9. package/dist/action-confidence.d.ts +2 -2
  10. package/dist/active-memory-bridge.d.ts +2 -2
  11. package/dist/active-recall.d.ts +2 -2
  12. package/dist/behavior-learner.d.ts +2 -2
  13. package/dist/behavior-signals.d.ts +2 -2
  14. package/dist/bootstrap.d.ts +4 -4
  15. package/dist/briefing.d.ts +2 -2
  16. package/dist/briefing.js +3 -3
  17. package/dist/buffer-surprise-report.d.ts +2 -2
  18. package/dist/buffer.d.ts +2 -2
  19. package/dist/bulk-import/index.d.ts +3 -3
  20. package/dist/bulk-import/index.js +2 -2
  21. package/dist/calibration.d.ts +2 -2
  22. package/dist/causal-behavior.d.ts +2 -2
  23. package/dist/causal-consolidation.d.ts +2 -2
  24. package/dist/causal-consolidation.js +4 -4
  25. package/dist/{chunk-WAKPKNEX.js → chunk-3UR4SBZF.js} +307 -70
  26. package/dist/chunk-3UR4SBZF.js.map +1 -0
  27. package/dist/{chunk-RJGPH2Q3.js → chunk-4HYLRROV.js} +2 -2
  28. package/dist/{chunk-3AZDLWDW.js → chunk-4HYWWO3W.js} +3 -3
  29. package/dist/{chunk-ISMZIMD3.js → chunk-4MNDVDBS.js} +2 -2
  30. package/dist/{chunk-JFHEEDRY.js → chunk-5IDVOWBE.js} +3 -3
  31. package/dist/{chunk-4GYGEKUB.js → chunk-6DDBW2V4.js} +4 -4
  32. package/dist/{chunk-LUDUFZTV.js → chunk-ABP6QMVM.js} +2 -2
  33. package/dist/chunk-ABP6QMVM.js.map +1 -0
  34. package/dist/{chunk-UZBK2JR6.js → chunk-ACNU2UBF.js} +16 -16
  35. package/dist/{chunk-UDZYZ5Q5.js → chunk-AK4DSORQ.js} +7 -7
  36. package/dist/{chunk-CMZLMIZI.js → chunk-BEMWL2FZ.js} +2 -2
  37. package/dist/{chunk-3F7RMHC4.js → chunk-C43KEWEV.js} +1 -1
  38. package/dist/{chunk-3F7RMHC4.js.map → chunk-C43KEWEV.js.map} +1 -1
  39. package/dist/{chunk-H2NCNXMS.js → chunk-CKITWVWJ.js} +2 -2
  40. package/dist/{chunk-C4YAIWDG.js → chunk-DM4US77W.js} +2 -2
  41. package/dist/{chunk-SBHQBC37.js → chunk-ECMMM2VE.js} +2 -2
  42. package/dist/{chunk-YMI4NRV7.js → chunk-EGBH5IPJ.js} +4 -4
  43. package/dist/{chunk-SHHT4JTC.js → chunk-GYITUZFT.js} +2 -2
  44. package/dist/{chunk-EKIQBGAY.js → chunk-IENGGY2C.js} +2 -2
  45. package/dist/{chunk-UU5LHD6J.js → chunk-NLPH23IQ.js} +2 -2
  46. package/dist/{chunk-A3UPMOJZ.js → chunk-NV2MGIW7.js} +2 -2
  47. package/dist/{chunk-PU44GBL4.js → chunk-OUELRE5E.js} +1 -1
  48. package/dist/chunk-OUELRE5E.js.map +1 -0
  49. package/dist/{chunk-J2KFC47S.js → chunk-RFSCIBCB.js} +2 -2
  50. package/dist/{chunk-IXSTQGYV.js → chunk-RREI7CNM.js} +2 -2
  51. package/dist/{chunk-C6XO6ONP.js → chunk-SZL2GGFY.js} +2 -2
  52. package/dist/{chunk-7XRSLMUD.js → chunk-THWT7RJU.js} +2 -2
  53. package/dist/{chunk-H4RWKZE2.js → chunk-TKNTAUA3.js} +2 -2
  54. package/dist/{chunk-7OH7KPF5.js → chunk-TTOYT5RB.js} +2 -2
  55. package/dist/{chunk-SEOTBRO4.js → chunk-U3GQ33JC.js} +35 -6
  56. package/dist/chunk-U3GQ33JC.js.map +1 -0
  57. package/dist/{chunk-C3EJ3UIS.js → chunk-WLGE6KEO.js} +3 -3
  58. package/dist/{cli-A4AIhv9e.d.ts → cli-DrL2Nv4j.d.ts} +5 -5
  59. package/dist/cli.d.ts +7 -7
  60. package/dist/cli.js +21 -21
  61. package/dist/compounding/engine.d.ts +2 -2
  62. package/dist/compounding/engine.js +3 -3
  63. package/dist/compounding/preference-consolidator.d.ts +2 -2
  64. package/dist/compression-optimizer.d.ts +2 -2
  65. package/dist/config.d.ts +2 -2
  66. package/dist/connectors/codex-materialize-runner.d.ts +2 -2
  67. package/dist/connectors/codex-materialize-runner.js +3 -3
  68. package/dist/connectors/codex-materialize.d.ts +2 -2
  69. package/dist/connectors/index.d.ts +2 -2
  70. package/dist/connectors/index.js +3 -3
  71. package/dist/consolidation-provenance-check.d.ts +2 -2
  72. package/dist/consolidation-undo.d.ts +2 -2
  73. package/dist/contradiction/index.d.ts +2 -2
  74. package/dist/conversation-index/backend.d.ts +2 -2
  75. package/dist/conversation-index/chunker.d.ts +2 -2
  76. package/dist/conversation-index/faiss-adapter.d.ts +2 -2
  77. package/dist/conversation-index/indexer.d.ts +2 -2
  78. package/dist/conversation-index/search.d.ts +2 -2
  79. package/dist/day-summary.d.ts +2 -2
  80. package/dist/delinearize.d.ts +2 -2
  81. package/dist/direct-answer-wiring.d.ts +2 -2
  82. package/dist/direct-answer.d.ts +2 -2
  83. package/dist/embedding-fallback.d.ts +2 -2
  84. package/dist/enrichment/index.d.ts +2 -2
  85. package/dist/entity-retrieval.d.ts +2 -2
  86. package/dist/entity-retrieval.js +3 -3
  87. package/dist/entity-schema.d.ts +2 -2
  88. package/dist/explicit-capture.d.ts +4 -4
  89. package/dist/extraction-judge-telemetry.d.ts +2 -2
  90. package/dist/extraction-judge-training.d.ts +2 -2
  91. package/dist/extraction-judge.d.ts +2 -2
  92. package/dist/extraction.d.ts +2 -2
  93. package/dist/extraction.js +1 -1
  94. package/dist/fallback-llm.d.ts +2 -2
  95. package/dist/identity-continuity.d.ts +2 -2
  96. package/dist/importance.d.ts +2 -2
  97. package/dist/importers/index.d.ts +2 -2
  98. package/dist/importers/index.js +2 -2
  99. package/dist/index.d.ts +138 -11
  100. package/dist/index.js +940 -92
  101. package/dist/index.js.map +1 -1
  102. package/dist/intent.d.ts +2 -2
  103. package/dist/lcm/engine.d.ts +2 -2
  104. package/dist/lcm/index.d.ts +2 -2
  105. package/dist/lcm/tools.d.ts +2 -2
  106. package/dist/lifecycle.d.ts +2 -2
  107. package/dist/live-connectors-runner.d.ts +2 -2
  108. package/dist/local-llm.d.ts +2 -2
  109. package/dist/maintenance/memory-governance.d.ts +2 -2
  110. package/dist/maintenance/memory-governance.js +3 -3
  111. package/dist/maintenance/rebuild-memory-lifecycle-ledger.js +3 -3
  112. package/dist/maintenance/rebuild-memory-projection.js +4 -4
  113. package/dist/mcp-memory-inspector-app.d.ts +5 -5
  114. package/dist/memory-action-policy.d.ts +2 -2
  115. package/dist/memory-cache.d.ts +2 -2
  116. package/dist/memory-lifecycle-ledger-utils.d.ts +2 -2
  117. package/dist/memory-projection-store.d.ts +2 -2
  118. package/dist/memory-provenance.d.ts +2 -2
  119. package/dist/memory-worth-outcomes.d.ts +2 -2
  120. package/dist/models-json.d.ts +2 -2
  121. package/dist/namespaces/migrate.d.ts +2 -2
  122. package/dist/namespaces/migrate.js +4 -4
  123. package/dist/namespaces/principal.d.ts +2 -2
  124. package/dist/namespaces/search.d.ts +2 -2
  125. package/dist/namespaces/storage.d.ts +2 -2
  126. package/dist/namespaces/storage.js +3 -3
  127. package/dist/native-knowledge.d.ts +2 -2
  128. package/dist/operator-toolkit.d.ts +2 -2
  129. package/dist/operator-toolkit.js +6 -6
  130. package/dist/{orchestrator-BEDTiuEO.d.ts → orchestrator-DEQW9j0Z.d.ts} +22 -5
  131. package/dist/orchestrator.d.ts +4 -4
  132. package/dist/orchestrator.js +15 -13
  133. package/dist/patterns-cli.d.ts +2 -2
  134. package/dist/{pipeline-D18UAKlN.d.ts → pipeline-BSTuml0d.d.ts} +1 -1
  135. package/dist/policy-runtime.d.ts +2 -2
  136. package/dist/qmd-recall-cache.d.ts +2 -2
  137. package/dist/qmd.d.ts +2 -2
  138. package/dist/recall-disclosure-escalation.d.ts +2 -2
  139. package/dist/recall-explain-renderer.d.ts +2 -2
  140. package/dist/recall-explain-renderer.js +3 -3
  141. package/dist/recall-planner-llm.d.ts +2 -2
  142. package/dist/recall-state.d.ts +2 -2
  143. package/dist/recall-tag-filter.d.ts +2 -2
  144. package/dist/recall-xray-cli.d.ts +2 -2
  145. package/dist/recall-xray-cli.js +4 -4
  146. package/dist/recall-xray-renderer.d.ts +2 -2
  147. package/dist/recall-xray-renderer.js +3 -3
  148. package/dist/recall-xray.d.ts +2 -2
  149. package/dist/recall-xray.js +2 -2
  150. package/dist/resolve-auth-token.d.ts +2 -2
  151. package/dist/retrieval-agents.d.ts +2 -2
  152. package/dist/retrieval-tiers.d.ts +2 -2
  153. package/dist/routing/engine.d.ts +2 -2
  154. package/dist/routing/store.d.ts +2 -2
  155. package/dist/search/embed-helper.d.ts +2 -2
  156. package/dist/search/factory.d.ts +2 -2
  157. package/dist/search/index.d.ts +2 -2
  158. package/dist/search/lancedb-backend.d.ts +2 -2
  159. package/dist/search/meilisearch-backend.d.ts +2 -2
  160. package/dist/search/noop-backend.d.ts +2 -2
  161. package/dist/search/orama-backend.d.ts +2 -2
  162. package/dist/search/port.d.ts +2 -2
  163. package/dist/search/remote-backend.d.ts +2 -2
  164. package/dist/{semantic-consolidation-Byut1ufK.d.ts → semantic-consolidation-DKdYzQOg.d.ts} +1 -1
  165. package/dist/semantic-consolidation.d.ts +3 -3
  166. package/dist/semantic-consolidation.js +4 -4
  167. package/dist/semantic-rule-promotion.js +3 -3
  168. package/dist/semantic-rule-verifier.d.ts +2 -2
  169. package/dist/semantic-rule-verifier.js +3 -3
  170. package/dist/session-observer-bands.d.ts +2 -2
  171. package/dist/session-observer-state.d.ts +2 -2
  172. package/dist/shared-context/manager.d.ts +2 -2
  173. package/dist/signal.d.ts +2 -2
  174. package/dist/storage.d.ts +2 -2
  175. package/dist/storage.js +2 -2
  176. package/dist/summarizer.d.ts +2 -2
  177. package/dist/summary-snapshot.d.ts +2 -2
  178. package/dist/temporal-supersession.d.ts +2 -2
  179. package/dist/temporal-validity.d.ts +2 -2
  180. package/dist/threading.d.ts +2 -2
  181. package/dist/tier-migration.d.ts +2 -2
  182. package/dist/tier-routing.d.ts +2 -2
  183. package/dist/topics.d.ts +2 -2
  184. package/dist/transcript.d.ts +2 -2
  185. package/dist/{types-BliCnURB.d.ts → types-ByK7T3L6.d.ts} +2 -0
  186. package/dist/{types-BzA1FKbg.d.ts → types-D8yUmSik.d.ts} +2 -1
  187. package/dist/types.d.ts +2 -2
  188. package/dist/types.js +1 -1
  189. package/dist/utility-runtime.d.ts +2 -2
  190. package/dist/verified-recall.js +3 -3
  191. package/package.json +1 -1
  192. package/src/bulk-import/types.ts +2 -0
  193. package/src/extraction-timeout.test.ts +6 -1
  194. package/src/extraction.ts +34 -5
  195. package/src/importers/base.ts +1 -1
  196. package/src/index.ts +7 -4
  197. package/src/orchestrator-flush.test.ts +640 -42
  198. package/src/orchestrator.ts +389 -70
  199. package/src/session-summaries/adapters.ts +438 -0
  200. package/src/session-summaries/index.ts +401 -0
  201. package/src/session-summaries/redaction.ts +160 -0
  202. package/src/session-summaries/session-summaries.test.ts +1748 -0
  203. package/src/session-summaries/types.ts +130 -0
  204. package/src/types.ts +1 -0
  205. package/dist/chunk-LUDUFZTV.js.map +0 -1
  206. package/dist/chunk-PU44GBL4.js.map +0 -1
  207. package/dist/chunk-SEOTBRO4.js.map +0 -1
  208. package/dist/chunk-WAKPKNEX.js.map +0 -1
  209. /package/dist/{chunk-RJGPH2Q3.js.map → chunk-4HYLRROV.js.map} +0 -0
  210. /package/dist/{chunk-3AZDLWDW.js.map → chunk-4HYWWO3W.js.map} +0 -0
  211. /package/dist/{chunk-ISMZIMD3.js.map → chunk-4MNDVDBS.js.map} +0 -0
  212. /package/dist/{chunk-JFHEEDRY.js.map → chunk-5IDVOWBE.js.map} +0 -0
  213. /package/dist/{chunk-4GYGEKUB.js.map → chunk-6DDBW2V4.js.map} +0 -0
  214. /package/dist/{chunk-UZBK2JR6.js.map → chunk-ACNU2UBF.js.map} +0 -0
  215. /package/dist/{chunk-UDZYZ5Q5.js.map → chunk-AK4DSORQ.js.map} +0 -0
  216. /package/dist/{chunk-CMZLMIZI.js.map → chunk-BEMWL2FZ.js.map} +0 -0
  217. /package/dist/{chunk-H2NCNXMS.js.map → chunk-CKITWVWJ.js.map} +0 -0
  218. /package/dist/{chunk-C4YAIWDG.js.map → chunk-DM4US77W.js.map} +0 -0
  219. /package/dist/{chunk-SBHQBC37.js.map → chunk-ECMMM2VE.js.map} +0 -0
  220. /package/dist/{chunk-YMI4NRV7.js.map → chunk-EGBH5IPJ.js.map} +0 -0
  221. /package/dist/{chunk-SHHT4JTC.js.map → chunk-GYITUZFT.js.map} +0 -0
  222. /package/dist/{chunk-EKIQBGAY.js.map → chunk-IENGGY2C.js.map} +0 -0
  223. /package/dist/{chunk-UU5LHD6J.js.map → chunk-NLPH23IQ.js.map} +0 -0
  224. /package/dist/{chunk-A3UPMOJZ.js.map → chunk-NV2MGIW7.js.map} +0 -0
  225. /package/dist/{chunk-J2KFC47S.js.map → chunk-RFSCIBCB.js.map} +0 -0
  226. /package/dist/{chunk-IXSTQGYV.js.map → chunk-RREI7CNM.js.map} +0 -0
  227. /package/dist/{chunk-C6XO6ONP.js.map → chunk-SZL2GGFY.js.map} +0 -0
  228. /package/dist/{chunk-7XRSLMUD.js.map → chunk-THWT7RJU.js.map} +0 -0
  229. /package/dist/{chunk-H4RWKZE2.js.map → chunk-TKNTAUA3.js.map} +0 -0
  230. /package/dist/{chunk-7OH7KPF5.js.map → chunk-TTOYT5RB.js.map} +0 -0
  231. /package/dist/{chunk-C3EJ3UIS.js.map → chunk-WLGE6KEO.js.map} +0 -0
@@ -29,7 +29,7 @@ import {
29
29
  import {
30
30
  CompoundingEngine,
31
31
  defaultTierMigrationCycleBudget
32
- } from "./chunk-SBHQBC37.js";
32
+ } from "./chunk-ECMMM2VE.js";
33
33
  import {
34
34
  SharedContextManager
35
35
  } from "./chunk-DRD2Q7HQ.js";
@@ -157,7 +157,7 @@ import {
157
157
  } from "./chunk-M75TBFKQ.js";
158
158
  import {
159
159
  ExtractionEngine
160
- } from "./chunk-SEOTBRO4.js";
160
+ } from "./chunk-U3GQ33JC.js";
161
161
  import {
162
162
  parseMemoryActionEligibilityContext
163
163
  } from "./chunk-ROZJACKP.js";
@@ -175,7 +175,7 @@ import {
175
175
  buildEntityRecallSection,
176
176
  entityRecentTranscriptLookbackHours,
177
177
  readRecentEntityTranscriptEntries
178
- } from "./chunk-A3UPMOJZ.js";
178
+ } from "./chunk-NV2MGIW7.js";
179
179
  import {
180
180
  buildEventOrderRecallSection,
181
181
  shouldRecallEventOrderEvidence
@@ -210,7 +210,7 @@ import {
210
210
  materializeAfterSemanticConsolidation,
211
211
  parseConsolidationResponse,
212
212
  parseOperatorAwareConsolidationResponse
213
- } from "./chunk-H4RWKZE2.js";
213
+ } from "./chunk-TKNTAUA3.js";
214
214
  import {
215
215
  normalizeReplaySessionKey
216
216
  } from "./chunk-2PRQG7PV.js";
@@ -219,13 +219,13 @@ import {
219
219
  } from "./chunk-X6IRLNOO.js";
220
220
  import {
221
221
  searchVerifiedEpisodes
222
- } from "./chunk-RJGPH2Q3.js";
222
+ } from "./chunk-4HYLRROV.js";
223
223
  import {
224
224
  ThreadingManager
225
225
  } from "./chunk-W4RVMTHR.js";
226
226
  import {
227
227
  searchVerifiedSemanticRules
228
- } from "./chunk-C6XO6ONP.js";
228
+ } from "./chunk-SZL2GGFY.js";
229
229
  import {
230
230
  searchWorkProductLedgerEntries
231
231
  } from "./chunk-ZRWB5D4H.js";
@@ -234,7 +234,7 @@ import {
234
234
  } from "./chunk-IHG27THY.js";
235
235
  import {
236
236
  NamespaceStorageRouter
237
- } from "./chunk-IXSTQGYV.js";
237
+ } from "./chunk-RREI7CNM.js";
238
238
  import {
239
239
  PolicyRuntimeManager
240
240
  } from "./chunk-33JBK2XP.js";
@@ -314,7 +314,7 @@ import {
314
314
  } from "./chunk-FF4KLI5W.js";
315
315
  import {
316
316
  buildXraySnapshot
317
- } from "./chunk-CMZLMIZI.js";
317
+ } from "./chunk-BEMWL2FZ.js";
318
318
  import {
319
319
  NamespaceSearchRouter
320
320
  } from "./chunk-HRXCPKN4.js";
@@ -352,7 +352,7 @@ import {
352
352
  } from "./chunk-Y56J7CXW.js";
353
353
  import {
354
354
  buildChainFollowupGenerator
355
- } from "./chunk-J2KFC47S.js";
355
+ } from "./chunk-RFSCIBCB.js";
356
356
  import {
357
357
  ContentHashIndex,
358
358
  StorageManager,
@@ -362,7 +362,7 @@ import {
362
362
  normalizeEntityName,
363
363
  parseEntityFile,
364
364
  stripAttributesSuffix
365
- } from "./chunk-SHHT4JTC.js";
365
+ } from "./chunk-GYITUZFT.js";
366
366
  import {
367
367
  isValidTranscriptDate,
368
368
  loadSpeakerRegistry,
@@ -377,7 +377,7 @@ import {
377
377
  } from "./chunk-J6A3CX5N.js";
378
378
  import {
379
379
  confidenceTier
380
- } from "./chunk-3F7RMHC4.js";
380
+ } from "./chunk-C43KEWEV.js";
381
381
  import {
382
382
  inferMemoryStatus,
383
383
  isActiveMemoryStatus
@@ -1541,6 +1541,16 @@ function extractSnippet(body, index, matchLength) {
1541
1541
  }
1542
1542
 
1543
1543
  // src/orchestrator.ts
1544
+ var BulkImportBatchPartialFailureError = class extends Error {
1545
+ partialResult;
1546
+ originalError;
1547
+ constructor(message, partialResult, originalError) {
1548
+ super(message);
1549
+ this.name = "BulkImportBatchPartialFailureError";
1550
+ this.partialResult = partialResult;
1551
+ this.originalError = originalError;
1552
+ }
1553
+ };
1544
1554
  function dedupeEntitySynthesisEvidenceEntries(entries) {
1545
1555
  const dedupedEvidenceEntries = [];
1546
1556
  const evidenceByFact = /* @__PURE__ */ new Map();
@@ -1862,7 +1872,7 @@ function sortSourceValidAtSlicesChronologically(slices) {
1862
1872
  return a.order < b.order ? -1 : 1;
1863
1873
  }).map((slice) => slice.turns);
1864
1874
  }
1865
- function splitTurnsBySourceValidAt(turns) {
1875
+ function splitTurnsBySourceValidAt(turns, options = {}) {
1866
1876
  if (turns.length === 0) return [];
1867
1877
  if (!turns.some((turn) => sourceValidAtMs(turn) !== null)) {
1868
1878
  return [[...turns]];
@@ -1876,13 +1886,9 @@ function splitTurnsBySourceValidAt(turns) {
1876
1886
  while (end < turns.length && sourceValidAtSliceKey(turns[end], end) === activeKey) {
1877
1887
  end += 1;
1878
1888
  }
1889
+ const contextTurns = options.includeContext === false ? [] : sourceValidAtContextTurns(turns, start, end, targetValidAtMs);
1879
1890
  slices.push([
1880
- ...sourceValidAtContextTurns(
1881
- turns,
1882
- start,
1883
- end,
1884
- targetValidAtMs
1885
- ),
1891
+ ...contextTurns,
1886
1892
  ...turns.slice(start, end).map(asExtractionTargetTurn)
1887
1893
  ]);
1888
1894
  start = end;
@@ -9539,8 +9545,30 @@ _Context: ${topQuestion.context}_`
9539
9545
  * the CLI surface does not yet expose a `--namespace` flag.
9540
9546
  */
9541
9547
  async ingestBulkImportBatch(turns, options = {}) {
9542
- if (!Array.isArray(turns) || turns.length === 0) return;
9543
- const sessionKey = `bulk-import:batch:${Date.now().toString(36)}-` + randomBytes(6).toString("hex");
9548
+ if (!Array.isArray(turns) || turns.length === 0) {
9549
+ return {
9550
+ attemptedTurnCount: 0,
9551
+ extractionCount: 0,
9552
+ persistedCount: 0,
9553
+ durableOutputCount: 0,
9554
+ skippedCount: 0,
9555
+ failedCount: 0,
9556
+ postPersistMetadataFailureCount: 0,
9557
+ processedTurnCount: 0
9558
+ };
9559
+ }
9560
+ const shouldUseStableBatchKey = turns.some(
9561
+ (turn) => turn.persistProcessedFingerprint === true || typeof turn.turnFingerprint === "string" && turn.turnFingerprint.length > 0
9562
+ );
9563
+ const stableBatchFingerprint = shouldUseStableBatchKey ? createHash("sha256").update(
9564
+ turns.map(
9565
+ (turn) => [
9566
+ turn.role,
9567
+ typeof turn.turnFingerprint === "string" && turn.turnFingerprint.length > 0 ? turn.turnFingerprint : turn.content.replace(/\s+/g, " ").trim()
9568
+ ].join(":")
9569
+ ).join("\n")
9570
+ ).digest("hex").slice(0, 32) : void 0;
9571
+ const sessionKey = stableBatchFingerprint ? `bulk-import:batch:${stableBatchFingerprint}` : `bulk-import:batch:${Date.now().toString(36)}-${randomBytes(6).toString("hex")}`;
9544
9572
  const sessionTurns = [];
9545
9573
  for (const turn of turns) {
9546
9574
  if (turn.role !== "user" && turn.role !== "assistant") continue;
@@ -9553,10 +9581,23 @@ _Context: ${topQuestion.context}_`
9553
9581
  parts: turn.parts,
9554
9582
  rawContent: turn.rawContent,
9555
9583
  sourceFormat: turn.sourceFormat,
9556
- importProvenance: turn.importProvenance
9584
+ importProvenance: turn.importProvenance,
9585
+ turnFingerprint: turn.turnFingerprint,
9586
+ persistProcessedFingerprint: turn.persistProcessedFingerprint === true
9557
9587
  });
9558
9588
  }
9559
- if (sessionTurns.length === 0) return;
9589
+ if (sessionTurns.length === 0) {
9590
+ return {
9591
+ attemptedTurnCount: 0,
9592
+ extractionCount: 0,
9593
+ persistedCount: 0,
9594
+ durableOutputCount: 0,
9595
+ skippedCount: 0,
9596
+ failedCount: 0,
9597
+ postPersistMetadataFailureCount: 0,
9598
+ processedTurnCount: 0
9599
+ };
9600
+ }
9560
9601
  if (this.lcmEngine?.enabled) {
9561
9602
  await this.lcmEngine.observeMessages(
9562
9603
  sessionKey,
@@ -9569,27 +9610,75 @@ _Context: ${topQuestion.context}_`
9569
9610
  }))
9570
9611
  );
9571
9612
  }
9572
- const importTasks = splitTurnsBySourceValidAt(sessionTurns).map(
9573
- (sessionSlice) => new Promise((resolve, reject) => {
9574
- void this.queueBufferedExtraction(sessionSlice, "trigger_mode", {
9575
- skipDedupeCheck: true,
9576
- clearBufferAfterExtraction: false,
9577
- skipCharThreshold: true,
9578
- skipUserTurnThreshold: true,
9579
- bufferKey: sessionKey,
9580
- extractionDeadlineMs: options.deadlineMs,
9581
- writeNamespaceOverride: this.bulkImportWriteNamespace(),
9582
- onTaskSettled: (err) => err ? reject(err) : resolve()
9583
- }).catch(reject);
9584
- })
9585
- );
9586
- const settled = await Promise.allSettled(importTasks);
9587
- const firstRejected = settled.find(
9588
- (result) => result.status === "rejected"
9589
- );
9613
+ const sessionSlices = splitTurnsBySourceValidAt(sessionTurns, {
9614
+ includeContext: options.includeSourceValidAtContext !== false
9615
+ });
9616
+ const results = [];
9617
+ let processedTurnCount = 0;
9618
+ let firstRejected;
9619
+ for (const sessionSlice of sessionSlices) {
9620
+ try {
9621
+ const result = await new Promise(
9622
+ (resolve, reject) => {
9623
+ void this.queueBufferedExtraction(sessionSlice, "trigger_mode", {
9624
+ skipDedupeCheck: true,
9625
+ clearBufferAfterExtraction: false,
9626
+ skipCharThreshold: true,
9627
+ skipUserTurnThreshold: true,
9628
+ bufferKey: sessionKey,
9629
+ extractionDeadlineMs: options.deadlineMs,
9630
+ failOnExtractionFailure: options.failOnExtractionFailure === true,
9631
+ writeNamespaceOverride: this.bulkImportWriteNamespace(),
9632
+ onTaskSettled: (err, result2) => err ? reject(err) : resolve(
9633
+ result2 ?? {
9634
+ status: "skipped",
9635
+ reason: "missing_extraction_result",
9636
+ persistedCount: 0,
9637
+ durableOutputCount: 0
9638
+ }
9639
+ )
9640
+ }).catch(reject);
9641
+ }
9642
+ );
9643
+ results.push(result);
9644
+ processedTurnCount += sessionSlice.filter(
9645
+ (turn) => turn.extractionContextOnly !== true
9646
+ ).length;
9647
+ } catch (err) {
9648
+ firstRejected = err;
9649
+ break;
9650
+ }
9651
+ }
9652
+ const rejectedCount = firstRejected ? 1 : 0;
9653
+ const ingestResult = {
9654
+ attemptedTurnCount: sessionTurns.length,
9655
+ extractionCount: results.length,
9656
+ persistedCount: results.reduce(
9657
+ (sum, result) => sum + result.persistedCount,
9658
+ 0
9659
+ ),
9660
+ durableOutputCount: results.reduce(
9661
+ (sum, result) => sum + result.durableOutputCount,
9662
+ 0
9663
+ ),
9664
+ skippedCount: results.filter((result) => result.status === "skipped").length,
9665
+ failedCount: rejectedCount,
9666
+ postPersistMetadataFailureCount: results.filter(
9667
+ (result) => result.postPersistMetadataFailed === true
9668
+ ).length,
9669
+ processedTurnCount: rejectedCount === 0 ? sessionTurns.length : processedTurnCount
9670
+ };
9590
9671
  if (firstRejected) {
9591
- throw firstRejected.reason;
9672
+ if (processedTurnCount > 0) {
9673
+ throw new BulkImportBatchPartialFailureError(
9674
+ "bulk import failed after partial processing",
9675
+ ingestResult,
9676
+ firstRejected
9677
+ );
9678
+ }
9679
+ throw firstRejected;
9592
9680
  }
9681
+ return ingestResult;
9593
9682
  }
9594
9683
  async observeSessionHeartbeat(sessionKey, options = {}) {
9595
9684
  if (this.config.sessionObserverEnabled !== true) return;
@@ -9647,24 +9736,63 @@ _Context: ${topQuestion.context}_`
9647
9736
  const bufferKey = options.bufferKey ?? turnsToExtract[0]?.sessionKey ?? "default";
9648
9737
  if (!options.skipDedupeCheck && !this.shouldQueueExtraction(turnsToExtract, { bufferKey })) {
9649
9738
  log.debug(`extraction dedupe skip: preserving buffer (${reason})`);
9650
- options.onTaskSettled?.();
9739
+ options.onTaskSettled?.(void 0, {
9740
+ status: "skipped",
9741
+ reason: "dedupe",
9742
+ persistedCount: 0,
9743
+ durableOutputCount: 0
9744
+ });
9651
9745
  return;
9652
9746
  }
9747
+ const extractionDeadlineMs = typeof options.extractionDeadlineMs === "number" && Number.isFinite(options.extractionDeadlineMs) ? options.extractionDeadlineMs : void 0;
9748
+ let timeout;
9749
+ let settled = false;
9750
+ const clearQueueWaitTimer = () => {
9751
+ if (timeout) {
9752
+ clearTimeout(timeout);
9753
+ timeout = void 0;
9754
+ }
9755
+ };
9756
+ const settleTask = (error, result) => {
9757
+ if (settled) return false;
9758
+ settled = true;
9759
+ clearQueueWaitTimer();
9760
+ options.onTaskSettled?.(error, result);
9761
+ return true;
9762
+ };
9763
+ if (typeof extractionDeadlineMs === "number") {
9764
+ const remainingMs = extractionDeadlineMs - Date.now();
9765
+ if (remainingMs <= 0) {
9766
+ settleTask(new Error("replay extraction deadline exceeded (queue_wait)"));
9767
+ return;
9768
+ }
9769
+ timeout = setTimeout(() => {
9770
+ settleTask(new Error("replay extraction deadline exceeded (queue_wait)"));
9771
+ }, remainingMs);
9772
+ }
9653
9773
  this.extractionQueue.push(async () => {
9774
+ if (settled) return;
9775
+ if (typeof extractionDeadlineMs === "number" && extractionDeadlineMs <= Date.now()) {
9776
+ settleTask(new Error("replay extraction deadline exceeded (queue_wait)"));
9777
+ return;
9778
+ }
9779
+ clearQueueWaitTimer();
9654
9780
  try {
9655
- await this.runExtraction(turnsToExtract, {
9781
+ const result = await this.runExtraction(turnsToExtract, {
9656
9782
  clearBufferAfterExtraction: options.clearBufferAfterExtraction ?? true,
9657
9783
  skipCharThreshold: options.skipCharThreshold ?? false,
9658
9784
  skipUserTurnThreshold: options.skipUserTurnThreshold ?? false,
9659
- deadlineMs: options.extractionDeadlineMs,
9785
+ deadlineMs: extractionDeadlineMs,
9660
9786
  bufferKey,
9661
9787
  abortSignal: options.abortSignal,
9788
+ failOnExtractionFailure: options.failOnExtractionFailure === true,
9662
9789
  writeNamespaceOverride: options.writeNamespaceOverride
9663
9790
  });
9664
- options.onTaskSettled?.();
9791
+ settleTask(void 0, result);
9665
9792
  } catch (err) {
9666
- options.onTaskSettled?.(err);
9667
- throw err;
9793
+ if (settleTask(err)) {
9794
+ throw err;
9795
+ }
9668
9796
  }
9669
9797
  });
9670
9798
  if (!this.queueProcessing) {
@@ -9787,7 +9915,12 @@ ${normalized}`).digest("hex");
9787
9915
  if (sessionKey.includes(":cron:")) {
9788
9916
  log.debug(`skipping extraction for cron session: ${sessionKey}`);
9789
9917
  await clearBuffer();
9790
- return;
9918
+ return {
9919
+ status: "skipped",
9920
+ reason: "cron_session",
9921
+ persistedCount: 0,
9922
+ durableOutputCount: 0
9923
+ };
9791
9924
  }
9792
9925
  const normalizedTurns = turns.filter(
9793
9926
  (t) => (t.role === "user" || t.role === "assistant") && typeof t.content === "string"
@@ -9801,7 +9934,12 @@ ${normalized}`).digest("hex");
9801
9934
  if (targetTurns.length === 0) {
9802
9935
  log.debug("skipping extraction: no non-context turns after normalization");
9803
9936
  await clearBuffer();
9804
- return;
9937
+ return {
9938
+ status: "skipped",
9939
+ reason: "empty_normalized_turns",
9940
+ persistedCount: 0,
9941
+ durableOutputCount: 0
9942
+ };
9805
9943
  }
9806
9944
  const sourceValidAt = latestSourceValidAtFromTurns(targetTurns);
9807
9945
  throwIfDeadlineExceeded("before_extract");
@@ -9818,7 +9956,12 @@ ${normalized}`).digest("hex");
9818
9956
  `skipping extraction: below threshold (totalChars=${totalChars}, userTurns=${userTurns.length})`
9819
9957
  );
9820
9958
  await clearBuffer();
9821
- return;
9959
+ return {
9960
+ status: "skipped",
9961
+ reason: "below_threshold",
9962
+ persistedCount: 0,
9963
+ durableOutputCount: 0
9964
+ };
9822
9965
  }
9823
9966
  const principal = resolvePrincipal(sessionKey, this.config);
9824
9967
  const selfNamespace = typeof options.writeNamespaceOverride === "string" && options.writeNamespaceOverride.length > 0 ? options.writeNamespaceOverride : this.applyCodingNamespaceOverlay(
@@ -9841,7 +9984,12 @@ ${normalized}`).digest("hex");
9841
9984
  `runExtraction: skipping already-processed extraction fingerprint for ${bufferKey}`
9842
9985
  );
9843
9986
  await clearBuffer();
9844
- return;
9987
+ return {
9988
+ status: "skipped",
9989
+ reason: "processed_fingerprint",
9990
+ persistedCount: 0,
9991
+ durableOutputCount: 0
9992
+ };
9845
9993
  }
9846
9994
  const existingEntities = await storage.listEntityNames();
9847
9995
  const result = await raceRecallAbort(
@@ -9856,23 +10004,74 @@ ${normalized}`).digest("hex");
9856
10004
  throwIfAborted2("before_persist");
9857
10005
  if (!result) {
9858
10006
  log.warn("runExtraction: extraction returned null/undefined");
10007
+ if (options.failOnExtractionFailure) {
10008
+ throw new Error("extraction failed: invalid_extraction_result");
10009
+ }
9859
10010
  await clearBuffer();
9860
- return;
10011
+ return {
10012
+ status: "skipped",
10013
+ reason: "invalid_extraction_result",
10014
+ persistedCount: 0,
10015
+ durableOutputCount: 0
10016
+ };
9861
10017
  }
9862
- if (!Array.isArray(result.facts)) {
10018
+ const invalidExtractionResultFields = [
10019
+ ["facts", result.facts],
10020
+ ["entities", result.entities],
10021
+ ["questions", result.questions],
10022
+ ["profileUpdates", result.profileUpdates]
10023
+ ].filter(([, value]) => !Array.isArray(value)).map(([field]) => field);
10024
+ if (invalidExtractionResultFields.length > 0) {
9863
10025
  log.warn(
9864
- "runExtraction: extraction returned invalid facts (not an array)",
9865
- { factsType: typeof result.facts, resultKeys: Object.keys(result) }
10026
+ "runExtraction: extraction returned invalid collection fields",
10027
+ {
10028
+ invalidFields: invalidExtractionResultFields,
10029
+ resultKeys: typeof result === "object" && result !== null ? Object.keys(result) : []
10030
+ }
9866
10031
  );
10032
+ if (options.failOnExtractionFailure) {
10033
+ throw new Error("extraction failed: invalid_extraction_result");
10034
+ }
9867
10035
  await clearBuffer();
9868
- return;
10036
+ return {
10037
+ status: "skipped",
10038
+ reason: "invalid_extraction_result",
10039
+ persistedCount: 0,
10040
+ durableOutputCount: 0
10041
+ };
10042
+ }
10043
+ const extractionFailure = typeof result.extractionFailure === "string" && result.extractionFailure.trim().length > 0 ? result.extractionFailure : void 0;
10044
+ if (options.failOnExtractionFailure && extractionFailure) {
10045
+ throw new Error(`extraction failed: ${extractionFailure}`);
9869
10046
  }
9870
10047
  if (result.facts.length === 0 && result.entities.length === 0 && result.questions.length === 0 && result.profileUpdates.length === 0) {
9871
10048
  log.debug(
9872
10049
  "runExtraction: extraction produced no durable outputs; skipping persistence"
9873
10050
  );
10051
+ if (extractionFailure) {
10052
+ log.warn(
10053
+ "runExtraction: extraction reported failure with no durable outputs; not marking fingerprint processed",
10054
+ { extractionFailure }
10055
+ );
10056
+ }
10057
+ if (extractionFingerprint && shouldPersistProcessedFingerprint && !extractionFailure) {
10058
+ meta ??= await storage.loadMeta();
10059
+ await this.recordProcessedExtractionFingerprint(
10060
+ storage,
10061
+ extractionFingerprint,
10062
+ meta
10063
+ );
10064
+ meta.extractionCount += 1;
10065
+ meta.lastExtractionAt = (/* @__PURE__ */ new Date()).toISOString();
10066
+ await storage.saveMeta(meta);
10067
+ }
9874
10068
  await clearBuffer();
9875
- return;
10069
+ return {
10070
+ status: "skipped",
10071
+ reason: "empty_extraction_result",
10072
+ persistedCount: 0,
10073
+ durableOutputCount: 0
10074
+ };
9876
10075
  }
9877
10076
  let threadIdForExtraction = null;
9878
10077
  if (this.config.threadingEnabled && turns.length > 0) {
@@ -9892,6 +10091,7 @@ ${normalized}`).digest("hex");
9892
10091
  threadIdForExtraction,
9893
10092
  { sessionKey, principal, validAt: sourceValidAt }
9894
10093
  );
10094
+ let postPersistMetadataFailed = false;
9895
10095
  meta ??= await storage.loadMeta();
9896
10096
  if (extractionFingerprint && shouldPersistProcessedFingerprint) {
9897
10097
  try {
@@ -9905,18 +10105,23 @@ ${normalized}`).digest("hex");
9905
10105
  "runExtraction: failed to persist processed extraction fingerprint; continuing with buffer clear",
9906
10106
  error
9907
10107
  );
10108
+ postPersistMetadataFailed = true;
9908
10109
  }
9909
10110
  }
9910
10111
  meta.extractionCount += 1;
9911
10112
  meta.lastExtractionAt = (/* @__PURE__ */ new Date()).toISOString();
9912
10113
  meta.totalMemories += Array.isArray(result?.facts) ? result.facts.length : 0;
9913
10114
  meta.totalEntities += Array.isArray(result?.entities) ? result.entities.length : 0;
9914
- let postPersistMetaError;
9915
10115
  try {
9916
10116
  await storage.saveMeta(meta);
9917
10117
  } catch (error) {
9918
- postPersistMetaError = error;
10118
+ log.warn(
10119
+ "runExtraction: failed to save extraction metadata after durable persistence; continuing with buffer clear",
10120
+ error
10121
+ );
10122
+ postPersistMetadataFailed = true;
9919
10123
  }
10124
+ const durableOutputCount = result.facts.length + result.entities.length + result.questions.length + result.profileUpdates.length;
9920
10125
  try {
9921
10126
  if (clearBufferAfterExtraction && !this.config.extractionJudgeShadow) {
9922
10127
  const deferredCount = this.lastPersistExtractionDeferredCount;
@@ -9964,19 +10169,50 @@ ${normalized}`).digest("hex");
9964
10169
  }
9965
10170
  if (this.config.threadingEnabled && threadIdForExtraction) {
9966
10171
  const conversationContent = turns.map((t) => t.content).join(" ");
9967
- await this.threading.updateThreadTitle(
9968
- threadIdForExtraction,
9969
- conversationContent
10172
+ try {
10173
+ await this.threading.updateThreadTitle(
10174
+ threadIdForExtraction,
10175
+ conversationContent
10176
+ );
10177
+ } catch (err) {
10178
+ log.warn(
10179
+ "[threading] updateThreadTitle failed after persistence (non-fatal)",
10180
+ err
10181
+ );
10182
+ }
10183
+ }
10184
+ const nonZeroExtraction = durableOutputCount > 0;
10185
+ try {
10186
+ if (nonZeroExtraction) this.nonZeroExtractionsSinceConsolidation += 1;
10187
+ this.maybeScheduleConsolidation(nonZeroExtraction);
10188
+ } catch (err) {
10189
+ log.warn(
10190
+ "runExtraction: consolidation scheduling failed after persistence (non-fatal)",
10191
+ err
9970
10192
  );
9971
10193
  }
9972
- const nonZeroExtraction = result.facts.length > 0 || result.entities.length > 0 || result.questions.length > 0 || result.profileUpdates.length > 0;
9973
- if (nonZeroExtraction) this.nonZeroExtractionsSinceConsolidation += 1;
9974
- this.maybeScheduleConsolidation(nonZeroExtraction);
9975
- this.requestQmdMaintenance();
9976
- await this.runTierMigrationCycle(storage, "extraction");
9977
- if (postPersistMetaError) {
9978
- throw postPersistMetaError;
10194
+ try {
10195
+ this.requestQmdMaintenance();
10196
+ } catch (err) {
10197
+ log.warn(
10198
+ "runExtraction: QMD maintenance scheduling failed after persistence (non-fatal)",
10199
+ err
10200
+ );
9979
10201
  }
10202
+ try {
10203
+ await this.runTierMigrationCycle(storage, "extraction");
10204
+ } catch (err) {
10205
+ log.warn(
10206
+ "runExtraction: tier migration failed after persistence (non-fatal)",
10207
+ err
10208
+ );
10209
+ }
10210
+ return {
10211
+ status: "completed",
10212
+ persistedCount: persistedIds.length,
10213
+ durableOutputCount,
10214
+ postPersistMetadataFailed
10215
+ };
9980
10216
  }
9981
10217
  async recordProcessedExtractionFingerprint(storage, fingerprint, preloadedMeta) {
9982
10218
  const meta = preloadedMeta ?? await storage.loadMeta();
@@ -14036,6 +14272,7 @@ export {
14036
14272
  ensureBuiltInWearableConnectors,
14037
14273
  WearablesService,
14038
14274
  locateTranscriptPath,
14275
+ BulkImportBatchPartialFailureError,
14039
14276
  dedupeEntitySynthesisEvidenceEntries,
14040
14277
  defaultWorkspaceDir,
14041
14278
  sanitizeSessionKeyForFilename,
@@ -14065,4 +14302,4 @@ export {
14065
14302
  resolvePersistedMemoryRelativePath,
14066
14303
  Orchestrator
14067
14304
  };
14068
- //# sourceMappingURL=chunk-WAKPKNEX.js.map
14305
+ //# sourceMappingURL=chunk-3UR4SBZF.js.map