@remnic/core 10.0.144 → 10.0.146

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 (385) hide show
  1. package/dist/access-admin-ops-surface.js +189 -183
  2. package/dist/access-cli.js +189 -183
  3. package/dist/access-cli.js.map +1 -1
  4. package/dist/access-correlation.d.ts +4 -0
  5. package/dist/access-correlation.d.ts.map +1 -0
  6. package/dist/access-correlation.js +10 -0
  7. package/dist/access-extraction-force-flush-preempt.js +189 -183
  8. package/dist/access-extraction-force-flush.js +189 -183
  9. package/dist/access-http-briefing.js +189 -183
  10. package/dist/access-http-query.js +189 -183
  11. package/dist/access-http.d.ts.map +1 -1
  12. package/dist/access-http.js +189 -183
  13. package/dist/access-identity-continuity-surface.js +189 -183
  14. package/dist/access-lcm-surface.js +189 -183
  15. package/dist/access-mcp.js +189 -183
  16. package/dist/access-observe-write-category.js +13 -13
  17. package/dist/access-observe-write-surface.d.ts.map +1 -1
  18. package/dist/access-observe-write-surface.js +189 -183
  19. package/dist/access-offline-manifest.js +11 -11
  20. package/dist/access-operations-batch.js +189 -183
  21. package/dist/access-operations.js +189 -183
  22. package/dist/access-recall-concurrency.js +189 -183
  23. package/dist/access-recall-diagnostics.js +2 -2
  24. package/dist/access-recall-response.js +189 -183
  25. package/dist/access-recall-surface.js +189 -183
  26. package/dist/access-schema.js +9 -9
  27. package/dist/access-service.d.ts.map +1 -1
  28. package/dist/access-service.js +189 -183
  29. package/dist/active-recall.js +33 -33
  30. package/dist/adapters/index.js +4 -4
  31. package/dist/adapters/registry.js +2 -2
  32. package/dist/auto-sync-PSZJHHXB.js +2 -2
  33. package/dist/briefing.js +22 -22
  34. package/dist/buffer-add-turns-bounded.d.ts +27 -0
  35. package/dist/buffer-add-turns-bounded.d.ts.map +1 -0
  36. package/dist/buffer-add-turns-bounded.js +13 -0
  37. package/dist/buffer-admission-idempotency.d.ts +18 -0
  38. package/dist/buffer-admission-idempotency.d.ts.map +1 -0
  39. package/dist/buffer-admission-idempotency.js +18 -0
  40. package/dist/buffer-persistence.d.ts +4 -0
  41. package/dist/buffer-persistence.d.ts.map +1 -1
  42. package/dist/buffer-persistence.js +1 -1
  43. package/dist/buffer-turn-helpers.d.ts.map +1 -1
  44. package/dist/buffer-turn-helpers.js +1 -1
  45. package/dist/buffer-types.d.ts.map +1 -1
  46. package/dist/buffer.d.ts +11 -0
  47. package/dist/buffer.d.ts.map +1 -1
  48. package/dist/buffer.js +15 -10
  49. package/dist/calibration.js +4 -4
  50. package/dist/{capsule-crypto-YO5QJ6L3.js → capsule-crypto-7FJQINUR.js} +2 -2
  51. package/dist/capsule-crypto-7FJQINUR.js.map +1 -0
  52. package/dist/causal-behavior.js +2 -2
  53. package/dist/causal-chain.js +2 -2
  54. package/dist/causal-consolidation.js +25 -25
  55. package/dist/causal-retrieval.js +2 -2
  56. package/dist/causal-trajectory-graph.js +3 -3
  57. package/dist/causal-trajectory.js +1 -1
  58. package/dist/{chunk-AWKD2A73.js → chunk-2NGTY22Z.js} +12 -12
  59. package/dist/{chunk-BXLOS5AJ.js → chunk-2NLLXCJG.js} +2 -2
  60. package/dist/{chunk-EDGWAJLS.js → chunk-2WD2TRTJ.js} +2 -2
  61. package/dist/{chunk-AZFQXYIJ.js → chunk-33VVVP57.js} +9 -2
  62. package/dist/{chunk-AZFQXYIJ.js.map → chunk-33VVVP57.js.map} +1 -1
  63. package/dist/{chunk-AOZYOS4G.js → chunk-3MXQ5XJT.js} +2 -2
  64. package/dist/{chunk-XGDWR2L6.js → chunk-3NLBDM7V.js} +2 -2
  65. package/dist/{chunk-XVZA6VXC.js → chunk-3SL52JKD.js} +4 -4
  66. package/dist/chunk-4IJBNRMZ.js +45 -0
  67. package/dist/chunk-4IJBNRMZ.js.map +1 -0
  68. package/dist/{chunk-LE27GU4M.js → chunk-4N4BAO66.js} +2 -2
  69. package/dist/{chunk-UC3KG7KX.js → chunk-4WX32RLU.js} +3 -3
  70. package/dist/{chunk-WVV54HL2.js → chunk-4Y4LPKFV.js} +7 -7
  71. package/dist/{chunk-MFDEEOOZ.js → chunk-5BE3FLKL.js} +4 -4
  72. package/dist/chunk-5EP2V675.js +60 -0
  73. package/dist/chunk-5EP2V675.js.map +1 -0
  74. package/dist/chunk-5JD4DXQX.js +91 -0
  75. package/dist/chunk-5JD4DXQX.js.map +1 -0
  76. package/dist/{chunk-MPQQIHA7.js → chunk-5LL2X5SO.js} +2 -2
  77. package/dist/{chunk-CBJRI6VJ.js → chunk-64TIBZPZ.js} +2 -2
  78. package/dist/{chunk-LL7WIK2Z.js → chunk-6NPLVV6M.js} +2 -2
  79. package/dist/{chunk-DC55RIEZ.js → chunk-73TPOGS4.js} +9 -9
  80. package/dist/{chunk-XF2QQQXO.js → chunk-7P72BY4F.js} +2 -2
  81. package/dist/{chunk-XUKBX3GO.js → chunk-7YHU3NJD.js} +15 -15
  82. package/dist/chunk-7ZFB4VZS.js +73 -0
  83. package/dist/chunk-7ZFB4VZS.js.map +1 -0
  84. package/dist/{chunk-6CSWINXA.js → chunk-AIDFYS4Z.js} +14 -14
  85. package/dist/{chunk-E23BTVB2.js → chunk-AO5LKFGO.js} +4 -4
  86. package/dist/{chunk-G4NKURT4.js → chunk-C6S353AG.js} +30 -1
  87. package/dist/chunk-C6S353AG.js.map +1 -0
  88. package/dist/{chunk-JY3WATTF.js → chunk-C6Z3H23R.js} +2 -2
  89. package/dist/{chunk-FWDVW2BD.js → chunk-CAWVPY6E.js} +499 -480
  90. package/dist/chunk-CAWVPY6E.js.map +1 -0
  91. package/dist/{chunk-VAVCFMMQ.js → chunk-CJ2SYU4S.js} +2 -2
  92. package/dist/{chunk-WZ55LEUN.js → chunk-CLVILSBR.js} +22 -22
  93. package/dist/{chunk-B72X3KWL.js → chunk-COJBTRTQ.js} +2 -2
  94. package/dist/{chunk-NWS4I4K7.js → chunk-CVCKYMVX.js} +2 -2
  95. package/dist/{chunk-2LQUPEWF.js → chunk-EJ6EPEMP.js} +36 -33
  96. package/dist/chunk-EJ6EPEMP.js.map +1 -0
  97. package/dist/{chunk-6MEQHJTF.js → chunk-FMFCQRDM.js} +3 -3
  98. package/dist/{chunk-A3EWNU5V.js → chunk-G2TK5YYU.js} +2 -2
  99. package/dist/{chunk-WWQMZBDI.js → chunk-GCHM5BYL.js} +4 -4
  100. package/dist/{chunk-RHQSAXN3.js → chunk-GCQIXPWZ.js} +2 -2
  101. package/dist/{chunk-VEFGHRKV.js → chunk-GMO3BGOF.js} +1 -1
  102. package/dist/{chunk-I3UBDUHO.js → chunk-H6OTEBPK.js} +2 -2
  103. package/dist/{chunk-MIG4KRYU.js → chunk-HADCITEA.js} +8 -8
  104. package/dist/{chunk-M43GO34S.js → chunk-HASIFVWH.js} +2 -2
  105. package/dist/{chunk-RQBYC7EK.js → chunk-HLWXCDUQ.js} +2 -2
  106. package/dist/{chunk-JVSHXYOO.js → chunk-HOGSBSCH.js} +2 -2
  107. package/dist/{chunk-BFPF5N3H.js → chunk-HXFIILGF.js} +4 -4
  108. package/dist/{chunk-2JAT4S7N.js → chunk-IMULTENA.js} +2 -2
  109. package/dist/{chunk-B4I37XX6.js → chunk-IOMWNBMH.js} +15 -15
  110. package/dist/{chunk-74BX5NCU.js → chunk-IXR3SNHL.js} +2 -2
  111. package/dist/{chunk-2S4XW47C.js → chunk-J3EU5H7W.js} +2 -2
  112. package/dist/{chunk-EUL3S3LE.js → chunk-J5WI4QRP.js} +4 -4
  113. package/dist/{chunk-N7LYEA3K.js → chunk-JOQZRIL4.js} +2 -2
  114. package/dist/{chunk-DLX277NS.js → chunk-JXAHMR5L.js} +2 -2
  115. package/dist/{chunk-POXJ3KXJ.js → chunk-KG7RO5XU.js} +3 -3
  116. package/dist/{chunk-JVNGFQJN.js → chunk-KJ3Z7JHF.js} +1 -1
  117. package/dist/{chunk-JVNGFQJN.js.map → chunk-KJ3Z7JHF.js.map} +1 -1
  118. package/dist/{chunk-R45L4TV6.js → chunk-KQAFEZQX.js} +6 -6
  119. package/dist/{chunk-L6CMR5OI.js → chunk-L2DACC2T.js} +2 -2
  120. package/dist/{chunk-77SYM565.js → chunk-LD7I5AZW.js} +9 -9
  121. package/dist/{chunk-OYUTSLBU.js → chunk-LKXED2DT.js} +14 -14
  122. package/dist/{chunk-3KQPFIVV.js → chunk-LMFINE37.js} +2 -2
  123. package/dist/{chunk-OYHGCAGQ.js → chunk-LYM65HMS.js} +2 -2
  124. package/dist/{chunk-OV3XHQAB.js → chunk-LYSE5FNF.js} +43 -48
  125. package/dist/chunk-LYSE5FNF.js.map +1 -0
  126. package/dist/{chunk-MEALRZYB.js → chunk-MKJBZR7J.js} +2 -2
  127. package/dist/{chunk-AGJJTD3Q.js → chunk-MONIOXEG.js} +2 -2
  128. package/dist/{chunk-RVUD4WN3.js → chunk-ND7ZKKVK.js} +2 -2
  129. package/dist/{chunk-PKPW7MXT.js → chunk-O7CHKXSF.js} +4 -4
  130. package/dist/{chunk-UH3FPX3L.js → chunk-OM5ESBES.js} +2 -2
  131. package/dist/{chunk-Y6IRNAWT.js → chunk-OSM5MKAU.js} +2 -2
  132. package/dist/chunk-PXY2B7BG.js +51 -0
  133. package/dist/chunk-PXY2B7BG.js.map +1 -0
  134. package/dist/{chunk-5IGWEYNV.js → chunk-QDY4TSKK.js} +3 -3
  135. package/dist/{chunk-IJBOJJVS.js → chunk-QP6CBFYL.js} +2 -2
  136. package/dist/{chunk-MZCGHPIJ.js → chunk-RB7NXZ2E.js} +2 -2
  137. package/dist/{chunk-FJVWKIDV.js → chunk-RMPHPB6B.js} +2 -2
  138. package/dist/{chunk-QPOWOQYH.js → chunk-RXXXT5PA.js} +6 -6
  139. package/dist/{chunk-FYH62SF3.js → chunk-S627NPRV.js} +6 -6
  140. package/dist/{chunk-YCNSMVWG.js → chunk-SDGD6MYV.js} +64 -3
  141. package/dist/chunk-SDGD6MYV.js.map +1 -0
  142. package/dist/{chunk-6DHSEJIO.js → chunk-SXVU57SW.js} +2 -2
  143. package/dist/{chunk-YWXFO7G2.js → chunk-TAUBEJ37.js} +5 -5
  144. package/dist/{chunk-GOZXQNIM.js → chunk-TH6OYP6I.js} +3 -3
  145. package/dist/{chunk-QJJURIZV.js → chunk-TNACU47L.js} +3 -3
  146. package/dist/{chunk-4Y26S76X.js → chunk-TRFSTCQK.js} +14 -2
  147. package/dist/chunk-TRFSTCQK.js.map +1 -0
  148. package/dist/{chunk-YLTU2DC4.js → chunk-U2PSE7MB.js} +2 -2
  149. package/dist/{chunk-2VS3DAXE.js → chunk-V3D2OOVE.js} +2 -2
  150. package/dist/{chunk-PCMGMPQZ.js → chunk-X4EF7IG3.js} +4 -4
  151. package/dist/{chunk-DQEMWVMT.js → chunk-X7Y7WX73.js} +1 -1
  152. package/dist/{chunk-CBTERRF5.js → chunk-XCJDDXJX.js} +2 -2
  153. package/dist/{chunk-RSRHWNNM.js → chunk-XPDMJC5O.js} +3 -3
  154. package/dist/{chunk-NLSMLRH4.js → chunk-XTGQTSZZ.js} +2 -2
  155. package/dist/{chunk-EZ25VE3G.js → chunk-YNDLCWXS.js} +4 -4
  156. package/dist/chunk-YRHBSYQR.js +15 -0
  157. package/dist/chunk-YRHBSYQR.js.map +1 -0
  158. package/dist/{chunk-VEPT6DXJ.js → chunk-YVK7WZYC.js} +5 -5
  159. package/dist/{chunk-2IMKMMUS.js → chunk-ZDWZYKCL.js} +11 -11
  160. package/dist/{chunk-FAPJG3OG.js → chunk-ZDZJNXL6.js} +4 -4
  161. package/dist/{chunk-BNQJKWWZ.js → chunk-ZG4GNPRE.js} +8 -8
  162. package/dist/cli.js +189 -183
  163. package/dist/coding/export-okf-codegraph.js +21 -21
  164. package/dist/coding/pre-action-gate.js +2 -2
  165. package/dist/compounding/engine.js +23 -23
  166. package/dist/config.js +33 -33
  167. package/dist/connectors/codex-materialize-runner.js +22 -22
  168. package/dist/connectors/index.js +22 -22
  169. package/dist/contradiction/index.js +7 -7
  170. package/dist/convergence-refresh.js +24 -24
  171. package/dist/corpus-watermark.js +24 -24
  172. package/dist/dashboard-runtime.js +2 -2
  173. package/dist/deep-recall-http-glue.js +10 -10
  174. package/dist/deep-recall.js +2 -2
  175. package/dist/entity-retrieval.js +25 -25
  176. package/dist/event-order-recall.js +4 -4
  177. package/dist/explicit-capture.js +189 -183
  178. package/dist/extraction-span-materialize.js +2 -2
  179. package/dist/extraction.js +32 -32
  180. package/dist/{graph-edge-decay-EKWXRBWF.js → graph-edge-decay-BC3IO2J4.js} +6 -6
  181. package/dist/graph-edge-decay-BC3IO2J4.js.map +1 -0
  182. package/dist/graph-jsonl.js +4 -4
  183. package/dist/graph-snapshot.js +4 -4
  184. package/dist/graph.js +5 -5
  185. package/dist/harmonic-retrieval.js +22 -22
  186. package/dist/index.js +324 -318
  187. package/dist/lcm/engine.js +3 -3
  188. package/dist/lcm/index.js +9 -9
  189. package/dist/local-llm.js +3 -3
  190. package/dist/location/index.js +23 -23
  191. package/dist/maintenance/memory-governance.js +22 -22
  192. package/dist/maintenance/rebuild-memory-lifecycle-ledger.js +22 -22
  193. package/dist/maintenance/rebuild-memory-projection-runner.js +24 -24
  194. package/dist/maintenance/rebuild-memory-projection.js +23 -23
  195. package/dist/memory-browse.js +7 -7
  196. package/dist/memory-subject.js +1 -1
  197. package/dist/namespaces/migrate.js +23 -23
  198. package/dist/namespaces/search.js +7 -7
  199. package/dist/namespaces/storage.js +22 -22
  200. package/dist/offline-sync-changeset-generations.js +3 -3
  201. package/dist/offline-sync-embedding-generation.js +2 -2
  202. package/dist/offline-sync-snapshot-stream.js +6 -6
  203. package/dist/offline-sync.js +7 -7
  204. package/dist/operator-doctor-corpus.js +25 -25
  205. package/dist/operator-toolkit.js +43 -43
  206. package/dist/orchestration/backlog-scheduler.js +190 -184
  207. package/dist/orchestration/backlog-scheduler.js.map +1 -1
  208. package/dist/orchestration/buffer-drain-runner.js +190 -184
  209. package/dist/orchestration/maintenance.js +34 -34
  210. package/dist/orchestration/recall-internal.d.ts.map +1 -1
  211. package/dist/orchestration/turn-ingestion-buffered.d.ts +13 -0
  212. package/dist/orchestration/turn-ingestion-buffered.d.ts.map +1 -0
  213. package/dist/orchestration/turn-ingestion.d.ts +2 -2
  214. package/dist/orchestration/turn-ingestion.d.ts.map +1 -1
  215. package/dist/orchestrator.js +189 -183
  216. package/dist/qmd.js +3 -3
  217. package/dist/recall-attempt-timing.d.ts +18 -0
  218. package/dist/recall-attempt-timing.d.ts.map +1 -0
  219. package/dist/recall-attempt-timing.js +14 -0
  220. package/dist/recall-attempt-timing.js.map +1 -0
  221. package/dist/recall-enrichment-promise.d.ts +22 -0
  222. package/dist/recall-enrichment-promise.d.ts.map +1 -0
  223. package/dist/recall-enrichment-promise.js +10 -0
  224. package/dist/recall-enrichment-promise.js.map +1 -0
  225. package/dist/recall-explain-renderer.js +3 -3
  226. package/dist/recall-navigate-access.js +2 -2
  227. package/dist/recall-navigate-disclosure.js +2 -2
  228. package/dist/recall-navigate.js +2 -2
  229. package/dist/recall-navigation.js +189 -183
  230. package/dist/recall-phase2-timing.d.ts +44 -0
  231. package/dist/recall-phase2-timing.d.ts.map +1 -0
  232. package/dist/recall-phase2-timing.js +22 -0
  233. package/dist/recall-phase2-timing.js.map +1 -0
  234. package/dist/recall-state-view-admission.js +6 -6
  235. package/dist/recall-timings.d.ts +35 -0
  236. package/dist/recall-timings.d.ts.map +1 -1
  237. package/dist/recall-timings.js +2 -1
  238. package/dist/recall-why-service.js +8 -8
  239. package/dist/recall-xray-cli.js +4 -4
  240. package/dist/recall-xray-renderer.js +3 -3
  241. package/dist/recall-xray.js +2 -2
  242. package/dist/reconcile/manifest.js +3 -3
  243. package/dist/{resolution-A3NAI3YE.js → resolution-TCO63RRC.js} +8 -8
  244. package/dist/resolution-TCO63RRC.js.map +1 -0
  245. package/dist/resume-bundles.js +34 -34
  246. package/dist/salvage-envelope.js +1 -1
  247. package/dist/search/factory.js +6 -6
  248. package/dist/search/index.js +10 -10
  249. package/dist/semantic-consolidation.js +23 -23
  250. package/dist/semantic-rule-promotion.js +22 -22
  251. package/dist/semantic-rule-verifier.js +22 -22
  252. package/dist/source-agent-qualifier.js +25 -25
  253. package/dist/standup/build.js +22 -22
  254. package/dist/storage/buffer-drain-claims.js +2 -2
  255. package/dist/storage/buffer-session-files.d.ts +4 -0
  256. package/dist/storage/buffer-session-files.d.ts.map +1 -1
  257. package/dist/storage/buffer-session-files.js +2 -2
  258. package/dist/storage.d.ts +1 -0
  259. package/dist/storage.d.ts.map +1 -1
  260. package/dist/storage.js +22 -22
  261. package/dist/subject-config.js +1 -1
  262. package/dist/summarizer.js +5 -5
  263. package/dist/support-passport/index.js +8 -8
  264. package/dist/transfer/autodetect.js +1 -1
  265. package/dist/transfer/backup.js +2 -2
  266. package/dist/transfer/capsule-export.js +3 -3
  267. package/dist/transfer/capsule-import.js +2 -2
  268. package/dist/transfer/export-okf.js +23 -23
  269. package/dist/types.d.ts +2 -0
  270. package/dist/types.d.ts.map +1 -1
  271. package/dist/types.js +1 -1
  272. package/dist/verified-recall.js +22 -22
  273. package/dist/who-knows-cli.js +23 -23
  274. package/dist/who-knows.js +22 -22
  275. package/dist/write-envelope.js +1 -1
  276. package/package.json +2 -2
  277. package/src/access-correlation.ts +17 -0
  278. package/src/access-http.ts +7 -8
  279. package/src/access-observe-write-surface.ts +10 -0
  280. package/src/access-service.ts +3 -1
  281. package/src/buffer-add-turns-bounded.ts +97 -0
  282. package/src/buffer-admission-idempotency.test.ts +297 -0
  283. package/src/buffer-admission-idempotency.ts +67 -0
  284. package/src/buffer-drain-handover.test.ts +1 -0
  285. package/src/buffer-persistence.ts +19 -1
  286. package/src/buffer-turn-helpers.ts +8 -1
  287. package/src/buffer-types.ts +1 -0
  288. package/src/buffer.ts +40 -43
  289. package/src/orchestration/recall-internal.ts +63 -75
  290. package/src/orchestration/turn-ingestion-buffered.ts +74 -0
  291. package/src/orchestration/turn-ingestion.ts +4 -78
  292. package/src/recall-attempt-timing.ts +78 -0
  293. package/src/recall-enrichment-promise.ts +62 -0
  294. package/src/recall-phase2-timing.ts +146 -0
  295. package/src/recall-timings-access.test.ts +140 -2
  296. package/src/recall-timings-request-contract.test.ts +488 -0
  297. package/src/recall-timings.ts +70 -0
  298. package/src/storage/buffer-session-files.ts +71 -0
  299. package/src/storage.ts +1 -0
  300. package/src/types.ts +2 -0
  301. package/dist/chunk-2LQUPEWF.js.map +0 -1
  302. package/dist/chunk-4Y26S76X.js.map +0 -1
  303. package/dist/chunk-FWDVW2BD.js.map +0 -1
  304. package/dist/chunk-G4NKURT4.js.map +0 -1
  305. package/dist/chunk-OV3XHQAB.js.map +0 -1
  306. package/dist/chunk-YCNSMVWG.js.map +0 -1
  307. /package/dist/{capsule-crypto-YO5QJ6L3.js.map → access-correlation.js.map} +0 -0
  308. /package/dist/{graph-edge-decay-EKWXRBWF.js.map → buffer-add-turns-bounded.js.map} +0 -0
  309. /package/dist/{resolution-A3NAI3YE.js.map → buffer-admission-idempotency.js.map} +0 -0
  310. /package/dist/{chunk-AWKD2A73.js.map → chunk-2NGTY22Z.js.map} +0 -0
  311. /package/dist/{chunk-BXLOS5AJ.js.map → chunk-2NLLXCJG.js.map} +0 -0
  312. /package/dist/{chunk-EDGWAJLS.js.map → chunk-2WD2TRTJ.js.map} +0 -0
  313. /package/dist/{chunk-AOZYOS4G.js.map → chunk-3MXQ5XJT.js.map} +0 -0
  314. /package/dist/{chunk-XGDWR2L6.js.map → chunk-3NLBDM7V.js.map} +0 -0
  315. /package/dist/{chunk-XVZA6VXC.js.map → chunk-3SL52JKD.js.map} +0 -0
  316. /package/dist/{chunk-LE27GU4M.js.map → chunk-4N4BAO66.js.map} +0 -0
  317. /package/dist/{chunk-UC3KG7KX.js.map → chunk-4WX32RLU.js.map} +0 -0
  318. /package/dist/{chunk-WVV54HL2.js.map → chunk-4Y4LPKFV.js.map} +0 -0
  319. /package/dist/{chunk-MFDEEOOZ.js.map → chunk-5BE3FLKL.js.map} +0 -0
  320. /package/dist/{chunk-MPQQIHA7.js.map → chunk-5LL2X5SO.js.map} +0 -0
  321. /package/dist/{chunk-CBJRI6VJ.js.map → chunk-64TIBZPZ.js.map} +0 -0
  322. /package/dist/{chunk-LL7WIK2Z.js.map → chunk-6NPLVV6M.js.map} +0 -0
  323. /package/dist/{chunk-DC55RIEZ.js.map → chunk-73TPOGS4.js.map} +0 -0
  324. /package/dist/{chunk-XF2QQQXO.js.map → chunk-7P72BY4F.js.map} +0 -0
  325. /package/dist/{chunk-XUKBX3GO.js.map → chunk-7YHU3NJD.js.map} +0 -0
  326. /package/dist/{chunk-6CSWINXA.js.map → chunk-AIDFYS4Z.js.map} +0 -0
  327. /package/dist/{chunk-E23BTVB2.js.map → chunk-AO5LKFGO.js.map} +0 -0
  328. /package/dist/{chunk-JY3WATTF.js.map → chunk-C6Z3H23R.js.map} +0 -0
  329. /package/dist/{chunk-VAVCFMMQ.js.map → chunk-CJ2SYU4S.js.map} +0 -0
  330. /package/dist/{chunk-WZ55LEUN.js.map → chunk-CLVILSBR.js.map} +0 -0
  331. /package/dist/{chunk-B72X3KWL.js.map → chunk-COJBTRTQ.js.map} +0 -0
  332. /package/dist/{chunk-NWS4I4K7.js.map → chunk-CVCKYMVX.js.map} +0 -0
  333. /package/dist/{chunk-6MEQHJTF.js.map → chunk-FMFCQRDM.js.map} +0 -0
  334. /package/dist/{chunk-A3EWNU5V.js.map → chunk-G2TK5YYU.js.map} +0 -0
  335. /package/dist/{chunk-WWQMZBDI.js.map → chunk-GCHM5BYL.js.map} +0 -0
  336. /package/dist/{chunk-RHQSAXN3.js.map → chunk-GCQIXPWZ.js.map} +0 -0
  337. /package/dist/{chunk-VEFGHRKV.js.map → chunk-GMO3BGOF.js.map} +0 -0
  338. /package/dist/{chunk-I3UBDUHO.js.map → chunk-H6OTEBPK.js.map} +0 -0
  339. /package/dist/{chunk-MIG4KRYU.js.map → chunk-HADCITEA.js.map} +0 -0
  340. /package/dist/{chunk-M43GO34S.js.map → chunk-HASIFVWH.js.map} +0 -0
  341. /package/dist/{chunk-RQBYC7EK.js.map → chunk-HLWXCDUQ.js.map} +0 -0
  342. /package/dist/{chunk-JVSHXYOO.js.map → chunk-HOGSBSCH.js.map} +0 -0
  343. /package/dist/{chunk-BFPF5N3H.js.map → chunk-HXFIILGF.js.map} +0 -0
  344. /package/dist/{chunk-2JAT4S7N.js.map → chunk-IMULTENA.js.map} +0 -0
  345. /package/dist/{chunk-B4I37XX6.js.map → chunk-IOMWNBMH.js.map} +0 -0
  346. /package/dist/{chunk-74BX5NCU.js.map → chunk-IXR3SNHL.js.map} +0 -0
  347. /package/dist/{chunk-2S4XW47C.js.map → chunk-J3EU5H7W.js.map} +0 -0
  348. /package/dist/{chunk-EUL3S3LE.js.map → chunk-J5WI4QRP.js.map} +0 -0
  349. /package/dist/{chunk-N7LYEA3K.js.map → chunk-JOQZRIL4.js.map} +0 -0
  350. /package/dist/{chunk-DLX277NS.js.map → chunk-JXAHMR5L.js.map} +0 -0
  351. /package/dist/{chunk-POXJ3KXJ.js.map → chunk-KG7RO5XU.js.map} +0 -0
  352. /package/dist/{chunk-R45L4TV6.js.map → chunk-KQAFEZQX.js.map} +0 -0
  353. /package/dist/{chunk-L6CMR5OI.js.map → chunk-L2DACC2T.js.map} +0 -0
  354. /package/dist/{chunk-77SYM565.js.map → chunk-LD7I5AZW.js.map} +0 -0
  355. /package/dist/{chunk-OYUTSLBU.js.map → chunk-LKXED2DT.js.map} +0 -0
  356. /package/dist/{chunk-3KQPFIVV.js.map → chunk-LMFINE37.js.map} +0 -0
  357. /package/dist/{chunk-OYHGCAGQ.js.map → chunk-LYM65HMS.js.map} +0 -0
  358. /package/dist/{chunk-MEALRZYB.js.map → chunk-MKJBZR7J.js.map} +0 -0
  359. /package/dist/{chunk-AGJJTD3Q.js.map → chunk-MONIOXEG.js.map} +0 -0
  360. /package/dist/{chunk-RVUD4WN3.js.map → chunk-ND7ZKKVK.js.map} +0 -0
  361. /package/dist/{chunk-PKPW7MXT.js.map → chunk-O7CHKXSF.js.map} +0 -0
  362. /package/dist/{chunk-UH3FPX3L.js.map → chunk-OM5ESBES.js.map} +0 -0
  363. /package/dist/{chunk-Y6IRNAWT.js.map → chunk-OSM5MKAU.js.map} +0 -0
  364. /package/dist/{chunk-5IGWEYNV.js.map → chunk-QDY4TSKK.js.map} +0 -0
  365. /package/dist/{chunk-IJBOJJVS.js.map → chunk-QP6CBFYL.js.map} +0 -0
  366. /package/dist/{chunk-MZCGHPIJ.js.map → chunk-RB7NXZ2E.js.map} +0 -0
  367. /package/dist/{chunk-FJVWKIDV.js.map → chunk-RMPHPB6B.js.map} +0 -0
  368. /package/dist/{chunk-QPOWOQYH.js.map → chunk-RXXXT5PA.js.map} +0 -0
  369. /package/dist/{chunk-FYH62SF3.js.map → chunk-S627NPRV.js.map} +0 -0
  370. /package/dist/{chunk-6DHSEJIO.js.map → chunk-SXVU57SW.js.map} +0 -0
  371. /package/dist/{chunk-YWXFO7G2.js.map → chunk-TAUBEJ37.js.map} +0 -0
  372. /package/dist/{chunk-GOZXQNIM.js.map → chunk-TH6OYP6I.js.map} +0 -0
  373. /package/dist/{chunk-QJJURIZV.js.map → chunk-TNACU47L.js.map} +0 -0
  374. /package/dist/{chunk-YLTU2DC4.js.map → chunk-U2PSE7MB.js.map} +0 -0
  375. /package/dist/{chunk-2VS3DAXE.js.map → chunk-V3D2OOVE.js.map} +0 -0
  376. /package/dist/{chunk-PCMGMPQZ.js.map → chunk-X4EF7IG3.js.map} +0 -0
  377. /package/dist/{chunk-DQEMWVMT.js.map → chunk-X7Y7WX73.js.map} +0 -0
  378. /package/dist/{chunk-CBTERRF5.js.map → chunk-XCJDDXJX.js.map} +0 -0
  379. /package/dist/{chunk-RSRHWNNM.js.map → chunk-XPDMJC5O.js.map} +0 -0
  380. /package/dist/{chunk-NLSMLRH4.js.map → chunk-XTGQTSZZ.js.map} +0 -0
  381. /package/dist/{chunk-EZ25VE3G.js.map → chunk-YNDLCWXS.js.map} +0 -0
  382. /package/dist/{chunk-VEPT6DXJ.js.map → chunk-YVK7WZYC.js.map} +0 -0
  383. /package/dist/{chunk-2IMKMMUS.js.map → chunk-ZDWZYKCL.js.map} +0 -0
  384. /package/dist/{chunk-FAPJG3OG.js.map → chunk-ZDZJNXL6.js.map} +0 -0
  385. /package/dist/{chunk-BNQJKWWZ.js.map → chunk-ZG4GNPRE.js.map} +0 -0
