@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.
- package/dist/abstraction-nodes.js +4 -4
- package/dist/access-admin-ops-surface.js +76 -75
- package/dist/access-cli.js +76 -75
- package/dist/access-cli.js.map +1 -1
- package/dist/access-extraction-force-flush-preempt.js +76 -75
- package/dist/access-extraction-force-flush.js +76 -75
- package/dist/access-http-briefing.js +76 -75
- package/dist/access-http-query.js +76 -75
- package/dist/access-http.js +76 -75
- package/dist/access-identity-continuity-surface.js +76 -75
- package/dist/access-lcm-surface.js +76 -75
- package/dist/access-mcp.js +76 -75
- package/dist/access-observe-write-surface.js +76 -75
- package/dist/access-operations-batch.js +76 -75
- package/dist/access-operations.js +76 -75
- package/dist/access-recall-concurrency.js +76 -75
- package/dist/access-recall-diagnostics.js +2 -2
- package/dist/access-recall-response.js +76 -75
- package/dist/access-recall-surface.js +76 -75
- package/dist/access-service.js +76 -75
- package/dist/active-recall.js +16 -16
- package/dist/admin/admin-surfaces.d.ts +11 -0
- package/dist/admin/admin-surfaces.d.ts.map +1 -1
- package/dist/admin/admin-surfaces.js +43 -0
- package/dist/briefing.js +16 -16
- package/dist/buffer-persistence.d.ts +7 -0
- package/dist/buffer-persistence.d.ts.map +1 -1
- package/dist/buffer-persistence.js +1 -1
- package/dist/buffer.d.ts +2 -0
- package/dist/buffer.d.ts.map +1 -1
- package/dist/buffer.js +6 -6
- package/dist/{capsule-merge-BADOICNP.js → capsule-merge-3FARYIHP.js} +5 -5
- package/dist/causal-consolidation.js +17 -17
- package/dist/{chunk-IMSLPQJB.js → chunk-2QW5HPKU.js} +2 -2
- package/dist/{chunk-KNYUEYB6.js → chunk-2YJ2ST23.js} +2 -2
- package/dist/{chunk-X3ERYOLO.js → chunk-3BICT225.js} +2 -2
- package/dist/{chunk-UWKHLWUE.js → chunk-3RZ4GDOH.js} +2 -2
- package/dist/{chunk-ODIBCZLG.js → chunk-3YID7KZ6.js} +2 -2
- package/dist/{chunk-56BNHKZM.js → chunk-4EAVEDLG.js} +9 -9
- package/dist/{chunk-TLRIRISJ.js → chunk-4LCA2GEX.js} +2 -2
- package/dist/{chunk-4N33L4HY.js → chunk-5GIYIYJI.js} +2 -2
- package/dist/{chunk-65DWWJKI.js → chunk-75K6DRPN.js} +12 -9
- package/dist/chunk-75K6DRPN.js.map +1 -0
- package/dist/{chunk-ZDLVHGIC.js → chunk-7EP4FURO.js} +2 -2
- package/dist/{chunk-CAUADFDM.js → chunk-7SOKOEAZ.js} +2 -2
- package/dist/{chunk-7Q74DD2W.js → chunk-7V6GNQC2.js} +2 -2
- package/dist/{chunk-QXHWOUS6.js → chunk-AALJHIKH.js} +3 -3
- package/dist/{chunk-ATPY63F5.js → chunk-AJ7JHHRY.js} +2 -2
- package/dist/{chunk-B7GZL7PR.js → chunk-ARD2TEY2.js} +4 -4
- package/dist/{chunk-QSVWIKNY.js → chunk-BDFSVUUZ.js} +9 -7
- package/dist/chunk-BDFSVUUZ.js.map +1 -0
- package/dist/{chunk-3DADRUGW.js → chunk-BGA7S5EF.js} +3 -3
- package/dist/{chunk-RPOG6HLI.js → chunk-CJSTQNE5.js} +2 -2
- package/dist/{chunk-VQQZJ6KJ.js → chunk-DYUPSTCV.js} +3 -3
- package/dist/{chunk-E5QI6C6C.js → chunk-E3LGAZJC.js} +3 -3
- package/dist/{chunk-TAPF7T26.js → chunk-EEA2RM4B.js} +2 -2
- package/dist/{chunk-BL7WULM5.js → chunk-FDO7ITP6.js} +2 -2
- package/dist/{chunk-K3JGILZC.js → chunk-FGFU6J26.js} +3 -3
- package/dist/{chunk-6TIQLG7I.js → chunk-FKHXXL42.js} +2 -2
- package/dist/{chunk-QPD7EYGI.js → chunk-G2MS56KM.js} +2 -2
- package/dist/{chunk-2I3ETW3G.js → chunk-GH7IKABD.js} +2 -2
- package/dist/{chunk-KVTUUU7H.js → chunk-GYCUX3N4.js} +2 -2
- package/dist/{chunk-2VNMSEZR.js → chunk-HEJFE3BC.js} +3 -3
- package/dist/{chunk-KM4QO4LN.js → chunk-HLQANATZ.js} +2 -2
- package/dist/{chunk-AXSQGJSG.js → chunk-J7RQ3RP7.js} +11 -11
- package/dist/{chunk-H442UKDV.js → chunk-JITK24KX.js} +7 -7
- package/dist/{chunk-EJYUAN5F.js → chunk-K6UXWVQ6.js} +2 -2
- package/dist/{chunk-RVODERA5.js → chunk-KJ65WZHB.js} +2 -2
- package/dist/{chunk-QGT5KNQT.js → chunk-KOVQZJ27.js} +2 -2
- package/dist/{chunk-O6QSBI3U.js → chunk-KZ4BJRGQ.js} +2 -2
- package/dist/{chunk-D3FP4JQI.js → chunk-LR6LWX33.js} +4 -4
- package/dist/{chunk-NTS2RCQK.js → chunk-NAULI3EG.js} +2 -2
- package/dist/{chunk-V5W67PQV.js → chunk-NOKHMWMW.js} +4 -4
- package/dist/{chunk-7X6EZ2QB.js → chunk-ODI4K32P.js} +5 -5
- package/dist/{chunk-H7USCTPQ.js → chunk-OLD2GKQJ.js} +3 -3
- package/dist/{chunk-D7HOJFDS.js → chunk-ONSEODO2.js} +2 -2
- package/dist/{chunk-R3YMWUF3.js → chunk-P3IAZQPS.js} +2 -2
- package/dist/{chunk-LL6WEMTC.js → chunk-P3OONWJJ.js} +2 -2
- package/dist/chunk-P3OONWJJ.js.map +1 -0
- package/dist/{chunk-ZG4GNPRE.js → chunk-PBE7NFB5.js} +5 -5
- package/dist/{chunk-7KC6LT7U.js → chunk-PSQ347YP.js} +3 -3
- package/dist/{chunk-TQODBIMW.js → chunk-QFKNIKUF.js} +2 -2
- package/dist/{chunk-RFVX4WE7.js → chunk-QIPRDRGM.js} +1 -1
- package/dist/chunk-QIPRDRGM.js.map +1 -0
- package/dist/{chunk-C6Y2YHJL.js → chunk-QZMGZBTF.js} +2 -2
- package/dist/{chunk-PCGBESAN.js → chunk-SKJM4PKE.js} +2 -2
- package/dist/{chunk-T7R42MWB.js → chunk-STSORBX5.js} +2 -2
- package/dist/{chunk-XWPYK5T4.js → chunk-T765HQ5U.js} +3 -3
- package/dist/{chunk-RFEQ7DQN.js → chunk-TDG5NZAZ.js} +2 -2
- package/dist/{chunk-DLPS5YP3.js → chunk-TJV5HGSC.js} +4 -4
- package/dist/{chunk-YVXR7CPS.js → chunk-TWYYUMYO.js} +2 -2
- package/dist/{chunk-6MDHK6NO.js → chunk-TZ7ZA2LM.js} +2 -2
- package/dist/{chunk-ABPOW3SX.js → chunk-UAEJKURK.js} +92 -493
- package/dist/chunk-UAEJKURK.js.map +1 -0
- package/dist/{chunk-6OHCNTKU.js → chunk-UH2VY2QQ.js} +3 -3
- package/dist/{chunk-XQF2KLV5.js → chunk-VHQNJW4Q.js} +2 -2
- package/dist/{chunk-K6BS5RB4.js → chunk-WEI6HEUX.js} +11 -6
- package/dist/chunk-WEI6HEUX.js.map +1 -0
- package/dist/{chunk-3IA2SUWM.js → chunk-WRVKI6ZO.js} +2 -2
- package/dist/chunk-XC4PRJWM.js +593 -0
- package/dist/chunk-XC4PRJWM.js.map +1 -0
- package/dist/{chunk-R5S57GRK.js → chunk-XSRZM6CQ.js} +38 -13
- package/dist/chunk-XSRZM6CQ.js.map +1 -0
- package/dist/{chunk-OA7YDB6A.js → chunk-XZLCAL5O.js} +2 -2
- package/dist/{chunk-CIAQK2OU.js → chunk-XZMQLON4.js} +430 -292
- package/dist/chunk-XZMQLON4.js.map +1 -0
- package/dist/{chunk-HL53XYHC.js → chunk-YCJJODER.js} +5 -5
- package/dist/chunk-YCJJODER.js.map +1 -0
- package/dist/{chunk-GGQ3CJVH.js → chunk-YTT6XJNX.js} +4 -4
- package/dist/{chunk-A32EBVCZ.js → chunk-Z6EFSXU3.js} +2 -2
- package/dist/{chunk-GRX5BE73.js → chunk-ZNCCX7P6.js} +2 -2
- package/dist/cli.js +76 -75
- package/dist/coding/export-okf-codegraph.js +15 -15
- package/dist/compounding/engine.js +17 -17
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +16 -16
- package/dist/connectors/codex-materialize-runner.js +16 -16
- package/dist/connectors/index.js +16 -16
- package/dist/consolidation-provenance-check.js +5 -5
- package/dist/consolidation-undo.js +4 -4
- package/dist/contradiction/index.js +3 -3
- package/dist/convergence-refresh.js +18 -18
- package/dist/corpus-watermark.js +18 -18
- package/dist/cue-anchors.js +5 -5
- package/dist/{entity-canonical-id-migration-74IDJFPB.js → entity-canonical-id-migration-46EMEXTB.js} +4 -4
- package/dist/entity-retrieval.d.ts.map +1 -1
- package/dist/entity-retrieval.js +16 -16
- package/dist/explicit-capture.js +76 -75
- package/dist/extraction.js +20 -20
- package/dist/harmonic-construction.js +6 -6
- package/dist/harmonic-graph-version.js +3 -3
- package/dist/harmonic-retrieval.d.ts +15 -0
- package/dist/harmonic-retrieval.d.ts.map +1 -1
- package/dist/harmonic-retrieval.js +21 -19
- package/dist/index.js +97 -96
- package/dist/lcm/engine.js +2 -2
- package/dist/lcm/index.js +5 -5
- package/dist/location/index.js +17 -17
- package/dist/maintenance/memory-governance.js +16 -16
- package/dist/maintenance/rebuild-memory-lifecycle-ledger.js +16 -16
- package/dist/maintenance/rebuild-memory-projection-runner.js +18 -18
- package/dist/maintenance/rebuild-memory-projection.js +17 -17
- package/dist/memory-browse.js +5 -5
- package/dist/memory-cache.d.ts +44 -3
- package/dist/memory-cache.d.ts.map +1 -1
- package/dist/memory-cache.js +9 -1
- package/dist/memory-corpus-version.js +2 -2
- package/dist/namespaces/migrate.js +17 -17
- package/dist/namespaces/search.js +9 -9
- package/dist/namespaces/storage.js +16 -16
- package/dist/operator-doctor-corpus.js +19 -19
- package/dist/operator-toolkit.js +24 -24
- package/dist/orchestration/backlog-scheduler.js +77 -76
- package/dist/orchestration/backlog-scheduler.js.map +1 -1
- package/dist/orchestration/buffer-drain-runner.js +77 -76
- package/dist/orchestration/maintenance.js +24 -24
- package/dist/orchestration/recall-internal.d.ts.map +1 -1
- package/dist/orchestration/turn-ingestion-buffered.d.ts.map +1 -1
- package/dist/orchestrator.js +76 -75
- package/dist/page-versioning.js +4 -4
- package/dist/qmd.js +2 -2
- package/dist/recall-explain-renderer.js +3 -3
- package/dist/recall-navigate-access.js +2 -2
- package/dist/recall-navigate-disclosure.js +2 -2
- package/dist/recall-navigate.js +2 -2
- package/dist/recall-navigation.js +76 -75
- package/dist/recall-state-view-admission.js +5 -5
- package/dist/recall-why-service.js +5 -5
- package/dist/recall-xray-cli.js +4 -4
- package/dist/recall-xray-renderer.js +3 -3
- package/dist/recall-xray.js +2 -2
- package/dist/{resolution-RWIGFH2W.js → resolution-4QPPLDEN.js} +4 -4
- package/dist/resolution-4QPPLDEN.js.map +1 -0
- package/dist/resume-bundles.js +17 -17
- package/dist/search/factory.js +8 -8
- package/dist/search/index.js +13 -13
- package/dist/search/lancedb-backend.js +2 -2
- package/dist/search/meilisearch-backend.js +2 -2
- package/dist/search/orama-backend.js +2 -2
- package/dist/semantic-consolidation.js +17 -17
- package/dist/semantic-rule-promotion.js +16 -16
- package/dist/semantic-rule-verifier.js +16 -16
- package/dist/source-agent-qualifier.js +19 -19
- package/dist/standup/build.js +16 -16
- package/dist/storage/entity-listing.d.ts +20 -0
- package/dist/storage/entity-listing.d.ts.map +1 -0
- package/dist/storage/entity-store.d.ts +5 -0
- package/dist/storage/entity-store.d.ts.map +1 -1
- package/dist/storage/hot-cache-validation.d.ts +60 -0
- package/dist/storage/hot-cache-validation.d.ts.map +1 -0
- package/dist/storage.d.ts +2 -0
- package/dist/storage.d.ts.map +1 -1
- package/dist/storage.js +15 -15
- package/dist/transfer/capsule-import.js +5 -5
- package/dist/transfer/export-okf.js +16 -16
- package/dist/types.d.ts +2 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -1
- package/dist/verified-recall.js +16 -16
- package/dist/who-knows-cli.js +17 -17
- package/dist/who-knows.js +16 -16
- package/package.json +12 -2
- package/src/admin/admin-surfaces.test.ts +171 -0
- package/src/admin/admin-surfaces.ts +215 -2
- package/src/buffer-large-session-defer.test.ts +81 -0
- package/src/buffer-persistence.ts +8 -1
- package/src/buffer.ts +9 -4
- package/src/config.test.ts +9 -0
- package/src/config.ts +3 -6
- package/src/entity-recall-hot-cache.test.ts +116 -0
- package/src/entity-retrieval.ts +22 -4
- package/src/harmonic-graph-cache.test.ts +28 -9
- package/src/harmonic-retrieval.ts +20 -4
- package/src/memory-cache-hot.test.ts +47 -0
- package/src/memory-cache.ts +96 -17
- package/src/observe-flush-force-keys.test.ts +130 -0
- package/src/orchestration/recall-internal.ts +1 -0
- package/src/orchestration/turn-ingestion-buffered.test.ts +6 -2
- package/src/orchestration/turn-ingestion-buffered.ts +5 -1
- package/src/storage/entity-listing.ts +73 -0
- package/src/storage/entity-store.ts +25 -26
- package/src/storage/hot-cache-validation.ts +149 -0
- package/src/storage-contract/cache-coherence.test.ts +42 -5
- package/src/storage-hot-cache-stat-validate.test.ts +112 -0
- package/src/storage.ts +58 -44
- package/src/types.ts +2 -0
- package/dist/chunk-65DWWJKI.js.map +0 -1
- package/dist/chunk-ABPOW3SX.js.map +0 -1
- package/dist/chunk-CIAQK2OU.js.map +0 -1
- package/dist/chunk-HL53XYHC.js.map +0 -1
- package/dist/chunk-K6BS5RB4.js.map +0 -1
- package/dist/chunk-LL6WEMTC.js.map +0 -1
- package/dist/chunk-QSVWIKNY.js.map +0 -1
- package/dist/chunk-R5S57GRK.js.map +0 -1
- package/dist/chunk-RFVX4WE7.js.map +0 -1
- /package/dist/{entity-canonical-id-migration-74IDJFPB.js.map → admin/admin-surfaces.js.map} +0 -0
- /package/dist/{capsule-merge-BADOICNP.js.map → capsule-merge-3FARYIHP.js.map} +0 -0
- /package/dist/{chunk-IMSLPQJB.js.map → chunk-2QW5HPKU.js.map} +0 -0
- /package/dist/{chunk-KNYUEYB6.js.map → chunk-2YJ2ST23.js.map} +0 -0
- /package/dist/{chunk-X3ERYOLO.js.map → chunk-3BICT225.js.map} +0 -0
- /package/dist/{chunk-UWKHLWUE.js.map → chunk-3RZ4GDOH.js.map} +0 -0
- /package/dist/{chunk-ODIBCZLG.js.map → chunk-3YID7KZ6.js.map} +0 -0
- /package/dist/{chunk-56BNHKZM.js.map → chunk-4EAVEDLG.js.map} +0 -0
- /package/dist/{chunk-TLRIRISJ.js.map → chunk-4LCA2GEX.js.map} +0 -0
- /package/dist/{chunk-4N33L4HY.js.map → chunk-5GIYIYJI.js.map} +0 -0
- /package/dist/{chunk-ZDLVHGIC.js.map → chunk-7EP4FURO.js.map} +0 -0
- /package/dist/{chunk-CAUADFDM.js.map → chunk-7SOKOEAZ.js.map} +0 -0
- /package/dist/{chunk-7Q74DD2W.js.map → chunk-7V6GNQC2.js.map} +0 -0
- /package/dist/{chunk-QXHWOUS6.js.map → chunk-AALJHIKH.js.map} +0 -0
- /package/dist/{chunk-ATPY63F5.js.map → chunk-AJ7JHHRY.js.map} +0 -0
- /package/dist/{chunk-B7GZL7PR.js.map → chunk-ARD2TEY2.js.map} +0 -0
- /package/dist/{chunk-3DADRUGW.js.map → chunk-BGA7S5EF.js.map} +0 -0
- /package/dist/{chunk-RPOG6HLI.js.map → chunk-CJSTQNE5.js.map} +0 -0
- /package/dist/{chunk-VQQZJ6KJ.js.map → chunk-DYUPSTCV.js.map} +0 -0
- /package/dist/{chunk-E5QI6C6C.js.map → chunk-E3LGAZJC.js.map} +0 -0
- /package/dist/{chunk-TAPF7T26.js.map → chunk-EEA2RM4B.js.map} +0 -0
- /package/dist/{chunk-BL7WULM5.js.map → chunk-FDO7ITP6.js.map} +0 -0
- /package/dist/{chunk-K3JGILZC.js.map → chunk-FGFU6J26.js.map} +0 -0
- /package/dist/{chunk-6TIQLG7I.js.map → chunk-FKHXXL42.js.map} +0 -0
- /package/dist/{chunk-QPD7EYGI.js.map → chunk-G2MS56KM.js.map} +0 -0
- /package/dist/{chunk-2I3ETW3G.js.map → chunk-GH7IKABD.js.map} +0 -0
- /package/dist/{chunk-KVTUUU7H.js.map → chunk-GYCUX3N4.js.map} +0 -0
- /package/dist/{chunk-2VNMSEZR.js.map → chunk-HEJFE3BC.js.map} +0 -0
- /package/dist/{chunk-KM4QO4LN.js.map → chunk-HLQANATZ.js.map} +0 -0
- /package/dist/{chunk-AXSQGJSG.js.map → chunk-J7RQ3RP7.js.map} +0 -0
- /package/dist/{chunk-H442UKDV.js.map → chunk-JITK24KX.js.map} +0 -0
- /package/dist/{chunk-EJYUAN5F.js.map → chunk-K6UXWVQ6.js.map} +0 -0
- /package/dist/{chunk-RVODERA5.js.map → chunk-KJ65WZHB.js.map} +0 -0
- /package/dist/{chunk-QGT5KNQT.js.map → chunk-KOVQZJ27.js.map} +0 -0
- /package/dist/{chunk-O6QSBI3U.js.map → chunk-KZ4BJRGQ.js.map} +0 -0
- /package/dist/{chunk-D3FP4JQI.js.map → chunk-LR6LWX33.js.map} +0 -0
- /package/dist/{chunk-NTS2RCQK.js.map → chunk-NAULI3EG.js.map} +0 -0
- /package/dist/{chunk-V5W67PQV.js.map → chunk-NOKHMWMW.js.map} +0 -0
- /package/dist/{chunk-7X6EZ2QB.js.map → chunk-ODI4K32P.js.map} +0 -0
- /package/dist/{chunk-H7USCTPQ.js.map → chunk-OLD2GKQJ.js.map} +0 -0
- /package/dist/{chunk-D7HOJFDS.js.map → chunk-ONSEODO2.js.map} +0 -0
- /package/dist/{chunk-R3YMWUF3.js.map → chunk-P3IAZQPS.js.map} +0 -0
- /package/dist/{chunk-ZG4GNPRE.js.map → chunk-PBE7NFB5.js.map} +0 -0
- /package/dist/{chunk-7KC6LT7U.js.map → chunk-PSQ347YP.js.map} +0 -0
- /package/dist/{chunk-TQODBIMW.js.map → chunk-QFKNIKUF.js.map} +0 -0
- /package/dist/{chunk-C6Y2YHJL.js.map → chunk-QZMGZBTF.js.map} +0 -0
- /package/dist/{chunk-PCGBESAN.js.map → chunk-SKJM4PKE.js.map} +0 -0
- /package/dist/{chunk-T7R42MWB.js.map → chunk-STSORBX5.js.map} +0 -0
- /package/dist/{chunk-XWPYK5T4.js.map → chunk-T765HQ5U.js.map} +0 -0
- /package/dist/{chunk-RFEQ7DQN.js.map → chunk-TDG5NZAZ.js.map} +0 -0
- /package/dist/{chunk-DLPS5YP3.js.map → chunk-TJV5HGSC.js.map} +0 -0
- /package/dist/{chunk-YVXR7CPS.js.map → chunk-TWYYUMYO.js.map} +0 -0
- /package/dist/{chunk-6MDHK6NO.js.map → chunk-TZ7ZA2LM.js.map} +0 -0
- /package/dist/{chunk-6OHCNTKU.js.map → chunk-UH2VY2QQ.js.map} +0 -0
- /package/dist/{chunk-XQF2KLV5.js.map → chunk-VHQNJW4Q.js.map} +0 -0
- /package/dist/{chunk-3IA2SUWM.js.map → chunk-WRVKI6ZO.js.map} +0 -0
- /package/dist/{chunk-OA7YDB6A.js.map → chunk-XZLCAL5O.js.map} +0 -0
- /package/dist/{chunk-GGQ3CJVH.js.map → chunk-YTT6XJNX.js.map} +0 -0
- /package/dist/{chunk-A32EBVCZ.js.map → chunk-Z6EFSXU3.js.map} +0 -0
- /package/dist/{chunk-GRX5BE73.js.map → chunk-ZNCCX7P6.js.map} +0 -0
- /package/dist/{resolution-RWIGFH2W.js.map → entity-canonical-id-migration-46EMEXTB.js.map} +0 -0
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* COS-825 hot-path fixes for the entity recall section.
|
|
3
|
+
*
|
|
4
|
+
* Two production-profile hotspots, each pinned by a test:
|
|
5
|
+
*
|
|
6
|
+
* 1. `readAllEntityFiles` keyed its cache on the memory-status version, which
|
|
7
|
+
* churns with every plain memory write. Under observe traffic the cache was
|
|
8
|
+
* busted on every recall, so the whole entity store was re-read (and
|
|
9
|
+
* re-decrypted) per recall. The cache is now validated by an entities-dir
|
|
10
|
+
* listing snapshot (name, mtime, size) plus the entity-mutation version,
|
|
11
|
+
* so unrelated memory writes no longer force a re-read while any entity
|
|
12
|
+
* file change — including one made without a version bump — does.
|
|
13
|
+
*
|
|
14
|
+
* 2. `readMemorySnippet` normalized (and `compactLine` re-normalized) the FULL
|
|
15
|
+
* memory content, then grapheme-truncated it to 180 units. `compactLine`
|
|
16
|
+
* now pre-slices its input to a bounded prefix before normalization, which
|
|
17
|
+
* bounds the regex + grapheme work per snippet. The pin below asserts the
|
|
18
|
+
* truncated output is unchanged for long plain-text content.
|
|
19
|
+
*/
|
|
20
|
+
import assert from "node:assert/strict";
|
|
21
|
+
import { mkdtemp, readdir, readFile, rm, utimes, writeFile } from "node:fs/promises";
|
|
22
|
+
import { tmpdir } from "node:os";
|
|
23
|
+
import path from "node:path";
|
|
24
|
+
import test from "node:test";
|
|
25
|
+
|
|
26
|
+
import { buildEntityRecallSection } from "./entity-retrieval.js";
|
|
27
|
+
import { clearMemoryCache, entityCacheStats } from "./memory-cache.js";
|
|
28
|
+
import { StorageManager } from "./storage.js";
|
|
29
|
+
import { parseConfig } from "./config.js";
|
|
30
|
+
import type { TranscriptEntry } from "./types.js";
|
|
31
|
+
|
|
32
|
+
async function withDir(run: (memoryDir: string, storage: StorageManager) => Promise<void>) {
|
|
33
|
+
const memoryDir = await mkdtemp(path.join(tmpdir(), "remnic-entity-hot-"));
|
|
34
|
+
clearMemoryCache();
|
|
35
|
+
try {
|
|
36
|
+
const storage = new StorageManager(memoryDir);
|
|
37
|
+
await storage.ensureDirectories();
|
|
38
|
+
await run(memoryDir, storage);
|
|
39
|
+
} finally {
|
|
40
|
+
clearMemoryCache();
|
|
41
|
+
await rm(memoryDir, { recursive: true, force: true });
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async function entityFilePath(memoryDir: string): Promise<string> {
|
|
46
|
+
const dir = path.join(memoryDir, "entities");
|
|
47
|
+
const entries = (await readdir(dir)).filter((name) => name.endsWith(".md"));
|
|
48
|
+
assert.equal(entries.length, 1, "expected exactly one entity file in the fixture");
|
|
49
|
+
return path.join(dir, entries[0]!);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
test("a plain memory write does not force an entity store re-read (COS-825)", async () => {
|
|
53
|
+
await withDir(async (_memoryDir, storage) => {
|
|
54
|
+
await storage.writeEntity("Alice", "person", ["Alice keeps the ledger."]);
|
|
55
|
+
await storage.readAllEntityFiles();
|
|
56
|
+
const afterFirstRead = { ...entityCacheStats };
|
|
57
|
+
assert.equal(afterFirstRead.rebuilds, 1, "first read rebuilds");
|
|
58
|
+
|
|
59
|
+
// A plain fact write bumps memory-status + corpus versions and the mention
|
|
60
|
+
// epoch, but touches no entity file.
|
|
61
|
+
await storage.writeMemory("fact", "an unrelated fact about whales", { source: "test" });
|
|
62
|
+
const entities = await storage.readAllEntityFiles();
|
|
63
|
+
assert.equal(entityCacheStats.rebuilds, afterFirstRead.rebuilds, "no re-read after a memory-only write");
|
|
64
|
+
assert.equal(entityCacheStats.hits, afterFirstRead.hits + 1);
|
|
65
|
+
assert.ok(entities.some((entity) => entity.name === "Alice"));
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
test("an entity file edit invalidates by listing snapshot even without a version bump (COS-825)", async () => {
|
|
70
|
+
await withDir(async (memoryDir, storage) => {
|
|
71
|
+
await storage.writeEntity("Alice", "person", ["Alice keeps the ledger."]);
|
|
72
|
+
await storage.readAllEntityFiles();
|
|
73
|
+
const afterFirstRead = { ...entityCacheStats };
|
|
74
|
+
|
|
75
|
+
// Out-of-band edit: no storage-layer write, no version bump. The listing
|
|
76
|
+
// snapshot (mtime + size) is the only signal.
|
|
77
|
+
const filePath = await entityFilePath(memoryDir);
|
|
78
|
+
const raw = await readFile(filePath, "utf8");
|
|
79
|
+
await writeFile(filePath, raw.replace("Alice keeps the ledger.", "Alice keeps the DOUBLE ledger."));
|
|
80
|
+
await utimes(filePath, new Date(), new Date(Date.now() + 5_000));
|
|
81
|
+
|
|
82
|
+
const entities = await storage.readAllEntityFiles();
|
|
83
|
+
assert.equal(entityCacheStats.rebuilds, afterFirstRead.rebuilds + 1, "the edit forces one rebuild");
|
|
84
|
+
const alice = entities.find((entity) => entity.name === "Alice");
|
|
85
|
+
assert.ok(alice, "Alice is still present");
|
|
86
|
+
assert.ok(
|
|
87
|
+
alice.facts.some((fact) => fact.includes("DOUBLE ledger")),
|
|
88
|
+
"the rebuilt entity carries the edited fact",
|
|
89
|
+
);
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
test("a long memory still yields the exact 180-unit snippet (COS-825 pre-slice pin)", async () => {
|
|
94
|
+
await withDir(async (memoryDir, storage) => {
|
|
95
|
+
const entityRef = await storage.writeEntity("Bob", "person", []);
|
|
96
|
+
const longBody = `${"deployment note. ".repeat(400)}final marker`;
|
|
97
|
+
await storage.writeMemory("fact", longBody, { source: "test", entityRef });
|
|
98
|
+
const transcriptEntries: TranscriptEntry[] = [];
|
|
99
|
+
const section = await buildEntityRecallSection({
|
|
100
|
+
storage,
|
|
101
|
+
config: parseConfig({ memoryDir, workspaceDir: path.join(memoryDir, "workspace") }),
|
|
102
|
+
query: "What is the deployment note for Bob?",
|
|
103
|
+
recentTurns: 0,
|
|
104
|
+
maxHints: 2,
|
|
105
|
+
maxSupportingFacts: 2,
|
|
106
|
+
maxRelatedEntities: 2,
|
|
107
|
+
maxChars: 10_000,
|
|
108
|
+
transcriptEntries,
|
|
109
|
+
});
|
|
110
|
+
assert.ok(section, "the section builds");
|
|
111
|
+
const normalized = longBody.replace(/\s+/g, " ").trim();
|
|
112
|
+
const expected = `${normalized.slice(0, 179)}…`;
|
|
113
|
+
assert.match(section, new RegExp(expected.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")));
|
|
114
|
+
assert.doesNotMatch(section, /final marker/, "content past the 180-unit budget stays out");
|
|
115
|
+
});
|
|
116
|
+
});
|
package/src/entity-retrieval.ts
CHANGED
|
@@ -112,9 +112,26 @@ export interface BuildEntityRecallSectionOptions {
|
|
|
112
112
|
function uniqueStrings(values: string[]): string[] {
|
|
113
113
|
return [...new Set(values.map((value) => value.trim()).filter((value) => value.length > 0))];
|
|
114
114
|
}
|
|
115
|
+
/**
|
|
116
|
+
* COS-825: the output only depends on the first maxLength display units, so
|
|
117
|
+
* normalization runs over a bounded prefix. Inputs longer than the prefix
|
|
118
|
+
* always take the truncate path (no short-circuit), so ordinary content keeps
|
|
119
|
+
* its exact output; only content whose first 4 KiB collapses to under one
|
|
120
|
+
* line of text (pathological leading whitespace) can differ.
|
|
121
|
+
*/
|
|
122
|
+
const COMPACT_LINE_PRESLICE_UNITS = 4_096;
|
|
123
|
+
|
|
115
124
|
function compactLine(value: string, maxLength: number = 220): string {
|
|
116
|
-
|
|
117
|
-
|
|
125
|
+
let sliced = value.length > COMPACT_LINE_PRESLICE_UNITS ? value.slice(0, COMPACT_LINE_PRESLICE_UNITS) : value;
|
|
126
|
+
// Never split a surrogate pair at the prefix boundary: a lone high surrogate
|
|
127
|
+
// would survive normalization and render as a malformed snippet (COS-825
|
|
128
|
+
// review round 3).
|
|
129
|
+
if (sliced.length > 0) {
|
|
130
|
+
const last = sliced.charCodeAt(sliced.length - 1);
|
|
131
|
+
if (last >= 0xd800 && last <= 0xdbff && sliced.length < value.length) sliced = sliced.slice(0, -1);
|
|
132
|
+
}
|
|
133
|
+
const normalized = sliced.replace(/\s+/g, " ").trim();
|
|
134
|
+
if (normalized.length <= maxLength && sliced === value) return normalized;
|
|
118
135
|
return `${truncateGraphemeSafe(normalized, maxLength - 1).trimEnd()}…`;
|
|
119
136
|
}
|
|
120
137
|
function dedupeHintSnippetsByText(snippets: EntityHintSnippet[]): EntityHintSnippet[] {
|
|
@@ -724,8 +741,9 @@ function resolveRecentTurnCandidates(
|
|
|
724
741
|
}
|
|
725
742
|
|
|
726
743
|
async function readMemorySnippet(memory: MemoryFile): Promise<string> {
|
|
727
|
-
|
|
728
|
-
|
|
744
|
+
// compactLine normalizes (bounded pre-slice, COS-825); a pre-normalized
|
|
745
|
+
// full-content pass here is redundant work on every entity-linked memory.
|
|
746
|
+
return compactLine(memory.content, 180);
|
|
729
747
|
}
|
|
730
748
|
|
|
731
749
|
async function buildHintSnippets(
|
|
@@ -43,7 +43,7 @@ async function withDir(run: (memoryDir: string, storage: StorageManager) => Prom
|
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
const read = (memoryDir: string, extra: { nowMs?: number } = {}) =>
|
|
46
|
+
const read = (memoryDir: string, extra: { nowMs?: number; ttlMs?: number } = {}) =>
|
|
47
47
|
readProjectedHarmonicGraph({ memoryDir, anchorsEnabled: true, useCache: true, ...extra });
|
|
48
48
|
|
|
49
49
|
test("a second cached read does no file reads", async () => {
|
|
@@ -274,16 +274,35 @@ test("a read past the TTL answers from the stale graph and refreshes behind it",
|
|
|
274
274
|
const clock = t.mock.method(Date, "now", () => start);
|
|
275
275
|
assert.equal((await read(memoryDir)).nodes.length, 1);
|
|
276
276
|
await rm(nodeFile, { force: true });
|
|
277
|
-
clock.mock.mockImplementation(() => start +
|
|
277
|
+
clock.mock.mockImplementation(() => start + 299_000);
|
|
278
278
|
assert.equal((await read(memoryDir)).nodes.length, 1, "still cached inside the TTL");
|
|
279
279
|
const missesBefore = harmonicGraphCacheStats.misses;
|
|
280
|
-
clock.mock.mockImplementation(() => start +
|
|
280
|
+
clock.mock.mockImplementation(() => start + 301_000);
|
|
281
281
|
assert.equal((await read(memoryDir)).nodes.length, 1, "past the TTL the caller does not wait for a rebuild");
|
|
282
282
|
assert.equal(harmonicGraphCacheStats.misses, missesBefore + 1, "a refresh was started");
|
|
283
283
|
await until(async () => (await read(memoryDir)).nodes.length === 0);
|
|
284
284
|
});
|
|
285
285
|
});
|
|
286
286
|
|
|
287
|
+
test("a custom ttlMs moves the refresh boundary (COS-825)", async (t) => {
|
|
288
|
+
await withDir(async (memoryDir, storage) => {
|
|
289
|
+
const memory = await storage.writeMemory("fact", "theta ttl fact", { source: "test" });
|
|
290
|
+
const nodeFile = await recordAbstractionNode({ memoryDir, node: node("n1", "theta ttl fact", [memory.id]) });
|
|
291
|
+
const start = Date.now();
|
|
292
|
+
const clock = t.mock.method(Date, "now", () => start);
|
|
293
|
+
assert.equal((await read(memoryDir, { ttlMs: 2_000 })).nodes.length, 1);
|
|
294
|
+
await rm(nodeFile, { force: true });
|
|
295
|
+
clock.mock.mockImplementation(() => start + 1_999);
|
|
296
|
+
const before = { ...harmonicGraphCacheStats };
|
|
297
|
+
assert.equal((await read(memoryDir, { ttlMs: 2_000 })).nodes.length, 1, "fresh inside the custom TTL");
|
|
298
|
+
assert.equal(harmonicGraphCacheStats.misses, before.misses, "no refresh inside the custom TTL");
|
|
299
|
+
clock.mock.mockImplementation(() => start + 2_001);
|
|
300
|
+
assert.equal((await read(memoryDir, { ttlMs: 2_000 })).nodes.length, 1, "past the custom TTL the stale graph is served");
|
|
301
|
+
assert.equal(harmonicGraphCacheStats.misses, before.misses + 1, "a refresh was started at the custom TTL");
|
|
302
|
+
await until(async () => (await read(memoryDir, { ttlMs: 2_000 })).nodes.length === 0);
|
|
303
|
+
});
|
|
304
|
+
});
|
|
305
|
+
|
|
287
306
|
test("a graph past the stale limit is rebuilt before it is served", async (t) => {
|
|
288
307
|
await withDir(async (memoryDir, storage) => {
|
|
289
308
|
const memory = await storage.writeMemory("fact", "kappa limit fact", { source: "test" });
|
|
@@ -292,8 +311,8 @@ test("a graph past the stale limit is rebuilt before it is served", async (t) =>
|
|
|
292
311
|
const clock = t.mock.method(Date, "now", () => start);
|
|
293
312
|
assert.equal((await read(memoryDir)).nodes.length, 1);
|
|
294
313
|
await rm(nodeFile, { force: true });
|
|
295
|
-
clock.mock.mockImplementation(() => start +
|
|
296
|
-
assert.equal((await read(memoryDir)).nodes.length, 0, "the stale window ends 300 s after the TTL, at
|
|
314
|
+
clock.mock.mockImplementation(() => start + 601_000);
|
|
315
|
+
assert.equal((await read(memoryDir)).nodes.length, 0, "the stale window ends 300 s after the 300 s TTL, at 600 s");
|
|
297
316
|
});
|
|
298
317
|
});
|
|
299
318
|
|
|
@@ -305,7 +324,7 @@ test("a graph is still served stale one millisecond before the stale window ends
|
|
|
305
324
|
const clock = t.mock.method(Date, "now", () => start);
|
|
306
325
|
assert.equal((await read(memoryDir)).nodes.length, 1);
|
|
307
326
|
await rm(nodeFile, { force: true });
|
|
308
|
-
clock.mock.mockImplementation(() => start +
|
|
327
|
+
clock.mock.mockImplementation(() => start + 599_999);
|
|
309
328
|
assert.equal((await read(memoryDir)).nodes.length, 1, "up to 300 s past the TTL the stale graph is served");
|
|
310
329
|
await settleHarmonicGraphBuilds();
|
|
311
330
|
});
|
|
@@ -406,18 +425,18 @@ test("a failing refresh is retried at most once per TTL, not on every stale read
|
|
|
406
425
|
const clock = t.mock.method(Date, "now", () => start);
|
|
407
426
|
assert.equal((await read(memoryDir)).nodes.length, 1);
|
|
408
427
|
const restore = await breakNodeStore(memoryDir);
|
|
409
|
-
clock.mock.mockImplementation(() => start +
|
|
428
|
+
clock.mock.mockImplementation(() => start + 301_000);
|
|
410
429
|
const missesBefore = harmonicGraphCacheStats.misses;
|
|
411
430
|
assert.equal((await read(memoryDir)).nodes.length, 1, "the stale graph is still served");
|
|
412
431
|
// The failing build bumps `misses` before it reads the broken store: wait for it to settle, not for a time.
|
|
413
432
|
await settleHarmonicGraphBuilds();
|
|
414
433
|
assert.equal(harmonicGraphCacheStats.misses, missesBefore + 1, "one refresh was started");
|
|
415
|
-
clock.mock.mockImplementation(() => start +
|
|
434
|
+
clock.mock.mockImplementation(() => start + 310_000);
|
|
416
435
|
for (let i = 0; i < 5; i += 1) await read(memoryDir);
|
|
417
436
|
await settleHarmonicGraphBuilds();
|
|
418
437
|
assert.equal(harmonicGraphCacheStats.misses, missesBefore + 1, "no new build inside the backoff");
|
|
419
438
|
await restore();
|
|
420
|
-
clock.mock.mockImplementation(() => start +
|
|
439
|
+
clock.mock.mockImplementation(() => start + 602_000);
|
|
421
440
|
await read(memoryDir);
|
|
422
441
|
await until(async () => harmonicGraphCacheStats.misses === missesBefore + 2);
|
|
423
442
|
});
|
|
@@ -579,7 +579,15 @@ async function buildExpiringHarmonicGraph(options: {
|
|
|
579
579
|
return { nodes: projectedNodes, anchors, validUntilMs };
|
|
580
580
|
}
|
|
581
581
|
|
|
582
|
-
|
|
582
|
+
/**
|
|
583
|
+
* Default time-to-live for a cached graph whose stamp is unchanged. Writes
|
|
584
|
+
* still invalidate immediately through the stamp; the TTL only bounds the
|
|
585
|
+
* wall-clock re-check. COS-825 moved the default from 30 s to 300 s: on a
|
|
586
|
+
* large store under observe traffic the stamp churns anyway, and a short TTL
|
|
587
|
+
* on top of it forced a whole-corpus rebuild every 30 s. Configurable via
|
|
588
|
+
* `harmonicGraphCacheTtlMs`.
|
|
589
|
+
*/
|
|
590
|
+
export const DEFAULT_HARMONIC_GRAPH_CACHE_TTL_MS = 300_000;
|
|
583
591
|
/**
|
|
584
592
|
* Past the TTL a graph whose stamp is unchanged is still served while a refresh runs behind it, so no
|
|
585
593
|
* recall waits for a rebuild just because the TTL lapsed. This is how long past the TTL; after it the graph is rebuilt first.
|
|
@@ -780,6 +788,10 @@ export async function readProjectedHarmonicGraph(options: {
|
|
|
780
788
|
temporalExpiredInInjection?: boolean;
|
|
781
789
|
nowMs?: number;
|
|
782
790
|
useCache?: boolean;
|
|
791
|
+
/** Cache time-to-live in ms for this read; defaults to
|
|
792
|
+
* DEFAULT_HARMONIC_GRAPH_CACHE_TTL_MS. Writes invalidate through the stamp
|
|
793
|
+
* regardless of this value. */
|
|
794
|
+
ttlMs?: number;
|
|
783
795
|
/** Per-caller bound on joining a shared build, in ms. On expiry the caller
|
|
784
796
|
* leaves with a HarmonicGraphWaitDeadlineError while the build keeps running.
|
|
785
797
|
* `0` or unset waits without a bound. Applies only on the cached path. */
|
|
@@ -798,18 +810,19 @@ export async function readProjectedHarmonicGraph(options: {
|
|
|
798
810
|
// The stamp is read BEFORE the build, so a write that lands mid-build leaves the
|
|
799
811
|
// entry stale and the next call rebuilds.
|
|
800
812
|
const stamp = readHarmonicGraphStamp(options.memoryDir, nodeStoreDir);
|
|
813
|
+
const ttlMs = options.ttlMs ?? DEFAULT_HARMONIC_GRAPH_CACHE_TTL_MS;
|
|
801
814
|
const nowMs = Date.now();
|
|
802
815
|
const hit = graphCache.get(key);
|
|
803
816
|
// A source's `invalid_at` passing changes the projection without bumping the stamp, so it ends the entry
|
|
804
817
|
// at the exact instant, however fresh the entry is.
|
|
805
|
-
if (hit && hit.stamp === stamp && nowMs < hit.validUntilMs && nowMs - hit.builtAtMs <
|
|
818
|
+
if (hit && hit.stamp === stamp && nowMs < hit.validUntilMs && nowMs - hit.builtAtMs < ttlMs + GRAPH_CACHE_MAX_STALE_MS) {
|
|
806
819
|
harmonicGraphCacheStats.hits++;
|
|
807
820
|
graphCache.delete(key);
|
|
808
821
|
graphCache.set(key, hit);
|
|
809
|
-
if (nowMs - hit.builtAtMs >=
|
|
822
|
+
if (nowMs - hit.builtAtMs >= ttlMs) {
|
|
810
823
|
harmonicGraphCacheStats.stale++;
|
|
811
824
|
const failedAtMs = refreshFailedAtMs.get(key);
|
|
812
|
-
const backingOff = failedAtMs !== undefined && nowMs - failedAtMs <
|
|
825
|
+
const backingOff = failedAtMs !== undefined && nowMs - failedAtMs < ttlMs;
|
|
813
826
|
if (graphBuilds.get(key)?.stamp !== stamp && !backingOff) {
|
|
814
827
|
startGraphBuild(key, stamp, options).promise.catch((err) => {
|
|
815
828
|
rememberRefreshFailure(key);
|
|
@@ -838,6 +851,8 @@ export async function searchHarmonicRetrieval(options: {
|
|
|
838
851
|
temporalExpiredInInjection?: boolean;
|
|
839
852
|
/** Share one projected graph between recalls until a write bumps a version sentinel (see readProjectedHarmonicGraph). */
|
|
840
853
|
useGraphCache?: boolean;
|
|
854
|
+
/** Cache time-to-live in ms for the shared graph (see readProjectedHarmonicGraph). */
|
|
855
|
+
graphCacheTtlMs?: number;
|
|
841
856
|
/** Bound on waiting for a shared graph build, in ms. Past it the search
|
|
842
857
|
* rejects with a HarmonicGraphWaitDeadlineError so a recall fails open
|
|
843
858
|
* instead of blocking on a rebuild a write storm keeps invalidating.
|
|
@@ -853,6 +868,7 @@ export async function searchHarmonicRetrieval(options: {
|
|
|
853
868
|
const graph = await readProjectedHarmonicGraph({
|
|
854
869
|
...options,
|
|
855
870
|
useCache: options.useGraphCache === true,
|
|
871
|
+
ttlMs: options.graphCacheTtlMs,
|
|
856
872
|
waitBudgetMs:
|
|
857
873
|
options.waitBudgetMs === undefined ? HARMONIC_GRAPH_WAIT_BUDGET_MS : options.waitBudgetMs,
|
|
858
874
|
});
|
|
@@ -129,3 +129,50 @@ test("hot cache: TTL expires an entry so external edits self-heal (#1902 Codex P
|
|
|
129
129
|
clearMemoryCache();
|
|
130
130
|
}
|
|
131
131
|
});
|
|
132
|
+
|
|
133
|
+
// COS-825: per-file stat snapshot so a version-mismatched entry can be
|
|
134
|
+
// validated by metadata instead of a full corpus re-read.
|
|
135
|
+
import { getHotCacheEntry, hotCacheReadStats, promoteHotCacheVersion } from "./memory-cache.js";
|
|
136
|
+
|
|
137
|
+
const STATS = new Map([["a.md", { mtimeMs: 100, size: 5 }]]);
|
|
138
|
+
|
|
139
|
+
test("hot cache: stat snapshot round-trips and promotes a patched entry", () => {
|
|
140
|
+
const dir = "/tmp/remnic-hot-unit-stats";
|
|
141
|
+
clearMemoryCache();
|
|
142
|
+
setCachedMemories(dir, [mem("a.md", "first")], 5, "", 0, STATS);
|
|
143
|
+
const entry = getHotCacheEntry(dir, "");
|
|
144
|
+
assert.ok(entry, "entry is visible for validation");
|
|
145
|
+
assert.deepEqual(entry.stats.get("a.md"), { mtimeMs: 100, size: 5 });
|
|
146
|
+
|
|
147
|
+
const promoted = promoteHotCacheVersion(dir, 6, "");
|
|
148
|
+
assert.ok(promoted, "a patched entry promotes to the current version");
|
|
149
|
+
assert.deepEqual(promoted.map((m) => m.path), ["a.md"]);
|
|
150
|
+
assert.ok(getCachedMemories(dir, 6), "after promotion the current version hits");
|
|
151
|
+
assert.equal(getCachedMemories(dir, 5), null, "the old version no longer hits");
|
|
152
|
+
clearMemoryCache();
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
test("hot cache: validation entry is keyId-scoped and absent without stats", () => {
|
|
156
|
+
const dir = "/tmp/remnic-hot-unit-stats-key";
|
|
157
|
+
clearMemoryCache();
|
|
158
|
+
setCachedMemories(dir, [mem("a.md")], 5, "keyA", 0, STATS);
|
|
159
|
+
assert.equal(getHotCacheEntry(dir, "keyB"), null, "a different key identity never validates");
|
|
160
|
+
setCachedMemories(dir, [mem("a.md")], 5, "", 0);
|
|
161
|
+
assert.equal(getHotCacheEntry(dir, ""), null, "an entry stored without stats cannot validate");
|
|
162
|
+
clearMemoryCache();
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
test("hot cache: updateCacheOnWrite drops the stat snapshot (never a false pass)", () => {
|
|
166
|
+
const dir = "/tmp/remnic-hot-unit-stats-patch";
|
|
167
|
+
clearMemoryCache();
|
|
168
|
+
setCachedMemories(dir, [mem("a.md")], 5, "", 0, STATS);
|
|
169
|
+
updateCacheOnWrite(dir, mem("a.md", "rewritten"), "");
|
|
170
|
+
assert.equal(getHotCacheEntry(dir, ""), null, "a patched entry carries no snapshot and cannot validate");
|
|
171
|
+
clearMemoryCache();
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
test("hot cache: read counters track validated hits vs full scans", () => {
|
|
175
|
+
clearMemoryCache();
|
|
176
|
+
assert.equal(hotCacheReadStats.validatedHits, 0);
|
|
177
|
+
assert.equal(hotCacheReadStats.fullScans, 0);
|
|
178
|
+
});
|
package/src/memory-cache.ts
CHANGED
|
@@ -15,8 +15,25 @@ interface CacheEntry {
|
|
|
15
15
|
// so the opportunistic sweep can evict abandoned corpora that are never
|
|
16
16
|
// revisited. 0 = no TTL (never swept by age).
|
|
17
17
|
ttlMs: number;
|
|
18
|
+
// COS-825: per-file stat snapshot (path -> mtime+size) taken when the entry
|
|
19
|
+
// was read from disk. Lets a version-mismatched entry be validated by
|
|
20
|
+
// metadata instead of a full corpus re-read (the write path patches the
|
|
21
|
+
// entry in place, so its contents are usually already current).
|
|
22
|
+
stats?: HotCacheStatsSnapshot;
|
|
18
23
|
}
|
|
19
24
|
|
|
25
|
+
/** COS-825: one file's entry in a hot-cache stat snapshot. */
|
|
26
|
+
export interface HotCacheStatEntry {
|
|
27
|
+
mtimeMs: number;
|
|
28
|
+
size: number;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** COS-825: per-file stat snapshot carried by a hot-cache entry. */
|
|
32
|
+
export type HotCacheStatsSnapshot = Map<string, HotCacheStatEntry>;
|
|
33
|
+
|
|
34
|
+
/** COS-825 diagnostics for the hot-memories read path. */
|
|
35
|
+
export const hotCacheReadStats = { validatedHits: 0, fullScans: 0 };
|
|
36
|
+
|
|
20
37
|
// Module-level singleton — shared across all StorageManager instances and sessions
|
|
21
38
|
const hotCacheByDir = new Map<string, CacheEntry>();
|
|
22
39
|
const archiveCacheByDir = new Map<string, CacheEntry>();
|
|
@@ -77,27 +94,76 @@ export function setCachedMemories(
|
|
|
77
94
|
version: number,
|
|
78
95
|
keyId = "",
|
|
79
96
|
ttlMs = 0,
|
|
97
|
+
stats?: HotCacheStatsSnapshot,
|
|
80
98
|
): void {
|
|
81
99
|
const map = new Map<string, MemoryFile>();
|
|
82
100
|
for (const m of memories) map.set(m.path, m);
|
|
83
101
|
const now = Date.now();
|
|
84
|
-
hotCacheByDir.set(baseDir, { memories: map, version, loadedAt: now, keyId, ttlMs });
|
|
102
|
+
hotCacheByDir.set(baseDir, { memories: map, version, loadedAt: now, keyId, ttlMs, stats });
|
|
85
103
|
// Release abandoned corpora that expired but were never revisited (Codex Medium).
|
|
86
104
|
sweepExpiredHotEntries(now);
|
|
87
105
|
}
|
|
88
106
|
|
|
107
|
+
/**
|
|
108
|
+
* COS-825: the raw entry for stat validation. Returns the entry only when its
|
|
109
|
+
* secure-store key identity matches AND it carries a stat snapshot; callers
|
|
110
|
+
* validate the snapshot against disk and then promote via
|
|
111
|
+
* {@link promoteHotCacheVersion}.
|
|
112
|
+
*/
|
|
113
|
+
export function getHotCacheEntry(
|
|
114
|
+
baseDir: string,
|
|
115
|
+
keyId: string,
|
|
116
|
+
): {
|
|
117
|
+
memories: ReadonlyMap<string, MemoryFile>;
|
|
118
|
+
stats: HotCacheStatsSnapshot;
|
|
119
|
+
loadedAt: number;
|
|
120
|
+
} | null {
|
|
121
|
+
const entry = hotCacheByDir.get(baseDir);
|
|
122
|
+
if (!entry || entry.keyId !== keyId || !entry.stats) return null;
|
|
123
|
+
return { memories: entry.memories, stats: entry.stats, loadedAt: entry.loadedAt };
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* COS-825: after stat validation passes, re-key the patched entry to the
|
|
128
|
+
* current corpus version and serve it — the equivalent of a fresh full read
|
|
129
|
+
* without the read. Counts as a validated hit.
|
|
130
|
+
*/
|
|
131
|
+
export function promoteHotCacheVersion(baseDir: string, version: number, keyId: string): MemoryFile[] | null {
|
|
132
|
+
const entry = hotCacheByDir.get(baseDir);
|
|
133
|
+
if (!entry || entry.keyId !== keyId || version === 0) return null;
|
|
134
|
+
entry.version = version;
|
|
135
|
+
// loadedAt is deliberately NOT refreshed: the TTL is the recovery bound for
|
|
136
|
+
// edits that preserve size and mtime, and resetting it here would let
|
|
137
|
+
// repeated version churn defer that fresh scan indefinitely (COS-825 review
|
|
138
|
+
// round 3).
|
|
139
|
+
hotCacheReadStats.validatedHits++;
|
|
140
|
+
return [...entry.memories.values()];
|
|
141
|
+
}
|
|
142
|
+
|
|
89
143
|
export function updateCacheOnWrite(baseDir: string, memory: MemoryFile, keyId = ""): void {
|
|
90
144
|
const entry = hotCacheByDir.get(baseDir);
|
|
91
145
|
// Only mutate an entry that belongs to THIS key identity (issue #1902, Codex
|
|
92
146
|
// Medium). A concurrent differently-keyed manager may have replaced the
|
|
93
147
|
// single hotCacheByDir slot during an awaited parse; inserting our decrypted
|
|
94
148
|
// MemoryFile into its entry would leak plaintext across the key boundary.
|
|
95
|
-
if (entry && entry.keyId === keyId)
|
|
149
|
+
if (entry && entry.keyId === keyId) {
|
|
150
|
+
entry.memories.set(memory.path, memory);
|
|
151
|
+
// COS-825 review: a peer can rewrite the same path between our content
|
|
152
|
+
// write and any stat we take, which would let the snapshot vouch the
|
|
153
|
+
// peer's bytes for our content on every later validation. Drop the
|
|
154
|
+
// snapshot instead: the entry keeps serving at its current version, and
|
|
155
|
+
// the next version churn costs the same full re-read as before this
|
|
156
|
+
// optimization. Never a false pass.
|
|
157
|
+
entry.stats = undefined;
|
|
158
|
+
}
|
|
96
159
|
}
|
|
97
160
|
|
|
98
161
|
export function updateCacheOnDelete(baseDir: string, filePath: string, keyId = ""): void {
|
|
99
162
|
const entry = hotCacheByDir.get(baseDir);
|
|
100
|
-
if (entry && entry.keyId === keyId)
|
|
163
|
+
if (entry && entry.keyId === keyId) {
|
|
164
|
+
entry.memories.delete(filePath);
|
|
165
|
+
entry.stats?.delete(filePath);
|
|
166
|
+
}
|
|
101
167
|
}
|
|
102
168
|
// Archive cache — same pattern, separate store
|
|
103
169
|
export function getCachedArchivedMemories(
|
|
@@ -125,7 +191,23 @@ export function setCachedArchivedMemories(
|
|
|
125
191
|
}
|
|
126
192
|
|
|
127
193
|
// Entity cache — same pattern as memory cache, but keyed by schema-aware parse inputs.
|
|
128
|
-
|
|
194
|
+
// COS-825: validity is the entities-dir listing snapshot (name, mtime, size)
|
|
195
|
+
// carried by the entry, NOT the memory-status version — status churns with
|
|
196
|
+
// unrelated memory lifecycle writes (supersede/archive/cleanup) and used to
|
|
197
|
+
// bust this cache on every recall under observe traffic. Entity-file changes
|
|
198
|
+
// always change the listing (and bump the entity-mutation version, which is
|
|
199
|
+
// part of the caller's cache key).
|
|
200
|
+
interface EntityCacheEntry {
|
|
201
|
+
entities: EntityFile[];
|
|
202
|
+
loadedAt: number;
|
|
203
|
+
/** Snapshot of the entities dir at build time: name -> `${mtimeMs}:${size}`. */
|
|
204
|
+
listing: ReadonlyMap<string, string>;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
const entityCacheByDir = new Map<string, EntityCacheEntry>();
|
|
208
|
+
|
|
209
|
+
/** COS-825 diagnostics: a hit is a served cache entry whose listing validated. */
|
|
210
|
+
export const entityCacheStats = { hits: 0, rebuilds: 0 };
|
|
129
211
|
|
|
130
212
|
/**
|
|
131
213
|
* Single normalization point for the entity-cache schema key (issue #1535).
|
|
@@ -146,26 +228,19 @@ function buildEntityCacheKey(baseDir: string, schemaKey?: string): string {
|
|
|
146
228
|
return `${entityCacheKeyPrefix(baseDir)}${normalizeEntitySchemaKey(schemaKey)}`;
|
|
147
229
|
}
|
|
148
230
|
|
|
149
|
-
export function getCachedEntities(
|
|
150
|
-
baseDir
|
|
151
|
-
currentVersion: number,
|
|
152
|
-
schemaKey: string = "",
|
|
153
|
-
): EntityFile[] | null {
|
|
154
|
-
if (currentVersion === 0) return null;
|
|
155
|
-
const entry = entityCacheByDir.get(buildEntityCacheKey(baseDir, schemaKey));
|
|
156
|
-
if (!entry || entry.version !== currentVersion) return null;
|
|
157
|
-
return entry.entities;
|
|
231
|
+
export function getCachedEntities(baseDir: string, cacheKey: string): EntityCacheEntry | null {
|
|
232
|
+
return entityCacheByDir.get(buildEntityCacheKey(baseDir, cacheKey)) ?? null;
|
|
158
233
|
}
|
|
159
234
|
|
|
160
235
|
export function setCachedEntities(
|
|
161
236
|
baseDir: string,
|
|
162
237
|
entities: EntityFile[],
|
|
163
|
-
|
|
164
|
-
|
|
238
|
+
cacheKey: string,
|
|
239
|
+
listing: ReadonlyMap<string, string>,
|
|
165
240
|
): void {
|
|
166
|
-
entityCacheByDir.set(buildEntityCacheKey(baseDir,
|
|
241
|
+
entityCacheByDir.set(buildEntityCacheKey(baseDir, cacheKey), {
|
|
167
242
|
entities,
|
|
168
|
-
|
|
243
|
+
listing,
|
|
169
244
|
loadedAt: Date.now(),
|
|
170
245
|
});
|
|
171
246
|
}
|
|
@@ -491,6 +566,10 @@ export function clearMemoryCache(baseDir?: string): void {
|
|
|
491
566
|
for (const layer of ALL_CACHE_LAYERS) {
|
|
492
567
|
layer.clearAll();
|
|
493
568
|
}
|
|
569
|
+
hotCacheReadStats.validatedHits = 0;
|
|
570
|
+
hotCacheReadStats.fullScans = 0;
|
|
571
|
+
entityCacheStats.hits = 0;
|
|
572
|
+
entityCacheStats.rebuilds = 0;
|
|
494
573
|
}
|
|
495
574
|
|
|
496
575
|
/**
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* COS-825 — the observe durable-buffer flush is a subset barrier.
|
|
3
|
+
*
|
|
4
|
+
* `ingestReplayBatchBuffered` used to end with a full durability barrier
|
|
5
|
+
* (`flushPendingSave({ throwOnFailure: true })` with no `allowDeferral`), so
|
|
6
|
+
* every observe force-rewrote EVERY dirty session — including large sessions
|
|
7
|
+
* rate-limited by #3389 — and forced the ~1.16 MB admission-idempotency file
|
|
8
|
+
* past its coalescing interval. Under observe traffic that made the
|
|
9
|
+
* durable-buffer stage 10-16 s per request.
|
|
10
|
+
*
|
|
11
|
+
* The fix: the flush forces exactly the sessions this observe admitted (their
|
|
12
|
+
* turns must be durable before the 202) and lets everything else keep its
|
|
13
|
+
* steady-state deferral with the armed retry.
|
|
14
|
+
*/
|
|
15
|
+
import test from "node:test";
|
|
16
|
+
import assert from "node:assert/strict";
|
|
17
|
+
|
|
18
|
+
import { ingestReplayBatchBuffered } from "./orchestration/turn-ingestion-buffered.js";
|
|
19
|
+
import { SmartBuffer } from "./buffer.js";
|
|
20
|
+
import { parseConfig } from "./config.js";
|
|
21
|
+
import { BUFFER_SESSION_DEFER_MIN_BYTES } from "./buffer-persistence.js";
|
|
22
|
+
import type { BufferEntryState, BufferState, BufferTurn } from "./types.js";
|
|
23
|
+
|
|
24
|
+
const BIG_CONTENT = "x".repeat(BUFFER_SESSION_DEFER_MIN_BYTES);
|
|
25
|
+
|
|
26
|
+
function makeTurn(sessionKey: string, content: string): BufferTurn {
|
|
27
|
+
return { role: "user", content, timestamp: "2026-12-02T12:00:00.000Z", sessionKey };
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function bigEntry(): BufferEntryState {
|
|
31
|
+
return { turns: [makeTurn("big", BIG_CONTENT)], lastExtractionAt: null, extractionCount: 0 };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function emptyState(): BufferState {
|
|
35
|
+
return { turns: [], lastExtractionAt: null, extractionCount: 0 };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
class CountingStorage {
|
|
39
|
+
readonly writes = new Map<string, number>();
|
|
40
|
+
private initial: BufferState;
|
|
41
|
+
|
|
42
|
+
constructor(initial: BufferState) {
|
|
43
|
+
this.initial = initial;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
async loadBuffer(): Promise<BufferState> {
|
|
47
|
+
return structuredClone(this.initial);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async saveBuffer(state: BufferState): Promise<void> {
|
|
51
|
+
this.initial = structuredClone(state);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async saveBufferSession(key: string, _entry: BufferEntryState): Promise<void> {
|
|
55
|
+
this.writes.set(key, (this.writes.get(key) ?? 0) + 1);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async deleteBufferSession(): Promise<void> {}
|
|
59
|
+
|
|
60
|
+
isBufferSessionClaimed(): boolean {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
writeCount(key: string): number {
|
|
65
|
+
return this.writes.get(key) ?? 0;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
test("COS-825 the observe ingest does not force unrelated deferred sessions", async () => {
|
|
70
|
+
const state = emptyState();
|
|
71
|
+
state.entries = { big: bigEntry() };
|
|
72
|
+
const storage = new CountingStorage(state);
|
|
73
|
+
const buffer = new SmartBuffer(
|
|
74
|
+
parseConfig({ triggerMode: "every_n", bufferMaxTurns: 1_000, bufferSaveDebounceMs: 0 }),
|
|
75
|
+
storage,
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
await buffer.addTurn("big", makeTurn("big", "more")); // first write lands
|
|
79
|
+
await buffer.addTurn("big", makeTurn("big", "more")); // large + recent: deferred
|
|
80
|
+
assert.equal(storage.writeCount("big"), 1);
|
|
81
|
+
|
|
82
|
+
await ingestReplayBatchBuffered(
|
|
83
|
+
{
|
|
84
|
+
config: parseConfig({ memoryDir: "/tmp/remnic-observe-flush" }),
|
|
85
|
+
buffer,
|
|
86
|
+
lcmEngine: null,
|
|
87
|
+
queueBufferedExtraction: async () => {},
|
|
88
|
+
},
|
|
89
|
+
new Map([["small", [makeTurn("small", "tiny observe turn")]]]),
|
|
90
|
+
{ archiveLcm: false, writeNamespaceOverride: "test-ns" },
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
assert.ok(storage.writeCount("small") >= 1, "the admitted session is durable before the ack");
|
|
94
|
+
assert.equal(storage.writeCount("big"), 1, "the unrelated large session was not forced by the observe");
|
|
95
|
+
|
|
96
|
+
// The deferred tail still lands on a real barrier.
|
|
97
|
+
await buffer.save();
|
|
98
|
+
assert.equal(storage.writeCount("big"), 2, "a full barrier flushes the deferred session");
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
test("COS-825 the observe flush forces a recently-persisted large admitted session", async () => {
|
|
102
|
+
// The review finding: deferral requires lastPersistedAt, so a never-persisted
|
|
103
|
+
// admitted session always writes regardless of forceKeys. Admit into a large
|
|
104
|
+
// session that WAS persisted within the defer interval — the forced path is
|
|
105
|
+
// the only thing keeping its turns durable before the ack.
|
|
106
|
+
const state = emptyState();
|
|
107
|
+
state.entries = { hot: bigEntry() };
|
|
108
|
+
const storage = new CountingStorage(state);
|
|
109
|
+
const buffer = new SmartBuffer(
|
|
110
|
+
parseConfig({ triggerMode: "every_n", bufferMaxTurns: 1_000, bufferSaveDebounceMs: 0 }),
|
|
111
|
+
storage,
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
await buffer.addTurn("hot", makeTurn("hot", "more")); // first write lands (lastPersistedAt set)
|
|
115
|
+
await buffer.addTurn("hot", makeTurn("hot", "more")); // large + recent: deferred, stays dirty
|
|
116
|
+
assert.equal(storage.writeCount("hot"), 1);
|
|
117
|
+
|
|
118
|
+
await ingestReplayBatchBuffered(
|
|
119
|
+
{
|
|
120
|
+
config: parseConfig({ memoryDir: "/tmp/remnic-observe-flush" }),
|
|
121
|
+
buffer,
|
|
122
|
+
lcmEngine: null,
|
|
123
|
+
queueBufferedExtraction: async () => {},
|
|
124
|
+
},
|
|
125
|
+
new Map([["hot", [makeTurn("hot", "more observe turn")]]]),
|
|
126
|
+
{ archiveLcm: false, writeNamespaceOverride: "test-ns" },
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
assert.equal(storage.writeCount("hot"), 2, "the admitted turns of a large recent session are durable before the ack");
|
|
130
|
+
});
|