@remnic/core 10.0.193 → 10.0.195

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 (277) hide show
  1. package/dist/access-admin-ops-surface.js +58 -59
  2. package/dist/access-cli.js +58 -59
  3. package/dist/access-cli.js.map +1 -1
  4. package/dist/access-extraction-force-flush-preempt.js +58 -59
  5. package/dist/access-extraction-force-flush.js +58 -59
  6. package/dist/access-http-briefing.js +58 -59
  7. package/dist/access-http-query.js +58 -59
  8. package/dist/access-http.js +58 -59
  9. package/dist/access-identity-continuity-surface.js +58 -59
  10. package/dist/access-lcm-surface.js +58 -59
  11. package/dist/access-mcp.js +58 -59
  12. package/dist/access-observe-write-surface.js +58 -59
  13. package/dist/access-operations-batch.js +58 -59
  14. package/dist/access-operations.js +58 -59
  15. package/dist/access-recall-concurrency.js +58 -59
  16. package/dist/access-recall-diagnostics.js +2 -2
  17. package/dist/access-recall-response.js +58 -59
  18. package/dist/access-recall-surface.js +58 -59
  19. package/dist/access-service.js +58 -59
  20. package/dist/active-recall.js +7 -6
  21. package/dist/active-recall.js.map +1 -1
  22. package/dist/{auto-sync-BJUAGKI5.js → auto-sync-BEW65FDT.js} +6 -5
  23. package/dist/{auto-sync-BJUAGKI5.js.map → auto-sync-BEW65FDT.js.map} +1 -1
  24. package/dist/briefing.js +7 -6
  25. package/dist/buffer.d.ts +1 -0
  26. package/dist/buffer.d.ts.map +1 -1
  27. package/dist/buffer.js +3 -3
  28. package/dist/calibration.js +5 -4
  29. package/dist/calibration.js.map +1 -1
  30. package/dist/causal-consolidation.js +8 -7
  31. package/dist/causal-consolidation.js.map +1 -1
  32. package/dist/{chunk-FZU62GIV.js → chunk-2X5I5C3M.js} +27 -10
  33. package/dist/chunk-2X5I5C3M.js.map +1 -0
  34. package/dist/{chunk-DYUPSTCV.js → chunk-3EXG2KPK.js} +3 -3
  35. package/dist/{chunk-FGFU6J26.js → chunk-4FTYKZ77.js} +3 -3
  36. package/dist/{chunk-4EAVEDLG.js → chunk-4GVSMPBP.js} +8 -8
  37. package/dist/{chunk-QIPRDRGM.js → chunk-4HEJDVPU.js} +1 -1
  38. package/dist/chunk-4HEJDVPU.js.map +1 -0
  39. package/dist/{chunk-EEA2RM4B.js → chunk-4I6A3SDL.js} +2 -2
  40. package/dist/{chunk-SKJM4PKE.js → chunk-4JI5PPFW.js} +2 -2
  41. package/dist/{chunk-TDG5NZAZ.js → chunk-65JA7LWV.js} +2 -2
  42. package/dist/{chunk-3YID7KZ6.js → chunk-6QMKUWXH.js} +2 -2
  43. package/dist/{chunk-7SOKOEAZ.js → chunk-6RRHTHKQ.js} +2 -2
  44. package/dist/{chunk-VHQNJW4Q.js → chunk-6W62D4MC.js} +2 -2
  45. package/dist/{chunk-2QW5HPKU.js → chunk-76LBLH62.js} +35 -28
  46. package/dist/chunk-76LBLH62.js.map +1 -0
  47. package/dist/{chunk-NN3LMWKA.js → chunk-7TQ3EDQ3.js} +1 -1
  48. package/dist/chunk-7TQ3EDQ3.js.map +1 -0
  49. package/dist/{chunk-KJ65WZHB.js → chunk-A7DIZOTF.js} +2 -2
  50. package/dist/{chunk-TZ7ZA2LM.js → chunk-AD3JOG2Q.js} +2 -2
  51. package/dist/{chunk-KZ4BJRGQ.js → chunk-BD26CK6T.js} +2 -2
  52. package/dist/{chunk-BDFSVUUZ.js → chunk-C3H2QZOZ.js} +2 -1
  53. package/dist/chunk-C3H2QZOZ.js.map +1 -0
  54. package/dist/{chunk-7EP4FURO.js → chunk-C72YQM7E.js} +2 -2
  55. package/dist/{chunk-CJSTQNE5.js → chunk-CTOMDCCA.js} +2 -2
  56. package/dist/{chunk-PSQ347YP.js → chunk-DSKII2W4.js} +3 -3
  57. package/dist/{chunk-KOVQZJ27.js → chunk-E7LDTUWK.js} +2 -2
  58. package/dist/{chunk-SPAKBUJY.js → chunk-EWLMEYLF.js} +2 -2
  59. package/dist/{chunk-3BICT225.js → chunk-FGNBUUPX.js} +2 -2
  60. package/dist/{chunk-QZMGZBTF.js → chunk-HBG6CQEX.js} +2 -2
  61. package/dist/{chunk-FKHXXL42.js → chunk-HD7M55OI.js} +2 -2
  62. package/dist/{chunk-7V6GNQC2.js → chunk-HINQENZG.js} +2 -2
  63. package/dist/{chunk-WRVKI6ZO.js → chunk-HLQXSX4F.js} +2 -2
  64. package/dist/{chunk-T765HQ5U.js → chunk-IIDAN7XJ.js} +2 -2
  65. package/dist/{chunk-G2MS56KM.js → chunk-IT4G6HTG.js} +2 -2
  66. package/dist/{chunk-M7Q7Z6V5.js → chunk-JDZ5JPYG.js} +38 -8
  67. package/dist/chunk-JDZ5JPYG.js.map +1 -0
  68. package/dist/{chunk-MMRTPH3J.js → chunk-KQYGUFMQ.js} +5 -3
  69. package/dist/chunk-KQYGUFMQ.js.map +1 -0
  70. package/dist/{chunk-TWYYUMYO.js → chunk-KXAGZRJV.js} +2 -2
  71. package/dist/{chunk-JITK24KX.js → chunk-LJNCJK7B.js} +10 -10
  72. package/dist/{chunk-Z6EFSXU3.js → chunk-LMM2LRVQ.js} +2 -2
  73. package/dist/{chunk-V65H7MI6.js → chunk-M42UFQZY.js} +51 -4
  74. package/dist/chunk-M42UFQZY.js.map +1 -0
  75. package/dist/{chunk-UAEJKURK.js → chunk-ME63JKWJ.js} +61 -59
  76. package/dist/{chunk-UAEJKURK.js.map → chunk-ME63JKWJ.js.map} +1 -1
  77. package/dist/{chunk-AALJHIKH.js → chunk-OHJ5PNYB.js} +3 -3
  78. package/dist/{chunk-XZMQLON4.js → chunk-OK726OF4.js} +7 -5
  79. package/dist/chunk-OK726OF4.js.map +1 -0
  80. package/dist/{chunk-Q6S67LHR.js → chunk-OOMFFMX3.js} +2 -2
  81. package/dist/{chunk-ODI4K32P.js → chunk-Q2GDUJSK.js} +5 -5
  82. package/dist/{chunk-JNDMIAJ4.js → chunk-QEVZKJM6.js} +2 -2
  83. package/dist/{chunk-ZNCCX7P6.js → chunk-QW5LZTKA.js} +2 -2
  84. package/dist/{chunk-5GIYIYJI.js → chunk-QZPAOOU7.js} +2 -2
  85. package/dist/{chunk-NKHRIDYP.js → chunk-RTXW6E6X.js} +3 -3
  86. package/dist/{chunk-5WDUY2ZZ.js → chunk-S4QWAWR6.js} +4 -4
  87. package/dist/{chunk-STSORBX5.js → chunk-SFUS2V2V.js} +1 -1
  88. package/dist/{chunk-HEJFE3BC.js → chunk-SJCN7ESG.js} +2 -2
  89. package/dist/{chunk-AJ7JHHRY.js → chunk-SPPWVMP4.js} +2 -2
  90. package/dist/{chunk-QSF5SJAM.js → chunk-STQNKDKZ.js} +9 -3
  91. package/dist/chunk-STQNKDKZ.js.map +1 -0
  92. package/dist/{chunk-QFKNIKUF.js → chunk-SXR7L57Z.js} +2 -2
  93. package/dist/{chunk-GYCUX3N4.js → chunk-TGMIJABS.js} +2 -2
  94. package/dist/{chunk-GH7IKABD.js → chunk-UFJJMQDV.js} +2 -2
  95. package/dist/{chunk-UH2VY2QQ.js → chunk-WCW7I7ZM.js} +2 -2
  96. package/dist/{chunk-3RZ4GDOH.js → chunk-XDNVWY7I.js} +93 -23
  97. package/dist/chunk-XDNVWY7I.js.map +1 -0
  98. package/dist/{chunk-LR6LWX33.js → chunk-XXDIPAUE.js} +2 -2
  99. package/dist/{chunk-YCJJODER.js → chunk-YCTD3XET.js} +10 -3
  100. package/dist/chunk-YCTD3XET.js.map +1 -0
  101. package/dist/{chunk-WEI6HEUX.js → chunk-YXAH5TSN.js} +2 -2
  102. package/dist/{chunk-75K6DRPN.js → chunk-ZAVFAGBE.js} +2 -2
  103. package/dist/{chunk-7KTORRIK.js → chunk-ZNJU3NBJ.js} +2 -2
  104. package/dist/cli.js +58 -59
  105. package/dist/coding/export-okf-codegraph.js +6 -5
  106. package/dist/coding/export-okf-codegraph.js.map +1 -1
  107. package/dist/compounding/engine.js +8 -7
  108. package/dist/config.d.ts.map +1 -1
  109. package/dist/config.js +7 -6
  110. package/dist/connectors/codex-materialize-runner.js +7 -6
  111. package/dist/connectors/index.js +7 -6
  112. package/dist/convergence-refresh.js +9 -8
  113. package/dist/corpus-watermark.js +9 -8
  114. package/dist/deep-recall-policy-llm.js +4 -3
  115. package/dist/entity-retrieval.js +7 -6
  116. package/dist/explicit-capture.js +58 -59
  117. package/dist/extraction-error-classification.d.ts +40 -5
  118. package/dist/extraction-error-classification.d.ts.map +1 -1
  119. package/dist/extraction-error-classification.js +5 -2
  120. package/dist/extraction-faithfulness.js +4 -3
  121. package/dist/extraction-judge.js +4 -3
  122. package/dist/extraction.d.ts.map +1 -1
  123. package/dist/extraction.js +17 -18
  124. package/dist/fallback-llm-codex-subscription.d.ts +3 -1
  125. package/dist/fallback-llm-codex-subscription.d.ts.map +1 -1
  126. package/dist/fallback-llm-codex-subscription.js +2 -1
  127. package/dist/fallback-llm.d.ts.map +1 -1
  128. package/dist/fallback-llm.js +3 -2
  129. package/dist/harmonic-retrieval.js +7 -6
  130. package/dist/index.js +58 -59
  131. package/dist/live-connectors-runner.js +1 -2
  132. package/dist/local-llm-helpers.d.ts +1 -0
  133. package/dist/local-llm-helpers.d.ts.map +1 -1
  134. package/dist/local-llm-helpers.js +1 -1
  135. package/dist/local-llm.d.ts.map +1 -1
  136. package/dist/local-llm.js +4 -3
  137. package/dist/location/index.js +8 -7
  138. package/dist/maintenance/memory-governance.js +7 -6
  139. package/dist/maintenance/rebuild-memory-lifecycle-ledger.js +7 -6
  140. package/dist/maintenance/rebuild-memory-projection-runner.js +9 -8
  141. package/dist/maintenance/rebuild-memory-projection.js +8 -7
  142. package/dist/memory-browse.js +3 -3
  143. package/dist/namespaces/migrate.js +8 -7
  144. package/dist/namespaces/storage.js +7 -6
  145. package/dist/operator-doctor-corpus.js +10 -9
  146. package/dist/operator-toolkit.js +14 -13
  147. package/dist/orchestration/backlog-scheduler.js +59 -60
  148. package/dist/orchestration/backlog-scheduler.js.map +1 -1
  149. package/dist/orchestration/buffer-drain-runner.js +59 -60
  150. package/dist/orchestration/extraction-drain.d.ts +1 -0
  151. package/dist/orchestration/extraction-drain.d.ts.map +1 -1
  152. package/dist/orchestration/extraction-persist-failure.d.ts +0 -2
  153. package/dist/orchestration/extraction-persist-failure.d.ts.map +1 -1
  154. package/dist/orchestration/extraction-persist.d.ts +6 -2
  155. package/dist/orchestration/extraction-persist.d.ts.map +1 -1
  156. package/dist/orchestration/extraction-run-helpers.d.ts +41 -4
  157. package/dist/orchestration/extraction-run-helpers.d.ts.map +1 -1
  158. package/dist/orchestration/extraction-run.d.ts +4 -0
  159. package/dist/orchestration/extraction-run.d.ts.map +1 -1
  160. package/dist/orchestration/maintenance.js +17 -16
  161. package/dist/orchestrator.js +58 -59
  162. package/dist/recall-explain-renderer.js +3 -3
  163. package/dist/recall-navigate-access.js +2 -2
  164. package/dist/recall-navigate-disclosure.js +2 -2
  165. package/dist/recall-navigate.js +2 -2
  166. package/dist/recall-navigation.js +58 -59
  167. package/dist/recall-planner-llm.js +3 -2
  168. package/dist/recall-planner-llm.js.map +1 -1
  169. package/dist/recall-state-view-admission.js +3 -3
  170. package/dist/recall-why-service.js +3 -3
  171. package/dist/recall-xray-cli.js +4 -4
  172. package/dist/recall-xray-renderer.js +3 -3
  173. package/dist/recall-xray.js +2 -2
  174. package/dist/resume-bundles.js +8 -7
  175. package/dist/semantic-consolidation.js +8 -7
  176. package/dist/semantic-rule-promotion.js +7 -6
  177. package/dist/semantic-rule-verifier.js +7 -6
  178. package/dist/source-agent-qualifier.js +10 -9
  179. package/dist/standup/build.js +7 -6
  180. package/dist/storage.d.ts.map +1 -1
  181. package/dist/storage.js +6 -5
  182. package/dist/summarizer.js +6 -5
  183. package/dist/support-passport/index.js +6 -5
  184. package/dist/transfer/export-okf.js +7 -6
  185. package/dist/types-extraction-failure.d.ts +7 -1
  186. package/dist/types-extraction-failure.d.ts.map +1 -1
  187. package/dist/types.d.ts +6 -6
  188. package/dist/types.d.ts.map +1 -1
  189. package/dist/types.js +1 -1
  190. package/dist/verified-recall.js +7 -6
  191. package/dist/who-knows-cli.js +8 -7
  192. package/dist/who-knows.js +7 -6
  193. package/package.json +2 -2
  194. package/src/buffer-incremental-persistence.test.ts +23 -0
  195. package/src/buffer.ts +30 -28
  196. package/src/config.ts +2 -0
  197. package/src/extraction-error-classification.ts +88 -8
  198. package/src/extraction-local-failure-class.test.ts +117 -3
  199. package/src/extraction-reply-diagnostic-wiring.test.ts +3 -1
  200. package/src/extraction.test.ts +73 -3
  201. package/src/extraction.ts +26 -25
  202. package/src/fallback-llm-codex-subscription.ts +17 -3
  203. package/src/fallback-llm.test.ts +70 -0
  204. package/src/fallback-llm.ts +17 -18
  205. package/src/local-llm-headers-timeout.test.ts +151 -0
  206. package/src/local-llm-helpers.ts +1 -1
  207. package/src/local-llm.ts +44 -43
  208. package/src/orchestration/extraction-drain.ts +11 -5
  209. package/src/orchestration/extraction-persist-declaration.test.ts +35 -0
  210. package/src/orchestration/extraction-persist-failure.ts +0 -3
  211. package/src/orchestration/extraction-persist.ts +3 -3
  212. package/src/orchestration/extraction-run-helpers.ts +110 -4
  213. package/src/orchestration/extraction-run.test.ts +408 -3
  214. package/src/orchestration/extraction-run.ts +75 -75
  215. package/src/storage.ts +5 -4
  216. package/src/types-extraction-failure.ts +12 -1
  217. package/src/types.ts +6 -6
  218. package/dist/chunk-2QW5HPKU.js.map +0 -1
  219. package/dist/chunk-3RZ4GDOH.js.map +0 -1
  220. package/dist/chunk-BDFSVUUZ.js.map +0 -1
  221. package/dist/chunk-C7SRUWBW.js +0 -54
  222. package/dist/chunk-C7SRUWBW.js.map +0 -1
  223. package/dist/chunk-FZU62GIV.js.map +0 -1
  224. package/dist/chunk-M7Q7Z6V5.js.map +0 -1
  225. package/dist/chunk-MMRTPH3J.js.map +0 -1
  226. package/dist/chunk-NN3LMWKA.js.map +0 -1
  227. package/dist/chunk-QIPRDRGM.js.map +0 -1
  228. package/dist/chunk-QSF5SJAM.js.map +0 -1
  229. package/dist/chunk-V65H7MI6.js.map +0 -1
  230. package/dist/chunk-XZMQLON4.js.map +0 -1
  231. package/dist/chunk-YCJJODER.js.map +0 -1
  232. /package/dist/{chunk-DYUPSTCV.js.map → chunk-3EXG2KPK.js.map} +0 -0
  233. /package/dist/{chunk-FGFU6J26.js.map → chunk-4FTYKZ77.js.map} +0 -0
  234. /package/dist/{chunk-4EAVEDLG.js.map → chunk-4GVSMPBP.js.map} +0 -0
  235. /package/dist/{chunk-EEA2RM4B.js.map → chunk-4I6A3SDL.js.map} +0 -0
  236. /package/dist/{chunk-SKJM4PKE.js.map → chunk-4JI5PPFW.js.map} +0 -0
  237. /package/dist/{chunk-TDG5NZAZ.js.map → chunk-65JA7LWV.js.map} +0 -0
  238. /package/dist/{chunk-3YID7KZ6.js.map → chunk-6QMKUWXH.js.map} +0 -0
  239. /package/dist/{chunk-7SOKOEAZ.js.map → chunk-6RRHTHKQ.js.map} +0 -0
  240. /package/dist/{chunk-VHQNJW4Q.js.map → chunk-6W62D4MC.js.map} +0 -0
  241. /package/dist/{chunk-KJ65WZHB.js.map → chunk-A7DIZOTF.js.map} +0 -0
  242. /package/dist/{chunk-TZ7ZA2LM.js.map → chunk-AD3JOG2Q.js.map} +0 -0
  243. /package/dist/{chunk-KZ4BJRGQ.js.map → chunk-BD26CK6T.js.map} +0 -0
  244. /package/dist/{chunk-7EP4FURO.js.map → chunk-C72YQM7E.js.map} +0 -0
  245. /package/dist/{chunk-CJSTQNE5.js.map → chunk-CTOMDCCA.js.map} +0 -0
  246. /package/dist/{chunk-PSQ347YP.js.map → chunk-DSKII2W4.js.map} +0 -0
  247. /package/dist/{chunk-KOVQZJ27.js.map → chunk-E7LDTUWK.js.map} +0 -0
  248. /package/dist/{chunk-SPAKBUJY.js.map → chunk-EWLMEYLF.js.map} +0 -0
  249. /package/dist/{chunk-3BICT225.js.map → chunk-FGNBUUPX.js.map} +0 -0
  250. /package/dist/{chunk-QZMGZBTF.js.map → chunk-HBG6CQEX.js.map} +0 -0
  251. /package/dist/{chunk-FKHXXL42.js.map → chunk-HD7M55OI.js.map} +0 -0
  252. /package/dist/{chunk-7V6GNQC2.js.map → chunk-HINQENZG.js.map} +0 -0
  253. /package/dist/{chunk-WRVKI6ZO.js.map → chunk-HLQXSX4F.js.map} +0 -0
  254. /package/dist/{chunk-T765HQ5U.js.map → chunk-IIDAN7XJ.js.map} +0 -0
  255. /package/dist/{chunk-G2MS56KM.js.map → chunk-IT4G6HTG.js.map} +0 -0
  256. /package/dist/{chunk-TWYYUMYO.js.map → chunk-KXAGZRJV.js.map} +0 -0
  257. /package/dist/{chunk-JITK24KX.js.map → chunk-LJNCJK7B.js.map} +0 -0
  258. /package/dist/{chunk-Z6EFSXU3.js.map → chunk-LMM2LRVQ.js.map} +0 -0
  259. /package/dist/{chunk-AALJHIKH.js.map → chunk-OHJ5PNYB.js.map} +0 -0
  260. /package/dist/{chunk-Q6S67LHR.js.map → chunk-OOMFFMX3.js.map} +0 -0
  261. /package/dist/{chunk-ODI4K32P.js.map → chunk-Q2GDUJSK.js.map} +0 -0
  262. /package/dist/{chunk-JNDMIAJ4.js.map → chunk-QEVZKJM6.js.map} +0 -0
  263. /package/dist/{chunk-ZNCCX7P6.js.map → chunk-QW5LZTKA.js.map} +0 -0
  264. /package/dist/{chunk-5GIYIYJI.js.map → chunk-QZPAOOU7.js.map} +0 -0
  265. /package/dist/{chunk-NKHRIDYP.js.map → chunk-RTXW6E6X.js.map} +0 -0
  266. /package/dist/{chunk-5WDUY2ZZ.js.map → chunk-S4QWAWR6.js.map} +0 -0
  267. /package/dist/{chunk-STSORBX5.js.map → chunk-SFUS2V2V.js.map} +0 -0
  268. /package/dist/{chunk-HEJFE3BC.js.map → chunk-SJCN7ESG.js.map} +0 -0
  269. /package/dist/{chunk-AJ7JHHRY.js.map → chunk-SPPWVMP4.js.map} +0 -0
  270. /package/dist/{chunk-QFKNIKUF.js.map → chunk-SXR7L57Z.js.map} +0 -0
  271. /package/dist/{chunk-GYCUX3N4.js.map → chunk-TGMIJABS.js.map} +0 -0
  272. /package/dist/{chunk-GH7IKABD.js.map → chunk-UFJJMQDV.js.map} +0 -0
  273. /package/dist/{chunk-UH2VY2QQ.js.map → chunk-WCW7I7ZM.js.map} +0 -0
  274. /package/dist/{chunk-LR6LWX33.js.map → chunk-XXDIPAUE.js.map} +0 -0
  275. /package/dist/{chunk-WEI6HEUX.js.map → chunk-YXAH5TSN.js.map} +0 -0
  276. /package/dist/{chunk-75K6DRPN.js.map → chunk-ZAVFAGBE.js.map} +0 -0
  277. /package/dist/{chunk-7KTORRIK.js.map → chunk-ZNJU3NBJ.js.map} +0 -0
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  BufferDrainRunner
3
- } from "../chunk-ODI4K32P.js";
4
- import "../chunk-UAEJKURK.js";
3
+ } from "../chunk-Q2GDUJSK.js";
4
+ import "../chunk-ME63JKWJ.js";
5
5
  import "../chunk-GOZXQNIM.js";