@@ -0,0 +1,67 @@
1
+ /** Fields on {@link BufferState} used by observe-buffer idempotency (#3368). */
2
+ export interface BufferAdmissionIdempotencyState {
3
+ admissionIdempotency?: Record<string, number>;
4
+ admissionIdempotencyOrder?: string[];
5
+ }
6
+
7
+ export const BUFFER_ADMISSION_IDEMPOTENCY_CAP = 512;
8
+
9
+ /** Client observe idempotency keys are namespaced by durable capture scope. */
10
+ export function scopeObserveBufferAdmissionIdempotencyKey(input: {
11
+ sessionKey: string;
12
+ writeNamespace: string;
13
+ principal?: string;
14
+ clientKey: string;
15
+ }): string {
16
+ const principal = input.principal?.trim() ?? "";
17
+ const client = input.clientKey.trim();
18
+ return `obs\u001f${input.writeNamespace}\u001f${principal}\u001f${input.sessionKey}\u001e${client}`;
19
+ }
20
+
21
+ export function ensureAdmissionIdempotencyMap(state: BufferAdmissionIdempotencyState): Record<string, number> {
22
+ const existing = state.admissionIdempotency;
23
+ if (existing && Object.getPrototypeOf(existing) === null) return existing;
24
+ // SAFETY: prototype-free map contract for observe idempotency keys (#3368).
25
+ const map = Object.create(null) as Record<string, number>;
26
+ if (existing) {
27
+ for (const key of Object.keys(existing)) {
28
+ if (Object.hasOwn(existing, key)) map[key] = existing[key]!;
29
+ }
30
+ }
31
+ state.admissionIdempotency = map;
32
+ return map;
33
+ }
34
+
35
+ export function ensureAdmissionIdempotencyOrder(state: BufferAdmissionIdempotencyState): string[] {
36
+ if (!state.admissionIdempotencyOrder) {
37
+ state.admissionIdempotencyOrder = [];
38
+ }
39
+ const order = state.admissionIdempotencyOrder;
40
+ const map = state.admissionIdempotency;
41
+ if (map) {
42
+ for (const key of Object.keys(map)) {
43
+ if (Object.hasOwn(map, key) && !order.includes(key)) order.push(key);
44
+ }
45
+ }
46
+ return order;
47
+ }
48
+
49
+ export function hasBufferedAdmissionIdempotencyKey(state: BufferAdmissionIdempotencyState, key: string): boolean {
50
+ const trimmed = key.trim();
51
+ if (!trimmed) return false;
52
+ const map = state.admissionIdempotency;
53
+ return map !== undefined && Object.hasOwn(map, trimmed);
54
+ }
55
+
56
+ export function recordBufferedAdmissionIdempotencyKey(state: BufferAdmissionIdempotencyState, key: string, turnCount: number): void {
57
+ const trimmed = key.trim();
58
+ if (!trimmed || turnCount <= 0) return;
59
+ const map = ensureAdmissionIdempotencyMap(state);
60
+ const order = ensureAdmissionIdempotencyOrder(state);
61
+ map[trimmed] = turnCount;
62
+ if (!order.includes(trimmed)) order.push(trimmed);
63
+ while (order.length > BUFFER_ADMISSION_IDEMPOTENCY_CAP) {
64
+ const evicted = order.shift();
65
+ if (evicted !== undefined) delete map[evicted];
66
+ }
67
+ }
@@ -85,6 +85,7 @@ function makeHarness(): Harness {
85
85
  loadBuffer: () => files.load(),
86
86
  saveBuffer: (state: BufferState) => files.reconcile(state),
87
87
  saveBufferSession: (key: string, entryState: BufferEntryState) => files.save(key, entryState),
88
+ saveBufferAdmissionIdempotency: (state: BufferState) => files.saveAdmissionIdempotency(state),
88
89
  deleteBufferSession: (key: string) => files.remove(key),
89
90
  isBufferSessionClaimed: (key: string) => files.isClaimed(key),
90
91
  };
