@remnic/core 10.0.38 → 10.0.39

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 (416) hide show
  1. package/dist/access-admin-ops-surface.js +73 -73
  2. package/dist/access-audit.js +2 -2
  3. package/dist/access-authorization-probe.js +74 -74
  4. package/dist/access-boundary.js +73 -73
  5. package/dist/access-citation-namespace.js +2 -2
  6. package/dist/access-cli.js +161 -160
  7. package/dist/access-cli.js.map +1 -1
  8. package/dist/access-extraction-force-flush.js +73 -73
  9. package/dist/access-http-briefing.js +74 -74
  10. package/dist/access-http-query.js +75 -75
  11. package/dist/access-http.js +98 -98
  12. package/dist/access-identity-continuity-surface.js +73 -73
  13. package/dist/access-lcm-surface.js +73 -73
  14. package/dist/access-mcp.js +87 -87
  15. package/dist/access-namespace-preflight.js +73 -73
  16. package/dist/access-observe-write-category.js +15 -15
  17. package/dist/access-observe-write-surface.js +73 -73
  18. package/dist/access-offline-manifest.js +12 -12
  19. package/dist/access-operations-batch.js +77 -77
  20. package/dist/access-operations.js +84 -84
  21. package/dist/access-recall-concurrency.js +73 -73
  22. package/dist/access-recall-diagnostics.js +2 -2
  23. package/dist/access-recall-response.js +73 -73
  24. package/dist/access-recall-surface.js +73 -73
  25. package/dist/access-schema.js +10 -10
  26. package/dist/access-service.js +73 -73
  27. package/dist/access-surface-catalog.js +75 -75
  28. package/dist/active-recall.js +29 -29
  29. package/dist/adapters/index.js +4 -4
  30. package/dist/adapters/registry.js +2 -2
  31. package/dist/{auto-sync-432USQDH.js → auto-sync-BNCBMU6H.js} +7 -7
  32. package/dist/briefing.js +19 -19
  33. package/dist/buffer-types.d.ts +59 -0
  34. package/dist/buffer-types.d.ts.map +1 -0
  35. package/dist/buffer-types.js +1 -0
  36. package/dist/buffer.d.ts +14 -22
  37. package/dist/buffer.d.ts.map +1 -1
  38. package/dist/buffer.js +11 -11
  39. package/dist/calibration.js +2 -2
  40. package/dist/{capsule-crypto-7FJQINUR.js → capsule-crypto-GWVG7LGC.js} +2 -2
  41. package/dist/causal-behavior.js +2 -2
  42. package/dist/causal-chain.js +2 -2
  43. package/dist/causal-consolidation.js +22 -22
  44. package/dist/causal-retrieval.js +2 -2
  45. package/dist/causal-trajectory-graph.js +2 -2
  46. package/dist/causal-trajectory.js +1 -1
  47. package/dist/{chunk-5K23NQRI.js → chunk-22YJQTPN.js} +2 -2
  48. package/dist/{chunk-MKE5DP3S.js → chunk-23ZMQONL.js} +2 -2
  49. package/dist/{chunk-3K5IEJTK.js → chunk-2AV2U2SZ.js} +3 -3
  50. package/dist/{chunk-HJ3UTGIW.js → chunk-2JNBPOZ2.js} +3 -3
  51. package/dist/{chunk-EEOYF3IB.js → chunk-3RJDYZJE.js} +2 -2
  52. package/dist/{chunk-SZPPCEYT.js → chunk-4HJ2QK32.js} +2 -2
  53. package/dist/{chunk-OLHN4ZNT.js → chunk-4LLV2N3R.js} +3 -3
  54. package/dist/{chunk-P5CUEB2Q.js → chunk-4QLKVZH6.js} +8 -8
  55. package/dist/{chunk-4IZ6AC2U.js → chunk-4UT2NUAC.js} +2 -2
  56. package/dist/{chunk-WCBLPKG3.js → chunk-5KZNWERU.js} +155 -142
  57. package/dist/chunk-5KZNWERU.js.map +1 -0
  58. package/dist/{chunk-VC3X7XP3.js → chunk-5Q6CR65T.js} +2 -2
  59. package/dist/{chunk-XTBEXZFN.js → chunk-5SF7JOJB.js} +4 -4
  60. package/dist/{chunk-DKHX2FHI.js → chunk-64WHWIPL.js} +2 -2
  61. package/dist/{chunk-TVIGN3XZ.js → chunk-6FRFVIKC.js} +10 -10
  62. package/dist/{chunk-JIA435P3.js → chunk-6ITNEPJO.js} +2 -2
  63. package/dist/{chunk-WEK3OUGO.js → chunk-6X3J4NLZ.js} +10 -5
  64. package/dist/chunk-6X3J4NLZ.js.map +1 -0
  65. package/dist/{chunk-3AODCBKX.js → chunk-6Z2ZWBOV.js} +6 -6
  66. package/dist/{chunk-TAEJ2MRR.js → chunk-7IANFJ24.js} +56 -56
  67. package/dist/{chunk-PSQ2P2T3.js → chunk-7XZ7TOLQ.js} +3 -3
  68. package/dist/{chunk-6JEEY42N.js → chunk-AER3HD3B.js} +2 -2
  69. package/dist/{chunk-4B37KNMP.js → chunk-ANV373S5.js} +2 -2
  70. package/dist/{chunk-AYBAC2N4.js → chunk-B3I2QQU7.js} +3 -3
  71. package/dist/{chunk-TYLNWE4D.js → chunk-B7VKRCAG.js} +2 -2
  72. package/dist/{chunk-HXFIILGF.js → chunk-BFPF5N3H.js} +4 -4
  73. package/dist/{chunk-KQAFEZQX.js → chunk-BUKK5SWA.js} +2 -2
  74. package/dist/{chunk-53BLBDV6.js → chunk-BUKZ7MTN.js} +2 -2
  75. package/dist/{chunk-MCPSMWUC.js → chunk-CR72WZ3M.js} +9 -9
  76. package/dist/{chunk-YC2C67F7.js → chunk-CRXGQRNA.js} +3 -3
  77. package/dist/{chunk-WRDFYSUC.js → chunk-CZVNOTLR.js} +2 -2
  78. package/dist/{chunk-VPO53QMG.js → chunk-D6DOLQYK.js} +2 -2
  79. package/dist/{chunk-RGKXF4W3.js → chunk-E5IEI2MR.js} +2 -2
  80. package/dist/{chunk-Z2T5BPOZ.js → chunk-EIYJK7OD.js} +2 -2
  81. package/dist/{chunk-FRAL3EU4.js → chunk-EKPRLTAE.js} +2 -2
  82. package/dist/{chunk-C2KOW2UQ.js → chunk-EKR6OO4P.js} +2 -2
  83. package/dist/{chunk-TYGLV6ZG.js → chunk-EYGOM6AI.js} +2 -2
  84. package/dist/{chunk-TYGLV6ZG.js.map → chunk-EYGOM6AI.js.map} +1 -1
  85. package/dist/{chunk-SWZOAQUM.js → chunk-F2IU6A2L.js} +57 -57
  86. package/dist/{chunk-2AKIVSHP.js → chunk-FAKRTS3Y.js} +2 -2
  87. package/dist/{chunk-MZWHIAOL.js → chunk-FC3ZFEXF.js} +2 -2
  88. package/dist/{chunk-3PLAL2KP.js → chunk-FJ264QBP.js} +17 -9
  89. package/dist/chunk-FJ264QBP.js.map +1 -0
  90. package/dist/{chunk-7VFNGQ4V.js → chunk-FLDXEJFX.js} +2 -2
  91. package/dist/{chunk-JH4FCVWJ.js → chunk-G6OFEGUR.js} +2 -2
  92. package/dist/{chunk-L7PGPH4E.js → chunk-GCW7UT5I.js} +2 -2
  93. package/dist/{chunk-J7G656MY.js → chunk-GE5ZNDLE.js} +4 -4
  94. package/dist/{chunk-63YPKHAU.js → chunk-GLB6VV3J.js} +2 -2
  95. package/dist/{chunk-6F5BGIAF.js → chunk-GPVGAHXL.js} +3 -3
  96. package/dist/{chunk-XHX67LX6.js → chunk-GSBSGT43.js} +2 -2
  97. package/dist/{chunk-645WOU5I.js → chunk-H7BZBSP6.js} +4 -4
  98. package/dist/{chunk-GFYFKXWZ.js → chunk-HUDPXTXW.js} +2 -2
  99. package/dist/{chunk-L2JQSG5M.js → chunk-I7TR2OCU.js} +2 -2
  100. package/dist/{chunk-6SYS5YX3.js → chunk-IAOW2L6K.js} +2 -2
  101. package/dist/{chunk-STM4T335.js → chunk-IJH6METJ.js} +2 -2
  102. package/dist/{chunk-3XVBGGF3.js → chunk-IZRNMXZC.js} +2 -2
  103. package/dist/{chunk-XHVO3CGX.js → chunk-JGS55BAS.js} +53 -2
  104. package/dist/chunk-JGS55BAS.js.map +1 -0
  105. package/dist/{chunk-Y5ZHZKZD.js → chunk-JM6U3SAE.js} +2 -2
  106. package/dist/{chunk-74AY3S7U.js → chunk-JNLYHJG7.js} +4 -4
  107. package/dist/{chunk-QOUKZ2N3.js → chunk-JOOGPZJE.js} +2 -2
  108. package/dist/{chunk-EGNONTVT.js → chunk-JORSMFL6.js} +6 -6
  109. package/dist/{chunk-JF3MEIHO.js → chunk-JQCP5QW3.js} +4 -4
  110. package/dist/{chunk-POGPI5GR.js → chunk-JRTKYFFY.js} +2 -2
  111. package/dist/{chunk-5UPOKIFP.js → chunk-JT3IXJIL.js} +12 -12
  112. package/dist/{chunk-6DTIYAAN.js → chunk-JZFJZLJY.js} +2 -2
  113. package/dist/{chunk-6QOL4G76.js → chunk-KQXRVELF.js} +2 -2
  114. package/dist/{chunk-KOAVX2IT.js → chunk-L74NWAD4.js} +2 -2
  115. package/dist/{chunk-5DCS4C4S.js → chunk-LJXBFVI2.js} +4 -4
  116. package/dist/{chunk-OKKBOTRA.js → chunk-LPD6I2U6.js} +2 -2
  117. package/dist/{chunk-N7DVBHU3.js → chunk-LR7RW4T6.js} +3 -3
  118. package/dist/{chunk-FZVZYU5C.js → chunk-LXN737FX.js} +2 -2
  119. package/dist/{chunk-LOMSBYNS.js → chunk-MD3W2H3G.js} +298 -95
  120. package/dist/chunk-MD3W2H3G.js.map +1 -0
  121. package/dist/{chunk-7ZRRJ6RG.js → chunk-MGYZENUY.js} +2 -2
  122. package/dist/{chunk-YQ6SLFNZ.js → chunk-MPJDQC4G.js} +3 -3
  123. package/dist/{chunk-5ANUG4JZ.js → chunk-NJ2DZYEK.js} +2 -2
  124. package/dist/{chunk-OLH4XCLU.js → chunk-O2O4FDAH.js} +2 -2
  125. package/dist/{chunk-CVMAOPAH.js → chunk-ODJ2HRFW.js} +10 -10
  126. package/dist/{chunk-2NLLXCJG.js → chunk-OWHERGF2.js} +2 -2
  127. package/dist/{chunk-I73ZSORJ.js → chunk-OXSTKCYK.js} +4 -4
  128. package/dist/{chunk-RWRHGE75.js → chunk-P3YUEPSQ.js} +2 -2
  129. package/dist/{chunk-UFM3PJDT.js → chunk-PARM6OYL.js} +1 -1
  130. package/dist/chunk-PARM6OYL.js.map +1 -0
  131. package/dist/{chunk-TPKB7T6Z.js → chunk-Q6UZREJK.js} +2 -2
  132. package/dist/{chunk-UJDTXWMT.js → chunk-QIMGULGN.js} +2 -2
  133. package/dist/{chunk-E24RUQEN.js → chunk-QNIYL5SK.js} +2 -2
  134. package/dist/{chunk-KOY25HUB.js → chunk-QYAXMXOB.js} +2 -2
  135. package/dist/{chunk-X247CYL6.js → chunk-RIAKNXZB.js} +4 -4
  136. package/dist/{chunk-WCIDCJOQ.js → chunk-RO2NNWR5.js} +3 -3
  137. package/dist/{chunk-AYXRK264.js → chunk-RROFIAYI.js} +9 -9
  138. package/dist/{chunk-YYGZ4EIY.js → chunk-RUAIO5UA.js} +2 -2
  139. package/dist/{chunk-FQFMLOAC.js → chunk-RWW5KPIY.js} +18 -18
  140. package/dist/{chunk-E5PVMB3I.js → chunk-SDXBR5QO.js} +2 -2
  141. package/dist/{chunk-NH6GZEQN.js → chunk-SJHFU52W.js} +8 -8
  142. package/dist/{chunk-FGEY2AGV.js → chunk-SRPGA6WN.js} +2 -2
  143. package/dist/{chunk-CUWOSRCS.js → chunk-SUKPM6DV.js} +2 -2
  144. package/dist/{chunk-TXP7Q7T5.js → chunk-TTQYX7VU.js} +2 -2
  145. package/dist/{chunk-TDCR6PQL.js → chunk-TWRPWJJT.js} +2 -2
  146. package/dist/{chunk-I75BWXRZ.js → chunk-U66CTIF5.js} +2 -2
  147. package/dist/{chunk-DG4H56SK.js → chunk-UIK3U36O.js} +2 -2
  148. package/dist/{chunk-XLEP7SS3.js → chunk-UMSH4I3E.js} +2 -2
  149. package/dist/{chunk-X7Y7WX73.js → chunk-UVYI6VIX.js} +1 -1
  150. package/dist/{chunk-LHBOFROT.js → chunk-V2XMG7GM.js} +2 -2
  151. package/dist/chunk-VA3GNAWQ.js +58 -0
  152. package/dist/chunk-VA3GNAWQ.js.map +1 -0
  153. package/dist/{chunk-ZAP7BKTZ.js → chunk-VCOCOBUS.js} +6 -6
  154. package/dist/{chunk-4P4VLPGB.js → chunk-VECRSYQG.js} +1 -1
  155. package/dist/{chunk-GGI6FLO6.js → chunk-VHBGJAYC.js} +2 -2
  156. package/dist/{chunk-QO5KDQGG.js → chunk-VIS23B6O.js} +7 -7
  157. package/dist/{chunk-NMKETOAX.js → chunk-VSHWPOUB.js} +2 -2
  158. package/dist/{chunk-UBN5AOLT.js → chunk-W5EO4USJ.js} +2 -2
  159. package/dist/{chunk-Y7427SL7.js → chunk-WCGJK4NQ.js} +4 -4
  160. package/dist/{chunk-7HXZOWTR.js → chunk-WQYS47G4.js} +2 -2
  161. package/dist/{chunk-JH2ALMPR.js → chunk-WR5POHQ3.js} +2 -2
  162. package/dist/{chunk-VSSQIBVU.js → chunk-WT2VVYBM.js} +2 -2
  163. package/dist/{chunk-EHIKY2IA.js → chunk-WU5WTCH5.js} +2 -2
  164. package/dist/{chunk-QKXPOLQD.js → chunk-WUBGMV3G.js} +6 -6
  165. package/dist/{chunk-FKTMWDN2.js → chunk-WUL6LDJ4.js} +2 -2
  166. package/dist/{chunk-U7HJBODU.js → chunk-XKTHJHSQ.js} +5 -5
  167. package/dist/{chunk-JFI3ATK4.js → chunk-XMYWYJM2.js} +2 -2
  168. package/dist/{chunk-64S6X4IU.js → chunk-XTN54NML.js} +4 -4
  169. package/dist/{chunk-VGFNTY3Y.js → chunk-YFXRLRKP.js} +2 -2
  170. package/dist/{chunk-DAOMWGO2.js → chunk-ZX5N5D6M.js} +4 -4
  171. package/dist/{chunk-VGRM43X6.js → chunk-ZXFKG7VZ.js} +2 -2
  172. package/dist/cli.js +121 -121
  173. package/dist/coding/export-okf-codegraph.js +20 -20
  174. package/dist/coding/pre-action-gate.js +2 -2
  175. package/dist/compounding/engine.js +21 -21
  176. package/dist/config.d.ts.map +1 -1
  177. package/dist/config.js +29 -29
  178. package/dist/connectors/codex-materialize-runner.js +19 -19
  179. package/dist/connectors/index.js +19 -19
  180. package/dist/contradiction/index.js +5 -5
  181. package/dist/convergence-refresh.js +21 -21
  182. package/dist/corpus-watermark.js +21 -21
  183. package/dist/deep-recall-http-glue.js +11 -11
  184. package/dist/deep-recall.js +2 -2
  185. package/dist/entity-retrieval.js +20 -20
  186. package/dist/event-order-recall.js +2 -2
  187. package/dist/explicit-capture.js +6 -6
  188. package/dist/external-wiki-access.js +74 -74
  189. package/dist/extraction-window-drain.d.ts +48 -0
  190. package/dist/extraction-window-drain.d.ts.map +1 -0
  191. package/dist/extraction-window-drain.js +14 -0
  192. package/dist/extraction.js +27 -27
  193. package/dist/{graph-edge-decay-2BZTY2IM.js → graph-edge-decay-3HVLMT6U.js} +5 -5
  194. package/dist/graph-edge-decay-3HVLMT6U.js.map +1 -0
  195. package/dist/graph-jsonl.js +3 -3
  196. package/dist/graph-snapshot.js +3 -3
  197. package/dist/graph.js +4 -4
  198. package/dist/harmonic-retrieval.js +20 -20
  199. package/dist/harmonic-source-lookup.js +2 -2
  200. package/dist/index.js +208 -207
  201. package/dist/lcm/engine.js +2 -2
  202. package/dist/lcm/index.js +7 -7
  203. package/dist/local-llm.js +2 -2
  204. package/dist/location/index.js +22 -22
  205. package/dist/maintenance/memory-governance.js +19 -19
  206. package/dist/maintenance/rebuild-memory-lifecycle-ledger.js +19 -19
  207. package/dist/maintenance/rebuild-memory-projection-runner.js +21 -21
  208. package/dist/maintenance/rebuild-memory-projection.js +20 -20
  209. package/dist/memory-browse-operations.js +74 -74
  210. package/dist/memory-browse.js +6 -6
  211. package/dist/memory-subject.js +3 -3
  212. package/dist/namespaces/migrate.js +20 -20
  213. package/dist/namespaces/search.js +7 -7
  214. package/dist/namespaces/storage.js +19 -19
  215. package/dist/offline-sync-changeset-generations.js +3 -3
  216. package/dist/offline-sync-embedding-generation.js +2 -2
  217. package/dist/offline-sync-file-io.js +2 -2
  218. package/dist/offline-sync-impression-drain.js +3 -3
  219. package/dist/offline-sync-snapshot-stream.js +8 -8
  220. package/dist/offline-sync-upload-staging.js +3 -3
  221. package/dist/offline-sync.js +9 -9
  222. package/dist/operator-doctor-corpus.js +22 -22
  223. package/dist/operator-toolkit.js +40 -40
  224. package/dist/orchestration/extraction-drain.d.ts +90 -0
  225. package/dist/orchestration/extraction-drain.d.ts.map +1 -0
  226. package/dist/orchestration/extraction-run-helpers.d.ts +3 -0
  227. package/dist/orchestration/extraction-run-helpers.d.ts.map +1 -1
  228. package/dist/orchestration/extraction-run.d.ts +4 -1
  229. package/dist/orchestration/extraction-run.d.ts.map +1 -1
  230. package/dist/orchestration/maintenance.js +33 -33
  231. package/dist/orchestration/turn-ingestion.d.ts +3 -0
  232. package/dist/orchestration/turn-ingestion.d.ts.map +1 -1
  233. package/dist/orchestrator.d.ts +8 -0
  234. package/dist/orchestrator.d.ts.map +1 -1
  235. package/dist/orchestrator.js +161 -160
  236. package/dist/qmd.js +5 -5
  237. package/dist/recall-explain-renderer.js +3 -3
  238. package/dist/recall-navigate-access.js +2 -2
  239. package/dist/recall-navigate-disclosure.js +2 -2
  240. package/dist/recall-navigate.js +2 -2
  241. package/dist/recall-navigation-operations.js +74 -74
  242. package/dist/recall-navigation.js +73 -73
  243. package/dist/recall-state-view-admission.js +6 -6
  244. package/dist/recall-why-service.js +6 -6
  245. package/dist/recall-xray-cli.js +4 -4
  246. package/dist/recall-xray-renderer.js +3 -3
  247. package/dist/recall-xray.js +2 -2
  248. package/dist/reconcile/manifest.js +3 -3
  249. package/dist/{resolution-4ZEQPXUZ.js → resolution-NNYG37YB.js} +6 -6
  250. package/dist/resolution-NNYG37YB.js.map +1 -0
  251. package/dist/resume-bundles.js +30 -30
  252. package/dist/retrieval-agents.js +2 -2
  253. package/dist/salvage-envelope.js +5 -5
  254. package/dist/search/factory.js +6 -6
  255. package/dist/search/index.js +10 -10
  256. package/dist/secure-store/index.js +2 -2
  257. package/dist/semantic-consolidation.js +20 -20
  258. package/dist/semantic-rule-promotion.js +19 -19
  259. package/dist/semantic-rule-verifier.js +19 -19
  260. package/dist/source-agent-qualifier.js +23 -23
  261. package/dist/standup/build.js +19 -19
  262. package/dist/storage/dropped-extraction-chunk.d.ts +8 -0
  263. package/dist/storage/dropped-extraction-chunk.d.ts.map +1 -0
  264. package/dist/storage.d.ts +1 -0
  265. package/dist/storage.d.ts.map +1 -1
  266. package/dist/storage.js +18 -18
  267. package/dist/subject-config.js +4 -4
  268. package/dist/summarizer.js +3 -3
  269. package/dist/support-passport/index.js +76 -76
  270. package/dist/transfer/backup.js +2 -2
  271. package/dist/transfer/capsule-export.js +2 -2
  272. package/dist/transfer/capsule-import.js +2 -2
  273. package/dist/transfer/export-okf.js +20 -20
  274. package/dist/types.d.ts +7 -0
  275. package/dist/types.d.ts.map +1 -1
  276. package/dist/types.js +1 -1
  277. package/dist/verified-recall.js +19 -19
  278. package/dist/who-knows-cli.js +20 -20
  279. package/dist/who-knows.js +19 -19
  280. package/dist/write-envelope.js +4 -4
  281. package/package.json +2 -2
  282. package/src/buffer-drop-extraction-chunk.test.ts +196 -0
  283. package/src/buffer-types.ts +65 -0
  284. package/src/buffer.ts +60 -62
  285. package/src/config.ts +8 -0
  286. package/src/extraction-window-drain.test.ts +123 -0
  287. package/src/extraction-window-drain.ts +110 -0
  288. package/src/orchestration/extraction-drain.ts +261 -0
  289. package/src/orchestration/extraction-run-helpers.ts +8 -0
  290. package/src/orchestration/extraction-run.ts +5 -4
  291. package/src/orchestration/turn-ingestion.ts +9 -5
  292. package/src/orchestrator.ts +21 -0
  293. package/src/secure-store/secure-fs.ts +3 -1
  294. package/src/storage/dropped-extraction-chunk.ts +27 -0
  295. package/src/storage-dropped-chunk-filenames.test.ts +30 -0
  296. package/src/storage.ts +6 -7
  297. package/src/types.ts +7 -0
  298. package/dist/chunk-3PLAL2KP.js.map +0 -1
  299. package/dist/chunk-LOMSBYNS.js.map +0 -1
  300. package/dist/chunk-UFM3PJDT.js.map +0 -1
  301. package/dist/chunk-WCBLPKG3.js.map +0 -1
  302. package/dist/chunk-WEK3OUGO.js.map +0 -1
  303. package/dist/chunk-XHVO3CGX.js.map +0 -1
  304. /package/dist/{auto-sync-432USQDH.js.map → auto-sync-BNCBMU6H.js.map} +0 -0
  305. /package/dist/{capsule-crypto-7FJQINUR.js.map → buffer-types.js.map} +0 -0
  306. /package/dist/{graph-edge-decay-2BZTY2IM.js.map → capsule-crypto-GWVG7LGC.js.map} +0 -0
  307. /package/dist/{chunk-5K23NQRI.js.map → chunk-22YJQTPN.js.map} +0 -0
  308. /package/dist/{chunk-MKE5DP3S.js.map → chunk-23ZMQONL.js.map} +0 -0
  309. /package/dist/{chunk-3K5IEJTK.js.map → chunk-2AV2U2SZ.js.map} +0 -0
  310. /package/dist/{chunk-HJ3UTGIW.js.map → chunk-2JNBPOZ2.js.map} +0 -0
  311. /package/dist/{chunk-EEOYF3IB.js.map → chunk-3RJDYZJE.js.map} +0 -0
  312. /package/dist/{chunk-SZPPCEYT.js.map → chunk-4HJ2QK32.js.map} +0 -0
  313. /package/dist/{chunk-OLHN4ZNT.js.map → chunk-4LLV2N3R.js.map} +0 -0
  314. /package/dist/{chunk-P5CUEB2Q.js.map → chunk-4QLKVZH6.js.map} +0 -0
  315. /package/dist/{chunk-4IZ6AC2U.js.map → chunk-4UT2NUAC.js.map} +0 -0
  316. /package/dist/{chunk-VC3X7XP3.js.map → chunk-5Q6CR65T.js.map} +0 -0
  317. /package/dist/{chunk-XTBEXZFN.js.map → chunk-5SF7JOJB.js.map} +0 -0
  318. /package/dist/{chunk-DKHX2FHI.js.map → chunk-64WHWIPL.js.map} +0 -0
  319. /package/dist/{chunk-TVIGN3XZ.js.map → chunk-6FRFVIKC.js.map} +0 -0
  320. /package/dist/{chunk-JIA435P3.js.map → chunk-6ITNEPJO.js.map} +0 -0
  321. /package/dist/{chunk-3AODCBKX.js.map → chunk-6Z2ZWBOV.js.map} +0 -0
  322. /package/dist/{chunk-TAEJ2MRR.js.map → chunk-7IANFJ24.js.map} +0 -0
  323. /package/dist/{chunk-PSQ2P2T3.js.map → chunk-7XZ7TOLQ.js.map} +0 -0
  324. /package/dist/{chunk-6JEEY42N.js.map → chunk-AER3HD3B.js.map} +0 -0
  325. /package/dist/{chunk-4B37KNMP.js.map → chunk-ANV373S5.js.map} +0 -0
  326. /package/dist/{chunk-AYBAC2N4.js.map → chunk-B3I2QQU7.js.map} +0 -0
  327. /package/dist/{chunk-TYLNWE4D.js.map → chunk-B7VKRCAG.js.map} +0 -0
  328. /package/dist/{chunk-HXFIILGF.js.map → chunk-BFPF5N3H.js.map} +0 -0
  329. /package/dist/{chunk-KQAFEZQX.js.map → chunk-BUKK5SWA.js.map} +0 -0
  330. /package/dist/{chunk-53BLBDV6.js.map → chunk-BUKZ7MTN.js.map} +0 -0
  331. /package/dist/{chunk-MCPSMWUC.js.map → chunk-CR72WZ3M.js.map} +0 -0
  332. /package/dist/{chunk-YC2C67F7.js.map → chunk-CRXGQRNA.js.map} +0 -0
  333. /package/dist/{chunk-WRDFYSUC.js.map → chunk-CZVNOTLR.js.map} +0 -0
  334. /package/dist/{chunk-VPO53QMG.js.map → chunk-D6DOLQYK.js.map} +0 -0
  335. /package/dist/{chunk-RGKXF4W3.js.map → chunk-E5IEI2MR.js.map} +0 -0
  336. /package/dist/{chunk-Z2T5BPOZ.js.map → chunk-EIYJK7OD.js.map} +0 -0
  337. /package/dist/{chunk-FRAL3EU4.js.map → chunk-EKPRLTAE.js.map} +0 -0
  338. /package/dist/{chunk-C2KOW2UQ.js.map → chunk-EKR6OO4P.js.map} +0 -0
  339. /package/dist/{chunk-SWZOAQUM.js.map → chunk-F2IU6A2L.js.map} +0 -0
  340. /package/dist/{chunk-2AKIVSHP.js.map → chunk-FAKRTS3Y.js.map} +0 -0
  341. /package/dist/{chunk-MZWHIAOL.js.map → chunk-FC3ZFEXF.js.map} +0 -0
  342. /package/dist/{chunk-7VFNGQ4V.js.map → chunk-FLDXEJFX.js.map} +0 -0
  343. /package/dist/{chunk-JH4FCVWJ.js.map → chunk-G6OFEGUR.js.map} +0 -0
  344. /package/dist/{chunk-L7PGPH4E.js.map → chunk-GCW7UT5I.js.map} +0 -0
  345. /package/dist/{chunk-J7G656MY.js.map → chunk-GE5ZNDLE.js.map} +0 -0
  346. /package/dist/{chunk-63YPKHAU.js.map → chunk-GLB6VV3J.js.map} +0 -0
  347. /package/dist/{chunk-6F5BGIAF.js.map → chunk-GPVGAHXL.js.map} +0 -0
  348. /package/dist/{chunk-XHX67LX6.js.map → chunk-GSBSGT43.js.map} +0 -0
  349. /package/dist/{chunk-645WOU5I.js.map → chunk-H7BZBSP6.js.map} +0 -0
  350. /package/dist/{chunk-GFYFKXWZ.js.map → chunk-HUDPXTXW.js.map} +0 -0
  351. /package/dist/{chunk-L2JQSG5M.js.map → chunk-I7TR2OCU.js.map} +0 -0
  352. /package/dist/{chunk-6SYS5YX3.js.map → chunk-IAOW2L6K.js.map} +0 -0
  353. /package/dist/{chunk-STM4T335.js.map → chunk-IJH6METJ.js.map} +0 -0
  354. /package/dist/{chunk-3XVBGGF3.js.map → chunk-IZRNMXZC.js.map} +0 -0
  355. /package/dist/{chunk-Y5ZHZKZD.js.map → chunk-JM6U3SAE.js.map} +0 -0
  356. /package/dist/{chunk-74AY3S7U.js.map → chunk-JNLYHJG7.js.map} +0 -0
  357. /package/dist/{chunk-QOUKZ2N3.js.map → chunk-JOOGPZJE.js.map} +0 -0
  358. /package/dist/{chunk-EGNONTVT.js.map → chunk-JORSMFL6.js.map} +0 -0
  359. /package/dist/{chunk-JF3MEIHO.js.map → chunk-JQCP5QW3.js.map} +0 -0
  360. /package/dist/{chunk-POGPI5GR.js.map → chunk-JRTKYFFY.js.map} +0 -0
  361. /package/dist/{chunk-5UPOKIFP.js.map → chunk-JT3IXJIL.js.map} +0 -0
  362. /package/dist/{chunk-6DTIYAAN.js.map → chunk-JZFJZLJY.js.map} +0 -0
  363. /package/dist/{chunk-6QOL4G76.js.map → chunk-KQXRVELF.js.map} +0 -0
  364. /package/dist/{chunk-KOAVX2IT.js.map → chunk-L74NWAD4.js.map} +0 -0
  365. /package/dist/{chunk-5DCS4C4S.js.map → chunk-LJXBFVI2.js.map} +0 -0
  366. /package/dist/{chunk-OKKBOTRA.js.map → chunk-LPD6I2U6.js.map} +0 -0
  367. /package/dist/{chunk-N7DVBHU3.js.map → chunk-LR7RW4T6.js.map} +0 -0
  368. /package/dist/{chunk-FZVZYU5C.js.map → chunk-LXN737FX.js.map} +0 -0
  369. /package/dist/{chunk-7ZRRJ6RG.js.map → chunk-MGYZENUY.js.map} +0 -0
  370. /package/dist/{chunk-YQ6SLFNZ.js.map → chunk-MPJDQC4G.js.map} +0 -0
  371. /package/dist/{chunk-5ANUG4JZ.js.map → chunk-NJ2DZYEK.js.map} +0 -0
  372. /package/dist/{chunk-OLH4XCLU.js.map → chunk-O2O4FDAH.js.map} +0 -0
  373. /package/dist/{chunk-CVMAOPAH.js.map → chunk-ODJ2HRFW.js.map} +0 -0
  374. /package/dist/{chunk-2NLLXCJG.js.map → chunk-OWHERGF2.js.map} +0 -0
  375. /package/dist/{chunk-I73ZSORJ.js.map → chunk-OXSTKCYK.js.map} +0 -0
  376. /package/dist/{chunk-RWRHGE75.js.map → chunk-P3YUEPSQ.js.map} +0 -0
  377. /package/dist/{chunk-TPKB7T6Z.js.map → chunk-Q6UZREJK.js.map} +0 -0
  378. /package/dist/{chunk-UJDTXWMT.js.map → chunk-QIMGULGN.js.map} +0 -0
  379. /package/dist/{chunk-E24RUQEN.js.map → chunk-QNIYL5SK.js.map} +0 -0
  380. /package/dist/{chunk-KOY25HUB.js.map → chunk-QYAXMXOB.js.map} +0 -0
  381. /package/dist/{chunk-X247CYL6.js.map → chunk-RIAKNXZB.js.map} +0 -0
  382. /package/dist/{chunk-WCIDCJOQ.js.map → chunk-RO2NNWR5.js.map} +0 -0
  383. /package/dist/{chunk-AYXRK264.js.map → chunk-RROFIAYI.js.map} +0 -0
  384. /package/dist/{chunk-YYGZ4EIY.js.map → chunk-RUAIO5UA.js.map} +0 -0
  385. /package/dist/{chunk-FQFMLOAC.js.map → chunk-RWW5KPIY.js.map} +0 -0
  386. /package/dist/{chunk-E5PVMB3I.js.map → chunk-SDXBR5QO.js.map} +0 -0
  387. /package/dist/{chunk-NH6GZEQN.js.map → chunk-SJHFU52W.js.map} +0 -0
  388. /package/dist/{chunk-FGEY2AGV.js.map → chunk-SRPGA6WN.js.map} +0 -0
  389. /package/dist/{chunk-CUWOSRCS.js.map → chunk-SUKPM6DV.js.map} +0 -0
  390. /package/dist/{chunk-TXP7Q7T5.js.map → chunk-TTQYX7VU.js.map} +0 -0
  391. /package/dist/{chunk-TDCR6PQL.js.map → chunk-TWRPWJJT.js.map} +0 -0
  392. /package/dist/{chunk-I75BWXRZ.js.map → chunk-U66CTIF5.js.map} +0 -0
  393. /package/dist/{chunk-DG4H56SK.js.map → chunk-UIK3U36O.js.map} +0 -0
  394. /package/dist/{chunk-XLEP7SS3.js.map → chunk-UMSH4I3E.js.map} +0 -0
  395. /package/dist/{chunk-X7Y7WX73.js.map → chunk-UVYI6VIX.js.map} +0 -0
  396. /package/dist/{chunk-LHBOFROT.js.map → chunk-V2XMG7GM.js.map} +0 -0
  397. /package/dist/{chunk-ZAP7BKTZ.js.map → chunk-VCOCOBUS.js.map} +0 -0
  398. /package/dist/{chunk-4P4VLPGB.js.map → chunk-VECRSYQG.js.map} +0 -0
  399. /package/dist/{chunk-GGI6FLO6.js.map → chunk-VHBGJAYC.js.map} +0 -0
  400. /package/dist/{chunk-QO5KDQGG.js.map → chunk-VIS23B6O.js.map} +0 -0
  401. /package/dist/{chunk-NMKETOAX.js.map → chunk-VSHWPOUB.js.map} +0 -0
  402. /package/dist/{chunk-UBN5AOLT.js.map → chunk-W5EO4USJ.js.map} +0 -0
  403. /package/dist/{chunk-Y7427SL7.js.map → chunk-WCGJK4NQ.js.map} +0 -0
  404. /package/dist/{chunk-7HXZOWTR.js.map → chunk-WQYS47G4.js.map} +0 -0
  405. /package/dist/{chunk-JH2ALMPR.js.map → chunk-WR5POHQ3.js.map} +0 -0
  406. /package/dist/{chunk-VSSQIBVU.js.map → chunk-WT2VVYBM.js.map} +0 -0
  407. /package/dist/{chunk-EHIKY2IA.js.map → chunk-WU5WTCH5.js.map} +0 -0
  408. /package/dist/{chunk-QKXPOLQD.js.map → chunk-WUBGMV3G.js.map} +0 -0
  409. /package/dist/{chunk-FKTMWDN2.js.map → chunk-WUL6LDJ4.js.map} +0 -0
  410. /package/dist/{chunk-U7HJBODU.js.map → chunk-XKTHJHSQ.js.map} +0 -0
  411. /package/dist/{chunk-JFI3ATK4.js.map → chunk-XMYWYJM2.js.map} +0 -0
  412. /package/dist/{chunk-64S6X4IU.js.map → chunk-XTN54NML.js.map} +0 -0
  413. /package/dist/{chunk-VGFNTY3Y.js.map → chunk-YFXRLRKP.js.map} +0 -0
  414. /package/dist/{chunk-DAOMWGO2.js.map → chunk-ZX5N5D6M.js.map} +0 -0
  415. /package/dist/{chunk-VGRM43X6.js.map → chunk-ZXFKG7VZ.js.map} +0 -0
  416. /package/dist/{resolution-4ZEQPXUZ.js.map → extraction-window-drain.js.map} +0 -0