6
6
  import "../chunk-PQM3B54K.js";
7
- import "../chunk-7KTORRIK.js";
7
+ import "../chunk-ZNJU3NBJ.js";
8
8
  import "../chunk-MMACM5G2.js";
9
9
  import "../chunk-54BGIBCR.js";
10
10
  import "../chunk-H4CKS5B2.js";
@@ -12,7 +12,7 @@ import "../chunk-FXZTL7F7.js";
12
12
  import "../chunk-W4F3C7N7.js";
13
13
  import "../chunk-MPC7TYTZ.js";
14
14
  import "../chunk-UP6MOYCB.js";
15
- import "../chunk-EEA2RM4B.js";
15
+ import "../chunk-4I6A3SDL.js";
16
16
  import "../chunk-BV2TIZ4F.js";
17
17
  import "../chunk-W5LJ3SJ7.js";
18
18
  import "../chunk-PYHOAXTI.js";
@@ -25,11 +25,11 @@ import "../chunk-765K3SAT.js";
25
25
  import "../chunk-NOKHMWMW.js";
26
26
  import "../chunk-QV2VZKD5.js";
27
27
  import "../chunk-IFBSZGW3.js";
28
- import "../chunk-QFKNIKUF.js";
29
- import "../chunk-NKHRIDYP.js";
28
+ import "../chunk-SXR7L57Z.js";
29
+ import "../chunk-RTXW6E6X.js";
30
30
  import "../chunk-TBUEE7XF.js";