@@ -21,6 +21,8 @@ export interface BufferStorage {
21
21
  isBufferSessionClaimed?(key: string): boolean;
22
22
  /** Optional surprise-telemetry sink; older storage and test doubles omit it. */
23
23
  appendBufferSurpriseEvents?(events: BufferSurpriseEvent[]): Promise<number>;
24
+ /** Persist observe-buffer idempotency metadata (#3368 production path). */
25
+ saveBufferAdmissionIdempotency?(state: BufferState): Promise<void>;
24
26
  }
25
27
 
26
28
  /** What one persist pass changed beyond plain writes. */
@@ -95,6 +97,7 @@ export interface BufferSessionPersistenceOptions {
95
97
  export class BufferSessionPersistence {
96
98
  private readonly dirty = new Set<string>();
97
99
  private readonly deleted = new Set<string>();
100
+ private admissionIdempotencyDirty = false;
98
101
  /** Last successful session-file write per key (deferral bookkeeping, #3389). */
99
102
  private readonly lastPersistedAt = new Map<string, number>();
100
103
  private readonly clock: () => number;
@@ -121,8 +124,12 @@ export class BufferSessionPersistence {
121
124
  for (const key of keys) this.markDeleted(key);
122
125
  }
123
126
 
127
+ markAdmissionIdempotencyDirty(): void {
128
+ this.admissionIdempotencyDirty = true;
129
+ }
130
+
124
131
  hasPending(): boolean {
125
- return this.dirty.size > 0 || this.deleted.size > 0;
132
+ return this.dirty.size > 0 || this.deleted.size > 0 || this.admissionIdempotencyDirty;
126
133
  }
127
134
 
128
135
  /**
@@ -149,8 +156,12 @@ export class BufferSessionPersistence {
149
156
  const deleteSession = storage.deleteBufferSession?.bind(storage);
150
157
  if (!saveSession || !deleteSession) {
151
158
  await storage.saveBuffer(state);
159
+ if (this.admissionIdempotencyDirty && storage.saveBufferAdmissionIdempotency) {
160
+ await storage.saveBufferAdmissionIdempotency(state);
161
+ }
152
162
  this.dirty.clear();
153
163
  this.deleted.clear();
164
+ this.admissionIdempotencyDirty = false;
154
165
  return { handedOver: [], drainedTurns, deferred: [] };
155
166
  }
156
167
  const now = opts?.now ?? this.clock;
@@ -204,6 +215,13 @@ export class BufferSessionPersistence {
204
215
  }
205
216
  if (saveOutcome?.status === "handed_over") this.lastPersistedAt.delete(key);
206
217
  }
218
+ // #3368: never persist admission keys while session bodies are still deferred —
219
+ // a crash after the key lands but before the deferred rewrite would make a
220
+ // same-key retry swallow the unwritten turns.
221
+ if (this.admissionIdempotencyDirty && deferred.length === 0 && storage.saveBufferAdmissionIdempotency) {
222
+ await storage.saveBufferAdmissionIdempotency(state);
223
+ this.admissionIdempotencyDirty = false;
224
+ }
207
225
  const outcome: BufferPersistOutcome = { handedOver, drainedTurns, deferred };
208
226
  if (deferred.length > 0 && nextEligibleAt !== undefined) {
209
227
  outcome.deferredRetryDelayMs = Math.max(0, nextEligibleAt - now());
@@ -453,12 +453,19 @@ export function normalizeBufferState(state: BufferState): BufferState {
453
453
  extractionCount: state.extractionCount ?? 0,
454
454
  };
455
455
  }
456
- return {
456
+ const normalized: BufferState = {
457
457
  turns: entries.default.turns,
458
458
  lastExtractionAt: entries.default.lastExtractionAt,
459
459
  extractionCount: entries.default.extractionCount,
460
460
  entries,
461
461
  };
462
+ if (state.admissionIdempotency) {
463
+ normalized.admissionIdempotency = Object.assign(Object.create(null), state.admissionIdempotency);
464
+ if (state.admissionIdempotencyOrder) {
465
+ normalized.admissionIdempotencyOrder = [...state.admissionIdempotencyOrder];
466
+ }
467
+ }
468
+ return normalized;
462
469
  }
463
470
 
464
471
  /** Trigger-mode decision for a buffer entry (extracted from SmartBuffer to
@@ -1,6 +1,7 @@
1
1
  /** Types split out of buffer.ts (structural ratchet, issue #1995). */
2
2
 
3
3
  import type { BufferTurn, CodingContext, SignalLevel } from "./types.js";
4
+
4
5
  import type { ResolvedScopeProfilePlan } from "./namespaces/scope-profiles.js";
5
6
 
6
7
  export type TriggerDecision = "extract_now" | "extract_batch" | "keep_buffering";
package/src/buffer.ts CHANGED
@@ -36,7 +36,8 @@ import {
36
36
  } from "./buffer-turn-helpers.js";
37
37
  import { BufferAdmissionRefusedError, BufferSessionTurnRefusedError, canAdmitNewEntryUnlocked } from "./buffer-admission.js";
38
38
  import { BufferIngressCounters } from "./buffer-ingress-counters.js";
39
- import { refuseOverCapBatch, refuseOverCapSingle, resolveMaxTurnsPerSession, sessionTurnCapReached } from "./buffer-session-cap.js";
39
+ import { addTurnsBoundedWithAdmissionKey, type AddTurnsBoundedHost } from "./buffer-add-turns-bounded.js";
40
+ import { refuseOverCapSingle, resolveMaxTurnsPerSession, sessionTurnCapReached } from "./buffer-session-cap.js";
40
41
  export { BufferAdmissionRefusedError, BufferSessionTurnRefusedError } from "./buffer-admission.js";
41
42
  import type { AddTurnMutationResult, AddTurnOutcome, RetainedTurnCleanupOptions, TriggerDecision } from "./buffer-types.js";
42
43
 
@@ -48,6 +49,7 @@ import type { BufferSurpriseProbe, SurpriseTelemetryQueueEntry } from "./buffer-
48
49
  // Raised from 200 in #3303: live captures were being dropped at busy hours
49
50
  // while the single extraction worker drained a backlog.
50
51
  const FALLBACK_MAX_BUFFER_SESSIONS = 1000;
52
+ export { BUFFER_ADMISSION_IDEMPOTENCY_CAP } from "./buffer-admission-idempotency.js";
51
53
 
52
54
  /**
53
55
  * Upper bound on how long a debounced buffer save may be deferred under
@@ -510,52 +512,47 @@ export class SmartBuffer {
510
512
  * Preflight every new key under the mutation lock before persisting any
511
513
  * turn; refusal records nothing and drops nothing.
512
514
  */
515
+
516
+ private addTurnsBoundedHost(): AddTurnsBoundedHost {
517
+ const self = this;
518
+ return {
519
+ get config() {
520
+ return self.config;
521
+ },
522
+ get maxSessionEntries() {
523
+ return self.maxSessionEntries;
524
+ },
525
+ get state() {
526
+ return self.state;
527
+ },
528
+ get persistence() {
529
+ return self.persistence;
530
+ },
531
+ get ingress() {
532
+ return self.ingress;
533
+ },
534
+ enqueueMutation: (work) => self.enqueueMutation(work),
535
+ loadUnlocked: () => self.loadUnlocked(),
536
+ peekEntry: (bufferKey) => self.peekEntry(bufferKey),
537
+ recordTurnUnlocked: (bufferKey, turn) => self.recordTurnUnlocked(bufferKey, turn),
538
+ completeAddTurnOutcome: (bufferKey, turn, mutation) =>
539
+ self.completeAddTurnOutcome(bufferKey, turn, mutation),
540
+ };
541
+ }
542
+
513
543
  async addTurnsBounded(
514
544
  batches: readonly { bufferKey: string; turns: readonly BufferTurn[] }[],
515
545
  ): Promise<Array<{ bufferKey: string; turn: BufferTurn; outcome: AddTurnOutcome }> | null> {
516
- const pending = await this.enqueueMutation(async () => {
517
- await this.loadUnlocked();
518
- const additions: Array<{ bufferKey: string; turn: BufferTurn }> = [];
519
- for (const batch of batches) {
520
- for (const turn of batch.turns) {
521
- additions.push({ bufferKey: batch.bufferKey, turn });
522
- }
523
- }
524
-
525
- if (refuseOverCapBatch((key) => this.peekEntry(key), batches, resolveMaxTurnsPerSession(this.config.bufferMaxTurnsPerSession))) return this.ingress.refuseAll(additions);
526
- const entries = this.state.entries ?? {};
527
- const newKeys = [...new Set(
528
- additions
529
- .map(({ bufferKey }) => bufferKey)
530
- .filter((bufferKey) => this.peekEntry(bufferKey) === null),
531
- )];
532
- const count = Object.keys(entries).length;
533
- const requiredEvictions = Math.max(0, count + newKeys.length - this.maxSessionEntries);
534
- if (requiredEvictions > 0) {
535
- const target = Math.max(0, this.maxSessionEntries - newKeys.length);
536
- const evicted = selectEvictedBufferKeys(entries, newKeys, target, EVICTION_HOOKS);
537
- if (newKeys.length > 0 && evicted.length < requiredEvictions) return this.ingress.refuseAll(additions);
538
- for (const key of evicted) delete entries[key];
539
- this.persistence.markEvicted(evicted);
540
- }
541
-
542
- const recorded: Array<{ bufferKey: string; turn: BufferTurn; mutation: AddTurnMutationResult }> = [];
543
- for (const { bufferKey, turn } of additions) {
544
- recorded.push({ bufferKey, turn, mutation: await this.recordTurnUnlocked(bufferKey, turn) });
545
- }
546
- return recorded;
547
- });
548
- if (pending === null) return null;
546
+ const result = await addTurnsBoundedWithAdmissionKey(this.addTurnsBoundedHost(), batches);
547
+ return result === "duplicate" ? null : result;
548
+ }
549
549
 
550
- const outcomes: Array<{ bufferKey: string; turn: BufferTurn; outcome: AddTurnOutcome }> = [];
551
- for (const item of pending) {
552
- outcomes.push({
553
- bufferKey: item.bufferKey,
554
- turn: item.turn,
555
- outcome: await this.completeAddTurnOutcome(item.bufferKey, item.turn, item.mutation),
556
- });
557
- }
558
- return outcomes;
550
+ /** #3368 durable observe replay only; duplicate means the scoped client key already landed. */
551
+ async addTurnsBoundedForObserveReplay(
552
+ batches: readonly { bufferKey: string; turns: readonly BufferTurn[] }[],
553
+ admissionKey: string,
554
+ ): Promise<Array<{ bufferKey: string; turn: BufferTurn; outcome: AddTurnOutcome }> | null | "duplicate"> {
555
+ return addTurnsBoundedWithAdmissionKey(this.addTurnsBoundedHost(), batches, admissionKey.trim());
559
556
  }
560
557
 
561
558
  /** Free one slot only when an empty entry can be reclaimed. */
@@ -65,7 +65,10 @@ import {
65
65
  type RecallXrayScoreDecomposition,
66
66
  buildXraySnapshot,
67
67
  } from "../recall-xray.js";
68
- import { foldQueueWaitTiming, recordRecallTiming } from "../recall-timings.js";
68
+ import { foldQueueWaitTiming } from "../recall-timings.js";
69
+ import { emitRecallTiming } from "../recall-attempt-timing.js";
70
+ import { createPhase2Timer, type Phase2AwaitStatus } from "../recall-phase2-timing.js";
71
+ import { createEnrichmentAbortHandle, observeEnrichmentPromise, type DeferredEnrichmentOutcome, type ObservedDeferredEnrichmentPromise } from "../recall-enrichment-promise.js";
69
72
  import { findUnresolvedEntityRefs } from "../reconstruct.js";
70
73
  import { rerankLocalOrNoop, reorderByRankedKeys } from "../rerank.js";
71
74
  import { buildResponseGuidanceRecallSection, shouldRecallResponseGuidance } from "../response-guidance-recall.js";
@@ -145,6 +148,10 @@ export class RecallInternalCoordinator {
145
148
  if (Number.isFinite(parsed)) asOfMs = parsed;
146
149
  }
147
150
  const timings = foldQueueWaitTiming(options.queueWaitMs); // #1906 queue-wait phase
151
+ // Phase-2 await timings (#1830): separate from `timings` so traces and the
152
+ // eval shadow keep their payloads; folded into the recall-timings record only.
153
+ const phase2Timings: Record<string, string> = {};
154
+ const phase2Timer = createPhase2Timer(phase2Timings, () => options.abortSignal?.aborted === true);
148
155
  const profileTraceId = this.deps.profiler.startTrace("recall", sessionKey, {
149
156
  qmdEnabled: resolveQmdCapabilities(this.deps.config).qmd,
150
157
  rerankEnabled: caps.rerank,
@@ -169,55 +176,6 @@ export class RecallInternalCoordinator {
169
176
  // Wrap entire recall body in try/finally so profiling trace is always closed,
170
177
  // even on unexpected exceptions (e.g., throwIfRecallAborted, phase-1 errors).
171
178
  try {
172
- type DeferredEnrichmentOutcome<T> =
173
- | { status: "resolved"; value: T }
174
- | { status: "rejected"; error: unknown };
175
- type ObservedDeferredEnrichmentPromise<T> =
176
- Promise<DeferredEnrichmentOutcome<T>> & {
177
- getSettledOutcome: () => DeferredEnrichmentOutcome<T> | undefined;
178
- cancel: () => void;
179
- };
180
- const createEnrichmentAbortHandle = (parentSignal?: AbortSignal) => {
181
- const controller = new AbortController();
182
- const onAbort = () => controller.abort();
183
- if (parentSignal?.aborted) {
184
- controller.abort();
185
- } else if (parentSignal) {
186
- parentSignal.addEventListener("abort", onAbort, { once: true });
187
- }
188
- let disposed = false;
189
- const dispose = () => {
190
- if (disposed) return;
191
- disposed = true;
192
- parentSignal?.removeEventListener("abort", onAbort);
193
- };
194
- return {
195
- signal: controller.signal,
196
- cancel: () => {
197
- controller.abort();
198
- dispose();
199
- },
200
- dispose,
201
- };
202
- };
203
- const observeEnrichmentPromise = <T>(
204
- promise: Promise<T>,
205
- cancel: () => void = () => {},
206
- ): ObservedDeferredEnrichmentPromise<T> => {
207
- let settledOutcome: DeferredEnrichmentOutcome<T> | undefined;
208
- const observed = promise
209
- .then<DeferredEnrichmentOutcome<T>, DeferredEnrichmentOutcome<T>>(
210
- (value) => ({ status: "resolved", value }),
211
- (error) => ({ status: "rejected", error }),
212
- )
213
- .then((outcome) => {
214
- settledOutcome = outcome;
215
- return outcome;
216
- }) as ObservedDeferredEnrichmentPromise<T>;
217
- observed.getSettledOutcome = () => settledOutcome;
218
- observed.cancel = cancel;
219
- return observed;
220
- };
221
179
  const recordRecallSectionMetric = createRecallSectionMetricRecorder({
222
180
  timings,
223
181
  logger: log,
@@ -548,7 +506,7 @@ export class RecallInternalCoordinator {
548
506
  const earlySessionKey = sessionKey ?? "default";
549
507
  this.deps._recallWorkspaceOverrides.delete(earlySessionKey);
550
508
  timings.total = `${Date.now() - recallStart}ms`;
551
- recordRecallTiming(this.deps.config, {
509
+ emitRecallTiming(this.deps.config, {
552
510
  ...timings,
553
511
  timestamp: new Date().toISOString(),
554
512
  namespace: selfNamespace,
@@ -1487,6 +1445,7 @@ export class RecallInternalCoordinator {
1487
1445
  return results.length > 0 ? this.deps.formatTrustZoneResults(results) : null;
1488
1446
  })();
1489
1447
 
1448
+ const harmonicStartedMs = performance.now();
1490
1449
  const harmonicRetrievalAbort = createEnrichmentAbortHandle(
1491
1450
  options.abortSignal,
1492
1451
  );
@@ -1835,6 +1794,7 @@ export class RecallInternalCoordinator {
1835
1794
  return results.length > 0 ? this.deps.formatWorkProductResults(results) : null;
1836
1795
  })();
1837
1796
 
1797
+ const prefilterStartedMs = performance.now();
1838
1798
  const queryAwarePrefilterPromise =
1839
1799
  (async (): Promise<QueryAwarePrefilter> => {
1840
1800
  const t0 = Date.now();
@@ -2698,6 +2658,7 @@ export class RecallInternalCoordinator {
2698
2658
  }
2699
2659
  })();
2700
2660
 
2661
+ const compoundingStartedMs = performance.now();
2701
2662
  const compoundingPromise = observeEnrichmentPromise(
2702
2663
  (async (): Promise<string | null> => {
2703
2664
  const t0 = Date.now();
@@ -2889,6 +2850,7 @@ export class RecallInternalCoordinator {
2889
2850
  const awaitEnrichmentSection = async <T>(
2890
2851
  name: string,
2891
2852
  promise: ObservedDeferredEnrichmentPromise<T>,
2853
+ onStatus?: (status: Phase2AwaitStatus) => void,
2892
2854
  ): Promise<T | null> => {
2893
2855
  const finalizeEnrichmentOutcome = (
2894
2856
  outcome: DeferredEnrichmentOutcome<T>,
@@ -2897,6 +2859,7 @@ export class RecallInternalCoordinator {
2897
2859
  log.debug(
2898
2860
  `recall phase-1 enrichment [${name}]: resolved at +${Date.now() - phase1Start}ms`,
2899
2861
  );
2862
+ onStatus?.("ok");
2900
2863
  return outcome.value;
2901
2864
  }
2902
2865
 
@@ -2904,12 +2867,14 @@ export class RecallInternalCoordinator {
2904
2867
  log.debug(
2905
2868
  `recall phase-1 enrichment [${name}]: skipped after abort at +${Date.now() - phase1Start}ms`,
2906
2869
  );
2870
+ onStatus?.("skipped");
2907
2871
  return null;
2908
2872
  }
2909
2873
  log.warn(
2910
2874
  `recall phase-1 enrichment [${name}] failed open: ` +
2911
2875
  `${outcome.error instanceof Error ? outcome.error.message : String(outcome.error)}`,
2912
2876
  );
2877
+ onStatus?.("error");
2913
2878
  return null;
2914
2879
  };
2915
2880
 
@@ -2918,6 +2883,7 @@ export class RecallInternalCoordinator {
2918
2883
  log.debug(
2919
2884
  `recall phase-1 enrichment [${name}]: skipped after abort at +${Date.now() - phase1Start}ms`,
2920
2885
  );
2886
+ onStatus?.("skipped");
2921
2887
  return null;
2922
2888
  }
2923
2889
 
@@ -2940,6 +2906,7 @@ export class RecallInternalCoordinator {
2940
2906
  `at +${Date.now() - phase1Start}ms`,
2941
2907
  );
2942
2908
  promise.cancel();
2909
+ onStatus?.("timeout");
2943
2910
  return null;
2944
2911
  }
2945
2912
 
@@ -2962,6 +2929,7 @@ export class RecallInternalCoordinator {
2962
2929
  `at +${Date.now() - phase1Start}ms`,
2963
2930
  );
2964
2931
  promise.cancel();
2932
+ onStatus?.("timeout");
2965
2933
  return null;
2966
2934
  }
2967
2935
 
@@ -4768,9 +4736,11 @@ export class RecallInternalCoordinator {
4768
4736
  }
4769
4737
  const phase2AfterQmdMs = Date.now() - recallStart;
4770
4738
 
4771
- const harmonicRetrievalSection = await awaitEnrichmentSection(
4772
- "harmonic",
4773
- harmonicRetrievalPromise,
4739
+ const harmonicRetrievalSection = await phase2Timer.enrichment(
4740
+ "Harmonic",
4741
+ harmonicStartedMs,
4742
+ () => timings.harmonicRetrieval?.startsWith("skip") === true,
4743
+ (onStatus) => awaitEnrichmentSection("harmonic", harmonicRetrievalPromise, onStatus),
4774
4744
  );
4775
4745
  if (harmonicRetrievalSection) {
4776
4746
  this.deps.appendRecallSection(
@@ -4794,35 +4764,39 @@ export class RecallInternalCoordinator {
4794
4764
  if (!graphDecisionReason) {
4795
4765
  graphDecisionReason = graphSnapshotReason;
4796
4766
  }
4797
- await this.deps.recordLastGraphRecallSnapshot({
4767
+ const persistedGraphSnapshotStatus = graphSnapshotStatus;
4768
+ await phase2Timer.step("GraphSnapshot", () => this.deps.recordLastGraphRecallSnapshot({
4798
4769
  storage: profileStorage,
4799
4770
  prompt: retrievalQuery,
4800
4771
  recallMode,
4801
4772
  recallNamespaces,
4802
4773
  seedPaths: graphSnapshotSeedPaths,
4803
4774
  expandedPaths: graphSnapshotExpandedPaths,
4804
- status: graphSnapshotStatus,
4775
+ status: persistedGraphSnapshotStatus,
4805
4776
  reason: graphSnapshotReason,
4806
4777
  shadowMode: graphDecisionShadowMode,
4807
4778
  queryIntent,
4808
4779
  seedResults: graphSnapshotSeedResults,
4809
4780
  finalResults: graphSnapshotFinalResults,
4810
4781
  shadowComparison: graphSnapshotShadowComparison,
4811
- });
4782
+ }));
4783
+ } else {
4784
+ phase2Timer.skipped("GraphSnapshot");
4812
4785
  }
4813
- await this.deps.recordLastIntentSnapshot({
4786
+ await phase2Timer.step("IntentSnapshot", () => this.deps.recordLastIntentSnapshot({
4814
4787
  storage: profileStorage,
4815
4788
  snapshot: buildIntentDebugSnapshot(),
4816
- });
4789
+ }));
4817
4790
  // 2.5. Compression guideline recall section (v8.11 Task 5)
4818
- if (
4819
- this.deps.isRecallSectionEnabled(
4820
- "compression-guidelines",
4821
- resolveCompressionCapabilities(this.deps.config).compressionGuidelineLearning === true,
4822
- )
4823
- ) {
4824
- const compressionGuidelineSection =
4825
- await this.deps.buildCompressionGuidelineRecallSection();
4791
+ const compressionEnabled = this.deps.isRecallSectionEnabled(
4792
+ "compression-guidelines",
4793
+ resolveCompressionCapabilities(this.deps.config).compressionGuidelineLearning === true,
4794
+ );
4795
+ if (compressionEnabled) {
4796
+ const compressionGuidelineSection = await phase2Timer.step(
4797
+ "Compression",
4798
+ () => this.deps.buildCompressionGuidelineRecallSection(),
4799
+ );
4826
4800
  if (compressionGuidelineSection) {
4827
4801
  this.deps.appendRecallSection(
4828
4802
  sectionBuckets,
@@ -4830,6 +4804,8 @@ export class RecallInternalCoordinator {
4830
4804
  compressionGuidelineSection,
4831
4805
  );
4832
4806
  }
4807
+ } else {
4808
+ phase2Timer.skipped("Compression");
4833
4809
  }
4834
4810
  // 3. Transcript/summaries/conversation/compounding are fetched in parallel above,
4835
4811
  // then assembled here according to recallPipeline order.
@@ -4854,9 +4830,11 @@ export class RecallInternalCoordinator {
4854
4830
  conversationRecallSection,
4855
4831
  );
4856
4832
  }
4857
- const compoundingSection = await awaitEnrichmentSection(
4858
- "compounding",
4859
- compoundingPromise,
4833
+ const compoundingSection = await phase2Timer.enrichment(
4834
+ "Compounding",
4835
+ compoundingStartedMs,
4836
+ () => timings.compounding?.startsWith("skip") === true,
4837
+ (onStatus) => awaitEnrichmentSection("compounding", compoundingPromise, onStatus),
4860
4838
  );
4861
4839
  if (compoundingSection) {
4862
4840
  this.deps.appendRecallSection(
@@ -4866,10 +4844,14 @@ export class RecallInternalCoordinator {
4866
4844
  );
4867
4845
  }
4868
4846
  let curiosityFooter: string | undefined, curiosityQuestionSelected = false, curiosityFooterTruncated = false;
4869
- const topQuestion = this.deps.config.injectQuestions &&
4870
- this.deps.isRecallSectionEnabled("questions", true)
4871
- ? selectCuriosityQuestion(await profileStorage.readQuestions({ unresolvedOnly: true }))
4847
+ const questionsEnabled = this.deps.config.injectQuestions &&
4848
+ this.deps.isRecallSectionEnabled("questions", true);
4849
+ const topQuestion = questionsEnabled
4850
+ ? selectCuriosityQuestion(
4851
+ await phase2Timer.step("Questions", () => profileStorage.readQuestions({ unresolvedOnly: true })),
4852
+ )
4872
4853
  : undefined;
4854
+ if (!questionsEnabled) phase2Timer.skipped("Questions");
4873
4855
  if (topQuestion) {
4874
4856
  curiosityQuestionSelected = true;
4875
4857
  const formattedFooter = formatCuriosityFooter(topQuestion);
@@ -4882,7 +4864,12 @@ export class RecallInternalCoordinator {
4882
4864
  }
4883
4865
  }
4884
4866
  const phase2QuestionsDoneMs = Date.now() - recallStart;
4885
- const finalizedQueryAwarePrefilter = await queryAwarePrefilterPromise;
4867
+ const finalizedQueryAwarePrefilter = await phase2Timer.enrichment(
4868
+ "Prefilter",
4869
+ prefilterStartedMs,
4870
+ () => timings.queryAware?.startsWith("skip") === true,
4871
+ () => queryAwarePrefilterPromise,
4872
+ );
4886
4873
  const phase2QapDoneMs = Date.now() - recallStart;
4887
4874
  throwIfRecallAborted(options.abortSignal);
4888
4875
  if (
@@ -4904,8 +4891,9 @@ export class RecallInternalCoordinator {
4904
4891
  .map(([k, v]) => `${k}=${v}`)
4905
4892
  .join(", ");
4906
4893
  log.info(`recall timings: ${timingParts}`);
4907
- recordRecallTiming(this.deps.config, {
4894
+ emitRecallTiming(this.deps.config, {
4908
4895
  ...timings,
4896
+ ...phase2Timings,
4909
4897
  timestamp: new Date().toISOString(),
4910
4898
  namespace: selfNamespace,
4911
4899
  total: timings.total,
@@ -0,0 +1,74 @@
1
+ /** Buffered durable replay ingest (#3368 split from turn-ingestion.ts — 1200-line ratchet). */
2
+
3
+ import { ReplayAdmissionRefusedError, StorageTargetRequiredError } from "../buffer-admission.js";
4
+ import { resolveNamespaceCapabilities } from "../capabilities.js";
5
+ import type { BufferTurn, CodingContext } from "../types.js";
6
+ import type { ResolvedScopeProfilePlan } from "../namespaces/scope-profiles.js";
7
+ import { queueBufferedCaptureScopeGroups } from "./extraction-task-queueing.js";
8
+ import type { TurnIngestionDeps } from "./turn-ingestion.js";
9
+
10
+ export async function ingestReplayBatchBuffered(
11
+ deps: Pick<TurnIngestionDeps, "config" | "buffer" | "lcmEngine" | "queueBufferedExtraction">,
12
+ bySession: Map<string, BufferTurn[]>,
13
+ options: {
14
+ archiveLcm?: boolean;
15
+ writeNamespaceOverride?: string;
16
+ principalOverride?: string;
17
+ scopeProfileWritePlan?: ResolvedScopeProfilePlan | null;
18
+ codingContext?: CodingContext;
19
+ bufferAdmissionIdempotencyKey?: string;
20
+ },
21
+ ): Promise<void> {
22
+ const resolvedWriteTarget =
23
+ options.writeNamespaceOverride ??
24
+ (resolveNamespaceCapabilities(deps.config).namespaces === true
25
+ ? options.scopeProfileWritePlan?.writeNamespace
26
+ : deps.config.defaultNamespace);
27
+ if (!resolvedWriteTarget) {
28
+ throw new StorageTargetRequiredError(
29
+ "accepted capture requires an explicit storage target (writeNamespaceOverride or scopeProfileWritePlan.writeNamespace)",
30
+ );
31
+ }
32
+ const pin = (turn: BufferTurn): BufferTurn => {
33
+ const pinned: BufferTurn = { ...turn, acceptedCapture: true, writeNamespaceOverride: resolvedWriteTarget };
34
+ if (options.codingContext) pinned.codingContext = options.codingContext;
35
+ if (options.principalOverride) pinned.principalOverride = options.principalOverride;
36
+ if (options.scopeProfileWritePlan) pinned.scopeProfileWritePlan = options.scopeProfileWritePlan;
37
+ return pinned;
38
+ };
39
+ const admissionKey = options.bufferAdmissionIdempotencyKey?.trim();
40
+ const batches = [...bySession].map(([bufferKey, sessionTurns]) => ({ bufferKey, turns: sessionTurns.map(pin) }));
41
+ const outcomes = admissionKey
42
+ ? await deps.buffer.addTurnsBoundedForObserveReplay(batches, admissionKey)
43
+ : await deps.buffer.addTurnsBounded(batches);
44
+ if (outcomes === "duplicate") return;
45
+ if (outcomes === null) {
46
+ const refusedKey = batches.find((batch) => batch.turns.length > 0)?.bufferKey ?? "unknown";
47
+ throw new ReplayAdmissionRefusedError(
48
+ `durable observe capture refused: extraction buffer at entry capacity for batch containing ${refusedKey}`,
49
+ );
50
+ }
51
+
52
+ await deps.buffer.flushPendingSave({ throwOnFailure: true });
53
+
54
+ if (options.archiveLcm !== false && deps.lcmEngine?.enabled) {
55
+ for (const [bufferKey, sessionTurns] of bySession) {
56
+ await deps.lcmEngine.observeMessages(
57
+ bufferKey,
58
+ sessionTurns.map((turn) => ({
59
+ role: turn.role,
60
+ content: turn.content,
61
+ parts: turn.parts,
62
+ rawContent: turn.rawContent,
63
+ sourceFormat: turn.sourceFormat,
64
+ })),
65
+ );
66
+ }
67
+ }
68
+
69
+ for (const { bufferKey, outcome } of outcomes) {
70
+ if (outcome.decision !== "keep_buffering" && outcome.extractionTurns) {
71
+ queueBufferedCaptureScopeGroups(deps.queueBufferedExtraction, outcome.extractionTurns, bufferKey, options);
72
+ }
73
+ }
74
+ }