@@ -0,0 +1,110 @@
1
+ /**
2
+ * Trigger-drain helpers (extraction trigger stall fix).
3
+ *
4
+ * A session whose buffered window outgrows the extraction model's context
5
+ * never drains: the trigger fires `extract_batch` on every observe, the
6
+ * oversized request fails, nothing is cleared, and the window only grows.
7
+ * These helpers split such a window into budget-fitting chunks and classify
8
+ * each extraction run so the caller can drain successes, defer on breaker/
9
+ * backoff retention, and drop repeatedly failing chunks.
10
+ */
11
+
12
+ import type { ExtractionRunResult } from "./orchestration/extraction-run.js";
13
+
14
+ /**
15
+ * Split `turns` into chunks whose summed content length stays within
16
+ * `maxChars`. Chunks keep turn order and never split a turn; a single turn
17
+ * longer than the budget becomes its own chunk (the extraction prompt still
18
+ * clamps per-turn content). A non-positive or non-finite budget, or an empty
19
+ * window, yields at most one chunk (no chunking).
20
+ */
21
+ export function chunkExtractionWindow<T extends { content: string }>(
22
+ turns: readonly T[],
23
+ maxChars: number,
24
+ ): T[][] {
25
+ if (turns.length === 0) return [];
26
+ const budget =
27
+ Number.isFinite(maxChars) && maxChars > 0 ? Math.floor(maxChars) : Number.POSITIVE_INFINITY;
28
+ const chunks: T[][] = [];
29
+ let current: T[] = [];
30
+ let currentChars = 0;
31
+ for (const turn of turns) {
32
+ const turnChars = turn.content.length;
33
+ if (current.length > 0 && currentChars + turnChars > budget) {
34
+ chunks.push(current);
35
+ current = [];
36
+ currentChars = 0;
37
+ }
38
+ current.push(turn);
39
+ currentChars += turnChars;
40
+ }
41
+ if (current.length > 0) chunks.push(current);
42
+ return chunks;
43
+ }
44
+
45
+ export type DrainVerdict = "drained" | "deferred" | "failed";
46
+
47
+ /**
48
+ * Run results that deliberately RETAIN the buffer (provider breaker open,
49
+ * per-fingerprint backoff) are deferrals, not chunk failures — counting them
50
+ * would drop good content during a provider outage.
51
+ */
52
+ const DRAIN_DEFERRAL_REASONS = {
53
+ provider_circuit_open: true,
54
+ extraction_backoff: true,
55
+ };
56
+
57
+ export function classifyDrainResult(result: ExtractionRunResult): DrainVerdict {
58
+ if (result.status !== "skipped") return "drained";
59
+ // An empty result is a failure only when the run kept the window for retry;
60
+ // otherwise it extracted fine, found nothing durable, and cleared its turns.
61
+ if (result.reason === "empty_extraction_result") {
62
+ return result.retainedBuffer === true ? "failed" : "drained";
63
+ }
64
+ if (result.reason !== undefined && result.reason in DRAIN_DEFERRAL_REASONS) return "deferred";
65
+ return "drained";
66
+ }
67
+
68
+ /**
69
+ * Combine chunk results into the single `ExtractionRunResult` the queue
70
+ * contract settles with: counts sum, any completed chunk completes the drain,
71
+ * and the last non-completed reason wins.
72
+ */
73
+ export function mergeDrainResults(
74
+ previous: ExtractionRunResult | null,
75
+ next: ExtractionRunResult,
76
+ ): ExtractionRunResult {
77
+ if (previous === null) return next;
78
+ const completed = previous.status === "completed" || next.status === "completed";
79
+ const merged: ExtractionRunResult = {
80
+ status: completed ? "completed" : "skipped",
81
+ persistedCount: previous.persistedCount + next.persistedCount,
82
+ durableOutputCount: previous.durableOutputCount + next.durableOutputCount,
83
+ };
84
+ if (!completed) merged.reason = next.reason ?? previous.reason;
85
+ if (previous.postPersistMetadataFailed === true || next.postPersistMetadataFailed === true) {
86
+ merged.postPersistMetadataFailed = true;
87
+ }
88
+ return merged;
89
+ }
90
+
91
+ /** The slice of ModelRegistry the drain budget needs. */
92
+ export interface WindowBudgetRegistry {
93
+ calculateContextSizes(modelId: string, maxContextOverride?: number): { maxInputChars: number };
94
+ }
95
+
96
+ /**
97
+ * Character budget for one extraction request. The learned local-model window
98
+ * only describes the extractor when the local LLM does the extracting; with a
99
+ * gateway extractor, a disabled local LLM, or no registry (legacy hosts, test
100
+ * doubles) there is no budget and the window runs in one request as before.
101
+ */
102
+ export function extractionWindowBudgetChars(input: {
103
+ registry: WindowBudgetRegistry | undefined;
104
+ localExtractionActive: boolean;
105
+ model: string;
106
+ maxContext: number | undefined;
107
+ }): number {
108
+ if (!input.registry || !input.localExtractionActive) return Number.POSITIVE_INFINITY;
109
+ return input.registry.calculateContextSizes(input.model, input.maxContext).maxInputChars;
110
+ }
@@ -0,0 +1,261 @@
1
+ /**
2
+ * Chunked trigger-drain for the extraction pipeline.
3
+ *
4
+ * Split out of `turn-ingestion.ts`: that file is at the structural ratchet's
5
+ * line cap (issue #1995), and the drain is a self-contained unit — it only
6
+ * needs the host's `runExtraction`, the buffer drop, the storage side-file
7
+ * copy and the preemption hook.
8
+ */
9
+
10
+ import { createHash } from "node:crypto";
11
+ import { isAbortError, preemptedExtractionError } from "../abort-error.js";
12
+ import { describeError } from "../buffer-turn-helpers.js";
13
+ import { chunkExtractionWindow, classifyDrainResult, mergeDrainResults } from "../extraction-window-drain.js";
14
+ import { log } from "../logger.js";
15
+ import type { BufferTurn } from "../types.js";
16
+ import type { ExtractionRunCoordinator, ExtractionRunResult } from "./extraction-run.js";
17
+
18
+ type RunOptions = Parameters<ExtractionRunCoordinator["runExtraction"]>[1];
19
+
20
+ /** The `runExtraction` options the drain forwards, with the ones it reads made required. */
21
+ export type DrainRunOptions = RunOptions & {
22
+ bufferKey: string;
23
+ clearBufferAfterExtraction: boolean;
24
+ skipUserTurnThreshold: boolean;
25
+ failOnExtractionFailure: boolean;
26
+ forceExtractionAttempt: boolean;
27
+ };
28
+
29
+ /** What the drain needs from its host (structurally satisfied by `TurnIngestionDeps`). */
30
+ export interface ExtractionDrainDeps {
31
+ config: {
32
+ extractionMinUserTurns: number;
33
+ extractionMinChars: number;
34
+ extractionMaxTurnChars: number;
35
+ extractionChunkDropAfterFailures: number;
36
+ };
37
+ extractionWindowBudgetChars?(): number;
38
+ runExtraction(turns: BufferTurn[], options: RunOptions): Promise<ExtractionRunResult>;
39
+ getStorage(): Promise<{
40
+ saveDroppedExtractionChunk(bufferKey: string, reason: string, turns: readonly BufferTurn[]): Promise<string>;
41
+ }>;
42
+ buffer: {
43
+ dropExtractionChunk(bufferKey: string, turns: readonly BufferTurn[], options?: { allowNonPrefix?: boolean }): Promise<number>;
44
+ };
45
+ extractionQueueCoordinator: { beginPreemptable(abort: () => void): void };
46
+ }
47
+
48
+ /** Identity of a chunk: its failure count must not follow a buffer key to different content. */
49
+ function chunkFingerprint(chunk: readonly BufferTurn[]): string {
50
+ const hash = createHash("sha256");
51
+ for (const turn of chunk) hash.update(`${turn.role}\u0000${turn.timestamp}\u0000${turn.content}\u0001`);
52
+ return hash.digest("hex");
53
+ }
54
+
55
+ export class ExtractionDrain {
56
+ /**
57
+ * Consecutive failed attempts on the head chunk, per buffer key. In memory on
58
+ * purpose (a restart re-counts from zero). Bound to the chunk's content: a
59
+ * count recorded for one chunk never applies to a different one, so a force
60
+ * flush that clears a failing chunk cannot make unrelated content inherit its
61
+ * failures.
62
+ */
63
+ private readonly failures = new Map<string, { fingerprint: string; count: number }>();
64
+
65
+ /**
66
+ * Buffer key to the first turn of the chunk a qualified window stopped on.
67
+ * The rest of such a window stays eligible on the next attempt even when it
68
+ * is assistant-only or short: the window passed the thresholds as a whole,
69
+ * and re-judging its tail would clear it unextracted. Cleared when the
70
+ * window drains; one entry per key.
71
+ */
72
+ private readonly qualified = new Map<string, string>();
73
+
74
+ constructor(private readonly deps: ExtractionDrainDeps) {}
75
+
76
+ /** Characters the coordinator would count for this window: user/assistant text, trimmed and capped per turn, context-only turns left out. */
77
+ private windowChars(turns: readonly BufferTurn[]): number {
78
+ let total = 0;
79
+ for (const turn of turns) {
80
+ if ((turn.role !== "user" && turn.role !== "assistant") || turn.extractionContextOnly === true) continue;
81
+ total += turn.content.trim().slice(0, this.deps.config.extractionMaxTurnChars).length;
82
+ }
83
+ return total;
84
+ }
85
+
86
+ private failureCount(bufferKey: string, chunk: readonly BufferTurn[]): number {
87
+ const entry = this.failures.get(bufferKey);
88
+ return entry && entry.fingerprint === chunkFingerprint(chunk) ? entry.count : 0;
89
+ }
90
+
91
+ private setFailureCount(bufferKey: string, chunk: readonly BufferTurn[], count: number): void {
92
+ if (count <= 0) this.failures.delete(bufferKey);
93
+ else this.failures.set(bufferKey, { fingerprint: chunkFingerprint(chunk), count });
94
+ }
95
+
96
+ /**
97
+ * Run `runExtraction` over the trigger-drain window. When the window outgrows
98
+ * the extraction model's input budget (the stall that keeps a session's buffer
99
+ * growing forever: every observe re-fires the trigger on a window that can
100
+ * never extract), split it into budget-fitting chunks and drain them in
101
+ * order; each successful run clears its chunk, so the buffer shrinks across
102
+ * observes. A chunk that fails `extractionChunkDropAfterFailures` times in a
103
+ * row is dropped (side-file copy first). Breaker/backoff retention results
104
+ * stop the drain without counting as chunk failures.
105
+ *
106
+ * Explicit drains (replay/import `clearBufferAfterExtraction: false`, force
107
+ * flush, fail-closed callers, accepted captures) and windows that fit the
108
+ * budget (or hosts without the budget accessor) take the single-run path.
109
+ *
110
+ * `preemptable`: the run was queued as preemptable automatic work. Each chunk's
111
+ * persist step ends the host's preemption registration, so the drain registers
112
+ * it again before every later chunk; a fail-closed flush can then abort the
113
+ * next chunk's model request instead of waiting behind the whole window.
114
+ */
115
+ async run(turns: BufferTurn[], runOptions: DrainRunOptions, preemptable = false): Promise<ExtractionRunResult> {
116
+ const budgetChars = this.deps.extractionWindowBudgetChars?.() ?? Number.POSITIVE_INFINITY;
117
+ const chunkable =
118
+ runOptions.clearBufferAfterExtraction &&
119
+ !runOptions.forceExtractionAttempt &&
120
+ !runOptions.failOnExtractionFailure &&
121
+ !turns.some((turn) => turn.acceptedCapture === true) &&
122
+ Number.isFinite(budgetChars) &&
123
+ budgetChars > 0;
124
+ const chunks = chunkable ? chunkExtractionWindow(turns, budgetChars) : [];
125
+ const resumed =
126
+ chunks.length > 0 && this.qualified.get(runOptions.bufferKey) === chunkFingerprint(chunks[0].slice(0, 1));
127
+ // The tail of a window that already qualified goes through the chunk loop even when it now fits in one
128
+ // chunk, so its failures still count toward the drop threshold.
129
+ if (chunks.length <= 1 && !resumed) return await this.deps.runExtraction(turns, runOptions);
130
+ // Eligibility (minimum user turns and characters) belongs to the whole
131
+ // window: a window that never qualified keeps the single-run path, which
132
+ // judges it exactly as before.
133
+ if (!resumed) {
134
+ const windowUserTurns = turns.filter((turn) => turn.role === "user").length;
135
+ const belowChars = !runOptions.skipCharThreshold && this.windowChars(turns) < this.deps.config.extractionMinChars;
136
+ if ((!runOptions.skipUserTurnThreshold && windowUserTurns < this.deps.config.extractionMinUserTurns) || belowChars) {
137
+ return await this.deps.runExtraction(turns, runOptions);
138
+ }
139
+ }
140
+ // The window qualified as a whole; its chunks must not be re-judged one by
141
+ // one (an assistant-only or short chunk would be cleared unextracted).
142
+ const baseOptions = { ...runOptions, skipCharThreshold: true, skipUserTurnThreshold: true };
143
+
144
+ const bufferKey = runOptions.bufferKey;
145
+ // A native group clears its turns by identity (a pinned capture can sit in front); a drop must find them the same way.
146
+ const byIdentity = runOptions.clearMatchingTurns === true;
147
+ const dropAfter = this.deps.config.extractionChunkDropAfterFailures;
148
+ let aggregate: ExtractionRunResult | null = null;
149
+ for (const [position, chunk] of chunks.entries()) {
150
+ this.qualified.set(bufferKey, chunkFingerprint(chunk.slice(0, 1)));
151
+ // retentionWindow: the chunks processed so far. A chunk's deferred retention replaces theirs (retained turns do not pile
152
+ // up across chunks) and leaves the retained turns of chunks not yet processed in the buffer.
153
+ let chunkOptions: DrainRunOptions = { ...baseOptions, retentionWindow: chunks.slice(0, position + 1).flat() };
154
+ let preempt: AbortController | undefined;
155
+ if (preemptable && position > 0) {
156
+ const local = new AbortController();
157
+ preempt = local;
158
+ this.deps.extractionQueueCoordinator.beginPreemptable(() => local.abort(preemptedExtractionError()));
159
+ chunkOptions = {
160
+ ...chunkOptions,
161
+ abortSignal: runOptions.abortSignal ? AbortSignal.any([runOptions.abortSignal, local.signal]) : local.signal,
162
+ };
163
+ }
164
+ let failures = this.failureCount(bufferKey, chunk);
165
+ let result: ExtractionRunResult;
166
+ try {
167
+ result = await this.deps.runExtraction(chunk, chunkOptions);
168
+ } catch (err) {
169
+ // The chunk-local abort leaves the outer signal untouched, so hand back the
170
+ // preemption reason the host looks for (as it does for the first chunk).
171
+ if (isAbortError(err)) throw preempt && preempt.signal.aborted && !runOptions.abortSignal?.aborted ? preempt.signal.reason : err;
172
+ failures += 1;
173
+ if (failures < dropAfter) {
174
+ this.setFailureCount(bufferKey, chunk, failures);
175
+ throw err;
176
+ }
177
+ // A chunk that keeps throwing is dropped like one that keeps failing,
178
+ // so later chunks are not stuck behind it.
179
+ const thrown: ExtractionRunResult = {
180
+ status: "skipped",
181
+ reason: `thrown: ${describeError(err)}`,
182
+ persistedCount: 0,
183
+ durableOutputCount: 0,
184
+ };
185
+ if (!(await this.dropFailedChunk(bufferKey, chunk, dropAfter, thrown, byIdentity))) {
186
+ this.setFailureCount(bufferKey, chunk, failures);
187
+ throw err;
188
+ }
189
+ this.setFailureCount(bufferKey, chunk, 0);
190
+ continue;
191
+ }
192
+ const verdict = classifyDrainResult(result);
193
+ if (verdict === "drained") {
194
+ this.setFailureCount(bufferKey, chunk, 0);
195
+ aggregate = mergeDrainResults(aggregate, result);
196
+ continue;
197
+ }
198
+ // Provider breaker/backoff retention: keep everything for retry.
199
+ if (verdict === "deferred") return mergeDrainResults(aggregate, result);
200
+ // An outage or a bad key is not the chunk's fault: keep the chunk and do not count toward dropping it.
201
+ if (result.failureClass === "provider_retryable" || result.failureClass === "auth_config") {
202
+ return mergeDrainResults(aggregate, result);
203
+ }
204
+ failures += 1;
205
+ if (failures >= dropAfter) {
206
+ if (!(await this.dropFailedChunk(bufferKey, chunk, dropAfter, result, byIdentity))) {
207
+ // No recovery copy: keep the only buffered copy and retry later.
208
+ this.setFailureCount(bufferKey, chunk, failures);
209
+ return mergeDrainResults(aggregate, result);
210
+ }
211
+ this.setFailureCount(bufferKey, chunk, 0);
212
+ aggregate = mergeDrainResults(aggregate, result);
213
+ continue;
214
+ }
215
+ this.setFailureCount(bufferKey, chunk, failures);
216
+ // Retain the remaining window for the next trigger (existing behavior).
217
+ return mergeDrainResults(aggregate, result);
218
+ }
219
+ this.qualified.delete(bufferKey);
220
+ return aggregate ?? { status: "skipped", persistedCount: 0, durableOutputCount: 0 };
221
+ }
222
+
223
+ /** Side-file copy first (content survives a failed drop), then remove the failing chunk from the buffer. Never throws:
224
+ * the drop must not fail the extraction task that already settled its result. */
225
+ private async dropFailedChunk(
226
+ bufferKey: string,
227
+ chunk: readonly BufferTurn[],
228
+ dropAfter: number,
229
+ result: ExtractionRunResult,
230
+ byIdentity: boolean,
231
+ ): Promise<boolean> {
232
+ const reason =
233
+ `dropped after ${dropAfter} repeated extraction failures ` +
234
+ `(last result: status=${result.status} reason=${result.reason ?? "n/a"})`;
235
+ try {
236
+ const storage = await this.deps.getStorage();
237
+ const path = await storage.saveDroppedExtractionChunk(bufferKey, reason, chunk);
238
+ log.warn(`buffer[${bufferKey}]: dropping ${chunk.length} turns — ${reason}; copy saved to ${path}`);
239
+ } catch (err) {
240
+ // Never destroy the only buffered copy without a recovery file.
241
+ log.warn(
242
+ `buffer[${bufferKey}]: could not save the dropped-chunk recovery copy; keeping the chunk in the buffer: ${describeError(err)}`,
243
+ );
244
+ return false;
245
+ }
246
+ try {
247
+ const dropped = await this.deps.buffer.dropExtractionChunk(bufferKey, chunk, { allowNonPrefix: byIdentity });
248
+ if (dropped > 0) {
249
+ log.warn(`buffer[${bufferKey}]: removed ${dropped} buffered turns — ${reason}`);
250
+ return true;
251
+ }
252
+ // Nothing removed (the live turns changed): the chunk is still buffered, so this is not a drop.
253
+ log.warn(`buffer[${bufferKey}]: dropped chunk no longer matches the buffer; keeping it and its failure count`);
254
+ } catch (err) {
255
+ log.warn(
256
+ `buffer[${bufferKey}]: failed to remove dropped chunk from buffer (will retry next trigger): ${describeError(err)}`,
257
+ );
258
+ }
259
+ return false;
260
+ }
261
+ }
@@ -1,6 +1,7 @@
1
1
  import type { BufferTurn, ExtractionFailureClass, ExtractionResult, MetaState } from "../types.js";
