@remnic/core 10.0.145 → 10.0.147

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 (310) hide show
  1. package/dist/access-admin-ops-surface.js +156 -152
  2. package/dist/access-cli.js +156 -152
  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 +156 -152
  8. package/dist/access-extraction-force-flush.js +156 -152
  9. package/dist/access-http-briefing.js +156 -152
  10. package/dist/access-http-query.js +156 -152
  11. package/dist/access-http.d.ts.map +1 -1
  12. package/dist/access-http.js +156 -152
  13. package/dist/access-identity-continuity-surface.js +156 -152
  14. package/dist/access-lcm-surface.js +156 -152
  15. package/dist/access-mcp.js +156 -152
  16. package/dist/access-observe-write-category.js +11 -11
  17. package/dist/access-observe-write-surface.js +156 -152
  18. package/dist/access-offline-manifest.js +10 -10
  19. package/dist/access-operations-batch.js +156 -152
  20. package/dist/access-operations.js +156 -152
  21. package/dist/access-recall-concurrency.js +156 -152
  22. package/dist/access-recall-response.js +156 -152
  23. package/dist/access-recall-surface.js +156 -152
  24. package/dist/access-schema.js +7 -7
  25. package/dist/access-service.d.ts.map +1 -1
  26. package/dist/access-service.js +156 -152
  27. package/dist/active-memory-bridge.js +2 -2
  28. package/dist/active-recall.js +30 -30
  29. package/dist/adapters/index.js +7 -7
  30. package/dist/adapters/registry.js +3 -3
  31. package/dist/auto-sync-PSZJHHXB.js +2 -2
  32. package/dist/briefing.js +21 -21
  33. package/dist/buffer.js +1 -1
  34. package/dist/calibration.js +3 -3
  35. package/dist/{capsule-crypto-GWVG7LGC.js → capsule-crypto-7FJQINUR.js} +2 -2
  36. package/dist/causal-behavior.js +2 -2
  37. package/dist/causal-chain.js +2 -2
  38. package/dist/causal-consolidation.js +24 -24
  39. package/dist/causal-retrieval.js +2 -2
  40. package/dist/causal-trajectory-graph.js +2 -2
  41. package/dist/causal-trajectory.js +1 -1
  42. package/dist/{chunk-GB442ZFG.js → chunk-2NGTY22Z.js} +5 -5
  43. package/dist/{chunk-OWHERGF2.js → chunk-2NLLXCJG.js} +2 -2
  44. package/dist/{chunk-XVZA6VXC.js → chunk-3SL52JKD.js} +4 -4
  45. package/dist/chunk-4IJBNRMZ.js +45 -0
  46. package/dist/chunk-4IJBNRMZ.js.map +1 -0
  47. package/dist/{chunk-GTW6GPQU.js → chunk-4JKIOAOF.js} +6 -6
  48. package/dist/{chunk-WN2DASTS.js → chunk-5BE3FLKL.js} +4 -4
  49. package/dist/{chunk-QFBBSKEU.js → chunk-5BKH4XG5.js} +2 -2
  50. package/dist/chunk-5JD4DXQX.js +91 -0
  51. package/dist/chunk-5JD4DXQX.js.map +1 -0
  52. package/dist/{chunk-FZ6QUOTL.js → chunk-5UYP5IQB.js} +2 -2
  53. package/dist/{chunk-DCLOMXQL.js → chunk-5ZSN2OFB.js} +31 -31
  54. package/dist/{chunk-FBV4QGXT.js → chunk-6S37C5UK.js} +2 -2
  55. package/dist/{chunk-M4IEZGCK.js → chunk-73TPOGS4.js} +6 -6
  56. package/dist/{chunk-MEYPQLXV.js → chunk-7OWV3GVD.js} +2 -2
  57. package/dist/{chunk-XIWRF7TG.js → chunk-7P72BY4F.js} +2 -2
  58. package/dist/{chunk-UWP6PGWN.js → chunk-7QKZOZF4.js} +2 -2
  59. package/dist/{chunk-DBNZYQCL.js → chunk-AHNGWFNG.js} +2 -2
  60. package/dist/{chunk-YIOP7IFD.js → chunk-AO5LKFGO.js} +4 -4
  61. package/dist/{chunk-D3ZISMKY.js → chunk-AWZ5CWSR.js} +10 -10
  62. package/dist/{chunk-63MKTHYT.js → chunk-B5MB2G3H.js} +2 -2
  63. package/dist/{chunk-TYOS62PM.js → chunk-BGSYM3SH.js} +2 -2
  64. package/dist/{chunk-64TIBZPZ.js → chunk-BHZ72ZQ3.js} +2 -2
  65. package/dist/{chunk-G4NKURT4.js → chunk-C6S353AG.js} +30 -1
  66. package/dist/chunk-C6S353AG.js.map +1 -0
  67. package/dist/{chunk-T3M5KJRV.js → chunk-C6Z3H23R.js} +2 -2
  68. package/dist/{chunk-SEIFDQ6U.js → chunk-CA56BOUE.js} +4 -4
  69. package/dist/{chunk-UIFWZMO7.js → chunk-CLVILSBR.js} +7 -7
  70. package/dist/{chunk-GDREJ32D.js → chunk-DOFLNJZD.js} +3 -3
  71. package/dist/{chunk-Z2OKWO35.js → chunk-E6VI7POW.js} +327 -318
  72. package/dist/chunk-E6VI7POW.js.map +1 -0
  73. package/dist/{chunk-SV6OLWPF.js → chunk-EIEANUBO.js} +15 -15
  74. package/dist/{chunk-PJKTFXE2.js → chunk-EMMUQUHF.js} +16 -6
  75. package/dist/chunk-EMMUQUHF.js.map +1 -0
  76. package/dist/{chunk-X2FEUBKD.js → chunk-EYES6ALH.js} +2 -2
  77. package/dist/{chunk-ENPJX3BB.js → chunk-FMFCQRDM.js} +3 -3
  78. package/dist/{chunk-IJVU4ILJ.js → chunk-GCHM5BYL.js} +7 -7
  79. package/dist/{chunk-KCU2ZWBS.js → chunk-GCQIXPWZ.js} +2 -2
  80. package/dist/{chunk-GKL6QYZO.js → chunk-GMO3BGOF.js} +1 -1
  81. package/dist/{chunk-OMPX3KLG.js → chunk-H6OTEBPK.js} +2 -2
  82. package/dist/{chunk-DK3T3Q6A.js → chunk-HADCITEA.js} +8 -8
  83. package/dist/{chunk-QCJ7Q5BM.js → chunk-HIUIJ4AB.js} +2 -2
  84. package/dist/{chunk-F4ZHKDBW.js → chunk-HLWXCDUQ.js} +2 -2
  85. package/dist/{chunk-4RASUAN3.js → chunk-HXFIILGF.js} +4 -4
  86. package/dist/{chunk-CIEEYVUB.js → chunk-IMULTENA.js} +2 -2
  87. package/dist/{chunk-EUL3S3LE.js → chunk-J5WI4QRP.js} +4 -4
  88. package/dist/{chunk-TFHL4WWY.js → chunk-JPVUBL4L.js} +5 -5
  89. package/dist/{chunk-KBMJWNSY.js → chunk-K6RKNQRD.js} +2 -2
  90. package/dist/{chunk-BUKK5SWA.js → chunk-KQAFEZQX.js} +2 -2
  91. package/dist/{chunk-PDVEY4QS.js → chunk-LD7I5AZW.js} +9 -9
  92. package/dist/{chunk-G3ZUQZGM.js → chunk-MBQVWTCS.js} +2 -2
  93. package/dist/{chunk-BKR2YCQ5.js → chunk-MKJBZR7J.js} +2 -2
  94. package/dist/{chunk-ETUMOYGL.js → chunk-NQJAF2Q4.js} +2 -2
  95. package/dist/{chunk-7TDJZV2S.js → chunk-O7CHKXSF.js} +4 -4
  96. package/dist/{chunk-ODHFX5JX.js → chunk-OFFT2B5R.js} +15 -15
  97. package/dist/{chunk-W7K5BP3M.js → chunk-OM5ESBES.js} +2 -2
  98. package/dist/{chunk-5JW2QIFH.js → chunk-ORPYIVT3.js} +3 -3
  99. package/dist/chunk-PXY2B7BG.js +51 -0
  100. package/dist/chunk-PXY2B7BG.js.map +1 -0
  101. package/dist/{chunk-MVTMKFBW.js → chunk-QDY4TSKK.js} +2 -2
  102. package/dist/{chunk-7TY5ZHFA.js → chunk-QGV6JVQ7.js} +2 -2
  103. package/dist/{chunk-4XINO77L.js → chunk-RB7NXZ2E.js} +2 -2
  104. package/dist/{chunk-GQDO6KHO.js → chunk-RQ6HMDA5.js} +2 -2
  105. package/dist/{chunk-E7WMDXAW.js → chunk-RSPPAPFI.js} +2 -2
  106. package/dist/{chunk-LS5VJO5O.js → chunk-SLZJ7HQX.js} +2 -2
  107. package/dist/{chunk-WQUGCOKF.js → chunk-TFA6HPOA.js} +4 -4
  108. package/dist/{chunk-6P7U3HWG.js → chunk-TH6OYP6I.js} +3 -3
  109. package/dist/{chunk-P4YYUDR5.js → chunk-TNACU47L.js} +3 -3
  110. package/dist/{chunk-KYZFW4LW.js → chunk-TQU2RB4B.js} +2 -2
  111. package/dist/{chunk-2UOU6CZZ.js → chunk-TVRUUT7U.js} +2 -2
  112. package/dist/{chunk-IHCXMYSE.js → chunk-U2PSE7MB.js} +2 -2
  113. package/dist/{chunk-D3ZKHLN2.js → chunk-ULLGI6XR.js} +2 -2
  114. package/dist/{chunk-U62EINFH.js → chunk-UMC6F3Y4.js} +3 -3
  115. package/dist/{chunk-FF6N7BXC.js → chunk-UWVMD54T.js} +2 -2
  116. package/dist/{chunk-PCMGMPQZ.js → chunk-X4EF7IG3.js} +4 -4
  117. package/dist/{chunk-UVYI6VIX.js → chunk-X7Y7WX73.js} +1 -1
  118. package/dist/{chunk-GA3Y7GZR.js → chunk-XCJDDXJX.js} +2 -2
  119. package/dist/{chunk-YGPRFYV6.js → chunk-YCASWFI6.js} +3 -3
  120. package/dist/chunk-YRHBSYQR.js +15 -0
  121. package/dist/chunk-YRHBSYQR.js.map +1 -0
  122. package/dist/{chunk-IBPE3Q5M.js → chunk-Z3GZRG5Z.js} +2 -2
  123. package/dist/{chunk-K3FH3LAQ.js → chunk-ZG4GNPRE.js} +10 -10
  124. package/dist/{chunk-ADBON4FI.js → chunk-ZIXP27JK.js} +10 -10
  125. package/dist/cli.js +156 -152
  126. package/dist/coding/export-okf-codegraph.js +20 -20
  127. package/dist/coding/pre-action-gate.js +2 -2
  128. package/dist/compounding/engine.js +22 -22
  129. package/dist/config.js +30 -30
  130. package/dist/connectors/codex-materialize-runner.js +21 -21
  131. package/dist/connectors/index.js +21 -21
  132. package/dist/contradiction/index.js +7 -7
  133. package/dist/convergence-refresh.js +23 -23
  134. package/dist/conversation-index/backend.js +2 -2
  135. package/dist/corpus-watermark.js +23 -23
  136. package/dist/deep-recall-http-glue.js +8 -8
  137. package/dist/deep-recall.js +2 -2
  138. package/dist/entity-retrieval.js +22 -22
  139. package/dist/explicit-capture.js +156 -152
  140. package/dist/extraction-evidence-class.js +2 -2
  141. package/dist/extraction-source-grounding.js +3 -3
  142. package/dist/extraction-span-materialize.js +2 -2
  143. package/dist/extraction.js +29 -29
  144. package/dist/{graph-edge-decay-OEX5OGMI.js → graph-edge-decay-BC3IO2J4.js} +5 -5
  145. package/dist/graph-jsonl.js +3 -3
  146. package/dist/graph-snapshot.js +3 -3
  147. package/dist/graph.js +4 -4
  148. package/dist/harmonic-retrieval.js +21 -21
  149. package/dist/index.js +265 -261
  150. package/dist/lcm/engine.js +4 -4
  151. package/dist/lcm/index.js +10 -10
  152. package/dist/local-llm.js +2 -2
  153. package/dist/location/index.js +22 -22
  154. package/dist/maintenance/memory-governance.js +21 -21
  155. package/dist/maintenance/rebuild-memory-lifecycle-ledger.js +21 -21
  156. package/dist/maintenance/rebuild-memory-projection-runner.js +23 -23
  157. package/dist/maintenance/rebuild-memory-projection.js +22 -22
  158. package/dist/memory-browse.js +1 -1
  159. package/dist/memory-subject.js +1 -1
  160. package/dist/namespaces/migrate.js +22 -22
  161. package/dist/namespaces/search.js +7 -7
  162. package/dist/namespaces/storage.js +21 -21
  163. package/dist/offline-sync-changeset-generations.js +3 -3
  164. package/dist/offline-sync-embedding-generation.js +2 -2
  165. package/dist/offline-sync-snapshot-stream.js +5 -5
  166. package/dist/offline-sync.js +7 -7
  167. package/dist/operator-doctor-corpus.js +24 -24
  168. package/dist/operator-toolkit.js +39 -39
  169. package/dist/orchestration/backlog-scheduler.js +157 -153
  170. package/dist/orchestration/backlog-scheduler.js.map +1 -1
  171. package/dist/orchestration/buffer-drain-runner.js +157 -153
  172. package/dist/orchestration/maintenance.js +32 -32
  173. package/dist/orchestration/recall-internal.d.ts.map +1 -1
  174. package/dist/orchestrator.js +156 -152
  175. package/dist/provenance.js +2 -2
  176. package/dist/recall-attempt-timing.d.ts +18 -0
  177. package/dist/recall-attempt-timing.d.ts.map +1 -0
  178. package/dist/recall-attempt-timing.js +14 -0
  179. package/dist/recall-attempt-timing.js.map +1 -0
  180. package/dist/recall-enrichment-promise.d.ts +22 -0
  181. package/dist/recall-enrichment-promise.d.ts.map +1 -0
  182. package/dist/recall-enrichment-promise.js +10 -0
  183. package/dist/recall-enrichment-promise.js.map +1 -0
  184. package/dist/recall-explain-renderer.js +3 -3
  185. package/dist/recall-navigation.js +156 -152
  186. package/dist/recall-phase2-timing.d.ts +44 -0
  187. package/dist/recall-phase2-timing.d.ts.map +1 -0
  188. package/dist/recall-phase2-timing.js +22 -0
  189. package/dist/recall-phase2-timing.js.map +1 -0
  190. package/dist/recall-timings.d.ts +35 -0
  191. package/dist/recall-timings.d.ts.map +1 -1
  192. package/dist/recall-timings.js +2 -1
  193. package/dist/recall-why-service.js +2 -2
  194. package/dist/recall-xray-cli.js +4 -4
  195. package/dist/recall-xray-renderer.js +3 -3
  196. package/dist/recall-xray.js +2 -2
  197. package/dist/reconcile/manifest.js +3 -3
  198. package/dist/{resolution-A3NAI3YE.js → resolution-TCO63RRC.js} +8 -8
  199. package/dist/resolution-TCO63RRC.js.map +1 -0
  200. package/dist/resume-bundles.js +31 -31
  201. package/dist/salvage-envelope.js +1 -1
  202. package/dist/search/factory.js +6 -6
  203. package/dist/search/index.js +12 -12
  204. package/dist/semantic-consolidation.js +22 -22
  205. package/dist/semantic-rule-promotion.js +21 -21
  206. package/dist/semantic-rule-verifier.js +21 -21
  207. package/dist/source-agent-qualifier.js +23 -23
  208. package/dist/standup/build.js +21 -21
  209. package/dist/storage.js +20 -20
  210. package/dist/subject-config.js +1 -1
  211. package/dist/summarizer.js +4 -4
  212. package/dist/support-passport/index.js +7 -7
  213. package/dist/transfer/backup.js +2 -2
  214. package/dist/transfer/capsule-export.js +2 -2
  215. package/dist/transfer/capsule-import.js +2 -2
  216. package/dist/transfer/export-okf.js +21 -21
  217. package/dist/verified-recall.js +21 -21
  218. package/dist/whitespace.d.ts.map +1 -1
  219. package/dist/whitespace.js +1 -1
  220. package/dist/who-knows-cli.js +22 -22
  221. package/dist/who-knows.js +21 -21
  222. package/dist/write-envelope.js +1 -1
  223. package/package.json +2 -2
  224. package/src/access-correlation.ts +17 -0
  225. package/src/access-http.ts +7 -8
  226. package/src/access-service.ts +3 -1
  227. package/src/orchestration/recall-internal.ts +63 -75
  228. package/src/recall-attempt-timing.ts +78 -0
  229. package/src/recall-enrichment-promise.ts +62 -0
  230. package/src/recall-phase2-timing.ts +146 -0
  231. package/src/recall-timings-access.test.ts +140 -2
  232. package/src/recall-timings-request-contract.test.ts +488 -0
  233. package/src/recall-timings.ts +70 -0
  234. package/src/whitespace.test.ts +48 -0
  235. package/src/whitespace.ts +19 -5
  236. package/dist/chunk-G4NKURT4.js.map +0 -1
  237. package/dist/chunk-PJKTFXE2.js.map +0 -1
  238. package/dist/chunk-Z2OKWO35.js.map +0 -1
  239. /package/dist/{capsule-crypto-GWVG7LGC.js.map → access-correlation.js.map} +0 -0
  240. /package/dist/{graph-edge-decay-OEX5OGMI.js.map → capsule-crypto-7FJQINUR.js.map} +0 -0
  241. /package/dist/{chunk-GB442ZFG.js.map → chunk-2NGTY22Z.js.map} +0 -0
  242. /package/dist/{chunk-OWHERGF2.js.map → chunk-2NLLXCJG.js.map} +0 -0
  243. /package/dist/{chunk-XVZA6VXC.js.map → chunk-3SL52JKD.js.map} +0 -0
  244. /package/dist/{chunk-GTW6GPQU.js.map → chunk-4JKIOAOF.js.map} +0 -0
  245. /package/dist/{chunk-WN2DASTS.js.map → chunk-5BE3FLKL.js.map} +0 -0
  246. /package/dist/{chunk-QFBBSKEU.js.map → chunk-5BKH4XG5.js.map} +0 -0
  247. /package/dist/{chunk-FZ6QUOTL.js.map → chunk-5UYP5IQB.js.map} +0 -0
  248. /package/dist/{chunk-DCLOMXQL.js.map → chunk-5ZSN2OFB.js.map} +0 -0
  249. /package/dist/{chunk-FBV4QGXT.js.map → chunk-6S37C5UK.js.map} +0 -0
  250. /package/dist/{chunk-M4IEZGCK.js.map → chunk-73TPOGS4.js.map} +0 -0
  251. /package/dist/{chunk-MEYPQLXV.js.map → chunk-7OWV3GVD.js.map} +0 -0
  252. /package/dist/{chunk-XIWRF7TG.js.map → chunk-7P72BY4F.js.map} +0 -0
  253. /package/dist/{chunk-UWP6PGWN.js.map → chunk-7QKZOZF4.js.map} +0 -0
  254. /package/dist/{chunk-DBNZYQCL.js.map → chunk-AHNGWFNG.js.map} +0 -0
  255. /package/dist/{chunk-YIOP7IFD.js.map → chunk-AO5LKFGO.js.map} +0 -0
  256. /package/dist/{chunk-D3ZISMKY.js.map → chunk-AWZ5CWSR.js.map} +0 -0
  257. /package/dist/{chunk-63MKTHYT.js.map → chunk-B5MB2G3H.js.map} +0 -0
  258. /package/dist/{chunk-TYOS62PM.js.map → chunk-BGSYM3SH.js.map} +0 -0
  259. /package/dist/{chunk-64TIBZPZ.js.map → chunk-BHZ72ZQ3.js.map} +0 -0
  260. /package/dist/{chunk-T3M5KJRV.js.map → chunk-C6Z3H23R.js.map} +0 -0
  261. /package/dist/{chunk-SEIFDQ6U.js.map → chunk-CA56BOUE.js.map} +0 -0
  262. /package/dist/{chunk-UIFWZMO7.js.map → chunk-CLVILSBR.js.map} +0 -0
  263. /package/dist/{chunk-GDREJ32D.js.map → chunk-DOFLNJZD.js.map} +0 -0
  264. /package/dist/{chunk-SV6OLWPF.js.map → chunk-EIEANUBO.js.map} +0 -0
  265. /package/dist/{chunk-X2FEUBKD.js.map → chunk-EYES6ALH.js.map} +0 -0
  266. /package/dist/{chunk-ENPJX3BB.js.map → chunk-FMFCQRDM.js.map} +0 -0
  267. /package/dist/{chunk-IJVU4ILJ.js.map → chunk-GCHM5BYL.js.map} +0 -0
  268. /package/dist/{chunk-KCU2ZWBS.js.map → chunk-GCQIXPWZ.js.map} +0 -0
  269. /package/dist/{chunk-GKL6QYZO.js.map → chunk-GMO3BGOF.js.map} +0 -0
  270. /package/dist/{chunk-OMPX3KLG.js.map → chunk-H6OTEBPK.js.map} +0 -0
  271. /package/dist/{chunk-DK3T3Q6A.js.map → chunk-HADCITEA.js.map} +0 -0
  272. /package/dist/{chunk-QCJ7Q5BM.js.map → chunk-HIUIJ4AB.js.map} +0 -0
  273. /package/dist/{chunk-F4ZHKDBW.js.map → chunk-HLWXCDUQ.js.map} +0 -0
  274. /package/dist/{chunk-4RASUAN3.js.map → chunk-HXFIILGF.js.map} +0 -0
  275. /package/dist/{chunk-CIEEYVUB.js.map → chunk-IMULTENA.js.map} +0 -0
  276. /package/dist/{chunk-EUL3S3LE.js.map → chunk-J5WI4QRP.js.map} +0 -0
  277. /package/dist/{chunk-TFHL4WWY.js.map → chunk-JPVUBL4L.js.map} +0 -0
  278. /package/dist/{chunk-KBMJWNSY.js.map → chunk-K6RKNQRD.js.map} +0 -0
  279. /package/dist/{chunk-BUKK5SWA.js.map → chunk-KQAFEZQX.js.map} +0 -0
  280. /package/dist/{chunk-PDVEY4QS.js.map → chunk-LD7I5AZW.js.map} +0 -0
  281. /package/dist/{chunk-G3ZUQZGM.js.map → chunk-MBQVWTCS.js.map} +0 -0
  282. /package/dist/{chunk-BKR2YCQ5.js.map → chunk-MKJBZR7J.js.map} +0 -0
  283. /package/dist/{chunk-ETUMOYGL.js.map → chunk-NQJAF2Q4.js.map} +0 -0
  284. /package/dist/{chunk-7TDJZV2S.js.map → chunk-O7CHKXSF.js.map} +0 -0
  285. /package/dist/{chunk-ODHFX5JX.js.map → chunk-OFFT2B5R.js.map} +0 -0
  286. /package/dist/{chunk-W7K5BP3M.js.map → chunk-OM5ESBES.js.map} +0 -0
  287. /package/dist/{chunk-5JW2QIFH.js.map → chunk-ORPYIVT3.js.map} +0 -0
  288. /package/dist/{chunk-MVTMKFBW.js.map → chunk-QDY4TSKK.js.map} +0 -0
  289. /package/dist/{chunk-7TY5ZHFA.js.map → chunk-QGV6JVQ7.js.map} +0 -0
  290. /package/dist/{chunk-4XINO77L.js.map → chunk-RB7NXZ2E.js.map} +0 -0
  291. /package/dist/{chunk-GQDO6KHO.js.map → chunk-RQ6HMDA5.js.map} +0 -0
  292. /package/dist/{chunk-E7WMDXAW.js.map → chunk-RSPPAPFI.js.map} +0 -0
  293. /package/dist/{chunk-LS5VJO5O.js.map → chunk-SLZJ7HQX.js.map} +0 -0
  294. /package/dist/{chunk-WQUGCOKF.js.map → chunk-TFA6HPOA.js.map} +0 -0
  295. /package/dist/{chunk-6P7U3HWG.js.map → chunk-TH6OYP6I.js.map} +0 -0
  296. /package/dist/{chunk-P4YYUDR5.js.map → chunk-TNACU47L.js.map} +0 -0
  297. /package/dist/{chunk-KYZFW4LW.js.map → chunk-TQU2RB4B.js.map} +0 -0
  298. /package/dist/{chunk-2UOU6CZZ.js.map → chunk-TVRUUT7U.js.map} +0 -0
  299. /package/dist/{chunk-IHCXMYSE.js.map → chunk-U2PSE7MB.js.map} +0 -0
  300. /package/dist/{chunk-D3ZKHLN2.js.map → chunk-ULLGI6XR.js.map} +0 -0
  301. /package/dist/{chunk-U62EINFH.js.map → chunk-UMC6F3Y4.js.map} +0 -0
  302. /package/dist/{chunk-FF6N7BXC.js.map → chunk-UWVMD54T.js.map} +0 -0
  303. /package/dist/{chunk-PCMGMPQZ.js.map → chunk-X4EF7IG3.js.map} +0 -0
  304. /package/dist/{chunk-UVYI6VIX.js.map → chunk-X7Y7WX73.js.map} +0 -0
  305. /package/dist/{chunk-GA3Y7GZR.js.map → chunk-XCJDDXJX.js.map} +0 -0
  306. /package/dist/{chunk-YGPRFYV6.js.map → chunk-YCASWFI6.js.map} +0 -0
  307. /package/dist/{chunk-IBPE3Q5M.js.map → chunk-Z3GZRG5Z.js.map} +0 -0
  308. /package/dist/{chunk-K3FH3LAQ.js.map → chunk-ZG4GNPRE.js.map} +0 -0
  309. /package/dist/{chunk-ADBON4FI.js.map → chunk-ZIXP27JK.js.map} +0 -0
  310. /package/dist/{resolution-A3NAI3YE.js.map → graph-edge-decay-BC3IO2J4.js.map} +0 -0
