@cortexkit/opencode-magic-context 0.49.93 → 0.49.96
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/{announcement-4ynkaf0d.js → announcement-8nj2jd87.js} +5 -5
- package/dist/auto-search-worker.js +5 -5
- package/dist/chunk-embedding-write-worker.js +16 -16
- package/dist/{compaction-marker-candidates-1ndjqh9k.js → compaction-marker-candidates-a4b0anvv.js} +3 -3
- package/dist/compaction-marker-candidates-worker.js +1 -1
- package/dist/{compartment-chunk-embedding-rp4asvk0.js → compartment-chunk-embedding-re2cw7y3.js} +8 -8
- package/dist/config/removed-agent-config.d.ts +1 -1
- package/dist/config/removed-agent-config.d.ts.map +1 -1
- package/dist/config/schema/magic-context.d.ts +0 -75
- package/dist/config/schema/magic-context.d.ts.map +1 -1
- package/dist/{conflict-warning-hook-exf96bpt.js → conflict-warning-hook-wcq55y61.js} +8 -8
- package/dist/{context-jpxthqxg.js → context-gtjdrp8f.js} +237 -140
- package/dist/{derive-budgets-hzzq71rm.js → derive-budgets-g1sy72e8.js} +5 -5
- package/dist/embedding-backfill-pdymqbnh.js +29 -0
- package/dist/embedding-worker-process.js +2 -2
- package/dist/embedding-worker.js +8 -8
- package/dist/features/magic-context/compartment-storage.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/docs-proposals.d.ts +5 -2
- package/dist/features/magic-context/dreamer/docs-proposals.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/token-budget.d.ts +2 -2
- package/dist/features/magic-context/dreamer/token-budget.d.ts.map +1 -1
- package/dist/features/magic-context/history-gap-recovery.d.ts +42 -0
- package/dist/features/magic-context/history-gap-recovery.d.ts.map +1 -0
- package/dist/features/magic-context/memory/embedding-synapse.d.ts +18 -5
- package/dist/features/magic-context/memory/embedding-synapse.d.ts.map +1 -1
- package/dist/features/magic-context/message-visibility.d.ts +10 -0
- package/dist/features/magic-context/message-visibility.d.ts.map +1 -0
- package/dist/features/magic-context/search-rerank.d.ts +2 -2
- package/dist/features/magic-context/search-rerank.d.ts.map +1 -1
- package/dist/features/magic-context/search.d.ts +4 -0
- package/dist/features/magic-context/search.d.ts.map +1 -1
- package/dist/features/magic-context/session-decision-calibration.d.ts.map +1 -1
- package/dist/features/magic-context/session-project-backfill.d.ts.map +1 -1
- package/dist/features/magic-context/store-generation-rebase.d.ts.map +1 -1
- package/dist/{history-owner-xqfsvf9k.js → history-owner-74826t4n.js} +3 -3
- package/dist/hooks/magic-context/compartment-runner-recomp.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-trigger.d.ts +1 -1
- package/dist/hooks/magic-context/compartment-trigger.d.ts.map +1 -1
- package/dist/hooks/magic-context/history-boundary-repair.d.ts +2 -2
- package/dist/hooks/magic-context/history-boundary-repair.d.ts.map +1 -1
- package/dist/hooks/magic-context/hook.d.ts.map +1 -1
- package/dist/hooks/magic-context/inject-compartments.d.ts +6 -1
- package/dist/hooks/magic-context/inject-compartments.d.ts.map +1 -1
- package/dist/hooks/magic-context/lkg-persist.d.ts +3 -1
- package/dist/hooks/magic-context/lkg-persist.d.ts.map +1 -1
- package/dist/hooks/magic-context/lkg-recovery-fence.d.ts +1 -0
- package/dist/hooks/magic-context/lkg-recovery-fence.d.ts.map +1 -1
- package/dist/hooks/magic-context/lkg-replay.d.ts +3 -0
- package/dist/hooks/magic-context/lkg-replay.d.ts.map +1 -1
- package/dist/hooks/magic-context/raw-ordinal-warmup.d.ts +1 -0
- package/dist/hooks/magic-context/raw-ordinal-warmup.d.ts.map +1 -1
- package/dist/hooks/magic-context/tail-hygiene-output-count.d.ts +4 -0
- package/dist/hooks/magic-context/tail-hygiene-output-count.d.ts.map +1 -1
- package/dist/hooks/magic-context/tail-hygiene-walk.d.ts +2 -0
- package/dist/hooks/magic-context/tail-hygiene-walk.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform-compartment-phase.d.ts +2 -1
- package/dist/hooks/magic-context/transform-compartment-phase.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform-postprocess-phase.d.ts +1 -0
- package/dist/hooks/magic-context/transform-postprocess-phase.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform-stage-logger.d.ts +6 -0
- package/dist/hooks/magic-context/transform-stage-logger.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform.d.ts +2 -0
- package/dist/hooks/magic-context/transform.d.ts.map +1 -1
- package/dist/{index-5zrzg8r1.js → index-0bjj9yf3.js} +2 -2
- package/dist/{index-g9qtxv87.js → index-0sqhg9nf.js} +132 -64
- package/dist/{index-nxxzeq4y.js → index-0ve29s6f.js} +1 -1
- package/dist/{index-g6y2wk32.js → index-2afrmgy3.js} +6 -6
- package/dist/{index-ywrz4wy2.js → index-3fhb0j32.js} +1 -1
- package/dist/{index-gqf8r04r.js → index-3n4j5rqc.js} +1 -1
- package/dist/{index-xsqw8kbd.js → index-45qgkg8j.js} +2 -2
- package/dist/{index-5df2fw5b.js → index-6mryx739.js} +1 -1
- package/dist/{index-n9kd68vc.js → index-7m2tnk8q.js} +10 -10
- package/dist/{index-r4y0dczp.js → index-7sdns2ww.js} +2 -2
- package/dist/{index-mjy2k9jr.js → index-880a24vd.js} +1 -1
- package/dist/{index-pnawfv4e.js → index-89bkkgcn.js} +4 -4
- package/dist/{index-s32f8y67.js → index-89xg64wb.js} +2 -2
- package/dist/{index-hee64h6k.js → index-8sgv96kq.js} +7 -7
- package/dist/{index-ttdk2w0z.js → index-910gahfb.js} +6 -6
- package/dist/{index-kty5k23y.js → index-9jvxq5rt.js} +4 -4
- package/dist/{index-832w615x.js → index-azkfw78y.js} +1 -1
- package/dist/{index-wh9fxds5.js → index-c205x7xd.js} +1 -1
- package/dist/{index-mg9s2rc3.js → index-cpbr0xvk.js} +2 -2
- package/dist/{index-g5c67kay.js → index-cq8znmyw.js} +17 -17
- package/dist/{index-cr483vx6.js → index-dj64gzg5.js} +2 -2
- package/dist/{index-jba6ny4m.js → index-dnpcv1rg.js} +4 -4
- package/dist/{index-z4p0ry94.js → index-dt7cyqfe.js} +2 -1
- package/dist/{index-j2w79s9r.js → index-e6ay1gez.js} +2 -2
- package/dist/{index-y2vshk67.js → index-f154w8m4.js} +229 -84
- package/dist/{index-6r99v53h.js → index-fgw241hh.js} +164 -62
- package/dist/{index-rz47hf2m.js → index-fvfnq8n6.js} +30 -14
- package/dist/{index-yqha238s.js → index-gnrwgvn7.js} +127 -17
- package/dist/{index-fpjnjxyx.js → index-h7kta6cn.js} +3 -3
- package/dist/{index-q7q6qp1f.js → index-hedgz8an.js} +1 -1
- package/dist/{index-5pgyqgmx.js → index-hj78hvhm.js} +2 -2
- package/dist/{index-dr6bd4c8.js → index-hp46xe93.js} +7 -7
- package/dist/{index-0twg41mh.js → index-j4dcjb8t.js} +4 -4
- package/dist/{index-e6ncz7a6.js → index-jzrvdqb8.js} +1 -1
- package/dist/{index-sp5pvs95.js → index-k34hc455.js} +2 -2
- package/dist/{index-9ffntwyr.js → index-kj4bprep.js} +4 -4
- package/dist/index-mgy7g740.js +119 -0
- package/dist/{index-za1yx1m4.js → index-nqdwpdje.js} +154 -32
- package/dist/{index-hes3k87g.js → index-r1d45dsr.js} +4 -4
- package/dist/{index-y915t3ey.js → index-r3f85n7y.js} +5 -1
- package/dist/{index-1kem0xxx.js → index-t2e10rag.js} +5 -5
- package/dist/{index-m0pwswv9.js → index-tqtpgnhr.js} +1 -1
- package/dist/{index-01h7tqe3.js → index-tr4ep2ej.js} +21 -6
- package/dist/{index-xr1t0fxb.js → index-w7n7qkpf.js} +49 -13
- package/dist/{index-s7460efs.js → index-zfx7mtqa.js} +1 -1
- package/dist/{index-gqfy38m9.js → index-zkjx8gq3.js} +11 -11
- package/dist/{index-et39x9k3.js → index-zmgp0tr6.js} +3 -3
- package/dist/index.js +59 -56
- package/dist/{logger-d7c8akh9.js → logger-nmb2508f.js} +2 -2
- package/dist/{message-fts-rowid-map-0xx8ge09.js → message-fts-rowid-map-vcatdan0.js} +5 -5
- package/dist/{message-index-bounded-vjrnptar.js → message-index-bounded-abhwe610.js} +12 -12
- package/dist/{message-time-backfill-pz5981mf.js → message-time-backfill-zc5rsvhv.js} +3 -3
- package/dist/migration-worker.js +13 -13
- package/dist/plugin/hooks/create-session-hooks.d.ts.map +1 -1
- package/dist/{project-embedding-registry-m8zcmrsg.js → project-embedding-registry-e566q4bg.js} +15 -15
- package/dist/raw-ordinal-warmup-worker.js +9 -9
- package/dist/{read-session-chunk-zkzdc0e5.js → read-session-chunk-sde0wym3.js} +10 -10
- package/dist/{read-session-raw-3sc9231y.js → read-session-raw-trhdgc9z.js} +3 -3
- package/dist/recomp-orchestrator-d3rbpa59.js +69 -0
- package/dist/render-6cf1dgc4.js +43 -0
- package/dist/{safe-notification-target-d21swr3n.js → safe-notification-target-54ns7dv9.js} +3 -3
- package/dist/{search-e9bb9hpx.js → search-11aw8wpq.js} +27 -27
- package/dist/search-archive-s9m5szf0.js +29 -0
- package/dist/{send-session-notification-0779tyd9.js → send-session-notification-gxrj4w1r.js} +6 -6
- package/dist/shared/host-sqlite-runtime.d.ts +3 -0
- package/dist/shared/host-sqlite-runtime.d.ts.map +1 -0
- package/dist/shared/redaction.d.ts.map +1 -1
- package/dist/shared/storage-file-mutex.d.ts.map +1 -1
- package/dist/{storage-tags-gk7gjkqt.js → storage-tags-jq0c0zsn.js} +7 -7
- package/dist/{store-yr443ye8.js → store-29ksp6vy.js} +4 -4
- package/dist/{store-reader-qbq6q4v0.js → store-reader-dgh3ssxx.js} +1 -1
- package/dist/tools/ctx-expand/search-archive.d.ts +3 -2
- package/dist/tools/ctx-expand/search-archive.d.ts.map +1 -1
- package/dist/tools/ctx-expand/tools.d.ts.map +1 -1
- package/dist/tools/ctx-expand/v2-archive-reader.d.ts +2 -0
- package/dist/tools/ctx-expand/v2-archive-reader.d.ts.map +1 -1
- package/dist/tools/ctx-search/tools.d.ts.map +1 -1
- package/dist/{transform-postprocess-phase-neds90e3.js → transform-postprocess-phase-376xn40x.js} +35 -35
- package/dist/v2/auto-search-worker.js +5 -5
- package/dist/v2/chunk-embedding-write-worker.js +16 -16
- package/dist/v2/{compaction-marker-candidates-bp1bn579.js → compaction-marker-candidates-6nypmsr3.js} +3 -3
- package/dist/v2/compaction-marker-candidates-worker.js +1 -1
- package/dist/v2/{compartment-chunk-embedding-w7ht0t9v.js → compartment-chunk-embedding-jthtfhcd.js} +8 -8
- package/dist/v2/{context-ctsd80vc.js → context-vm09agrs.js} +426 -185
- package/dist/v2/{derive-budgets-hr4qqrnv.js → derive-budgets-wj0q7s7d.js} +6 -6
- package/dist/v2/embedding-backfill-16b16m38.js +29 -0
- package/dist/v2/embedding-worker-process.js +2 -2
- package/dist/v2/embedding-worker.js +8 -8
- package/dist/v2/fold/memory-cache.d.ts +2 -0
- package/dist/v2/fold/memory-cache.d.ts.map +1 -1
- package/dist/v2/fold/native-replay.d.ts +23 -5
- package/dist/v2/fold/native-replay.d.ts.map +1 -1
- package/dist/v2/hidden-child-native.d.ts.map +1 -1
- package/dist/v2/hidden-child-record.d.ts +8 -0
- package/dist/v2/hidden-child-record.d.ts.map +1 -1
- package/dist/v2/hidden-completion.d.ts.map +1 -1
- package/dist/v2/hidden-run-holder.d.ts +8 -2
- package/dist/v2/hidden-run-holder.d.ts.map +1 -1
- package/dist/v2/{history-owner-260djmv5.js → history-owner-8pd5ax3n.js} +3 -3
- package/dist/v2/hooks/context.d.ts.map +1 -1
- package/dist/v2/hooks/hidden-child.d.ts +3 -0
- package/dist/v2/hooks/hidden-child.d.ts.map +1 -1
- package/dist/v2/hooks/revert-message-state.d.ts.map +1 -1
- package/dist/v2/hooks/session-project-backfill.d.ts +2 -1
- package/dist/v2/hooks/session-project-backfill.d.ts.map +1 -1
- package/dist/v2/{logger-zyf43np1.js → logger-58jfese9.js} +2 -2
- package/dist/v2/{message-fts-rowid-map-n8mcvcpz.js → message-fts-rowid-map-ax4vk78j.js} +5 -5
- package/dist/v2/{message-index-bounded-1vew9c37.js → message-index-bounded-qh794qxx.js} +12 -12
- package/dist/v2/{message-time-backfill-ynb3vg6r.js → message-time-backfill-yj773saf.js} +3 -3
- package/dist/v2/migration-worker.js +13 -13
- package/dist/v2/{project-embedding-registry-je5jam7y.js → project-embedding-registry-z05xvckg.js} +15 -15
- package/dist/v2/raw-ordinal-warmup-worker.js +9 -9
- package/dist/v2/{read-session-chunk-09sre4xv.js → read-session-chunk-8tn2dbn1.js} +10 -10
- package/dist/v2/{read-session-raw-wg5zc29f.js → read-session-raw-ywebck9q.js} +3 -3
- package/dist/v2/recomp-orchestrator-pfjpzdrb.js +69 -0
- package/dist/v2/render-7t5d7hkv.js +43 -0
- package/dist/v2/{safe-notification-target-y55z2zat.js → safe-notification-target-zrwbh6k7.js} +3 -3
- package/dist/v2/{search-gmye6n25.js → search-35cz80x0.js} +26 -26
- package/dist/v2/search-archive-5dpxv0ck.js +29 -0
- package/dist/v2/{send-session-notification-v69y04f5.js → send-session-notification-8x146x5y.js} +6 -6
- package/dist/v2/{server-z9czv2vb.js → server-11ra1pmx.js} +49 -13
- package/dist/v2/{server-gs2251jr.js → server-2cq3e1c1.js} +4 -4
- package/dist/v2/{server-39bcszk4.js → server-2qvnr3t7.js} +1 -1
- package/dist/v2/{server-jkj1dq6j.js → server-2sare4qg.js} +4 -4
- package/dist/v2/{server-jdfe07mp.js → server-2wz6y46g.js} +1 -1
- package/dist/v2/{server-at0v0z4t.js → server-379fd3n7.js} +1 -1
- package/dist/v2/{server-ds8vpfkr.js → server-40vdz8sf.js} +2 -2
- package/dist/v2/{server-qntmqaca.js → server-4yrvbnnm.js} +2 -2
- package/dist/v2/{server-x69fqsvz.js → server-5t4nzfpt.js} +1 -1
- package/dist/v2/{server-npdey91q.js → server-63ree5ns.js} +1 -1
- package/dist/v2/{server-gqkdfdvw.js → server-6qax5pds.js} +2 -2
- package/dist/v2/{server-qb3s0mnc.js → server-73bqw5c0.js} +1 -1
- package/dist/v2/{server-6chcnnhq.js → server-7h4gwphm.js} +4 -4
- package/dist/v2/{server-rkj44mez.js → server-7tj8yzrv.js} +2 -2
- package/dist/v2/{server-e6xneh68.js → server-arfzfxe8.js} +5 -1
- package/dist/v2/{server-6ash6z8z.js → server-av3p9c8k.js} +1 -1
- package/dist/v2/{server-5hwf5c7r.js → server-bx5k66qc.js} +1 -1
- package/dist/v2/{server-dgsjamm4.js → server-db91dxwc.js} +7 -7
- package/dist/v2/{server-z4p0ry94.js → server-dt7cyqfe.js} +2 -1
- package/dist/v2/{server-k1xc2bw1.js → server-ganavh75.js} +2 -2
- package/dist/v2/{server-6x40bnb7.js → server-gh2w75fn.js} +3 -3
- package/dist/v2/server-j1gxs1gj.js +119 -0
- package/dist/v2/{server-ps6zrzwj.js → server-k3ntgf6n.js} +164 -62
- package/dist/v2/{server-j8376q08.js → server-kzrrdjp5.js} +1 -1
- package/dist/v2/{server-1rrmxhd1.js → server-n33hyq9t.js} +2 -2
- package/dist/v2/{server-0tv6kytx.js → server-n34vzyfm.js} +1 -1
- package/dist/v2/{server-vc5fta6s.js → server-nnh81jqy.js} +6 -6
- package/dist/v2/{server-g53asaqt.js → server-pcq2d1wh.js} +30 -14
- package/dist/v2/{server-bnkc9kph.js → server-ppy2dj7g.js} +6 -6
- package/dist/v2/{server-96nm9vk4.js → server-rr5c0xcg.js} +2 -2
- package/dist/v2/{server-j4jjtdc5.js → server-rt8t6s2a.js} +2 -2
- package/dist/v2/{server-2xm0gxke.js → server-svccj9rd.js} +4 -4
- package/dist/v2/{server-5sbsnpkn.js → server-tq523gj6.js} +1 -1
- package/dist/v2/{server-00adcfjd.js → server-vj0xbbrc.js} +17 -3
- package/dist/v2/{server-4ecpanyn.js → server-vntc961c.js} +127 -17
- package/dist/v2/{server-btgnkr9z.js → server-vsx9tsks.js} +11 -11
- package/dist/v2/{server-vtgeyhq6.js → server-vtkbxzw1.js} +21 -6
- package/dist/v2/{server-cvp9w5gs.js → server-w35ep6wn.js} +192 -84
- package/dist/v2/{server-myp4pc6x.js → server-z2nv8jdv.js} +132 -64
- package/dist/v2/{server-pcarsvj2.js → server-z5cv5wm5.js} +10 -10
- package/dist/v2/{server-barj0mjz.js → server-zemnpv92.js} +4 -4
- package/dist/v2/server.js +9 -9
- package/dist/v2/{storage-tags-nccqr0kr.js → storage-tags-pcenytad.js} +7 -7
- package/dist/v2/{store-enef5jcn.js → store-gx19qc3a.js} +4 -4
- package/dist/v2/{store-reader-jbaqv1yp.js → store-reader-qt2msa8z.js} +1 -1
- package/dist/v2/store-reader.d.ts +1 -1
- package/dist/v2/store-reader.d.ts.map +1 -1
- package/dist/v2/{v2-archive-reader-7vmng8q7.js → v2-archive-reader-jqrwz7b8.js} +1 -1
- package/dist/v2/{wrapup-orchestrator-7r4y0bf6.js → wrapup-orchestrator-kcq3cv7y.js} +35 -35
- package/dist/{v2-archive-reader-7s90gfax.js → v2-archive-reader-64h2gtam.js} +1 -1
- package/dist/wrapup-orchestrator-knyac7jp.js +56 -0
- package/package.json +1 -1
- package/src/config/index.test.ts +23 -5
- package/src/config/live-run-config.test.ts +7 -7
- package/src/config/removed-agent-config.ts +14 -1
- package/src/config/schema/magic-context.ts +5 -1
- package/src/shared/host-sqlite-runtime.test.ts +21 -0
- package/src/shared/host-sqlite-runtime.ts +32 -0
- package/src/shared/redaction.test.ts +11 -8
- package/src/shared/redaction.ts +5 -1
- package/src/shared/storage-file-mutex-review.test.ts +110 -0
- package/src/shared/storage-file-mutex.ts +12 -0
- package/dist/embedding-backfill-6wzc4p2n.js +0 -29
- package/dist/index-52x68mj4.js +0 -58
- package/dist/recomp-orchestrator-qb2hymj5.js +0 -69
- package/dist/render-34p0kek8.js +0 -43
- package/dist/search-archive-08ppk0q5.js +0 -27
- package/dist/v2/embedding-backfill-40g0anxh.js +0 -29
- package/dist/v2/recomp-orchestrator-mgcty3we.js +0 -69
- package/dist/v2/render-ygcmyn9x.js +0 -43
- package/dist/v2/search-archive-nrsqqmk5.js +0 -27
- package/dist/v2/server-52x68mj4.js +0 -58
- package/dist/wrapup-orchestrator-m2p89973.js +0 -56
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
resolveLegacyConfigSources,
|
|
8
8
|
getProtectedTokensTierOverrides,
|
|
9
9
|
loadPluginConfigDetailed
|
|
10
|
-
} from "./server-
|
|
10
|
+
} from "./server-vj0xbbrc.js";
|
|
11
11
|
import {
|
|
12
12
|
getHarness2,
|
|
13
13
|
harnessOwnsOpenCodeStore2
|
|
@@ -21,25 +21,25 @@ import {
|
|
|
21
21
|
log2,
|
|
22
22
|
sessionLog2,
|
|
23
23
|
getLoggerDiagnostics2
|
|
24
|
-
} from "./server-
|
|
24
|
+
} from "./server-kzrrdjp5.js";
|
|
25
25
|
import {
|
|
26
26
|
sanitizeDiagnosticText,
|
|
27
27
|
hasShareabilitySensitiveText
|
|
28
|
-
} from "./server-
|
|
28
|
+
} from "./server-dt7cyqfe.js";
|
|
29
29
|
import {
|
|
30
30
|
registerOwnRpcServerInstance,
|
|
31
31
|
rpcPortDir,
|
|
32
32
|
rpcPortFilePath,
|
|
33
33
|
parseRpcPortFile,
|
|
34
34
|
inspectProcessesAsync
|
|
35
|
-
} from "./server-
|
|
35
|
+
} from "./server-2wz6y46g.js";
|
|
36
36
|
import {
|
|
37
37
|
shouldEnforcePrivateStoragePermissions,
|
|
38
38
|
ensureStorageDirectorySync,
|
|
39
39
|
writeStorageFileAtomicSync,
|
|
40
40
|
writeStorageFileAsync,
|
|
41
41
|
createStorageWriteStream
|
|
42
|
-
} from "./server-
|
|
42
|
+
} from "./server-n34vzyfm.js";
|
|
43
43
|
import {
|
|
44
44
|
hasTrustedAbsoluteWall,
|
|
45
45
|
applyProvenInputFloor,
|
|
@@ -52,7 +52,7 @@ import {
|
|
|
52
52
|
getSdkContextLimit,
|
|
53
53
|
getSdkOutputLimit,
|
|
54
54
|
getModelsDevCacheState
|
|
55
|
-
} from "./server-
|
|
55
|
+
} from "./server-rr5c0xcg.js";
|
|
56
56
|
import {
|
|
57
57
|
COMPACTION_ENABLED_PATH,
|
|
58
58
|
isDreamerRunnable,
|
|
@@ -93,7 +93,7 @@ import {
|
|
|
93
93
|
DEFAULT_HISTORIAN_TIMEOUT_MS,
|
|
94
94
|
DEFAULT_LOCAL_EMBEDDING_MODEL,
|
|
95
95
|
DREAM_TASK_PROMOTION_DEFAULTS
|
|
96
|
-
} from "./server-
|
|
96
|
+
} from "./server-arfzfxe8.js";
|
|
97
97
|
import {
|
|
98
98
|
historianRunConfig,
|
|
99
99
|
dreamerRunConfig,
|
|
@@ -129,18 +129,21 @@ import {
|
|
|
129
129
|
DREAMER_CLASSIFIER_AGENT,
|
|
130
130
|
DREAMER_DOCS_AGENT,
|
|
131
131
|
DREAMER_REVIEWER_AGENT,
|
|
132
|
+
keptUnderRetention,
|
|
133
|
+
roleTitle,
|
|
134
|
+
childCreateInput,
|
|
135
|
+
assistantOutcome,
|
|
136
|
+
withReader,
|
|
137
|
+
errorText,
|
|
138
|
+
supportsHolderArchive,
|
|
132
139
|
supportsQuietHiddenChildren,
|
|
133
140
|
matchesHiddenRunLocation,
|
|
134
141
|
hiddenRunPlacement,
|
|
135
|
-
HIDDEN_HISTORIAN_AGENT,
|
|
136
|
-
HIDDEN_DREAMER_AGENT,
|
|
137
142
|
HIDDEN_CURATE_AGENT,
|
|
138
|
-
hiddenAgentFor,
|
|
139
143
|
hiddenToolLoop,
|
|
140
144
|
HIDDEN_RUN_DISPOSED_REASON,
|
|
141
145
|
noteChildOfDisposedInstance,
|
|
142
146
|
noteTimedOutHiddenChild,
|
|
143
|
-
hiddenChildPermissions,
|
|
144
147
|
registerHiddenChildAgents,
|
|
145
148
|
hiddenToolCallRefusal,
|
|
146
149
|
HiddenAgentStepLimit,
|
|
@@ -246,7 +249,7 @@ import {
|
|
|
246
249
|
startCompartmentAgent,
|
|
247
250
|
setRecompStarting2,
|
|
248
251
|
setRecompTerminal2
|
|
249
|
-
} from "./server-
|
|
252
|
+
} from "./server-w35ep6wn.js";
|
|
250
253
|
import {
|
|
251
254
|
embedPauseBySession,
|
|
252
255
|
embedRunStateBySession,
|
|
@@ -269,7 +272,7 @@ import {
|
|
|
269
272
|
estimateTokens,
|
|
270
273
|
estimateFixedPromptTokens,
|
|
271
274
|
normalizeText
|
|
272
|
-
} from "./server-
|
|
275
|
+
} from "./server-73bqw5c0.js";
|
|
273
276
|
import {
|
|
274
277
|
SubcClient,
|
|
275
278
|
connectionFileExists,
|
|
@@ -277,9 +280,10 @@ import {
|
|
|
277
280
|
toSynapseLaneDescriptor,
|
|
278
281
|
formatSynapseLaneDescriptor,
|
|
279
282
|
SynapseEmbeddingProvider
|
|
280
|
-
} from "./server-
|
|
283
|
+
} from "./server-k3ntgf6n.js";
|
|
281
284
|
import {
|
|
282
285
|
inRootAsyncContext2,
|
|
286
|
+
detectSqliteRuntime2,
|
|
283
287
|
getTagIdentityWriteGeneration2,
|
|
284
288
|
Database2,
|
|
285
289
|
getSqliteDatabasePath2,
|
|
@@ -306,15 +310,21 @@ import {
|
|
|
306
310
|
buildInMemoryTailRawMessages2,
|
|
307
311
|
RawOrdinalsNotReady2,
|
|
308
312
|
runSessionWarmupWorker
|
|
309
|
-
} from "./server-
|
|
310
|
-
import"./server-
|
|
313
|
+
} from "./server-av3p9c8k.js";
|
|
314
|
+
import"./server-40vdz8sf.js";
|
|
311
315
|
import {
|
|
312
316
|
deleteChunkEmbedBackoffForSession2
|
|
313
|
-
} from "./server-
|
|
317
|
+
} from "./server-zemnpv92.js";
|
|
314
318
|
import {
|
|
315
319
|
acquireCompartmentLease,
|
|
316
320
|
releaseCompartmentLeaseBestEffort,
|
|
317
321
|
isCompartmentLeaseHeld,
|
|
322
|
+
readSummaryCoverage,
|
|
323
|
+
markHistoryGapAfterCoverageChange,
|
|
324
|
+
readHistoryGapMark,
|
|
325
|
+
clearHistoryGapMark,
|
|
326
|
+
claimHistoryGapCheck,
|
|
327
|
+
recordHistoryGapAdmission,
|
|
318
328
|
queueM0Mutation,
|
|
319
329
|
getMaxM0MutationId,
|
|
320
330
|
getLastCompartmentEndMessage,
|
|
@@ -430,12 +440,12 @@ import {
|
|
|
430
440
|
saveSourceContent,
|
|
431
441
|
replaceSourceContent,
|
|
432
442
|
getSourceContents
|
|
433
|
-
} from "./server-
|
|
443
|
+
} from "./server-vntc961c.js";
|
|
434
444
|
import {
|
|
435
445
|
cleanSearchText,
|
|
436
446
|
matchedSearchSnippet,
|
|
437
447
|
getLastIndexedOrdinal
|
|
438
|
-
} from "./server-
|
|
448
|
+
} from "./server-svccj9rd.js";
|
|
439
449
|
import {
|
|
440
450
|
ensureSessionMetaRow,
|
|
441
451
|
clearCachedM0M1,
|
|
@@ -503,6 +513,7 @@ import {
|
|
|
503
513
|
resolveCompactionModeRecord,
|
|
504
514
|
getCompactionModeRecord,
|
|
505
515
|
setCompactionModeRecord,
|
|
516
|
+
EMERGENCY_DRAIN_FAILURE_BACKOFF_MS,
|
|
506
517
|
getPersistedReasoningWatermark,
|
|
507
518
|
setPersistedReasoningWatermark,
|
|
508
519
|
clearPersistedReasoningWatermark,
|
|
@@ -534,6 +545,7 @@ import {
|
|
|
534
545
|
setPersistedTodoSyntheticAnchor,
|
|
535
546
|
clearPersistedTodoSyntheticAnchor,
|
|
536
547
|
setNoteLastReadAt,
|
|
548
|
+
getHistorianFailureState,
|
|
537
549
|
clearHistorianFailureState,
|
|
538
550
|
getOverflowState,
|
|
539
551
|
loadTransformPassStateSnapshot,
|
|
@@ -692,7 +704,7 @@ import {
|
|
|
692
704
|
adoptNullOwnerToolTag2,
|
|
693
705
|
getCandidateToolOwners2,
|
|
694
706
|
pickNearestPriorOwner2
|
|
695
|
-
} from "./server-
|
|
707
|
+
} from "./server-11ra1pmx.js";
|
|
696
708
|
import {
|
|
697
709
|
BoundedSessionMap,
|
|
698
710
|
getTableColumnNames,
|
|
@@ -706,7 +718,7 @@ import {
|
|
|
706
718
|
freezeTemporalDecisions,
|
|
707
719
|
tagRevisionKey,
|
|
708
720
|
tagIdentityRevisionKey
|
|
709
|
-
} from "./server-
|
|
721
|
+
} from "./server-4yrvbnnm.js";
|
|
710
722
|
import {
|
|
711
723
|
resolveHistorianModel2
|
|
712
724
|
} from "./server-5kym00ag.js";
|
|
@@ -724,7 +736,7 @@ import {
|
|
|
724
736
|
shouldBypassFailClosedBlock,
|
|
725
737
|
resolveAgentNameFromMessages,
|
|
726
738
|
createFailClosedController
|
|
727
|
-
} from "./server-
|
|
739
|
+
} from "./server-2qvnr3t7.js";
|
|
728
740
|
import {
|
|
729
741
|
pruneMissingProjectIdentities,
|
|
730
742
|
setHomeProjectPermission,
|
|
@@ -742,7 +754,7 @@ import {
|
|
|
742
754
|
storedPathBelongsToIdentity,
|
|
743
755
|
beginBootQuietPeriod,
|
|
744
756
|
scheduleAfterBootQuiet
|
|
745
|
-
} from "./server-
|
|
757
|
+
} from "./server-n33hyq9t.js";
|
|
746
758
|
import {
|
|
747
759
|
resolveModelCalibration,
|
|
748
760
|
calibrateBuckets,
|
|
@@ -763,7 +775,7 @@ import {
|
|
|
763
775
|
latestRealUserTurnIdFromOpenCodeDb,
|
|
764
776
|
getMessageTimesFromOpenCodeDb,
|
|
765
777
|
findLastAssistantModelFromOpenCodeDb
|
|
766
|
-
} from "./server-
|
|
778
|
+
} from "./server-bx5k66qc.js";
|
|
767
779
|
import {
|
|
768
780
|
askAnswerLines,
|
|
769
781
|
estimateTrueRawMessageTokens,
|
|
@@ -791,6 +803,7 @@ import {
|
|
|
791
803
|
cleanUserText2,
|
|
792
804
|
withRawSessionMessageCache2,
|
|
793
805
|
readRawSessionMessages2,
|
|
806
|
+
getRawSessionMessageOrdinalCount2,
|
|
794
807
|
visitRawSessionMessages2,
|
|
795
808
|
visitRawSessionMessagesAsync2,
|
|
796
809
|
prepareRawSessionOrdinals2,
|
|
@@ -805,7 +818,7 @@ import {
|
|
|
805
818
|
readRawSessionMessageOrdinalById2,
|
|
806
819
|
readSessionChunk2,
|
|
807
820
|
readRawSessionSeedTail2
|
|
808
|
-
} from "./server-
|
|
821
|
+
} from "./server-db91dxwc.js";
|
|
809
822
|
import {
|
|
810
823
|
getMessageIndexEpoch,
|
|
811
824
|
isMessageIndexSearchable,
|
|
@@ -831,7 +844,7 @@ import {
|
|
|
831
844
|
resolveMemoriesByIdsForSearch2,
|
|
832
845
|
unifiedSearch2,
|
|
833
846
|
formatSearchResults2
|
|
834
|
-
} from "./server-
|
|
847
|
+
} from "./server-z2nv8jdv.js";
|
|
835
848
|
import {
|
|
836
849
|
startBootDeadline,
|
|
837
850
|
getUnconfirmedMigrationHolders,
|
|
@@ -847,7 +860,7 @@ import {
|
|
|
847
860
|
openDatabaseAsync,
|
|
848
861
|
isDatabasePersisted,
|
|
849
862
|
getDatabasePersistenceError
|
|
850
|
-
} from "./server-
|
|
863
|
+
} from "./server-vsx9tsks.js";
|
|
851
864
|
import {
|
|
852
865
|
V2_MEMORY_CATEGORIES,
|
|
853
866
|
CATEGORY_PRIORITY
|
|
@@ -860,13 +873,13 @@ import {
|
|
|
860
873
|
resolveStoredPathWorkspaceIdentity,
|
|
861
874
|
storedPathBelongsToWorkspace,
|
|
862
875
|
computeWorkspaceEpochFingerprint
|
|
863
|
-
} from "./server-
|
|
876
|
+
} from "./server-2sare4qg.js";
|
|
864
877
|
import {
|
|
865
878
|
gaDatabasePath2,
|
|
866
879
|
RAW_MESSAGE_TYPES2,
|
|
867
880
|
V2StoreReaderPool2,
|
|
868
881
|
V2StoreReader2
|
|
869
|
-
} from "./server-
|
|
882
|
+
} from "./server-vtkbxzw1.js";
|
|
870
883
|
import {
|
|
871
884
|
configureContextDatabasePragmas2
|
|
872
885
|
} from "./server-fb3zxn06.js";
|
|
@@ -895,15 +908,15 @@ import {
|
|
|
895
908
|
createPrimer,
|
|
896
909
|
updatePrimerSupport,
|
|
897
910
|
updatePrimerAnswer
|
|
898
|
-
} from "./server-
|
|
911
|
+
} from "./server-5t4nzfpt.js";
|
|
899
912
|
import {
|
|
900
913
|
deriveTriggerBudget2,
|
|
901
914
|
deriveHistorianChunkTokens2,
|
|
902
915
|
resolveKnownHistorianContextLimit2,
|
|
903
916
|
resolveHistorianProducerLimits2,
|
|
904
917
|
resolveHistorianContextLimit2
|
|
905
|
-
} from "./server-
|
|
906
|
-
import"./server-
|
|
918
|
+
} from "./server-rt8t6s2a.js";
|
|
919
|
+
import"./server-379fd3n7.js";
|
|
907
920
|
import {
|
|
908
921
|
isEmbeddingHostBusy2
|
|
909
922
|
} from "./server-qt1qqasc.js";
|
|
@@ -929,7 +942,7 @@ import {
|
|
|
929
942
|
embedSessionCompartmentChunks2,
|
|
930
943
|
getEmbeddingCoverageStatus2,
|
|
931
944
|
getAutoEmbeddingSessionCoverage2
|
|
932
|
-
} from "./server-
|
|
945
|
+
} from "./server-z5cv5wm5.js";
|
|
933
946
|
import {
|
|
934
947
|
GIT_SWEEP_LEASE_RENEWAL_MS,
|
|
935
948
|
acquireGitSweepLease,
|
|
@@ -939,7 +952,7 @@ import {
|
|
|
939
952
|
releaseGitSweepLease,
|
|
940
953
|
recordSessionProjectIdentity,
|
|
941
954
|
hasRecordedSessionProjectIdentity
|
|
942
|
-
} from "./server-
|
|
955
|
+
} from "./server-6qax5pds.js";
|
|
943
956
|
import {
|
|
944
957
|
saveEmbeddingIfHashMatches,
|
|
945
958
|
invalidateProject2,
|
|
@@ -949,7 +962,7 @@ import {
|
|
|
949
962
|
getCachedLocalEmbeddingPooling,
|
|
950
963
|
preflightLocalEmbeddingPooling,
|
|
951
964
|
getLocalEmbeddingNativeMemoryStats
|
|
952
|
-
} from "./server-
|
|
965
|
+
} from "./server-7h4gwphm.js";
|
|
953
966
|
import {
|
|
954
967
|
renderUserFacingFailure,
|
|
955
968
|
userFacingFailureCode,
|
|
@@ -969,8 +982,8 @@ import {
|
|
|
969
982
|
readGitFileChangeTimesSince,
|
|
970
983
|
verificationFileExists,
|
|
971
984
|
normalizeVerificationFiles
|
|
972
|
-
} from "./server-
|
|
973
|
-
import"./server-
|
|
985
|
+
} from "./server-nnh81jqy.js";
|
|
986
|
+
import"./server-ganavh75.js";
|
|
974
987
|
import {
|
|
975
988
|
computeCueContentHash,
|
|
976
989
|
hasMuralCueColumns,
|
|
@@ -1006,11 +1019,11 @@ import {
|
|
|
1006
1019
|
drainNotifications2,
|
|
1007
1020
|
isTuiConnected2
|
|
1008
1021
|
} from "./server-y14pawe1.js";
|
|
1009
|
-
import"./server-
|
|
1022
|
+
import"./server-63ree5ns.js";
|
|
1010
1023
|
import {
|
|
1011
1024
|
flushIgnoredMessages2,
|
|
1012
1025
|
sendStatusNotification2
|
|
1013
|
-
} from "./server-
|
|
1026
|
+
} from "./server-2cq3e1c1.js";
|
|
1014
1027
|
import {
|
|
1015
1028
|
rememberHostMedia,
|
|
1016
1029
|
hostMediaAsset,
|
|
@@ -1036,7 +1049,7 @@ import {
|
|
|
1036
1049
|
readV2RawMessagePagesForConversion2,
|
|
1037
1050
|
createV2RawMessageReader2,
|
|
1038
1051
|
createV2RawMessageProvider2
|
|
1039
|
-
} from "./server-
|
|
1052
|
+
} from "./server-7tj8yzrv.js";
|
|
1040
1053
|
import {
|
|
1041
1054
|
resolvePromptContext2
|
|
1042
1055
|
} from "./server-fmsr7v69.js";
|
|
@@ -1044,14 +1057,15 @@ import {
|
|
|
1044
1057
|
renderMessageByOrdinal2,
|
|
1045
1058
|
renderVerboseRangeForTool2,
|
|
1046
1059
|
renderItemByTag2
|
|
1047
|
-
} from "./server-
|
|
1048
|
-
import"./server-
|
|
1060
|
+
} from "./server-gh2w75fn.js";
|
|
1061
|
+
import"./server-j1gxs1gj.js";
|
|
1049
1062
|
import {
|
|
1050
1063
|
readV2ArchiveOffThread2
|
|
1051
|
-
} from "./server-
|
|
1064
|
+
} from "./server-ppy2dj7g.js";
|
|
1052
1065
|
import {
|
|
1066
|
+
unresolvedLiveTailRefusal2,
|
|
1053
1067
|
renderSearchArchiveOffThread2
|
|
1054
|
-
} from "./server-
|
|
1068
|
+
} from "./server-pcq2d1wh.js";
|
|
1055
1069
|
import {
|
|
1056
1070
|
markHostInstructionRow,
|
|
1057
1071
|
hostInstructionRow,
|
|
@@ -1087,7 +1101,7 @@ import {
|
|
|
1087
1101
|
} from "./server-8ajstryz.js";
|
|
1088
1102
|
import {
|
|
1089
1103
|
logSlowWriteTransaction
|
|
1090
|
-
} from "./server-
|
|
1104
|
+
} from "./server-tq523gj6.js";
|
|
1091
1105
|
import {
|
|
1092
1106
|
sameProjectDirectory,
|
|
1093
1107
|
canonicalProjectDirectory
|
|
@@ -3365,11 +3379,14 @@ function dropCompartmentsAfter(db, sessionId, anchor, holderId, activeBranch = f
|
|
|
3365
3379
|
return null;
|
|
3366
3380
|
}
|
|
3367
3381
|
const dropped = db.prepare("SELECT id, sequence FROM compartments WHERE session_id = ? AND sequence > ? ORDER BY sequence").all(sessionId, anchor?.sequence ?? -1);
|
|
3368
|
-
|
|
3382
|
+
const previousCoverage = readSummaryCoverage(db, sessionId);
|
|
3383
|
+
const hostQueuedRecovery = onRetire?.() === true;
|
|
3369
3384
|
const deleteEmbeddings = db.prepare("DELETE FROM compartment_chunk_embeddings WHERE compartment_id = ?");
|
|
3370
3385
|
for (const row of dropped)
|
|
3371
3386
|
deleteEmbeddings.run(row.id);
|
|
3372
3387
|
db.prepare("DELETE FROM compartments WHERE session_id = ? AND sequence > ?").run(sessionId, anchor?.sequence ?? -1);
|
|
3388
|
+
if (!hostQueuedRecovery)
|
|
3389
|
+
markHistoryGapAfterCoverageChange(db, sessionId, previousCoverage);
|
|
3373
3390
|
db.prepare("DELETE FROM compression_depth WHERE session_id = ? AND message_ordinal > ?").run(sessionId, anchor?.endMessage ?? 0);
|
|
3374
3391
|
if (activeBranch) {
|
|
3375
3392
|
db.prepare("UPDATE session_meta SET prior_boundary_ordinal = ? WHERE session_id = ?").run((anchor?.endMessage ?? 0) + 1, sessionId);
|
|
@@ -6626,7 +6643,11 @@ function getUnsummarizedTailInfo(db, sessionId, triggerBudget, usage, executeThr
|
|
|
6626
6643
|
}
|
|
6627
6644
|
const rawEligibility = getRawHistoryEligibility(db, sessionId);
|
|
6628
6645
|
if (!rawEligibility.hasRawBeyondLastCompartment) {
|
|
6629
|
-
return {
|
|
6646
|
+
return {
|
|
6647
|
+
...TAIL_INFO_DEFAULTS,
|
|
6648
|
+
nextStartOrdinal: rawEligibility.offset,
|
|
6649
|
+
noRawBeyondSummary: true
|
|
6650
|
+
};
|
|
6630
6651
|
}
|
|
6631
6652
|
const boundary = resolveOpenCodeProtectedTailBoundary({
|
|
6632
6653
|
db,
|
|
@@ -6686,6 +6707,12 @@ function checkCompartmentTrigger(db, sessionId, sessionMeta, usage, _previousPer
|
|
|
6686
6707
|
executeThresholdPercentage
|
|
6687
6708
|
}))
|
|
6688
6709
|
return { shouldFire: false };
|
|
6710
|
+
let historyGapMark = readHistoryGapMark(db, sessionId);
|
|
6711
|
+
const gapCoverageEnd = historyGapMark ? getLastCompartmentEndMessage(db, sessionId) : -1;
|
|
6712
|
+
if (historyGapMark && gapCoverageEnd > historyGapMark.endOrdinal) {
|
|
6713
|
+
clearHistoryGapMark(db, sessionId, historyGapMark.id);
|
|
6714
|
+
historyGapMark = null;
|
|
6715
|
+
}
|
|
6689
6716
|
const lazyInMemoryTail = typeof inMemoryTail === "function" ? inMemoryTail : undefined;
|
|
6690
6717
|
let resolvedInMemoryTail = typeof inMemoryTail === "function" ? undefined : inMemoryTail;
|
|
6691
6718
|
if (resolvedInMemoryTail) {
|
|
@@ -6699,6 +6726,7 @@ function checkCompartmentTrigger(db, sessionId, sessionMeta, usage, _previousPer
|
|
|
6699
6726
|
}
|
|
6700
6727
|
const taggerFloor = taggerFloorOverride !== undefined && taggerFloorOverride > 0 ? taggerFloorOverride : resolvedInMemoryTail ? deriveTagLoadFloor2(db, sessionId, resolvedInMemoryTail.messages.map((m) => m.id)) : 0;
|
|
6701
6728
|
const proactiveFloorForGate = getProactiveCompartmentTriggerPercentage(executeThresholdPercentage);
|
|
6729
|
+
let cheapSkip;
|
|
6702
6730
|
if (usage.percentage < proactiveFloorForGate) {
|
|
6703
6731
|
try {
|
|
6704
6732
|
const boundFloor = resolvedInMemoryTail || lazyInMemoryTail ? taggerFloor : 0;
|
|
@@ -6708,15 +6736,53 @@ function checkCompartmentTrigger(db, sessionId, sessionMeta, usage, _previousPer
|
|
|
6708
6736
|
const seed = sessionDecisionCalibration(db, sessionId);
|
|
6709
6737
|
const eligibleUpperBound = Math.ceil((persistedBound + untaggedUpperBound) * Math.max(1, seed.proseRatio, seed.toolsRatio, seed.systemRatio));
|
|
6710
6738
|
if (eligibleUpperBound < triggerBudget) {
|
|
6711
|
-
|
|
6712
|
-
sessionLog2(sessionId, `compartment trigger: cheap-skip at ${usage.percentage.toFixed(1)}% (below proactive floor ${proactiveFloorForGate}%) — live-tail upper bound ${eligibleUpperBound}${memorySuffix} < triggerBudget ${triggerBudget}; no size trigger possible, skipped full raw read`);
|
|
6713
|
-
return { shouldFire: false };
|
|
6739
|
+
cheapSkip = { eligibleUpperBound, persistedBound, untaggedUpperBound };
|
|
6714
6740
|
}
|
|
6715
6741
|
}
|
|
6716
6742
|
} catch (error) {
|
|
6717
6743
|
sessionLog2(sessionId, `compartment trigger: cheap-gate skipped (falling through to full read): ${error instanceof Error ? error.message : String(error)}`);
|
|
6718
6744
|
}
|
|
6719
6745
|
}
|
|
6746
|
+
const forceMaterializationPercentage = escalationBands(executeThresholdPercentage).forceMaterializationPercentage;
|
|
6747
|
+
let historyGapAdmission;
|
|
6748
|
+
if (historyGapMark && usage.percentage < forceMaterializationPercentage) {
|
|
6749
|
+
const now = Date.now();
|
|
6750
|
+
const checkedAt = historyGapMark.checkedAt;
|
|
6751
|
+
if (checkedAt === undefined || checkedAt > now || now - checkedAt >= EMERGENCY_DRAIN_FAILURE_BACKOFF_MS) {
|
|
6752
|
+
const { failureCount, lastFailureAt } = getHistorianFailureState(db, sessionId);
|
|
6753
|
+
const failedAt = lastFailureAt ?? 0;
|
|
6754
|
+
const admittedRuns = historyGapMark.admittedRuns ?? 0;
|
|
6755
|
+
const previousRunFailed = failureCount > (historyGapMark.failureCountAtAdmission ?? failureCount);
|
|
6756
|
+
if (previousRunFailed && admittedRuns >= 2) {
|
|
6757
|
+
clearHistoryGapMark(db, sessionId, historyGapMark.id);
|
|
6758
|
+
historyGapMark = null;
|
|
6759
|
+
} else if (failedAt <= 0 || failedAt > now || now - failedAt >= EMERGENCY_DRAIN_FAILURE_BACKOFF_MS) {
|
|
6760
|
+
const count = resolvedInMemoryTail?.absoluteMessageCount ?? getRawSessionMessageOrdinalCount2(sessionId);
|
|
6761
|
+
if (count <= Math.max(0, gapCoverageEnd)) {
|
|
6762
|
+
clearHistoryGapMark(db, sessionId, historyGapMark.id);
|
|
6763
|
+
} else {
|
|
6764
|
+
const inspectedCount = historyGapMark.inspectedCount ?? 0;
|
|
6765
|
+
const canAdmit = admittedRuns < 2 && (admittedRuns === 0 || previousRunFailed);
|
|
6766
|
+
const shouldInspect = canAdmit && count > inspectedCount;
|
|
6767
|
+
const nextFrontier = shouldInspect || count < inspectedCount ? count : inspectedCount;
|
|
6768
|
+
if (claimHistoryGapCheck(db, sessionId, historyGapMark, now, nextFrontier) && shouldInspect) {
|
|
6769
|
+
historyGapAdmission = {
|
|
6770
|
+
id: historyGapMark.id,
|
|
6771
|
+
checkedAt: now,
|
|
6772
|
+
admittedRuns: admittedRuns + 1,
|
|
6773
|
+
failureCount
|
|
6774
|
+
};
|
|
6775
|
+
}
|
|
6776
|
+
}
|
|
6777
|
+
}
|
|
6778
|
+
}
|
|
6779
|
+
}
|
|
6780
|
+
if (cheapSkip && !historyGapAdmission) {
|
|
6781
|
+
const { eligibleUpperBound, persistedBound, untaggedUpperBound } = cheapSkip;
|
|
6782
|
+
const memorySuffix = resolvedInMemoryTail ? ` (persisted=${persistedBound}, untagged-memory≤${untaggedUpperBound})` : "";
|
|
6783
|
+
sessionLog2(sessionId, `compartment trigger: cheap-skip at ${usage.percentage.toFixed(1)}% (below proactive floor ${proactiveFloorForGate}%) — live-tail upper bound ${eligibleUpperBound}${memorySuffix} < triggerBudget ${triggerBudget}; no size trigger possible, skipped full raw read`);
|
|
6784
|
+
return { shouldFire: false };
|
|
6785
|
+
}
|
|
6720
6786
|
if (lazyInMemoryTail) {
|
|
6721
6787
|
try {
|
|
6722
6788
|
const policyVersion = loadProtectedTailMeta(db, sessionId).protectedTailPolicyVersion;
|
|
@@ -6743,6 +6809,8 @@ function checkCompartmentTrigger(db, sessionId, sessionMeta, usage, _previousPer
|
|
|
6743
6809
|
}
|
|
6744
6810
|
}
|
|
6745
6811
|
if (!tailInfo.hasNewRawHistory) {
|
|
6812
|
+
if (historyGapMark && tailInfo.noRawBeyondSummary)
|
|
6813
|
+
clearHistoryGapMark(db, sessionId, historyGapMark.id);
|
|
6746
6814
|
try {
|
|
6747
6815
|
const lastCompartmentEnd = getLastCompartmentEndMessage(db, sessionId);
|
|
6748
6816
|
sessionLog2(sessionId, `compartment trigger: skipped — no new raw history (usage=${usage.percentage.toFixed(1)}% nextStartOrdinal=${tailInfo.nextStartOrdinal} lastCompartmentEnd=${lastCompartmentEnd})`);
|
|
@@ -6762,13 +6830,19 @@ function checkCompartmentTrigger(db, sessionId, sessionMeta, usage, _previousPer
|
|
|
6762
6830
|
sessionLog2(sessionId, "compartment trigger: waiting for new history after no forward progress");
|
|
6763
6831
|
return { shouldFire: false };
|
|
6764
6832
|
}
|
|
6833
|
+
if (historyGapAdmission && tailInfo.boundarySnapshot && hasRunnableCompartmentWindow(tailInfo.boundarySnapshot) && recordHistoryGapAdmission(db, sessionId, historyGapAdmission)) {
|
|
6834
|
+
return {
|
|
6835
|
+
shouldFire: true,
|
|
6836
|
+
reason: "history_gap",
|
|
6837
|
+
boundarySnapshot: tailInfo.boundarySnapshot
|
|
6838
|
+
};
|
|
6839
|
+
}
|
|
6765
6840
|
const canClearReasoning = reasoningProjection?.canClearReasoning ?? modelAcceptsEmptyContent(reasoningProjection?.providerID);
|
|
6766
6841
|
const projectedPostDropPercentage = estimateProjectedPostDropPercentage(db, sessionId, usage, preloadedActiveTags ?? getActiveTagsBySession2(db, sessionId), keepReasoningTokens, sessionMeta.clearedReasoningThroughTag, canClearReasoning, reasoningProjection?.budgetCutoff, eligiblePendingDropTagIds);
|
|
6767
6842
|
const relativePostDropTarget = executeThresholdPercentage * POST_DROP_TARGET_RATIO;
|
|
6768
6843
|
const ridePermitted = reclaimRide !== undefined && (reclaimRide.permission ? reclaimRidePermitted(reclaimRide, reclaimRide.permission) : hasReclaimRide(reclaimRide));
|
|
6769
6844
|
const rideLabel = reclaimRide ? reclaimRideLabel(reclaimRide) : "ride=none";
|
|
6770
6845
|
const dropsCanLand = ridePermitted;
|
|
6771
|
-
const forceMaterializationPercentage = escalationBands(executeThresholdPercentage).forceMaterializationPercentage;
|
|
6772
6846
|
if (usage.percentage >= forceMaterializationPercentage) {
|
|
6773
6847
|
if (dropsCanLand && projectedPostDropPercentage !== null && projectedPostDropPercentage <= relativePostDropTarget) {
|
|
6774
6848
|
sessionLog2(sessionId, `historian redundancy skip: summarizer not needed this pass — force band is ${forceMaterializationPercentage}%; queued/automatic drops are projected to reclaim to ${projectedPostDropPercentage.toFixed(1)}% (target ${relativePostDropTarget.toFixed(1)}%) on this pass (${rideLabel})`);
|
|
@@ -12640,7 +12714,7 @@ async function runPostTransformPhase(args) {
|
|
|
12640
12714
|
if (args.pendingCompartmentInjection.compartmentEndMessageId === null) {
|
|
12641
12715
|
const nextCount = (degradedCacheCountBySession.get(args.sessionId) ?? 0) + 1;
|
|
12642
12716
|
degradedCacheCountBySession.set(args.sessionId, nextCount);
|
|
12643
|
-
if (nextCount === DEGRADE_CACHE_WARNING_THRESHOLD) {
|
|
12717
|
+
if (nextCount === DEGRADE_CACHE_WARNING_THRESHOLD && !args.expectedAbsentCompartmentBoundary) {
|
|
12644
12718
|
sessionLog2(args.sessionId, `WARNING: compartment injection cache has rebuilt with a degraded null boundary ${nextCount} consecutive times; investigate missing boundary messages`);
|
|
12645
12719
|
}
|
|
12646
12720
|
} else {
|
|
@@ -20718,7 +20792,7 @@ async function runCompartmentPhaseImpl(args) {
|
|
|
20718
20792
|
function refreshCompartmentCoverage() {
|
|
20719
20793
|
sessionLog2(args.sessionId, "transform: compartment agent completed, refreshing compartment coverage");
|
|
20720
20794
|
const historyReprepareShouldBust = published && args.deferredHistoryRefreshSessions.has(args.sessionId);
|
|
20721
|
-
pendingCompartmentInjection = prepareCompartmentInjection(args.db, args.resolvedSessionId, args.messages, historyReprepareShouldBust, args.coveredInstructions, args.projectPath, args.injectionBudgetTokens, args.experimentalTemporalAwareness);
|
|
20795
|
+
pendingCompartmentInjection = prepareCompartmentInjection(args.db, args.resolvedSessionId, args.messages, historyReprepareShouldBust, args.coveredInstructions, args.projectPath, args.injectionBudgetTokens, args.experimentalTemporalAwareness, undefined, args.restoredBoundaryDiagnostic);
|
|
20722
20796
|
if (historyReprepareShouldBust) {
|
|
20723
20797
|
rebuiltHistoryThisPass = true;
|
|
20724
20798
|
}
|
|
@@ -21957,6 +22031,8 @@ ${notice}`, notificationParams));
|
|
|
21957
22031
|
logTransformTiming(sessionId, "compartmentTrigger", tTrigger);
|
|
21958
22032
|
}
|
|
21959
22033
|
let pendingCompartmentInjection = null;
|
|
22034
|
+
const restoredAfterId = deps.restoredAfterSummaryBoundary?.(sessionId);
|
|
22035
|
+
const restoredBoundaryDiagnostic = restoredAfterId ? { restoredAfterId, expectedAbsence: false } : undefined;
|
|
21960
22036
|
let rebuiltHistoryFromInitialPrepare = false;
|
|
21961
22037
|
let hiddenMessagesAtCompactionSeam = [];
|
|
21962
22038
|
let trimmedMessagesAtCompactionBoundary = [];
|
|
@@ -21967,7 +22043,7 @@ ${notice}`, notificationParams));
|
|
|
21967
22043
|
hasCachedM0: sessionMeta.cachedM0Bytes !== null,
|
|
21968
22044
|
boundary: sessionMeta.cachedM0TrimBoundaryId,
|
|
21969
22045
|
partial: sessionMeta.cachedM0TrimBoundaryPartial ?? true
|
|
21970
|
-
});
|
|
22046
|
+
}, restoredBoundaryDiagnostic);
|
|
21971
22047
|
if (messagesBeforeInitialPrepare) {
|
|
21972
22048
|
const skippedVisibleMessages = pendingCompartmentInjection?.skippedVisibleMessages ?? 0;
|
|
21973
22049
|
trimmedMessagesAtCompactionBoundary = messagesBeforeInitialPrepare.slice(0, skippedVisibleMessages);
|
|
@@ -22212,6 +22288,7 @@ ${notice}`, notificationParams));
|
|
|
22212
22288
|
messages,
|
|
22213
22289
|
coveredInstructions: coveredHostInstructions,
|
|
22214
22290
|
pendingCompartmentInjection,
|
|
22291
|
+
restoredBoundaryDiagnostic,
|
|
22215
22292
|
fallbackModelId,
|
|
22216
22293
|
projectPath: projectIdentity,
|
|
22217
22294
|
injectionBudgetTokens: deps.memoryConfig?.injectionBudgetTokens,
|
|
@@ -22548,6 +22625,7 @@ ${notice}`, notificationParams));
|
|
|
22548
22625
|
},
|
|
22549
22626
|
deferredHistoryWasPendingAtPassStart,
|
|
22550
22627
|
compartmentInjectionRebuiltFromDb: pendingCompartmentInjection?.rebuiltFromDb === true,
|
|
22628
|
+
expectedAbsentCompartmentBoundary: restoredBoundaryDiagnostic?.expectedAbsence,
|
|
22551
22629
|
rebuiltHistoryFromInitialPrepare,
|
|
22552
22630
|
historyRebuiltThisPass,
|
|
22553
22631
|
canConsumeDeferredLate,
|
|
@@ -26509,7 +26587,7 @@ function registerRpcHandlers(rpcServer, args) {
|
|
|
26509
26587
|
return { count: buildCompartmentCount(db, sessionId, moduleStatus) };
|
|
26510
26588
|
});
|
|
26511
26589
|
const buildManagedCtx = async (db) => {
|
|
26512
|
-
const { deriveHistorianChunkTokens, resolveHistorianContextLimit } = await importPluginModule(() => import("./derive-budgets-
|
|
26590
|
+
const { deriveHistorianChunkTokens, resolveHistorianContextLimit } = await importPluginModule(() => import("./derive-budgets-wj0q7s7d.js"));
|
|
26513
26591
|
const { resolveHistorianModel } = await importPluginModule(() => import("./model-resolution-280gmqvd.js"));
|
|
26514
26592
|
const { userObservationCollectionEnabled, userObservationsRequested } = await importPluginModule(() => import("./task-config-4nqq2s0w.js"));
|
|
26515
26593
|
const DEFAULT_HISTORIAN_TIMEOUT_MS = 10 * 60 * 1000;
|
|
@@ -26542,7 +26620,7 @@ function registerRpcHandlers(rpcServer, args) {
|
|
|
26542
26620
|
return { ok: false, error: "no session" };
|
|
26543
26621
|
const readDirectory = args.readSessionDirectory;
|
|
26544
26622
|
if (readDirectory) {
|
|
26545
|
-
const { handoffHistoryWork } = await import("./history-owner-
|
|
26623
|
+
const { handoffHistoryWork } = await import("./history-owner-8pd5ax3n.js");
|
|
26546
26624
|
const handed = await handoffHistoryWork({
|
|
26547
26625
|
storageDir: args.storageDir ?? getMagicContextStorageDir(),
|
|
26548
26626
|
directory,
|
|
@@ -26561,8 +26639,8 @@ function registerRpcHandlers(rpcServer, args) {
|
|
|
26561
26639
|
const db = readDatabase();
|
|
26562
26640
|
if (!db)
|
|
26563
26641
|
return { ok: false, error: "db unavailable" };
|
|
26564
|
-
const { runManagedRecomp } = await importPluginModule(() => import("./recomp-orchestrator-
|
|
26565
|
-
const { sendIgnoredMessage } = await importPluginModule(() => import("./send-session-notification-
|
|
26642
|
+
const { runManagedRecomp } = await importPluginModule(() => import("./recomp-orchestrator-pfjpzdrb.js"));
|
|
26643
|
+
const { sendIgnoredMessage } = await importPluginModule(() => import("./send-session-notification-8x146x5y.js"));
|
|
26566
26644
|
log2(`[rpc] recomp requested for session ${sessionId}`);
|
|
26567
26645
|
if (!args.client && !args.hiddenCompletionExecutor) {
|
|
26568
26646
|
return {
|
|
@@ -26620,7 +26698,7 @@ function registerRpcHandlers(rpcServer, args) {
|
|
|
26620
26698
|
rpcServer.handle("wrapup", async (params) => {
|
|
26621
26699
|
const readDirectory = args.readSessionDirectory;
|
|
26622
26700
|
if (readDirectory && params.sessionId) {
|
|
26623
|
-
const { handoffHistoryWork } = await import("./history-owner-
|
|
26701
|
+
const { handoffHistoryWork } = await import("./history-owner-8pd5ax3n.js");
|
|
26624
26702
|
const sessionId = String(params.sessionId);
|
|
26625
26703
|
const handed = await handoffHistoryWork({
|
|
26626
26704
|
storageDir: args.storageDir ?? getMagicContextStorageDir(),
|
|
@@ -26646,7 +26724,7 @@ function registerRpcHandlers(rpcServer, args) {
|
|
|
26646
26724
|
const db = readDatabase();
|
|
26647
26725
|
if (!db)
|
|
26648
26726
|
return { ok: false, error: "db unavailable" };
|
|
26649
|
-
const { runManagedWrapup } = await importPluginModule(() => import("./wrapup-orchestrator-
|
|
26727
|
+
const { runManagedWrapup } = await importPluginModule(() => import("./wrapup-orchestrator-kcq3cv7y.js"));
|
|
26650
26728
|
const model = await args.readSelectedSessionModel?.(sessionId) ?? liveSessionState.liveModelBySession.get(sessionId);
|
|
26651
26729
|
const window = resolveOpenCodeWrapupWindow(db, sessionId, model);
|
|
26652
26730
|
if (!window)
|
|
@@ -27030,6 +27108,28 @@ function readOmoDisabledHooks(directory) {
|
|
|
27030
27108
|
return disabled;
|
|
27031
27109
|
}
|
|
27032
27110
|
|
|
27111
|
+
// src/shared/host-sqlite-runtime.ts
|
|
27112
|
+
var RECORDED = Symbol.for("magic-context.host-sqlite-runtime-recorded");
|
|
27113
|
+
function recordHostSqliteRuntime(db, harness, write = (line) => sessionLog2("global", line)) {
|
|
27114
|
+
const processGlobals = globalThis;
|
|
27115
|
+
if (processGlobals[RECORDED])
|
|
27116
|
+
return;
|
|
27117
|
+
try {
|
|
27118
|
+
const row = db.prepare("SELECT sqlite_version() AS version").get();
|
|
27119
|
+
if (!row?.version)
|
|
27120
|
+
return;
|
|
27121
|
+
const bun = detectSqliteRuntime2() === "Bun";
|
|
27122
|
+
const electron = !bun && process.versions.electron;
|
|
27123
|
+
const runtime = bun ? "Bun" : electron ? "Electron" : "Node.js";
|
|
27124
|
+
const version = bun ? process.versions.bun : electron || process.versions.node;
|
|
27125
|
+
if (!version)
|
|
27126
|
+
return;
|
|
27127
|
+
const binding = bun ? "bun:sqlite" : "node:sqlite";
|
|
27128
|
+
processGlobals[RECORDED] = true;
|
|
27129
|
+
write(`host SQLite runtime harness=${harness} sqlite=${row.version} runtime=${runtime} version=${version} binding=${binding}`);
|
|
27130
|
+
} catch {}
|
|
27131
|
+
}
|
|
27132
|
+
|
|
27033
27133
|
// src/shared/rpc-server.ts
|
|
27034
27134
|
import { randomBytes, timingSafeEqual } from "node:crypto";
|
|
27035
27135
|
import { readdirSync, readFileSync as readFileSync4, rmdirSync, unlinkSync } from "node:fs";
|
|
@@ -28285,6 +28385,9 @@ class NativeFoldCache {
|
|
|
28285
28385
|
const kept = this.nativeRows.get(sessionID);
|
|
28286
28386
|
return ids.every((id) => kept?.has(id));
|
|
28287
28387
|
}
|
|
28388
|
+
holdsState(sessionID) {
|
|
28389
|
+
return this.tails.has(sessionID) || (this.nativeRows.get(sessionID)?.size ?? 0) > 0;
|
|
28390
|
+
}
|
|
28288
28391
|
rows(sessionID, after, through) {
|
|
28289
28392
|
if (this.retention.has(sessionID))
|
|
28290
28393
|
this.touch(sessionID);
|
|
@@ -29185,8 +29288,11 @@ class NativeFoldReplay {
|
|
|
29185
29288
|
stampMRU;
|
|
29186
29289
|
loaded = new Map;
|
|
29187
29290
|
sources = new Map;
|
|
29291
|
+
memorySources = new Map;
|
|
29188
29292
|
staleHeads = new Set;
|
|
29189
29293
|
unprovenControls = new Set;
|
|
29294
|
+
reportedCaptureReplacements = new Set;
|
|
29295
|
+
reportedForeignRefreshes = new Set;
|
|
29190
29296
|
editedAdmissions = new Map;
|
|
29191
29297
|
legacyUpgrades = new Map;
|
|
29192
29298
|
constructor(storage, openReader, admissions, options = {}) {
|
|
@@ -29210,6 +29316,7 @@ class NativeFoldReplay {
|
|
|
29210
29316
|
await this.forget(sessionID);
|
|
29211
29317
|
this.sources.set(sessionID, source);
|
|
29212
29318
|
this.account(sessionID);
|
|
29319
|
+
return source;
|
|
29213
29320
|
}
|
|
29214
29321
|
onEvent(event) {
|
|
29215
29322
|
const sessionID = event.data?.sessionID;
|
|
@@ -29282,6 +29389,18 @@ class NativeFoldReplay {
|
|
|
29282
29389
|
this.options.log?.(sessionID, `v3 host fold: ${reason}`);
|
|
29283
29390
|
} catch {}
|
|
29284
29391
|
}
|
|
29392
|
+
reportOnce(sessionID, reported, message) {
|
|
29393
|
+
if (reported.has(sessionID))
|
|
29394
|
+
return;
|
|
29395
|
+
reported.add(sessionID);
|
|
29396
|
+
const sessionLog = this.options.log;
|
|
29397
|
+
try {
|
|
29398
|
+
sessionLog?.(sessionID, message);
|
|
29399
|
+
} catch {}
|
|
29400
|
+
}
|
|
29401
|
+
reportCaptureReplacement(sessionID) {
|
|
29402
|
+
this.reportOnce(sessionID, this.reportedCaptureReplacements, "v3 host fold: capture skipped: host database file changed between readers");
|
|
29403
|
+
}
|
|
29285
29404
|
historyCoverage(sessionID, reader) {
|
|
29286
29405
|
if (!this.options.rendersHistory?.(sessionID))
|
|
29287
29406
|
return;
|
|
@@ -29298,13 +29417,15 @@ class NativeFoldReplay {
|
|
|
29298
29417
|
return false;
|
|
29299
29418
|
}
|
|
29300
29419
|
async floorState(sessionID, reader, boundary, served, preferCapture = false) {
|
|
29420
|
+
const source = reader.hostIdentity();
|
|
29421
|
+
await this.fenceMemory(sessionID, source);
|
|
29301
29422
|
const coverage = this.historyCoverage(sessionID, reader);
|
|
29302
29423
|
const retained = this.tail(sessionID)?.replay;
|
|
29303
29424
|
const controlsKnown = (replay) => replay.controls.every((control) => !control.after || reader.sequenceForId(sessionID, control.after) !== undefined);
|
|
29304
29425
|
const memory = retained && validReplayState(retained) && controlsKnown(retained) && validFloor(reader, sessionID, retained.floor) && this.floorCovered(sessionID, retained.floor, coverage, retained) ? retained : undefined;
|
|
29305
29426
|
const cut = reader.latestCompaction(sessionID);
|
|
29306
29427
|
const saved = await this.readV3(sessionID);
|
|
29307
|
-
const durable = saved && saved.proof.sourceDigest === foldDigest(
|
|
29428
|
+
const durable = saved && saved.proof.sourceDigest === foldDigest(source) && (!cut || saved.proof.admissionID === cut.id) && controlsKnown(saved.replay) && validFloor(reader, sessionID, saved.replay.floor) && this.floorCovered(sessionID, saved.replay.floor, coverage, saved.replay) ? saved.replay : undefined;
|
|
29308
29429
|
const marker = importedFloor(reader, sessionID, cut?.seq);
|
|
29309
29430
|
const imported = marker && this.floorCovered(sessionID, marker, coverage) ? marker : undefined;
|
|
29310
29431
|
const capturedRecord = await this.readCapturedReplay(sessionID, reader);
|
|
@@ -29364,11 +29485,11 @@ class NativeFoldReplay {
|
|
|
29364
29485
|
return;
|
|
29365
29486
|
}
|
|
29366
29487
|
}
|
|
29367
|
-
async saveCapturedReplay(sessionID, replay, reader) {
|
|
29488
|
+
async saveCapturedReplay(sessionID, replay, reader, sourceDigest) {
|
|
29368
29489
|
const value = {
|
|
29369
29490
|
version: 3,
|
|
29370
29491
|
sessionID,
|
|
29371
|
-
sourceDigest
|
|
29492
|
+
sourceDigest,
|
|
29372
29493
|
through: reader.latestSequence(sessionID),
|
|
29373
29494
|
replay
|
|
29374
29495
|
};
|
|
@@ -29398,11 +29519,33 @@ class NativeFoldReplay {
|
|
|
29398
29519
|
${cached}
|
|
29399
29520
|
</summary>`)))) ? cached : undefined;
|
|
29400
29521
|
}
|
|
29401
|
-
async retainReplay(sessionID, replay, model, sourceSeq) {
|
|
29522
|
+
async retainReplay(sessionID, replay, model, sourceSeq, source) {
|
|
29523
|
+
await this.fenceMemory(sessionID, source);
|
|
29402
29524
|
const tail = this.tail(sessionID) ?? { model, sourceSeq };
|
|
29403
29525
|
await this.storage.saveTail(sessionID, JSON.stringify({ ...tail, replay }), []);
|
|
29404
29526
|
if (!this.storage.tail(sessionID))
|
|
29405
29527
|
await this.storage.saveTail(sessionID, JSON.stringify({ model, sourceSeq, replay }), []);
|
|
29528
|
+
this.memorySources.set(sessionID, source);
|
|
29529
|
+
}
|
|
29530
|
+
async fenceMemory(sessionID, source) {
|
|
29531
|
+
const recorded = this.memorySources.get(sessionID);
|
|
29532
|
+
if (recorded === source)
|
|
29533
|
+
return;
|
|
29534
|
+
if (recorded === undefined && !this.storage.holdsState(sessionID) && !this.metadata.has(sessionID))
|
|
29535
|
+
return;
|
|
29536
|
+
await this.discardCapture(sessionID);
|
|
29537
|
+
this.reportCaptureReplacement(sessionID);
|
|
29538
|
+
}
|
|
29539
|
+
async discardCapture(sessionID) {
|
|
29540
|
+
if (this.stampMRU?.sessionID === sessionID)
|
|
29541
|
+
this.stampMRU = undefined;
|
|
29542
|
+
const source = this.sources.get(sessionID);
|
|
29543
|
+
const forgotten = this.storage.forget(sessionID);
|
|
29544
|
+
if (source !== undefined) {
|
|
29545
|
+
this.sources.set(sessionID, source);
|
|
29546
|
+
this.account(sessionID);
|
|
29547
|
+
}
|
|
29548
|
+
await forgotten;
|
|
29406
29549
|
}
|
|
29407
29550
|
async canFold(sessionID, reader) {
|
|
29408
29551
|
if (this.options.protocol !== 3) {
|
|
@@ -29503,7 +29646,7 @@ ${cached}
|
|
|
29503
29646
|
}
|
|
29504
29647
|
};
|
|
29505
29648
|
this.legacyUpgrades.set(draft.sessionID, { value, rows, started });
|
|
29506
|
-
await this.retainReplay(draft.sessionID, replay, `${draft.model.providerID}/${draft.model.id}`, cut.seq - 1);
|
|
29649
|
+
await this.retainReplay(draft.sessionID, replay, `${draft.model.providerID}/${draft.model.id}`, cut.seq - 1, reader.hostIdentity());
|
|
29507
29650
|
return true;
|
|
29508
29651
|
}
|
|
29509
29652
|
legacyUpgradeInput(sessionID, model) {
|
|
@@ -29511,8 +29654,16 @@ ${cached}
|
|
|
29511
29654
|
if (!pending)
|
|
29512
29655
|
return;
|
|
29513
29656
|
let reader;
|
|
29657
|
+
const open = () => {
|
|
29658
|
+
const opened = this.openReader(sessionID);
|
|
29659
|
+
if (foldDigest(opened.hostIdentity()) !== pending.value.proof.sourceDigest) {
|
|
29660
|
+
opened.close();
|
|
29661
|
+
throw new NativeReplayUnavailable("Host database file changed during upgrade");
|
|
29662
|
+
}
|
|
29663
|
+
return opened;
|
|
29664
|
+
};
|
|
29514
29665
|
const blobs = {
|
|
29515
|
-
mediaBlob: (hash) => (reader ??=
|
|
29666
|
+
mediaBlob: (hash) => (reader ??= open()).mediaBlob(hash)
|
|
29516
29667
|
};
|
|
29517
29668
|
try {
|
|
29518
29669
|
return pending.rows.filter((row) => row.seq > pending.value.replay.floor.after).flatMap((row) => {
|
|
@@ -29532,6 +29683,11 @@ ${cached}
|
|
|
29532
29683
|
const admissions = this.admissions;
|
|
29533
29684
|
if (!pending || !admissions)
|
|
29534
29685
|
return false;
|
|
29686
|
+
const recorded = this.memorySources.get(sessionID);
|
|
29687
|
+
if (recorded === undefined ? this.storage.holdsState(sessionID) || this.metadata.has(sessionID) : foldDigest(recorded) !== pending.value.proof.sourceDigest) {
|
|
29688
|
+
await this.discardCapture(sessionID);
|
|
29689
|
+
this.reportCaptureReplacement(sessionID);
|
|
29690
|
+
}
|
|
29535
29691
|
const replay = this.tail(sessionID)?.replay ?? pending.value.replay;
|
|
29536
29692
|
if (replay.blocked)
|
|
29537
29693
|
return false;
|
|
@@ -29569,13 +29725,16 @@ ${cached}
|
|
|
29569
29725
|
stripCheckpointRecentContext(rendered, row.data.summary ?? "");
|
|
29570
29726
|
return { row, rendered, submitted: row.data.summary ?? "" };
|
|
29571
29727
|
}
|
|
29572
|
-
async checkpointCovered(sessionID, checkpointID) {
|
|
29728
|
+
async checkpointCovered(sessionID, checkpointID, sourceIdentity) {
|
|
29573
29729
|
const admissions = this.admissions;
|
|
29574
29730
|
if (!admissions)
|
|
29575
29731
|
return;
|
|
29732
|
+
await this.fenceMemory(sessionID, sourceIdentity);
|
|
29576
29733
|
const pending = this.legacyUpgrades.get(sessionID);
|
|
29577
|
-
const
|
|
29578
|
-
|
|
29734
|
+
const sourceDigest = foldDigest(sourceIdentity);
|
|
29735
|
+
const saved = await this.readV3(sessionID);
|
|
29736
|
+
const value = saved?.proof.sourceDigest === sourceDigest ? saved : pending?.value;
|
|
29737
|
+
if (value?.proof.sourceDigest !== sourceDigest || value.replay.floor.kind !== "host-checkpoint" || value.replay.floor.id !== checkpointID || value.replay.withoutRecentContext)
|
|
29579
29738
|
return;
|
|
29580
29739
|
value.replay.withoutRecentContext = true;
|
|
29581
29740
|
const payload = encodeAdmissionV3(value);
|
|
@@ -29586,7 +29745,7 @@ ${cached}
|
|
|
29586
29745
|
});
|
|
29587
29746
|
const tail = this.tail(sessionID);
|
|
29588
29747
|
if (tail)
|
|
29589
|
-
await this.retainReplay(sessionID, value.replay, tail.model, tail.sourceSeq);
|
|
29748
|
+
await this.retainReplay(sessionID, value.replay, tail.model, tail.sourceSeq, sourceIdentity);
|
|
29590
29749
|
}
|
|
29591
29750
|
async removeAdmission(key) {
|
|
29592
29751
|
if (this.admissions?.remove)
|
|
@@ -29604,7 +29763,8 @@ ${cached}
|
|
|
29604
29763
|
if (!saved || !isLocalCheckpoint(cut) || cut.session_id !== sessionID)
|
|
29605
29764
|
return false;
|
|
29606
29765
|
const proof = saved.proof;
|
|
29607
|
-
|
|
29766
|
+
const source = reader.hostIdentity();
|
|
29767
|
+
if (proof.sourceDigest !== foldDigest(source) || proof.admissionID !== cut.id || proof.summaryDigest !== foldDigest(cut.data.summary ?? "")) {
|
|
29608
29768
|
this.report(sessionID, "replay refused: invalid checkpoint floor or provenance");
|
|
29609
29769
|
return false;
|
|
29610
29770
|
}
|
|
@@ -29620,17 +29780,17 @@ ${cached}
|
|
|
29620
29780
|
this.editedAdmissions.set(sessionID, { original: saved, replay });
|
|
29621
29781
|
this.staleHeads.add(sessionID);
|
|
29622
29782
|
this.invalidate(sessionID);
|
|
29623
|
-
await this.retainReplay(sessionID, replay, this.tail(sessionID)?.model ?? "", cut.seq - 1);
|
|
29783
|
+
await this.retainReplay(sessionID, replay, this.tail(sessionID)?.model ?? "", cut.seq - 1, source);
|
|
29624
29784
|
return false;
|
|
29625
29785
|
}
|
|
29626
29786
|
if (!this.floorCovered(sessionID, replay.floor, this.historyCoverage(sessionID, reader), replay))
|
|
29627
29787
|
return false;
|
|
29628
|
-
await this.retainReplay(sessionID, saved.replay, this.tail(sessionID)?.model ?? "", cut.seq - 1);
|
|
29788
|
+
await this.retainReplay(sessionID, saved.replay, this.tail(sessionID)?.model ?? "", cut.seq - 1, source);
|
|
29629
29789
|
if (proof.historyDigest !== historyDigest(reader, sessionID, cut.seq - 1, saved.replay.floor.after)) {
|
|
29630
29790
|
this.staleHeads.add(sessionID);
|
|
29631
29791
|
this.invalidate(sessionID);
|
|
29632
29792
|
this.editedAdmissions.set(sessionID, { original: saved, replay });
|
|
29633
|
-
await this.retainReplay(sessionID, saved.replay, this.tail(sessionID)?.model ?? "", cut.seq - 1);
|
|
29793
|
+
await this.retainReplay(sessionID, saved.replay, this.tail(sessionID)?.model ?? "", cut.seq - 1, source);
|
|
29634
29794
|
return false;
|
|
29635
29795
|
}
|
|
29636
29796
|
await this.storage.supply(sessionID, cut.id, JSON.stringify({
|
|
@@ -29682,6 +29842,7 @@ ${cached}
|
|
|
29682
29842
|
return false;
|
|
29683
29843
|
const reader = this.openReader(sessionID);
|
|
29684
29844
|
try {
|
|
29845
|
+
await this.fenceMemory(sessionID, reader.hostIdentity());
|
|
29685
29846
|
const cut = reader.latestCompaction(sessionID);
|
|
29686
29847
|
const proof = pending.original.proof;
|
|
29687
29848
|
const replay = this.tail(sessionID)?.replay ?? pending.replay;
|
|
@@ -29886,14 +30047,23 @@ ${cached}
|
|
|
29886
30047
|
}
|
|
29887
30048
|
return [...grouped].map(([row, messages]) => this.record(row, messages));
|
|
29888
30049
|
}
|
|
29889
|
-
async capture(draft, native, boundary, restoredFirstRow) {
|
|
30050
|
+
async capture(draft, native, draftSourceIdentity, boundary, restoredFirstRow) {
|
|
29890
30051
|
const release = this.storage.hold(draft.sessionID);
|
|
29891
30052
|
let replay;
|
|
30053
|
+
let capturedIdentity;
|
|
29892
30054
|
let sourceSeq = -1;
|
|
29893
30055
|
try {
|
|
29894
30056
|
rememberHostMedia(native);
|
|
29895
30057
|
const reader = this.openReader(draft.sessionID);
|
|
29896
30058
|
try {
|
|
30059
|
+
capturedIdentity = reader.hostIdentity();
|
|
30060
|
+
if (capturedIdentity !== draftSourceIdentity) {
|
|
30061
|
+
await this.discardCapture(draft.sessionID);
|
|
30062
|
+
this.reportCaptureReplacement(draft.sessionID);
|
|
30063
|
+
return;
|
|
30064
|
+
}
|
|
30065
|
+
await this.fenceMemory(draft.sessionID, capturedIdentity);
|
|
30066
|
+
this.memorySources.set(draft.sessionID, capturedIdentity);
|
|
29897
30067
|
if (this.options.protocol === 3) {
|
|
29898
30068
|
replay = await this.floorState(draft.sessionID, reader, boundary, draft);
|
|
29899
30069
|
if (!replay && restoredFirstRow) {
|
|
@@ -29943,6 +30113,7 @@ ${cached}
|
|
|
29943
30113
|
};
|
|
29944
30114
|
await this.storage.saveTail(draft.sessionID, JSON.stringify(tail), rows);
|
|
29945
30115
|
this.storage.truncate(draft.sessionID, through);
|
|
30116
|
+
this.memorySources.set(draft.sessionID, capturedIdentity);
|
|
29946
30117
|
this.loaded.set(draft.sessionID, through);
|
|
29947
30118
|
this.unavailable.delete(draft.sessionID);
|
|
29948
30119
|
this.changed.delete(draft.sessionID);
|
|
@@ -29965,13 +30136,24 @@ ${cached}
|
|
|
29965
30136
|
}
|
|
29966
30137
|
}
|
|
29967
30138
|
if (replay) {
|
|
29968
|
-
await this.retainReplay(draft.sessionID, replay, `${draft.model.providerID}/${draft.model.id}`, sourceSeq);
|
|
30139
|
+
await this.retainReplay(draft.sessionID, replay, `${draft.model.providerID}/${draft.model.id}`, sourceSeq, draftSourceIdentity);
|
|
29969
30140
|
const reader = this.openReader(draft.sessionID);
|
|
29970
30141
|
try {
|
|
29971
|
-
|
|
30142
|
+
const identity = reader.hostIdentity();
|
|
30143
|
+
if (identity !== capturedIdentity) {
|
|
30144
|
+
await this.discardCapture(draft.sessionID);
|
|
30145
|
+
this.reportCaptureReplacement(draft.sessionID);
|
|
30146
|
+
return;
|
|
30147
|
+
}
|
|
30148
|
+
const sourceDigest = foldDigest(identity);
|
|
30149
|
+
await this.saveCapturedReplay(draft.sessionID, replay, reader, sourceDigest);
|
|
29972
30150
|
const saved = await this.readV3(draft.sessionID);
|
|
29973
30151
|
const cut = reader.latestCompaction(draft.sessionID);
|
|
29974
30152
|
if (saved && !this.editedAdmissions.has(draft.sessionID) && cut?.id === saved.proof.admissionID && (replay.floor.after > saved.replay.floor.after || !this.floorCovered(draft.sessionID, saved.replay.floor, this.historyCoverage(draft.sessionID, reader), saved.replay)) && (boundary && this.servedBaseline(draft) === boundary.summary || replay.floor.kind === "start" && restoredFirstRow === replay.floor.id)) {
|
|
30153
|
+
if (saved.proof.sourceDigest !== sourceDigest) {
|
|
30154
|
+
this.reportOnce(draft.sessionID, this.reportedForeignRefreshes, "v3 host fold: admission refresh skipped: admission belongs to a different host database file");
|
|
30155
|
+
return;
|
|
30156
|
+
}
|
|
29975
30157
|
const value = {
|
|
29976
30158
|
...saved,
|
|
29977
30159
|
replay: {
|
|
@@ -30014,6 +30196,8 @@ ${cached}
|
|
|
30014
30196
|
async supplyHeld(args) {
|
|
30015
30197
|
const { draft, reader, summary } = args;
|
|
30016
30198
|
const stored = args.checkpointText ?? summary;
|
|
30199
|
+
const source = reader.hostIdentity();
|
|
30200
|
+
await this.fenceMemory(draft.sessionID, source);
|
|
30017
30201
|
if (this.options.protocol === 3) {
|
|
30018
30202
|
if (this.unprovenControls.has(draft.sessionID))
|
|
30019
30203
|
return false;
|
|
@@ -30038,7 +30222,7 @@ ${cached}
|
|
|
30038
30222
|
if (!args.manual && this.tail(draft.sessionID)?.model !== model)
|
|
30039
30223
|
this.storage.replaceRows(draft.sessionID, reader.latestSequence(draft.sessionID), []);
|
|
30040
30224
|
if (!args.manual)
|
|
30041
|
-
await this.retainReplay(draft.sessionID, replay, model, reader.latestSequence(draft.sessionID));
|
|
30225
|
+
await this.retainReplay(draft.sessionID, replay, model, reader.latestSequence(draft.sessionID), source);
|
|
30042
30226
|
if (!args.manual)
|
|
30043
30227
|
await this.storage.supply(draft.sessionID, running.id, JSON.stringify({
|
|
30044
30228
|
source: this.storage.sourceID,
|
|
@@ -30100,7 +30284,7 @@ ${cached}
|
|
|
30100
30284
|
this.invalidate(draft.sessionID);
|
|
30101
30285
|
this.cancelLegacyUpgrade(draft.sessionID);
|
|
30102
30286
|
this.cancelEditedAdmission(draft.sessionID);
|
|
30103
|
-
await this.retainReplay(draft.sessionID, replay, model, running.seq - 1);
|
|
30287
|
+
await this.retainReplay(draft.sessionID, replay, model, running.seq - 1, source);
|
|
30104
30288
|
await this.storage.supply(draft.sessionID, running.id, JSON.stringify({
|
|
30105
30289
|
source: this.storage.sourceID,
|
|
30106
30290
|
sessionID: draft.sessionID,
|
|
@@ -30133,6 +30317,7 @@ ${cached}
|
|
|
30133
30317
|
baseline: tail?.baseline ?? summary,
|
|
30134
30318
|
sourceSeq: Math.max(tail?.sourceSeq ?? through, ...fresh.map((row) => row.seq))
|
|
30135
30319
|
}), records);
|
|
30320
|
+
this.memorySources.set(draft.sessionID, source);
|
|
30136
30321
|
this.dirty.delete(draft.sessionID);
|
|
30137
30322
|
this.metadata.delete(draft.sessionID);
|
|
30138
30323
|
this.metadataThrough.delete(draft.sessionID);
|
|
@@ -30161,13 +30346,16 @@ ${cached}
|
|
|
30161
30346
|
}
|
|
30162
30347
|
return true;
|
|
30163
30348
|
}
|
|
30164
|
-
async restore(sessionID, cut, model, options = {}) {
|
|
30349
|
+
async restore(sessionID, cut, model, passSource, options = {}) {
|
|
30165
30350
|
let replay;
|
|
30166
30351
|
let controls = [];
|
|
30167
30352
|
let after;
|
|
30353
|
+
await this.fenceMemory(sessionID, passSource);
|
|
30168
30354
|
if (this.options.protocol === 3) {
|
|
30169
30355
|
const reader = this.openReader(sessionID);
|
|
30170
30356
|
try {
|
|
30357
|
+
if (reader.hostIdentity() !== passSource)
|
|
30358
|
+
throw new NativeReplayUnavailable("Host database file changed during restore");
|
|
30171
30359
|
replay = await this.floorState(sessionID, reader);
|
|
30172
30360
|
if (replay) {
|
|
30173
30361
|
controls = controlsThrough(replay.controls, reader, sessionID, cut.seq - 1);
|
|
@@ -30191,7 +30379,7 @@ ${cached}
|
|
|
30191
30379
|
const release = this.storage.hold(sessionID);
|
|
30192
30380
|
let result;
|
|
30193
30381
|
try {
|
|
30194
|
-
result = await this.restoreHeld(sessionID, cut, model, options);
|
|
30382
|
+
result = await this.restoreHeld(sessionID, cut, model, options, passSource);
|
|
30195
30383
|
} finally {
|
|
30196
30384
|
try {
|
|
30197
30385
|
this.account(sessionID);
|
|
@@ -30200,14 +30388,25 @@ ${cached}
|
|
|
30200
30388
|
}
|
|
30201
30389
|
}
|
|
30202
30390
|
if (replay) {
|
|
30203
|
-
await this.retainReplay(sessionID, replay, model, cut.seq - 1);
|
|
30391
|
+
await this.retainReplay(sessionID, replay, model, cut.seq - 1, passSource);
|
|
30392
|
+
if (result && replay.floor.kind === "summary" && after === replay.floor.seq && after < cut.seq)
|
|
30393
|
+
options.onRestoredAfterSummary?.(replay.floor.id);
|
|
30204
30394
|
return result && insertControls(result, controls, nativeRowID);
|
|
30205
30395
|
}
|
|
30206
30396
|
return result;
|
|
30207
30397
|
}
|
|
30208
|
-
async restoreHeld(sessionID, cut, model, options) {
|
|
30398
|
+
async restoreHeld(sessionID, cut, model, options, expected) {
|
|
30209
30399
|
if (!isLocalCheckpoint(cut))
|
|
30210
30400
|
return;
|
|
30401
|
+
const open = () => {
|
|
30402
|
+
const opened = this.openReader(sessionID);
|
|
30403
|
+
if (opened.hostIdentity() !== expected) {
|
|
30404
|
+
opened.close();
|
|
30405
|
+
throw new NativeReplayUnavailable("Host database file changed during restore");
|
|
30406
|
+
}
|
|
30407
|
+
this.memorySources.set(sessionID, expected);
|
|
30408
|
+
return opened;
|
|
30409
|
+
};
|
|
30211
30410
|
const resolvedModel = {
|
|
30212
30411
|
providerID: model.slice(0, model.indexOf("/")),
|
|
30213
30412
|
id: model.slice(model.indexOf("/") + 1)
|
|
@@ -30223,13 +30422,13 @@ ${cached}
|
|
|
30223
30422
|
const max = this.storage.db.prepare("SELECT COALESCE(MAX(id),0) AS id FROM m0_mutation_log WHERE session_id=?").get(sessionID);
|
|
30224
30423
|
const boundary = this.storage.db.prepare("SELECT cached_m0_last_baseline_end_message_id AS id FROM session_meta WHERE session_id=?").get(sessionID)?.id;
|
|
30225
30424
|
if (max.id <= (state.cachedM0MaxMutationId ?? 0) && boundary) {
|
|
30226
|
-
after = this.storage.sequenceForID(sessionID, boundary) ?? (reader =
|
|
30425
|
+
after = this.storage.sequenceForID(sessionID, boundary) ?? (reader = open()).sequenceForId(sessionID, boundary) ?? -1;
|
|
30227
30426
|
}
|
|
30228
30427
|
}
|
|
30229
30428
|
const through = cut.seq - 1;
|
|
30230
30429
|
let metadata = this.metadata.get(sessionID);
|
|
30231
30430
|
if (!metadata || (this.metadataThrough.get(sessionID) ?? -1) < through || this.options.protocol === 3 && this.options.rendersHistory?.(sessionID) && (this.metadataAfter.get(sessionID) ?? -1) > after) {
|
|
30232
|
-
reader ??=
|
|
30431
|
+
reader ??= open();
|
|
30233
30432
|
metadata = reader.rowStampsThrough(sessionID, through, this.options.protocol === 3 ? after : undefined).filter(conversational);
|
|
30234
30433
|
this.metadata.set(sessionID, metadata);
|
|
30235
30434
|
this.metadataThrough.set(sessionID, through);
|
|
@@ -30237,7 +30436,7 @@ ${cached}
|
|
|
30237
30436
|
}
|
|
30238
30437
|
const required = metadata.filter((row) => row.seq > after && row.seq <= through);
|
|
30239
30438
|
if (this.dirty.has(sessionID) || !tail || (this.loaded.get(sessionID) ?? -1) < through && !this.storage.admission(sessionID, cut.id) || !this.storage.containsRows(sessionID, required.map((row) => row.id))) {
|
|
30240
|
-
const source = reader ??=
|
|
30439
|
+
const source = reader ??= open();
|
|
30241
30440
|
const fresh = source.range(sessionID, after, through).filter(conversational);
|
|
30242
30441
|
const records = fresh.map((row) => this.record(row, this.rendered(row, resolvedModel, source)));
|
|
30243
30442
|
const restored = new Set(records.map((row) => row.id));
|
|
@@ -30267,9 +30466,11 @@ ${cached}
|
|
|
30267
30466
|
}
|
|
30268
30467
|
return messages;
|
|
30269
30468
|
}
|
|
30270
|
-
async restoreRead(sessionID, cut, model) {
|
|
30469
|
+
async restoreRead(sessionID, cut, model, passSource, onRestoredAfterSummary) {
|
|
30271
30470
|
const reader = this.openReader(sessionID);
|
|
30272
30471
|
try {
|
|
30472
|
+
if (reader.hostIdentity() !== passSource)
|
|
30473
|
+
throw new NativeReplayUnavailable("Host checkpoint replay boundary is unavailable");
|
|
30273
30474
|
const replay = this.options.protocol === 3 ? await this.floorState(sessionID, reader) : undefined;
|
|
30274
30475
|
if (this.options.protocol === 3 && !replay) {
|
|
30275
30476
|
this.report(sessionID, "replay refused: missing usable checkpoint boundary");
|
|
@@ -30283,6 +30484,8 @@ ${cached}
|
|
|
30283
30484
|
bindNativeRowID(message, row.id, row.seq);
|
|
30284
30485
|
return messages;
|
|
30285
30486
|
});
|
|
30487
|
+
if (replay?.floor.kind === "summary" && after === replay.floor.seq && after < cut.seq)
|
|
30488
|
+
onRestoredAfterSummary?.(replay.floor.id);
|
|
30286
30489
|
return replay ? insertControls(messages, controlsThrough(replay.controls, reader, sessionID, cut.seq - 1), nativeRowID) : messages;
|
|
30287
30490
|
} finally {
|
|
30288
30491
|
reader.close();
|
|
@@ -30296,6 +30499,7 @@ ${cached}
|
|
|
30296
30499
|
}
|
|
30297
30500
|
clear(sessionID) {
|
|
30298
30501
|
this.sources.delete(sessionID);
|
|
30502
|
+
this.memorySources.delete(sessionID);
|
|
30299
30503
|
this.metadata.delete(sessionID);
|
|
30300
30504
|
this.metadataThrough.delete(sessionID);
|
|
30301
30505
|
this.metadataAfter.delete(sessionID);
|
|
@@ -30310,6 +30514,8 @@ ${cached}
|
|
|
30310
30514
|
if (this.stampMRU?.sessionID === sessionID)
|
|
30311
30515
|
this.stampMRU = undefined;
|
|
30312
30516
|
this.unprovenControls.delete(sessionID);
|
|
30517
|
+
this.reportedCaptureReplacements.delete(sessionID);
|
|
30518
|
+
this.reportedForeignRefreshes.delete(sessionID);
|
|
30313
30519
|
this.cancelLegacyUpgrade(sessionID);
|
|
30314
30520
|
this.cancelEditedAdmission(sessionID);
|
|
30315
30521
|
if (this.admissions)
|
|
@@ -30674,57 +30880,6 @@ function seedV2ForkFromParent(args) {
|
|
|
30674
30880
|
return { kind: "seeded", parentSessionID, pairedRows: idMap.parentToFork.size, result };
|
|
30675
30881
|
}
|
|
30676
30882
|
|
|
30677
|
-
// src/v2/hidden-child-record.ts
|
|
30678
|
-
function keptUnderRetention(keepSubagents, child) {
|
|
30679
|
-
return keepSubagents && (child.ever_settled === true || child.role === "historian");
|
|
30680
|
-
}
|
|
30681
|
-
function roleTitle(role) {
|
|
30682
|
-
return role === "historian" ? "Magic Context historian" : "Magic Context dreamer";
|
|
30683
|
-
}
|
|
30684
|
-
function roleAgent(role) {
|
|
30685
|
-
if (role === "historian")
|
|
30686
|
-
return HIDDEN_HISTORIAN_AGENT;
|
|
30687
|
-
return role === "dreamer-curate" ? HIDDEN_CURATE_AGENT : HIDDEN_DREAMER_AGENT;
|
|
30688
|
-
}
|
|
30689
|
-
function childCreateInput(identity, role, model) {
|
|
30690
|
-
const agent = hiddenToolLoop(identity) ? hiddenAgentFor(identity) : roleAgent(role);
|
|
30691
|
-
return {
|
|
30692
|
-
title: roleTitle(role),
|
|
30693
|
-
agent,
|
|
30694
|
-
model: {
|
|
30695
|
-
providerID: model.providerID,
|
|
30696
|
-
id: model.modelID,
|
|
30697
|
-
...model.variant ? { variant: model.variant } : {}
|
|
30698
|
-
},
|
|
30699
|
-
location: { directory: identity.directory },
|
|
30700
|
-
metadata: { magic_context: "hidden-run", role },
|
|
30701
|
-
permissions: hiddenChildPermissions(agent, model.providerID)
|
|
30702
|
-
};
|
|
30703
|
-
}
|
|
30704
|
-
function assistantOutcome(row) {
|
|
30705
|
-
const outcome = row?.data.outcome;
|
|
30706
|
-
return outcome === "succeeded" || outcome === "failed" || outcome === "interrupted" ? outcome : undefined;
|
|
30707
|
-
}
|
|
30708
|
-
function withReader(openReader, read) {
|
|
30709
|
-
const reader = openReader();
|
|
30710
|
-
try {
|
|
30711
|
-
return read(reader);
|
|
30712
|
-
} finally {
|
|
30713
|
-
reader.close?.();
|
|
30714
|
-
}
|
|
30715
|
-
}
|
|
30716
|
-
function errorText(value) {
|
|
30717
|
-
if (value instanceof Error)
|
|
30718
|
-
return value.message;
|
|
30719
|
-
if (typeof value === "string")
|
|
30720
|
-
return value;
|
|
30721
|
-
try {
|
|
30722
|
-
return JSON.stringify(value);
|
|
30723
|
-
} catch {
|
|
30724
|
-
return String(value);
|
|
30725
|
-
}
|
|
30726
|
-
}
|
|
30727
|
-
|
|
30728
30883
|
// src/v2/hidden-child-sweep.ts
|
|
30729
30884
|
var PREFIX = "hidden_child:";
|
|
30730
30885
|
var HIDDEN_CHILD_MAX_AGE_MS = 60 * 60 * 1000;
|
|
@@ -30845,6 +31000,7 @@ function isSessionNotFound(error) {
|
|
|
30845
31000
|
}
|
|
30846
31001
|
function createNativeHiddenChildren(host, removeSession, options) {
|
|
30847
31002
|
const quiet = supportsQuietHiddenChildren(options.hostVersion);
|
|
31003
|
+
const archiveHolder = host.archiveHolder && supportsHolderArchive(options.hostVersion) ? { update: host.archiveHolder, log: options.log } : undefined;
|
|
30848
31004
|
const removing = new Map;
|
|
30849
31005
|
const removeBounded = async (id, timeoutMs = options.removalTimeoutMs ?? 5000) => {
|
|
30850
31006
|
let timer;
|
|
@@ -30913,7 +31069,7 @@ function createNativeHiddenChildren(host, removeSession, options) {
|
|
|
30913
31069
|
const input = childCreateInput(identity, role, model);
|
|
30914
31070
|
const directory = identity.directory;
|
|
30915
31071
|
if (quiet && host.createHolder) {
|
|
30916
|
-
const placement = await hiddenRunPlacement(host.createHolder, directory, budget);
|
|
31072
|
+
const placement = await hiddenRunPlacement(host.createHolder, directory, budget, archiveHolder);
|
|
30917
31073
|
input.id = placement.id;
|
|
30918
31074
|
input.parentID = placement.parentID;
|
|
30919
31075
|
delete input.location;
|
|
@@ -31906,6 +32062,7 @@ async function createV2HiddenCompletionExecutor(host, options) {
|
|
|
31906
32062
|
throw new DreamTokenBudgetExceeded(run.child.id, budget.snapshot().spent);
|
|
31907
32063
|
}
|
|
31908
32064
|
let usageSeq = baseline;
|
|
32065
|
+
let finishedSteps = 0;
|
|
31909
32066
|
let budgetPoll;
|
|
31910
32067
|
let budgetReject;
|
|
31911
32068
|
const budgetStopped = new Promise((_resolve, reject) => {
|
|
@@ -31921,7 +32078,15 @@ async function createV2HiddenCompletionExecutor(host, options) {
|
|
|
31921
32078
|
break;
|
|
31922
32079
|
usageSeq = row.seq;
|
|
31923
32080
|
const tokens = row.data.tokens;
|
|
31924
|
-
const
|
|
32081
|
+
const hasUsage = [
|
|
32082
|
+
tokens?.input,
|
|
32083
|
+
tokens?.output,
|
|
32084
|
+
tokens?.cache?.read,
|
|
32085
|
+
tokens?.cache?.write,
|
|
32086
|
+
tokens?.reasoning
|
|
32087
|
+
].some((value) => typeof value === "number" && Number.isFinite(value));
|
|
32088
|
+
const estimatedInput = attempt.requestTokenEstimates?.[finishedSteps++] ?? 0;
|
|
32089
|
+
const decision = budget.charge(hasUsage ? Math.max(0, tokens?.input ?? 0) : estimatedInput, hasUsage ? Math.max(0, tokens?.cache?.read ?? 0) : 0, hasUsage ? Math.max(0, tokens?.cache?.write ?? 0) : 0, row.data.finish === "stop" && !(row.data.content ?? []).some((part) => part.type === "tool-call"), false);
|
|
31925
32090
|
const onBudgetUpdate = run.identity.metadata?.onBudgetUpdate;
|
|
31926
32091
|
if (typeof onBudgetUpdate === "function")
|
|
31927
32092
|
onBudgetUpdate({ ...budget.snapshot(), sessionId: run.child.id });
|
|
@@ -34712,15 +34877,39 @@ function hasCurrentDocsProposal(projectDir) {
|
|
|
34712
34877
|
const hashes = docsBaseHashes(projectDir);
|
|
34713
34878
|
return listPendingDocsProposals(projectDir).some((path) => Object.entries(hashes).every(([name, value]) => readFileSync6(path, "utf8").includes(`Base SHA-256 ${name}: ${value}`)));
|
|
34714
34879
|
}
|
|
34715
|
-
function git(projectDir, args) {
|
|
34880
|
+
function git(projectDir, args, options) {
|
|
34716
34881
|
return execFileSync("git", args, {
|
|
34717
34882
|
windowsHide: true,
|
|
34718
34883
|
cwd: projectDir,
|
|
34719
34884
|
encoding: "utf8",
|
|
34720
34885
|
timeout: 1e4,
|
|
34721
|
-
maxBuffer: 2000000
|
|
34886
|
+
maxBuffer: 2000000,
|
|
34887
|
+
...options
|
|
34722
34888
|
}).trim();
|
|
34723
34889
|
}
|
|
34890
|
+
function gitExitStatus(error) {
|
|
34891
|
+
if (!error || typeof error !== "object")
|
|
34892
|
+
return;
|
|
34893
|
+
const { status, code, signal } = error;
|
|
34894
|
+
return typeof status === "number" && !code && !signal ? status : undefined;
|
|
34895
|
+
}
|
|
34896
|
+
function isCheckpointCommit(projectDir, anchor) {
|
|
34897
|
+
if (typeof anchor !== "string" || !/^[a-f0-9]{40}$/.test(anchor))
|
|
34898
|
+
return false;
|
|
34899
|
+
try {
|
|
34900
|
+
return git(projectDir, ["cat-file", "-t", anchor], { stdio: "pipe" }) === "commit";
|
|
34901
|
+
} catch (error) {
|
|
34902
|
+
if (gitExitStatus(error) === undefined)
|
|
34903
|
+
throw error;
|
|
34904
|
+
try {
|
|
34905
|
+
git(projectDir, ["cat-file", "-e", anchor], { stdio: "pipe" });
|
|
34906
|
+
} catch (existenceError) {
|
|
34907
|
+
if (gitExitStatus(existenceError) === 1)
|
|
34908
|
+
return false;
|
|
34909
|
+
}
|
|
34910
|
+
throw error;
|
|
34911
|
+
}
|
|
34912
|
+
}
|
|
34724
34913
|
function gitOutputPrefix(projectDir, args) {
|
|
34725
34914
|
try {
|
|
34726
34915
|
return git(projectDir, args);
|
|
@@ -34741,14 +34930,16 @@ function docsChangeSet(projectDir, storedAnchor) {
|
|
|
34741
34930
|
if (realpathSync(git(projectDir, ["rev-parse", "--show-toplevel"])) !== realpathSync(projectDir))
|
|
34742
34931
|
return null;
|
|
34743
34932
|
const head = git(projectDir, ["rev-parse", "HEAD"]);
|
|
34744
|
-
const recorded = Boolean(storedAnchor);
|
|
34745
34933
|
let anchor = storedAnchor;
|
|
34746
|
-
|
|
34747
|
-
|
|
34934
|
+
const recovered = anchor != null && !isCheckpointCommit(projectDir, anchor);
|
|
34935
|
+
if (recovered)
|
|
34936
|
+
anchor = undefined;
|
|
34937
|
+
const recorded = Boolean(anchor);
|
|
34748
34938
|
if (!anchor)
|
|
34749
34939
|
anchor = git(projectDir, ["log", "-1", "--format=%H", "--", ...FILES]);
|
|
34940
|
+
const emptyRecovery = recovered ? { head, text: "", unchanged: false, relevant: false, recoveredAnchor: anchor || null } : null;
|
|
34750
34941
|
if (!anchor)
|
|
34751
|
-
return
|
|
34942
|
+
return emptyRecovery;
|
|
34752
34943
|
if (recorded && anchor === head)
|
|
34753
34944
|
return { head, text: "", unchanged: true, relevant: false };
|
|
34754
34945
|
if (recorded) {
|
|
@@ -34850,7 +35041,7 @@ ${stat}`
|
|
|
34850
35041
|
...excluded.map((path) => `:(exclude)${path}`)
|
|
34851
35042
|
]);
|
|
34852
35043
|
if (!raw)
|
|
34853
|
-
return
|
|
35044
|
+
return emptyRecovery;
|
|
34854
35045
|
const commits = raw.split(/^commit /m);
|
|
34855
35046
|
const text = raw.slice(0, 24000);
|
|
34856
35047
|
return {
|
|
@@ -34859,7 +35050,8 @@ ${stat}`
|
|
|
34859
35050
|
relevant: true,
|
|
34860
35051
|
text: `${text}${raw.length > text.length ? `
|
|
34861
35052
|
[cut ${raw.length - text.length} bytes]` : ""}${commits.length > 201 ? `
|
|
34862
|
-
[cut commits beyond newest 200]` : ""}
|
|
35053
|
+
[cut commits beyond newest 200]` : ""}`,
|
|
35054
|
+
...recovered ? { recoveredAnchor: anchor } : {}
|
|
34863
35055
|
};
|
|
34864
35056
|
} catch (error) {
|
|
34865
35057
|
if (storedAnchor)
|
|
@@ -40707,6 +40899,9 @@ async function runAgenticTask(config, ctx, helpers) {
|
|
|
40707
40899
|
anchor = JSON.parse(storedAnchor ?? "null")?.head;
|
|
40708
40900
|
} catch {}
|
|
40709
40901
|
const changes = task === "maintain-docs" ? docsChangeSet(docsDir, anchor) : null;
|
|
40902
|
+
if (changes?.recoveredAnchor !== undefined) {
|
|
40903
|
+
log2("[dreamer] maintain-docs: stored checkpoint was no longer a commit; restarted from the docs files' last commit, if any");
|
|
40904
|
+
}
|
|
40710
40905
|
const existingDocs = task === "maintain-docs" ? {
|
|
40711
40906
|
architecture: existsSync7(`${docsDir}/ARCHITECTURE.md`),
|
|
40712
40907
|
structure: existsSync7(`${docsDir}/STRUCTURE.md`)
|
|
@@ -40776,7 +40971,7 @@ async function runAgenticTask(config, ctx, helpers) {
|
|
|
40776
40971
|
return { status: "completed", detail: reason };
|
|
40777
40972
|
}
|
|
40778
40973
|
if (task === "maintain-docs" && changes && (changes.unchanged || !changes.relevant)) {
|
|
40779
|
-
const reason = changes.unchanged ? "no commits since last run" : "diff does not describe a documented area";
|
|
40974
|
+
const reason = changes.unchanged ? "no commits since last run" : changes.recoveredAnchor !== undefined ? "no relevant commits or no git repository" : "diff does not describe a documented area";
|
|
40780
40975
|
helpers.recordRun("completed", null, { progress: reason });
|
|
40781
40976
|
return {
|
|
40782
40977
|
status: "completed",
|
|
@@ -40787,7 +40982,15 @@ async function runAgenticTask(config, ctx, helpers) {
|
|
|
40787
40982
|
if (task === "maintain-docs" && hasCurrentDocsProposal(docsDir)) {
|
|
40788
40983
|
const reason = "pending proposal matches current docs";
|
|
40789
40984
|
helpers.recordRun("completed", null, { progress: reason });
|
|
40790
|
-
return {
|
|
40985
|
+
return {
|
|
40986
|
+
status: "completed",
|
|
40987
|
+
detail: reason,
|
|
40988
|
+
...changes?.recoveredAnchor ? {
|
|
40989
|
+
schedulePatch: {
|
|
40990
|
+
taskStateJson: JSON.stringify({ head: changes.recoveredAnchor })
|
|
40991
|
+
}
|
|
40992
|
+
} : {}
|
|
40993
|
+
};
|
|
40791
40994
|
}
|
|
40792
40995
|
const curateChunks = curateMemories ? chunkCurateMemories(curateMemories, Math.max(4000, Math.floor(resolveRetrospectiveUsableInputTokens(config, deps) * 2))) : [];
|
|
40793
40996
|
const batches = task === "curate" ? curateChunks : [{ memories: [], crossChunkCandidates: [] }];
|
|
@@ -42946,7 +43149,10 @@ class V2RevertMessageCleanup {
|
|
|
42946
43149
|
sessionId: sessionID,
|
|
42947
43150
|
isInHostStore: (id) => source.sequenceForId(sessionID, id) !== undefined,
|
|
42948
43151
|
removedByCommittedRevert: removed,
|
|
42949
|
-
onRetire: () =>
|
|
43152
|
+
onRetire: () => {
|
|
43153
|
+
clearRecompStaging(db, sessionID);
|
|
43154
|
+
return;
|
|
43155
|
+
}
|
|
42950
43156
|
});
|
|
42951
43157
|
if (result.kind !== "unresolved") {
|
|
42952
43158
|
this.pendingHistory = this.pendingHistory.filter((proof) => proof.sessionID !== sessionID);
|
|
@@ -43240,6 +43446,7 @@ function hasRequiredSessionAPI(session) {
|
|
|
43240
43446
|
import { randomUUID as randomUUID6 } from "node:crypto";
|
|
43241
43447
|
import { existsSync as existsSync8 } from "node:fs";
|
|
43242
43448
|
var LEASE_TTL_MS = 10 * 60 * 1000;
|
|
43449
|
+
var DEAD_DIRECTORY_RECHECK_MS = 24 * 60 * 60 * 1000;
|
|
43243
43450
|
var SESSION_PAGE_SIZE = 100;
|
|
43244
43451
|
var SESSION_QUERY_CHUNK_SIZE = 250;
|
|
43245
43452
|
var YIELD_EVERY_PROCESSED_SESSIONS = 25;
|
|
@@ -43283,13 +43490,27 @@ function withImmediateTransaction(db, fn) {
|
|
|
43283
43490
|
function defaultYieldFn() {
|
|
43284
43491
|
return new Promise((resolve) => setTimeout(resolve, 0));
|
|
43285
43492
|
}
|
|
43493
|
+
function readBackfillLease(db, harness) {
|
|
43494
|
+
return db.prepare(`SELECT status, lease_expires_at
|
|
43495
|
+
FROM session_project_backfill_state
|
|
43496
|
+
WHERE harness = ?`).get(harness);
|
|
43497
|
+
}
|
|
43498
|
+
function isCompletedAndNotDue(lease, now) {
|
|
43499
|
+
return lease?.status === "completed" && (lease.lease_expires_at === null || lease.lease_expires_at > now);
|
|
43500
|
+
}
|
|
43286
43501
|
function acquireBackfillLease(db, harness, holderId, now) {
|
|
43502
|
+
try {
|
|
43503
|
+
if (isCompletedAndNotDue(readBackfillLease(db, harness), now))
|
|
43504
|
+
return "already_completed";
|
|
43505
|
+
} catch (error) {
|
|
43506
|
+
if (!(error instanceof Error) || error.message !== "no such table: session_project_backfill_state") {
|
|
43507
|
+
throw error;
|
|
43508
|
+
}
|
|
43509
|
+
}
|
|
43287
43510
|
ensureBackfillStateTable(db);
|
|
43288
43511
|
return withImmediateTransaction(db, () => {
|
|
43289
|
-
const current = db
|
|
43290
|
-
|
|
43291
|
-
WHERE harness = ?`).get(harness);
|
|
43292
|
-
if (current?.status === "completed")
|
|
43512
|
+
const current = readBackfillLease(db, harness);
|
|
43513
|
+
if (isCompletedAndNotDue(current, now))
|
|
43293
43514
|
return "already_completed";
|
|
43294
43515
|
if (current?.status === "running" && current.lease_expires_at !== null && current.lease_expires_at > now) {
|
|
43295
43516
|
return "blocked_by_lease";
|
|
@@ -43318,11 +43539,11 @@ function renewBackfillLease(db, harness, holderId, now) {
|
|
|
43318
43539
|
SET lease_expires_at = ?
|
|
43319
43540
|
WHERE harness = ? AND status = 'running' AND holder_id = ?`).run(now + LEASE_TTL_MS, harness, holderId).changes === 1;
|
|
43320
43541
|
}
|
|
43321
|
-
function markBackfillCompleted(db, harness, holderId, now) {
|
|
43542
|
+
function markBackfillCompleted(db, harness, holderId, now, recheckAt) {
|
|
43322
43543
|
ensureBackfillStateTable(db);
|
|
43323
43544
|
return db.prepare(`UPDATE session_project_backfill_state
|
|
43324
|
-
SET status = 'completed', lease_expires_at =
|
|
43325
|
-
WHERE harness = ? AND status = 'running' AND holder_id = ?`).run(now, harness, holderId).changes === 1;
|
|
43545
|
+
SET status = 'completed', lease_expires_at = ?, completed_at = ?
|
|
43546
|
+
WHERE harness = ? AND status = 'running' AND holder_id = ?`).run(recheckAt, now, harness, holderId).changes === 1;
|
|
43326
43547
|
}
|
|
43327
43548
|
function markBackfillRetryPending(db, harness, holderId, now) {
|
|
43328
43549
|
ensureBackfillStateTable(db);
|
|
@@ -43365,9 +43586,10 @@ function createPageReader(source) {
|
|
|
43365
43586
|
if (typeof source === "function") {
|
|
43366
43587
|
return async (afterSessionId, limit) => source(afterSessionId, limit);
|
|
43367
43588
|
}
|
|
43368
|
-
|
|
43589
|
+
let sessions;
|
|
43369
43590
|
let offset = 0;
|
|
43370
43591
|
return async (_afterSessionId, limit) => {
|
|
43592
|
+
sessions ??= dedupeSessions(source);
|
|
43371
43593
|
const page = sessions.slice(offset, offset + limit);
|
|
43372
43594
|
offset += page.length;
|
|
43373
43595
|
return page;
|
|
@@ -43383,7 +43605,6 @@ async function runSessionProjectBackfillPass(db, source, options = {}) {
|
|
|
43383
43605
|
const resolveIdentity = options.resolveIdentity ?? ((directory) => resolveProjectIdentityForSession(directory, options.allowHomeProject));
|
|
43384
43606
|
const yieldFn = options.yieldFn ?? defaultYieldFn;
|
|
43385
43607
|
const holderId = options.holderId ?? randomUUID6();
|
|
43386
|
-
const readPage = createPageReader(source);
|
|
43387
43608
|
const result = {
|
|
43388
43609
|
status: "completed",
|
|
43389
43610
|
totalSessions: 0,
|
|
@@ -43394,13 +43615,15 @@ async function runSessionProjectBackfillPass(db, source, options = {}) {
|
|
|
43394
43615
|
skippedEmptyDirectories: 0,
|
|
43395
43616
|
durationMs: 0
|
|
43396
43617
|
};
|
|
43397
|
-
const
|
|
43618
|
+
const baseLeaseKey = options.leaseKey ?? harness;
|
|
43619
|
+
const leaseKey = options.allowHomeProject ? `${baseLeaseKey}:allow-home-project` : baseLeaseKey;
|
|
43398
43620
|
const leaseStatus = acquireBackfillLease(db, leaseKey, holderId, now());
|
|
43399
43621
|
if (leaseStatus !== "acquired") {
|
|
43400
43622
|
result.status = leaseStatus;
|
|
43401
43623
|
result.durationMs = performance.now() - startedAt;
|
|
43402
43624
|
return result;
|
|
43403
43625
|
}
|
|
43626
|
+
const readPage = createPageReader(source);
|
|
43404
43627
|
const finishWithLostLease = () => {
|
|
43405
43628
|
result.status = "lost_lease";
|
|
43406
43629
|
result.durationMs = performance.now() - startedAt;
|
|
@@ -43492,13 +43715,9 @@ async function runSessionProjectBackfillPass(db, source, options = {}) {
|
|
|
43492
43715
|
if (sourcePage.length < SESSION_PAGE_SIZE)
|
|
43493
43716
|
break;
|
|
43494
43717
|
}
|
|
43495
|
-
const
|
|
43496
|
-
|
|
43497
|
-
|
|
43498
|
-
return finishWithLostLease();
|
|
43499
|
-
}
|
|
43500
|
-
result.status = "retry_pending";
|
|
43501
|
-
} else if (!markBackfillCompleted(db, leaseKey, holderId, now())) {
|
|
43718
|
+
const completedAt = now();
|
|
43719
|
+
const recheckAt = result.skippedDeadDirectories > 0 ? completedAt + DEAD_DIRECTORY_RECHECK_MS : null;
|
|
43720
|
+
if (!markBackfillCompleted(db, leaseKey, holderId, completedAt, recheckAt)) {
|
|
43502
43721
|
return finishWithLostLease();
|
|
43503
43722
|
}
|
|
43504
43723
|
result.durationMs = performance.now() - startedAt;
|
|
@@ -55472,10 +55691,11 @@ function createCtxExpandTool(deps) {
|
|
|
55472
55691
|
}
|
|
55473
55692
|
const { start, end, verbose } = mode;
|
|
55474
55693
|
const lastCompartmentEnd = getLastCompartmentEndMessage(deps.db, sessionId);
|
|
55475
|
-
|
|
55476
|
-
|
|
55477
|
-
|
|
55478
|
-
const
|
|
55694
|
+
const refusal = unresolvedLiveTailRefusal2(deps.db, sessionId, start, end, lastCompartmentEnd);
|
|
55695
|
+
if (refusal)
|
|
55696
|
+
return refusal;
|
|
55697
|
+
const liveTailAfter = lastCompartmentEnd >= 0 && start > lastCompartmentEnd ? lastCompartmentEnd : undefined;
|
|
55698
|
+
const effectiveEnd = lastCompartmentEnd >= start ? Math.min(end, lastCompartmentEnd) : end;
|
|
55479
55699
|
if (verbose && source) {
|
|
55480
55700
|
if (!path)
|
|
55481
55701
|
throw new Error("Search archive worker unavailable: private archive has no off-thread source");
|
|
@@ -55484,13 +55704,14 @@ function createCtxExpandTool(deps) {
|
|
|
55484
55704
|
start,
|
|
55485
55705
|
end: effectiveEnd,
|
|
55486
55706
|
tokenBudget: CTX_EXPAND_TOKEN_BUDGET,
|
|
55487
|
-
expandTools: deps.expandTools
|
|
55707
|
+
expandTools: deps.expandTools,
|
|
55708
|
+
liveTailAfter
|
|
55488
55709
|
});
|
|
55489
55710
|
if (text === null)
|
|
55490
55711
|
throw new Error("Search archive worker unavailable: unexpected verbose reply");
|
|
55491
55712
|
return text;
|
|
55492
55713
|
}
|
|
55493
|
-
const archived = await renderSearchArchiveOffThread2(deps.db, sessionId, start, effectiveEnd, CTX_EXPAND_TOKEN_BUDGET);
|
|
55714
|
+
const archived = await renderSearchArchiveOffThread2(deps.db, sessionId, start, effectiveEnd, CTX_EXPAND_TOKEN_BUDGET, false, liveTailAfter);
|
|
55494
55715
|
if (archived)
|
|
55495
55716
|
return archived;
|
|
55496
55717
|
if (verbose) {
|
|
@@ -57279,8 +57500,7 @@ function createCtxSearchTool(deps) {
|
|
|
57279
57500
|
return `Error: ${error.message}`;
|
|
57280
57501
|
throw error;
|
|
57281
57502
|
}
|
|
57282
|
-
const
|
|
57283
|
-
const messageOrdinalCutoff = lastCompartmentEnd >= 0 ? lastCompartmentEnd : 0;
|
|
57503
|
+
const messageOrdinalCutoff = Math.max(0, getLastCompartmentEndMessage(deps.db, toolContext.sessionID));
|
|
57284
57504
|
const visibleMemoryIds = getVisibleMemoryIds(deps.db, toolContext.sessionID);
|
|
57285
57505
|
const diagnostics = createUnifiedSearchDiagnostics2();
|
|
57286
57506
|
const projectPath = deps.resolveProjectPath(toolContext.directory);
|
|
@@ -57316,6 +57536,7 @@ function createCtxSearchTool(deps) {
|
|
|
57316
57536
|
isEmbeddingRuntimeEnabled: () => embeddingEnabled === true,
|
|
57317
57537
|
readMessages: deps.readMessages,
|
|
57318
57538
|
maxMessageOrdinal: messageOrdinalCutoff,
|
|
57539
|
+
includeDroppedTailMessages: true,
|
|
57319
57540
|
gitCommitsEnabled,
|
|
57320
57541
|
sources: normalizeSources(args.sources),
|
|
57321
57542
|
visibleMemoryIds,
|
|
@@ -57923,7 +58144,10 @@ function checkHistoryBoundary(db, reader, sessionID) {
|
|
|
57923
58144
|
db,
|
|
57924
58145
|
sessionId: sessionID,
|
|
57925
58146
|
isInHostStore: (messageId) => storeHasSession ? reader.sequenceForId(sessionID, messageId) !== undefined : null,
|
|
57926
|
-
onRetire: () =>
|
|
58147
|
+
onRetire: () => {
|
|
58148
|
+
clearRecompStaging(db, sessionID);
|
|
58149
|
+
return;
|
|
58150
|
+
}
|
|
57927
58151
|
});
|
|
57928
58152
|
} catch (error) {
|
|
57929
58153
|
sessionLog2(sessionID, "history boundary check failed; continuing without repair", error);
|
|
@@ -58285,6 +58509,8 @@ async function setupContext(context, config, nativeRemove, compactionOff, cleanu
|
|
|
58285
58509
|
};
|
|
58286
58510
|
const wrapperStorageGuard = { failClosed, failClosedBlockingEnabled };
|
|
58287
58511
|
let db = await probeV2StorageAtBoot(storage);
|
|
58512
|
+
if (db)
|
|
58513
|
+
recordHostSqliteRuntime(db, "opencode2");
|
|
58288
58514
|
const storageOpenedAtBoot = db !== undefined;
|
|
58289
58515
|
let legacyCleanupStarted = false;
|
|
58290
58516
|
const hiddenChildSweep = createHiddenChildSweeper(nativeRemove, log2, {
|
|
@@ -58433,6 +58659,7 @@ async function setupContext(context, config, nativeRemove, compactionOff, cleanu
|
|
|
58433
58659
|
return createV2HiddenCompletionExecutor({
|
|
58434
58660
|
...context.session,
|
|
58435
58661
|
createHolder: (input) => context.session.create(input),
|
|
58662
|
+
archiveHolder: (input) => context.session.update.call(context.session, input),
|
|
58436
58663
|
watchModelActivity: (sessionID, onOutput) => hiddenModelActivity.watch(sessionID, onOutput),
|
|
58437
58664
|
get: async (input) => {
|
|
58438
58665
|
const session = await context.session.get(input);
|
|
@@ -59240,6 +59467,9 @@ async function setupContext(context, config, nativeRemove, compactionOff, cleanu
|
|
|
59240
59467
|
sessionLog2(draft.sessionID, `v2 restore: from the module boundary ${moduleBoundaryID} to the host checkpoint`);
|
|
59241
59468
|
const present = new Set(args.messages.map((message) => message.id));
|
|
59242
59469
|
const restored = restoredRows.rows(reader, draft.sessionID, boundary, cut.seq).filter((row) => !retiredInstructions(row)).filter((row) => !present.has(row.id)).flatMap((row) => restoreRow(row, draft.model, readerRestoreMedia(reader, (detail) => sessionLog2(draft.sessionID, `v2 restore: attachment replaced by a note row=${detail.rowID} name=${JSON.stringify(detail.name ?? null)} mediaType=${detail.mediaType} reason=${JSON.stringify(detail.reason)}`))));
|
|
59470
|
+
const pass = contextPass.getStore();
|
|
59471
|
+
if (args.canRebuild && pass?.sessionID === draft.sessionID && floorRow && floorRow.id === boundaryID && boundary === floorRow.seq && boundary < cut.seq)
|
|
59472
|
+
pass.restoredAfterSummaryId = floorRow.id;
|
|
59243
59473
|
return [
|
|
59244
59474
|
...rustModeModuleClient ? [] : coveredInstructionRows(reader, draft.sessionID, Math.min(boundary, cut.seq), draft.model, retiredInstructions),
|
|
59245
59475
|
...restored,
|
|
@@ -59262,6 +59492,10 @@ async function setupContext(context, config, nativeRemove, compactionOff, cleanu
|
|
|
59262
59492
|
pushLiveNotification2("toast", { message, variant: "warning" }, sessionID);
|
|
59263
59493
|
},
|
|
59264
59494
|
hostInputEstimate: (sessionID) => checkpointInputEstimates.get(sessionID),
|
|
59495
|
+
restoredAfterSummaryBoundary: (sessionID) => {
|
|
59496
|
+
const pass = contextPass.getStore();
|
|
59497
|
+
return pass?.sessionID === sessionID ? pass.restoredAfterSummaryId : undefined;
|
|
59498
|
+
},
|
|
59265
59499
|
onPassPermission: (sessionID, permission) => {
|
|
59266
59500
|
checkpointPassPermissions.set(sessionID, permission);
|
|
59267
59501
|
},
|
|
@@ -59657,11 +59891,12 @@ async function setupContext(context, config, nativeRemove, compactionOff, cleanu
|
|
|
59657
59891
|
let recordedHead;
|
|
59658
59892
|
let upgradeCheckpointSequence;
|
|
59659
59893
|
let restoredFirstRow;
|
|
59894
|
+
let draftSourceIdentity;
|
|
59660
59895
|
try {
|
|
59661
59896
|
syntheticIDs = await readSyntheticProvenance(reader, draft.messages);
|
|
59662
59897
|
const cut = reader.latestCompaction(draft.sessionID);
|
|
59663
59898
|
if (nativeFoldReplay)
|
|
59664
|
-
await nativeFoldReplay.observeSource(draft.sessionID, reader);
|
|
59899
|
+
draftSourceIdentity = await nativeFoldReplay.observeSource(draft.sessionID, reader);
|
|
59665
59900
|
const boundaryRepair = !rustModeModuleClient && db && !compactionOff ? revertMessageCleanup.retireProvenHistory(db, draft.sessionID, reader) ?? checkHistoryBoundary(db, reader, draft.sessionID) : undefined;
|
|
59666
59901
|
if (boundaryRepair?.kind === "repaired" || boundaryRepair?.kind === "baseline-reset") {
|
|
59667
59902
|
historyRefreshSessions.add(draft.sessionID);
|
|
@@ -59701,13 +59936,18 @@ async function setupContext(context, config, nativeRemove, compactionOff, cleanu
|
|
|
59701
59936
|
}
|
|
59702
59937
|
}
|
|
59703
59938
|
let nativeRestored = localCut ? nativeFoldReplay?.legacyUpgradeInput(draft.sessionID, draft.model) : undefined;
|
|
59704
|
-
|
|
59939
|
+
let nativeRestoredAfterSummaryId;
|
|
59940
|
+
if (nativeRestored === undefined && cut && nativeFoldReplay && draftSourceIdentity !== undefined && await nativeFoldReplay.admits(draft.sessionID, cut, reader)) {
|
|
59941
|
+
const passSource = draftSourceIdentity;
|
|
59942
|
+
const onRestoredAfterSummary = (id) => {
|
|
59943
|
+
nativeRestoredAfterSummaryId = id;
|
|
59944
|
+
};
|
|
59705
59945
|
try {
|
|
59706
|
-
nativeRestored = await nativeFoldReplay.restore(draft.sessionID, cut, `${draft.model.providerID}/${draft.model.id}`, { bounded: !rustModeModuleClient });
|
|
59946
|
+
nativeRestored = await nativeFoldReplay.restore(draft.sessionID, cut, `${draft.model.providerID}/${draft.model.id}`, passSource, { bounded: !rustModeModuleClient, onRestoredAfterSummary });
|
|
59707
59947
|
} catch (error) {
|
|
59708
59948
|
nativeFoldReplay.invalidate(draft.sessionID, true);
|
|
59709
59949
|
sessionLog2(draft.sessionID, "v2 host fold: cache unavailable; restoring host rows", error);
|
|
59710
|
-
nativeRestored = await nativeFoldReplay.restoreRead(draft.sessionID, cut, draft.model);
|
|
59950
|
+
nativeRestored = await nativeFoldReplay.restoreRead(draft.sessionID, cut, draft.model, passSource, onRestoredAfterSummary);
|
|
59711
59951
|
}
|
|
59712
59952
|
if (nativeRestored)
|
|
59713
59953
|
pass.nativeReplayCheckpointID = cut.id;
|
|
@@ -59721,6 +59961,7 @@ async function setupContext(context, config, nativeRemove, compactionOff, cleanu
|
|
|
59721
59961
|
requestPendingMaterialization(pendingMaterializationSessions, draft.sessionID, "host_history_change");
|
|
59722
59962
|
}
|
|
59723
59963
|
if (cut && incoming && nativeRestored) {
|
|
59964
|
+
pass.restoredAfterSummaryId = nativeRestoredAfterSummaryId;
|
|
59724
59965
|
draft.messages.splice(0, draft.messages.length, ...restoreNativeCheckpointInput(draft.messages, incoming, nativeRestored, reader, draft.sessionID));
|
|
59725
59966
|
} else if (!compactionOff && localCut && cut && incoming) {
|
|
59726
59967
|
const legacy = await folds.read(draft.sessionID);
|
|
@@ -59856,8 +60097,8 @@ async function setupContext(context, config, nativeRemove, compactionOff, cleanu
|
|
|
59856
60097
|
const stripped = await folds.stripRecentContext(draft.sessionID, checkpointID);
|
|
59857
60098
|
if (stripped?.rendered) {
|
|
59858
60099
|
checkpoint = structuredClone(stripped.rendered);
|
|
59859
|
-
if (upgradeCheckpointSequence !== undefined)
|
|
59860
|
-
await nativeFoldReplay?.checkpointCovered(draft.sessionID, checkpointID);
|
|
60100
|
+
if (upgradeCheckpointSequence !== undefined && draftSourceIdentity !== undefined)
|
|
60101
|
+
await nativeFoldReplay?.checkpointCovered(draft.sessionID, checkpointID, draftSourceIdentity);
|
|
59861
60102
|
}
|
|
59862
60103
|
}
|
|
59863
60104
|
}
|
|
@@ -59875,11 +60116,11 @@ async function setupContext(context, config, nativeRemove, compactionOff, cleanu
|
|
|
59875
60116
|
} : null;
|
|
59876
60117
|
const servedHead = head && structuredClone(head);
|
|
59877
60118
|
const headApplied = head ? applyCheckpointHead(draft, head) : false;
|
|
59878
|
-
if (nativeMessages && (!checkpoint || upgradeCheckpointSequence !== undefined)) {
|
|
60119
|
+
if (nativeMessages && draftSourceIdentity !== undefined && (!checkpoint || upgradeCheckpointSequence !== undefined)) {
|
|
59879
60120
|
try {
|
|
59880
60121
|
const state = db && getOrCreateSessionMeta(db, draft.sessionID);
|
|
59881
60122
|
const boundary = db?.prepare("SELECT cached_m0_last_baseline_end_message_id AS id FROM session_meta WHERE session_id=?").get(draft.sessionID);
|
|
59882
|
-
await nativeFoldReplay?.capture(draft, nativeMessages, boundary?.id && state?.cachedM0Bytes ? { id: boundary.id, summary: state.cachedM0Bytes.toString("utf8") } : undefined, restoredFirstRow);
|
|
60123
|
+
await nativeFoldReplay?.capture(draft, nativeMessages, draftSourceIdentity, boundary?.id && state?.cachedM0Bytes ? { id: boundary.id, summary: state.cachedM0Bytes.toString("utf8") } : undefined, restoredFirstRow);
|
|
59883
60124
|
} catch (error) {
|
|
59884
60125
|
nativeFoldReplay?.invalidate(draft.sessionID, true);
|
|
59885
60126
|
sessionLog2(draft.sessionID, "v2 host fold: optional capture unavailable", error);
|