@remnic/core 10.0.190 → 10.0.192

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 (296) hide show
  1. package/dist/abstraction-nodes.js +4 -4
  2. package/dist/access-admin-ops-surface.js +76 -75
  3. package/dist/access-cli.js +76 -75
  4. package/dist/access-cli.js.map +1 -1
  5. package/dist/access-extraction-force-flush-preempt.js +76 -75
  6. package/dist/access-extraction-force-flush.js +76 -75
  7. package/dist/access-http-briefing.js +76 -75
  8. package/dist/access-http-query.js +76 -75
  9. package/dist/access-http.js +76 -75
  10. package/dist/access-identity-continuity-surface.js +76 -75
  11. package/dist/access-lcm-surface.js +76 -75
  12. package/dist/access-mcp.js +76 -75
  13. package/dist/access-observe-write-surface.js +76 -75
  14. package/dist/access-operations-batch.js +76 -75
  15. package/dist/access-operations.js +76 -75
  16. package/dist/access-recall-concurrency.js +76 -75
  17. package/dist/access-recall-diagnostics.js +2 -2
  18. package/dist/access-recall-response.js +76 -75
  19. package/dist/access-recall-surface.js +76 -75
  20. package/dist/access-service.js +76 -75
  21. package/dist/active-recall.js +16 -16
  22. package/dist/admin/admin-surfaces.d.ts +11 -0
  23. package/dist/admin/admin-surfaces.d.ts.map +1 -1
  24. package/dist/admin/admin-surfaces.js +43 -0
  25. package/dist/briefing.js +16 -16
  26. package/dist/buffer-persistence.d.ts +7 -0
  27. package/dist/buffer-persistence.d.ts.map +1 -1
  28. package/dist/buffer-persistence.js +1 -1
  29. package/dist/buffer.d.ts +2 -0
  30. package/dist/buffer.d.ts.map +1 -1
  31. package/dist/buffer.js +6 -6
  32. package/dist/{capsule-merge-BADOICNP.js → capsule-merge-3FARYIHP.js} +5 -5
  33. package/dist/causal-consolidation.js +17 -17
  34. package/dist/{chunk-IMSLPQJB.js → chunk-2QW5HPKU.js} +2 -2
  35. package/dist/{chunk-KNYUEYB6.js → chunk-2YJ2ST23.js} +2 -2
  36. package/dist/{chunk-X3ERYOLO.js → chunk-3BICT225.js} +2 -2
  37. package/dist/{chunk-UWKHLWUE.js → chunk-3RZ4GDOH.js} +2 -2
  38. package/dist/{chunk-ODIBCZLG.js → chunk-3YID7KZ6.js} +2 -2
  39. package/dist/{chunk-56BNHKZM.js → chunk-4EAVEDLG.js} +9 -9
  40. package/dist/{chunk-TLRIRISJ.js → chunk-4LCA2GEX.js} +2 -2
  41. package/dist/{chunk-4N33L4HY.js → chunk-5GIYIYJI.js} +2 -2
  42. package/dist/{chunk-65DWWJKI.js → chunk-75K6DRPN.js} +12 -9
  43. package/dist/chunk-75K6DRPN.js.map +1 -0
  44. package/dist/{chunk-ZDLVHGIC.js → chunk-7EP4FURO.js} +2 -2
  45. package/dist/{chunk-CAUADFDM.js → chunk-7SOKOEAZ.js} +2 -2
  46. package/dist/{chunk-7Q74DD2W.js → chunk-7V6GNQC2.js} +2 -2
  47. package/dist/{chunk-QXHWOUS6.js → chunk-AALJHIKH.js} +3 -3
  48. package/dist/{chunk-ATPY63F5.js → chunk-AJ7JHHRY.js} +2 -2
  49. package/dist/{chunk-B7GZL7PR.js → chunk-ARD2TEY2.js} +4 -4
  50. package/dist/{chunk-QSVWIKNY.js → chunk-BDFSVUUZ.js} +9 -7
  51. package/dist/chunk-BDFSVUUZ.js.map +1 -0
  52. package/dist/{chunk-3DADRUGW.js → chunk-BGA7S5EF.js} +3 -3
  53. package/dist/{chunk-RPOG6HLI.js → chunk-CJSTQNE5.js} +2 -2
  54. package/dist/{chunk-VQQZJ6KJ.js → chunk-DYUPSTCV.js} +3 -3
  55. package/dist/{chunk-E5QI6C6C.js → chunk-E3LGAZJC.js} +3 -3
  56. package/dist/{chunk-TAPF7T26.js → chunk-EEA2RM4B.js} +2 -2
  57. package/dist/{chunk-BL7WULM5.js → chunk-FDO7ITP6.js} +2 -2
  58. package/dist/{chunk-K3JGILZC.js → chunk-FGFU6J26.js} +3 -3
  59. package/dist/{chunk-6TIQLG7I.js → chunk-FKHXXL42.js} +2 -2
  60. package/dist/{chunk-QPD7EYGI.js → chunk-G2MS56KM.js} +2 -2
  61. package/dist/{chunk-2I3ETW3G.js → chunk-GH7IKABD.js} +2 -2
  62. package/dist/{chunk-KVTUUU7H.js → chunk-GYCUX3N4.js} +2 -2
  63. package/dist/{chunk-2VNMSEZR.js → chunk-HEJFE3BC.js} +3 -3
  64. package/dist/{chunk-KM4QO4LN.js → chunk-HLQANATZ.js} +2 -2
  65. package/dist/{chunk-AXSQGJSG.js → chunk-J7RQ3RP7.js} +11 -11
  66. package/dist/{chunk-H442UKDV.js → chunk-JITK24KX.js} +7 -7
  67. package/dist/{chunk-EJYUAN5F.js → chunk-K6UXWVQ6.js} +2 -2
  68. package/dist/{chunk-RVODERA5.js → chunk-KJ65WZHB.js} +2 -2
  69. package/dist/{chunk-QGT5KNQT.js → chunk-KOVQZJ27.js} +2 -2
  70. package/dist/{chunk-O6QSBI3U.js → chunk-KZ4BJRGQ.js} +2 -2
  71. package/dist/{chunk-D3FP4JQI.js → chunk-LR6LWX33.js} +4 -4
  72. package/dist/{chunk-NTS2RCQK.js → chunk-NAULI3EG.js} +2 -2
  73. package/dist/{chunk-V5W67PQV.js → chunk-NOKHMWMW.js} +4 -4
  74. package/dist/{chunk-7X6EZ2QB.js → chunk-ODI4K32P.js} +5 -5
  75. package/dist/{chunk-H7USCTPQ.js → chunk-OLD2GKQJ.js} +3 -3
  76. package/dist/{chunk-D7HOJFDS.js → chunk-ONSEODO2.js} +2 -2
  77. package/dist/{chunk-R3YMWUF3.js → chunk-P3IAZQPS.js} +2 -2
  78. package/dist/{chunk-LL6WEMTC.js → chunk-P3OONWJJ.js} +2 -2
  79. package/dist/chunk-P3OONWJJ.js.map +1 -0
  80. package/dist/{chunk-ZG4GNPRE.js → chunk-PBE7NFB5.js} +5 -5
  81. package/dist/{chunk-7KC6LT7U.js → chunk-PSQ347YP.js} +3 -3
  82. package/dist/{chunk-TQODBIMW.js → chunk-QFKNIKUF.js} +2 -2
  83. package/dist/{chunk-RFVX4WE7.js → chunk-QIPRDRGM.js} +1 -1
  84. package/dist/chunk-QIPRDRGM.js.map +1 -0
  85. package/dist/{chunk-C6Y2YHJL.js → chunk-QZMGZBTF.js} +2 -2
  86. package/dist/{chunk-PCGBESAN.js → chunk-SKJM4PKE.js} +2 -2
  87. package/dist/{chunk-T7R42MWB.js → chunk-STSORBX5.js} +2 -2
  88. package/dist/{chunk-XWPYK5T4.js → chunk-T765HQ5U.js} +3 -3
  89. package/dist/{chunk-RFEQ7DQN.js → chunk-TDG5NZAZ.js} +2 -2
  90. package/dist/{chunk-DLPS5YP3.js → chunk-TJV5HGSC.js} +4 -4
  91. package/dist/{chunk-YVXR7CPS.js → chunk-TWYYUMYO.js} +2 -2
  92. package/dist/{chunk-6MDHK6NO.js → chunk-TZ7ZA2LM.js} +2 -2
  93. package/dist/{chunk-ABPOW3SX.js → chunk-UAEJKURK.js} +92 -493
  94. package/dist/chunk-UAEJKURK.js.map +1 -0
  95. package/dist/{chunk-6OHCNTKU.js → chunk-UH2VY2QQ.js} +3 -3
  96. package/dist/{chunk-XQF2KLV5.js → chunk-VHQNJW4Q.js} +2 -2
  97. package/dist/{chunk-K6BS5RB4.js → chunk-WEI6HEUX.js} +11 -6
  98. package/dist/chunk-WEI6HEUX.js.map +1 -0
  99. package/dist/{chunk-3IA2SUWM.js → chunk-WRVKI6ZO.js} +2 -2
  100. package/dist/chunk-XC4PRJWM.js +593 -0
  101. package/dist/chunk-XC4PRJWM.js.map +1 -0
  102. package/dist/{chunk-R5S57GRK.js → chunk-XSRZM6CQ.js} +38 -13
  103. package/dist/chunk-XSRZM6CQ.js.map +1 -0
  104. package/dist/{chunk-OA7YDB6A.js → chunk-XZLCAL5O.js} +2 -2
  105. package/dist/{chunk-CIAQK2OU.js → chunk-XZMQLON4.js} +430 -292
  106. package/dist/chunk-XZMQLON4.js.map +1 -0
  107. package/dist/{chunk-HL53XYHC.js → chunk-YCJJODER.js} +5 -5
  108. package/dist/chunk-YCJJODER.js.map +1 -0
  109. package/dist/{chunk-GGQ3CJVH.js → chunk-YTT6XJNX.js} +4 -4
  110. package/dist/{chunk-A32EBVCZ.js → chunk-Z6EFSXU3.js} +2 -2
  111. package/dist/{chunk-GRX5BE73.js → chunk-ZNCCX7P6.js} +2 -2
  112. package/dist/cli.js +76 -75
  113. package/dist/coding/export-okf-codegraph.js +15 -15
  114. package/dist/compounding/engine.js +17 -17
  115. package/dist/config.d.ts.map +1 -1
  116. package/dist/config.js +16 -16
  117. package/dist/connectors/codex-materialize-runner.js +16 -16
  118. package/dist/connectors/index.js +16 -16
  119. package/dist/consolidation-provenance-check.js +5 -5
  120. package/dist/consolidation-undo.js +4 -4
  121. package/dist/contradiction/index.js +3 -3
  122. package/dist/convergence-refresh.js +18 -18
  123. package/dist/corpus-watermark.js +18 -18
  124. package/dist/cue-anchors.js +5 -5
  125. package/dist/{entity-canonical-id-migration-74IDJFPB.js → entity-canonical-id-migration-46EMEXTB.js} +4 -4
  126. package/dist/entity-retrieval.d.ts.map +1 -1
  127. package/dist/entity-retrieval.js +16 -16
  128. package/dist/explicit-capture.js +76 -75
  129. package/dist/extraction.js +20 -20
  130. package/dist/harmonic-construction.js +6 -6
  131. package/dist/harmonic-graph-version.js +3 -3
  132. package/dist/harmonic-retrieval.d.ts +15 -0
  133. package/dist/harmonic-retrieval.d.ts.map +1 -1
  134. package/dist/harmonic-retrieval.js +21 -19
  135. package/dist/index.js +97 -96
  136. package/dist/lcm/engine.js +2 -2
  137. package/dist/lcm/index.js +5 -5
  138. package/dist/location/index.js +17 -17
  139. package/dist/maintenance/memory-governance.js +16 -16
  140. package/dist/maintenance/rebuild-memory-lifecycle-ledger.js +16 -16
  141. package/dist/maintenance/rebuild-memory-projection-runner.js +18 -18
  142. package/dist/maintenance/rebuild-memory-projection.js +17 -17
  143. package/dist/memory-browse.js +5 -5
  144. package/dist/memory-cache.d.ts +44 -3
  145. package/dist/memory-cache.d.ts.map +1 -1
  146. package/dist/memory-cache.js +9 -1
  147. package/dist/memory-corpus-version.js +2 -2
  148. package/dist/namespaces/migrate.js +17 -17
  149. package/dist/namespaces/search.js +9 -9
  150. package/dist/namespaces/storage.js +16 -16
  151. package/dist/operator-doctor-corpus.js +19 -19
  152. package/dist/operator-toolkit.js +24 -24
  153. package/dist/orchestration/backlog-scheduler.js +77 -76
  154. package/dist/orchestration/backlog-scheduler.js.map +1 -1
  155. package/dist/orchestration/buffer-drain-runner.js +77 -76
  156. package/dist/orchestration/maintenance.js +24 -24
  157. package/dist/orchestration/recall-internal.d.ts.map +1 -1
  158. package/dist/orchestration/turn-ingestion-buffered.d.ts.map +1 -1
  159. package/dist/orchestrator.js +76 -75
  160. package/dist/page-versioning.js +4 -4
  161. package/dist/qmd.js +2 -2
  162. package/dist/recall-explain-renderer.js +3 -3
  163. package/dist/recall-navigate-access.js +2 -2
  164. package/dist/recall-navigate-disclosure.js +2 -2
  165. package/dist/recall-navigate.js +2 -2
  166. package/dist/recall-navigation.js +76 -75
  167. package/dist/recall-state-view-admission.js +5 -5
  168. package/dist/recall-why-service.js +5 -5
  169. package/dist/recall-xray-cli.js +4 -4
  170. package/dist/recall-xray-renderer.js +3 -3
  171. package/dist/recall-xray.js +2 -2
  172. package/dist/{resolution-RWIGFH2W.js → resolution-4QPPLDEN.js} +4 -4
  173. package/dist/resolution-4QPPLDEN.js.map +1 -0
  174. package/dist/resume-bundles.js +17 -17
  175. package/dist/search/factory.js +8 -8
  176. package/dist/search/index.js +13 -13
  177. package/dist/search/lancedb-backend.js +2 -2
  178. package/dist/search/meilisearch-backend.js +2 -2
  179. package/dist/search/orama-backend.js +2 -2
  180. package/dist/semantic-consolidation.js +17 -17
  181. package/dist/semantic-rule-promotion.js +16 -16
  182. package/dist/semantic-rule-verifier.js +16 -16
  183. package/dist/source-agent-qualifier.js +19 -19
  184. package/dist/standup/build.js +16 -16
  185. package/dist/storage/entity-listing.d.ts +20 -0
  186. package/dist/storage/entity-listing.d.ts.map +1 -0
  187. package/dist/storage/entity-store.d.ts +5 -0
  188. package/dist/storage/entity-store.d.ts.map +1 -1
  189. package/dist/storage/hot-cache-validation.d.ts +60 -0
  190. package/dist/storage/hot-cache-validation.d.ts.map +1 -0
  191. package/dist/storage.d.ts +2 -0
  192. package/dist/storage.d.ts.map +1 -1
  193. package/dist/storage.js +15 -15
  194. package/dist/transfer/capsule-import.js +5 -5
  195. package/dist/transfer/export-okf.js +16 -16
  196. package/dist/types.d.ts +2 -0
  197. package/dist/types.d.ts.map +1 -1
  198. package/dist/types.js +1 -1
  199. package/dist/verified-recall.js +16 -16
  200. package/dist/who-knows-cli.js +17 -17
  201. package/dist/who-knows.js +16 -16
  202. package/package.json +12 -2
  203. package/src/admin/admin-surfaces.test.ts +171 -0
  204. package/src/admin/admin-surfaces.ts +215 -2
  205. package/src/buffer-large-session-defer.test.ts +81 -0
  206. package/src/buffer-persistence.ts +8 -1
  207. package/src/buffer.ts +9 -4
  208. package/src/config.test.ts +9 -0
  209. package/src/config.ts +3 -6
  210. package/src/entity-recall-hot-cache.test.ts +116 -0
  211. package/src/entity-retrieval.ts +22 -4
  212. package/src/harmonic-graph-cache.test.ts +28 -9
  213. package/src/harmonic-retrieval.ts +20 -4
  214. package/src/memory-cache-hot.test.ts +47 -0
  215. package/src/memory-cache.ts +96 -17
  216. package/src/observe-flush-force-keys.test.ts +130 -0
  217. package/src/orchestration/recall-internal.ts +1 -0
  218. package/src/orchestration/turn-ingestion-buffered.test.ts +6 -2
  219. package/src/orchestration/turn-ingestion-buffered.ts +5 -1
  220. package/src/storage/entity-listing.ts +73 -0
  221. package/src/storage/entity-store.ts +25 -26
  222. package/src/storage/hot-cache-validation.ts +149 -0
  223. package/src/storage-contract/cache-coherence.test.ts +42 -5
  224. package/src/storage-hot-cache-stat-validate.test.ts +112 -0
  225. package/src/storage.ts +58 -44
  226. package/src/types.ts +2 -0
  227. package/dist/chunk-65DWWJKI.js.map +0 -1
  228. package/dist/chunk-ABPOW3SX.js.map +0 -1
  229. package/dist/chunk-CIAQK2OU.js.map +0 -1
  230. package/dist/chunk-HL53XYHC.js.map +0 -1
  231. package/dist/chunk-K6BS5RB4.js.map +0 -1
  232. package/dist/chunk-LL6WEMTC.js.map +0 -1
  233. package/dist/chunk-QSVWIKNY.js.map +0 -1
  234. package/dist/chunk-R5S57GRK.js.map +0 -1
  235. package/dist/chunk-RFVX4WE7.js.map +0 -1
  236. /package/dist/{entity-canonical-id-migration-74IDJFPB.js.map → admin/admin-surfaces.js.map} +0 -0
  237. /package/dist/{capsule-merge-BADOICNP.js.map → capsule-merge-3FARYIHP.js.map} +0 -0
  238. /package/dist/{chunk-IMSLPQJB.js.map → chunk-2QW5HPKU.js.map} +0 -0
  239. /package/dist/{chunk-KNYUEYB6.js.map → chunk-2YJ2ST23.js.map} +0 -0
  240. /package/dist/{chunk-X3ERYOLO.js.map → chunk-3BICT225.js.map} +0 -0
  241. /package/dist/{chunk-UWKHLWUE.js.map → chunk-3RZ4GDOH.js.map} +0 -0
  242. /package/dist/{chunk-ODIBCZLG.js.map → chunk-3YID7KZ6.js.map} +0 -0
  243. /package/dist/{chunk-56BNHKZM.js.map → chunk-4EAVEDLG.js.map} +0 -0
  244. /package/dist/{chunk-TLRIRISJ.js.map → chunk-4LCA2GEX.js.map} +0 -0
  245. /package/dist/{chunk-4N33L4HY.js.map → chunk-5GIYIYJI.js.map} +0 -0
  246. /package/dist/{chunk-ZDLVHGIC.js.map → chunk-7EP4FURO.js.map} +0 -0
  247. /package/dist/{chunk-CAUADFDM.js.map → chunk-7SOKOEAZ.js.map} +0 -0
  248. /package/dist/{chunk-7Q74DD2W.js.map → chunk-7V6GNQC2.js.map} +0 -0
  249. /package/dist/{chunk-QXHWOUS6.js.map → chunk-AALJHIKH.js.map} +0 -0
  250. /package/dist/{chunk-ATPY63F5.js.map → chunk-AJ7JHHRY.js.map} +0 -0
  251. /package/dist/{chunk-B7GZL7PR.js.map → chunk-ARD2TEY2.js.map} +0 -0
  252. /package/dist/{chunk-3DADRUGW.js.map → chunk-BGA7S5EF.js.map} +0 -0
  253. /package/dist/{chunk-RPOG6HLI.js.map → chunk-CJSTQNE5.js.map} +0 -0
  254. /package/dist/{chunk-VQQZJ6KJ.js.map → chunk-DYUPSTCV.js.map} +0 -0
  255. /package/dist/{chunk-E5QI6C6C.js.map → chunk-E3LGAZJC.js.map} +0 -0
  256. /package/dist/{chunk-TAPF7T26.js.map → chunk-EEA2RM4B.js.map} +0 -0
  257. /package/dist/{chunk-BL7WULM5.js.map → chunk-FDO7ITP6.js.map} +0 -0
  258. /package/dist/{chunk-K3JGILZC.js.map → chunk-FGFU6J26.js.map} +0 -0
  259. /package/dist/{chunk-6TIQLG7I.js.map → chunk-FKHXXL42.js.map} +0 -0
  260. /package/dist/{chunk-QPD7EYGI.js.map → chunk-G2MS56KM.js.map} +0 -0
  261. /package/dist/{chunk-2I3ETW3G.js.map → chunk-GH7IKABD.js.map} +0 -0
  262. /package/dist/{chunk-KVTUUU7H.js.map → chunk-GYCUX3N4.js.map} +0 -0
  263. /package/dist/{chunk-2VNMSEZR.js.map → chunk-HEJFE3BC.js.map} +0 -0
  264. /package/dist/{chunk-KM4QO4LN.js.map → chunk-HLQANATZ.js.map} +0 -0
  265. /package/dist/{chunk-AXSQGJSG.js.map → chunk-J7RQ3RP7.js.map} +0 -0
  266. /package/dist/{chunk-H442UKDV.js.map → chunk-JITK24KX.js.map} +0 -0
  267. /package/dist/{chunk-EJYUAN5F.js.map → chunk-K6UXWVQ6.js.map} +0 -0
  268. /package/dist/{chunk-RVODERA5.js.map → chunk-KJ65WZHB.js.map} +0 -0
  269. /package/dist/{chunk-QGT5KNQT.js.map → chunk-KOVQZJ27.js.map} +0 -0
  270. /package/dist/{chunk-O6QSBI3U.js.map → chunk-KZ4BJRGQ.js.map} +0 -0
  271. /package/dist/{chunk-D3FP4JQI.js.map → chunk-LR6LWX33.js.map} +0 -0
  272. /package/dist/{chunk-NTS2RCQK.js.map → chunk-NAULI3EG.js.map} +0 -0
  273. /package/dist/{chunk-V5W67PQV.js.map → chunk-NOKHMWMW.js.map} +0 -0
  274. /package/dist/{chunk-7X6EZ2QB.js.map → chunk-ODI4K32P.js.map} +0 -0
  275. /package/dist/{chunk-H7USCTPQ.js.map → chunk-OLD2GKQJ.js.map} +0 -0
  276. /package/dist/{chunk-D7HOJFDS.js.map → chunk-ONSEODO2.js.map} +0 -0
  277. /package/dist/{chunk-R3YMWUF3.js.map → chunk-P3IAZQPS.js.map} +0 -0
  278. /package/dist/{chunk-ZG4GNPRE.js.map → chunk-PBE7NFB5.js.map} +0 -0
  279. /package/dist/{chunk-7KC6LT7U.js.map → chunk-PSQ347YP.js.map} +0 -0
  280. /package/dist/{chunk-TQODBIMW.js.map → chunk-QFKNIKUF.js.map} +0 -0
  281. /package/dist/{chunk-C6Y2YHJL.js.map → chunk-QZMGZBTF.js.map} +0 -0
  282. /package/dist/{chunk-PCGBESAN.js.map → chunk-SKJM4PKE.js.map} +0 -0
  283. /package/dist/{chunk-T7R42MWB.js.map → chunk-STSORBX5.js.map} +0 -0
  284. /package/dist/{chunk-XWPYK5T4.js.map → chunk-T765HQ5U.js.map} +0 -0
  285. /package/dist/{chunk-RFEQ7DQN.js.map → chunk-TDG5NZAZ.js.map} +0 -0
  286. /package/dist/{chunk-DLPS5YP3.js.map → chunk-TJV5HGSC.js.map} +0 -0
  287. /package/dist/{chunk-YVXR7CPS.js.map → chunk-TWYYUMYO.js.map} +0 -0
  288. /package/dist/{chunk-6MDHK6NO.js.map → chunk-TZ7ZA2LM.js.map} +0 -0
  289. /package/dist/{chunk-6OHCNTKU.js.map → chunk-UH2VY2QQ.js.map} +0 -0
  290. /package/dist/{chunk-XQF2KLV5.js.map → chunk-VHQNJW4Q.js.map} +0 -0
  291. /package/dist/{chunk-3IA2SUWM.js.map → chunk-WRVKI6ZO.js.map} +0 -0
  292. /package/dist/{chunk-OA7YDB6A.js.map → chunk-XZLCAL5O.js.map} +0 -0
  293. /package/dist/{chunk-GGQ3CJVH.js.map → chunk-YTT6XJNX.js.map} +0 -0
  294. /package/dist/{chunk-A32EBVCZ.js.map → chunk-Z6EFSXU3.js.map} +0 -0
  295. /package/dist/{chunk-GRX5BE73.js.map → chunk-ZNCCX7P6.js.map} +0 -0
  296. /package/dist/{resolution-RWIGFH2W.js.map → entity-canonical-id-migration-46EMEXTB.js.map} +0 -0
