@remnic/core 10.0.167 → 10.0.169

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 (390) hide show
  1. package/dist/access-admin-ops-surface.js +139 -138
  2. package/dist/access-cli.js +139 -138
  3. package/dist/access-cli.js.map +1 -1
  4. package/dist/access-coding-context-resolution.js +11 -11
  5. package/dist/access-extraction-force-flush-preempt.js +139 -138
  6. package/dist/access-extraction-force-flush.js +139 -138
  7. package/dist/access-http-briefing.js +139 -138
  8. package/dist/access-http-query.js +139 -138
  9. package/dist/access-http.js +139 -138
  10. package/dist/access-identity-continuity-surface.js +139 -138
  11. package/dist/access-lcm-surface.js +139 -138
  12. package/dist/access-mcp.js +139 -138
  13. package/dist/access-observe-write-category.js +11 -11
  14. package/dist/access-observe-write-surface.js +139 -138
  15. package/dist/access-offline-manifest.js +9 -9
  16. package/dist/access-operations-batch.js +139 -138
  17. package/dist/access-operations.js +139 -138
  18. package/dist/access-recall-concurrency.js +139 -138
  19. package/dist/access-recall-excerpt-attribution.d.ts +19 -0
  20. package/dist/access-recall-excerpt-attribution.d.ts.map +1 -0
  21. package/dist/access-recall-excerpt-attribution.js +8 -0
  22. package/dist/access-recall-response.js +139 -138
  23. package/dist/access-recall-surface.d.ts.map +1 -1
  24. package/dist/access-recall-surface.js +139 -138
  25. package/dist/access-schema.js +10 -10
  26. package/dist/access-service.js +139 -138
  27. package/dist/active-recall.js +24 -24
  28. package/dist/adapters/index.js +4 -4
  29. package/dist/adapters/registry.js +2 -2
  30. package/dist/{auto-sync-L3M4RKJD.js → auto-sync-ACP5U5A3.js} +3 -3
  31. package/dist/binary-lifecycle/scanner.d.ts +2 -4
  32. package/dist/binary-lifecycle/scanner.d.ts.map +1 -1
  33. package/dist/briefing.js +13 -13
  34. package/dist/buffer-add-turns-bounded.d.ts +11 -1
  35. package/dist/buffer-add-turns-bounded.d.ts.map +1 -1
  36. package/dist/buffer-add-turns-bounded.js +3 -3
  37. package/dist/buffer-session-cap.d.ts +2 -2
  38. package/dist/buffer-session-cap.d.ts.map +1 -1
  39. package/dist/buffer-session-cap.js +1 -1
  40. package/dist/buffer.d.ts +3 -2
  41. package/dist/buffer.d.ts.map +1 -1
  42. package/dist/buffer.js +12 -12
  43. package/dist/bulk-import/index.d.ts +1 -1
  44. package/dist/bulk-import/index.d.ts.map +1 -1
  45. package/dist/bulk-import/index.js +3 -1
  46. package/dist/bulk-import/pipeline.d.ts +8 -0
  47. package/dist/bulk-import/pipeline.d.ts.map +1 -1
  48. package/dist/calibration.d.ts +19 -2
  49. package/dist/calibration.d.ts.map +1 -1
  50. package/dist/calibration.js +28 -5
  51. package/dist/calibration.js.map +1 -1
  52. package/dist/{capsule-crypto-GWVG7LGC.js → capsule-crypto-7FJQINUR.js} +2 -2
  53. package/dist/{capsule-merge-VHBRF65A.js → capsule-merge-BADOICNP.js} +2 -2
  54. package/dist/causal-behavior.js +2 -2
  55. package/dist/causal-chain.js +2 -2
  56. package/dist/causal-consolidation.js +17 -17
  57. package/dist/causal-retrieval.js +2 -2
  58. package/dist/causal-trajectory-graph.js +3 -3
  59. package/dist/causal-trajectory.js +1 -1
  60. package/dist/{chunk-OWHERGF2.js → chunk-2NLLXCJG.js} +2 -2
  61. package/dist/{chunk-IE2ZLO3R.js → chunk-32OTLNAU.js} +274 -248
  62. package/dist/chunk-32OTLNAU.js.map +1 -0
  63. package/dist/{chunk-L7SEYUHS.js → chunk-3I3NXB6X.js} +3 -3
  64. package/dist/{chunk-4NBUHYUV.js → chunk-3LADDLAF.js} +5 -5
  65. package/dist/{chunk-2DL3OFLD.js → chunk-45GEJRIG.js} +2 -2
  66. package/dist/{chunk-HSSERO3E.js → chunk-4P4GF76E.js} +8 -1
  67. package/dist/chunk-4P4GF76E.js.map +1 -0
  68. package/dist/{chunk-5BE3FLKL.js → chunk-5KDDAQ6K.js} +8 -8
  69. package/dist/{chunk-BPCR5DZP.js → chunk-62YZOQFR.js} +5 -5
  70. package/dist/chunk-62YZOQFR.js.map +1 -0
  71. package/dist/{chunk-HLWXCDUQ.js → chunk-63A2BU2B.js} +5 -5
  72. package/dist/{chunk-C5QYWM6F.js → chunk-7FPI5MFB.js} +5 -5
  73. package/dist/{chunk-ZX546Y3Y.js → chunk-7OYDFIL4.js} +2 -2
  74. package/dist/{chunk-CKZWLAHN.js → chunk-ACPFBVUD.js} +2 -2
  75. package/dist/{chunk-BKTCVXMK.js → chunk-AHOYKJ5X.js} +3 -3
  76. package/dist/{chunk-WEHSQBFR.js → chunk-AIF6V2OX.js} +9 -4
  77. package/dist/chunk-AIF6V2OX.js.map +1 -0
  78. package/dist/{chunk-FGT7CUYZ.js → chunk-ALTLOHO7.js} +2 -2
  79. package/dist/{chunk-FMFCQRDM.js → chunk-AUFPPBC3.js} +3 -3
  80. package/dist/{chunk-OAQRZ4SV.js → chunk-B5KTTWC7.js} +2 -2
  81. package/dist/{chunk-73TPOGS4.js → chunk-BFBS7OFQ.js} +9 -9
  82. package/dist/{chunk-QFTK6EDM.js → chunk-BFZFNXOC.js} +13 -13
  83. package/dist/{chunk-ZQUOUPP3.js → chunk-BHRPZBAH.js} +4 -4
  84. package/dist/{chunk-4L25GAYL.js → chunk-CX24SVLK.js} +2 -2
  85. package/dist/{chunk-YY57TRKN.js → chunk-D5ZLTLHF.js} +2 -2
  86. package/dist/{chunk-WEFFO2MJ.js → chunk-D6YCETHG.js} +2 -2
  87. package/dist/{chunk-ZDZJNXL6.js → chunk-DK2VBJ6Q.js} +4 -4
  88. package/dist/{chunk-VRHY7Y5A.js → chunk-DPL5VO5V.js} +3 -3
  89. package/dist/{chunk-LVGTH6IQ.js → chunk-E7ATID4Z.js} +11 -11
  90. package/dist/{chunk-CKELO7Q6.js → chunk-FHWX2REL.js} +2 -2
  91. package/dist/{chunk-CUPILBIP.js → chunk-FMIM36I4.js} +2 -2
  92. package/dist/{chunk-OWM2VWNX.js → chunk-FSXYBIEZ.js} +25 -24
  93. package/dist/chunk-FSXYBIEZ.js.map +1 -0
  94. package/dist/{chunk-A5UOREWD.js → chunk-FWTGO4NE.js} +2 -2
  95. package/dist/{chunk-3SL52JKD.js → chunk-FZVROZKC.js} +5 -5
  96. package/dist/{chunk-U3BCW7GX.js → chunk-G3RLCVJC.js} +3 -3
  97. package/dist/{chunk-UYIBNDQE.js → chunk-GF5NN3LE.js} +2 -2
  98. package/dist/{chunk-7OCKK5M5.js → chunk-GWY5ZFHP.js} +6 -6
  99. package/dist/{chunk-AL3TCNSJ.js → chunk-H3MLOQ7F.js} +24 -53
  100. package/dist/chunk-H3MLOQ7F.js.map +1 -0
  101. package/dist/{chunk-TNRGWJYT.js → chunk-H4IU24V5.js} +2 -2
  102. package/dist/{chunk-T4BT4FQN.js → chunk-HH6PXQ2B.js} +3 -3
  103. package/dist/{chunk-FEUWI5QH.js → chunk-HHPY5SSE.js} +2 -2
  104. package/dist/{chunk-OM5ESBES.js → chunk-HQPFACXO.js} +2 -2
  105. package/dist/{chunk-QLQUAVVP.js → chunk-I7WPLMUX.js} +16 -16
  106. package/dist/chunk-I7WPLMUX.js.map +1 -0
  107. package/dist/{chunk-IMULTENA.js → chunk-ID65XTF3.js} +2 -2
  108. package/dist/{chunk-WWQMZBDI.js → chunk-IJVU4ILJ.js} +4 -4
  109. package/dist/{chunk-GBSXTTLP.js → chunk-ITGAGNX5.js} +2 -2
  110. package/dist/chunk-IUGOGDCP.js +39 -0
  111. package/dist/chunk-IUGOGDCP.js.map +1 -0
  112. package/dist/{chunk-3PNJZTDV.js → chunk-JGGNUEVD.js} +2 -2
  113. package/dist/{chunk-YYXYZM2I.js → chunk-JN7OSQJR.js} +2 -2
  114. package/dist/{chunk-4D2EY4WM.js → chunk-K2DTHNDY.js} +6 -6
  115. package/dist/{chunk-TH6OYP6I.js → chunk-K36RMINQ.js} +3 -3
  116. package/dist/{chunk-OZKVVUJB.js → chunk-KIM5VNZN.js} +2 -2
  117. package/dist/{chunk-BFPQJNFZ.js → chunk-LXSDEPEK.js} +60 -11
  118. package/dist/{chunk-BFPQJNFZ.js.map → chunk-LXSDEPEK.js.map} +1 -1
  119. package/dist/{chunk-ZWDDY4WF.js → chunk-M7CFCRWJ.js} +2 -2
  120. package/dist/{chunk-QPFM6DHY.js → chunk-MTJFK42O.js} +2 -2
  121. package/dist/{chunk-RO5EGRAI.js → chunk-N3FRR6II.js} +2 -2
  122. package/dist/{chunk-UMEUU66X.js → chunk-O3OEVYUR.js} +2 -2
  123. package/dist/{chunk-J74YOBB3.js → chunk-PFR6ZKQI.js} +8 -8
  124. package/dist/{chunk-TAD6QMMD.js → chunk-PRC7SZYM.js} +2 -2
  125. package/dist/{chunk-LWZNSQN3.js → chunk-PUQQPLVV.js} +3 -3
  126. package/dist/{chunk-LWZNSQN3.js.map → chunk-PUQQPLVV.js.map} +1 -1
  127. package/dist/{chunk-GMO3BGOF.js → chunk-QC2MHZDD.js} +1 -1
  128. package/dist/{chunk-FOTFLHBN.js → chunk-QPLI7LUU.js} +3 -2
  129. package/dist/chunk-QPLI7LUU.js.map +1 -0
  130. package/dist/{chunk-2MWKUVHT.js → chunk-RK7SE3BL.js} +5 -5
  131. package/dist/{chunk-HDWISXFH.js → chunk-RVAPK2S7.js} +2 -2
  132. package/dist/{chunk-5PUZV73Z.js → chunk-SEIGLG62.js} +11 -11
  133. package/dist/{chunk-AVWOULJH.js → chunk-SH3GOZWK.js} +2 -2
  134. package/dist/{chunk-PFLN6TTW.js → chunk-T3MCVSUC.js} +2 -2
  135. package/dist/{chunk-WQUGCOKF.js → chunk-TFA6HPOA.js} +4 -4
  136. package/dist/{chunk-CLVILSBR.js → chunk-TGQW3AMK.js} +22 -22
  137. package/dist/{chunk-YZYAYUJQ.js → chunk-TLRIRISJ.js} +4 -4
  138. package/dist/{chunk-7VIJUZYW.js → chunk-TQ4CELUR.js} +3 -3
  139. package/dist/{chunk-5QDTZIGH.js → chunk-U7KP6QFU.js} +2 -2
  140. package/dist/{chunk-BUKK5SWA.js → chunk-UPD5XDJX.js} +5 -5
  141. package/dist/{chunk-BUKK5SWA.js.map → chunk-UPD5XDJX.js.map} +1 -1
  142. package/dist/{chunk-QVXEXGIM.js → chunk-VF6SC4OD.js} +2 -2
  143. package/dist/{chunk-EZG54YDS.js → chunk-VKXJQF5C.js} +2 -2
  144. package/dist/{chunk-RFLC6PKQ.js → chunk-VMRPLHEU.js} +2 -2
  145. package/dist/{chunk-U2PSE7MB.js → chunk-VPEIWMUT.js} +2 -2
  146. package/dist/{chunk-X67XNZ64.js → chunk-W4EJMMPP.js} +10 -10
  147. package/dist/{chunk-RB7NXZ2E.js → chunk-W4Q65VJL.js} +2 -2
  148. package/dist/{chunk-HDDRVXX4.js → chunk-W5LJ3SJ7.js} +2 -2
  149. package/dist/{chunk-W7N7NWG5.js → chunk-WCJQ3OUP.js} +2 -2
  150. package/dist/{chunk-JIF22AXI.js → chunk-WGKIXNLY.js} +5 -2
  151. package/dist/{chunk-JIF22AXI.js.map → chunk-WGKIXNLY.js.map} +1 -1
  152. package/dist/{chunk-FFWFFAP3.js → chunk-WI2WTIMY.js} +14 -8
  153. package/dist/chunk-WI2WTIMY.js.map +1 -0
  154. package/dist/{chunk-UVYI6VIX.js → chunk-X7Y7WX73.js} +1 -1
  155. package/dist/{chunk-22V3CMIW.js → chunk-XJTRIHTH.js} +8 -8
  156. package/dist/{chunk-SIONKXLU.js → chunk-XTRC6SSS.js} +14 -14
  157. package/dist/{chunk-SBRUTD5O.js → chunk-YSATDEBY.js} +5 -5
  158. package/dist/{chunk-3YOX2BQD.js → chunk-YWMCV5HL.js} +3 -3
  159. package/dist/{chunk-L272A5QW.js → chunk-YYDUBGUF.js} +30 -22
  160. package/dist/chunk-YYDUBGUF.js.map +1 -0
  161. package/dist/{chunk-6QWFZ3X5.js → chunk-ZA6CYFAK.js} +2 -2
  162. package/dist/cli.d.ts +1 -6
  163. package/dist/cli.d.ts.map +1 -1
  164. package/dist/cli.js +139 -138
  165. package/dist/coding/export-okf-codegraph.js +24 -24
  166. package/dist/coding/pre-action-gate.js +2 -2
  167. package/dist/compounding/engine.js +14 -14
  168. package/dist/config.js +24 -24
  169. package/dist/connectors/codex-marketplace.d.ts.map +1 -1
  170. package/dist/connectors/codex-materialize-runner.js +14 -14
  171. package/dist/connectors/codex-materialize.d.ts.map +1 -1
  172. package/dist/connectors/codex-materialize.js +1 -1
  173. package/dist/connectors/index.js +15 -15
  174. package/dist/consolidation-provenance-check.js +2 -2
  175. package/dist/convergence-refresh.js +15 -15
  176. package/dist/conversation-index/backend.js +2 -2
  177. package/dist/corpus-watermark.js +15 -15
  178. package/dist/deep-recall-http-glue.js +11 -11
  179. package/dist/embedding-fallback.js +2 -2
  180. package/dist/entity-retrieval.js +14 -14
  181. package/dist/event-order-recall.js +3 -3
  182. package/dist/explicit-capture.js +139 -138
  183. package/dist/extraction-judge.js +1 -1
  184. package/dist/extraction-normalization.js +1 -1
  185. package/dist/extraction-span-materialize.js +2 -2
  186. package/dist/extraction.js +27 -27
  187. package/dist/{graph-edge-decay-BC3IO2J4.js → graph-edge-decay-CXTNJ7IQ.js} +6 -6
  188. package/dist/graph-edge-decay-CXTNJ7IQ.js.map +1 -0
  189. package/dist/graph-jsonl.js +4 -4
  190. package/dist/graph-snapshot.js +4 -4
  191. package/dist/graph.js +5 -5
  192. package/dist/harmonic-retrieval.js +13 -13
  193. package/dist/index.js +198 -197
  194. package/dist/lcm/index.js +3 -3
  195. package/dist/local-llm.js +2 -2
  196. package/dist/location/index.js +14 -14
  197. package/dist/maintenance/memory-governance.js +13 -13
  198. package/dist/maintenance/rebuild-memory-lifecycle-ledger.js +13 -13
  199. package/dist/maintenance/rebuild-memory-projection-runner.js +15 -15
  200. package/dist/maintenance/rebuild-memory-projection.js +14 -14
  201. package/dist/memory-browse.js +5 -5
  202. package/dist/memory-controller.d.ts.map +1 -1
  203. package/dist/memory-controller.js +1 -1
  204. package/dist/namespaces/migrate.js +14 -14
  205. package/dist/namespaces/search.js +7 -7
  206. package/dist/namespaces/storage.d.ts.map +1 -1
  207. package/dist/namespaces/storage.js +13 -13
  208. package/dist/offline-sync-changeset-generations.js +4 -4
  209. package/dist/offline-sync-embedding-generation.js +3 -3
  210. package/dist/offline-sync-snapshot-stream.js +7 -7
  211. package/dist/offline-sync.js +6 -6
  212. package/dist/operator-doctor-corpus.js +16 -16
  213. package/dist/operator-toolkit.js +35 -35
  214. package/dist/orchestration/backlog-scheduler.d.ts +4 -0
  215. package/dist/orchestration/backlog-scheduler.d.ts.map +1 -1
  216. package/dist/orchestration/backlog-scheduler.js +150 -143
  217. package/dist/orchestration/backlog-scheduler.js.map +1 -1
  218. package/dist/orchestration/buffer-drain-runner.js +140 -139
  219. package/dist/orchestration/extraction-persist-citation.d.ts +2 -2
  220. package/dist/orchestration/extraction-persist-citation.d.ts.map +1 -1
  221. package/dist/orchestration/extraction-persist.d.ts.map +1 -1
  222. package/dist/orchestration/maintenance.js +23 -23
  223. package/dist/orchestration/recall-internal.d.ts.map +1 -1
  224. package/dist/orchestration/turn-ingestion-buffered.d.ts.map +1 -1
  225. package/dist/orchestrator.d.ts.map +1 -1
  226. package/dist/orchestrator.js +141 -140
  227. package/dist/qmd.js +4 -4
  228. package/dist/recall-navigation.js +139 -138
  229. package/dist/recall-state-view-admission.js +5 -5
  230. package/dist/recall-state-view-packet.d.ts.map +1 -1
  231. package/dist/recall-state-view-packet.js +30 -8
  232. package/dist/recall-state-view-packet.js.map +1 -1
  233. package/dist/recall-why-service.js +5 -5
  234. package/dist/reconcile/manifest.js +2 -2
  235. package/dist/resume-bundles.js +25 -25
  236. package/dist/search/factory.js +6 -6
  237. package/dist/search/index.js +8 -8
  238. package/dist/semantic-consolidation.js +18 -18
  239. package/dist/semantic-rule-promotion.js +13 -13
  240. package/dist/semantic-rule-verifier.js +13 -13
  241. package/dist/source-agent-qualifier.js +18 -18
  242. package/dist/source-attribution.d.ts +3 -3
  243. package/dist/source-attribution.d.ts.map +1 -1
  244. package/dist/source-attribution.js +1 -1
  245. package/dist/standup/build.js +13 -13
  246. package/dist/storage.d.ts +1 -0
  247. package/dist/storage.d.ts.map +1 -1
  248. package/dist/storage.js +12 -12
  249. package/dist/summarizer.d.ts +7 -1
  250. package/dist/summarizer.d.ts.map +1 -1
  251. package/dist/summarizer.js +3 -3
  252. package/dist/support-passport/index.js +16 -16
  253. package/dist/transfer/autodetect.js +3 -3
  254. package/dist/transfer/backup.js +2 -2
  255. package/dist/transfer/capsule-export.js +3 -3
  256. package/dist/transfer/capsule-import.js +3 -3
  257. package/dist/transfer/export-okf.js +13 -13
  258. package/dist/transfer/import-json.js +2 -2
  259. package/dist/transfer/import-md.js +2 -2
  260. package/dist/transfer/types.d.ts +15 -3
  261. package/dist/transfer/types.d.ts.map +1 -1
  262. package/dist/transfer/types.js +3 -1
  263. package/dist/verified-recall.js +13 -13
  264. package/dist/who-knows-cli.js +14 -14
  265. package/dist/who-knows.js +13 -13
  266. package/package.json +2 -2
  267. package/src/access-cli.test.ts +9 -9
  268. package/src/access-recall-excerpt-attribution.ts +69 -0
  269. package/src/access-recall-surface.ts +26 -31
  270. package/src/access-service-raw-excerpt-read-gate.test.ts +192 -11
  271. package/src/backlog-scheduler.test.ts +31 -0
  272. package/src/binary-lifecycle/scanner.ts +35 -14
  273. package/src/buffer-add-turns-bounded.ts +16 -2
  274. package/src/buffer-session-cap.ts +4 -4
  275. package/src/buffer.ts +5 -5
  276. package/src/bulk-import/index.ts +1 -0
  277. package/src/bulk-import/pipeline.test.ts +31 -0
  278. package/src/bulk-import/pipeline.ts +14 -0
  279. package/src/calibration.ts +56 -4
  280. package/src/cli.ts +3 -23
  281. package/src/connectors/codex-marketplace-git.test.ts +267 -0
  282. package/src/connectors/codex-marketplace.ts +76 -13
  283. package/src/connectors/codex-materialize.ts +29 -55
  284. package/src/memory-controller.test.ts +11 -0
  285. package/src/memory-controller.ts +5 -1
  286. package/src/namespaces/storage.ts +1 -0
  287. package/src/orchestration/backlog-scheduler.ts +12 -3
  288. package/src/orchestration/extraction-persist-citation.ts +5 -3
  289. package/src/orchestration/extraction-persist.ts +15 -14
  290. package/src/orchestration/recall-internal.ts +2 -3
  291. package/src/orchestration/turn-ingestion-buffered.test.ts +52 -1
  292. package/src/orchestration/turn-ingestion-buffered.ts +26 -8
  293. package/src/orchestrator.ts +1 -0
  294. package/src/recall-state-view-packet.test.ts +40 -0
  295. package/src/recall-state-view-packet.ts +46 -9
  296. package/src/source-attribution.test.ts +57 -0
  297. package/src/source-attribution.ts +46 -43
  298. package/src/storage.ts +4 -3
  299. package/src/summarizer-shutdown.test.ts +49 -16
  300. package/src/summarizer.ts +13 -5
  301. package/src/testing/subjects/memory-maintenance.test.ts +293 -0
  302. package/src/transfer/capsule-export.ts +2 -1
  303. package/src/transfer/capsule-taxonomy-version.test.ts +70 -0
  304. package/src/transfer/types.ts +13 -3
  305. package/dist/chunk-AL3TCNSJ.js.map +0 -1
  306. package/dist/chunk-BPCR5DZP.js.map +0 -1
  307. package/dist/chunk-FFWFFAP3.js.map +0 -1
  308. package/dist/chunk-FOTFLHBN.js.map +0 -1
  309. package/dist/chunk-HSSERO3E.js.map +0 -1
  310. package/dist/chunk-IE2ZLO3R.js.map +0 -1
  311. package/dist/chunk-L272A5QW.js.map +0 -1
  312. package/dist/chunk-OWM2VWNX.js.map +0 -1
  313. package/dist/chunk-QLQUAVVP.js.map +0 -1
  314. package/dist/chunk-WEHSQBFR.js.map +0 -1
  315. /package/dist/{capsule-crypto-GWVG7LGC.js.map → access-recall-excerpt-attribution.js.map} +0 -0
  316. /package/dist/{auto-sync-L3M4RKJD.js.map → auto-sync-ACP5U5A3.js.map} +0 -0
  317. /package/dist/{graph-edge-decay-BC3IO2J4.js.map → capsule-crypto-7FJQINUR.js.map} +0 -0
  318. /package/dist/{capsule-merge-VHBRF65A.js.map → capsule-merge-BADOICNP.js.map} +0 -0
  319. /package/dist/{chunk-OWHERGF2.js.map → chunk-2NLLXCJG.js.map} +0 -0
  320. /package/dist/{chunk-L7SEYUHS.js.map → chunk-3I3NXB6X.js.map} +0 -0
  321. /package/dist/{chunk-4NBUHYUV.js.map → chunk-3LADDLAF.js.map} +0 -0
  322. /package/dist/{chunk-2DL3OFLD.js.map → chunk-45GEJRIG.js.map} +0 -0
  323. /package/dist/{chunk-5BE3FLKL.js.map → chunk-5KDDAQ6K.js.map} +0 -0
  324. /package/dist/{chunk-HLWXCDUQ.js.map → chunk-63A2BU2B.js.map} +0 -0
  325. /package/dist/{chunk-C5QYWM6F.js.map → chunk-7FPI5MFB.js.map} +0 -0
  326. /package/dist/{chunk-ZX546Y3Y.js.map → chunk-7OYDFIL4.js.map} +0 -0
  327. /package/dist/{chunk-CKZWLAHN.js.map → chunk-ACPFBVUD.js.map} +0 -0
  328. /package/dist/{chunk-BKTCVXMK.js.map → chunk-AHOYKJ5X.js.map} +0 -0
  329. /package/dist/{chunk-FGT7CUYZ.js.map → chunk-ALTLOHO7.js.map} +0 -0
  330. /package/dist/{chunk-FMFCQRDM.js.map → chunk-AUFPPBC3.js.map} +0 -0
  331. /package/dist/{chunk-OAQRZ4SV.js.map → chunk-B5KTTWC7.js.map} +0 -0
  332. /package/dist/{chunk-73TPOGS4.js.map → chunk-BFBS7OFQ.js.map} +0 -0
  333. /package/dist/{chunk-QFTK6EDM.js.map → chunk-BFZFNXOC.js.map} +0 -0
  334. /package/dist/{chunk-ZQUOUPP3.js.map → chunk-BHRPZBAH.js.map} +0 -0
  335. /package/dist/{chunk-4L25GAYL.js.map → chunk-CX24SVLK.js.map} +0 -0
  336. /package/dist/{chunk-YY57TRKN.js.map → chunk-D5ZLTLHF.js.map} +0 -0
  337. /package/dist/{chunk-WEFFO2MJ.js.map → chunk-D6YCETHG.js.map} +0 -0
  338. /package/dist/{chunk-ZDZJNXL6.js.map → chunk-DK2VBJ6Q.js.map} +0 -0
  339. /package/dist/{chunk-VRHY7Y5A.js.map → chunk-DPL5VO5V.js.map} +0 -0
  340. /package/dist/{chunk-LVGTH6IQ.js.map → chunk-E7ATID4Z.js.map} +0 -0
  341. /package/dist/{chunk-CKELO7Q6.js.map → chunk-FHWX2REL.js.map} +0 -0
  342. /package/dist/{chunk-CUPILBIP.js.map → chunk-FMIM36I4.js.map} +0 -0
  343. /package/dist/{chunk-A5UOREWD.js.map → chunk-FWTGO4NE.js.map} +0 -0
  344. /package/dist/{chunk-3SL52JKD.js.map → chunk-FZVROZKC.js.map} +0 -0
  345. /package/dist/{chunk-U3BCW7GX.js.map → chunk-G3RLCVJC.js.map} +0 -0
  346. /package/dist/{chunk-UYIBNDQE.js.map → chunk-GF5NN3LE.js.map} +0 -0
  347. /package/dist/{chunk-7OCKK5M5.js.map → chunk-GWY5ZFHP.js.map} +0 -0
  348. /package/dist/{chunk-TNRGWJYT.js.map → chunk-H4IU24V5.js.map} +0 -0
  349. /package/dist/{chunk-T4BT4FQN.js.map → chunk-HH6PXQ2B.js.map} +0 -0
  350. /package/dist/{chunk-FEUWI5QH.js.map → chunk-HHPY5SSE.js.map} +0 -0
  351. /package/dist/{chunk-OM5ESBES.js.map → chunk-HQPFACXO.js.map} +0 -0
  352. /package/dist/{chunk-IMULTENA.js.map → chunk-ID65XTF3.js.map} +0 -0
  353. /package/dist/{chunk-WWQMZBDI.js.map → chunk-IJVU4ILJ.js.map} +0 -0
  354. /package/dist/{chunk-GBSXTTLP.js.map → chunk-ITGAGNX5.js.map} +0 -0
  355. /package/dist/{chunk-3PNJZTDV.js.map → chunk-JGGNUEVD.js.map} +0 -0
  356. /package/dist/{chunk-YYXYZM2I.js.map → chunk-JN7OSQJR.js.map} +0 -0
  357. /package/dist/{chunk-4D2EY4WM.js.map → chunk-K2DTHNDY.js.map} +0 -0
  358. /package/dist/{chunk-TH6OYP6I.js.map → chunk-K36RMINQ.js.map} +0 -0
  359. /package/dist/{chunk-OZKVVUJB.js.map → chunk-KIM5VNZN.js.map} +0 -0
  360. /package/dist/{chunk-ZWDDY4WF.js.map → chunk-M7CFCRWJ.js.map} +0 -0
  361. /package/dist/{chunk-QPFM6DHY.js.map → chunk-MTJFK42O.js.map} +0 -0
  362. /package/dist/{chunk-RO5EGRAI.js.map → chunk-N3FRR6II.js.map} +0 -0
  363. /package/dist/{chunk-UMEUU66X.js.map → chunk-O3OEVYUR.js.map} +0 -0
  364. /package/dist/{chunk-J74YOBB3.js.map → chunk-PFR6ZKQI.js.map} +0 -0
  365. /package/dist/{chunk-TAD6QMMD.js.map → chunk-PRC7SZYM.js.map} +0 -0
  366. /package/dist/{chunk-GMO3BGOF.js.map → chunk-QC2MHZDD.js.map} +0 -0
  367. /package/dist/{chunk-2MWKUVHT.js.map → chunk-RK7SE3BL.js.map} +0 -0
  368. /package/dist/{chunk-HDWISXFH.js.map → chunk-RVAPK2S7.js.map} +0 -0
  369. /package/dist/{chunk-5PUZV73Z.js.map → chunk-SEIGLG62.js.map} +0 -0
  370. /package/dist/{chunk-AVWOULJH.js.map → chunk-SH3GOZWK.js.map} +0 -0
  371. /package/dist/{chunk-PFLN6TTW.js.map → chunk-T3MCVSUC.js.map} +0 -0
  372. /package/dist/{chunk-WQUGCOKF.js.map → chunk-TFA6HPOA.js.map} +0 -0
  373. /package/dist/{chunk-CLVILSBR.js.map → chunk-TGQW3AMK.js.map} +0 -0
  374. /package/dist/{chunk-YZYAYUJQ.js.map → chunk-TLRIRISJ.js.map} +0 -0
  375. /package/dist/{chunk-7VIJUZYW.js.map → chunk-TQ4CELUR.js.map} +0 -0
  376. /package/dist/{chunk-5QDTZIGH.js.map → chunk-U7KP6QFU.js.map} +0 -0
  377. /package/dist/{chunk-QVXEXGIM.js.map → chunk-VF6SC4OD.js.map} +0 -0
  378. /package/dist/{chunk-EZG54YDS.js.map → chunk-VKXJQF5C.js.map} +0 -0
  379. /package/dist/{chunk-RFLC6PKQ.js.map → chunk-VMRPLHEU.js.map} +0 -0
  380. /package/dist/{chunk-U2PSE7MB.js.map → chunk-VPEIWMUT.js.map} +0 -0
  381. /package/dist/{chunk-X67XNZ64.js.map → chunk-W4EJMMPP.js.map} +0 -0
  382. /package/dist/{chunk-RB7NXZ2E.js.map → chunk-W4Q65VJL.js.map} +0 -0
  383. /package/dist/{chunk-HDDRVXX4.js.map → chunk-W5LJ3SJ7.js.map} +0 -0
  384. /package/dist/{chunk-W7N7NWG5.js.map → chunk-WCJQ3OUP.js.map} +0 -0
  385. /package/dist/{chunk-UVYI6VIX.js.map → chunk-X7Y7WX73.js.map} +0 -0
  386. /package/dist/{chunk-22V3CMIW.js.map → chunk-XJTRIHTH.js.map} +0 -0
  387. /package/dist/{chunk-SIONKXLU.js.map → chunk-XTRC6SSS.js.map} +0 -0
  388. /package/dist/{chunk-SBRUTD5O.js.map → chunk-YSATDEBY.js.map} +0 -0
  389. /package/dist/{chunk-3YOX2BQD.js.map → chunk-YWMCV5HL.js.map} +0 -0
  390. /package/dist/{chunk-6QWFZ3X5.js.map → chunk-ZA6CYFAK.js.map} +0 -0