2
2
  import type { StorageManager } from "../index.js";
3
3
  import { log } from "../logger.js";
4
+ import type { ExtractionRunResult } from "./extraction-run.js";
4
5
 
5
6
  export function combineExtractionAbortSignals(
6
7
  primary: AbortSignal | undefined,
@@ -11,6 +12,13 @@ export function combineExtractionAbortSignals(
11
12
  }
12
13
 
13
14
 
15
+ /** Result of a run whose extraction found nothing durable; `retained` marks a recorded failure that left the window in the buffer. */
16
+ export function emptyExtractionResult(retained: boolean, failureClass?: ExtractionFailureClass): ExtractionRunResult {
17
+ const result: ExtractionRunResult = { status: "skipped", reason: "empty_extraction_result", persistedCount: 0, durableOutputCount: 0 };
18
+ if (retained) Object.assign(result, { retainedBuffer: true, failureClass: failureClass ?? "provider_retryable" }); // same default as the retry bookkeeping
19
+ return result;
20
+ }
21
+
14
22
  function isRecord(value: unknown): value is Record<string, unknown> {
15
23
  return typeof value === "object" && value !== null;
16
24
  }
@@ -38,6 +38,7 @@ export interface ExtractionRunResult {
38
38
  persistedCount: number;
39
39
  durableOutputCount: number;
40
40
  postPersistMetadataFailed?: boolean;
41
+ retainedBuffer?: boolean; failureClass?: ExtractionFailureClass; // retained: the run left the window in the buffer for a retry (a recorded failure) of this class
41
42
  }
42
43
 
43
44
  export class ExtractionDeadlineError extends Error {
@@ -118,7 +119,7 @@ import {
118
119
  commitEmptySuccessExtraction,
119
120
  computeExtractionRetryNextEligibleMs,
120
121
  deriveSourceConnector,
121
- deriveTopicsFromExtraction,
122
+ deriveTopicsFromExtraction, emptyExtractionResult,
122
123
  runExtractionPostPersist,
123
124
  runExtractionPostPersistBestEffort,
124
125
  EXTRACTION_RETRY_STATE_MAX_ENTRIES,
@@ -439,7 +440,7 @@ export class ExtractionRunCoordinator {
439
440
  turns: BufferTurn[],
440
441
  options: {
441
442
  clearBufferAfterExtraction?: boolean;
442
- clearMatchingTurns?: boolean;
443
+ clearMatchingTurns?: boolean; retentionWindow?: readonly BufferTurn[];
443
444
  skipCharThreshold?: boolean;
444
445
  skipUserTurnThreshold?: boolean;
445
446
  deadlineMs?: number;
@@ -1044,7 +1045,7 @@ export class ExtractionRunCoordinator {
1044
1045
  if (!shouldPersistProcessedFingerprint) {
1045
1046
  await commitEmptySuccessExtraction(emptySuccessCommit);
1046
1047
  }
1047
- return { status: "skipped", reason: "empty_extraction_result", persistedCount: 0, durableOutputCount: 0 };
1048
+ return emptyExtractionResult(recordedRetryFailure, result.extractionFailureClass);
1048
1049
  }
1049
1050
 
1050
1051
  let threadIdForExtraction: string | null = null;
@@ -1108,7 +1109,7 @@ export class ExtractionRunCoordinator {
1108
1109
  normalizedTurns: normalizedTurns as BufferTurn[],
1109
1110
  bufferKey,
1110
1111
  retainDeferredTurns: (key, retainedTurns, max) =>
1111
- this.deps.getBuffer().retainDeferredTurns(key, retainedTurns, max, turns),
1112
+ this.deps.getBuffer().retainDeferredTurns(key, retainedTurns, max, options.retentionWindow ?? turns),
1112
1113
  clearBuffer,
1113
1114
  failOnExtractionFailure: options.failOnExtractionFailure === true,
1114
1115
  });
@@ -42,6 +42,7 @@ import { TranscriptManager } from "../transcript.js";
42
42
  import type { BufferTurn, PluginConfig, SourceConnectorProvenance } from "../types.js";
43
43
 
44
44
  import { groupTurnsByExtractionScope, bufferTurnsEqual } from "../buffer-turn-helpers.js";
45
+ import { ExtractionDrain } from "./extraction-drain.js";
45
46
  import { resolveScopeProfilePlan, type ResolvedScopeProfilePlan, hasExplicitNamespacePolicy } from "../namespaces/scope-profiles.js";
46
47
  import { resolveCodingNamespaceOverlay, combineNamespaces } from "../coding/coding-namespace.js";
47
48
  import { canWriteNamespace, defaultNamespaceForPrincipal } from "../namespaces/principal.js";
@@ -114,6 +115,8 @@ export interface TurnIngestionDeps {
114
115
  },
115
116
  ): Promise<void>;
116
117
  resolveMemoryIdOrHandle(ref: string, sessionKey?: string): string;
118
+ /** Max conversation chars the extraction model accepts; absent on legacy hosts (single-run behavior). */
119
+ extractionWindowBudgetChars?(): number;
117
120
  runExtraction(
118
121
  ...args: Parameters<ExtractionRunCoordinator["runExtraction"]>
119
122
  ): Promise<ExtractionRunResult>;
@@ -156,9 +159,10 @@ function isFlushPlanRecoveryTurn(
156
159
  }
157
160
 
158
161
  export class TurnIngestionCoordinator {
159
- constructor(
160
- private readonly deps: TurnIngestionDeps,
161
- ) {}
162
+ private readonly drain: ExtractionDrain; // chunked trigger-drain (extraction-drain.ts)
163
+ constructor(private readonly deps: TurnIngestionDeps) {
164
+ this.drain = new ExtractionDrain(deps);
165
+ }
162
166
 
163
167
  async processTurn(
164
168
  role: "user" | "assistant",
@@ -1067,7 +1071,7 @@ export class TurnIngestionCoordinator {
1067
1071
  effectiveScopePlan = fresh;
1068
1072
  }
1069
1073
  }
1070
- const result = await this.deps.runExtraction(effectiveTurns, {
1074
+ const result = await this.drain.run(effectiveTurns, {
1071
1075
  clearBufferAfterExtraction:
1072
1076
  options.clearBufferAfterExtraction ?? true,
1073
1077
  clearMatchingTurns: options.clearMatchingTurns === true,
@@ -1083,7 +1087,7 @@ export class TurnIngestionCoordinator {
1083
1087
  principalOverride: options.principalOverride,
1084
1088
  scopeProfileWritePlan: effectiveScopePlan,
1085
1089
  forceExtractionAttempt: options.forceExtractionAttempt === true,
1086
- });
1090
+ }, preemptable);
1087
1091
  settleTask(undefined, result);
1088
1092
  } catch (err) {
1089
1093
  const reason = abortSignal.reason;
@@ -238,6 +238,7 @@ import {
238
238
  } from "./maintenance/pattern-reinforcement.js";
239
239
  import { refreshConvergedNamespaces } from "./convergence-refresh.js";
240
240
  import { ModelRegistry } from "./model-registry.js";
241
+ import { extractionWindowBudgetChars } from "./extraction-window-drain.js";
241
242
  import { applyRuntimeRetrievalPolicy, expandQuery } from "./retrieval.js";
242
243
  import {
243
244
  mergeWithAgentResults,
@@ -3062,6 +3063,26 @@ export class Orchestrator {
3062
3063
  );
3063
3064
  }
3064
3065
 
3066
+ /**
3067
+ * Max conversation characters the extraction model can take as input
3068
+ * (context window the ModelRegistry learned, capped by
3069
+ * `localLlmMaxContext` when set). Exposed for the trigger-drain chunking
3070
+ * in the turn-ingestion coordinator so an oversized buffer window is
3071
+ * drained in fitting chunks instead of failing whole.
3072
+ */
3073
+ private extractionWindowBudgetChars(): number {
3074
+ // Object.create(Orchestrator.prototype) test doubles skip the constructor,
3075
+ // so neither modelRegistry nor config exists there: report "no budget".
3076
+ if (!this.modelRegistry) return Number.POSITIVE_INFINITY;
3077
+ return extractionWindowBudgetChars({
3078
+ registry: this.modelRegistry,
3079
+ localExtractionActive:
3080
+ this.config.modelSource !== "gateway" && resolveLocalLlmCapabilities(this.config).localLlm,
3081
+ model: this.config.localLlmModel,
3082
+ maxContext: this.config.localLlmMaxContext,
3083
+ });
3084
+ }
3085
+
3065
3086
  private normalizeExtractionFingerprintTurns(turns: BufferTurn[]): string[] {
3066
3087
  return this.extractionRunCoordinator.normalizeExtractionFingerprintTurns(turns);
3067
3088
  }
@@ -902,7 +902,9 @@ const ENCRYPTABLE_STATE_SIDECARS = new Set([
902
902
  ]);
903
903
 
904
904
  function isEncryptableStateSidecar(normalized: string): boolean {
905
- return ENCRYPTABLE_STATE_SIDECARS.has(normalized);
905
+ // state/dropped/ holds copies of extraction-buffer turns dropped after
906
+ // repeated extraction failures — same content sensitivity as buffer.json.
907
+ return ENCRYPTABLE_STATE_SIDECARS.has(normalized) || normalized.startsWith("state/dropped/");
906
908
  }
907
909
 
908
910
  /**
@@ -0,0 +1,27 @@
1
+ import { randomUUID } from "node:crypto";
2
+ import { mkdir } from "node:fs/promises";
3
+ import path from "node:path";
4
+ import type { BufferTurn } from "../types.js";
5
+
6
+ /**
7
+ * Persist a copy of extraction-buffer turns that are being DROPPED after repeated extraction failures (trigger-drain drop
8
+ * path), so a destructive drop never loses content silently. Written under `<stateDir>/dropped/` through the store's secure
9
+ * writer, so encrypted stores keep it encrypted (secure-fs encrypts the whole `state/dropped/` prefix). Returns the path.
10
+ */
11
+ export async function saveDroppedExtractionChunk(
12
+ stateDir: string,
13
+ writeSecureFile: (filePath: string, content: string) => Promise<void>,
14
+ bufferKey: string,
15
+ reason: string,
16
+ turns: readonly BufferTurn[],
17
+ ): Promise<string> {
18
+ const droppedDir = path.join(stateDir, "dropped");
19
+ await mkdir(droppedDir, { recursive: true });
20
+ const safeKey = bufferKey.replace(/[^a-zA-Z0-9._-]/g, "-").slice(0, 80) || "default";
21
+ // The random suffix keeps copies written in the same millisecond (or for keys that truncate to the same name) from
22
+ // overwriting each other.
23
+ const filePath = path.join(droppedDir, `${Date.now()}-${randomUUID().slice(0, 8)}-${safeKey}.json`);
24
+ const payload = { bufferKey, reason, droppedAt: new Date().toISOString(), turns };
25
+ await writeSecureFile(filePath, JSON.stringify(payload, null, 2));
26
+ return filePath;
27
+ }
@@ -0,0 +1,30 @@
1
+ import assert from "node:assert/strict";
2
+ import { mkdtemp, readdir, rm } from "node:fs/promises";
3
+ import os from "node:os";
4
+ import path from "node:path";
5
+ import test from "node:test";
6
+ import { StorageManager } from "./storage.js";
7
+ import type { BufferTurn } from "./types.js";
8
+
9
+ function makeTurn(content: string): BufferTurn {
10
+ return { role: "user", content, timestamp: "2026-10-29T00:00:00.000Z", sessionKey: "s1" };
11
+ }
12
+
13
+ test("dropped-chunk recovery files never overwrite each other, even within one millisecond", async () => {
14
+ const dir = await mkdtemp(path.join(os.tmpdir(), "remnic-dropped-chunks-"));
15
+ const realNow = Date.now;
16
+ try {
17
+ Date.now = () => 1_793_000_000_000;
18
+ const storage = new StorageManager(dir);
19
+ await storage.ensureDirectories();
20
+ const first = await storage.saveDroppedExtractionChunk("same-key", "first", [makeTurn("one")]);
21
+ const second = await storage.saveDroppedExtractionChunk("same-key", "second", [makeTurn("two")]);
22
+
23
+ assert.notEqual(first, second);
24
+ const files = await readdir(path.dirname(first));
25
+ assert.equal(files.length, 2, "both safety copies exist");
26
+ } finally {
27
+ Date.now = realNow;
28
+ await rm(dir, { recursive: true, force: true });
29
+ }
30
+ });
package/src/storage.ts CHANGED
@@ -144,6 +144,7 @@ import {
144
144
  import { supersessionKeysForFact } from "./temporal-supersession.js";
145
145
  import { BufferSessionFiles } from "./storage/buffer-session-files.js";
146
146
  import { runSupersessionSideEffects, type SupersessionAuditOptions } from "./storage/supersession-side-effects.js";
147
+ import { saveDroppedExtractionChunk as saveDroppedChunk } from "./storage/dropped-extraction-chunk.js";
147
148
  import type {
148
149
  AccessTrackingEntry,
149
150
  BufferEntryState,
@@ -4799,7 +4800,6 @@ export class StorageManager extends TombstoneBlockedCaptureIndexHost {
4799
4800
  return results.filter((filePath): filePath is string => filePath !== null);
4800
4801
  }
4801
4802
 
4802
-
4803
4803
  private orderWindowPaths(filePaths: string[]): string[] {
4804
4804
  const correctionPaths: string[] = [];
4805
4805
  const factPaths: string[] = [];
@@ -5520,6 +5520,9 @@ export class StorageManager extends TombstoneBlockedCaptureIndexHost {
5520
5520
  async saveBuffer(state: BufferState): Promise<void> { await this.bufferSessionFiles().reconcile(state); }
5521
5521
  async saveBufferSession(key: string, entry: BufferEntryState): Promise<void> { await this.bufferSessionFiles().save(key, entry); }
5522
5522
  async deleteBufferSession(key: string): Promise<void> { await this.bufferSessionFiles().remove(key); }
5523
+ saveDroppedExtractionChunk(bufferKey: string, reason: string, turns: readonly import("./types.js").BufferTurn[]): Promise<string> { // storage/dropped-extraction-chunk.ts
5524
+ return saveDroppedChunk(this.stateDir, (file, content) => this.writeStorageSecureFile(file, content), bufferKey, reason, turns);
5525
+ }
5523
5526
 
5524
5527
  async loadMeta(): Promise<MetaState> {
5525
5528
  const metaPath = path.join(this.stateDir, "meta.json");
@@ -5564,8 +5567,7 @@ export class StorageManager extends TombstoneBlockedCaptureIndexHost {
5564
5567
 
5565
5568
  async saveMeta(state: MetaState): Promise<void> {
5566
5569
  await this.ensureDirectories();
5567
- const metaPath = path.join(this.stateDir, "meta.json");
5568
- await this.writeStorageSecureFile(metaPath, JSON.stringify(state, null, 2));
5570
+ await this.writeStorageSecureFile(path.join(this.stateDir, "meta.json"), JSON.stringify(state, null, 2));
5569
5571
  }
5570
5572
 
5571
5573
  async appendMemoryActionEvents(events: MemoryActionEvent[]): Promise<number> {
@@ -7208,10 +7210,7 @@ export class StorageManager extends TombstoneBlockedCaptureIndexHost {
7208
7210
  async saveTopics(topics: TopicScore[]): Promise<void> {
7209
7211
  const metaPath = path.join(this.stateDir, "topics.json");
7210
7212
  await mkdir(this.stateDir, { recursive: true });
7211
- await this.writeStorageSecureFile(
7212
- metaPath,
7213
- JSON.stringify({ topics, updatedAt: new Date().toISOString() }, null, 2)
7214
- );
7213
+ await this.writeStorageSecureFile(metaPath, JSON.stringify({ topics, updatedAt: new Date().toISOString() }, null, 2));
7215
7214
  log.debug(`saved ${topics.length} topic scores`);
7216
7215
  }
7217
7216
 
package/src/types.ts CHANGED
@@ -1697,6 +1697,13 @@ export interface PluginConfig
1697
1697
  extractionBreakerCooldownMs: number;
1698
1698
  /** Breaker open cooldown (ms) for auth/config failures (longer — provider is misconfigured). */
1699
1699
  extractionBreakerAuthCooldownMs: number;
1700
+ /**
1701
+ * Consecutive failed extraction attempts after which the failing
1702
+ * trigger-drain chunk is dropped (with a side-file copy under
1703
+ * `state/dropped/`) so a session whose window never extracts cannot stall
1704
+ * the buffer forever. Default: `5`.
1705
+ */
1706
+ extractionChunkDropAfterFailures: number;
1700
1707
  // Local LLM fast tier (v9.1) — smaller model for quick ops
1701
1708
  localLlmFastEnabled: boolean;
1702
1709
  localLlmFastModel: string;