@@ -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,78 @@
1
+ import { AsyncLocalStorage } from "node:async_hooks";
2
+ import { randomUUID } from "node:crypto";
3
+
4
+ import { isAbortError } from "./abort-error.js";
5
+ import { currentCorrelationId } from "./access-correlation.js";
6
+ import {
7
+ recordRecallTiming,
8
+ type RecallTimingEmission,
9
+ type RecallTimingOutcome,
10
+ } from "./recall-timings.js";
11
+ import type { PluginConfig } from "./types.js";
12
+
13
+ // Receives the recall pipeline's per-phase timing payload for the attempt in
14
+ // flight, so the attempt's single record (requestId + outcome + httpTotalMs +
15
+ // phases) is pushed once, from recordRecallAttempt's `finally`. Scoped per
16
+ // attempt via AsyncLocalStorage: no recall option or signature carries it.
17
+ const attemptSinkStore = new AsyncLocalStorage<(payload: RecallTimingEmission) => void>();
18
+
19
+ /**
20
+ * Pipeline side. Inside a recorded attempt the payload folds into that
21
+ * attempt's record; outside one (x-ray, daemon hooks, direct orchestrator
22
+ * callers) it keeps the legacy success-only push.
23
+ */
24
+ export function emitRecallTiming(config: PluginConfig, payload: RecallTimingEmission): void {
25
+ const sink = attemptSinkStore.getStore();
26
+ if (sink) {
27
+ sink(payload);
28
+ return;
29
+ }
30
+ recordRecallTiming(config, payload);
31
+ }
32
+
33
+ /**
34
+ * Run one executed recall and leave exactly one timing record for it, pushed
35
+ * in `finally` so denials, disconnects and assembly failures carry the same
36
+ * trail as successes. `requestId` is the HTTP request's server-generated
37
+ * correlation id (x-request-id); outside HTTP dispatch it falls back to a
38
+ * generated `local:<uuid>` id in the same field, so a record says whether it
39
+ * has an HTTP request behind it. Never derived from client input.
40
+ */
41
+ export async function recordRecallAttempt<T>(
42
+ config: PluginConfig,
43
+ abortSignal: AbortSignal | undefined,
44
+ run: () => Promise<T>,
45
+ ): Promise<T> {
46
+ const requestId = currentCorrelationId() ?? `local:${randomUUID()}`;
47
+ const startedMs = performance.now();
48
+ const emitted: RecallTimingEmission[] = [];
49
+ let failure: { abortError: boolean } | undefined;
50
+ try {
51
+ return await attemptSinkStore.run((payload) => {
52
+ emitted.push(payload);
53
+ }, run);
54
+ } catch (err) {
55
+ failure = { abortError: isAbortError(err) };
56
+ throw err;
57
+ } finally {
58
+ const phases = emitted.at(-1);
59
+ // aborted: the request/flight signal fired, or an abort error was thrown
60
+ // (the pipeline's soft abort returns normally with the signal already
61
+ // aborted). error: any other throw, or a normal return from a pipeline
62
+ // that never reached its timing emit (the entry coordinator swallows
63
+ // outer timeouts, init-gate aborts and internal failures into a degraded
64
+ // context). ok: the pipeline ran to completion.
65
+ const outcome: RecallTimingOutcome =
66
+ abortSignal?.aborted === true || failure?.abortError === true
67
+ ? "aborted"
68
+ : failure !== undefined || phases === undefined
69
+ ? "error"
70
+ : "ok";
71
+ recordRecallTiming(config, {
72
+ ...phases,
73
+ requestId,
74
+ outcome,
75
+ httpTotalMs: performance.now() - startedMs,
76
+ });
77
+ }
78
+ }
@@ -0,0 +1,62 @@
1
+ export type DeferredEnrichmentOutcome<T> =
2
+ | { status: "resolved"; value: T }
3
+ | { status: "rejected"; error: unknown };
4
+
5
+ export type ObservedDeferredEnrichmentPromise<T> =
6
+ Promise<DeferredEnrichmentOutcome<T>> & {
7
+ getSettledOutcome: () => DeferredEnrichmentOutcome<T> | undefined;
8
+ cancel: () => void;
9
+ };
10
+
11
+ /** Cancelable child abort signal owned by one enrichment promise. */
12
+ export interface EnrichmentAbortHandle {
13
+ signal: AbortSignal;
14
+ cancel: () => void;
15
+ dispose: () => void;
16
+ }
17
+
18
+ /** Child abort controller that follows `parentSignal`; `dispose` detaches the listener. */
19
+ export function createEnrichmentAbortHandle(parentSignal?: AbortSignal): EnrichmentAbortHandle {
20
+ const controller = new AbortController();
21
+ const onAbort = () => controller.abort();
22
+ if (parentSignal?.aborted) {
23
+ controller.abort();
24
+ } else if (parentSignal) {
25
+ parentSignal.addEventListener("abort", onAbort, { once: true });
26
+ }
27
+ let disposed = false;
28
+ const dispose = () => {
29
+ if (disposed) return;
30
+ disposed = true;
31
+ parentSignal?.removeEventListener("abort", onAbort);
32
+ };
33
+ return {
34
+ signal: controller.signal,
35
+ cancel: () => {
36
+ controller.abort();
37
+ dispose();
38
+ },
39
+ dispose,
40
+ };
41
+ }
42
+
43
+ /** Never-rejecting view of `promise` that also exposes its settled outcome and a cancel hook. */
44
+ export function observeEnrichmentPromise<T>(
45
+ promise: Promise<T>,
46
+ cancel: () => void = () => {},
47
+ ): ObservedDeferredEnrichmentPromise<T> {
48
+ let settledOutcome: DeferredEnrichmentOutcome<T> | undefined;
49
+ const settled = promise
50
+ .then<DeferredEnrichmentOutcome<T>, DeferredEnrichmentOutcome<T>>(
51
+ (value) => ({ status: "resolved", value }),
52
+ (error) => ({ status: "rejected", error }),
53
+ )
54
+ .then((outcome) => {
55
+ settledOutcome = outcome;
56
+ return outcome;
57
+ });
58
+ return Object.assign(settled, {
59
+ getSettledOutcome: () => settledOutcome,
60
+ cancel,
61
+ });
62
+ }
@@ -0,0 +1,146 @@
1
+ /**
2
+ * Phase-2 await timing fields for the recall-timings attempt record (issue
3
+ * #1830). Each instrumented phase-2 await contributes three optionally-named
4
+ * fields: `phase2<Name>Ms` (monotonic elapsed of the await itself),
5
+ * `phase2<Name>Status` (ok | timeout | error | skipped), and — for promises
6
+ * started earlier in phase 1 and awaited later — `phase2<Name>TotalMs`
7
+ * (monotonic time since the promise was created). The await fields are
8
+ * OVERLAPPING, not additive: awaits of promises started earlier include time
9
+ * spent doing other phase-2 work.
10
+ */
11
+
12
+ export type Phase2AwaitStatus = "ok" | "timeout" | "error" | "skipped";
13
+
14
+ export const PHASE2_AWAIT_NAMES = [
15
+ "Harmonic",
16
+ "GraphSnapshot",
17
+ "IntentSnapshot",
18
+ "Compression",
19
+ "Compounding",
20
+ "Questions",
21
+ "Prefilter",
22
+ ] as const;
23
+
24
+ export type Phase2AwaitName = (typeof PHASE2_AWAIT_NAMES)[number];
25
+
26
+ /** Awaits of promises started earlier in phase 1; their await time overlaps earlier work. */
27
+ export const PHASE2_AWAIT_TOTAL_NAMES: readonly Phase2AwaitName[] = [
28
+ "Harmonic",
29
+ "Compounding",
30
+ "Prefilter",
31
+ ];
32
+
33
+ export const PHASE2_AWAIT_STATUSES: readonly Phase2AwaitStatus[] = [
34
+ "ok",
35
+ "timeout",
36
+ "error",
37
+ "skipped",
38
+ ];
39
+
40
+ export function phase2MsField(name: Phase2AwaitName): string {
41
+ return `phase2${name}Ms`;
42
+ }
43
+
44
+ export function phase2StatusField(name: Phase2AwaitName): string {
45
+ return `phase2${name}Status`;
46
+ }
47
+
48
+ export function phase2TotalField(name: Phase2AwaitName): string {
49
+ return `phase2${name}TotalMs`;
50
+ }
51
+
52
+ export interface Phase2AwaitTiming {
53
+ status: Phase2AwaitStatus;
54
+ /** Monotonic elapsed ms of the await itself (measured at the await site). */
55
+ ms: number;
56
+ /** Monotonic ms since the awaited promise was created (started-earlier awaits only). */
57
+ totalMs?: number;
58
+ }
59
+
60
+ /** Fold one await's timing into the recall pipeline's flat timing payload. Values stay string-encoded ("12ms") so the recall-timings sanitizer parses them like every other phase. */
61
+ export function recordPhase2Await(
62
+ sink: Record<string, string>,
63
+ name: Phase2AwaitName,
64
+ timing: Phase2AwaitTiming,
65
+ ): void {
66
+ sink[phase2MsField(name)] = `${Math.max(0, Math.round(timing.ms))}ms`;
67
+ sink[phase2StatusField(name)] = timing.status;
68
+ if (timing.totalMs !== undefined) {
69
+ sink[phase2TotalField(name)] = `${Math.max(0, Math.round(timing.totalMs))}ms`;
70
+ }
71
+ }
72
+
73
+ export interface Phase2Timer {
74
+ /** Time one direct phase-2 await. A throw is re-thrown unchanged after its status is recorded. */
75
+ step<T>(name: Phase2AwaitName, run: () => Promise<T>): Promise<T>;
76
+ /** Record a phase-2 await that did not run (section disabled): 0 ms, status skipped. */
77
+ skipped(name: Phase2AwaitName): void;
78
+ /**
79
+ * Time one await of an enrichment promise started earlier (`startedMs` is its
80
+ * performance.now() creation time). `run` reports the await's own outcome
81
+ * through `onStatus`; `isSkipped` is read after the await so a section that
82
+ * skipped itself (disabled / limit 0) is recorded as skipped, not ok.
83
+ */
84
+ enrichment<T>(
85
+ name: Phase2AwaitName,
86
+ startedMs: number,
87
+ isSkipped: () => boolean,
88
+ run: (onStatus: (status: Phase2AwaitStatus) => void) => Promise<T>,
89
+ ): Promise<T>;
90
+ }
91
+
92
+ /** Per-recall phase-2 await timer; all durations are performance.now() deltas, never wall clock. */
93
+ export function createPhase2Timer(
94
+ sink: Record<string, string>,
95
+ isAborted: () => boolean,
96
+ ): Phase2Timer {
97
+ return {
98
+ async step<T>(name: Phase2AwaitName, run: () => Promise<T>): Promise<T> {
99
+ const awaitStartMs = performance.now();
100
+ try {
101
+ const value = await run();
102
+ recordPhase2Await(sink, name, { status: "ok", ms: performance.now() - awaitStartMs });
103
+ return value;
104
+ } catch (err) {
105
+ recordPhase2Await(sink, name, {
106
+ status: isAborted() ? "skipped" : "error",
107
+ ms: performance.now() - awaitStartMs,
108
+ });
109
+ throw err;
110
+ }
111
+ },
112
+ skipped(name: Phase2AwaitName): void {
113
+ recordPhase2Await(sink, name, { status: "skipped", ms: 0 });
114
+ },
115
+ async enrichment<T>(
116
+ name: Phase2AwaitName,
117
+ startedMs: number,
118
+ isSkipped: () => boolean,
119
+ run: (onStatus: (status: Phase2AwaitStatus) => void) => Promise<T>,
120
+ ): Promise<T> {
121
+ const awaitStartMs = performance.now();
122
+ const reported: Phase2AwaitStatus[] = [];
123
+ let threw = false;
124
+ try {
125
+ return await run((status) => {
126
+ reported.push(status);
127
+ });
128
+ } catch (err) {
129
+ threw = true;
130
+ throw err;
131
+ } finally {
132
+ const nowMs = performance.now();
133
+ const status: Phase2AwaitStatus = threw
134
+ ? (isAborted() ? "skipped" : "error")
135
+ : (reported.at(-1) ?? "ok");
136
+ recordPhase2Await(
137
+ sink,
138
+ name,
139
+ status === "ok" && isSkipped()
140
+ ? { status: "skipped", ms: 0, totalMs: 0 }
141
+ : { status, ms: nowMs - awaitStartMs, totalMs: nowMs - startedMs },
142
+ );
143
+ }
144
+ },
145
+ };
146
+ }