@@ -27,6 +27,7 @@
27
27
 
28
28
  import { randomUUID } from "node:crypto";
29
29
  import { hostname } from "node:os";
30
+ import { resolveMaxTurnsPerSession } from "../buffer-session-cap.js";
30
31
  import { log } from "../logger.js";
31
32
  import type { Orchestrator } from "../orchestrator.js";
32
33
  import type { BufferDrainClaims, DrainLease } from "../storage/buffer-drain-claims.js";
@@ -61,6 +62,10 @@ export interface BacklogSchedulerDeps {
61
62
  breakerSnapshot?(): ProviderBreakerSnapshot;
62
63
  /** Test seam: monotonic-ish clock for backoff windows. */
63
64
  now?(): number;
65
+ /** The buffer's per-session turn cap. A live key holding this many turns
66
+ * refuses new captures, so discovery lists it before the claim page.
67
+ * Optional: without it, discovery keeps plain claim-page-first order. */
68
+ maxTurnsPerSession?(): number;
64
69
  }
65
70
 
66
71
  export interface BacklogSchedulerOptions {
@@ -285,6 +290,7 @@ export class BacklogScheduler {
285
290
 
286
291
  /** Bounded discovery: ONE page of existing claims with pending turns */
287
292
  private async discoverCandidates(): Promise<{ key: string; needsClaim: boolean }[]> {
293
+ const capped: { key: string; needsClaim: boolean }[] = [];
288
294
  const out: { key: string; needsClaim: boolean }[] = [];
289
295
  const seen = new Set<string>();
290
296
  const pageLimit = Math.max(this.submissionLimit() * 4, 16);
@@ -294,13 +300,15 @@ export class BacklogScheduler {
294
300
  out.push({ key: listed.key, needsClaim: false });
295
301
  }
296
302
  this.claimCursor = page.nextCursor;
303
+ const turnCap = this.deps.maxTurnsPerSession?.() ?? Number.POSITIVE_INFINITY;
297
304
  for (const [key, counts] of await this.deps.liveBufferCounts()) {
298
- if (counts.turns + counts.retainedTurns <= 0) continue;
305
+ const held = counts.turns + counts.retainedTurns;
306
+ if (held <= 0) continue;
299
307
  if (seen.has(key) || this.deps.claims.isClaimed(key)) continue;
300
308
  seen.add(key);
301
- out.push({ key, needsClaim: true });
309
+ (held >= turnCap ? capped : out).push({ key, needsClaim: true });
302
310
  }
303
- return out;
311
+ return [...capped, ...out];
304
312
  }
305
313
 
306
314
  /** Submission bound: the queue's own concurrency limit, read with the
@@ -529,6 +537,7 @@ export function wireBacklogScheduler(
529
537
  // The orchestrator's one shared provider breaker (foreground and every
530
538
  // claim-backed drain accumulate toward the same threshold).
531
539
  breakerSnapshot: () => orchestrator.getExtractionResilienceStatus().breaker,
540
+ maxTurnsPerSession: () => resolveMaxTurnsPerSession(orchestrator.config.bufferMaxTurnsPerSession),
532
541
  },
533
542
  options
534
543
  );
@@ -11,11 +11,12 @@ export function normalizeStoredHashSource(
11
11
  raw: string,
12
12
  citationEnabled: boolean,
13
13
  citationTemplate: string,
14
+ citationHistory: readonly string[] = [],
14
15
  ): string {
15
16
  return ContentHashIndex.normalizeContent(
16
17
  sanitizeMemoryContent(
17
- citationEnabled && hasCitationForTemplate(raw, citationTemplate)
18
- ? stripCitationForTemplate(raw, citationTemplate)
18
+ citationEnabled && hasCitationForTemplate(raw, citationTemplate, citationHistory)
19
+ ? stripCitationForTemplate(raw, citationTemplate, citationHistory)
19
20
  : raw,
20
21
  ).text,
21
22
  );
@@ -26,6 +27,7 @@ export function applyInlineCitation(
26
27
  citationEnabled: boolean,
27
28
  citationTemplate: string,
28
29
  citationContextBase: Omit<CitationContext, "ts">,
30
+ citationHistory: readonly string[] = [],
29
31
  ): string {
30
32
  if (!citationEnabled) return content;
31
33
  if (typeof content !== "string" || content.length === 0) return content;
@@ -33,5 +35,5 @@ export function applyInlineCitation(
33
35
  ...citationContextBase,
34
36
  ts: new Date().toISOString(),
35
37
  };
36
- return attachCitation(content, citationContext, citationTemplate);
38
+ return attachCitation(content, citationContext, citationTemplate, citationHistory);
37
39
  }
@@ -171,6 +171,7 @@ export class ExtractionPersistCoordinator {
171
171
  ): Promise<ExtractionPersistResult> {
172
172
  const citationEnabled = resolvePipelineProcessingCapabilities(this.deps.config).inlineSourceAttribution === true;
173
173
  const citationTemplate = this.deps.config.inlineSourceAttributionFormat;
174
+ const citationHistory = this.deps.config.inlineSourceAttributionFormatHistory;
174
175
  const factDedupEnabled = resolveRecallAuxiliaryCapabilities(this.deps.config).factDeduplication;
175
176
  const harmonicConstructionEnabled = resolveCapabilities(this.deps.config).harmonicRetrieval;
176
177
  const harmonicAnchorsEnabled =
@@ -189,7 +190,7 @@ export class ExtractionPersistCoordinator {
189
190
  const promotedCopyProbe = createBatchPromotedCopyProbe(this.deps.config, this.deps.getStorageRouter, scopeProfileWritePlan); // #2330 finding F: one promoted-copy scan per namespace per batch
190
191
 
191
192
  const normalizeStoredHashSource = (raw: string): string =>
192
- normalizeStoredHashSourceContent(raw, citationEnabled, citationTemplate);
193
+ normalizeStoredHashSourceContent(raw, citationEnabled, citationTemplate, citationHistory);
193
194
  const citationContextBase: Omit<CitationContext, "ts"> = citationEnabled
194
195
  ? {
195
196
  agent: sourceContext?.principal,
@@ -197,7 +198,7 @@ export class ExtractionPersistCoordinator {
197
198
  }
198
199
  : {};
199
200
  const applyInlineCitation = (content: string): string =>
200
- applyInlineCitationToContent(content, citationEnabled, citationTemplate, citationContextBase);
201
+ applyInlineCitationToContent(content, citationEnabled, citationTemplate, citationContextBase, citationHistory);
201
202
  const persistedIds: string[] = [];
202
203
  const memoryPathById = new Map<string, string>();
203
204
  const anchorSnapshots = new ExtractionAnchorSnapshot({
@@ -385,8 +386,8 @@ export class ExtractionPersistCoordinator {
385
386
  );
386
387
  if (targets.length === 0) return [];
387
388
  const rawContent =
388
- citationEnabled && hasCitationForTemplate(options.content, citationTemplate)
389
- ? stripCitationForTemplate(options.content, citationTemplate)
389
+ citationEnabled && hasCitationForTemplate(options.content, citationTemplate, citationHistory)
390
+ ? stripCitationForTemplate(options.content, citationTemplate, citationHistory)
390
391
  : options.content;
391
392
  const citedContent = applyInlineCitation(rawContent);
392
393
  const sanitizedBase = sanitizeMemoryContent(rawContent);
@@ -617,8 +618,8 @@ export class ExtractionPersistCoordinator {
617
618
  // uses the exact body writeMemory stores (#369/#401, #402 round-6).
618
619
  const rawContent =
619
620
  citationEnabled &&
620
- hasCitationForTemplate(options.content, citationTemplate)
621
- ? stripCitationForTemplate(options.content, citationTemplate)
621
+ hasCitationForTemplate(options.content, citationTemplate, citationHistory)
622
+ ? stripCitationForTemplate(options.content, citationTemplate, citationHistory)
622
623
  : options.content;
623
624
  const citedContent = applyInlineCitation(rawContent);
624
625
  const sanitizedBase = sanitizeMemoryContent(rawContent);
@@ -996,8 +997,8 @@ export class ExtractionPersistCoordinator {
996
997
  // Build the same dedupContent the promotion functions hash on so the
997
998
  // content-hash lookup in the helper matches what was stored.
998
999
  const rawContent =
999
- citationEnabled && hasCitationForTemplate(args.content, citationTemplate)
1000
- ? stripCitationForTemplate(args.content, citationTemplate)
1000
+ citationEnabled && hasCitationForTemplate(args.content, citationTemplate, citationHistory)
1001
+ ? stripCitationForTemplate(args.content, citationTemplate, citationHistory)
1001
1002
  : args.content;
1002
1003
  const sanitizedBase = sanitizeMemoryContent(rawContent);
1003
1004
  // #2014 round 3: promoted copies were written from SALVAGE envelopes,
@@ -1659,8 +1660,8 @@ export class ExtractionPersistCoordinator {
1659
1660
  // the title alone, so distinct step lists are not collapsed (issue #519).
1660
1661
  const canonicalContentForHash =
1661
1662
  citationEnabled &&
1662
- hasCitationForTemplate(fact.content, citationTemplate)
1663
- ? stripCitationForTemplate(fact.content, citationTemplate)
1663
+ hasCitationForTemplate(fact.content, citationTemplate, citationHistory)
1664
+ ? stripCitationForTemplate(fact.content, citationTemplate, citationHistory)
1664
1665
  : fact.content;
1665
1666
  const contentHashDedupKey =
1666
1667
  writeCategory === "procedure"
@@ -2161,8 +2162,8 @@ export class ExtractionPersistCoordinator {
2161
2162
  // via stripCitationForTemplate before calling hasFactContentHash.
2162
2163
  const rawChunkedContent =
2163
2164
  citationEnabled &&
2164
- hasCitationForTemplate(fact.content, citationTemplate)
2165
- ? stripCitationForTemplate(fact.content, citationTemplate)
2165
+ hasCitationForTemplate(fact.content, citationTemplate, citationHistory)
2166
+ ? stripCitationForTemplate(fact.content, citationTemplate, citationHistory)
2166
2167
  : fact.content;
2167
2168
  const citedChunkedContent = applyInlineCitation(rawChunkedContent);
2168
2169
  const parentWriteEnvelope = composeSalvagedExtractionEnvelope(
@@ -2416,8 +2417,8 @@ export class ExtractionPersistCoordinator {
2416
2417
  try {
2417
2418
  const canonicalChunkedContent =
2418
2419
  citationEnabled &&
2419
- hasCitationForTemplate(fact.content, citationTemplate)
2420
- ? stripCitationForTemplate(fact.content, citationTemplate)
2420
+ hasCitationForTemplate(fact.content, citationTemplate, citationHistory)
2421
+ ? stripCitationForTemplate(fact.content, citationTemplate, citationHistory)
2421
2422
  : fact.content;
2422
2423
  // #1645: do NOT register a tombstone-blocked fact's content in the
2423
2424
  // dedup index — writeMemory already skipped it (rule 44). Re-adding
@@ -1368,9 +1368,8 @@ export class RecallInternalCoordinator {
1368
1368
  return null;
1369
1369
  }
1370
1370
  const section = buildCalibrationRecallSection(
1371
- rules.slice(0, this.deps.config.calibrationMaxRulesPerRecall),
1372
- retrievalQuery,
1373
- this.deps.config.calibrationMaxChars,
1371
+ rules, retrievalQuery, this.deps.config.calibrationMaxChars,
1372
+ this.deps.config.calibrationMaxRulesPerRecall,
1374
1373
  );
1375
1374
  recordRecallSectionMetric({
1376
1375
  section: "calibrationRules",
@@ -3,8 +3,9 @@ import test from "node:test";
3
3
 
4
4
  import { ReplayAdmissionRefusedError, StorageTargetRequiredError } from "../buffer-admission.js";
5
5
  import type { AddTurnOutcome } from "../buffer-types.js";
6
+ import { SmartBuffer } from "../buffer.js";
6
7
  import { parseConfig } from "../config.js";
7
- import type { BufferTurn, PluginConfig } from "../types.js";
8
+ import type { BufferEntryState, BufferState, BufferTurn, PluginConfig } from "../types.js";
8
9
  import { ingestReplayBatchBuffered } from "./turn-ingestion-buffered.js";
9
10
  import type { TurnIngestionDeps } from "./turn-ingestion.js";
10
11
 
@@ -222,3 +223,53 @@ test("buffered ingest: LCM archive observes raw turns per session and honors arc
222
223
  await ingestReplayBatchBuffered(deps, bySession, { writeNamespaceOverride: "ns-work", archiveLcm: false });
223
224
  assert.equal(observed.length, 0);
224
225
  });
226
+
227
+ function realBufferDeps(config: PluginConfig, entries: Record<string, BufferEntryState>) {
228
+ const initial: BufferState = { turns: [], lastExtractionAt: null, extractionCount: 0, entries };
229
+ const storage = { loadBuffer: async () => structuredClone(initial), saveBuffer: async () => {} };
230
+ // SAFETY: the stub implements the load/save surface SmartBuffer reads; the cast only satisfies StorageManager.
231
+ const buffer = new SmartBuffer(config, storage as never);
232
+ const deps: Deps = { config, buffer, lcmEngine: null, queueBufferedExtraction: async () => {} };
233
+ return deps;
234
+ }
235
+
236
+ function heldTurns(sessionKey: string, count: number): BufferTurn[] {
237
+ return Array.from({ length: count }, (_, i) => ({ ...turn(`held ${i}`), sessionKey, acceptedCapture: true }));
238
+ }
239
+
240
+ test("buffered ingest: a session at its turn cap is refused with the per-session turn cap reason, not entry capacity", async () => {
241
+ const config = parseConfig({ memoryDir: "/tmp/remnic-buffered-test", bufferSaveDebounceMs: 0, bufferMaxTurnsPerSession: 4 });
242
+ const deps = realBufferDeps(config, {
243
+ "pi:full": { turns: heldTurns("pi:full", 4), lastExtractionAt: null, extractionCount: 0 },
244
+ });
245
+
246
+ await assert.rejects(
247
+ ingestReplayBatchBuffered(deps, new Map([["pi:full", [turn("one too many")]]]), { writeNamespaceOverride: "ns-work" }),
248
+ (err: Error) => {
249
+ assert.ok(err instanceof ReplayAdmissionRefusedError, "still the retryable admission class");
250
+ assert.match(err.message, /per-session turn cap \(4\)/);
251
+ assert.match(err.message, /pi:full/);
252
+ assert.doesNotMatch(err.message, /entry capacity/);
253
+ return true;
254
+ },
255
+ );
256
+ });
257
+
258
+ test("buffered ingest: a new session refused at the session-entry cap keeps the entry capacity reason", async () => {
259
+ const config = parseConfig({ memoryDir: "/tmp/remnic-buffered-test", bufferSaveDebounceMs: 0, bufferMaxSessions: 3 });
260
+ const deps = realBufferDeps(config, {
261
+ "pi:a": { turns: heldTurns("pi:a", 1), lastExtractionAt: null, extractionCount: 0 },
262
+ "pi:b": { turns: heldTurns("pi:b", 1), lastExtractionAt: null, extractionCount: 0 },
263
+ });
264
+
265
+ await assert.rejects(
266
+ ingestReplayBatchBuffered(deps, new Map([["pi:new", [turn("new session")]]]), { writeNamespaceOverride: "ns-work" }),
267
+ (err: Error) => {
268
+ assert.ok(err instanceof ReplayAdmissionRefusedError);
269
+ assert.match(err.message, /session-entry cap \(3\)/);
270
+ assert.match(err.message, /entry capacity/, "operators grepping the old text still find entry-cap refusals");
271
+ assert.doesNotMatch(err.message, /per-session turn cap/);
272
+ return true;
273
+ },
274
+ );
275
+ });
@@ -1,6 +1,7 @@
1
1
  /** Buffered durable replay ingest (#3368 split from turn-ingestion.ts — 1200-line ratchet). */
2
2
 
3
3
  import { ReplayAdmissionRefusedError, StorageTargetRequiredError } from "../buffer-admission.js";
4
+ import type { BoundedAdmissionRefusal } from "../buffer-add-turns-bounded.js";
4
5
  import { resolveNamespaceCapabilities } from "../capabilities.js";
5
6
  import type { BufferTurn, CodingContext } from "../types.js";
6
7
  import type { ResolvedScopeProfilePlan } from "../namespaces/scope-profiles.js";
@@ -38,16 +39,15 @@ export async function ingestReplayBatchBuffered(
38
39
  };
39
40
  const admissionKey = options.bufferAdmissionIdempotencyKey?.trim();
40
41
  const batches = [...bySession].map(([bufferKey, sessionTurns]) => ({ bufferKey, turns: sessionTurns.map(pin) }));
42
+ let refusal: BoundedAdmissionRefusal | undefined;
43
+ const onRefused = (reason: BoundedAdmissionRefusal): void => {
44
+ refusal = reason;
45
+ };
41
46
  const outcomes = admissionKey
42
- ? await deps.buffer.addTurnsBoundedForObserveReplay(batches, admissionKey)
43
- : await deps.buffer.addTurnsBounded(batches);
47
+ ? await deps.buffer.addTurnsBoundedForObserveReplay(batches, admissionKey, onRefused)
48
+ : await deps.buffer.addTurnsBounded(batches, onRefused);
44
49
  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
- }
50
+ if (outcomes === null) throw replayRefusal(refusal, batches);
51
51
 
52
52
  await deps.buffer.flushPendingSave({ throwOnFailure: true });
53
53
 
@@ -72,3 +72,21 @@ export async function ingestReplayBatchBuffered(
72
72
  }
73
73
  }
