@remnic/core 10.0.143 → 10.0.145
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/access-admin-ops-surface.js +177 -174
- package/dist/access-cli.js +177 -174
- package/dist/access-cli.js.map +1 -1
- package/dist/access-extraction-force-flush-preempt.js +177 -174
- package/dist/access-extraction-force-flush.js +177 -174
- package/dist/access-http-briefing.js +177 -174
- package/dist/access-http-query.js +177 -174
- package/dist/access-http.js +177 -174
- package/dist/access-identity-continuity-surface.js +177 -174
- package/dist/access-lcm-surface.js +177 -174
- package/dist/access-mcp.js +177 -174
- package/dist/access-observe-write-category.js +9 -9
- package/dist/access-observe-write-surface.d.ts.map +1 -1
- package/dist/access-observe-write-surface.js +177 -174
- package/dist/access-offline-manifest.js +6 -6
- package/dist/access-operations-batch.js +177 -174
- package/dist/access-operations.js +177 -174
- package/dist/access-recall-concurrency.js +177 -174
- package/dist/access-recall-diagnostics.js +2 -2
- package/dist/access-recall-response.js +177 -174
- package/dist/access-recall-surface.js +177 -174
- package/dist/access-schema.js +8 -8
- package/dist/access-service.js +177 -174
- package/dist/active-recall.js +30 -30
- package/dist/adapters/index.js +4 -4
- package/dist/adapters/registry.js +2 -2
- package/dist/briefing.js +22 -22
- package/dist/buffer-add-turns-bounded.d.ts +27 -0
- package/dist/buffer-add-turns-bounded.d.ts.map +1 -0
- package/dist/buffer-add-turns-bounded.js +13 -0
- package/dist/buffer-admission-idempotency.d.ts +18 -0
- package/dist/buffer-admission-idempotency.d.ts.map +1 -0
- package/dist/buffer-admission-idempotency.js +18 -0
- package/dist/buffer-persistence.d.ts +4 -0
- package/dist/buffer-persistence.d.ts.map +1 -1
- package/dist/buffer-persistence.js +1 -1
- package/dist/buffer-turn-helpers.d.ts.map +1 -1
- package/dist/buffer-turn-helpers.js +1 -1
- package/dist/buffer-types.d.ts.map +1 -1
- package/dist/buffer.d.ts +11 -0
- package/dist/buffer.d.ts.map +1 -1
- package/dist/buffer.js +13 -8
- package/dist/calibration.js +3 -3
- package/dist/{capsule-crypto-7FJQINUR.js → capsule-crypto-GWVG7LGC.js} +2 -2
- package/dist/capsule-crypto-GWVG7LGC.js.map +1 -0
- package/dist/causal-behavior.js +2 -2
- package/dist/causal-chain.js +2 -2
- package/dist/causal-consolidation.js +25 -25
- package/dist/causal-retrieval.js +2 -2
- package/dist/causal-trajectory-graph.js +2 -2
- package/dist/causal-trajectory.js +1 -1
- package/dist/{chunk-O5OFHBAP.js → chunk-2UOU6CZZ.js} +2 -2
- package/dist/{chunk-AZFQXYIJ.js → chunk-33VVVP57.js} +9 -2
- package/dist/{chunk-AZFQXYIJ.js.map → chunk-33VVVP57.js.map} +1 -1
- package/dist/{chunk-MX5VGD6C.js → chunk-3DJ6R4CC.js} +4 -4
- package/dist/chunk-3TKX7ZMV.js +27 -0
- package/dist/chunk-3TKX7ZMV.js.map +1 -0
- package/dist/{chunk-HXFIILGF.js → chunk-4RASUAN3.js} +4 -4
- package/dist/{chunk-MZCGHPIJ.js → chunk-4XINO77L.js} +2 -2
- package/dist/{chunk-AHUTHRTL.js → chunk-4Y4LPKFV.js} +6 -6
- package/dist/chunk-5EP2V675.js +60 -0
- package/dist/chunk-5EP2V675.js.map +1 -0
- package/dist/{chunk-2DXDHGLG.js → chunk-5JW2QIFH.js} +11 -11
- package/dist/{chunk-2642VLWP.js → chunk-5LL2X5SO.js} +2 -2
- package/dist/{chunk-YJUZ465J.js → chunk-63MKTHYT.js} +5 -5
- package/dist/{chunk-VKTZXJSR.js → chunk-64TIBZPZ.js} +2 -2
- package/dist/{chunk-4LF5E2LM.js → chunk-66DUCUOC.js} +4 -4
- package/dist/{chunk-LL7WIK2Z.js → chunk-6NPLVV6M.js} +2 -2
- package/dist/{chunk-GOZXQNIM.js → chunk-6P7U3HWG.js} +3 -3
- package/dist/{chunk-PKPW7MXT.js → chunk-7TDJZV2S.js} +2 -2
- package/dist/{chunk-TJE4LIVD.js → chunk-7TY5ZHFA.js} +2 -2
- package/dist/chunk-7ZFB4VZS.js +73 -0
- package/dist/chunk-7ZFB4VZS.js.map +1 -0
- package/dist/{chunk-B4I37XX6.js → chunk-ADBON4FI.js} +14 -14
- package/dist/{chunk-NFNH4ZPB.js → chunk-BKR2YCQ5.js} +2 -2
- package/dist/{chunk-KQAFEZQX.js → chunk-BUKK5SWA.js} +2 -2
- package/dist/{chunk-2JAT4S7N.js → chunk-CIEEYVUB.js} +2 -2
- package/dist/{chunk-CPWZGM4E.js → chunk-D3ZISMKY.js} +14 -14
- package/dist/{chunk-LYPBQHAX.js → chunk-DBNZYQCL.js} +2 -2
- package/dist/{chunk-MSVBNOFX.js → chunk-DCLOMXQL.js} +25 -22
- package/dist/chunk-DCLOMXQL.js.map +1 -0
- package/dist/{chunk-C7CP7OEG.js → chunk-DK3T3Q6A.js} +11 -11
- package/dist/{chunk-RJ5L6LRD.js → chunk-DLR3SBOM.js} +4 -4
- package/dist/{chunk-P3COXHWB.js → chunk-E7WMDXAW.js} +2 -2
- package/dist/{chunk-ZANNIXXE.js → chunk-ENPJX3BB.js} +3 -3
- package/dist/{chunk-DVC2OYLF.js → chunk-ETUMOYGL.js} +2 -2
- package/dist/{chunk-3DAWHP5K.js → chunk-F4ZHKDBW.js} +5 -5
- package/dist/{chunk-W236BAJR.js → chunk-FBV4QGXT.js} +2 -2
- package/dist/{chunk-GOT6G3C6.js → chunk-FZ6QUOTL.js} +2 -2
- package/dist/{chunk-OM2YWPFX.js → chunk-G2TK5YYU.js} +2 -2
- package/dist/{chunk-MBBRU5LJ.js → chunk-G3ZUQZGM.js} +2 -2
- package/dist/{chunk-IIVDGKMW.js → chunk-GA3Y7GZR.js} +2 -2
- package/dist/{chunk-AWKD2A73.js → chunk-GB442ZFG.js} +8 -8
- package/dist/{chunk-NIG54XKA.js → chunk-GDREJ32D.js} +3 -3
- package/dist/{chunk-VEFGHRKV.js → chunk-GKL6QYZO.js} +1 -1
- package/dist/{chunk-TD72RHHZ.js → chunk-GQDO6KHO.js} +2 -2
- package/dist/{chunk-HQV5GCMD.js → chunk-GTW6GPQU.js} +3 -3
- package/dist/{chunk-2M7F2I7I.js → chunk-HASIFVWH.js} +2 -2
- package/dist/{chunk-72QMGTDF.js → chunk-IBPE3Q5M.js} +2 -2
- package/dist/{chunk-YLTU2DC4.js → chunk-IHCXMYSE.js} +2 -2
- package/dist/{chunk-WWQMZBDI.js → chunk-IJVU4ILJ.js} +4 -4
- package/dist/{chunk-NKO4VZRO.js → chunk-JOQZRIL4.js} +2 -2
- package/dist/{chunk-PBE7NFB5.js → chunk-K3FH3LAQ.js} +7 -7
- package/dist/{chunk-HQJAQENN.js → chunk-KBMJWNSY.js} +2 -2
- package/dist/{chunk-GCQIXPWZ.js → chunk-KCU2ZWBS.js} +2 -2
- package/dist/{chunk-JVNGFQJN.js → chunk-KJ3Z7JHF.js} +1 -1
- package/dist/{chunk-JVNGFQJN.js.map → chunk-KJ3Z7JHF.js.map} +1 -1
- package/dist/{chunk-JKYAKDBP.js → chunk-KYZFW4LW.js} +2 -2
- package/dist/{chunk-L6CMR5OI.js → chunk-L2DACC2T.js} +2 -2
- package/dist/{chunk-SFHEIWIE.js → chunk-LMFINE37.js} +2 -2
- package/dist/{chunk-5XONJ5C4.js → chunk-LS5VJO5O.js} +2 -2
- package/dist/{chunk-CPYVH6LI.js → chunk-LYSE5FNF.js} +43 -48
- package/dist/chunk-LYSE5FNF.js.map +1 -0
- package/dist/{chunk-DC55RIEZ.js → chunk-M4IEZGCK.js} +4 -4
- package/dist/{chunk-7SUAHTGH.js → chunk-MEYPQLXV.js} +2 -2
- package/dist/{chunk-KETT3EZO.js → chunk-MONIOXEG.js} +2 -2
- package/dist/{chunk-5IGWEYNV.js → chunk-MVTMKFBW.js} +3 -3
- package/dist/{chunk-22M7NYJK.js → chunk-ODHFX5JX.js} +3 -3
- package/dist/{chunk-I3UBDUHO.js → chunk-OMPX3KLG.js} +2 -2
- package/dist/{chunk-2NLLXCJG.js → chunk-OWHERGF2.js} +2 -2
- package/dist/{chunk-YXPUQBHK.js → chunk-P4YYUDR5.js} +3 -3
- package/dist/{chunk-77SYM565.js → chunk-PDVEY4QS.js} +2 -2
- package/dist/{chunk-LE27GU4M.js → chunk-QCJ7Q5BM.js} +2 -2
- package/dist/{chunk-RVPISCKY.js → chunk-QFBBSKEU.js} +2 -2
- package/dist/{chunk-YCNSMVWG.js → chunk-SDGD6MYV.js} +64 -3
- package/dist/chunk-SDGD6MYV.js.map +1 -0
- package/dist/{chunk-CSZCLTIV.js → chunk-SEIFDQ6U.js} +6 -6
- package/dist/{chunk-ITT4SVVA.js → chunk-SV6OLWPF.js} +14 -14
- package/dist/{chunk-A7SU5ET7.js → chunk-T3M5KJRV.js} +2 -2
- package/dist/{chunk-QBNZLS3U.js → chunk-TFHL4WWY.js} +2 -2
- package/dist/{chunk-4Y26S76X.js → chunk-TRFSTCQK.js} +14 -2
- package/dist/chunk-TRFSTCQK.js.map +1 -0
- package/dist/{chunk-F3PTUQIK.js → chunk-U62EINFH.js} +3 -3
- package/dist/{chunk-OZNBZJ3S.js → chunk-UIFWZMO7.js} +23 -23
- package/dist/{chunk-X7Y7WX73.js → chunk-UVYI6VIX.js} +1 -1
- package/dist/{chunk-VNMJWFYR.js → chunk-UWP6PGWN.js} +2 -2
- package/dist/{chunk-2VS3DAXE.js → chunk-V3D2OOVE.js} +2 -2
- package/dist/{chunk-UH3FPX3L.js → chunk-W7K5BP3M.js} +2 -2
- package/dist/{chunk-TAUHAP5J.js → chunk-WN2DASTS.js} +5 -5
- package/dist/{chunk-TFA6HPOA.js → chunk-WQUGCOKF.js} +4 -4
- package/dist/{chunk-OOJMQV3L.js → chunk-X2FEUBKD.js} +2 -2
- package/dist/{chunk-XF2QQQXO.js → chunk-XIWRF7TG.js} +2 -2
- package/dist/{chunk-BFFKIME2.js → chunk-YGPRFYV6.js} +3 -3
- package/dist/{chunk-SU63UQPL.js → chunk-YIOP7IFD.js} +2 -2
- package/dist/{chunk-EZ25VE3G.js → chunk-YNDLCWXS.js} +4 -4
- package/dist/{chunk-ZNYOY2MM.js → chunk-Z2OKWO35.js} +381 -366
- package/dist/chunk-Z2OKWO35.js.map +1 -0
- package/dist/{chunk-FAPJG3OG.js → chunk-ZDZJNXL6.js} +4 -4
- package/dist/cli.js +177 -174
- package/dist/coding/export-okf-codegraph.js +21 -21
- package/dist/coding/pre-action-gate.js +2 -2
- package/dist/compounding/engine.js +23 -23
- package/dist/config.js +30 -30
- package/dist/connectors/codex-materialize-runner.js +22 -22
- package/dist/connectors/index.js +22 -22
- package/dist/convergence-refresh.js +24 -24
- package/dist/conversation-index/backend.js +2 -2
- package/dist/corpus-watermark.js +24 -24
- package/dist/dashboard-runtime.js +2 -2
- package/dist/deep-recall-http-glue.js +9 -9
- package/dist/deep-recall.js +2 -2
- package/dist/entity-retrieval.js +24 -24
- package/dist/event-order-recall.js +4 -4
- package/dist/explicit-capture.js +177 -174
- package/dist/extraction.js +30 -30
- package/dist/{graph-edge-decay-EKWXRBWF.js → graph-edge-decay-OEX5OGMI.js} +5 -5
- package/dist/graph-edge-decay-OEX5OGMI.js.map +1 -0
- package/dist/graph-jsonl.js +3 -3
- package/dist/graph-snapshot.js +3 -3
- package/dist/graph.js +2 -2
- package/dist/harmonic-retrieval.js +22 -22
- package/dist/index.js +247 -244
- package/dist/lcm/engine.js +3 -3
- package/dist/lcm/index.js +6 -6
- package/dist/lcm-summarize-budget.d.ts +13 -0
- package/dist/lcm-summarize-budget.d.ts.map +1 -0
- package/dist/lcm-summarize-budget.js +11 -0
- package/dist/lcm-summarize-budget.js.map +1 -0
- package/dist/local-llm.js +3 -3
- package/dist/location/index.js +23 -23
- package/dist/maintenance/memory-governance.js +22 -22
- package/dist/maintenance/rebuild-memory-lifecycle-ledger.js +22 -22
- package/dist/maintenance/rebuild-memory-projection-runner.js +24 -24
- package/dist/maintenance/rebuild-memory-projection.js +23 -23
- package/dist/memory-browse.js +5 -5
- package/dist/namespaces/migrate.js +23 -23
- package/dist/namespaces/search.js +11 -11
- package/dist/namespaces/storage.js +22 -22
- package/dist/offline-sync-changeset-generations.js +4 -4
- package/dist/offline-sync-embedding-generation.js +3 -3
- package/dist/offline-sync-snapshot-stream.js +6 -6
- package/dist/offline-sync.js +8 -8
- package/dist/operator-doctor-corpus.js +25 -25
- package/dist/operator-toolkit.js +39 -39
- package/dist/orchestration/backlog-scheduler.js +178 -175
- package/dist/orchestration/backlog-scheduler.js.map +1 -1
- package/dist/orchestration/buffer-drain-runner.js +178 -175
- package/dist/orchestration/maintenance.js +33 -33
- package/dist/orchestration/turn-ingestion-buffered.d.ts +13 -0
- package/dist/orchestration/turn-ingestion-buffered.d.ts.map +1 -0
- package/dist/orchestration/turn-ingestion.d.ts +2 -2
- package/dist/orchestration/turn-ingestion.d.ts.map +1 -1
- package/dist/orchestrator.d.ts.map +1 -1
- package/dist/orchestrator.js +177 -174
- package/dist/qmd.js +4 -4
- 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 +177 -174
- 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/resume-bundles.js +31 -31
- package/dist/search/factory.js +10 -10
- package/dist/search/index.js +14 -14
- 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 +23 -23
- package/dist/semantic-rule-promotion.js +22 -22
- package/dist/semantic-rule-verifier.js +22 -22
- package/dist/source-agent-qualifier.js +25 -25
- package/dist/standup/build.js +22 -22
- package/dist/storage/buffer-drain-claims.js +2 -2
- package/dist/storage/buffer-session-files.d.ts +4 -0
- package/dist/storage/buffer-session-files.d.ts.map +1 -1
- package/dist/storage/buffer-session-files.js +2 -2
- package/dist/storage.d.ts +1 -0
- package/dist/storage.d.ts.map +1 -1
- package/dist/storage.js +22 -22
- package/dist/summarizer.js +4 -4
- package/dist/support-passport/index.js +4 -4
- package/dist/transfer/backup.js +2 -2
- package/dist/transfer/capsule-export.js +2 -2
- package/dist/transfer/capsule-import.js +2 -2
- package/dist/transfer/export-okf.js +23 -23
- 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 +22 -22
- package/dist/who-knows-cli.js +23 -23
- package/dist/who-knows.js +22 -22
- package/package.json +2 -2
- package/src/access-observe-write-surface.ts +10 -0
- package/src/buffer-add-turns-bounded.ts +97 -0
- package/src/buffer-admission-idempotency.test.ts +297 -0
- package/src/buffer-admission-idempotency.ts +67 -0
- package/src/buffer-drain-handover.test.ts +1 -0
- package/src/buffer-persistence.ts +19 -1
- package/src/buffer-turn-helpers.ts +8 -1
- package/src/buffer-types.ts +1 -0
- package/src/buffer.ts +40 -43
- package/src/lcm-summarize-budget.test.ts +66 -0
- package/src/lcm-summarize-budget.ts +34 -0
- package/src/orchestration/turn-ingestion-buffered.ts +74 -0
- package/src/orchestration/turn-ingestion.ts +4 -78
- package/src/orchestrator.ts +8 -5
- package/src/storage/buffer-session-files.ts +71 -0
- package/src/storage.ts +1 -0
- package/src/types.ts +2 -0
- package/dist/chunk-4Y26S76X.js.map +0 -1
- package/dist/chunk-CPYVH6LI.js.map +0 -1
- package/dist/chunk-MSVBNOFX.js.map +0 -1
- package/dist/chunk-YCNSMVWG.js.map +0 -1
- package/dist/chunk-ZNYOY2MM.js.map +0 -1
- /package/dist/{capsule-crypto-7FJQINUR.js.map → buffer-add-turns-bounded.js.map} +0 -0
- /package/dist/{graph-edge-decay-EKWXRBWF.js.map → buffer-admission-idempotency.js.map} +0 -0
- /package/dist/{chunk-O5OFHBAP.js.map → chunk-2UOU6CZZ.js.map} +0 -0
- /package/dist/{chunk-MX5VGD6C.js.map → chunk-3DJ6R4CC.js.map} +0 -0
- /package/dist/{chunk-HXFIILGF.js.map → chunk-4RASUAN3.js.map} +0 -0
- /package/dist/{chunk-MZCGHPIJ.js.map → chunk-4XINO77L.js.map} +0 -0
- /package/dist/{chunk-AHUTHRTL.js.map → chunk-4Y4LPKFV.js.map} +0 -0
- /package/dist/{chunk-2DXDHGLG.js.map → chunk-5JW2QIFH.js.map} +0 -0
- /package/dist/{chunk-2642VLWP.js.map → chunk-5LL2X5SO.js.map} +0 -0
- /package/dist/{chunk-YJUZ465J.js.map → chunk-63MKTHYT.js.map} +0 -0
- /package/dist/{chunk-VKTZXJSR.js.map → chunk-64TIBZPZ.js.map} +0 -0
- /package/dist/{chunk-4LF5E2LM.js.map → chunk-66DUCUOC.js.map} +0 -0
- /package/dist/{chunk-LL7WIK2Z.js.map → chunk-6NPLVV6M.js.map} +0 -0
- /package/dist/{chunk-GOZXQNIM.js.map → chunk-6P7U3HWG.js.map} +0 -0
- /package/dist/{chunk-PKPW7MXT.js.map → chunk-7TDJZV2S.js.map} +0 -0
- /package/dist/{chunk-TJE4LIVD.js.map → chunk-7TY5ZHFA.js.map} +0 -0
- /package/dist/{chunk-B4I37XX6.js.map → chunk-ADBON4FI.js.map} +0 -0
- /package/dist/{chunk-NFNH4ZPB.js.map → chunk-BKR2YCQ5.js.map} +0 -0
- /package/dist/{chunk-KQAFEZQX.js.map → chunk-BUKK5SWA.js.map} +0 -0
- /package/dist/{chunk-2JAT4S7N.js.map → chunk-CIEEYVUB.js.map} +0 -0
- /package/dist/{chunk-CPWZGM4E.js.map → chunk-D3ZISMKY.js.map} +0 -0
- /package/dist/{chunk-LYPBQHAX.js.map → chunk-DBNZYQCL.js.map} +0 -0
- /package/dist/{chunk-C7CP7OEG.js.map → chunk-DK3T3Q6A.js.map} +0 -0
- /package/dist/{chunk-RJ5L6LRD.js.map → chunk-DLR3SBOM.js.map} +0 -0
- /package/dist/{chunk-P3COXHWB.js.map → chunk-E7WMDXAW.js.map} +0 -0
- /package/dist/{chunk-ZANNIXXE.js.map → chunk-ENPJX3BB.js.map} +0 -0
- /package/dist/{chunk-DVC2OYLF.js.map → chunk-ETUMOYGL.js.map} +0 -0
- /package/dist/{chunk-3DAWHP5K.js.map → chunk-F4ZHKDBW.js.map} +0 -0
- /package/dist/{chunk-W236BAJR.js.map → chunk-FBV4QGXT.js.map} +0 -0
- /package/dist/{chunk-GOT6G3C6.js.map → chunk-FZ6QUOTL.js.map} +0 -0
- /package/dist/{chunk-OM2YWPFX.js.map → chunk-G2TK5YYU.js.map} +0 -0
- /package/dist/{chunk-MBBRU5LJ.js.map → chunk-G3ZUQZGM.js.map} +0 -0
- /package/dist/{chunk-IIVDGKMW.js.map → chunk-GA3Y7GZR.js.map} +0 -0
- /package/dist/{chunk-AWKD2A73.js.map → chunk-GB442ZFG.js.map} +0 -0
- /package/dist/{chunk-NIG54XKA.js.map → chunk-GDREJ32D.js.map} +0 -0
- /package/dist/{chunk-VEFGHRKV.js.map → chunk-GKL6QYZO.js.map} +0 -0
- /package/dist/{chunk-TD72RHHZ.js.map → chunk-GQDO6KHO.js.map} +0 -0
- /package/dist/{chunk-HQV5GCMD.js.map → chunk-GTW6GPQU.js.map} +0 -0
- /package/dist/{chunk-2M7F2I7I.js.map → chunk-HASIFVWH.js.map} +0 -0
- /package/dist/{chunk-72QMGTDF.js.map → chunk-IBPE3Q5M.js.map} +0 -0
- /package/dist/{chunk-YLTU2DC4.js.map → chunk-IHCXMYSE.js.map} +0 -0
- /package/dist/{chunk-WWQMZBDI.js.map → chunk-IJVU4ILJ.js.map} +0 -0
- /package/dist/{chunk-NKO4VZRO.js.map → chunk-JOQZRIL4.js.map} +0 -0
- /package/dist/{chunk-PBE7NFB5.js.map → chunk-K3FH3LAQ.js.map} +0 -0
- /package/dist/{chunk-HQJAQENN.js.map → chunk-KBMJWNSY.js.map} +0 -0
- /package/dist/{chunk-GCQIXPWZ.js.map → chunk-KCU2ZWBS.js.map} +0 -0
- /package/dist/{chunk-JKYAKDBP.js.map → chunk-KYZFW4LW.js.map} +0 -0
- /package/dist/{chunk-L6CMR5OI.js.map → chunk-L2DACC2T.js.map} +0 -0
- /package/dist/{chunk-SFHEIWIE.js.map → chunk-LMFINE37.js.map} +0 -0
- /package/dist/{chunk-5XONJ5C4.js.map → chunk-LS5VJO5O.js.map} +0 -0
- /package/dist/{chunk-DC55RIEZ.js.map → chunk-M4IEZGCK.js.map} +0 -0
- /package/dist/{chunk-7SUAHTGH.js.map → chunk-MEYPQLXV.js.map} +0 -0
- /package/dist/{chunk-KETT3EZO.js.map → chunk-MONIOXEG.js.map} +0 -0
- /package/dist/{chunk-5IGWEYNV.js.map → chunk-MVTMKFBW.js.map} +0 -0
- /package/dist/{chunk-22M7NYJK.js.map → chunk-ODHFX5JX.js.map} +0 -0
- /package/dist/{chunk-I3UBDUHO.js.map → chunk-OMPX3KLG.js.map} +0 -0
- /package/dist/{chunk-2NLLXCJG.js.map → chunk-OWHERGF2.js.map} +0 -0
- /package/dist/{chunk-YXPUQBHK.js.map → chunk-P4YYUDR5.js.map} +0 -0
- /package/dist/{chunk-77SYM565.js.map → chunk-PDVEY4QS.js.map} +0 -0
- /package/dist/{chunk-LE27GU4M.js.map → chunk-QCJ7Q5BM.js.map} +0 -0
- /package/dist/{chunk-RVPISCKY.js.map → chunk-QFBBSKEU.js.map} +0 -0
- /package/dist/{chunk-CSZCLTIV.js.map → chunk-SEIFDQ6U.js.map} +0 -0
- /package/dist/{chunk-ITT4SVVA.js.map → chunk-SV6OLWPF.js.map} +0 -0
- /package/dist/{chunk-A7SU5ET7.js.map → chunk-T3M5KJRV.js.map} +0 -0
- /package/dist/{chunk-QBNZLS3U.js.map → chunk-TFHL4WWY.js.map} +0 -0
- /package/dist/{chunk-F3PTUQIK.js.map → chunk-U62EINFH.js.map} +0 -0
- /package/dist/{chunk-OZNBZJ3S.js.map → chunk-UIFWZMO7.js.map} +0 -0
- /package/dist/{chunk-X7Y7WX73.js.map → chunk-UVYI6VIX.js.map} +0 -0
- /package/dist/{chunk-VNMJWFYR.js.map → chunk-UWP6PGWN.js.map} +0 -0
- /package/dist/{chunk-2VS3DAXE.js.map → chunk-V3D2OOVE.js.map} +0 -0
- /package/dist/{chunk-UH3FPX3L.js.map → chunk-W7K5BP3M.js.map} +0 -0
- /package/dist/{chunk-TAUHAP5J.js.map → chunk-WN2DASTS.js.map} +0 -0
- /package/dist/{chunk-TFA6HPOA.js.map → chunk-WQUGCOKF.js.map} +0 -0
- /package/dist/{chunk-OOJMQV3L.js.map → chunk-X2FEUBKD.js.map} +0 -0
- /package/dist/{chunk-XF2QQQXO.js.map → chunk-XIWRF7TG.js.map} +0 -0
- /package/dist/{chunk-BFFKIME2.js.map → chunk-YGPRFYV6.js.map} +0 -0
- /package/dist/{chunk-SU63UQPL.js.map → chunk-YIOP7IFD.js.map} +0 -0
- /package/dist/{chunk-EZ25VE3G.js.map → chunk-YNDLCWXS.js.map} +0 -0
- /package/dist/{chunk-FAPJG3OG.js.map → chunk-ZDZJNXL6.js.map} +0 -0
|
@@ -453,12 +453,19 @@ export function normalizeBufferState(state: BufferState): BufferState {
|
|
|
453
453
|
extractionCount: state.extractionCount ?? 0,
|
|
454
454
|
};
|
|
455
455
|
}
|
|
456
|
-
|
|
456
|
+
const normalized: BufferState = {
|
|
457
457
|
turns: entries.default.turns,
|
|
458
458
|
lastExtractionAt: entries.default.lastExtractionAt,
|
|
459
459
|
extractionCount: entries.default.extractionCount,
|
|
460
460
|
entries,
|
|
461
461
|
};
|
|
462
|
+
if (state.admissionIdempotency) {
|
|
463
|
+
normalized.admissionIdempotency = Object.assign(Object.create(null), state.admissionIdempotency);
|
|
464
|
+
if (state.admissionIdempotencyOrder) {
|
|
465
|
+
normalized.admissionIdempotencyOrder = [...state.admissionIdempotencyOrder];
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
return normalized;
|
|
462
469
|
}
|
|
463
470
|
|
|
464
471
|
/** Trigger-mode decision for a buffer entry (extracted from SmartBuffer to
|
package/src/buffer-types.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/** Types split out of buffer.ts (structural ratchet, issue #1995). */
|
|
2
2
|
|
|
3
3
|
import type { BufferTurn, CodingContext, SignalLevel } from "./types.js";
|
|
4
|
+
|
|
4
5
|
import type { ResolvedScopeProfilePlan } from "./namespaces/scope-profiles.js";
|
|
5
6
|
|
|
6
7
|
export type TriggerDecision = "extract_now" | "extract_batch" | "keep_buffering";
|
package/src/buffer.ts
CHANGED
|
@@ -36,7 +36,8 @@ import {
|
|
|
36
36
|
} from "./buffer-turn-helpers.js";
|
|
37
37
|
import { BufferAdmissionRefusedError, BufferSessionTurnRefusedError, canAdmitNewEntryUnlocked } from "./buffer-admission.js";
|
|
38
38
|
import { BufferIngressCounters } from "./buffer-ingress-counters.js";
|
|
39
|
-
import {
|
|
39
|
+
import { addTurnsBoundedWithAdmissionKey, type AddTurnsBoundedHost } from "./buffer-add-turns-bounded.js";
|
|
40
|
+
import { refuseOverCapSingle, resolveMaxTurnsPerSession, sessionTurnCapReached } from "./buffer-session-cap.js";
|
|
40
41
|
export { BufferAdmissionRefusedError, BufferSessionTurnRefusedError } from "./buffer-admission.js";
|
|
41
42
|
import type { AddTurnMutationResult, AddTurnOutcome, RetainedTurnCleanupOptions, TriggerDecision } from "./buffer-types.js";
|
|
42
43
|
|
|
@@ -48,6 +49,7 @@ import type { BufferSurpriseProbe, SurpriseTelemetryQueueEntry } from "./buffer-
|
|
|
48
49
|
// Raised from 200 in #3303: live captures were being dropped at busy hours
|
|
49
50
|
// while the single extraction worker drained a backlog.
|
|
50
51
|
const FALLBACK_MAX_BUFFER_SESSIONS = 1000;
|
|
52
|
+
export { BUFFER_ADMISSION_IDEMPOTENCY_CAP } from "./buffer-admission-idempotency.js";
|
|
51
53
|
|
|
52
54
|
/**
|
|
53
55
|
* Upper bound on how long a debounced buffer save may be deferred under
|
|
@@ -510,52 +512,47 @@ export class SmartBuffer {
|
|
|
510
512
|
* Preflight every new key under the mutation lock before persisting any
|
|
511
513
|
* turn; refusal records nothing and drops nothing.
|
|
512
514
|
*/
|
|
515
|
+
|
|
516
|
+
private addTurnsBoundedHost(): AddTurnsBoundedHost {
|
|
517
|
+
const self = this;
|
|
518
|
+
return {
|
|
519
|
+
get config() {
|
|
520
|
+
return self.config;
|
|
521
|
+
},
|
|
522
|
+
get maxSessionEntries() {
|
|
523
|
+
return self.maxSessionEntries;
|
|
524
|
+
},
|
|
525
|
+
get state() {
|
|
526
|
+
return self.state;
|
|
527
|
+
},
|
|
528
|
+
get persistence() {
|
|
529
|
+
return self.persistence;
|
|
530
|
+
},
|
|
531
|
+
get ingress() {
|
|
532
|
+
return self.ingress;
|
|
533
|
+
},
|
|
534
|
+
enqueueMutation: (work) => self.enqueueMutation(work),
|
|
535
|
+
loadUnlocked: () => self.loadUnlocked(),
|
|
536
|
+
peekEntry: (bufferKey) => self.peekEntry(bufferKey),
|
|
537
|
+
recordTurnUnlocked: (bufferKey, turn) => self.recordTurnUnlocked(bufferKey, turn),
|
|
538
|
+
completeAddTurnOutcome: (bufferKey, turn, mutation) =>
|
|
539
|
+
self.completeAddTurnOutcome(bufferKey, turn, mutation),
|
|
540
|
+
};
|
|
541
|
+
}
|
|
542
|
+
|
|
513
543
|
async addTurnsBounded(
|
|
514
544
|
batches: readonly { bufferKey: string; turns: readonly BufferTurn[] }[],
|
|
515
545
|
): Promise<Array<{ bufferKey: string; turn: BufferTurn; outcome: AddTurnOutcome }> | null> {
|
|
516
|
-
const
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
for (const batch of batches) {
|
|
520
|
-
for (const turn of batch.turns) {
|
|
521
|
-
additions.push({ bufferKey: batch.bufferKey, turn });
|
|
522
|
-
}
|
|
523
|
-
}
|
|
524
|
-
|
|
525
|
-
if (refuseOverCapBatch((key) => this.peekEntry(key), batches, resolveMaxTurnsPerSession(this.config.bufferMaxTurnsPerSession))) return this.ingress.refuseAll(additions);
|
|
526
|
-
const entries = this.state.entries ?? {};
|
|
527
|
-
const newKeys = [...new Set(
|
|
528
|
-
additions
|
|
529
|
-
.map(({ bufferKey }) => bufferKey)
|
|
530
|
-
.filter((bufferKey) => this.peekEntry(bufferKey) === null),
|
|
531
|
-
)];
|
|
532
|
-
const count = Object.keys(entries).length;
|
|
533
|
-
const requiredEvictions = Math.max(0, count + newKeys.length - this.maxSessionEntries);
|
|
534
|
-
if (requiredEvictions > 0) {
|
|
535
|
-
const target = Math.max(0, this.maxSessionEntries - newKeys.length);
|
|
536
|
-
const evicted = selectEvictedBufferKeys(entries, newKeys, target, EVICTION_HOOKS);
|
|
537
|
-
if (newKeys.length > 0 && evicted.length < requiredEvictions) return this.ingress.refuseAll(additions);
|
|
538
|
-
for (const key of evicted) delete entries[key];
|
|
539
|
-
this.persistence.markEvicted(evicted);
|
|
540
|
-
}
|
|
541
|
-
|
|
542
|
-
const recorded: Array<{ bufferKey: string; turn: BufferTurn; mutation: AddTurnMutationResult }> = [];
|
|
543
|
-
for (const { bufferKey, turn } of additions) {
|
|
544
|
-
recorded.push({ bufferKey, turn, mutation: await this.recordTurnUnlocked(bufferKey, turn) });
|
|
545
|
-
}
|
|
546
|
-
return recorded;
|
|
547
|
-
});
|
|
548
|
-
if (pending === null) return null;
|
|
546
|
+
const result = await addTurnsBoundedWithAdmissionKey(this.addTurnsBoundedHost(), batches);
|
|
547
|
+
return result === "duplicate" ? null : result;
|
|
548
|
+
}
|
|
549
549
|
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
});
|
|
557
|
-
}
|
|
558
|
-
return outcomes;
|
|
550
|
+
/** #3368 durable observe replay only; duplicate means the scoped client key already landed. */
|
|
551
|
+
async addTurnsBoundedForObserveReplay(
|
|
552
|
+
batches: readonly { bufferKey: string; turns: readonly BufferTurn[] }[],
|
|
553
|
+
admissionKey: string,
|
|
554
|
+
): Promise<Array<{ bufferKey: string; turn: BufferTurn; outcome: AddTurnOutcome }> | null | "duplicate"> {
|
|
555
|
+
return addTurnsBoundedWithAdmissionKey(this.addTurnsBoundedHost(), batches, admissionKey.trim());
|
|
559
556
|
}
|
|
560
557
|
|
|
561
558
|
/** Free one slot only when an empty entry can be reclaimed. */
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
|
|
4
|
+
import { LCM_SUMMARIZE_PROMPT_MAX_CHARS, scaleLcmSummarizeBudget } from "./lcm-summarize-budget.js";
|
|
5
|
+
import { estimateTokenCount } from "./token-estimate.js";
|
|
6
|
+
|
|
7
|
+
test("#3407 truncates summarize max_tokens when prompt text is sliced", () => {
|
|
8
|
+
const filler = "word ".repeat(4000);
|
|
9
|
+
const fullText = filler + "x".repeat(LCM_SUMMARIZE_PROMPT_MAX_CHARS + 50_000);
|
|
10
|
+
const batchTokens = estimateTokenCount(fullText);
|
|
11
|
+
const targetTokens = Math.max(64, Math.ceil(batchTokens * 0.25));
|
|
12
|
+
const budget = scaleLcmSummarizeBudget(fullText, targetTokens);
|
|
13
|
+
assert.equal(budget.promptText.length, LCM_SUMMARIZE_PROMPT_MAX_CHARS);
|
|
14
|
+
assert.ok(
|
|
15
|
+
budget.effectiveTargetTokens < targetTokens,
|
|
16
|
+
`expected scaled target (${budget.effectiveTargetTokens}) < batch target (${targetTokens})`,
|
|
17
|
+
);
|
|
18
|
+
assert.ok(
|
|
19
|
+
budget.maxCompletionTokens <= targetTokens,
|
|
20
|
+
`max completion tokens ${budget.maxCompletionTokens} should not exceed unscaled target*2 ${targetTokens * 2}`,
|
|
21
|
+
);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test("#3407 leaves short batches unchanged", () => {
|
|
25
|
+
const text = "short lcm batch";
|
|
26
|
+
const targetTokens = 128;
|
|
27
|
+
const budget = scaleLcmSummarizeBudget(text, targetTokens);
|
|
28
|
+
assert.equal(budget.promptText, text);
|
|
29
|
+
assert.equal(budget.effectiveTargetTokens, targetTokens);
|
|
30
|
+
assert.equal(budget.maxCompletionTokens, targetTokens * 2);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test("#3407 aggressive retry keeps halved target (32 stays 32)", () => {
|
|
34
|
+
const text = "short lcm batch";
|
|
35
|
+
const normal = scaleLcmSummarizeBudget(text, 64);
|
|
36
|
+
assert.equal(normal.effectiveTargetTokens, 64);
|
|
37
|
+
const aggressiveInput = Math.max(32, Math.ceil(normal.effectiveTargetTokens * 0.5));
|
|
38
|
+
assert.equal(aggressiveInput, 32);
|
|
39
|
+
const aggressive = scaleLcmSummarizeBudget(text, aggressiveInput);
|
|
40
|
+
assert.equal(aggressive.effectiveTargetTokens, 32);
|
|
41
|
+
assert.ok(aggressive.effectiveTargetTokens < normal.effectiveTargetTokens);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test("#3407 unscaled 32-token target passes through on short batch", () => {
|
|
45
|
+
const budget = scaleLcmSummarizeBudget("short lcm batch", 32);
|
|
46
|
+
assert.equal(budget.effectiveTargetTokens, 32);
|
|
47
|
+
assert.equal(budget.maxCompletionTokens, 64);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test("#3407 120k-char batch at target 64 does not collapse below 64", () => {
|
|
51
|
+
const fullText = "word ".repeat(30_000);
|
|
52
|
+
const budget = scaleLcmSummarizeBudget(fullText, 64);
|
|
53
|
+
assert.equal(budget.promptText.length, LCM_SUMMARIZE_PROMPT_MAX_CHARS);
|
|
54
|
+
assert.equal(budget.effectiveTargetTokens, 64);
|
|
55
|
+
assert.equal(budget.maxCompletionTokens, 128);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
test("#3407 truncated 12k-char batch scales below batch target", () => {
|
|
59
|
+
const filler = "word ".repeat(4000);
|
|
60
|
+
const fullText = filler + "z".repeat(80_000);
|
|
61
|
+
const batchTokens = estimateTokenCount(fullText);
|
|
62
|
+
const targetTokens = Math.max(64, Math.ceil(batchTokens * 0.25));
|
|
63
|
+
const budget = scaleLcmSummarizeBudget(fullText, targetTokens);
|
|
64
|
+
assert.equal(budget.promptText.length, LCM_SUMMARIZE_PROMPT_MAX_CHARS);
|
|
65
|
+
assert.ok(budget.effectiveTargetTokens < targetTokens);
|
|
66
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { estimateTokenCount } from "./token-estimate.js";
|
|
2
|
+
|
|
3
|
+
/** User payload char cap in orchestrator LCM summarize closure (issue #3407). */
|
|
4
|
+
export const LCM_SUMMARIZE_PROMPT_MAX_CHARS = 12_000;
|
|
5
|
+
|
|
6
|
+
const MIN_LCM_SUMMARIZE_TARGET_TOKENS = 64;
|
|
7
|
+
|
|
8
|
+
export interface LcmSummarizeBudget {
|
|
9
|
+
promptText: string;
|
|
10
|
+
effectiveTargetTokens: number;
|
|
11
|
+
maxCompletionTokens: number;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Scale summarize budgets to the text actually sent to the model when the
|
|
16
|
+
* full batch exceeds {@link LCM_SUMMARIZE_PROMPT_MAX_CHARS}.
|
|
17
|
+
*/
|
|
18
|
+
export function scaleLcmSummarizeBudget(
|
|
19
|
+
fullText: string,
|
|
20
|
+
targetTokens: number,
|
|
21
|
+
): LcmSummarizeBudget {
|
|
22
|
+
const promptText = fullText.slice(0, LCM_SUMMARIZE_PROMPT_MAX_CHARS);
|
|
23
|
+
const fullEst = Math.max(1, estimateTokenCount(fullText));
|
|
24
|
+
const sentEst = Math.max(1, estimateTokenCount(promptText));
|
|
25
|
+
const ratio = Math.min(1, sentEst / fullEst);
|
|
26
|
+
const scaledTarget = Math.ceil(targetTokens * ratio);
|
|
27
|
+
const minimumTarget = Math.min(targetTokens, MIN_LCM_SUMMARIZE_TARGET_TOKENS);
|
|
28
|
+
const effectiveTargetTokens = Math.max(minimumTarget, scaledTarget);
|
|
29
|
+
return {
|
|
30
|
+
promptText,
|
|
31
|
+
effectiveTargetTokens,
|
|
32
|
+
maxCompletionTokens: effectiveTargetTokens * 2,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/** Buffered durable replay ingest (#3368 split from turn-ingestion.ts — 1200-line ratchet). */
|
|
2
|
+
|
|
3
|
+
import { ReplayAdmissionRefusedError, StorageTargetRequiredError } from "../buffer-admission.js";
|
|
4
|
+
import { resolveNamespaceCapabilities } from "../capabilities.js";
|
|
5
|
+
import type { BufferTurn, CodingContext } from "../types.js";
|
|
6
|
+
import type { ResolvedScopeProfilePlan } from "../namespaces/scope-profiles.js";
|
|
7
|
+
import { queueBufferedCaptureScopeGroups } from "./extraction-task-queueing.js";
|
|
8
|
+
import type { TurnIngestionDeps } from "./turn-ingestion.js";
|
|
9
|
+
|
|
10
|
+
export async function ingestReplayBatchBuffered(
|
|
11
|
+
deps: Pick<TurnIngestionDeps, "config" | "buffer" | "lcmEngine" | "queueBufferedExtraction">,
|
|
12
|
+
bySession: Map<string, BufferTurn[]>,
|
|
13
|
+
options: {
|
|
14
|
+
archiveLcm?: boolean;
|
|
15
|
+
writeNamespaceOverride?: string;
|
|
16
|
+
principalOverride?: string;
|
|
17
|
+
scopeProfileWritePlan?: ResolvedScopeProfilePlan | null;
|
|
18
|
+
codingContext?: CodingContext;
|
|
19
|
+
bufferAdmissionIdempotencyKey?: string;
|
|
20
|
+
},
|
|
21
|
+
): Promise<void> {
|
|
22
|
+
const resolvedWriteTarget =
|
|
23
|
+
options.writeNamespaceOverride ??
|
|
24
|
+
(resolveNamespaceCapabilities(deps.config).namespaces === true
|
|
25
|
+
? options.scopeProfileWritePlan?.writeNamespace
|
|
26
|
+
: deps.config.defaultNamespace);
|
|
27
|
+
if (!resolvedWriteTarget) {
|
|
28
|
+
throw new StorageTargetRequiredError(
|
|
29
|
+
"accepted capture requires an explicit storage target (writeNamespaceOverride or scopeProfileWritePlan.writeNamespace)",
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
const pin = (turn: BufferTurn): BufferTurn => {
|
|
33
|
+
const pinned: BufferTurn = { ...turn, acceptedCapture: true, writeNamespaceOverride: resolvedWriteTarget };
|
|
34
|
+
if (options.codingContext) pinned.codingContext = options.codingContext;
|
|
35
|
+
if (options.principalOverride) pinned.principalOverride = options.principalOverride;
|
|
36
|
+
if (options.scopeProfileWritePlan) pinned.scopeProfileWritePlan = options.scopeProfileWritePlan;
|
|
37
|
+
return pinned;
|
|
38
|
+
};
|
|
39
|
+
const admissionKey = options.bufferAdmissionIdempotencyKey?.trim();
|
|
40
|
+
const batches = [...bySession].map(([bufferKey, sessionTurns]) => ({ bufferKey, turns: sessionTurns.map(pin) }));
|
|
41
|
+
const outcomes = admissionKey
|
|
42
|
+
? await deps.buffer.addTurnsBoundedForObserveReplay(batches, admissionKey)
|
|
43
|
+
: await deps.buffer.addTurnsBounded(batches);
|
|
44
|
+
if (outcomes === "duplicate") return;
|
|
45
|
+
if (outcomes === null) {
|
|
46
|
+
const refusedKey = batches.find((batch) => batch.turns.length > 0)?.bufferKey ?? "unknown";
|
|
47
|
+
throw new ReplayAdmissionRefusedError(
|
|
48
|
+
`durable observe capture refused: extraction buffer at entry capacity for batch containing ${refusedKey}`,
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
await deps.buffer.flushPendingSave({ throwOnFailure: true });
|
|
53
|
+
|
|
54
|
+
if (options.archiveLcm !== false && deps.lcmEngine?.enabled) {
|
|
55
|
+
for (const [bufferKey, sessionTurns] of bySession) {
|
|
56
|
+
await deps.lcmEngine.observeMessages(
|
|
57
|
+
bufferKey,
|
|
58
|
+
sessionTurns.map((turn) => ({
|
|
59
|
+
role: turn.role,
|
|
60
|
+
content: turn.content,
|
|
61
|
+
parts: turn.parts,
|
|
62
|
+
rawContent: turn.rawContent,
|
|
63
|
+
sourceFormat: turn.sourceFormat,
|
|
64
|
+
})),
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
for (const { bufferKey, outcome } of outcomes) {
|
|
70
|
+
if (outcome.decision !== "keep_buffering" && outcome.extractionTurns) {
|
|
71
|
+
queueBufferedCaptureScopeGroups(deps.queueBufferedExtraction, outcome.extractionTurns, bufferKey, options);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -42,6 +42,7 @@ import { TranscriptManager } from "../transcript.js";
|
|
|
42
42
|
import type { BufferTurn, PluginConfig, SourceConnectorProvenance } from "../types.js";
|
|
43
43
|
|
|
44
44
|
import { groupTurnsByExtractionScope, bufferTurnsEqual } from "../buffer-turn-helpers.js";
|
|
45
|
+
import { ingestReplayBatchBuffered } from "./turn-ingestion-buffered.js";
|
|
45
46
|
import { ExtractionDrain } from "./extraction-drain.js";
|
|
46
47
|
import { skipClaimedSession } from "./buffer-drain-gate.js";
|
|
47
48
|
import { queueBufferedCaptureScopeGroups, type CaptureScopeGroupQueueOptions, type ExtractionTaskExecutionContext } from "./extraction-task-queueing.js";
|
|
@@ -281,6 +282,8 @@ export class TurnIngestionCoordinator {
|
|
|
281
282
|
extractionMode?: "immediate" | "buffered";
|
|
282
283
|
/** #3251: invoked per trigger-queued extraction promise (buffered mode). */
|
|
283
284
|
onExtractionQueued?: (extraction: Promise<void>) => void;
|
|
285
|
+
/** #3368: durable observe retry — skip buffer add when key already admitted. */
|
|
286
|
+
bufferAdmissionIdempotencyKey?: string;
|
|
284
287
|
/**
|
|
285
288
|
* #3251: the ALREADY-resolved native coding context for this capture
|
|
286
289
|
* (buffered mode). Pinned on the durable turns so drains re-resolve
|
|
@@ -322,7 +325,7 @@ export class TurnIngestionCoordinator {
|
|
|
322
325
|
// applies to extraction, never to durable admission. The abort pre-check
|
|
323
326
|
// below guards only the immediate (forced-queue) path.
|
|
324
327
|
if (options.extractionMode === "buffered") {
|
|
325
|
-
return this.
|
|
328
|
+
return ingestReplayBatchBuffered(this.deps, bySession, options);
|
|
326
329
|
}
|
|
327
330
|
|
|
328
331
|
if (options.abortSignal?.aborted) {
|
|
@@ -404,83 +407,6 @@ export class TurnIngestionCoordinator {
|
|
|
404
407
|
}
|
|
405
408
|
}
|
|
406
409
|
|
|
407
|
-
/** #3251 buffered capture: durable scope-pinned admission; await settles at durability. */
|
|
408
|
-
private async ingestReplayBatchBuffered(
|
|
409
|
-
bySession: Map<string, BufferTurn[]>,
|
|
410
|
-
options: {
|
|
411
|
-
deadlineMs?: number;
|
|
412
|
-
archiveLcm?: boolean;
|
|
413
|
-
abortSignal?: AbortSignal;
|
|
414
|
-
writeNamespaceOverride?: string;
|
|
415
|
-
principalOverride?: string;
|
|
416
|
-
scopeProfileWritePlan?: ResolvedScopeProfilePlan | null;
|
|
417
|
-
codingContext?: import("../types.js").CodingContext;
|
|
418
|
-
onExtractionQueued?: (extraction: Promise<void>) => void;
|
|
419
|
-
},
|
|
420
|
-
): Promise<void> {
|
|
421
|
-
// #3251: resolve the original actual storage target ONCE at method entry,
|
|
422
|
-
// BEFORE any LCM archival or buffer admission. Explicit override is
|
|
423
|
-
// authoritative; otherwise namespaces OFF → the collapsed default store;
|
|
424
|
-
// namespaces ON → the plan's writeNamespace. Reject before any side
|
|
425
|
-
// effect if neither is available.
|
|
426
|
-
const resolvedWriteTarget =
|
|
427
|
-
options.writeNamespaceOverride ??
|
|
428
|
-
(resolveNamespaceCapabilities(this.deps.config).namespaces === true
|
|
429
|
-
? options.scopeProfileWritePlan?.writeNamespace
|
|
430
|
-
: this.deps.config.defaultNamespace);
|
|
431
|
-
if (!resolvedWriteTarget) {
|
|
432
|
-
throw new StorageTargetRequiredError(
|
|
433
|
-
"accepted capture requires an explicit storage target (writeNamespaceOverride or scopeProfileWritePlan.writeNamespace)",
|
|
434
|
-
);
|
|
435
|
-
}
|
|
436
|
-
const pin = (turn: BufferTurn): BufferTurn => {
|
|
437
|
-
const pinned: BufferTurn = { ...turn, acceptedCapture: true, writeNamespaceOverride: resolvedWriteTarget };
|
|
438
|
-
if (options.codingContext) pinned.codingContext = options.codingContext;
|
|
439
|
-
if (options.principalOverride) pinned.principalOverride = options.principalOverride;
|
|
440
|
-
if (options.scopeProfileWritePlan) pinned.scopeProfileWritePlan = options.scopeProfileWritePlan;
|
|
441
|
-
return pinned;
|
|
442
|
-
};
|
|
443
|
-
const batches = [...bySession].map(([bufferKey, sessionTurns]) => ({ bufferKey, turns: sessionTurns.map(pin) }));
|
|
444
|
-
const outcomes = await this.deps.buffer.addTurnsBounded(batches);
|
|
445
|
-
if (outcomes === null) {
|
|
446
|
-
const refusedKey = batches.find((batch) => batch.turns.length > 0)?.bufferKey ?? "unknown";
|
|
447
|
-
throw new ReplayAdmissionRefusedError(
|
|
448
|
-
`durable observe capture refused: extraction buffer at entry capacity for batch containing ${refusedKey}`,
|
|
449
|
-
);
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
// All requested session keys were capacity-admitted together before any
|
|
453
|
-
// turn was saved. There is no retry identity: a repeat after a crash that
|
|
454
|
-
// persisted only a prefix duplicates that prefix, as on main.
|
|
455
|
-
await this.deps.buffer.flushPendingSave({ throwOnFailure: true });
|
|
456
|
-
|
|
457
|
-
if (options.archiveLcm !== false && this.deps.lcmEngine?.enabled) {
|
|
458
|
-
for (const [bufferKey, sessionTurns] of bySession) {
|
|
459
|
-
await this.deps.lcmEngine.observeMessages(
|
|
460
|
-
bufferKey,
|
|
461
|
-
sessionTurns.map((turn) => ({
|
|
462
|
-
role: turn.role,
|
|
463
|
-
content: turn.content,
|
|
464
|
-
parts: turn.parts,
|
|
465
|
-
rawContent: turn.rawContent,
|
|
466
|
-
sourceFormat: turn.sourceFormat,
|
|
467
|
-
})),
|
|
468
|
-
);
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
for (const { bufferKey, outcome } of outcomes) {
|
|
473
|
-
if (outcome.decision !== "keep_buffering" && outcome.extractionTurns) {
|
|
474
|
-
queueBufferedCaptureScopeGroups(
|
|
475
|
-
this.deps.queueBufferedExtraction,
|
|
476
|
-
outcome.extractionTurns,
|
|
477
|
-
bufferKey,
|
|
478
|
-
options,
|
|
479
|
-
);
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
}
|
|
483
|
-
|
|
484
410
|
/**
|
|
485
411
|
* Ingest a batch of bulk-import turns (#460). Like ingestReplayBatch, this
|
|
486
412
|
* normalizes user/assistant turns into the extraction buffer and awaits
|
package/src/orchestrator.ts
CHANGED
|
@@ -439,6 +439,7 @@ import {
|
|
|
439
439
|
type MemoryIntent,
|
|
440
440
|
type MemorySummary,
|
|
441
441
|
} from "./types.js";
|
|
442
|
+
import { scaleLcmSummarizeBudget } from "./lcm-summarize-budget.js";
|
|
442
443
|
import { LcmEngine } from "./lcm/index.js";
|
|
443
444
|
import { shouldSkipImplicitExtraction } from "./explicit-capture.js";
|
|
444
445
|
import {
|
|
@@ -1772,17 +1773,19 @@ export class Orchestrator {
|
|
|
1772
1773
|
targetTokens: number,
|
|
1773
1774
|
aggressive: boolean,
|
|
1774
1775
|
) => {
|
|
1776
|
+
const budget = scaleLcmSummarizeBudget(text, targetTokens);
|
|
1777
|
+
const { promptText, effectiveTargetTokens, maxCompletionTokens } = budget;
|
|
1775
1778
|
const instructionText = aggressive
|
|
1776
|
-
? `Compress the following into bullet points. One bullet per distinct fact or decision. Maximum ${
|
|
1777
|
-
: `Compress the following conversation segment into a dense summary. Preserve: decisions made, code artifacts mentioned, errors encountered, open questions, and any commitments or next-steps. Omit: pleasantries, restatements, and anything the agent would not need to recall later. Output a single paragraph, maximum ${
|
|
1779
|
+
? `Compress the following into bullet points. One bullet per distinct fact or decision. Maximum ${effectiveTargetTokens} tokens total. No prose.`
|
|
1780
|
+
: `Compress the following conversation segment into a dense summary. Preserve: decisions made, code artifacts mentioned, errors encountered, open questions, and any commitments or next-steps. Omit: pleasantries, restatements, and anything the agent would not need to recall later. Output a single paragraph, maximum ${effectiveTargetTokens} tokens.`;
|
|
1778
1781
|
try {
|
|
1779
1782
|
const messages = [
|
|
1780
1783
|
{ role: "system" as const, content: instructionText },
|
|
1781
|
-
{ role: "user" as const, content:
|
|
1784
|
+
{ role: "user" as const, content: promptText },
|
|
1782
1785
|
];
|
|
1783
1786
|
const result = this.config.modelSource === "gateway" && this._fastGatewayLlm
|
|
1784
1787
|
? await this._fastGatewayLlm.chatCompletion(messages, {
|
|
1785
|
-
maxTokens:
|
|
1788
|
+
maxTokens: maxCompletionTokens,
|
|
1786
1789
|
timeoutMs: this.config.localLlmFastTimeoutMs,
|
|
1787
1790
|
// LCM is latency-sensitive. A configured fast persona is the
|
|
1788
1791
|
// explicit fast-tier route; otherwise use taskModelChain so LCM
|
|
@@ -1792,7 +1795,7 @@ export class Orchestrator {
|
|
|
1792
1795
|
: gatewayTaskChainOptions(this.config)),
|
|
1793
1796
|
})
|
|
1794
1797
|
: await this.fastLlm.chatCompletion(messages, {
|
|
1795
|
-
maxTokens:
|
|
1798
|
+
maxTokens: maxCompletionTokens,
|
|
1796
1799
|
operation: "lcm-summarize",
|
|
1797
1800
|
priority: "background",
|
|
1798
1801
|
});
|
|
@@ -66,6 +66,13 @@ interface SessionFileBody {
|
|
|
66
66
|
extractionCount?: number;
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
+
const ADMISSION_IDEMPOTENCY_FILE = "_admission-idempotency.json";
|
|
70
|
+
|
|
71
|
+
interface AdmissionIdempotencyFileBody {
|
|
72
|
+
keys?: Record<string, number>;
|
|
73
|
+
order?: string[];
|
|
74
|
+
}
|
|
75
|
+
|
|
69
76
|
function entryFromBody(body: SessionFileBody): { key: string; entry: BufferEntryState } | null {
|
|
70
77
|
if (!body || !Array.isArray(body.turns) || (body.key?.length ?? 0) === 0) return null;
|
|
71
78
|
const entry: BufferEntryState = {
|
|
@@ -116,6 +123,68 @@ export class BufferSessionFiles {
|
|
|
116
123
|
return path.join(this.dir, bufferSessionFileName(key));
|
|
117
124
|
}
|
|
118
125
|
|
|
126
|
+
private admissionMetaPath(): string {
|
|
127
|
+
return path.join(this.dir, ADMISSION_IDEMPOTENCY_FILE);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
private async readAdmissionIdempotency(): Promise<Pick<BufferState, "admissionIdempotency" | "admissionIdempotencyOrder">> {
|
|
131
|
+
let raw: string;
|
|
132
|
+
try {
|
|
133
|
+
raw = await this.io.read(this.admissionMetaPath());
|
|
134
|
+
} catch (err) {
|
|
135
|
+
if (err instanceof Error && isMissing(asFsError(err))) return {};
|
|
136
|
+
throw err;
|
|
137
|
+
}
|
|
138
|
+
try {
|
|
139
|
+
const body: AdmissionIdempotencyFileBody = JSON.parse(raw);
|
|
140
|
+
const rawKeys = body.keys;
|
|
141
|
+
if (rawKeys == null || Array.isArray(rawKeys)) return {};
|
|
142
|
+
// SAFETY: admission file contract — keys is a plain record of finite turn counts.
|
|
143
|
+
const map = Object.create(null) as Record<string, number>;
|
|
144
|
+
for (const [key, value] of Object.entries(rawKeys)) {
|
|
145
|
+
const count = Number(value);
|
|
146
|
+
if (Number.isFinite(count)) map[key] = count;
|
|
147
|
+
}
|
|
148
|
+
const loaded: Pick<BufferState, "admissionIdempotency" | "admissionIdempotencyOrder"> = {
|
|
149
|
+
admissionIdempotency: map,
|
|
150
|
+
};
|
|
151
|
+
if (Array.isArray(body.order) && body.order.length > 0) {
|
|
152
|
+
const order: string[] = [];
|
|
153
|
+
for (const entry of body.order) {
|
|
154
|
+
const slot = String(entry);
|
|
155
|
+
if (Object.hasOwn(map, slot)) order.push(slot);
|
|
156
|
+
}
|
|
157
|
+
if (order.length > 0) loaded.admissionIdempotencyOrder = order;
|
|
158
|
+
}
|
|
159
|
+
return loaded;
|
|
160
|
+
} catch (err) {
|
|
161
|
+
log.warn(
|
|
162
|
+
`buffer: unreadable admission idempotency file; starting empty (${err instanceof Error ? err.message : String(err)})`,
|
|
163
|
+
);
|
|
164
|
+
return {};
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** Persist observe-buffer idempotency metadata (production storage path). */
|
|
169
|
+
async saveAdmissionIdempotency(state: BufferState): Promise<void> {
|
|
170
|
+
const keys = state.admissionIdempotency;
|
|
171
|
+
if (!keys || Object.keys(keys).length === 0) {
|
|
172
|
+
await this.assertDirSafe();
|
|
173
|
+
try {
|
|
174
|
+
await unlink(this.admissionMetaPath());
|
|
175
|
+
} catch (err) {
|
|
176
|
+
if (!(err instanceof Error) || !isMissing(asFsError(err))) throw err;
|
|
177
|
+
}
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
await this.assertDirSafe();
|
|
181
|
+
const order = state.admissionIdempotencyOrder ?? Object.keys(keys);
|
|
182
|
+
await this.io.write(
|
|
183
|
+
this.admissionMetaPath(),
|
|
184
|
+
JSON.stringify({ keys, order }),
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
|
|
119
188
|
/**
|
|
120
189
|
* Refuse a symlinked buffer directory: following it would send buffered
|
|
121
190
|
* conversation data (and deletions) outside the memory root. One lstat of
|
|
@@ -269,11 +338,13 @@ export class BufferSessionFiles {
|
|
|
269
338
|
const out: NonNullable<BufferState["entries"]> = Object.create(null);
|
|
270
339
|
for (const [key, entry] of entries) out[key] = entry;
|
|
271
340
|
const def = entries.get("default");
|
|
341
|
+
const admission = await this.readAdmissionIdempotency();
|
|
272
342
|
return {
|
|
273
343
|
turns: def?.turns ?? [],
|
|
274
344
|
lastExtractionAt: def?.lastExtractionAt ?? null,
|
|
275
345
|
extractionCount: def?.extractionCount ?? 0,
|
|
276
346
|
entries: out,
|
|
347
|
+
...admission,
|
|
277
348
|
};
|
|
278
349
|
}
|
|
279
350
|
|
package/src/storage.ts
CHANGED
|
@@ -5518,6 +5518,7 @@ export class StorageManager extends TombstoneBlockedCaptureIndexHost {
|
|
|
5518
5518
|
async loadBuffer(): Promise<BufferState> { return this.bufferSessionFiles().load(); }
|
|
5519
5519
|
async saveBuffer(state: BufferState): Promise<void> { await this.bufferSessionFiles().reconcile(state); }
|
|
5520
5520
|
async saveBufferSession(key: string, entry: BufferEntryState): Promise<BufferSessionSaveOutcome> { return await this.bufferSessionFiles().save(key, entry); }
|
|
5521
|
+
async saveBufferAdmissionIdempotency(state: BufferState): Promise<void> { await this.bufferSessionFiles().saveAdmissionIdempotency(state); }
|
|
5521
5522
|
async deleteBufferSession(key: string): Promise<void> { await this.bufferSessionFiles().remove(key); }
|
|
5522
5523
|
/** Sync gate check for the extraction queue: is this session claimed by a buffer drain? */
|
|
5523
5524
|
isBufferSessionClaimed(key: string): boolean { return this.bufferSessionFiles().isClaimed(key); }
|
package/src/types.ts
CHANGED
|
@@ -2700,6 +2700,8 @@ export interface BufferState {
|
|
|
2700
2700
|
lastExtractionAt: string | null;
|
|
2701
2701
|
extractionCount: number;
|
|
2702
2702
|
entries?: Record<string, BufferEntryState>;
|
|
2703
|
+
admissionIdempotency?: Record<string, number>;
|
|
2704
|
+
admissionIdempotencyOrder?: string[];
|
|
2703
2705
|
}
|
|
2704
2706
|
|
|
2705
2707
|
export interface BehaviorLoopAdjustment {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/buffer-persistence.ts"],"sourcesContent":["import type { DrainedTurnSets } from \"./buffer-turn-helpers.js\";\nimport type { BufferEntryState, BufferState, BufferSurpriseEvent } from \"./types.js\";\nimport type { BufferSessionSaveOutcome } from \"./storage/buffer-drain-claims.js\";\n\n/**\n * The buffer persistence surface SmartBuffer depends on.\n *\n * `saveBufferSession` / `deleteBufferSession` are the per-session incremental\n * writes (one file per session); when a storage backend does not provide\n * them, the buffer falls back to the whole-state `saveBuffer`. Both are\n * optional in the type so a storage double only has to implement what it\n * actually supports.\n */\nexport interface BufferStorage {\n loadBuffer(): Promise<BufferState>;\n saveBuffer(state: BufferState): Promise<void>;\n /** Reports \"handed_over\" when the session is claimed by `remnic buffer drain` and the entry moved into the claim instead of a session file. Legacy doubles may return void (treated as \"saved\"). */\n saveBufferSession?(key: string, entry: BufferEntryState): Promise<BufferSessionSaveOutcome | void>;\n deleteBufferSession?(key: string): Promise<void>;\n /** Sync claim check for the extraction gate; omitted when the backend has no drain-claim store. */\n isBufferSessionClaimed?(key: string): boolean;\n /** Optional surprise-telemetry sink; older storage and test doubles omit it. */\n appendBufferSurpriseEvents?(events: BufferSurpriseEvent[]): Promise<number>;\n}\n\n/** What one persist pass changed beyond plain writes. */\nexport interface BufferPersistOutcome {\n /** Sessions whose in-memory entry moved into a drain claim: the caller must evict them (a claimed session no longer lives in this process). */\n handedOver: string[];\n /** Per session, the turns a drain extracted, kept in their original lists. */\n drainedTurns: Map<string, DrainedTurnSets>;\n /** Sessions whose rewrite this pass deferred (#3389); they stay dirty. */\n deferred: string[];\n /**\n * Milliseconds until the earliest deferred session becomes rewrite-eligible\n * (set only when `deferred` is non-empty). The caller arms a retry for this\n * delay so a deferred tail of a burst lands without needing another turn.\n */\n deferredRetryDelayMs?: number;\n}\n\n/**\n * Session files at or above this estimated serialized size get rate-limited\n * rewrites on steady-state passes (issue #3389). A single hot session grew to\n * ~44 MB and its whole-file rewrite dominated `durable-bufferMs` (~99% of\n * observe latency, worst ~10 min) while real disk utilization sat at ~2%.\n */\nexport const BUFFER_SESSION_DEFER_MIN_BYTES = 8 * 1024 * 1024;\n\n/** A session past the size floor is rewritten at most once per this interval. */\nexport const BUFFER_SESSION_DEFER_INTERVAL_MS = 60_000;\n\nexport interface BufferPersistOptions {\n /** Injectable clock (monotonic ms) for tests. */\n now?: () => number;\n /**\n * Steady-state passes may defer rewriting a dirty session whose estimated\n * size is at or above BUFFER_SESSION_DEFER_MIN_BYTES and whose last persist\n * was within BUFFER_SESSION_DEFER_INTERVAL_MS. Durability barriers\n * (extraction-trigger saves, explicit buffer.save / flushPendingSave,\n * shutdown flushes) omit this: they always write. Deferral never applies to\n * a session's first persist or to a drain-claimed session. Bounds match the\n * sanctioned bufferSaveDebounceMs crash-loss window: deferred turns stay in\n * memory until the next pass or a forced flush.\n */\n allowDeferral?: boolean;\n}\n\n/** Approximate serialized size of one session file without stringifying it. */\nfunction estimateEntryBytes(entry: BufferEntryState): number {\n // ~15% over content for JSON structure + string escaping (quotes, braces,\n // key names, escape growth); the fixed per-turn overhead covers field names\n // and metadata. Under-counting here biases against deferral — the exact\n // case the floor exists for — so the estimate errs high.\n let bytes = 256;\n for (const turn of entry.turns) bytes += Math.ceil(turn.content.length * 1.15) + 128;\n for (const turn of entry.retainedTurns ?? [])\n bytes += Math.ceil(turn.content.length * 1.15) + 128;\n return bytes;\n}\n\n/**\n * Tracks which sessions' persisted files are stale and writes only those.\n *\n * Marks are cleared only after a durable write of that session. All calls\n * happen under SmartBuffer's serialized mutation chain: one writer.\n */\nexport interface BufferSessionPersistenceOptions {\n /** Injectable clock (monotonic ms) for tests; defaults to performance.now(). */\n now?: () => number;\n /** Test seam: override BUFFER_SESSION_DEFER_INTERVAL_MS. */\n deferIntervalMs?: number;\n}\n\nexport class BufferSessionPersistence {\n private readonly dirty = new Set<string>();\n private readonly deleted = new Set<string>();\n /** Last successful session-file write per key (deferral bookkeeping, #3389). */\n private readonly lastPersistedAt = new Map<string, number>();\n private readonly clock: () => number;\n private readonly deferIntervalMs: number;\n\n constructor(options: BufferSessionPersistenceOptions = {}) {\n this.clock = options.now ?? (() => performance.now());\n this.deferIntervalMs = options.deferIntervalMs ?? BUFFER_SESSION_DEFER_INTERVAL_MS;\n }\n\n markDirty(key: string): void {\n this.dirty.add(key);\n this.deleted.delete(key);\n }\n\n markDeleted(key: string): void {\n this.deleted.add(key);\n this.dirty.delete(key);\n this.lastPersistedAt.delete(key);\n }\n\n /** Eviction removed `key` from memory: its session file must go, any pending write is moot. */\n markEvicted(keys: readonly string[]): void {\n for (const key of keys) this.markDeleted(key);\n }\n\n hasPending(): boolean {\n return this.dirty.size > 0 || this.deleted.size > 0;\n }\n\n /**\n * Persist buffer state. On session-capable storage this writes ONLY the\n * sessions whose state changed since the last successful persist and\n * deletes files for evicted/reset sessions, so the observe path never\n * re-serializes other sessions' turns. On legacy storage it falls back to\n * the whole-state saveBuffer. Files are deleted before dirty writes: a\n * crash mid-persist can then only resurrect already-evicted data (the same\n * exposure as a whole-file rewrite), never drop sessions the state says\n * exist.\n */\n async persist(\n storage: BufferStorage,\n state: BufferState,\n peekEntry: (key: string) => BufferEntryState | undefined,\n reconcile?: { key: string; drained: DrainedTurnSets },\n opts?: BufferPersistOptions,\n ): Promise<BufferPersistOutcome> {\n const drainedTurns = new Map<string, DrainedTurnSets>(\n reconcile ? [[reconcile.key, reconcile.drained]] : [],\n );\n const saveSession = storage.saveBufferSession?.bind(storage);\n const deleteSession = storage.deleteBufferSession?.bind(storage);\n if (!saveSession || !deleteSession) {\n await storage.saveBuffer(state);\n this.dirty.clear();\n this.deleted.clear();\n return { handedOver: [], drainedTurns, deferred: [] };\n }\n const now = opts?.now ?? this.clock;\n const handedOver: string[] = [];\n const deferred: string[] = [];\n let nextEligibleAt: number | undefined;\n for (const key of [...this.deleted]) {\n await deleteSession(key);\n this.deleted.delete(key);\n }\n for (const key of [...this.dirty]) {\n const entry = peekEntry(key);\n if (!entry) {\n // A dirty key without state must not be written from a fabricated\n // empty entry: treat it as a deletion instead.\n this.markDeleted(key);\n continue;\n }\n if (opts?.allowDeferral === true && key !== reconcile?.key) {\n const last = this.lastPersistedAt.get(key);\n if (\n last !== undefined &&\n now() - last < this.deferIntervalMs &&\n estimateEntryBytes(entry) >= BUFFER_SESSION_DEFER_MIN_BYTES &&\n // Fail closed: a backend that omits isBufferSessionClaimed cannot\n // prove the session is unclaimed, so it never defers (PR 3481 review).\n storage.isBufferSessionClaimed?.(key) === false\n ) {\n deferred.push(key);\n const eligibleAt = last + this.deferIntervalMs;\n if (nextEligibleAt === undefined || eligibleAt < nextEligibleAt) {\n nextEligibleAt = eligibleAt;\n }\n continue;\n }\n }\n const saveOutcome = await saveSession(key, entry);\n this.dirty.delete(key);\n this.lastPersistedAt.set(key, now());\n // \"handed_over\": the entry moved into a drain claim. Content is durable\n // in the claim, so this key's pending state is settled — the caller\n // evicts the in-memory entry on its side.\n if (saveOutcome?.status === \"handed_over\") handedOver.push(key);\n // A drain tombstone: the turns it extracted must leave this process's\n // copy too, or the owner would extract them a second time.\n if (\n saveOutcome?.drainedTurns &&\n (saveOutcome.drainedTurns.turns.length > 0 || saveOutcome.drainedTurns.retainedTurns.length > 0)\n ) {\n drainedTurns.set(key, saveOutcome.drainedTurns);\n }\n if (saveOutcome?.status === \"handed_over\") this.lastPersistedAt.delete(key);\n }\n const outcome: BufferPersistOutcome = { handedOver, drainedTurns, deferred };\n if (deferred.length > 0 && nextEligibleAt !== undefined) {\n outcome.deferredRetryDelayMs = Math.max(0, nextEligibleAt - now());\n }\n return outcome;\n }\n}\n"],"mappings":";AA+CO,IAAM,iCAAiC,IAAI,OAAO;AAGlD,IAAM,mCAAmC;AAmBhD,SAAS,mBAAmB,OAAiC;AAK3D,MAAI,QAAQ;AACZ,aAAW,QAAQ,MAAM,MAAO,UAAS,KAAK,KAAK,KAAK,QAAQ,SAAS,IAAI,IAAI;AACjF,aAAW,QAAQ,MAAM,iBAAiB,CAAC;AACzC,aAAS,KAAK,KAAK,KAAK,QAAQ,SAAS,IAAI,IAAI;AACnD,SAAO;AACT;AAeO,IAAM,2BAAN,MAA+B;AAAA,EACnB,QAAQ,oBAAI,IAAY;AAAA,EACxB,UAAU,oBAAI,IAAY;AAAA;AAAA,EAE1B,kBAAkB,oBAAI,IAAoB;AAAA,EAC1C;AAAA,EACA;AAAA,EAEjB,YAAY,UAA2C,CAAC,GAAG;AACzD,SAAK,QAAQ,QAAQ,QAAQ,MAAM,YAAY,IAAI;AACnD,SAAK,kBAAkB,QAAQ,mBAAmB;AAAA,EACpD;AAAA,EAEA,UAAU,KAAmB;AAC3B,SAAK,MAAM,IAAI,GAAG;AAClB,SAAK,QAAQ,OAAO,GAAG;AAAA,EACzB;AAAA,EAEA,YAAY,KAAmB;AAC7B,SAAK,QAAQ,IAAI,GAAG;AACpB,SAAK,MAAM,OAAO,GAAG;AACrB,SAAK,gBAAgB,OAAO,GAAG;AAAA,EACjC;AAAA;AAAA,EAGA,YAAY,MAA+B;AACzC,eAAW,OAAO,KAAM,MAAK,YAAY,GAAG;AAAA,EAC9C;AAAA,EAEA,aAAsB;AACpB,WAAO,KAAK,MAAM,OAAO,KAAK,KAAK,QAAQ,OAAO;AAAA,EACpD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYA,MAAM,QACJ,SACA,OACA,WACA,WACA,MAC+B;AAC/B,UAAM,eAAe,IAAI;AAAA,MACvB,YAAY,CAAC,CAAC,UAAU,KAAK,UAAU,OAAO,CAAC,IAAI,CAAC;AAAA,IACtD;AACA,UAAM,cAAc,QAAQ,mBAAmB,KAAK,OAAO;AAC3D,UAAM,gBAAgB,QAAQ,qBAAqB,KAAK,OAAO;AAC/D,QAAI,CAAC,eAAe,CAAC,eAAe;AAClC,YAAM,QAAQ,WAAW,KAAK;AAC9B,WAAK,MAAM,MAAM;AACjB,WAAK,QAAQ,MAAM;AACnB,aAAO,EAAE,YAAY,CAAC,GAAG,cAAc,UAAU,CAAC,EAAE;AAAA,IACtD;AACA,UAAM,MAAM,MAAM,OAAO,KAAK;AAC9B,UAAM,aAAuB,CAAC;AAC9B,UAAM,WAAqB,CAAC;AAC5B,QAAI;AACJ,eAAW,OAAO,CAAC,GAAG,KAAK,OAAO,GAAG;AACnC,YAAM,cAAc,GAAG;AACvB,WAAK,QAAQ,OAAO,GAAG;AAAA,IACzB;AACA,eAAW,OAAO,CAAC,GAAG,KAAK,KAAK,GAAG;AACjC,YAAM,QAAQ,UAAU,GAAG;AAC3B,UAAI,CAAC,OAAO;AAGV,aAAK,YAAY,GAAG;AACpB;AAAA,MACF;AACA,UAAI,MAAM,kBAAkB,QAAQ,QAAQ,WAAW,KAAK;AAC1D,cAAM,OAAO,KAAK,gBAAgB,IAAI,GAAG;AACzC,YACE,SAAS,UACT,IAAI,IAAI,OAAO,KAAK,mBACpB,mBAAmB,KAAK,KAAK;AAAA;AAAA,QAG7B,QAAQ,yBAAyB,GAAG,MAAM,OAC1C;AACA,mBAAS,KAAK,GAAG;AACjB,gBAAM,aAAa,OAAO,KAAK;AAC/B,cAAI,mBAAmB,UAAa,aAAa,gBAAgB;AAC/D,6BAAiB;AAAA,UACnB;AACA;AAAA,QACF;AAAA,MACF;AACA,YAAM,cAAc,MAAM,YAAY,KAAK,KAAK;AAChD,WAAK,MAAM,OAAO,GAAG;AACrB,WAAK,gBAAgB,IAAI,KAAK,IAAI,CAAC;AAInC,UAAI,aAAa,WAAW,cAAe,YAAW,KAAK,GAAG;AAG9D,UACE,aAAa,iBACZ,YAAY,aAAa,MAAM,SAAS,KAAK,YAAY,aAAa,cAAc,SAAS,IAC9F;AACA,qBAAa,IAAI,KAAK,YAAY,YAAY;AAAA,MAChD;AACA,UAAI,aAAa,WAAW,cAAe,MAAK,gBAAgB,OAAO,GAAG;AAAA,IAC5E;AACA,UAAM,UAAgC,EAAE,YAAY,cAAc,SAAS;AAC3E,QAAI,SAAS,SAAS,KAAK,mBAAmB,QAAW;AACvD,cAAQ,uBAAuB,KAAK,IAAI,GAAG,iBAAiB,IAAI,CAAC;AAAA,IACnE;AACA,WAAO;AAAA,EACT;AACF;","names":[]}
|