@@ -1504,6 +1504,7 @@ export class RecallInternalCoordinator {
1504
1504
  anchorsEnabled: resolveConsolidationCapabilities(this.deps.config).abstractionAnchors,
1505
1505
  temporalExpiredInInjection: this.deps.config.temporalExpiredInInjection,
1506
1506
  abortSignal: harmonicRetrievalAbort.signal, useGraphCache: true,
1507
+ graphCacheTtlMs: this.deps.config.harmonicGraphCacheTtlMs,
1507
1508
  }),
1508
1509
  ),
1509
1510
  );
@@ -22,7 +22,7 @@ interface StubBuffer {
22
22
  batches: readonly { bufferKey: string; turns: readonly BufferTurn[] }[],
23
23
  admissionKey: string,
24
24
  ): Promise<OutcomeRow[] | null | "duplicate">;
25
- flushPendingSave(opts?: { throwOnFailure?: boolean }): Promise<void>;
25
+ flushPendingSave(opts?: { throwOnFailure?: boolean; allowDeferral?: boolean; forceKeys?: ReadonlySet<string> }): Promise<void>;
26
26
  }
27
27
 
28
28
  function turn(content: string): BufferTurn {
@@ -174,7 +174,11 @@ test("buffered ingest: accepted batches flush the pending save and queue non-buf
174
174
 
175
175
  await ingestReplayBatchBuffered(deps, new Map([["s1", [turn("a")]]]), { writeNamespaceOverride: "ns-work" });
176
176
 
177
- assert.deepEqual(calls.flushArgs, [{ throwOnFailure: true }]);
177
+ assert.deepEqual(calls.flushArgs, [{
178
+ throwOnFailure: true,
179
+ allowDeferral: true,
180
+ forceKeys: new Set(["s1"]),
181
+ }]);
178
182
  assert.equal(queued.length, 1);
179
183
  assert.deepEqual(queued[0]?.turns, [extractionTurn]);
180
184
  assert.equal(queued[0]?.opts.bufferKey, "s1");
@@ -49,7 +49,11 @@ export async function ingestReplayBatchBuffered(
49
49
  if (outcomes === "duplicate") return;
50
50
  if (outcomes === null) throw replayRefusal(refusal, batches);
51
51
 
52
- await deps.buffer.flushPendingSave({ throwOnFailure: true });
52
+ // COS-825 subset barrier: the sessions THIS observe admitted must be durable
53
+ // before the ack, but other dirty sessions keep their #3389 steady-state
54
+ // deferral (armed retry lands the tail) instead of being forced per observe.
55
+ const forceKeys = new Set(outcomes.map(({ bufferKey }) => bufferKey));
56
+ await deps.buffer.flushPendingSave({ throwOnFailure: true, allowDeferral: true, forceKeys });
53
57
 
54
58
  if (options.archiveLcm !== false && deps.lcmEngine?.enabled) {
55
59
  for (const [bufferKey, sessionTurns] of bySession) {
@@ -0,0 +1,73 @@
1
+ import { readdir, stat } from "node:fs/promises";
2
+ import { checkCorpusReadAbort, type CorpusReadOptions } from "../corpus-read-cancellation.js";
3
+ import path from "node:path";
4
+ import { isTrustedEntitiesRoot } from "./entity-migration-completion-cache.js";
5
+ import { log } from "../logger.js";
6
+ import {
7
+ warnIgnoredMacOsReplicationJunk,
8
+ withoutMacOsReplicationJunk,
9
+ } from "../utils/macos-replication-junk.js";
10
+
11
+ /** The slice of the entity store the listing scan needs. */
12
+ export interface EntityListingDeps {
13
+ baseDir: string;
14
+ entitiesDir: string;
15
+ }
16
+
17
+ /**
18
+ * COS-825: one readdir + stat pass over the entities dir. `warn` is true on
19
+ * the rebuild path (junk entries log once per rebuild); validation passes
20
+ * quietly so cache reads never spam. Returns null when the root is untrusted
21
+ * (#3207: resolve empty) or the directory cannot be listed. Honors
22
+ * cancellation at each batch boundary (#2291 class).
23
+ */
24
+ export async function scanEntitiesDir(
25
+ deps: EntityListingDeps,
26
+ warn: boolean,
27
+ options?: CorpusReadOptions,
28
+ ): Promise<{ names: string[]; listing: Map<string, string> } | null> {
29
+ if (!(await isTrustedEntitiesRoot(deps.baseDir, deps.entitiesDir))) return null;
30
+ let listed: string[];
31
+ try {
32
+ listed = await readdir(deps.entitiesDir);
33
+ } catch {
34
+ return null;
35
+ }
36
+ const { kept: names, ignored } = withoutMacOsReplicationJunk(listed, (name) => name);
37
+ if (warn) {
38
+ warnIgnoredMacOsReplicationJunk(deps.entitiesDir, ignored, (message) => {
39
+ log.warn(`entity load ${message}`);
40
+ });
41
+ }
42
+ const listing = new Map<string, string>();
43
+ const BATCH = 200;
44
+ for (let i = 0; i < names.length; i += BATCH) {
45
+ checkCorpusReadAbort(options);
46
+ await Promise.all(names.slice(i, i + BATCH).map(async (name) => {
47
+ try {
48
+ const st = await stat(path.join(deps.entitiesDir, name));
49
+ listing.set(name, `${st.mtimeMs}:${st.size}`);
50
+ } catch {
51
+ // A racing rename/delete: mark unreadable so any mismatch against a
52
+ // stored snapshot forces a rebuild — never a false validation pass.
53
+ listing.set(name, "missing");
54
+ }
55
+ }));
56
+ }
57
+ return { names, listing };
58
+ }
59
+
60
+ /** COS-825: does a fresh listing scan match the cached snapshot exactly? */
61
+ export async function entitiesListingUnchanged(
62
+ deps: EntityListingDeps,
63
+ listing: ReadonlyMap<string, string>,
64
+ options?: CorpusReadOptions,
65
+ ): Promise<boolean> {
66
+ const scanned = await scanEntitiesDir(deps, /* warn */ false, options);
67
+ if (!scanned || scanned.listing.size !== listing.size) return false;
68
+ checkCorpusReadAbort(options);
69
+ for (const [name, token] of listing) {
70
+ if (scanned.listing.get(name) !== token) return false;
71
+ }
72
+ return true;
73
+ }
@@ -10,24 +10,20 @@
10
10
  * - fragmented-entity merge (consolidation)
11
11
  */
12
12
 
13
- import { lstat, readdir, unlink } from "node:fs/promises";
13
+ import { lstat, unlink } from "node:fs/promises";
14
14
  import path from "node:path";
15
15
  import { checkCorpusReadAbort, type CorpusReadOptions } from "../corpus-read-cancellation.js";
16
16
  import { normalizeEntityStructuredSection, sortStructuredSectionsBySchema } from "../entity-schema.js";
17
17
  import { withEntityCanonicalMutationLock } from "./entity-canonical-id-lock.js";
18
18
  import { assertSafeEntityId } from "./entity-id-safety.js";
19
+ import { entitiesListingUnchanged, scanEntitiesDir } from "./entity-listing.js";
19
20
  import {
20
21
  EntityMigrationCompletionCache,
21
- isTrustedEntitiesRoot,
22
22
  readEntityFileResolvingRename,
23
23
  } from "./entity-migration-completion-cache.js";
24
24
  import { isMalformedEntityRecord } from "../utils/malformed-entity-record.js";
25
25
  import { log } from "../logger.js";
26
- import {
27
- warnIgnoredMacOsReplicationJunk,
28
- withoutMacOsReplicationJunk,
29
- } from "../utils/macos-replication-junk.js";
30
- import { getCachedEntities, setCachedEntities } from "../memory-cache.js";
26
+ import { entityCacheStats, getCachedEntities, setCachedEntities } from "../memory-cache.js";
31
27
  import type { VersionTrigger } from "../page-versioning.js";
32
28
  import { SecureStoreDecryptError, SecureStoreLockedError } from "../secure-store/secure-fs.js";
33
29
  import type {
@@ -431,13 +427,8 @@ export class EntityStore {
431
427
  * A symlinked entities root yields an empty list and is not read.
432
428
  */
433
429
  private async readEntityDirectoryNames(): Promise<string[]> {
434
- if (!(await isTrustedEntitiesRoot(this.deps.baseDir, this.deps.entitiesDir))) return [];
435
- const entries = await readdir(this.deps.entitiesDir);
436
- const { kept, ignored } = withoutMacOsReplicationJunk(entries, (name) => name);
437
- warnIgnoredMacOsReplicationJunk(this.deps.entitiesDir, ignored, (message) => {
438
- log.warn(`entity load ${message}`);
439
- });
440
- return kept;
430
+ const scanned = await scanEntitiesDir(this.deps, /* warn */ true);
431
+ return scanned?.names ?? [];
441
432
  }
442
433
 
443
434
  /**
@@ -675,31 +666,39 @@ export class EntityStore {
675
666
  /**
676
667
  * Read all entity files and return lightweight EntityFile objects.
677
668
  * Parsing is fast (~50-100ms for ~1,800 files) since entity files are small.
669
+ *
670
+ * COS-825: the parsed cache is validated by an entities-dir listing snapshot
671
+ * (name, mtime, size) plus the entity-mutation version — NOT the memory-status
672
+ * version, which churns with unrelated memory lifecycle writes and used to
673
+ * force a full re-read on every recall under observe traffic.
678
674
  */
679
675
  async readAllEntityFiles(options?: CorpusReadOptions): Promise<EntityFile[]> {
680
676
  checkCorpusReadAbort(options);
681
- const currentVersion = this.deps.getMemoryStatusVersion();
682
677
  const cacheKey = [
683
678
  this.deps.getEntityCacheSecureStoreKey(),
684
679
  buildEntitySchemaCacheKey(this.deps.entitySchemas),
685
680
  this.deps.getEntityMutationVersion(),
686
681
  ].join("\u0000");
687
- const cached = getCachedEntities(this.deps.baseDir, currentVersion, cacheKey);
688
- if (cached) return cached;
682
+ const cached = getCachedEntities(this.deps.baseDir, cacheKey);
683
+ if (cached && (await entitiesListingUnchanged(this.deps, cached.listing, options))) {
684
+ entityCacheStats.hits++;
685
+ return cached.entities;
686
+ }
687
+ entityCacheStats.rebuilds++;
689
688
 
690
689
  try {
690
+ const scanned = await scanEntitiesDir(this.deps, /* warn */ true, options);
691
+ checkCorpusReadAbort(options);
691
692
  // A symlinked/replaced entities root has no readable entries (merged
692
693
  // #3207 semantics): resolve empty rather than following it. Within a
693
694
  // trusted root, readdir directly so planted entries reach the secure
694
695
  // read instead of being swallowed by the listing guards.
695
- if (!(await isTrustedEntitiesRoot(this.deps.baseDir, this.deps.entitiesDir))) return [];
696
- const listed = await readdir(this.deps.entitiesDir);
697
- const { kept: entries, ignored } = withoutMacOsReplicationJunk(listed, (name) => name);
698
- warnIgnoredMacOsReplicationJunk(this.deps.entitiesDir, ignored, (message) => {
699
- log.warn(`entity load ${message}`);
700
- });
701
- const mdFiles = entries.filter((e) => e.endsWith(".md"));
702
- if (mdFiles.length === 0) return [];
696
+ if (!scanned) return [];
697
+ const mdFiles = scanned.names.filter((e) => e.endsWith(".md"));
698
+ if (mdFiles.length === 0) {
699
+ setCachedEntities(this.deps.baseDir, [], cacheKey, scanned.listing);
700
+ return [];
701
+ }
703
702
 
704
703
  const historicalIds = this.deps.currentHistoricalIds();
705
704
  const seen = new Map<string, Set<string>>();
@@ -756,7 +755,7 @@ export class EntityStore {
756
755
  // A signal that fired during the last batch's await would otherwise publish
757
756
  // and return as if uncancelled (issue #2307 review).
758
757
  checkCorpusReadAbort(options);
759
- setCachedEntities(this.deps.baseDir, entities, currentVersion, cacheKey);
758
+ setCachedEntities(this.deps.baseDir, entities, cacheKey, scanned.listing);
760
759
  return entities;
761
760
  } catch (err) {
762
761
  if (err instanceof SecureStoreLockedError || !isErrnoCode(err, "ENOENT")) throw err;
@@ -0,0 +1,149 @@
1
+ import { stat } from "node:fs/promises";
2
+ import {
3
+ getCachedMemories,
4
+ getHotCacheEntry,
5
+ hotCacheReadStats,
6
+ promoteHotCacheVersion,
7
+ setCachedMemories,
8
+ type HotCacheStatEntry,
9
+ type HotCacheStatsSnapshot,
10
+ } from "../memory-cache.js";
11
+ import type { MemoryFile } from "../types.js";
12
+
13
+ /**
14
+ * The slice of StorageManager the hot-cache read path needs. Structural, so
15
+ * test doubles and Object.create prototypes keep working (#1526 playbook).
16
+ */
17
+ export interface HotCacheHost {
18
+ /** Public alias of the storage root. */
19
+ dir: string;
20
+ isHotCacheEnabled(): boolean;
21
+ hotCacheKeyId(): string;
22
+ hotCacheTtlMs(): number;
23
+ getMemoryCorpusVersion(): number;
24
+ collectActiveMemoryPaths(options?: { abortSignal?: AbortSignal }): Promise<string[]>;
25
+ }
26
+
27
+ /**
28
+ * COS-825: per-file stat snapshot for the hot-memories cache. The snapshot is
29
+ * captured by the scan itself (stat before and after each file's read), so a
30
+ * peer write that straddled a read omits that file and validation later
31
+ * misses — a snapshot can only vouch bytes actually read. Fail closed; an edit that
32
+ * preserves size and mtime is outside what file metadata can observe.
33
+ */
34
+
35
+ /**
36
+ * COS-825: publish a freshly scanned corpus with its scan-collected stat
37
+ * snapshot. Counts one disk scan. The #1902 publish guards (version and key
38
+ * identity unchanged through the scan) live here: the version guard prevents
39
+ * clobbering a newer patched + re-keyed entry, the keyId guard prevents
40
+ * publishing this key's decrypted corpus under a since-changed identity
41
+ * (#1902 Codex Medium), and a cancelled scan never reaches this at all — the
42
+ * checkpoints throw — so a partial corpus is never published.
43
+ */
44
+ export async function publishCorpusAfterScan(
45
+ host: HotCacheHost,
46
+ memories: MemoryFile[],
47
+ version: number,
48
+ keyId: string,
49
+ snapshot?: HotCacheStatsSnapshot,
50
+ ): Promise<void> {
51
+ hotCacheReadStats.fullScans++;
52
+ if (
53
+ !host.isHotCacheEnabled() ||
54
+ host.getMemoryCorpusVersion() !== version ||
55
+ host.hotCacheKeyId() !== keyId
56
+ ) {
57
+ return;
58
+ }
59
+ setCachedMemories(host.dir, memories, version, keyId, host.hotCacheTtlMs(), snapshot);
60
+ }
61
+
62
+ /**
63
+ * COS-825: read one memory file for a snapshot-bearing scan. Stats before and
64
+ * after the read: only a read that no write straddled yields a stat entry for
65
+ * the caller to record — a straddled write or a vanished file yields null, so
66
+ * a snapshot can only vouch bytes actually read. The entry is recorded by the
67
+ * CALLER after parsing succeeds, so malformed files never enter a snapshot.
68
+ */
69
+ export async function readWithStableStat(
70
+ fullPath: string,
71
+ snapshot: HotCacheStatsSnapshot | undefined,
72
+ read: () => Promise<string>,
73
+ ): Promise<{ raw: string; stat: { mtimeMs: number; size: number } } | null> {
74
+ if (!snapshot) return { raw: await read(), stat: { mtimeMs: 0, size: 0 } };
75
+ // One retry when a write straddled the read: the retried read pairs fresh
76
+ // content with a fresh stat, so the file stays in the corpus instead of
77
+ // being dropped from recall until the next full scan. A second straddle
78
+ // skips the file entirely — fail closed (COS-825 review round 4).
79
+ for (let attempt = 0; attempt < 2; attempt++) {
80
+ let before: HotCacheStatEntry;
81
+ try {
82
+ const st = await stat(fullPath);
83
+ before = { mtimeMs: st.mtimeMs, size: st.size };
84
+ } catch {
85
+ return null;
86
+ }
87
+ const raw = await read();
88
+ try {
89
+ const st = await stat(fullPath);
90
+ if (st.mtimeMs === before.mtimeMs && st.size === before.size) {
91
+ return { raw, stat: before };
92
+ }
93
+ } catch {
94
+ // The file vanished after a successful read: skip it entirely so
95
+ // validation misses instead of promoting.
96
+ return null;
97
+ }
98
+ }
99
+ return null;
100
+ }
101
+
102
+ /**
103
+ * COS-825: serve readAllMemories from the hot cache; null means the caller
104
+ * must scan disk. The fast path is the version-keyed hit (#1902). On a
105
+ * version mismatch this process's own writes have usually patched the entry
106
+ * in place, and peer sentinel bumps (other daemons, CLI runs, converge sync)
107
+ * leave the disk unchanged — so the entry is validated against its per-file
108
+ * stat snapshot and promoted instead of re-reading the corpus. Any provable
109
+ * disk change (out-of-band edit, delete, add), or an inability to prove
110
+ * freshness (missing snapshot, unreadable file), returns null.
111
+ */
112
+ export async function serveHotMemoriesValidated(host: HotCacheHost, abortSignal?: AbortSignal): Promise<MemoryFile[] | null> {
113
+ if (!host.isHotCacheEnabled()) return null;
114
+ const keyId = host.hotCacheKeyId();
115
+ const cached = getCachedMemories(host.dir, host.getMemoryCorpusVersion(), keyId, host.hotCacheTtlMs());
116
+ if (cached !== null) return cached;
117
+ const entry = getHotCacheEntry(host.dir, keyId);
118
+ if (!entry) return null;
119
+ // The TTL is the recovery bound for edits that preserve size and mtime: an
120
+ // expired entry is never validated, it forces the full scan that re-arms a
121
+ // fresh snapshot (COS-825 review round 4).
122
+ const ttlMs = host.hotCacheTtlMs();
123
+ if (ttlMs > 0 && Date.now() - entry.loadedAt > ttlMs) return null;
124
+ // A peer write during this walk must not be promoted over: capture the
125
+ // version now and refuse promotion if it moved (the caller's scan path
126
+ // handles the changed corpus instead).
127
+ const versionAtStart = host.getMemoryCorpusVersion();
128
+ let paths: string[];
129
+ try {
130
+ paths = await host.collectActiveMemoryPaths({ abortSignal });
131
+ } catch {
132
+ return null;
133
+ }
134
+ if (paths.length !== entry.memories.size) return null;
135
+ const pathSet = new Set(paths);
136
+ for (const cachedPath of pathSet) {
137
+ const snap = entry.stats.get(cachedPath);
138
+ if (!snap) return null;
139
+ try {
140
+ const st = await stat(cachedPath);
141
+ if (st.mtimeMs !== snap.mtimeMs || st.size !== snap.size) return null;
142
+ } catch {
143
+ return null;
144
+ }
145
+ }
146
+ if (host.getMemoryCorpusVersion() !== versionAtStart) return null;
147
+ return promoteHotCacheVersion(host.dir, versionAtStart, keyId);
148
+ }
149
+
@@ -108,9 +108,12 @@ function installScanSpy(sm: StorageManager): { scans: () => number } {
108
108
  const spy = sm as unknown as ScanSpy;
109
109
  const orig = spy._readAllMemoriesFromDisk.bind(sm);
110
110
  let count = 0;
111
- spy._readAllMemoriesFromDisk = async () => {
111
+ // Argument-transparent: the COS-825 snapshot parameter must reach the real
112
+ // scan or the spy itself would disable snapshot publication.
113
+ spy._readAllMemoriesFromDisk = async (...args: Parameters<StorageManager["_readAllMemoriesFromDisk"]>) => {
112
114
  count += 1;
113
- return orig();
115
+ // @ts-expect-error -- the private method is exposed for observation only.
116
+ return orig(...args);
114
117
  };
115
118
  return { scans: () => count };
116
119
  }
@@ -153,7 +156,7 @@ test("hot cache (#1902): a single-file write patches the cache in place — next
153
156
  }
154
157
  });
155
158
 
156
- test("hot cache (#1902): a peer corpus-version bump forces exactly one rescan (cross-process coherence)", async () => {
159
+ test("hot cache (#1902+COS-825): a peer corpus-version bump with unchanged disk promotes instead of rescanning", async () => {
157
160
  const dir = await mkdtemp(path.join(os.tmpdir(), "remnic-hot-peer-"));
158
161
  try {
159
162
  resetStaticCaches();
@@ -163,10 +166,11 @@ test("hot cache (#1902): a peer corpus-version bump forces exactly one rescan (c
163
166
  await sm.readAllMemories(); // warm
164
167
  const spy = installScanSpy(sm);
165
168
  // Simulate a peer process advancing the on-disk corpus sentinel (its byte
166
- // size IS the version). This instance's warm entry is now stale-versioned.
169
+ // size IS the version) without touching any file. The disk is provably
170
+ // unchanged, so the warm entry is validated and promoted — no re-read.
167
171
  await appendFile(path.join(dir, "state", ".memory-corpus-version.log"), "x");
168
172
  const afterPeer = await sm.readAllMemories();
169
- assert.equal(spy.scans(), 1, "a peer sentinel bump must force exactly one rescan");
173
+ assert.equal(spy.scans(), 0, "an unchanged disk must promote, not rescan");
170
174
  assert.ok(afterPeer.some((m) => m.content === "A"));
171
175
  } finally {
172
176
  resetStaticCaches();
@@ -174,6 +178,39 @@ test("hot cache (#1902): a peer corpus-version bump forces exactly one rescan (c
174
178
  }
175
179
  });
176
180
 
181
+ test("hot cache (#1902+COS-825): a peer write forces exactly one rescan and is served", async () => {
182
+ const dir = await mkdtemp(path.join(os.tmpdir(), "remnic-hot-peer-write-"));
183
+ try {
184
+ resetStaticCaches();
185
+ const sm = new StorageManager(dir);
186
+ await sm.ensureDirectories();
187
+ await sm.writeMemory("fact", "A");
188
+ await sm.readAllMemories(); // warm
189
+ const spy = installScanSpy(sm);
190
+ // A peer process writes a NEW memory file out-of-band (plain fs write, no
191
+ // shared cache to patch) and advances the sentinel, its own write order.
192
+ const dateToken = new Date().toISOString().slice(0, 10);
193
+ const peerDir = path.join(dir, "facts", dateToken);
194
+ await mkdir(peerDir, { recursive: true });
195
+ await writeFile(
196
+ path.join(peerDir, "peerfact1.md"),
197
+ "---\nid: peerfact1\ncategory: fact\ncreated: 2026-12-02T00:00:00.000Z\n---\n\nPEER BODY\n",
198
+ );
199
+ await appendFile(path.join(dir, "state", ".memory-corpus-version.log"), "x");
200
+ const afterPeer = await sm.readAllMemories();
201
+ assert.equal(spy.scans(), 1, "a real peer write must force exactly one rescan");
202
+ assert.ok(afterPeer.some((m) => m.content === "PEER BODY"), "the peer's memory is served after the rescan");
203
+ assert.ok(afterPeer.some((m) => m.content === "A"));
204
+ // The rescan re-arms a valid snapshot: a further unchanged-disk bump promotes.
205
+ await appendFile(path.join(dir, "state", ".memory-corpus-version.log"), "x");
206
+ await sm.readAllMemories();
207
+ assert.equal(spy.scans(), 1, "the re-armed snapshot validates a second peer bump");
208
+ } finally {
209
+ resetStaticCaches();
210
+ await rm(dir, { recursive: true, force: true });
211
+ }
212
+ });
213
+
177
214
  test("hot cache (#1902): a delete rescans and drops the removed memory", async () => {
178
215
  const dir = await mkdtemp(path.join(os.tmpdir(), "remnic-hot-del-"));
179
216
  try {
@@ -0,0 +1,112 @@
1
+ /**
2
+ * COS-825 — the hot-memories cache survives version churn by stat validation.
3
+ *
4
+ * The write path already patches the hot entry in place and re-keys it to the
5
+ * version it produced, so this process's own writes never re-read the corpus.
6
+ * What forced full re-reads was version churn the patch cannot see: peer
7
+ * processes (other daemons, CLI runs, converge sync) append to the same
8
+ * corpus-version sentinel, bulk mutations bump it, and every readAllMemories
9
+ * then re-read the whole store. The read path now validates the mismatched
10
+ * entry against its per-file stat snapshot (mtime + size + path set) and
11
+ * promotes it instead — the disk is provably unchanged, so the promoted entry
12
+ * is exactly what a fresh scan would return. Any real disk change fails
13
+ * validation and forces the scan.
14
+ */
15
+ import assert from "node:assert/strict";
16
+ import { mkdtemp, readFile, rm, unlink, utimes, writeFile } from "node:fs/promises";
17
+ import { tmpdir } from "node:os";
18
+ import path from "node:path";
19
+ import test from "node:test";
20
+
21
+ import { clearMemoryCache, hotCacheReadStats } from "./memory-cache.js";
22
+ import { StorageManager } from "./storage.js";
23
+ import { bumpMemoryCorpusVersionForDir } from "./memory-corpus-version.js";
24
+
25
+ async function withDir(run: (memoryDir: string, storage: StorageManager) => Promise<void>) {
26
+ const memoryDir = await mkdtemp(path.join(tmpdir(), "remnic-hot-stat-"));
27
+ // The read counters are process-global: reset them so assertions measure
28
+ // only this test's reads.
29
+ clearMemoryCache();
30
+ try {
31
+ const storage = new StorageManager(memoryDir);
32
+ await storage.ensureDirectories();
33
+ await run(memoryDir, storage);
34
+ } finally {
35
+ clearMemoryCache();
36
+ await rm(memoryDir, { recursive: true, force: true });
37
+ }
38
+ }
39
+
40
+ test("a peer process version bump promotes the unchanged entry instead of re-reading (COS-825)", async () => {
41
+ await withDir(async (_memoryDir, storage) => {
42
+ await storage.writeMemory("fact", "alpha stat fact", { source: "test" });
43
+ await storage.writeMemory("fact", "bravo stat fact", { source: "test" });
44
+ await storage.readAllMemories();
45
+ const scansAfterFirst = hotCacheReadStats.fullScans;
46
+ assert.equal(scansAfterFirst, 1, "first read is a full scan");
47
+
48
+ // A peer process bump (shared sentinel append, no local file change):
49
+ // the disk is unchanged, so stat validation must promote the entry.
50
+ bumpMemoryCorpusVersionForDir(storage.dir);
51
+ const memories = await storage.readAllMemories();
52
+ assert.equal(hotCacheReadStats.fullScans, scansAfterFirst, "no full scan for an unchanged disk");
53
+ assert.equal(hotCacheReadStats.validatedHits, 1, "the entry was validated and promoted");
54
+ assert.equal(memories.length, 2);
55
+ });
56
+ });
57
+
58
+ test("a write patch drops the stat snapshot, so peer churn costs a full scan (COS-825 review)", async () => {
59
+ await withDir(async (_memoryDir, storage) => {
60
+ await storage.writeMemory("fact", "alpha patch fact", { source: "test" });
61
+ await storage.readAllMemories();
62
+ const scansAfterFirst = hotCacheReadStats.fullScans;
63
+ await storage.writeMemory("fact", "charlie patch fact", { source: "test" });
64
+ // Own writes patch + re-key the entry: the fast path serves without a scan.
65
+ let memories = await storage.readAllMemories();
66
+ assert.equal(hotCacheReadStats.fullScans, scansAfterFirst, "a patched write needs no scan");
67
+ assert.ok(memories.some((memory) => memory.content.includes("charlie patch fact")), "patched content is fresh");
68
+ // The patch invalidated the snapshot (a peer may have rewritten the same
69
+ // path between content and stat), so the later peer bump must re-read:
70
+ // promoting a snapshot the write path cannot vouch for would be a false pass.
71
+ bumpMemoryCorpusVersionForDir(storage.dir);
72
+ memories = await storage.readAllMemories();
73
+ assert.equal(hotCacheReadStats.fullScans, scansAfterFirst + 1, "peer churn after a patch re-reads (fail closed)");
74
+ assert.equal(hotCacheReadStats.validatedHits, 0);
75
+ assert.equal(memories.length, 2);
76
+ assert.ok(memories.some((memory) => memory.content.includes("charlie patch fact")), "the scan serves fresh content");
77
+ });
78
+ });
79
+
80
+ test("an out-of-band delete fails stat validation and forces a full scan (COS-825)", async () => {
81
+ await withDir(async (_memoryDir, storage) => {
82
+ const a = await storage.writeMemory("fact", "alpha delete fact", { source: "test" });
83
+ await storage.writeMemory("fact", "bravo delete fact", { source: "test" });
84
+ await storage.readAllMemories();
85
+ const scansAfterFirst = hotCacheReadStats.fullScans;
86
+
87
+ const memoryPath = (await storage.getMemoryById(a.id))!.path;
88
+ await unlink(memoryPath);
89
+ bumpMemoryCorpusVersionForDir(storage.dir);
90
+ const memories = await storage.readAllMemories();
91
+ assert.equal(hotCacheReadStats.fullScans, scansAfterFirst + 1, "a real disk change forces the scan");
92
+ assert.equal(hotCacheReadStats.validatedHits, 0, "no validated hit when a file vanished");
93
+ assert.ok(!memories.some((memory) => memory.content.includes("alpha delete fact")));
94
+ });
95
+ });
96
+
97
+ test("an out-of-band edit fails stat validation and the new content is served (COS-825)", async () => {
98
+ await withDir(async (_memoryDir, storage) => {
99
+ const a = await storage.writeMemory("fact", "alpha edit fact", { source: "test" });
100
+ await storage.readAllMemories();
101
+ const scansAfterFirst = hotCacheReadStats.fullScans;
102
+
103
+ const memoryPath = (await storage.getMemoryById(a.id))!.path;
104
+ // Preserve the frontmatter: edit the raw file text like an out-of-band writer.
105
+ await writeFile(memoryPath, (await readFile(memoryPath, "utf8")).replace("alpha", "OMEGA"));
106
+ await utimes(memoryPath, new Date(), new Date(Date.now() + 5_000));
107
+ bumpMemoryCorpusVersionForDir(storage.dir);
108
+ const memories = await storage.readAllMemories();
109
+ assert.equal(hotCacheReadStats.fullScans, scansAfterFirst + 1, "the edit forces the scan");
110
+ assert.ok(memories.some((memory) => memory.content.includes("OMEGA")), "new content is visible");
111
+ });
112
+ });