31
31
  import "../chunk-5OBYISRA.js";
32
- import "../chunk-JITK24KX.js";
32
+ import "../chunk-LJNCJK7B.js";
33
33
  import "../chunk-WTXUUZYI.js";
34
34
  import "../chunk-IMA4DJ7K.js";
35
35
  import "../chunk-FGDKJJZS.js";
@@ -38,11 +38,11 @@ import "../chunk-VZAKYDMJ.js";
38
38
  import "../chunk-SZDLX763.js";
39
39
  import "../chunk-PYIFUBRK.js";
40
40
  import "../chunk-6PEEZSGL.js";
41
- import "../chunk-SKJM4PKE.js";
42
- import "../chunk-KJ65WZHB.js";
41
+ import "../chunk-4JI5PPFW.js";
42
+ import "../chunk-A7DIZOTF.js";
43
43
  import "../chunk-2X4WP4GD.js";
44
44
  import "../chunk-QO5WYRK2.js";
45
- import "../chunk-AALJHIKH.js";
45
+ import "../chunk-OHJ5PNYB.js";
46
46
  import "../chunk-SBQOBY3S.js";
47
47
  import "../chunk-666A3MOW.js";
48
48
  import "../chunk-RZN4LQ5Y.js";
@@ -60,7 +60,7 @@ import "../chunk-2YJ2ST23.js";
60
60
  import "../chunk-TECVW3JP.js";
61
61
  import "../chunk-C5JF6EZ7.js";
62
62
  import "../chunk-KBL3JJR6.js";
63
- import "../chunk-FGFU6J26.js";
63
+ import "../chunk-4FTYKZ77.js";
64
64
  import "../chunk-DPPIBEGC.js";
65
65
  import "../chunk-VOVSZYCP.js";
66
66
  import "../chunk-XC4PRJWM.js";
@@ -78,15 +78,15 @@ import "../chunk-ZTJPFACY.js";
78
78
  import "../chunk-HCAGBFE7.js";
79
79
  import "../chunk-SI36RWC3.js";
80
80
  import "../chunk-NJAIR57U.js";
81
- import "../chunk-VHQNJW4Q.js";
82
- import "../chunk-TWYYUMYO.js";
81
+ import "../chunk-6W62D4MC.js";
82
+ import "../chunk-KXAGZRJV.js";
83
83
  import "../chunk-BANSBRNX.js";
84
84
  import "../chunk-TB6CBZ5V.js";
85
85
  import "../chunk-47DU4SGJ.js";
86
86
  import "../chunk-W2E2WFXL.js";
87
87
  import "../chunk-PRRWKTK6.js";
88
88
  import "../chunk-EOU6V4IN.js";
89
- import "../chunk-UH2VY2QQ.js";
89
+ import "../chunk-WCW7I7ZM.js";
90
90
  import "../chunk-HL4DB7TO.js";
91
91
  import "../chunk-GNVZQ5JN.js";
92
92
  import "../chunk-YN2UN7N3.js";
@@ -98,16 +98,16 @@ import "../chunk-KVDUKH5E.js";
98
98
  import "../chunk-VHF73MGU.js";
99
99
  import "../chunk-4EX5WZ4M.js";
100
100
  import "../chunk-VHSQU3RO.js";
101
- import "../chunk-5WDUY2ZZ.js";
101
+ import "../chunk-S4QWAWR6.js";
102
102
  import "../chunk-HNOSWPKG.js";
103
103
  import "../chunk-77NTFICT.js";
104
104
  import "../chunk-LJLGH2DE.js";
105
105
  import "../chunk-ODZKV2F7.js";
106
106
  import "../chunk-WWDO7ZWM.js";
107
- import "../chunk-QZMGZBTF.js";
108
- import "../chunk-T765HQ5U.js";
107
+ import "../chunk-HBG6CQEX.js";
108
+ import "../chunk-IIDAN7XJ.js";
109
109
  import "../chunk-ZKE4CO6B.js";
110
- import "../chunk-7EP4FURO.js";
110
+ import "../chunk-C72YQM7E.js";
111
111
  import "../chunk-B2NXOVZN.js";
112
112
  import "../chunk-DTTDMK7Q.js";
113
113
  import "../chunk-GE5J2T67.js";
@@ -122,12 +122,12 @@ import "../chunk-X7XN6YU4.js";
122
122
  import "../chunk-FEYPXEKE.js";
123
123
  import "../chunk-WBOJMAAV.js";
124
124
  import "../chunk-2KHIBLO5.js";
125
- import "../chunk-G2MS56KM.js";
125
+ import "../chunk-IT4G6HTG.js";
126
126
  import "../chunk-5HFVWYHL.js";
127
- import "../chunk-PSQ347YP.js";
127
+ import "../chunk-DSKII2W4.js";
128
128
  import "../chunk-HDU3MIK3.js";
129
129
  import "../chunk-G2DF5MI7.js";
130
- import "../chunk-5GIYIYJI.js";
130
+ import "../chunk-QZPAOOU7.js";
131
131
  import "../chunk-DBB5JPSL.js";
132
132
  import "../chunk-3D75XIYO.js";
133
133
  import "../chunk-5KVT6G5U.js";
@@ -135,14 +135,14 @@ import "../chunk-5VMRM2X3.js";
135
135
  import "../chunk-TE6S7KDF.js";
136
136
  import "../chunk-GIL2M2OI.js";
137
137
  import "../chunk-KIW3OOZE.js";
138
- import "../chunk-3YID7KZ6.js";
138
+ import "../chunk-6QMKUWXH.js";
139
139
  import "../chunk-YE4JBZO5.js";
140
140
  import "../chunk-7O5EW7KX.js";
141
- import "../chunk-TDG5NZAZ.js";
141
+ import "../chunk-65JA7LWV.js";
142
142
  import "../chunk-SOBJ6NEY.js";
143
- import "../chunk-7SOKOEAZ.js";
143
+ import "../chunk-6RRHTHKQ.js";
144
144
  import "../chunk-IIK2PD3F.js";
145
- import "../chunk-WRVKI6ZO.js";
145
+ import "../chunk-HLQXSX4F.js";
146
146
  import "../chunk-VYDGHJIN.js";
147
147
  import "../chunk-H7XKCNR6.js";
148
148
  import "../chunk-DRXFLPSE.js";
@@ -153,13 +153,13 @@ import "../chunk-HAB7LLE7.js";
153
153
  import "../chunk-MNDIM6JB.js";
154
154
  import "../chunk-E5IZTY4W.js";
155
155
  import "../chunk-ROI7BK7H.js";
156
- import "../chunk-4EAVEDLG.js";
157
- import "../chunk-3BICT225.js";
156
+ import "../chunk-4GVSMPBP.js";
157
+ import "../chunk-FGNBUUPX.js";
158
158
  import "../chunk-KFY3SGN7.js";
159
159
  import "../chunk-3T74IZB3.js";
160
160
  import "../chunk-CMTINOFS.js";
161
161
  import "../chunk-ZNYDDZVW.js";
162
- import "../chunk-TZ7ZA2LM.js";
162
+ import "../chunk-AD3JOG2Q.js";
163
163
  import "../chunk-AQZL7JBZ.js";
164
164
  import "../chunk-2TJSGIKT.js";
165
165
  import "../chunk-UD7UNYRD.js";
@@ -170,14 +170,14 @@ import "../chunk-3GPTTA4J.js";
170
170
  import "../chunk-IISBCCWR.js";
171
171
  import "../chunk-EIB4FJVR.js";
172
172
  import "../chunk-4IMOGAFF.js";
173
- import "../chunk-KZ4BJRGQ.js";
174
- import "../chunk-ZNCCX7P6.js";
173
+ import "../chunk-BD26CK6T.js";
174
+ import "../chunk-QW5LZTKA.js";
175
175
  import "../chunk-WGKIXNLY.js";
176
176
  import "../chunk-E4RMZGRS.js";
177
177
  import "../chunk-MZUQVWVC.js";
178
178
  import "../chunk-M4DB6ZNN.js";
179
179
  import "../chunk-XUVCQ4YZ.js";
180
- import "../chunk-V65H7MI6.js";
180
+ import "../chunk-M42UFQZY.js";
181
181
  import "../chunk-MDPT6QFK.js";
182
182
  import "../chunk-3HSRWJTC.js";
183
183
  import "../chunk-3TKX7ZMV.js";
@@ -186,7 +186,7 @@ import "../chunk-UOBPK2OS.js";
186
186
  import "../chunk-2YA5N2BY.js";
187
187
  import "../chunk-YLTU2DC4.js";
188
188
  import "../chunk-OLD2GKQJ.js";
189
- import "../chunk-75K6DRPN.js";
189
+ import "../chunk-ZAVFAGBE.js";
190
190
  import "../chunk-GXL52YZA.js";
191
191
  import "../chunk-AZEZSQ5R.js";
192
192
  import "../chunk-JA2GJCOS.js";
@@ -194,9 +194,9 @@ import "../chunk-UH3FPX3L.js";
194
194
  import "../chunk-XXSOVESA.js";
195
195
  import "../chunk-PHRLJFWZ.js";
196
196
  import "../chunk-64NJRYU2.js";
197
- import "../chunk-2QW5HPKU.js";
197
+ import "../chunk-76LBLH62.js";
198
198
  import "../chunk-EI6V5UXY.js";
199
- import "../chunk-FKHXXL42.js";
199
+ import "../chunk-HD7M55OI.js";
200
200
  import "../chunk-NIIWKDIU.js";