74
74
  }
75
+
76
+ function replayRefusal(
77
+ refusal: BoundedAdmissionRefusal | undefined,
78
+ batches: readonly { bufferKey: string; turns: readonly BufferTurn[] }[],
79
+ ): ReplayAdmissionRefusedError {
80
+ if (refusal?.reason === "session_turn_cap") {
81
+ return new ReplayAdmissionRefusedError(
82
+ `durable observe capture refused: session ${refusal.bufferKey} holds the per-session turn cap ` +
83
+ `(${refusal.maxTurnsPerSession}) of unextracted turns; retry after extraction drains it`,
84
+ );
85
+ }
86
+ const refusedKey = batches.find((batch) => batch.turns.length > 0)?.bufferKey ?? "unknown";
87
+ const cap = refusal?.reason === "session_entry_cap" ? ` (${refusal.maxSessionEntries})` : "";
88
+ return new ReplayAdmissionRefusedError(
89
+ `durable observe capture refused: extraction buffer at entry capacity, session-entry cap${cap} ` +
90
+ `full for batch containing ${refusedKey}`,
91
+ );
92
+ }
@@ -1520,6 +1520,7 @@ export class Orchestrator {
1520
1520
  // Propagate the inline-attribution template so the storage layer can strip
1521
1521
  // citations from legacy facts during the hash-index rebuild path.
1522
1522
  this.storage.citationTemplate = config.inlineSourceAttributionFormat;
1523
+ this.storage.citationTemplateHistory = config.inlineSourceAttributionFormatHistory;
1523
1524
  // #1522: bind the post-write catalog touch at the storage chokepoint.
1524
1525
  if (config.defaultNamespace) this.storageRouter.bindCatalogWriteHook(this.storage, config.defaultNamespace);
1525
1526
  // Wire page-level versioning (issue #371)
@@ -156,3 +156,43 @@ test("input entries are not mutated", () => {
156
156
  buildStateEvidencePackets(entries);
157
157
  assert.deepEqual(entries, snapshot);
158
158
  });
159
+
160
+ test("shared chain suffixes resolve each entry at its own depth — #3565", () => {
161
+ // Diamond: two predecessors share one suffix chain. A memoized walk must
162
+ // give every entry its OWN depth (a1/a2 = 3, b = 2, c = 1), not the depth
163
+ // of whichever entry populated the cache entry it shared.
164
+ const entries: StateViewEntry[] = [
165
+ { memoryId: "head", stateLabel: "current" },
166
+ { memoryId: "a1", stateLabel: "historical", supersededById: "b" },
167
+ { memoryId: "a2", stateLabel: "historical", supersededById: "b" },
168
+ { memoryId: "b", stateLabel: "historical", supersededById: "c" },
169
+ { memoryId: "c", stateLabel: "historical", supersededById: "head" },
170
+ ];
171
+ const out = buildStateEvidencePackets(entries);
172
+ assert.deepEqual(out, {
173
+ packets: [{ headId: "head", historyIds: ["c", "b", "a1", "a2"] }],
174
+ orphanHistoryIds: [],
175
+ });
176
+ });
177
+
178
+ test("a long chain resolves in one pass, preserving per-entry depth order — #3565", () => {
179
+ // 600-entry chain: nearest-to-head ordering must hold end-to-end. Guards
180
+ // the O(n) memoized walk against off-by-one depth corruption at scale.
181
+ const n = 600;
182
+ const entries: StateViewEntry[] = [{ memoryId: "head", stateLabel: "current" }];
183
+ for (let i = n - 1; i >= 0; i--) {
184
+ entries.push({
185
+ memoryId: `h${i}`,
186
+ stateLabel: "historical",
187
+ supersededById: i === n - 1 ? "head" : `h${i + 1}`,
188
+ });
189
+ }
190
+ const out = buildStateEvidencePackets(entries);
191
+ const packet = out.packets.find((p) => p.headId === "head");
192
+ assert.ok(packet);
193
+ assert.equal(packet.historyIds.length, n);
194
+ assert.deepEqual(
195
+ packet.historyIds,
196
+ Array.from({ length: n }, (_, i) => `h${n - 1 - i}`),
197
+ );
198
+ });
@@ -47,25 +47,63 @@ interface Attachment {
47
47
  * stop at the first current/transition successor. Returns undefined when the
48
48
  * walk dead-ends (no or blank successor, successor id absent from the input)
49
49
  * or revisits an id (cycle), so callers treat the entry as an orphan.
50
+ *
51
+ * `resolved` memoizes per-entry outcomes across calls (#3565): every id
52
+ * traversed gets its own cached resolution (its own depth), so one long
53
+ * chain resolves in a single pass instead of O(n^2) re-walks.
50
54
  */
51
55
  function resolveHead(
52
56
  entry: StateViewEntry,
53
57
  byId: ReadonlyMap<string, StateViewEntry>,
58
+ resolved: Map<string, HeadResolution | undefined>,
54
59
  ): HeadResolution | undefined {
55
- const visited = new Set<string>();
60
+ const cached = resolved.get(entry.memoryId);
61
+ if (cached !== undefined || resolved.has(entry.memoryId)) return cached;
62
+ const path: string[] = [entry.memoryId];
63
+ const visited = new Set<string>(path);
56
64
  let current = entry;
57
65
  let depth = 0;
58
66
  for (;;) {
59
67
  const successorId = current.supersededById;
60
- if (successorId === undefined || successorId.trim() === "") return undefined;
61
- const successor = byId.get(successorId);
62
- if (successor === undefined) return undefined;
68
+ const successor =
69
+ successorId === undefined || successorId.trim() === ""
70
+ ? undefined
71
+ : byId.get(successorId);
72
+ if (successor === undefined || successorId === undefined) break;
73
+ const hit = resolved.get(successorId);
74
+ if (hit !== undefined || resolved.has(successorId)) {
75
+ // A node with a known outcome: splice its resolution on with an
76
+ // offset, or propagate the dead-end.
77
+ const result =
78
+ hit === undefined
79
+ ? undefined
80
+ : { headId: hit.headId, depth: depth + 1 + hit.depth };
81
+ for (let i = 0; i < path.length; i++) {
82
+ resolved.set(
83
+ path[i],
84
+ result === undefined
85
+ ? undefined
86
+ : { headId: result.headId, depth: result.depth - i },
87
+ );
88
+ }
89
+ return result;
90
+ }
63
91
  depth += 1;
64
- if (successor.stateLabel !== "historical") return { headId: successorId, depth };
65
- if (visited.has(successorId)) return undefined;
92
+ if (successor.stateLabel !== "historical") {
93
+ // Head found: every path node resolves to it at its own depth.
94
+ for (let i = 0; i < path.length; i++) {
95
+ resolved.set(path[i], { headId: successorId, depth: depth - i });
96
+ }
97
+ return { headId: successorId, depth };
98
+ }
99
+ if (visited.has(successorId)) break;
66
100
  visited.add(successorId);
101
+ path.push(successorId);
67
102
  current = successor;
68
103
  }
104
+ // Dead-end or cycle: every node on the path is an orphan.
105
+ for (const id of path) resolved.set(id, undefined);
106
+ return undefined;
69
107
  }
70
108
 
71
109
  function compareStrings(a: string, b: string): number {
@@ -97,12 +135,11 @@ export function buildStateEvidencePackets(
97
135
  if (!byId.has(entry.memoryId)) byId.set(entry.memoryId, entry);
98
136
  }
99
137
 
100
- // ponytail: per-entry chain walks are O(n^2) on one long chain; recall-sized
101
- // result sets stay tiny, memoize if packet building ever moves offline.
102
138
  const packets: StateEvidencePacket[] = [];
103
139
  const packetByHead = new Map<string, StateEvidencePacket>();
104
140
  const attachments: Attachment[] = [];
105
141
  const orphanHistoryIds: string[] = [];
142
+ const resolved = new Map<string, HeadResolution | undefined>();
106
143
 
107
144
  for (const [id, entry] of byId) {
108
145
  if (entry.stateLabel !== "historical") {
@@ -111,7 +148,7 @@ export function buildStateEvidencePackets(
111
148
  packets.push(packet);
112
149
  continue;
113
150
  }
114
- const head = resolveHead(entry, byId);
151
+ const head = resolveHead(entry, byId, resolved);
115
152
  if (head === undefined) orphanHistoryIds.push(id);
116
153
  else attachments.push({ headId: head.headId, historyId: id, depth: head.depth });
117
154
  }
@@ -1518,3 +1518,60 @@ test("citation matcher resists polynomial ReDoS on hostile unterminated input (C
1518
1518
  const valid = parseAllCitations("body [Source: doc-1 , 2026-06-08 ]");
1519
1519
  assert.equal(valid.length, 1);
1520
1520
  });
1521
+
1522
+ test("#3567 hasCitationForTemplate: default fast path consults configured prior templates", () => {
1523
+ // Fact written while a custom template was configured; config later reverted
1524
+ // to the default. The marker does not match the default shape, so the old
1525
+ // `template === DEFAULT_CITATION_FORMAT` fast path returned false and the
1526
+ // body was double-cited / hash-mismatched on reprocess.
1527
+ const priorTemplate = "[src:{agent}/{session}@{date}]";
1528
+ const body = "Latency improved after the index rebuild.";
1529
+ const cited = attachCitation(
1530
+ body,
1531
+ { agent: "scout", session: "agent:scout:alpha", ts: "2026-04-10T14:25:07Z" },
1532
+ priorTemplate,
1533
+ );
1534
+
1535
+ // The prior template is out of history: the miss stands (documents the
1536
+ // operator contract — list prior formats in inlineSourceAttributionFormatHistory).
1537
+ assert.equal(hasCitationForTemplate(cited, DEFAULT_CITATION_FORMAT), false);
1538
+
1539
+ // With the prior template declared, the same check detects it.
1540
+ assert.equal(
1541
+ hasCitationForTemplate(cited, DEFAULT_CITATION_FORMAT, [priorTemplate]),
1542
+ true,
1543
+ );
1544
+ });
1545
+
1546
+ test("#3567 stripCitationForTemplate strips a prior-template marker under a reverted config", () => {
1547
+ const priorTemplate = "[src:{agent}/{session}@{date}]";
1548
+ const body = "Latency improved after the index rebuild.";
1549
+ const cited = attachCitation(
1550
+ body,
1551
+ { agent: "scout", session: "agent:scout:alpha", ts: "2026-04-10T14:25:07Z" },
1552
+ priorTemplate,
1553
+ );
1554
+
1555
+ assert.equal(
1556
+ stripCitationForTemplate(cited, DEFAULT_CITATION_FORMAT, [priorTemplate]),
1557
+ body,
1558
+ );
1559
+ });
1560
+
1561
+ test("#3567 attachCitation does not double-cite a body carrying a prior-template marker", () => {
1562
+ const priorTemplate = "[src:{agent}/{session}@{date}]";
1563
+ const body = "Latency improved after the index rebuild.";
1564
+ const cited = attachCitation(
1565
+ body,
1566
+ { agent: "scout", session: "agent:scout:alpha", ts: "2026-04-10T14:25:07Z" },
1567
+ priorTemplate,
1568
+ );
1569
+
1570
+ const reattached = attachCitation(
1571
+ cited,
1572
+ { agent: "planner", session: "agent:planner:main", ts: "2026-06-01T00:00:00Z" },
1573
+ DEFAULT_CITATION_FORMAT,
1574
+ [priorTemplate],
1575
+ );
1576
+ assert.equal(reattached, cited);
1577
+ });