201
201
  import "../chunk-ZWOYG256.js";
202
202
  import "../chunk-54V4BZWP.js";
@@ -216,14 +216,12 @@ import "../chunk-FNV6ZPCY.js";
216
216
  import "../chunk-ULLGI6XR.js";
217
217
  import "../chunk-PT4DZDJA.js";
218
218
  import "../chunk-PWFCHOB3.js";
219
- import "../chunk-Q6S67LHR.js";
219
+ import "../chunk-OOMFFMX3.js";
220
220
  import "../chunk-DR4TYD56.js";
221
221
  import "../chunk-MLAMXQAW.js";
222
222
  import "../chunk-AIYXVWUH.js";
223
223
  import "../chunk-LTHVM4XN.js";
224
224
  import "../chunk-A5KNZSNA.js";
225
- import "../chunk-M7Q7Z6V5.js";
226
- import "../chunk-C7SRUWBW.js";
227
225
  import "../chunk-OZKOPQCM.js";
228
226
  import "../chunk-NED7IR7B.js";
229
227
  import "../chunk-YVVQUAOO.js";
@@ -240,7 +238,7 @@ import "../chunk-C37ZRXX7.js";
240
238
  import "../chunk-BUYVPUEM.js";
241
239
  import "../chunk-IAIPNEHD.js";
242
240
  import "../chunk-DGFU5MSX.js";
243
- import "../chunk-WEI6HEUX.js";
241
+ import "../chunk-YXAH5TSN.js";
244
242
  import "../chunk-NVKO5YKP.js";
245
243
  import "../chunk-GKUA4MGB.js";
246
244
  import "../chunk-CWOMCAUE.js";
@@ -260,16 +258,16 @@ import "../chunk-A6JDNYXE.js";
260
258
  import "../chunk-J66ZJW5U.js";
261
259
  import "../chunk-KQIOW3TG.js";
262
260
  import "../chunk-HUSTM6PU.js";
263
- import "../chunk-SPAKBUJY.js";
261
+ import "../chunk-EWLMEYLF.js";
264
262
  import "../chunk-RF2SMMPP.js";
265
263
  import "../chunk-3X5OPDPF.js";
266
264
  import "../chunk-4RASUAN3.js";
267
265
  import "../chunk-VZIAVM72.js";
268
266
  import "../chunk-HRATODNO.js";
269
267
  import "../chunk-WTWQA7BB.js";
270
- import "../chunk-CJSTQNE5.js";
271
- import "../chunk-HEJFE3BC.js";
272
- import "../chunk-AJ7JHHRY.js";
268
+ import "../chunk-CTOMDCCA.js";
269
+ import "../chunk-SJCN7ESG.js";
270
+ import "../chunk-SPPWVMP4.js";
273
271
  import "../chunk-UFGFMWAD.js";
274
272
  import "../chunk-BGA7S5EF.js";
275
273
  import "../chunk-EZ25VE3G.js";
@@ -277,18 +275,18 @@ import "../chunk-44442YCH.js";
277
275
  import "../chunk-AUDJPF4N.js";
278
276
  import "../chunk-Y4Z4I6WK.js";
279
277
  import "../chunk-4LCA2GEX.js";
280
- import "../chunk-GYCUX3N4.js";
281
- import "../chunk-DYUPSTCV.js";
278
+ import "../chunk-TGMIJABS.js";
279
+ import "../chunk-3EXG2KPK.js";
282
280
  import "../chunk-KJTKLXTH.js";
283
- import "../chunk-LR6LWX33.js";
281
+ import "../chunk-XXDIPAUE.js";
284
282
  import "../chunk-2DQ2XREU.js";
285
283
  import "../chunk-4NZQ7IID.js";
286
284
  import "../chunk-3I4FUAVJ.js";
287
285
  import "../chunk-OKTXM5H4.js";
288
286
  import "../chunk-D24OXEPB.js";
289
287
  import "../chunk-ZAJLJ35W.js";
290
- import "../chunk-GH7IKABD.js";
291
- import "../chunk-Z6EFSXU3.js";
288
+ import "../chunk-UFJJMQDV.js";
289
+ import "../chunk-LMM2LRVQ.js";
292
290
  import "../chunk-3UXOZBHV.js";
293
291
  import "../chunk-H3MLOQ7F.js";
294
292
  import "../chunk-5JMAGU26.js";
@@ -298,15 +296,15 @@ import "../chunk-2LSZVONP.js";
298
296
  import "../chunk-DEUNUKTD.js";
299
297
  import "../chunk-LXY5VVGM.js";
300
298
  import "../chunk-GKCXTSFF.js";
301
- import "../chunk-YCJJODER.js";
302
- import "../chunk-3RZ4GDOH.js";
303
- import "../chunk-STSORBX5.js";
299
+ import "../chunk-YCTD3XET.js";
300
+ import "../chunk-XDNVWY7I.js";
301
+ import "../chunk-SFUS2V2V.js";
304
302
  import "../chunk-CSAKJVXW.js";
305
303
  import "../chunk-TK6EBBKG.js";
306
304
  import "../chunk-K2XUWZBM.js";
307
305
  import "../chunk-OD4FM2U7.js";
308
- import "../chunk-FZU62GIV.js";
309
- import "../chunk-NN3LMWKA.js";
306
+ import "../chunk-2X5I5C3M.js";
307
+ import "../chunk-7TQ3EDQ3.js";
310
308
  import "../chunk-MJFL75J6.js";
311
309
  import "../chunk-GT2HWRST.js";
312
310
  import "../chunk-U4LUIE6Y.js";
@@ -322,7 +320,7 @@ import "../chunk-HK6KYIF6.js";
322
320
  import "../chunk-2GBFKHBZ.js";
323
321
  import "../chunk-6TBIWIAG.js";
324
322
  import "../chunk-B7RWBZXW.js";
325
- import "../chunk-KOVQZJ27.js";
323
+ import "../chunk-E7LDTUWK.js";
326
324
  import "../chunk-FNFURZBZ.js";
327
325
  import "../chunk-GZFKCLRC.js";
328
326
  import "../chunk-EKUI7I2X.js";
@@ -345,7 +343,7 @@ import "../chunk-43HUVDTD.js";
345
343
  import "../chunk-4RA3C3EV.js";
346
344
  import "../chunk-TOTT6S2V.js";
347
345
  import "../chunk-U4ECSKQE.js";
348
- import "../chunk-BDFSVUUZ.js";
346
+ import "../chunk-C3H2QZOZ.js";
349
347
  import "../chunk-ZKOPY4WW.js";
350
348
  import "../chunk-62OKGIJA.js";
351
349
  import "../chunk-J5WI4QRP.js";
@@ -388,7 +386,7 @@ import "../chunk-QDW3E4RD.js";
388
386
  import "../chunk-ZOJUWVAU.js";
389
387
  import "../chunk-ZJP66Q4I.js";
390
388
  import "../chunk-KFZY2OFH.js";
391
- import "../chunk-XZMQLON4.js";
389
+ import "../chunk-OK726OF4.js";
392
390
  import "../chunk-QGVCFVX6.js";
393
391
  import "../chunk-UHVXE24Y.js";
394
392
  import "../chunk-FDO7ITP6.js";
@@ -416,7 +414,7 @@ import "../chunk-L76BQSWB.js";
416
414
  import "../chunk-DM2T26WE.js";
417
415
  import "../chunk-LDXUBPMO.js";
418
416
  import "../chunk-UWVMD54T.js";
419
- import "../chunk-JNDMIAJ4.js";
417
+ import "../chunk-QEVZKJM6.js";
420
418
  import "../chunk-AAD2ZS6P.js";
421
419
  import "../chunk-ZIKENA2C.js";
422
420
  import "../chunk-YXZG5TVN.js";
@@ -442,11 +440,12 @@ import "../chunk-2WREX7KD.js";
442
440
  import "../chunk-S45VECVD.js";
443
441
  import "../chunk-XBJOO7G5.js";
444
442
  import "../chunk-23G5P7TA.js";
445
- import "../chunk-MMRTPH3J.js";
443
+ import "../chunk-KQYGUFMQ.js";
446
444
  import "../chunk-I55KAVET.js";
447
445
  import "../chunk-L2EXJQJP.js";
448
446
  import "../chunk-45GF7Y3V.js";
449
- import "../chunk-QSF5SJAM.js";
447
+ import "../chunk-STQNKDKZ.js";
448
+ import "../chunk-JDZ5JPYG.js";
450
449
  import "../chunk-E2AWJ7KQ.js";
451
450
  import {
452
451
  resolveMaxTurnsPerSession
@@ -460,11 +459,11 @@ import "../chunk-YCVB7X56.js";
460
459
  import "../chunk-B32WYRXX.js";
461
460
  import "../chunk-PQVCH2AE.js";
462
461
  import "../chunk-EMMUQUHF.js";
463
- import "../chunk-7V6GNQC2.js";
462
+ import "../chunk-HINQENZG.js";
464
463
  import "../chunk-2LWXBERZ.js";
465
464
  import "../chunk-NT7JD6D6.js";
466
465
  import "../chunk-CTVWELNK.js";
467
- import "../chunk-QIPRDRGM.js";
466
+ import "../chunk-4HEJDVPU.js";
468
467
  import "../chunk-YBA52OKG.js";
469
468
  import "../chunk-IUGOGDCP.js";
470
469
  import "../chunk-CQ3IG3GZ.js";
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/orchestration/backlog-scheduler.ts"],"sourcesContent":["/**\n * Daemon-owned extraction backlog scheduler.\n *\n * ONE bounded in-process loop that owns ALL persisted extraction backlog:\n * at startup (existing drain claims + buffered sessions), on every poll tick\n * (new persisted work), and by retrying keys that are still pending — with\n * bounded memory (per-key COUNTS only; candidate scans never retain turn\n * payloads) and bounded outstanding work (the extraction queue's own\n * maxConcurrency gates submissions, so live foreground work keeps its share\n * of the queue).\n *\n * Claim authority: an existing claim — including an EMPTY ack tombstone — is\n * authoritative over the live buffer's in-memory copy. A tombstoned key is\n * never re-claimed or counted as work; new ingress consumes the tombstone\n * through the native save handover, which is what makes the key a candidate\n * again. Claim creation is fenced: the key is reserved synchronously on the\n * extraction queue BEFORE the async claim decision, so a queued live task for\n * the same key cannot start past the claimed-session gate until the decision\n * settles; live capture continues via the native merge-into-claim protocol.\n *\n * Failed, deferred, or policy-denied outcomes keep their turns durable in the\n * claim and re-submit after backoff (exponential from `retryBaseMs` to\n * `retryMaxMs`, reset by progress; denials wait the full max) — never a busy\n * retry. `stop()` aborts in-flight drains at their chunk boundary and leaves\n * every claim retryable; a restarted daemon's scheduler adopts them.\n */\n\nimport { randomUUID } from \"node:crypto\";\nimport { hostname } from \"node:os\";\nimport { resolveMaxTurnsPerSession } from \"../buffer-session-cap.js\";\nimport { log } from \"../logger.js\";\nimport type { Orchestrator } from \"../orchestrator.js\";\nimport type { BufferDrainClaims, DrainLease } from \"../storage/buffer-drain-claims.js\";\nimport { BufferDrainRunner } from \"./buffer-drain-runner.js\";\nimport type { DrainRunnerEvent, DrainSessionOutcome } from \"./buffer-drain-runner.js\";\nimport type { ExtractionQueueCoordinator } from \"./extraction-queue-coordinator.js\";\nimport type { ProviderBreakerSnapshot } from \"./provider-breaker.js\";\n\n/** What the scheduler needs from its host (structurally satisfied by the\n * orchestrator wiring); injectable so tests drive ticks deterministically. */\nexport interface BacklogSchedulerDeps {\n queue: Pick<ExtractionQueueCoordinator, \"tryReserveKey\" | \"releaseKeyReservation\" | \"maxConcurrency\">;\n claims: Pick<BufferDrainClaims, \"list\" | \"listPage\" | \"claimFromSessionFile\" | \"isClaimed\">;\n /** Live per-key pending counts (counts only — never turn payloads). May be\n * async: hosts with a lazily-loaded buffer load it here (idempotent). */\n liveBufferCounts():\n | Map<string, { turns: number; retainedTurns: number }>\n | Promise<Map<string, { turns: number; retainedTurns: number }>>;\n /** Create a fresh lease for a unique owner token. */\n lease(ownerId: string): DrainLease;\n /** Drain one key to quiescence (BufferDrainRunner.drainSession). */\n drainKey(\n key: string,\n options: { ownerId: string; signal: AbortSignal; onEvent?: (event: DrainRunnerEvent) => void }\n ): Promise<DrainSessionOutcome>;\n /** Shared provider circuit-breaker snapshot (the same instance the run\n * coordinator gates attempts on). While OPEN inside its cooldown window\n * the scheduler skips submission entirely — claims stay durable, and the\n * breaker's single half-open probe (one attempt through once the window\n * lapses) keeps recovery automatic. Optional: hosts without a breaker\n * never skip. */\n breakerSnapshot?(): ProviderBreakerSnapshot;\n /** Test seam: monotonic-ish clock for backoff windows. */\n now?(): number;\n /** The buffer's per-session turn cap. A live key holding this many turns\n * refuses new captures, so discovery lists it before the claim page.\n * Optional: without it, discovery keeps plain claim-page-first order. */\n maxTurnsPerSession?(): number;\n}\n\nexport interface BacklogSchedulerOptions {\n /** Optional label prefix; each scheduler instance adds a unique token. */\n ownerId?: string;\n /** Scan cadence in ms (startup + new-work + retry checks). */\n pollMs?: number;\n retryBaseMs?: number;\n retryMaxMs?: number;\n /** Bound on `stop()`'s wait for aborted drains to settle. */\n stopSettleTimeoutMs?: number;\n now?: () => number;\n}\n\nexport interface BacklogSchedulerCounters {\n /** Keys submitted to the drain (claimed or adopted) this process lifetime. */\n claimed: number;\n /** Outcomes with genuinely empty claims (durable outputs preceded ack). */\n processed: number;\n /** Sum of durable outputs (memories + entities) across processed drains. */\n durableOutputs: number;\n /** Re-submissions after a failed/deferred/denied outcome. */\n retried: number;\n denied: { keys: number; turns: number };\n failed: number;\n}\n\nexport type BacklogKeyState = \"inflight\" | \"backoff\" | \"denied\";\n\nexport interface BacklogKeySnapshot {\n key: string;\n state: BacklogKeyState;\n turnsRemaining?: number;\n reason?: string;\n}\n\nexport interface BacklogSchedulerSnapshot {\n counters: BacklogSchedulerCounters;\n inFlight: string[];\n reservedKeys: string[];\n keys: BacklogKeySnapshot[];\n}\n\ninterface KeyState {\n state: BacklogKeyState;\n nextAttemptMs: number;\n /** Last observed remaining turns; progress resets the backoff exponent. */\n turnsRemaining: number;\n reason?: string;\n backoffExponent: number;\n}\n\nconst DEFAULT_POLL_MS = 15_000;\nconst DEFAULT_RETRY_BASE_MS = 30_000;\nconst DEFAULT_RETRY_MAX_MS = 15 * 60_000;\n// Aborted drains normally settle within seconds (a chunk boundary); this only\n// bounds the pathological case, well inside the daemon's stop budget.\nconst DEFAULT_STOP_SETTLE_TIMEOUT_MS = 30_000;\n\nexport class BacklogScheduler {\n private readonly deps: BacklogSchedulerDeps;\n private readonly options: Required<Omit<BacklogSchedulerOptions, \"now\">> & Pick<BacklogSchedulerOptions, \"now\">;\n private readonly keys = new Map<string, KeyState>();\n private readonly inFlight = new Map<string, { controller: AbortController; settled: Promise<void> }>();\n private readonly reserved = new Set<string>();\n private readonly counters: BacklogSchedulerCounters = {\n claimed: 0,\n processed: 0,\n durableOutputs: 0,\n retried: 0,\n denied: { keys: 0, turns: 0 },\n failed: 0,\n };\n private claimCursor: string | undefined;\n private timer: ReturnType<typeof setInterval> | undefined;\n private ticking = false;\n private stopped = true;\n\n constructor(deps: BacklogSchedulerDeps, options: BacklogSchedulerOptions = {}) {\n this.deps = deps;\n this.options = {\n ownerId: `${options.ownerId ?? \"daemon-drain\"}-${randomUUID()}`,\n pollMs: options.pollMs ?? DEFAULT_POLL_MS,\n retryBaseMs: options.retryBaseMs ?? DEFAULT_RETRY_BASE_MS,\n retryMaxMs: options.retryMaxMs ?? DEFAULT_RETRY_MAX_MS,\n stopSettleTimeoutMs: options.stopSettleTimeoutMs ?? DEFAULT_STOP_SETTLE_TIMEOUT_MS,\n now: options.now,\n };\n }\n\n /** Idempotent. Starts the poll timer (unref'd) and runs an initial tick. */\n start(): void {\n if (!this.stopped) return;\n this.stopped = false;\n this.timer = setInterval(() => void this.tick(), this.options.pollMs);\n this.timer.unref?.();\n void this.tick();\n }\n\n /** Idempotent. Stops the timer, aborts in-flight drains (their claims stay\n * retryable) and waits up to `stopSettleTimeoutMs` for them to settle. A\n * drain that ignores abort is named in a warning and left behind: the\n * caller's later shutdown phases (orchestrator flush and dispose) must\n * still run before the service manager's kill. */\n async stop(): Promise<void> {\n if (this.stopped) return;\n this.stopped = true;\n if (this.timer) {\n clearInterval(this.timer);\n this.timer = undefined;\n }\n const aborts: Promise<void>[] = [];\n for (const entry of this.inFlight.values()) {\n entry.controller.abort(new Error(\"backlog scheduler stopping\"));\n aborts.push(entry.settled);\n }\n const bound = Promise.withResolvers<\"timeout\">();\n const boundTimer = setTimeout(() => bound.resolve(\"timeout\"), this.options.stopSettleTimeoutMs);\n try {\n const result = await Promise.race([Promise.allSettled(aborts), bound.promise]);\n if (result === \"timeout\") {\n log.warn(\n `backlog scheduler stop: ${this.inFlight.size} drain(s) ignored abort for ${this.options.stopSettleTimeoutMs}ms; ` +\n `continuing shutdown (stuck keys: ${[...this.inFlight.keys()].join(\", \")})`,\n );\n }\n } finally {\n clearTimeout(boundTimer);\n }\n }\n\n /** Bounded snapshot for ops/watchers: counters + per-key states + live sets. */\n snapshot(): BacklogSchedulerSnapshot {\n return {\n counters: {\n claimed: this.counters.claimed,\n processed: this.counters.processed,\n durableOutputs: this.counters.durableOutputs,\n retried: this.counters.retried,\n denied: { ...this.counters.denied },\n failed: this.counters.failed,\n },\n inFlight: [...this.inFlight.keys()],\n reservedKeys: [...this.reserved],\n keys: [...this.keys.entries()].map(([key, state]) => ({\n key,\n state: state.state,\n turnsRemaining: state.turnsRemaining,\n reason: state.reason,\n })),\n };\n }\n\n /** One scan+submit pass (tests drive this instead of the timer). Waits out\n * any in-progress tick first so the pass always actually scans. */\n async tickForTest(): Promise<void> {\n // setImmediate: yields to the event loop so pending I/O (a slow first\n // scan) can finish; a microtask spin would starve it.\n while (this.ticking) await new Promise((resolve) => setImmediate(resolve));\n await this.tick();\n }\n\n /** Await the settle (slot release) of everything currently in flight,\n * optionally excluding one still-gated key (tests). */\n async settleForTest(exclude?: string): Promise<void> {\n for (;;) {\n const pending = [...this.inFlight.entries()].filter(([key]) => key !== exclude).map(([, entry]) => entry.settled);\n if (pending.length === 0) return;\n await Promise.allSettled(pending);\n }\n }\n\n private now(): number {\n return this.options.now?.() ?? Date.now();\n }\n\n private async tick(): Promise<void> {\n if (this.ticking || this.stopped) return;\n this.ticking = true;\n const cursorBeforeTick = this.claimCursor;\n try {\n // Fast bail: a breaker already open must not pay discovery I/O\n // (listPage reads and parses claim bodies on every poll). The\n // submitCandidates guard below still catches a breaker that opens\n // while discovery awaits.\n const breakerBeforeDiscovery = this.deps.breakerSnapshot?.();\n if (\n breakerBeforeDiscovery &&\n breakerBeforeDiscovery.state === \"open\" &&\n this.now() < breakerBeforeDiscovery.openUntilMs\n ) {\n return;\n }\n // stop() may land while discovery's I/O is pending: re-check before\n // submitting anything, and again per candidate.\n // A discovery failure (EACCES/EIO on the claims dir) must not reject\n // into a detached timer callback: it would be an unhandled rejection\n // that terminates the server. Log, skip this pass, retry next poll.\n let candidates: { key: string; needsClaim: boolean }[];\n try {\n candidates = await this.discoverCandidates();\n } catch (err) {\n // Discovery may have listed a page before it failed: the page cursor\n // already moved, so restore it — otherwise those claims wait for the\n // cursor to wrap instead of the next poll.\n this.claimCursor = cursorBeforeTick;\n log.warn(\n `backlog drain: discovery failed; retrying next poll: ${err instanceof Error ? err.message : String(err)}`\n );\n return;\n }\n if (this.stopped) return;\n const dropped = this.submitCandidates(candidates);\n // The concurrency bound stopped submission mid-page: rewind the page\n // cursor so the unsubmitted claims are re-listed on the next tick\n // (already-submitted ones are gated by inFlight and key backoff).\n if (dropped) this.claimCursor = cursorBeforeTick;\n } finally {\n this.ticking = false;\n }\n }\n\n /** Bounded discovery: ONE page of existing claims with pending turns */\n private async discoverCandidates(): Promise<{ key: string; needsClaim: boolean }[]> {\n const capped: { key: string; needsClaim: boolean }[] = [];\n const out: { key: string; needsClaim: boolean }[] = [];\n const seen = new Set<string>();\n const pageLimit = Math.max(this.submissionLimit() * 4, 16);\n const page = await this.deps.claims.listPage(this.claimCursor, pageLimit);\n for (const listed of page.entries) {\n seen.add(listed.key);\n out.push({ key: listed.key, needsClaim: false });\n }\n this.claimCursor = page.nextCursor;\n const turnCap = this.deps.maxTurnsPerSession?.() ?? Number.POSITIVE_INFINITY;\n for (const [key, counts] of await this.deps.liveBufferCounts()) {\n const held = counts.turns + counts.retainedTurns;\n if (held <= 0) continue;\n if (seen.has(key) || this.deps.claims.isClaimed(key)) continue;\n seen.add(key);\n (held >= turnCap ? capped : out).push({ key, needsClaim: true });\n }\n return [...capped, ...out];\n }\n\n /** Submission bound: the queue's own concurrency limit, read with the\n * documented \"0 disables\" contract — a zero limit submits nothing. */\n private submissionLimit(): number {\n if (this.deps.queue.maxConcurrency <= 0) return 0;\n return this.deps.queue.maxConcurrency;\n }\n\n /** Submit discovery candidates within the queue's concurrency bound. */\n private submitCandidates(candidates: { key: string; needsClaim: boolean }[]): boolean {\n // Breaker-open churn guard: a full attempt reads the claim, rebuilds the\n // buffer/coordinator and re-renders chunks before the breaker fails it\n // fast — pure heap pressure per poll during a provider stall. Skip while\n // the window is open; once it lapses, submissions resume and the\n // breaker's half-open probe runs as usual.\n const breaker = this.deps.breakerSnapshot?.();\n if (breaker && breaker.state === \"open\" && this.now() < breaker.openUntilMs) {\n return true;\n }\n let dropped = false;\n for (const candidate of candidates) {\n if (this.stopped || this.inFlight.size >= this.submissionLimit()) {\n dropped = true;\n break;\n }\n if (!this.candidateEligible(candidate)) continue;\n // Fence the claim decision: reserve the key synchronously BEFORE the\n // async rename so no queued task for it can pass the claimed gate in\n // the meantime. Release happens when the decision settles.\n if (candidate.needsClaim) {\n if (!this.deps.queue.tryReserveKey(candidate.key)) continue;\n this.reserved.add(candidate.key);\n }\n void this.submit(candidate.key, candidate.needsClaim);\n }\n return dropped;\n }\n\n /** inFlight is the authority for \"already submitted\" — key state only\n * exists once an outcome landed (backoff/denied gating below). */\n private candidateEligible(candidate: { key: string; needsClaim: boolean }): boolean {\n if (this.stopped || this.inFlight.size >= this.submissionLimit()) return false;\n if (this.inFlight.has(candidate.key)) return false;\n const state = this.keys.get(candidate.key);\n return !(state && this.now() < state.nextAttemptMs);\n }\n\n /** Claim (when needed), then drain one key; the reservation spans the async\n * claim decision, the queue entry carries the key afterwards. */\n private async submit(key: string, needsClaim: boolean): Promise<void> {\n const controller = new AbortController();\n const { promise: settled, resolve: settle } = Promise.withResolvers<void>();\n this.inFlight.set(key, { controller, settled });\n try {\n if (!(await this.claimForSubmit(key, needsClaim, this.options.ownerId))) return;\n // Stopped between the claim decision and the task: leave the claim\n // with its lease (it expires; the next start adopts) — never drain.\n if (this.stopped) return;\n await this.drainClaimedKey(key, controller.signal, this.options.ownerId);\n } catch (err) {\n // Claim/drain failures are scheduler-level: the claim content is\n // untouched — count failed and back off (never an unhandled rejection\n // in the detached submission).\n this.counters.failed += 1;\n const message = err instanceof Error ? err.message : String(err);\n // SAFETY: a thrown non-Error (incl. null) carries no retry hint; the\n // optional chain reads the hint off Error throws only.\n this.setBackoff(key, (err as { turnsRemaining?: number } | null | undefined)?.turnsRemaining ?? 0, message);\n log.warn(`backlog drain: ${key} submission failed: ${message}`);\n } finally {\n this.inFlight.delete(key);\n this.reserved.delete(key);\n this.deps.queue.releaseKeyReservation(key);\n settle();\n }\n }\n\n /** after all — the key goes quiet without a task. \"claimed\": ours. */\n private async claimForSubmit(key: string, needsClaim: boolean, ownerId: string): Promise<boolean> {\n if (!needsClaim) return true;\n try {\n const outcome = await this.deps.claims.claimFromSessionFile(key, this.deps.lease(ownerId));\n if (outcome === \"empty\") {\n this.keys.delete(key);\n return false;\n }\n return true;\n } finally {\n this.reserved.delete(key);\n this.deps.queue.releaseKeyReservation(key);\n }\n }\n\n /** Drain one claimed key. drainKey reports failures as outcomes; a thrown\n * error still means the claim content is intact — count it failed and\n * back off. */\n private async drainClaimedKey(key: string, signal: AbortSignal, ownerId: string): Promise<void> {\n this.counters.claimed += 1;\n try {\n const outcome = await this.deps.drainKey(key, {\n ownerId,\n signal,\n });\n this.applyOutcome(key, outcome);\n } catch (err) {\n this.counters.failed += 1;\n const message = err instanceof Error ? err.message : String(err);\n // SAFETY: a thrown non-Error (incl. null) carries no retry hint; the\n // optional chain reads the hint off Error throws only.\n this.setBackoff(key, (err as { turnsRemaining?: number } | null | undefined)?.turnsRemaining ?? 0, message);\n log.warn(`backlog drain: ${key} threw: ${message}`);\n }\n }\n\n private applyOutcome(key: string, outcome: DrainSessionOutcome): void {\n const deniedTurns = outcome.denied?.reduce((sum, entry) => sum + entry.turns, 0) ?? 0;\n const previous = this.keys.get(key);\n const progressed = outcome.turnsRemaining < (previous?.turnsRemaining ?? Number.POSITIVE_INFINITY);\n if (outcome.status === \"drained\") {\n // The claim is now an empty tombstone: authoritative, nothing pending.\n // New ingress consumes it via the native save path and re-candidates.\n this.keys.delete(key);\n this.counters.processed += 1;\n this.counters.durableOutputs += outcome.durableOutputCount;\n log.info(\n `backlog drain: ${key} drained (${outcome.turnsAtStart} turn(s), ${outcome.durableOutputCount} durable output(s))`\n );\n return;\n }\n this.recordNonDrainedCounters(previous, outcome, deniedTurns);\n const denied = deniedTurns > 0 && outcome.turnsRemaining > 0;\n this.keys.set(key, this.nextKeyState(previous, outcome, denied, progressed));\n log.info(\n `backlog drain: ${key} ${outcome.status} (${outcome.turnsRemaining} turn(s) remaining` +\n `${denied ? `, denied: ${deniedTurns}` : \"\"}${outcome.reason ? `, ${outcome.reason}` : \"\"})`\n );\n }\n\n /** Denied backlog counters for a non-drained outcome. */\n private recordNonDrainedCounters(\n previous: KeyState | undefined,\n outcome: DrainSessionOutcome,\n deniedTurns: number\n ): void {\n if (deniedTurns > 0) {\n this.counters.denied.keys += 1;\n this.counters.denied.turns += deniedTurns;\n }\n if (outcome.status === \"failed\") this.counters.failed += 1;\n else if (previous !== undefined && (previous.state === \"backoff\" || previous.state === \"denied\"))\n this.counters.retried += 1;\n }\n\n /** The post-drain key state: denial waits the full max window (its content\n * is valid but currently unauthorized); progress resets the exponent. */\n private nextKeyState(\n previous: KeyState | undefined,\n outcome: DrainSessionOutcome,\n denied: boolean,\n progressed: boolean\n ): KeyState {\n return {\n state: denied ? \"denied\" : \"backoff\",\n nextAttemptMs: this.now() + this.backoffMs(previous, progressed && !denied),\n turnsRemaining: outcome.turnsRemaining,\n reason: outcome.reason,\n backoffExponent: this.nextBackoffExponent(denied, progressed, previous),\n };\n }\n\n private nextBackoffExponent(denied: boolean, progressed: boolean, previous: KeyState | undefined): number {\n return denied || !progressed ? (previous?.backoffExponent ?? 0) + 1 : 0;\n }\n\n private backoffMs(previous: KeyState | undefined, progressed: boolean): number {\n if (previous?.state === \"denied\") return this.options.retryMaxMs;\n const exponent = progressed ? 0 : (previous?.backoffExponent ?? 0) + 1;\n return Math.min(this.options.retryBaseMs * 2 ** exponent, this.options.retryMaxMs);\n }\n\n private setBackoff(key: string, turnsRemaining: number, reason: string): void {\n const previous = this.keys.get(key);\n this.keys.set(key, {\n state: \"backoff\",\n nextAttemptMs: this.now() + this.backoffMs(previous, false),\n turnsRemaining,\n reason,\n backoffExponent: (previous?.backoffExponent ?? 0) + 1,\n });\n }\n}\n\n/** Lease lifetime for claims the scheduler takes (matches the runner default). */\nconst SCHEDULER_LEASE_MS = 120_000;\n\n/** Wire the scheduler to an orchestrator's own queue, claim store, live buffer\n * counts and drain runner — the daemon's single ownership point. */\nexport function wireBacklogScheduler(\n orchestrator: Orchestrator,\n options: BacklogSchedulerOptions = {}\n): BacklogScheduler {\n const runner = new BufferDrainRunner(orchestrator);\n return new BacklogScheduler(\n {\n queue: orchestrator.extractionQueueCoordinator,\n claims: orchestrator.storage.bufferDrainClaims(),\n liveBufferCounts: async () => {\n // The daemon's buffer may be lazy: ensure the persisted state is in\n // memory before counting (load is guarded/idempotent).\n await orchestrator.buffer.load();\n return orchestrator.buffer.entryCounts();\n },\n lease: (ownerId) => {\n const now = new Date().toISOString();\n return {\n ownerId,\n pid: process.pid,\n host: hostname(),\n acquiredAt: now,\n heartbeatAt: now,\n leaseMs: SCHEDULER_LEASE_MS,\n };\n },\n drainKey: (key, drainOptions) => runner.drainSession(key, drainOptions),\n // The orchestrator's one shared provider breaker (foreground and every\n // claim-backed drain accumulate toward the same threshold).\n breakerSnapshot: () => orchestrator.getExtractionResilienceStatus().breaker,\n maxTurnsPerSession: () => resolveMaxTurnsPerSession(orchestrator.config.bufferMaxTurnsPerSession),\n },\n options\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,UACb,MAAM,SAAS;AAAA,UACf,YAAY;AAAA,UACZ,aAAa;AAAA,UACb,SAAS;AAAA,QACX;AAAA,MACF;AAAA,MACA,UAAU,CAAC,KAAK,iBAAiB,OAAO,aAAa,KAAK,YAAY;AAAA;AAAA;AAAA,MAGtE,iBAAiB,MAAM,aAAa,8BAA8B,EAAE;AAAA,MACpE,oBAAoB,MAAM,0BAA0B,aAAa,OAAO,wBAAwB;AAAA,IAClG;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../../src/orchestration/backlog-scheduler.ts"],"sourcesContent":["/**\n * Daemon-owned extraction backlog scheduler.\n *\n * ONE bounded in-process loop that owns ALL persisted extraction backlog:\n * at startup (existing drain claims + buffered sessions), on every poll tick\n * (new persisted work), and by retrying keys that are still pending — with\n * bounded memory (per-key COUNTS only; candidate scans never retain turn\n * payloads) and bounded outstanding work (the extraction queue's own\n * maxConcurrency gates submissions, so live foreground work keeps its share\n * of the queue).\n *\n * Claim authority: an existing claim — including an EMPTY ack tombstone — is\n * authoritative over the live buffer's in-memory copy. A tombstoned key is\n * never re-claimed or counted as work; new ingress consumes the tombstone\n * through the native save handover, which is what makes the key a candidate\n * again. Claim creation is fenced: the key is reserved synchronously on the\n * extraction queue BEFORE the async claim decision, so a queued live task for\n * the same key cannot start past the claimed-session gate until the decision\n * settles; live capture continues via the native merge-into-claim protocol.\n *\n * Failed, deferred, or policy-denied outcomes keep their turns durable in the\n * claim and re-submit after backoff (exponential from `retryBaseMs` to\n * `retryMaxMs`, reset by progress; denials wait the full max) — never a busy\n * retry. `stop()` aborts in-flight drains at their chunk boundary and leaves\n * every claim retryable; a restarted daemon's scheduler adopts them.\n */\n\nimport { randomUUID } from \"node:crypto\";\nimport { hostname } from \"node:os\";\nimport { resolveMaxTurnsPerSession } from \"../buffer-session-cap.js\";\nimport { log } from \"../logger.js\";\nimport type { Orchestrator } from \"../orchestrator.js\";\nimport type { BufferDrainClaims, DrainLease } from \"../storage/buffer-drain-claims.js\";\nimport { BufferDrainRunner } from \"./buffer-drain-runner.js\";\nimport type { DrainRunnerEvent, DrainSessionOutcome } from \"./buffer-drain-runner.js\";\nimport type { ExtractionQueueCoordinator } from \"./extraction-queue-coordinator.js\";\nimport type { ProviderBreakerSnapshot } from \"./provider-breaker.js\";\n\n/** What the scheduler needs from its host (structurally satisfied by the\n * orchestrator wiring); injectable so tests drive ticks deterministically. */\nexport interface BacklogSchedulerDeps {\n queue: Pick<ExtractionQueueCoordinator, \"tryReserveKey\" | \"releaseKeyReservation\" | \"maxConcurrency\">;\n claims: Pick<BufferDrainClaims, \"list\" | \"listPage\" | \"claimFromSessionFile\" | \"isClaimed\">;\n /** Live per-key pending counts (counts only — never turn payloads). May be\n * async: hosts with a lazily-loaded buffer load it here (idempotent). */\n liveBufferCounts():\n | Map<string, { turns: number; retainedTurns: number }>\n | Promise<Map<string, { turns: number; retainedTurns: number }>>;\n /** Create a fresh lease for a unique owner token. */\n lease(ownerId: string): DrainLease;\n /** Drain one key to quiescence (BufferDrainRunner.drainSession). */\n drainKey(\n key: string,\n options: { ownerId: string; signal: AbortSignal; onEvent?: (event: DrainRunnerEvent) => void }\n ): Promise<DrainSessionOutcome>;\n /** Shared provider circuit-breaker snapshot (the same instance the run\n * coordinator gates attempts on). While OPEN inside its cooldown window\n * the scheduler skips submission entirely — claims stay durable, and the\n * breaker's single half-open probe (one attempt through once the window\n * lapses) keeps recovery automatic. Optional: hosts without a breaker\n * never skip. */\n breakerSnapshot?(): ProviderBreakerSnapshot;\n /** Test seam: monotonic-ish clock for backoff windows. */\n now?(): number;\n /** The buffer's per-session turn cap. A live key holding this many turns\n * refuses new captures, so discovery lists it before the claim page.\n * Optional: without it, discovery keeps plain claim-page-first order. */\n maxTurnsPerSession?(): number;\n}\n\nexport interface BacklogSchedulerOptions {\n /** Optional label prefix; each scheduler instance adds a unique token. */\n ownerId?: string;\n /** Scan cadence in ms (startup + new-work + retry checks). */\n pollMs?: number;\n retryBaseMs?: number;\n retryMaxMs?: number;\n /** Bound on `stop()`'s wait for aborted drains to settle. */\n stopSettleTimeoutMs?: number;\n now?: () => number;\n}\n\nexport interface BacklogSchedulerCounters {\n /** Keys submitted to the drain (claimed or adopted) this process lifetime. */\n claimed: number;\n /** Outcomes with genuinely empty claims (durable outputs preceded ack). */\n processed: number;\n /** Sum of durable outputs (memories + entities) across processed drains. */\n durableOutputs: number;\n /** Re-submissions after a failed/deferred/denied outcome. */\n retried: number;\n denied: { keys: number; turns: number };\n failed: number;\n}\n\nexport type BacklogKeyState = \"inflight\" | \"backoff\" | \"denied\";\n\nexport interface BacklogKeySnapshot {\n key: string;\n state: BacklogKeyState;\n turnsRemaining?: number;\n reason?: string;\n}\n\nexport interface BacklogSchedulerSnapshot {\n counters: BacklogSchedulerCounters;\n inFlight: string[];\n reservedKeys: string[];\n keys: BacklogKeySnapshot[];\n}\n\ninterface KeyState {\n state: BacklogKeyState;\n nextAttemptMs: number;\n /** Last observed remaining turns; progress resets the backoff exponent. */\n turnsRemaining: number;\n reason?: string;\n backoffExponent: number;\n}\n\nconst DEFAULT_POLL_MS = 15_000;\nconst DEFAULT_RETRY_BASE_MS = 30_000;\nconst DEFAULT_RETRY_MAX_MS = 15 * 60_000;\n// Aborted drains normally settle within seconds (a chunk boundary); this only\n// bounds the pathological case, well inside the daemon's stop budget.\nconst DEFAULT_STOP_SETTLE_TIMEOUT_MS = 30_000;\n\nexport class BacklogScheduler {\n private readonly deps: BacklogSchedulerDeps;\n private readonly options: Required<Omit<BacklogSchedulerOptions, \"now\">> & Pick<BacklogSchedulerOptions, \"now\">;\n private readonly keys = new Map<string, KeyState>();\n private readonly inFlight = new Map<string, { controller: AbortController; settled: Promise<void> }>();\n private readonly reserved = new Set<string>();\n private readonly counters: BacklogSchedulerCounters = {\n claimed: 0,\n processed: 0,\n durableOutputs: 0,\n retried: 0,\n denied: { keys: 0, turns: 0 },\n failed: 0,\n };\n private claimCursor: string | undefined;\n private timer: ReturnType<typeof setInterval> | undefined;\n private ticking = false;\n private stopped = true;\n\n constructor(deps: BacklogSchedulerDeps, options: BacklogSchedulerOptions = {}) {\n this.deps = deps;\n this.options = {\n ownerId: `${options.ownerId ?? \"daemon-drain\"}-${randomUUID()}`,\n pollMs: options.pollMs ?? DEFAULT_POLL_MS,\n retryBaseMs: options.retryBaseMs ?? DEFAULT_RETRY_BASE_MS,\n retryMaxMs: options.retryMaxMs ?? DEFAULT_RETRY_MAX_MS,\n stopSettleTimeoutMs: options.stopSettleTimeoutMs ?? DEFAULT_STOP_SETTLE_TIMEOUT_MS,\n now: options.now,\n };\n }\n\n /** Idempotent. Starts the poll timer (unref'd) and runs an initial tick. */\n start(): void {\n if (!this.stopped) return;\n this.stopped = false;\n this.timer = setInterval(() => void this.tick(), this.options.pollMs);\n this.timer.unref?.();\n void this.tick();\n }\n\n /** Idempotent. Stops the timer, aborts in-flight drains (their claims stay\n * retryable) and waits up to `stopSettleTimeoutMs` for them to settle. A\n * drain that ignores abort is named in a warning and left behind: the\n * caller's later shutdown phases (orchestrator flush and dispose) must\n * still run before the service manager's kill. */\n async stop(): Promise<void> {\n if (this.stopped) return;\n this.stopped = true;\n if (this.timer) {\n clearInterval(this.timer);\n this.timer = undefined;\n }\n const aborts: Promise<void>[] = [];\n for (const entry of this.inFlight.values()) {\n entry.controller.abort(new Error(\"backlog scheduler stopping\"));\n aborts.push(entry.settled);\n }\n const bound = Promise.withResolvers<\"timeout\">();\n const boundTimer = setTimeout(() => bound.resolve(\"timeout\"), this.options.stopSettleTimeoutMs);\n try {\n const result = await Promise.race([Promise.allSettled(aborts), bound.promise]);\n if (result === \"timeout\") {\n log.warn(\n `backlog scheduler stop: ${this.inFlight.size} drain(s) ignored abort for ${this.options.stopSettleTimeoutMs}ms; ` +\n `continuing shutdown (stuck keys: ${[...this.inFlight.keys()].join(\", \")})`,\n );\n }\n } finally {\n clearTimeout(boundTimer);\n }\n }\n\n /** Bounded snapshot for ops/watchers: counters + per-key states + live sets. */\n snapshot(): BacklogSchedulerSnapshot {\n return {\n counters: {\n claimed: this.counters.claimed,\n processed: this.counters.processed,\n durableOutputs: this.counters.durableOutputs,\n retried: this.counters.retried,\n denied: { ...this.counters.denied },\n failed: this.counters.failed,\n },\n inFlight: [...this.inFlight.keys()],\n reservedKeys: [...this.reserved],\n keys: [...this.keys.entries()].map(([key, state]) => ({\n key,\n state: state.state,\n turnsRemaining: state.turnsRemaining,\n reason: state.reason,\n })),\n };\n }\n\n /** One scan+submit pass (tests drive this instead of the timer). Waits out\n * any in-progress tick first so the pass always actually scans. */\n async tickForTest(): Promise<void> {\n // setImmediate: yields to the event loop so pending I/O (a slow first\n // scan) can finish; a microtask spin would starve it.\n while (this.ticking) await new Promise((resolve) => setImmediate(resolve));\n await this.tick();\n }\n\n /** Await the settle (slot release) of everything currently in flight,\n * optionally excluding one still-gated key (tests). */\n async settleForTest(exclude?: string): Promise<void> {\n for (;;) {\n const pending = [...this.inFlight.entries()].filter(([key]) => key !== exclude).map(([, entry]) => entry.settled);\n if (pending.length === 0) return;\n await Promise.allSettled(pending);\n }\n }\n\n private now(): number {\n return this.options.now?.() ?? Date.now();\n }\n\n private async tick(): Promise<void> {\n if (this.ticking || this.stopped) return;\n this.ticking = true;\n const cursorBeforeTick = this.claimCursor;\n try {\n // Fast bail: a breaker already open must not pay discovery I/O\n // (listPage reads and parses claim bodies on every poll). The\n // submitCandidates guard below still catches a breaker that opens\n // while discovery awaits.\n const breakerBeforeDiscovery = this.deps.breakerSnapshot?.();\n if (\n breakerBeforeDiscovery &&\n breakerBeforeDiscovery.state === \"open\" &&\n this.now() < breakerBeforeDiscovery.openUntilMs\n ) {\n return;\n }\n // stop() may land while discovery's I/O is pending: re-check before\n // submitting anything, and again per candidate.\n // A discovery failure (EACCES/EIO on the claims dir) must not reject\n // into a detached timer callback: it would be an unhandled rejection\n // that terminates the server. Log, skip this pass, retry next poll.\n let candidates: { key: string; needsClaim: boolean }[];\n try {\n candidates = await this.discoverCandidates();\n } catch (err) {\n // Discovery may have listed a page before it failed: the page cursor\n // already moved, so restore it — otherwise those claims wait for the\n // cursor to wrap instead of the next poll.\n this.claimCursor = cursorBeforeTick;\n log.warn(\n `backlog drain: discovery failed; retrying next poll: ${err instanceof Error ? err.message : String(err)}`\n );\n return;\n }\n if (this.stopped) return;\n const dropped = this.submitCandidates(candidates);\n // The concurrency bound stopped submission mid-page: rewind the page\n // cursor so the unsubmitted claims are re-listed on the next tick\n // (already-submitted ones are gated by inFlight and key backoff).\n if (dropped) this.claimCursor = cursorBeforeTick;\n } finally {\n this.ticking = false;\n }\n }\n\n /** Bounded discovery: ONE page of existing claims with pending turns */\n private async discoverCandidates(): Promise<{ key: string; needsClaim: boolean }[]> {\n const capped: { key: string; needsClaim: boolean }[] = [];\n const out: { key: string; needsClaim: boolean }[] = [];\n const seen = new Set<string>();\n const pageLimit = Math.max(this.submissionLimit() * 4, 16);\n const page = await this.deps.claims.listPage(this.claimCursor, pageLimit);\n for (const listed of page.entries) {\n seen.add(listed.key);\n out.push({ key: listed.key, needsClaim: false });\n }\n this.claimCursor = page.nextCursor;\n const turnCap = this.deps.maxTurnsPerSession?.() ?? Number.POSITIVE_INFINITY;\n for (const [key, counts] of await this.deps.liveBufferCounts()) {\n const held = counts.turns + counts.retainedTurns;\n if (held <= 0) continue;\n if (seen.has(key) || this.deps.claims.isClaimed(key)) continue;\n seen.add(key);\n (held >= turnCap ? capped : out).push({ key, needsClaim: true });\n }\n return [...capped, ...out];\n }\n\n /** Submission bound: the queue's own concurrency limit, read with the\n * documented \"0 disables\" contract — a zero limit submits nothing. */\n private submissionLimit(): number {\n if (this.deps.queue.maxConcurrency <= 0) return 0;\n return this.deps.queue.maxConcurrency;\n }\n\n /** Submit discovery candidates within the queue's concurrency bound. */\n private submitCandidates(candidates: { key: string; needsClaim: boolean }[]): boolean {\n // Breaker-open churn guard: a full attempt reads the claim, rebuilds the\n // buffer/coordinator and re-renders chunks before the breaker fails it\n // fast — pure heap pressure per poll during a provider stall. Skip while\n // the window is open; once it lapses, submissions resume and the\n // breaker's half-open probe runs as usual.\n const breaker = this.deps.breakerSnapshot?.();\n if (breaker && breaker.state === \"open\" && this.now() < breaker.openUntilMs) {\n return true;\n }\n let dropped = false;\n for (const candidate of candidates) {\n if (this.stopped || this.inFlight.size >= this.submissionLimit()) {\n dropped = true;\n break;\n }\n if (!this.candidateEligible(candidate)) continue;\n // Fence the claim decision: reserve the key synchronously BEFORE the\n // async rename so no queued task for it can pass the claimed gate in\n // the meantime. Release happens when the decision settles.\n if (candidate.needsClaim) {\n if (!this.deps.queue.tryReserveKey(candidate.key)) continue;\n this.reserved.add(candidate.key);\n }\n void this.submit(candidate.key, candidate.needsClaim);\n }\n return dropped;\n }\n\n /** inFlight is the authority for \"already submitted\" — key state only\n * exists once an outcome landed (backoff/denied gating below). */\n private candidateEligible(candidate: { key: string; needsClaim: boolean }): boolean {\n if (this.stopped || this.inFlight.size >= this.submissionLimit()) return false;\n if (this.inFlight.has(candidate.key)) return false;\n const state = this.keys.get(candidate.key);\n return !(state && this.now() < state.nextAttemptMs);\n }\n\n /** Claim (when needed), then drain one key; the reservation spans the async\n * claim decision, the queue entry carries the key afterwards. */\n private async submit(key: string, needsClaim: boolean): Promise<void> {\n const controller = new AbortController();\n const { promise: settled, resolve: settle } = Promise.withResolvers<void>();\n this.inFlight.set(key, { controller, settled });\n try {\n if (!(await this.claimForSubmit(key, needsClaim, this.options.ownerId))) return;\n // Stopped between the claim decision and the task: leave the claim\n // with its lease (it expires; the next start adopts) — never drain.\n if (this.stopped) return;\n await this.drainClaimedKey(key, controller.signal, this.options.ownerId);\n } catch (err) {\n // Claim/drain failures are scheduler-level: the claim content is\n // untouched — count failed and back off (never an unhandled rejection\n // in the detached submission).\n this.counters.failed += 1;\n const message = err instanceof Error ? err.message : String(err);\n // SAFETY: a thrown non-Error (incl. null) carries no retry hint; the\n // optional chain reads the hint off Error throws only.\n this.setBackoff(key, (err as { turnsRemaining?: number } | null | undefined)?.turnsRemaining ?? 0, message);\n log.warn(`backlog drain: ${key} submission failed: ${message}`);\n } finally {\n this.inFlight.delete(key);\n this.reserved.delete(key);\n this.deps.queue.releaseKeyReservation(key);\n settle();\n }\n }\n\n /** after all — the key goes quiet without a task. \"claimed\": ours. */\n private async claimForSubmit(key: string, needsClaim: boolean, ownerId: string): Promise<boolean> {\n if (!needsClaim) return true;\n try {\n const outcome = await this.deps.claims.claimFromSessionFile(key, this.deps.lease(ownerId));\n if (outcome === \"empty\") {\n this.keys.delete(key);\n return false;\n }\n return true;\n } finally {\n this.reserved.delete(key);\n this.deps.queue.releaseKeyReservation(key);\n }\n }\n\n /** Drain one claimed key. drainKey reports failures as outcomes; a thrown\n * error still means the claim content is intact — count it failed and\n * back off. */\n private async drainClaimedKey(key: string, signal: AbortSignal, ownerId: string): Promise<void> {\n this.counters.claimed += 1;\n try {\n const outcome = await this.deps.drainKey(key, {\n ownerId,\n signal,\n });\n this.applyOutcome(key, outcome);\n } catch (err) {\n this.counters.failed += 1;\n const message = err instanceof Error ? err.message : String(err);\n // SAFETY: a thrown non-Error (incl. null) carries no retry hint; the\n // optional chain reads the hint off Error throws only.\n this.setBackoff(key, (err as { turnsRemaining?: number } | null | undefined)?.turnsRemaining ?? 0, message);\n log.warn(`backlog drain: ${key} threw: ${message}`);\n }\n }\n\n private applyOutcome(key: string, outcome: DrainSessionOutcome): void {\n const deniedTurns = outcome.denied?.reduce((sum, entry) => sum + entry.turns, 0) ?? 0;\n const previous = this.keys.get(key);\n const progressed = outcome.turnsRemaining < (previous?.turnsRemaining ?? Number.POSITIVE_INFINITY);\n if (outcome.status === \"drained\") {\n // The claim is now an empty tombstone: authoritative, nothing pending.\n // New ingress consumes it via the native save path and re-candidates.\n this.keys.delete(key);\n this.counters.processed += 1;\n this.counters.durableOutputs += outcome.durableOutputCount;\n log.info(\n `backlog drain: ${key} drained (${outcome.turnsAtStart} turn(s), ${outcome.durableOutputCount} durable output(s))`\n );\n return;\n }\n this.recordNonDrainedCounters(previous, outcome, deniedTurns);\n const denied = deniedTurns > 0 && outcome.turnsRemaining > 0;\n this.keys.set(key, this.nextKeyState(previous, outcome, denied, progressed));\n log.info(\n `backlog drain: ${key} ${outcome.status} (${outcome.turnsRemaining} turn(s) remaining` +\n `${denied ? `, denied: ${deniedTurns}` : \"\"}${outcome.reason ? `, ${outcome.reason}` : \"\"})`\n );\n }\n\n /** Denied backlog counters for a non-drained outcome. */\n private recordNonDrainedCounters(\n previous: KeyState | undefined,\n outcome: DrainSessionOutcome,\n deniedTurns: number\n ): void {\n if (deniedTurns > 0) {\n this.counters.denied.keys += 1;\n this.counters.denied.turns += deniedTurns;\n }\n if (outcome.status === \"failed\") this.counters.failed += 1;\n else if (previous !== undefined && (previous.state === \"backoff\" || previous.state === \"denied\"))\n this.counters.retried += 1;\n }\n\n /** The post-drain key state: denial waits the full max window (its content\n * is valid but currently unauthorized); progress resets the exponent. */\n private nextKeyState(\n previous: KeyState | undefined,\n outcome: DrainSessionOutcome,\n denied: boolean,\n progressed: boolean\n ): KeyState {\n return {\n state: denied ? \"denied\" : \"backoff\",\n nextAttemptMs: this.now() + this.backoffMs(previous, progressed && !denied),\n turnsRemaining: outcome.turnsRemaining,\n reason: outcome.reason,\n backoffExponent: this.nextBackoffExponent(denied, progressed, previous),\n };\n }\n\n private nextBackoffExponent(denied: boolean, progressed: boolean, previous: KeyState | undefined): number {\n return denied || !progressed ? (previous?.backoffExponent ?? 0) + 1 : 0;\n }\n\n private backoffMs(previous: KeyState | undefined, progressed: boolean): number {\n if (previous?.state === \"denied\") return this.options.retryMaxMs;\n const exponent = progressed ? 0 : (previous?.backoffExponent ?? 0) + 1;\n return Math.min(this.options.retryBaseMs * 2 ** exponent, this.options.retryMaxMs);\n }\n\n private setBackoff(key: string, turnsRemaining: number, reason: string): void {\n const previous = this.keys.get(key);\n this.keys.set(key, {\n state: \"backoff\",\n nextAttemptMs: this.now() + this.backoffMs(previous, false),\n turnsRemaining,\n reason,\n backoffExponent: (previous?.backoffExponent ?? 0) + 1,\n });\n }\n}\n\n/** Lease lifetime for claims the scheduler takes (matches the runner default). */\nconst SCHEDULER_LEASE_MS = 120_000;\n\n/** Wire the scheduler to an orchestrator's own queue, claim store, live buffer\n * counts and drain runner — the daemon's single ownership point. */\nexport function wireBacklogScheduler(\n orchestrator: Orchestrator,\n options: BacklogSchedulerOptions = {}\n): BacklogScheduler {\n const runner = new BufferDrainRunner(orchestrator);\n return new BacklogScheduler(\n {\n queue: orchestrator.extractionQueueCoordinator,\n claims: orchestrator.storage.bufferDrainClaims(),\n liveBufferCounts: async () => {\n // The daemon's buffer may be lazy: ensure the persisted state is in\n // memory before counting (load is guarded/idempotent).\n await orchestrator.buffer.load();\n return orchestrator.buffer.entryCounts();\n },\n lease: (ownerId) => {\n const now = new Date().toISOString();\n return {\n ownerId,\n pid: process.pid,\n host: hostname(),\n acquiredAt: now,\n heartbeatAt: now,\n leaseMs: SCHEDULER_LEASE_MS,\n };\n },\n drainKey: (key, drainOptions) => runner.drainSession(key, drainOptions),\n // The orchestrator's one shared provider breaker (foreground and every\n // claim-backed drain accumulate toward the same threshold).\n breakerSnapshot: () => orchestrator.getExtractionResilienceStatus().breaker,\n maxTurnsPerSession: () => resolveMaxTurnsPerSession(orchestrator.config.bufferMaxTurnsPerSession),\n },\n options\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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