@cortexkit/opencode-magic-context 0.49.93 → 0.49.95
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/auto-search-worker.js +4 -4
- package/dist/chunk-embedding-write-worker.js +3 -3
- package/dist/{compartment-chunk-embedding-rp4asvk0.js → compartment-chunk-embedding-4nn3hsw2.js} +2 -2
- package/dist/{context-jpxthqxg.js → context-h9x9m2p3.js} +176 -61
- package/dist/{embedding-backfill-6wzc4p2n.js → embedding-backfill-wdrqkw09.js} +5 -5
- package/dist/embedding-worker.js +2 -2
- 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/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.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/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/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-stage-logger.d.ts +6 -0
- package/dist/hooks/magic-context/transform-stage-logger.d.ts.map +1 -1
- package/dist/{index-za1yx1m4.js → index-2gewejcz.js} +17 -8
- package/dist/{index-hee64h6k.js → index-2v9qpmb3.js} +5 -5
- package/dist/{index-g5c67kay.js → index-3tmbvn0z.js} +8 -8
- package/dist/{index-5zrzg8r1.js → index-3ywyr4zx.js} +1 -1
- package/dist/{index-kty5k23y.js → index-47hst5me.js} +1 -1
- package/dist/{index-g6y2wk32.js → index-7dzaamqg.js} +6 -6
- package/dist/{index-dr6bd4c8.js → index-7r11k4xr.js} +1 -1
- package/dist/{index-g9qtxv87.js → index-7skgrbsg.js} +100 -52
- package/dist/{index-gqfy38m9.js → index-c81tggen.js} +1 -1
- package/dist/{index-0twg41mh.js → index-ejgp0z9p.js} +1 -1
- package/dist/{index-pnawfv4e.js → index-esacb9d0.js} +1 -1
- package/dist/{index-1kem0xxx.js → index-ewta5h87.js} +4 -4
- package/dist/{index-6r99v53h.js → index-j7n64sg4.js} +162 -60
- package/dist/{index-y2vshk67.js → index-jm62g83a.js} +177 -59
- package/dist/{index-yqha238s.js → index-pc49a7zt.js} +119 -9
- package/dist/{index-ttdk2w0z.js → index-qmm8xpbc.js} +3 -3
- package/dist/{index-n9kd68vc.js → index-tedck05r.js} +3 -3
- package/dist/{index-j2w79s9r.js → index-tm799pq7.js} +1 -1
- package/dist/{index-01h7tqe3.js → index-tr4ep2ej.js} +21 -6
- package/dist/{index-rz47hf2m.js → index-wqwjawer.js} +27 -11
- package/dist/index-xe34pwb6.js +119 -0
- package/dist/{index-hes3k87g.js → index-xjaf9g90.js} +1 -1
- package/dist/{index-fpjnjxyx.js → index-yzzxb5e1.js} +2 -2
- package/dist/{index-xr1t0fxb.js → index-zk6gtf43.js} +44 -8
- package/dist/index.js +26 -26
- package/dist/{message-index-bounded-vjrnptar.js → message-index-bounded-d3x8rhpz.js} +3 -3
- package/dist/migration-worker.js +1 -1
- package/dist/{project-embedding-registry-m8zcmrsg.js → project-embedding-registry-az68q792.js} +4 -4
- package/dist/raw-ordinal-warmup-worker.js +5 -5
- package/dist/{read-session-chunk-zkzdc0e5.js → read-session-chunk-70r1snq3.js} +2 -2
- package/dist/{recomp-orchestrator-qb2hymj5.js → recomp-orchestrator-cn4r2gz6.js} +14 -14
- package/dist/{render-34p0kek8.js → render-g45k3gts.js} +9 -9
- package/dist/{search-archive-08ppk0q5.js → search-archive-s9t3exc1.js} +8 -6
- package/dist/{search-e9bb9hpx.js → search-b0cb342r.js} +12 -12
- package/dist/shared/storage-file-mutex.d.ts.map +1 -1
- package/dist/{storage-tags-gk7gjkqt.js → storage-tags-xvbje7jm.js} +1 -1
- package/dist/{store-yr443ye8.js → store-91kawq9a.js} +2 -2
- 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-r1xhsjrh.js} +15 -15
- package/dist/v2/auto-search-worker.js +4 -4
- package/dist/v2/chunk-embedding-write-worker.js +3 -3
- package/dist/v2/{compartment-chunk-embedding-w7ht0t9v.js → compartment-chunk-embedding-a7ddvz7v.js} +2 -2
- package/dist/v2/{context-ctsd80vc.js → context-2hssw26q.js} +332 -99
- package/dist/v2/{embedding-backfill-40g0anxh.js → embedding-backfill-gveter8p.js} +5 -5
- package/dist/v2/embedding-worker.js +2 -2
- 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 +22 -5
- package/dist/v2/fold/native-replay.d.ts.map +1 -1
- package/dist/v2/hooks/context.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/{message-index-bounded-1vew9c37.js → message-index-bounded-tbwrff24.js} +3 -3
- package/dist/v2/migration-worker.js +1 -1
- package/dist/v2/{project-embedding-registry-je5jam7y.js → project-embedding-registry-2zeycxek.js} +4 -4
- package/dist/v2/raw-ordinal-warmup-worker.js +5 -5
- package/dist/v2/{read-session-chunk-09sre4xv.js → read-session-chunk-cvgsfsgr.js} +2 -2
- package/dist/v2/{recomp-orchestrator-mgcty3we.js → recomp-orchestrator-k4cj62f2.js} +13 -13
- package/dist/v2/{render-ygcmyn9x.js → render-ys7a3zks.js} +9 -9
- package/dist/v2/{search-archive-nrsqqmk5.js → search-archive-k2yh0jj3.js} +8 -6
- package/dist/v2/{search-gmye6n25.js → search-x1cac8t6.js} +11 -11
- package/dist/v2/{server-rkj44mez.js → server-476anw1w.js} +1 -1
- package/dist/v2/{server-barj0mjz.js → server-5016ccyn.js} +1 -1
- package/dist/v2/{server-pcarsvj2.js → server-6aj72z52.js} +3 -3
- package/dist/v2/{server-cvp9w5gs.js → server-6nh36020.js} +68 -59
- package/dist/v2/{server-btgnkr9z.js → server-88pjnecb.js} +1 -1
- package/dist/v2/{server-myp4pc6x.js → server-bfct1yvb.js} +99 -51
- package/dist/v2/{server-4ecpanyn.js → server-cd93xyyx.js} +119 -9
- package/dist/v2/{server-6x40bnb7.js → server-cvm1qrqc.js} +2 -2
- package/dist/v2/{server-z9czv2vb.js → server-gj259dqy.js} +44 -8
- package/dist/v2/{server-vc5fta6s.js → server-prrx17q3.js} +3 -3
- package/dist/v2/{server-6chcnnhq.js → server-qy58c11s.js} +1 -1
- package/dist/v2/{server-dgsjamm4.js → server-s81b3nct.js} +1 -1
- package/dist/v2/{server-g53asaqt.js → server-s8mk882p.js} +27 -11
- package/dist/v2/{server-2xm0gxke.js → server-srtq37nh.js} +1 -1
- package/dist/v2/{server-bnkc9kph.js → server-vbr1rdkg.js} +6 -6
- package/dist/v2/{server-vtgeyhq6.js → server-vtkbxzw1.js} +21 -6
- package/dist/v2/{server-ps6zrzwj.js → server-xepfjgv5.js} +162 -60
- package/dist/v2/server-y0pd600x.js +119 -0
- package/dist/v2/{server-k1xc2bw1.js → server-zc8s06gx.js} +1 -1
- package/dist/v2/server.js +2 -2
- package/dist/v2/{storage-tags-nccqr0kr.js → storage-tags-y20j3jdp.js} +1 -1
- package/dist/v2/{store-enef5jcn.js → store-b95snz31.js} +2 -2
- 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-q92kwkr5.js} +1 -1
- package/dist/v2/{wrapup-orchestrator-7r4y0bf6.js → wrapup-orchestrator-ydqkxkhj.js} +13 -13
- package/dist/{v2-archive-reader-7s90gfax.js → v2-archive-reader-x62hsr4c.js} +1 -1
- package/dist/{wrapup-orchestrator-m2p89973.js → wrapup-orchestrator-kt81d6et.js} +15 -15
- package/package.json +1 -1
- package/src/shared/storage-file-mutex-review.test.ts +110 -0
- package/src/shared/storage-file-mutex.ts +12 -0
- package/dist/index-52x68mj4.js +0 -58
- package/dist/v2/server-52x68mj4.js +0 -58
|
@@ -246,7 +246,7 @@ import {
|
|
|
246
246
|
startCompartmentAgent,
|
|
247
247
|
setRecompStarting2,
|
|
248
248
|
setRecompTerminal2
|
|
249
|
-
} from "./server-
|
|
249
|
+
} from "./server-6nh36020.js";
|
|
250
250
|
import {
|
|
251
251
|
embedPauseBySession,
|
|
252
252
|
embedRunStateBySession,
|
|
@@ -277,7 +277,7 @@ import {
|
|
|
277
277
|
toSynapseLaneDescriptor,
|
|
278
278
|
formatSynapseLaneDescriptor,
|
|
279
279
|
SynapseEmbeddingProvider
|
|
280
|
-
} from "./server-
|
|
280
|
+
} from "./server-xepfjgv5.js";
|
|
281
281
|
import {
|
|
282
282
|
inRootAsyncContext2,
|
|
283
283
|
getTagIdentityWriteGeneration2,
|
|
@@ -310,11 +310,17 @@ import {
|
|
|
310
310
|
import"./server-ds8vpfkr.js";
|
|
311
311
|
import {
|
|
312
312
|
deleteChunkEmbedBackoffForSession2
|
|
313
|
-
} from "./server-
|
|
313
|
+
} from "./server-5016ccyn.js";
|
|
314
314
|
import {
|
|
315
315
|
acquireCompartmentLease,
|
|
316
316
|
releaseCompartmentLeaseBestEffort,
|
|
317
317
|
isCompartmentLeaseHeld,
|
|
318
|
+
readSummaryCoverage,
|
|
319
|
+
markHistoryGapAfterCoverageChange,
|
|
320
|
+
readHistoryGapMark,
|
|
321
|
+
clearHistoryGapMark,
|
|
322
|
+
claimHistoryGapCheck,
|
|
323
|
+
recordHistoryGapAdmission,
|
|
318
324
|
queueM0Mutation,
|
|
319
325
|
getMaxM0MutationId,
|
|
320
326
|
getLastCompartmentEndMessage,
|
|
@@ -430,12 +436,12 @@ import {
|
|
|
430
436
|
saveSourceContent,
|
|
431
437
|
replaceSourceContent,
|
|
432
438
|
getSourceContents
|
|
433
|
-
} from "./server-
|
|
439
|
+
} from "./server-cd93xyyx.js";
|
|
434
440
|
import {
|
|
435
441
|
cleanSearchText,
|
|
436
442
|
matchedSearchSnippet,
|
|
437
443
|
getLastIndexedOrdinal
|
|
438
|
-
} from "./server-
|
|
444
|
+
} from "./server-srtq37nh.js";
|
|
439
445
|
import {
|
|
440
446
|
ensureSessionMetaRow,
|
|
441
447
|
clearCachedM0M1,
|
|
@@ -503,6 +509,7 @@ import {
|
|
|
503
509
|
resolveCompactionModeRecord,
|
|
504
510
|
getCompactionModeRecord,
|
|
505
511
|
setCompactionModeRecord,
|
|
512
|
+
EMERGENCY_DRAIN_FAILURE_BACKOFF_MS,
|
|
506
513
|
getPersistedReasoningWatermark,
|
|
507
514
|
setPersistedReasoningWatermark,
|
|
508
515
|
clearPersistedReasoningWatermark,
|
|
@@ -534,6 +541,7 @@ import {
|
|
|
534
541
|
setPersistedTodoSyntheticAnchor,
|
|
535
542
|
clearPersistedTodoSyntheticAnchor,
|
|
536
543
|
setNoteLastReadAt,
|
|
544
|
+
getHistorianFailureState,
|
|
537
545
|
clearHistorianFailureState,
|
|
538
546
|
getOverflowState,
|
|
539
547
|
loadTransformPassStateSnapshot,
|
|
@@ -692,7 +700,7 @@ import {
|
|
|
692
700
|
adoptNullOwnerToolTag2,
|
|
693
701
|
getCandidateToolOwners2,
|
|
694
702
|
pickNearestPriorOwner2
|
|
695
|
-
} from "./server-
|
|
703
|
+
} from "./server-gj259dqy.js";
|
|
696
704
|
import {
|
|
697
705
|
BoundedSessionMap,
|
|
698
706
|
getTableColumnNames,
|
|
@@ -791,6 +799,7 @@ import {
|
|
|
791
799
|
cleanUserText2,
|
|
792
800
|
withRawSessionMessageCache2,
|
|
793
801
|
readRawSessionMessages2,
|
|
802
|
+
getRawSessionMessageOrdinalCount2,
|
|
794
803
|
visitRawSessionMessages2,
|
|
795
804
|
visitRawSessionMessagesAsync2,
|
|
796
805
|
prepareRawSessionOrdinals2,
|
|
@@ -805,7 +814,7 @@ import {
|
|
|
805
814
|
readRawSessionMessageOrdinalById2,
|
|
806
815
|
readSessionChunk2,
|
|
807
816
|
readRawSessionSeedTail2
|
|
808
|
-
} from "./server-
|
|
817
|
+
} from "./server-s81b3nct.js";
|
|
809
818
|
import {
|
|
810
819
|
getMessageIndexEpoch,
|
|
811
820
|
isMessageIndexSearchable,
|
|
@@ -831,7 +840,7 @@ import {
|
|
|
831
840
|
resolveMemoriesByIdsForSearch2,
|
|
832
841
|
unifiedSearch2,
|
|
833
842
|
formatSearchResults2
|
|
834
|
-
} from "./server-
|
|
843
|
+
} from "./server-bfct1yvb.js";
|
|
835
844
|
import {
|
|
836
845
|
startBootDeadline,
|
|
837
846
|
getUnconfirmedMigrationHolders,
|
|
@@ -847,7 +856,7 @@ import {
|
|
|
847
856
|
openDatabaseAsync,
|
|
848
857
|
isDatabasePersisted,
|
|
849
858
|
getDatabasePersistenceError
|
|
850
|
-
} from "./server-
|
|
859
|
+
} from "./server-88pjnecb.js";
|
|
851
860
|
import {
|
|
852
861
|
V2_MEMORY_CATEGORIES,
|
|
853
862
|
CATEGORY_PRIORITY
|
|
@@ -866,7 +875,7 @@ import {
|
|
|
866
875
|
RAW_MESSAGE_TYPES2,
|
|
867
876
|
V2StoreReaderPool2,
|
|
868
877
|
V2StoreReader2
|
|
869
|
-
} from "./server-
|
|
878
|
+
} from "./server-vtkbxzw1.js";
|
|
870
879
|
import {
|
|
871
880
|
configureContextDatabasePragmas2
|
|
872
881
|
} from "./server-fb3zxn06.js";
|
|
@@ -929,7 +938,7 @@ import {
|
|
|
929
938
|
embedSessionCompartmentChunks2,
|
|
930
939
|
getEmbeddingCoverageStatus2,
|
|
931
940
|
getAutoEmbeddingSessionCoverage2
|
|
932
|
-
} from "./server-
|
|
941
|
+
} from "./server-6aj72z52.js";
|
|
933
942
|
import {
|
|
934
943
|
GIT_SWEEP_LEASE_RENEWAL_MS,
|
|
935
944
|
acquireGitSweepLease,
|
|
@@ -949,7 +958,7 @@ import {
|
|
|
949
958
|
getCachedLocalEmbeddingPooling,
|
|
950
959
|
preflightLocalEmbeddingPooling,
|
|
951
960
|
getLocalEmbeddingNativeMemoryStats
|
|
952
|
-
} from "./server-
|
|
961
|
+
} from "./server-qy58c11s.js";
|
|
953
962
|
import {
|
|
954
963
|
renderUserFacingFailure,
|
|
955
964
|
userFacingFailureCode,
|
|
@@ -969,8 +978,8 @@ import {
|
|
|
969
978
|
readGitFileChangeTimesSince,
|
|
970
979
|
verificationFileExists,
|
|
971
980
|
normalizeVerificationFiles
|
|
972
|
-
} from "./server-
|
|
973
|
-
import"./server-
|
|
981
|
+
} from "./server-prrx17q3.js";
|
|
982
|
+
import"./server-zc8s06gx.js";
|
|
974
983
|
import {
|
|
975
984
|
computeCueContentHash,
|
|
976
985
|
hasMuralCueColumns,
|
|
@@ -1036,7 +1045,7 @@ import {
|
|
|
1036
1045
|
readV2RawMessagePagesForConversion2,
|
|
1037
1046
|
createV2RawMessageReader2,
|
|
1038
1047
|
createV2RawMessageProvider2
|
|
1039
|
-
} from "./server-
|
|
1048
|
+
} from "./server-476anw1w.js";
|
|
1040
1049
|
import {
|
|
1041
1050
|
resolvePromptContext2
|
|
1042
1051
|
} from "./server-fmsr7v69.js";
|
|
@@ -1044,14 +1053,15 @@ import {
|
|
|
1044
1053
|
renderMessageByOrdinal2,
|
|
1045
1054
|
renderVerboseRangeForTool2,
|
|
1046
1055
|
renderItemByTag2
|
|
1047
|
-
} from "./server-
|
|
1048
|
-
import"./server-
|
|
1056
|
+
} from "./server-cvm1qrqc.js";
|
|
1057
|
+
import"./server-y0pd600x.js";
|
|
1049
1058
|
import {
|
|
1050
1059
|
readV2ArchiveOffThread2
|
|
1051
|
-
} from "./server-
|
|
1060
|
+
} from "./server-vbr1rdkg.js";
|
|
1052
1061
|
import {
|
|
1062
|
+
unresolvedLiveTailRefusal2,
|
|
1053
1063
|
renderSearchArchiveOffThread2
|
|
1054
|
-
} from "./server-
|
|
1064
|
+
} from "./server-s8mk882p.js";
|
|
1055
1065
|
import {
|
|
1056
1066
|
markHostInstructionRow,
|
|
1057
1067
|
hostInstructionRow,
|
|
@@ -3365,11 +3375,14 @@ function dropCompartmentsAfter(db, sessionId, anchor, holderId, activeBranch = f
|
|
|
3365
3375
|
return null;
|
|
3366
3376
|
}
|
|
3367
3377
|
const dropped = db.prepare("SELECT id, sequence FROM compartments WHERE session_id = ? AND sequence > ? ORDER BY sequence").all(sessionId, anchor?.sequence ?? -1);
|
|
3368
|
-
|
|
3378
|
+
const previousCoverage = readSummaryCoverage(db, sessionId);
|
|
3379
|
+
const hostQueuedRecovery = onRetire?.() === true;
|
|
3369
3380
|
const deleteEmbeddings = db.prepare("DELETE FROM compartment_chunk_embeddings WHERE compartment_id = ?");
|
|
3370
3381
|
for (const row of dropped)
|
|
3371
3382
|
deleteEmbeddings.run(row.id);
|
|
3372
3383
|
db.prepare("DELETE FROM compartments WHERE session_id = ? AND sequence > ?").run(sessionId, anchor?.sequence ?? -1);
|
|
3384
|
+
if (!hostQueuedRecovery)
|
|
3385
|
+
markHistoryGapAfterCoverageChange(db, sessionId, previousCoverage);
|
|
3373
3386
|
db.prepare("DELETE FROM compression_depth WHERE session_id = ? AND message_ordinal > ?").run(sessionId, anchor?.endMessage ?? 0);
|
|
3374
3387
|
if (activeBranch) {
|
|
3375
3388
|
db.prepare("UPDATE session_meta SET prior_boundary_ordinal = ? WHERE session_id = ?").run((anchor?.endMessage ?? 0) + 1, sessionId);
|
|
@@ -6626,7 +6639,11 @@ function getUnsummarizedTailInfo(db, sessionId, triggerBudget, usage, executeThr
|
|
|
6626
6639
|
}
|
|
6627
6640
|
const rawEligibility = getRawHistoryEligibility(db, sessionId);
|
|
6628
6641
|
if (!rawEligibility.hasRawBeyondLastCompartment) {
|
|
6629
|
-
return {
|
|
6642
|
+
return {
|
|
6643
|
+
...TAIL_INFO_DEFAULTS,
|
|
6644
|
+
nextStartOrdinal: rawEligibility.offset,
|
|
6645
|
+
noRawBeyondSummary: true
|
|
6646
|
+
};
|
|
6630
6647
|
}
|
|
6631
6648
|
const boundary = resolveOpenCodeProtectedTailBoundary({
|
|
6632
6649
|
db,
|
|
@@ -6686,6 +6703,12 @@ function checkCompartmentTrigger(db, sessionId, sessionMeta, usage, _previousPer
|
|
|
6686
6703
|
executeThresholdPercentage
|
|
6687
6704
|
}))
|
|
6688
6705
|
return { shouldFire: false };
|
|
6706
|
+
let historyGapMark = readHistoryGapMark(db, sessionId);
|
|
6707
|
+
const gapCoverageEnd = historyGapMark ? getLastCompartmentEndMessage(db, sessionId) : -1;
|
|
6708
|
+
if (historyGapMark && gapCoverageEnd > historyGapMark.endOrdinal) {
|
|
6709
|
+
clearHistoryGapMark(db, sessionId, historyGapMark.id);
|
|
6710
|
+
historyGapMark = null;
|
|
6711
|
+
}
|
|
6689
6712
|
const lazyInMemoryTail = typeof inMemoryTail === "function" ? inMemoryTail : undefined;
|
|
6690
6713
|
let resolvedInMemoryTail = typeof inMemoryTail === "function" ? undefined : inMemoryTail;
|
|
6691
6714
|
if (resolvedInMemoryTail) {
|
|
@@ -6699,6 +6722,7 @@ function checkCompartmentTrigger(db, sessionId, sessionMeta, usage, _previousPer
|
|
|
6699
6722
|
}
|
|
6700
6723
|
const taggerFloor = taggerFloorOverride !== undefined && taggerFloorOverride > 0 ? taggerFloorOverride : resolvedInMemoryTail ? deriveTagLoadFloor2(db, sessionId, resolvedInMemoryTail.messages.map((m) => m.id)) : 0;
|
|
6701
6724
|
const proactiveFloorForGate = getProactiveCompartmentTriggerPercentage(executeThresholdPercentage);
|
|
6725
|
+
let cheapSkip;
|
|
6702
6726
|
if (usage.percentage < proactiveFloorForGate) {
|
|
6703
6727
|
try {
|
|
6704
6728
|
const boundFloor = resolvedInMemoryTail || lazyInMemoryTail ? taggerFloor : 0;
|
|
@@ -6708,15 +6732,53 @@ function checkCompartmentTrigger(db, sessionId, sessionMeta, usage, _previousPer
|
|
|
6708
6732
|
const seed = sessionDecisionCalibration(db, sessionId);
|
|
6709
6733
|
const eligibleUpperBound = Math.ceil((persistedBound + untaggedUpperBound) * Math.max(1, seed.proseRatio, seed.toolsRatio, seed.systemRatio));
|
|
6710
6734
|
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 };
|
|
6735
|
+
cheapSkip = { eligibleUpperBound, persistedBound, untaggedUpperBound };
|
|
6714
6736
|
}
|
|
6715
6737
|
}
|
|
6716
6738
|
} catch (error) {
|
|
6717
6739
|
sessionLog2(sessionId, `compartment trigger: cheap-gate skipped (falling through to full read): ${error instanceof Error ? error.message : String(error)}`);
|
|
6718
6740
|
}
|
|
6719
6741
|
}
|
|
6742
|
+
const forceMaterializationPercentage = escalationBands(executeThresholdPercentage).forceMaterializationPercentage;
|
|
6743
|
+
let historyGapAdmission;
|
|
6744
|
+
if (historyGapMark && usage.percentage < forceMaterializationPercentage) {
|
|
6745
|
+
const now = Date.now();
|
|
6746
|
+
const checkedAt = historyGapMark.checkedAt;
|
|
6747
|
+
if (checkedAt === undefined || checkedAt > now || now - checkedAt >= EMERGENCY_DRAIN_FAILURE_BACKOFF_MS) {
|
|
6748
|
+
const { failureCount, lastFailureAt } = getHistorianFailureState(db, sessionId);
|
|
6749
|
+
const failedAt = lastFailureAt ?? 0;
|
|
6750
|
+
const admittedRuns = historyGapMark.admittedRuns ?? 0;
|
|
6751
|
+
const previousRunFailed = failureCount > (historyGapMark.failureCountAtAdmission ?? failureCount);
|
|
6752
|
+
if (previousRunFailed && admittedRuns >= 2) {
|
|
6753
|
+
clearHistoryGapMark(db, sessionId, historyGapMark.id);
|
|
6754
|
+
historyGapMark = null;
|
|
6755
|
+
} else if (failedAt <= 0 || failedAt > now || now - failedAt >= EMERGENCY_DRAIN_FAILURE_BACKOFF_MS) {
|
|
6756
|
+
const count = resolvedInMemoryTail?.absoluteMessageCount ?? getRawSessionMessageOrdinalCount2(sessionId);
|
|
6757
|
+
if (count <= Math.max(0, gapCoverageEnd)) {
|
|
6758
|
+
clearHistoryGapMark(db, sessionId, historyGapMark.id);
|
|
6759
|
+
} else {
|
|
6760
|
+
const inspectedCount = historyGapMark.inspectedCount ?? 0;
|
|
6761
|
+
const canAdmit = admittedRuns < 2 && (admittedRuns === 0 || previousRunFailed);
|
|
6762
|
+
const shouldInspect = canAdmit && count > inspectedCount;
|
|
6763
|
+
const nextFrontier = shouldInspect || count < inspectedCount ? count : inspectedCount;
|
|
6764
|
+
if (claimHistoryGapCheck(db, sessionId, historyGapMark, now, nextFrontier) && shouldInspect) {
|
|
6765
|
+
historyGapAdmission = {
|
|
6766
|
+
id: historyGapMark.id,
|
|
6767
|
+
checkedAt: now,
|
|
6768
|
+
admittedRuns: admittedRuns + 1,
|
|
6769
|
+
failureCount
|
|
6770
|
+
};
|
|
6771
|
+
}
|
|
6772
|
+
}
|
|
6773
|
+
}
|
|
6774
|
+
}
|
|
6775
|
+
}
|
|
6776
|
+
if (cheapSkip && !historyGapAdmission) {
|
|
6777
|
+
const { eligibleUpperBound, persistedBound, untaggedUpperBound } = cheapSkip;
|
|
6778
|
+
const memorySuffix = resolvedInMemoryTail ? ` (persisted=${persistedBound}, untagged-memory≤${untaggedUpperBound})` : "";
|
|
6779
|
+
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`);
|
|
6780
|
+
return { shouldFire: false };
|
|
6781
|
+
}
|
|
6720
6782
|
if (lazyInMemoryTail) {
|
|
6721
6783
|
try {
|
|
6722
6784
|
const policyVersion = loadProtectedTailMeta(db, sessionId).protectedTailPolicyVersion;
|
|
@@ -6743,6 +6805,8 @@ function checkCompartmentTrigger(db, sessionId, sessionMeta, usage, _previousPer
|
|
|
6743
6805
|
}
|
|
6744
6806
|
}
|
|
6745
6807
|
if (!tailInfo.hasNewRawHistory) {
|
|
6808
|
+
if (historyGapMark && tailInfo.noRawBeyondSummary)
|
|
6809
|
+
clearHistoryGapMark(db, sessionId, historyGapMark.id);
|
|
6746
6810
|
try {
|
|
6747
6811
|
const lastCompartmentEnd = getLastCompartmentEndMessage(db, sessionId);
|
|
6748
6812
|
sessionLog2(sessionId, `compartment trigger: skipped — no new raw history (usage=${usage.percentage.toFixed(1)}% nextStartOrdinal=${tailInfo.nextStartOrdinal} lastCompartmentEnd=${lastCompartmentEnd})`);
|
|
@@ -6762,13 +6826,19 @@ function checkCompartmentTrigger(db, sessionId, sessionMeta, usage, _previousPer
|
|
|
6762
6826
|
sessionLog2(sessionId, "compartment trigger: waiting for new history after no forward progress");
|
|
6763
6827
|
return { shouldFire: false };
|
|
6764
6828
|
}
|
|
6829
|
+
if (historyGapAdmission && tailInfo.boundarySnapshot && hasRunnableCompartmentWindow(tailInfo.boundarySnapshot) && recordHistoryGapAdmission(db, sessionId, historyGapAdmission)) {
|
|
6830
|
+
return {
|
|
6831
|
+
shouldFire: true,
|
|
6832
|
+
reason: "history_gap",
|
|
6833
|
+
boundarySnapshot: tailInfo.boundarySnapshot
|
|
6834
|
+
};
|
|
6835
|
+
}
|
|
6765
6836
|
const canClearReasoning = reasoningProjection?.canClearReasoning ?? modelAcceptsEmptyContent(reasoningProjection?.providerID);
|
|
6766
6837
|
const projectedPostDropPercentage = estimateProjectedPostDropPercentage(db, sessionId, usage, preloadedActiveTags ?? getActiveTagsBySession2(db, sessionId), keepReasoningTokens, sessionMeta.clearedReasoningThroughTag, canClearReasoning, reasoningProjection?.budgetCutoff, eligiblePendingDropTagIds);
|
|
6767
6838
|
const relativePostDropTarget = executeThresholdPercentage * POST_DROP_TARGET_RATIO;
|
|
6768
6839
|
const ridePermitted = reclaimRide !== undefined && (reclaimRide.permission ? reclaimRidePermitted(reclaimRide, reclaimRide.permission) : hasReclaimRide(reclaimRide));
|
|
6769
6840
|
const rideLabel = reclaimRide ? reclaimRideLabel(reclaimRide) : "ride=none";
|
|
6770
6841
|
const dropsCanLand = ridePermitted;
|
|
6771
|
-
const forceMaterializationPercentage = escalationBands(executeThresholdPercentage).forceMaterializationPercentage;
|
|
6772
6842
|
if (usage.percentage >= forceMaterializationPercentage) {
|
|
6773
6843
|
if (dropsCanLand && projectedPostDropPercentage !== null && projectedPostDropPercentage <= relativePostDropTarget) {
|
|
6774
6844
|
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})`);
|
|
@@ -26561,7 +26631,7 @@ function registerRpcHandlers(rpcServer, args) {
|
|
|
26561
26631
|
const db = readDatabase();
|
|
26562
26632
|
if (!db)
|
|
26563
26633
|
return { ok: false, error: "db unavailable" };
|
|
26564
|
-
const { runManagedRecomp } = await importPluginModule(() => import("./recomp-orchestrator-
|
|
26634
|
+
const { runManagedRecomp } = await importPluginModule(() => import("./recomp-orchestrator-k4cj62f2.js"));
|
|
26565
26635
|
const { sendIgnoredMessage } = await importPluginModule(() => import("./send-session-notification-v69y04f5.js"));
|
|
26566
26636
|
log2(`[rpc] recomp requested for session ${sessionId}`);
|
|
26567
26637
|
if (!args.client && !args.hiddenCompletionExecutor) {
|
|
@@ -26646,7 +26716,7 @@ function registerRpcHandlers(rpcServer, args) {
|
|
|
26646
26716
|
const db = readDatabase();
|
|
26647
26717
|
if (!db)
|
|
26648
26718
|
return { ok: false, error: "db unavailable" };
|
|
26649
|
-
const { runManagedWrapup } = await importPluginModule(() => import("./wrapup-orchestrator-
|
|
26719
|
+
const { runManagedWrapup } = await importPluginModule(() => import("./wrapup-orchestrator-ydqkxkhj.js"));
|
|
26650
26720
|
const model = await args.readSelectedSessionModel?.(sessionId) ?? liveSessionState.liveModelBySession.get(sessionId);
|
|
26651
26721
|
const window = resolveOpenCodeWrapupWindow(db, sessionId, model);
|
|
26652
26722
|
if (!window)
|
|
@@ -28285,6 +28355,9 @@ class NativeFoldCache {
|
|
|
28285
28355
|
const kept = this.nativeRows.get(sessionID);
|
|
28286
28356
|
return ids.every((id) => kept?.has(id));
|
|
28287
28357
|
}
|
|
28358
|
+
holdsState(sessionID) {
|
|
28359
|
+
return this.tails.has(sessionID) || (this.nativeRows.get(sessionID)?.size ?? 0) > 0;
|
|
28360
|
+
}
|
|
28288
28361
|
rows(sessionID, after, through) {
|
|
28289
28362
|
if (this.retention.has(sessionID))
|
|
28290
28363
|
this.touch(sessionID);
|
|
@@ -29185,8 +29258,11 @@ class NativeFoldReplay {
|
|
|
29185
29258
|
stampMRU;
|
|
29186
29259
|
loaded = new Map;
|
|
29187
29260
|
sources = new Map;
|
|
29261
|
+
memorySources = new Map;
|
|
29188
29262
|
staleHeads = new Set;
|
|
29189
29263
|
unprovenControls = new Set;
|
|
29264
|
+
reportedCaptureReplacements = new Set;
|
|
29265
|
+
reportedForeignRefreshes = new Set;
|
|
29190
29266
|
editedAdmissions = new Map;
|
|
29191
29267
|
legacyUpgrades = new Map;
|
|
29192
29268
|
constructor(storage, openReader, admissions, options = {}) {
|
|
@@ -29210,6 +29286,7 @@ class NativeFoldReplay {
|
|
|
29210
29286
|
await this.forget(sessionID);
|
|
29211
29287
|
this.sources.set(sessionID, source);
|
|
29212
29288
|
this.account(sessionID);
|
|
29289
|
+
return source;
|
|
29213
29290
|
}
|
|
29214
29291
|
onEvent(event) {
|
|
29215
29292
|
const sessionID = event.data?.sessionID;
|
|
@@ -29282,6 +29359,18 @@ class NativeFoldReplay {
|
|
|
29282
29359
|
this.options.log?.(sessionID, `v3 host fold: ${reason}`);
|
|
29283
29360
|
} catch {}
|
|
29284
29361
|
}
|
|
29362
|
+
reportOnce(sessionID, reported, message) {
|
|
29363
|
+
if (reported.has(sessionID))
|
|
29364
|
+
return;
|
|
29365
|
+
reported.add(sessionID);
|
|
29366
|
+
const sessionLog = this.options.log;
|
|
29367
|
+
try {
|
|
29368
|
+
sessionLog?.(sessionID, message);
|
|
29369
|
+
} catch {}
|
|
29370
|
+
}
|
|
29371
|
+
reportCaptureReplacement(sessionID) {
|
|
29372
|
+
this.reportOnce(sessionID, this.reportedCaptureReplacements, "v3 host fold: capture skipped: host database file changed between readers");
|
|
29373
|
+
}
|
|
29285
29374
|
historyCoverage(sessionID, reader) {
|
|
29286
29375
|
if (!this.options.rendersHistory?.(sessionID))
|
|
29287
29376
|
return;
|
|
@@ -29298,13 +29387,15 @@ class NativeFoldReplay {
|
|
|
29298
29387
|
return false;
|
|
29299
29388
|
}
|
|
29300
29389
|
async floorState(sessionID, reader, boundary, served, preferCapture = false) {
|
|
29390
|
+
const source = reader.hostIdentity();
|
|
29391
|
+
await this.fenceMemory(sessionID, source);
|
|
29301
29392
|
const coverage = this.historyCoverage(sessionID, reader);
|
|
29302
29393
|
const retained = this.tail(sessionID)?.replay;
|
|
29303
29394
|
const controlsKnown = (replay) => replay.controls.every((control) => !control.after || reader.sequenceForId(sessionID, control.after) !== undefined);
|
|
29304
29395
|
const memory = retained && validReplayState(retained) && controlsKnown(retained) && validFloor(reader, sessionID, retained.floor) && this.floorCovered(sessionID, retained.floor, coverage, retained) ? retained : undefined;
|
|
29305
29396
|
const cut = reader.latestCompaction(sessionID);
|
|
29306
29397
|
const saved = await this.readV3(sessionID);
|
|
29307
|
-
const durable = saved && saved.proof.sourceDigest === foldDigest(
|
|
29398
|
+
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
29399
|
const marker = importedFloor(reader, sessionID, cut?.seq);
|
|
29309
29400
|
const imported = marker && this.floorCovered(sessionID, marker, coverage) ? marker : undefined;
|
|
29310
29401
|
const capturedRecord = await this.readCapturedReplay(sessionID, reader);
|
|
@@ -29364,11 +29455,11 @@ class NativeFoldReplay {
|
|
|
29364
29455
|
return;
|
|
29365
29456
|
}
|
|
29366
29457
|
}
|
|
29367
|
-
async saveCapturedReplay(sessionID, replay, reader) {
|
|
29458
|
+
async saveCapturedReplay(sessionID, replay, reader, sourceDigest) {
|
|
29368
29459
|
const value = {
|
|
29369
29460
|
version: 3,
|
|
29370
29461
|
sessionID,
|
|
29371
|
-
sourceDigest
|
|
29462
|
+
sourceDigest,
|
|
29372
29463
|
through: reader.latestSequence(sessionID),
|
|
29373
29464
|
replay
|
|
29374
29465
|
};
|
|
@@ -29398,11 +29489,33 @@ class NativeFoldReplay {
|
|
|
29398
29489
|
${cached}
|
|
29399
29490
|
</summary>`)))) ? cached : undefined;
|
|
29400
29491
|
}
|
|
29401
|
-
async retainReplay(sessionID, replay, model, sourceSeq) {
|
|
29492
|
+
async retainReplay(sessionID, replay, model, sourceSeq, source) {
|
|
29493
|
+
await this.fenceMemory(sessionID, source);
|
|
29402
29494
|
const tail = this.tail(sessionID) ?? { model, sourceSeq };
|
|
29403
29495
|
await this.storage.saveTail(sessionID, JSON.stringify({ ...tail, replay }), []);
|
|
29404
29496
|
if (!this.storage.tail(sessionID))
|
|
29405
29497
|
await this.storage.saveTail(sessionID, JSON.stringify({ model, sourceSeq, replay }), []);
|
|
29498
|
+
this.memorySources.set(sessionID, source);
|
|
29499
|
+
}
|
|
29500
|
+
async fenceMemory(sessionID, source) {
|
|
29501
|
+
const recorded = this.memorySources.get(sessionID);
|
|
29502
|
+
if (recorded === source)
|
|
29503
|
+
return;
|
|
29504
|
+
if (recorded === undefined && !this.storage.holdsState(sessionID) && !this.metadata.has(sessionID))
|
|
29505
|
+
return;
|
|
29506
|
+
await this.discardCapture(sessionID);
|
|
29507
|
+
this.reportCaptureReplacement(sessionID);
|
|
29508
|
+
}
|
|
29509
|
+
async discardCapture(sessionID) {
|
|
29510
|
+
if (this.stampMRU?.sessionID === sessionID)
|
|
29511
|
+
this.stampMRU = undefined;
|
|
29512
|
+
const source = this.sources.get(sessionID);
|
|
29513
|
+
const forgotten = this.storage.forget(sessionID);
|
|
29514
|
+
if (source !== undefined) {
|
|
29515
|
+
this.sources.set(sessionID, source);
|
|
29516
|
+
this.account(sessionID);
|
|
29517
|
+
}
|
|
29518
|
+
await forgotten;
|
|
29406
29519
|
}
|
|
29407
29520
|
async canFold(sessionID, reader) {
|
|
29408
29521
|
if (this.options.protocol !== 3) {
|
|
@@ -29503,7 +29616,7 @@ ${cached}
|
|
|
29503
29616
|
}
|
|
29504
29617
|
};
|
|
29505
29618
|
this.legacyUpgrades.set(draft.sessionID, { value, rows, started });
|
|
29506
|
-
await this.retainReplay(draft.sessionID, replay, `${draft.model.providerID}/${draft.model.id}`, cut.seq - 1);
|
|
29619
|
+
await this.retainReplay(draft.sessionID, replay, `${draft.model.providerID}/${draft.model.id}`, cut.seq - 1, reader.hostIdentity());
|
|
29507
29620
|
return true;
|
|
29508
29621
|
}
|
|
29509
29622
|
legacyUpgradeInput(sessionID, model) {
|
|
@@ -29511,8 +29624,16 @@ ${cached}
|
|
|
29511
29624
|
if (!pending)
|
|
29512
29625
|
return;
|
|
29513
29626
|
let reader;
|
|
29627
|
+
const open = () => {
|
|
29628
|
+
const opened = this.openReader(sessionID);
|
|
29629
|
+
if (foldDigest(opened.hostIdentity()) !== pending.value.proof.sourceDigest) {
|
|
29630
|
+
opened.close();
|
|
29631
|
+
throw new NativeReplayUnavailable("Host database file changed during upgrade");
|
|
29632
|
+
}
|
|
29633
|
+
return opened;
|
|
29634
|
+
};
|
|
29514
29635
|
const blobs = {
|
|
29515
|
-
mediaBlob: (hash) => (reader ??=
|
|
29636
|
+
mediaBlob: (hash) => (reader ??= open()).mediaBlob(hash)
|
|
29516
29637
|
};
|
|
29517
29638
|
try {
|
|
29518
29639
|
return pending.rows.filter((row) => row.seq > pending.value.replay.floor.after).flatMap((row) => {
|
|
@@ -29532,6 +29653,11 @@ ${cached}
|
|
|
29532
29653
|
const admissions = this.admissions;
|
|
29533
29654
|
if (!pending || !admissions)
|
|
29534
29655
|
return false;
|
|
29656
|
+
const recorded = this.memorySources.get(sessionID);
|
|
29657
|
+
if (recorded === undefined ? this.storage.holdsState(sessionID) || this.metadata.has(sessionID) : foldDigest(recorded) !== pending.value.proof.sourceDigest) {
|
|
29658
|
+
await this.discardCapture(sessionID);
|
|
29659
|
+
this.reportCaptureReplacement(sessionID);
|
|
29660
|
+
}
|
|
29535
29661
|
const replay = this.tail(sessionID)?.replay ?? pending.value.replay;
|
|
29536
29662
|
if (replay.blocked)
|
|
29537
29663
|
return false;
|
|
@@ -29569,13 +29695,16 @@ ${cached}
|
|
|
29569
29695
|
stripCheckpointRecentContext(rendered, row.data.summary ?? "");
|
|
29570
29696
|
return { row, rendered, submitted: row.data.summary ?? "" };
|
|
29571
29697
|
}
|
|
29572
|
-
async checkpointCovered(sessionID, checkpointID) {
|
|
29698
|
+
async checkpointCovered(sessionID, checkpointID, sourceIdentity) {
|
|
29573
29699
|
const admissions = this.admissions;
|
|
29574
29700
|
if (!admissions)
|
|
29575
29701
|
return;
|
|
29702
|
+
await this.fenceMemory(sessionID, sourceIdentity);
|
|
29576
29703
|
const pending = this.legacyUpgrades.get(sessionID);
|
|
29577
|
-
const
|
|
29578
|
-
|
|
29704
|
+
const sourceDigest = foldDigest(sourceIdentity);
|
|
29705
|
+
const saved = await this.readV3(sessionID);
|
|
29706
|
+
const value = saved?.proof.sourceDigest === sourceDigest ? saved : pending?.value;
|
|
29707
|
+
if (value?.proof.sourceDigest !== sourceDigest || value.replay.floor.kind !== "host-checkpoint" || value.replay.floor.id !== checkpointID || value.replay.withoutRecentContext)
|
|
29579
29708
|
return;
|
|
29580
29709
|
value.replay.withoutRecentContext = true;
|
|
29581
29710
|
const payload = encodeAdmissionV3(value);
|
|
@@ -29586,7 +29715,7 @@ ${cached}
|
|
|
29586
29715
|
});
|
|
29587
29716
|
const tail = this.tail(sessionID);
|
|
29588
29717
|
if (tail)
|
|
29589
|
-
await this.retainReplay(sessionID, value.replay, tail.model, tail.sourceSeq);
|
|
29718
|
+
await this.retainReplay(sessionID, value.replay, tail.model, tail.sourceSeq, sourceIdentity);
|
|
29590
29719
|
}
|
|
29591
29720
|
async removeAdmission(key) {
|
|
29592
29721
|
if (this.admissions?.remove)
|
|
@@ -29604,7 +29733,8 @@ ${cached}
|
|
|
29604
29733
|
if (!saved || !isLocalCheckpoint(cut) || cut.session_id !== sessionID)
|
|
29605
29734
|
return false;
|
|
29606
29735
|
const proof = saved.proof;
|
|
29607
|
-
|
|
29736
|
+
const source = reader.hostIdentity();
|
|
29737
|
+
if (proof.sourceDigest !== foldDigest(source) || proof.admissionID !== cut.id || proof.summaryDigest !== foldDigest(cut.data.summary ?? "")) {
|
|
29608
29738
|
this.report(sessionID, "replay refused: invalid checkpoint floor or provenance");
|
|
29609
29739
|
return false;
|
|
29610
29740
|
}
|
|
@@ -29620,17 +29750,17 @@ ${cached}
|
|
|
29620
29750
|
this.editedAdmissions.set(sessionID, { original: saved, replay });
|
|
29621
29751
|
this.staleHeads.add(sessionID);
|
|
29622
29752
|
this.invalidate(sessionID);
|
|
29623
|
-
await this.retainReplay(sessionID, replay, this.tail(sessionID)?.model ?? "", cut.seq - 1);
|
|
29753
|
+
await this.retainReplay(sessionID, replay, this.tail(sessionID)?.model ?? "", cut.seq - 1, source);
|
|
29624
29754
|
return false;
|
|
29625
29755
|
}
|
|
29626
29756
|
if (!this.floorCovered(sessionID, replay.floor, this.historyCoverage(sessionID, reader), replay))
|
|
29627
29757
|
return false;
|
|
29628
|
-
await this.retainReplay(sessionID, saved.replay, this.tail(sessionID)?.model ?? "", cut.seq - 1);
|
|
29758
|
+
await this.retainReplay(sessionID, saved.replay, this.tail(sessionID)?.model ?? "", cut.seq - 1, source);
|
|
29629
29759
|
if (proof.historyDigest !== historyDigest(reader, sessionID, cut.seq - 1, saved.replay.floor.after)) {
|
|
29630
29760
|
this.staleHeads.add(sessionID);
|
|
29631
29761
|
this.invalidate(sessionID);
|
|
29632
29762
|
this.editedAdmissions.set(sessionID, { original: saved, replay });
|
|
29633
|
-
await this.retainReplay(sessionID, saved.replay, this.tail(sessionID)?.model ?? "", cut.seq - 1);
|
|
29763
|
+
await this.retainReplay(sessionID, saved.replay, this.tail(sessionID)?.model ?? "", cut.seq - 1, source);
|
|
29634
29764
|
return false;
|
|
29635
29765
|
}
|
|
29636
29766
|
await this.storage.supply(sessionID, cut.id, JSON.stringify({
|
|
@@ -29682,6 +29812,7 @@ ${cached}
|
|
|
29682
29812
|
return false;
|
|
29683
29813
|
const reader = this.openReader(sessionID);
|
|
29684
29814
|
try {
|
|
29815
|
+
await this.fenceMemory(sessionID, reader.hostIdentity());
|
|
29685
29816
|
const cut = reader.latestCompaction(sessionID);
|
|
29686
29817
|
const proof = pending.original.proof;
|
|
29687
29818
|
const replay = this.tail(sessionID)?.replay ?? pending.replay;
|
|
@@ -29886,14 +30017,23 @@ ${cached}
|
|
|
29886
30017
|
}
|
|
29887
30018
|
return [...grouped].map(([row, messages]) => this.record(row, messages));
|
|
29888
30019
|
}
|
|
29889
|
-
async capture(draft, native, boundary, restoredFirstRow) {
|
|
30020
|
+
async capture(draft, native, draftSourceIdentity, boundary, restoredFirstRow) {
|
|
29890
30021
|
const release = this.storage.hold(draft.sessionID);
|
|
29891
30022
|
let replay;
|
|
30023
|
+
let capturedIdentity;
|
|
29892
30024
|
let sourceSeq = -1;
|
|
29893
30025
|
try {
|
|
29894
30026
|
rememberHostMedia(native);
|
|
29895
30027
|
const reader = this.openReader(draft.sessionID);
|
|
29896
30028
|
try {
|
|
30029
|
+
capturedIdentity = reader.hostIdentity();
|
|
30030
|
+
if (capturedIdentity !== draftSourceIdentity) {
|
|
30031
|
+
await this.discardCapture(draft.sessionID);
|
|
30032
|
+
this.reportCaptureReplacement(draft.sessionID);
|
|
30033
|
+
return;
|
|
30034
|
+
}
|
|
30035
|
+
await this.fenceMemory(draft.sessionID, capturedIdentity);
|
|
30036
|
+
this.memorySources.set(draft.sessionID, capturedIdentity);
|
|
29897
30037
|
if (this.options.protocol === 3) {
|
|
29898
30038
|
replay = await this.floorState(draft.sessionID, reader, boundary, draft);
|
|
29899
30039
|
if (!replay && restoredFirstRow) {
|
|
@@ -29943,6 +30083,7 @@ ${cached}
|
|
|
29943
30083
|
};
|
|
29944
30084
|
await this.storage.saveTail(draft.sessionID, JSON.stringify(tail), rows);
|
|
29945
30085
|
this.storage.truncate(draft.sessionID, through);
|
|
30086
|
+
this.memorySources.set(draft.sessionID, capturedIdentity);
|
|
29946
30087
|
this.loaded.set(draft.sessionID, through);
|
|
29947
30088
|
this.unavailable.delete(draft.sessionID);
|
|
29948
30089
|
this.changed.delete(draft.sessionID);
|
|
@@ -29965,13 +30106,24 @@ ${cached}
|
|
|
29965
30106
|
}
|
|
29966
30107
|
}
|
|
29967
30108
|
if (replay) {
|
|
29968
|
-
await this.retainReplay(draft.sessionID, replay, `${draft.model.providerID}/${draft.model.id}`, sourceSeq);
|
|
30109
|
+
await this.retainReplay(draft.sessionID, replay, `${draft.model.providerID}/${draft.model.id}`, sourceSeq, draftSourceIdentity);
|
|
29969
30110
|
const reader = this.openReader(draft.sessionID);
|
|
29970
30111
|
try {
|
|
29971
|
-
|
|
30112
|
+
const identity = reader.hostIdentity();
|
|
30113
|
+
if (identity !== capturedIdentity) {
|
|
30114
|
+
await this.discardCapture(draft.sessionID);
|
|
30115
|
+
this.reportCaptureReplacement(draft.sessionID);
|
|
30116
|
+
return;
|
|
30117
|
+
}
|
|
30118
|
+
const sourceDigest = foldDigest(identity);
|
|
30119
|
+
await this.saveCapturedReplay(draft.sessionID, replay, reader, sourceDigest);
|
|
29972
30120
|
const saved = await this.readV3(draft.sessionID);
|
|
29973
30121
|
const cut = reader.latestCompaction(draft.sessionID);
|
|
29974
30122
|
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)) {
|
|
30123
|
+
if (saved.proof.sourceDigest !== sourceDigest) {
|
|
30124
|
+
this.reportOnce(draft.sessionID, this.reportedForeignRefreshes, "v3 host fold: admission refresh skipped: admission belongs to a different host database file");
|
|
30125
|
+
return;
|
|
30126
|
+
}
|
|
29975
30127
|
const value = {
|
|
29976
30128
|
...saved,
|
|
29977
30129
|
replay: {
|
|
@@ -30014,6 +30166,8 @@ ${cached}
|
|
|
30014
30166
|
async supplyHeld(args) {
|
|
30015
30167
|
const { draft, reader, summary } = args;
|
|
30016
30168
|
const stored = args.checkpointText ?? summary;
|
|
30169
|
+
const source = reader.hostIdentity();
|
|
30170
|
+
await this.fenceMemory(draft.sessionID, source);
|
|
30017
30171
|
if (this.options.protocol === 3) {
|
|
30018
30172
|
if (this.unprovenControls.has(draft.sessionID))
|
|
30019
30173
|
return false;
|
|
@@ -30038,7 +30192,7 @@ ${cached}
|
|
|
30038
30192
|
if (!args.manual && this.tail(draft.sessionID)?.model !== model)
|
|
30039
30193
|
this.storage.replaceRows(draft.sessionID, reader.latestSequence(draft.sessionID), []);
|
|
30040
30194
|
if (!args.manual)
|
|
30041
|
-
await this.retainReplay(draft.sessionID, replay, model, reader.latestSequence(draft.sessionID));
|
|
30195
|
+
await this.retainReplay(draft.sessionID, replay, model, reader.latestSequence(draft.sessionID), source);
|
|
30042
30196
|
if (!args.manual)
|
|
30043
30197
|
await this.storage.supply(draft.sessionID, running.id, JSON.stringify({
|
|
30044
30198
|
source: this.storage.sourceID,
|
|
@@ -30100,7 +30254,7 @@ ${cached}
|
|
|
30100
30254
|
this.invalidate(draft.sessionID);
|
|
30101
30255
|
this.cancelLegacyUpgrade(draft.sessionID);
|
|
30102
30256
|
this.cancelEditedAdmission(draft.sessionID);
|
|
30103
|
-
await this.retainReplay(draft.sessionID, replay, model, running.seq - 1);
|
|
30257
|
+
await this.retainReplay(draft.sessionID, replay, model, running.seq - 1, source);
|
|
30104
30258
|
await this.storage.supply(draft.sessionID, running.id, JSON.stringify({
|
|
30105
30259
|
source: this.storage.sourceID,
|
|
30106
30260
|
sessionID: draft.sessionID,
|
|
@@ -30133,6 +30287,7 @@ ${cached}
|
|
|
30133
30287
|
baseline: tail?.baseline ?? summary,
|
|
30134
30288
|
sourceSeq: Math.max(tail?.sourceSeq ?? through, ...fresh.map((row) => row.seq))
|
|
30135
30289
|
}), records);
|
|
30290
|
+
this.memorySources.set(draft.sessionID, source);
|
|
30136
30291
|
this.dirty.delete(draft.sessionID);
|
|
30137
30292
|
this.metadata.delete(draft.sessionID);
|
|
30138
30293
|
this.metadataThrough.delete(draft.sessionID);
|
|
@@ -30161,13 +30316,16 @@ ${cached}
|
|
|
30161
30316
|
}
|
|
30162
30317
|
return true;
|
|
30163
30318
|
}
|
|
30164
|
-
async restore(sessionID, cut, model, options = {}) {
|
|
30319
|
+
async restore(sessionID, cut, model, passSource, options = {}) {
|
|
30165
30320
|
let replay;
|
|
30166
30321
|
let controls = [];
|
|
30167
30322
|
let after;
|
|
30323
|
+
await this.fenceMemory(sessionID, passSource);
|
|
30168
30324
|
if (this.options.protocol === 3) {
|
|
30169
30325
|
const reader = this.openReader(sessionID);
|
|
30170
30326
|
try {
|
|
30327
|
+
if (reader.hostIdentity() !== passSource)
|
|
30328
|
+
throw new NativeReplayUnavailable("Host database file changed during restore");
|
|
30171
30329
|
replay = await this.floorState(sessionID, reader);
|
|
30172
30330
|
if (replay) {
|
|
30173
30331
|
controls = controlsThrough(replay.controls, reader, sessionID, cut.seq - 1);
|
|
@@ -30191,7 +30349,7 @@ ${cached}
|
|
|
30191
30349
|
const release = this.storage.hold(sessionID);
|
|
30192
30350
|
let result;
|
|
30193
30351
|
try {
|
|
30194
|
-
result = await this.restoreHeld(sessionID, cut, model, options);
|
|
30352
|
+
result = await this.restoreHeld(sessionID, cut, model, options, passSource);
|
|
30195
30353
|
} finally {
|
|
30196
30354
|
try {
|
|
30197
30355
|
this.account(sessionID);
|
|
@@ -30200,14 +30358,23 @@ ${cached}
|
|
|
30200
30358
|
}
|
|
30201
30359
|
}
|
|
30202
30360
|
if (replay) {
|
|
30203
|
-
await this.retainReplay(sessionID, replay, model, cut.seq - 1);
|
|
30361
|
+
await this.retainReplay(sessionID, replay, model, cut.seq - 1, passSource);
|
|
30204
30362
|
return result && insertControls(result, controls, nativeRowID);
|
|
30205
30363
|
}
|
|
30206
30364
|
return result;
|
|
30207
30365
|
}
|
|
30208
|
-
async restoreHeld(sessionID, cut, model, options) {
|
|
30366
|
+
async restoreHeld(sessionID, cut, model, options, expected) {
|
|
30209
30367
|
if (!isLocalCheckpoint(cut))
|
|
30210
30368
|
return;
|
|
30369
|
+
const open = () => {
|
|
30370
|
+
const opened = this.openReader(sessionID);
|
|
30371
|
+
if (opened.hostIdentity() !== expected) {
|
|
30372
|
+
opened.close();
|
|
30373
|
+
throw new NativeReplayUnavailable("Host database file changed during restore");
|
|
30374
|
+
}
|
|
30375
|
+
this.memorySources.set(sessionID, expected);
|
|
30376
|
+
return opened;
|
|
30377
|
+
};
|
|
30211
30378
|
const resolvedModel = {
|
|
30212
30379
|
providerID: model.slice(0, model.indexOf("/")),
|
|
30213
30380
|
id: model.slice(model.indexOf("/") + 1)
|
|
@@ -30223,13 +30390,13 @@ ${cached}
|
|
|
30223
30390
|
const max = this.storage.db.prepare("SELECT COALESCE(MAX(id),0) AS id FROM m0_mutation_log WHERE session_id=?").get(sessionID);
|
|
30224
30391
|
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
30392
|
if (max.id <= (state.cachedM0MaxMutationId ?? 0) && boundary) {
|
|
30226
|
-
after = this.storage.sequenceForID(sessionID, boundary) ?? (reader =
|
|
30393
|
+
after = this.storage.sequenceForID(sessionID, boundary) ?? (reader = open()).sequenceForId(sessionID, boundary) ?? -1;
|
|
30227
30394
|
}
|
|
30228
30395
|
}
|
|
30229
30396
|
const through = cut.seq - 1;
|
|
30230
30397
|
let metadata = this.metadata.get(sessionID);
|
|
30231
30398
|
if (!metadata || (this.metadataThrough.get(sessionID) ?? -1) < through || this.options.protocol === 3 && this.options.rendersHistory?.(sessionID) && (this.metadataAfter.get(sessionID) ?? -1) > after) {
|
|
30232
|
-
reader ??=
|
|
30399
|
+
reader ??= open();
|
|
30233
30400
|
metadata = reader.rowStampsThrough(sessionID, through, this.options.protocol === 3 ? after : undefined).filter(conversational);
|
|
30234
30401
|
this.metadata.set(sessionID, metadata);
|
|
30235
30402
|
this.metadataThrough.set(sessionID, through);
|
|
@@ -30237,7 +30404,7 @@ ${cached}
|
|
|
30237
30404
|
}
|
|
30238
30405
|
const required = metadata.filter((row) => row.seq > after && row.seq <= through);
|
|
30239
30406
|
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 ??=
|
|
30407
|
+
const source = reader ??= open();
|
|
30241
30408
|
const fresh = source.range(sessionID, after, through).filter(conversational);
|
|
30242
30409
|
const records = fresh.map((row) => this.record(row, this.rendered(row, resolvedModel, source)));
|
|
30243
30410
|
const restored = new Set(records.map((row) => row.id));
|
|
@@ -30267,9 +30434,11 @@ ${cached}
|
|
|
30267
30434
|
}
|
|
30268
30435
|
return messages;
|
|
30269
30436
|
}
|
|
30270
|
-
async restoreRead(sessionID, cut, model) {
|
|
30437
|
+
async restoreRead(sessionID, cut, model, passSource) {
|
|
30271
30438
|
const reader = this.openReader(sessionID);
|
|
30272
30439
|
try {
|
|
30440
|
+
if (reader.hostIdentity() !== passSource)
|
|
30441
|
+
throw new NativeReplayUnavailable("Host checkpoint replay boundary is unavailable");
|
|
30273
30442
|
const replay = this.options.protocol === 3 ? await this.floorState(sessionID, reader) : undefined;
|
|
30274
30443
|
if (this.options.protocol === 3 && !replay) {
|
|
30275
30444
|
this.report(sessionID, "replay refused: missing usable checkpoint boundary");
|
|
@@ -30296,6 +30465,7 @@ ${cached}
|
|
|
30296
30465
|
}
|
|
30297
30466
|
clear(sessionID) {
|
|
30298
30467
|
this.sources.delete(sessionID);
|
|
30468
|
+
this.memorySources.delete(sessionID);
|
|
30299
30469
|
this.metadata.delete(sessionID);
|
|
30300
30470
|
this.metadataThrough.delete(sessionID);
|
|
30301
30471
|
this.metadataAfter.delete(sessionID);
|
|
@@ -30310,6 +30480,8 @@ ${cached}
|
|
|
30310
30480
|
if (this.stampMRU?.sessionID === sessionID)
|
|
30311
30481
|
this.stampMRU = undefined;
|
|
30312
30482
|
this.unprovenControls.delete(sessionID);
|
|
30483
|
+
this.reportedCaptureReplacements.delete(sessionID);
|
|
30484
|
+
this.reportedForeignRefreshes.delete(sessionID);
|
|
30313
30485
|
this.cancelLegacyUpgrade(sessionID);
|
|
30314
30486
|
this.cancelEditedAdmission(sessionID);
|
|
30315
30487
|
if (this.admissions)
|
|
@@ -34712,15 +34884,39 @@ function hasCurrentDocsProposal(projectDir) {
|
|
|
34712
34884
|
const hashes = docsBaseHashes(projectDir);
|
|
34713
34885
|
return listPendingDocsProposals(projectDir).some((path) => Object.entries(hashes).every(([name, value]) => readFileSync6(path, "utf8").includes(`Base SHA-256 ${name}: ${value}`)));
|
|
34714
34886
|
}
|
|
34715
|
-
function git(projectDir, args) {
|
|
34887
|
+
function git(projectDir, args, options) {
|
|
34716
34888
|
return execFileSync("git", args, {
|
|
34717
34889
|
windowsHide: true,
|
|
34718
34890
|
cwd: projectDir,
|
|
34719
34891
|
encoding: "utf8",
|
|
34720
34892
|
timeout: 1e4,
|
|
34721
|
-
maxBuffer: 2000000
|
|
34893
|
+
maxBuffer: 2000000,
|
|
34894
|
+
...options
|
|
34722
34895
|
}).trim();
|
|
34723
34896
|
}
|
|
34897
|
+
function gitExitStatus(error) {
|
|
34898
|
+
if (!error || typeof error !== "object")
|
|
34899
|
+
return;
|
|
34900
|
+
const { status, code, signal } = error;
|
|
34901
|
+
return typeof status === "number" && !code && !signal ? status : undefined;
|
|
34902
|
+
}
|
|
34903
|
+
function isCheckpointCommit(projectDir, anchor) {
|
|
34904
|
+
if (typeof anchor !== "string" || !/^[a-f0-9]{40}$/.test(anchor))
|
|
34905
|
+
return false;
|
|
34906
|
+
try {
|
|
34907
|
+
return git(projectDir, ["cat-file", "-t", anchor], { stdio: "pipe" }) === "commit";
|
|
34908
|
+
} catch (error) {
|
|
34909
|
+
if (gitExitStatus(error) === undefined)
|
|
34910
|
+
throw error;
|
|
34911
|
+
try {
|
|
34912
|
+
git(projectDir, ["cat-file", "-e", anchor], { stdio: "pipe" });
|
|
34913
|
+
} catch (existenceError) {
|
|
34914
|
+
if (gitExitStatus(existenceError) === 1)
|
|
34915
|
+
return false;
|
|
34916
|
+
}
|
|
34917
|
+
throw error;
|
|
34918
|
+
}
|
|
34919
|
+
}
|
|
34724
34920
|
function gitOutputPrefix(projectDir, args) {
|
|
34725
34921
|
try {
|
|
34726
34922
|
return git(projectDir, args);
|
|
@@ -34741,14 +34937,16 @@ function docsChangeSet(projectDir, storedAnchor) {
|
|
|
34741
34937
|
if (realpathSync(git(projectDir, ["rev-parse", "--show-toplevel"])) !== realpathSync(projectDir))
|
|
34742
34938
|
return null;
|
|
34743
34939
|
const head = git(projectDir, ["rev-parse", "HEAD"]);
|
|
34744
|
-
const recorded = Boolean(storedAnchor);
|
|
34745
34940
|
let anchor = storedAnchor;
|
|
34746
|
-
|
|
34747
|
-
|
|
34941
|
+
const recovered = anchor != null && !isCheckpointCommit(projectDir, anchor);
|
|
34942
|
+
if (recovered)
|
|
34943
|
+
anchor = undefined;
|
|
34944
|
+
const recorded = Boolean(anchor);
|
|
34748
34945
|
if (!anchor)
|
|
34749
34946
|
anchor = git(projectDir, ["log", "-1", "--format=%H", "--", ...FILES]);
|
|
34947
|
+
const emptyRecovery = recovered ? { head, text: "", unchanged: false, relevant: false, recoveredAnchor: anchor || null } : null;
|
|
34750
34948
|
if (!anchor)
|
|
34751
|
-
return
|
|
34949
|
+
return emptyRecovery;
|
|
34752
34950
|
if (recorded && anchor === head)
|
|
34753
34951
|
return { head, text: "", unchanged: true, relevant: false };
|
|
34754
34952
|
if (recorded) {
|
|
@@ -34850,7 +35048,7 @@ ${stat}`
|
|
|
34850
35048
|
...excluded.map((path) => `:(exclude)${path}`)
|
|
34851
35049
|
]);
|
|
34852
35050
|
if (!raw)
|
|
34853
|
-
return
|
|
35051
|
+
return emptyRecovery;
|
|
34854
35052
|
const commits = raw.split(/^commit /m);
|
|
34855
35053
|
const text = raw.slice(0, 24000);
|
|
34856
35054
|
return {
|
|
@@ -34859,7 +35057,8 @@ ${stat}`
|
|
|
34859
35057
|
relevant: true,
|
|
34860
35058
|
text: `${text}${raw.length > text.length ? `
|
|
34861
35059
|
[cut ${raw.length - text.length} bytes]` : ""}${commits.length > 201 ? `
|
|
34862
|
-
[cut commits beyond newest 200]` : ""}
|
|
35060
|
+
[cut commits beyond newest 200]` : ""}`,
|
|
35061
|
+
...recovered ? { recoveredAnchor: anchor } : {}
|
|
34863
35062
|
};
|
|
34864
35063
|
} catch (error) {
|
|
34865
35064
|
if (storedAnchor)
|
|
@@ -40707,6 +40906,9 @@ async function runAgenticTask(config, ctx, helpers) {
|
|
|
40707
40906
|
anchor = JSON.parse(storedAnchor ?? "null")?.head;
|
|
40708
40907
|
} catch {}
|
|
40709
40908
|
const changes = task === "maintain-docs" ? docsChangeSet(docsDir, anchor) : null;
|
|
40909
|
+
if (changes?.recoveredAnchor !== undefined) {
|
|
40910
|
+
log2("[dreamer] maintain-docs: stored checkpoint was no longer a commit; restarted from the docs files' last commit, if any");
|
|
40911
|
+
}
|
|
40710
40912
|
const existingDocs = task === "maintain-docs" ? {
|
|
40711
40913
|
architecture: existsSync7(`${docsDir}/ARCHITECTURE.md`),
|
|
40712
40914
|
structure: existsSync7(`${docsDir}/STRUCTURE.md`)
|
|
@@ -40776,7 +40978,7 @@ async function runAgenticTask(config, ctx, helpers) {
|
|
|
40776
40978
|
return { status: "completed", detail: reason };
|
|
40777
40979
|
}
|
|
40778
40980
|
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";
|
|
40981
|
+
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
40982
|
helpers.recordRun("completed", null, { progress: reason });
|
|
40781
40983
|
return {
|
|
40782
40984
|
status: "completed",
|
|
@@ -40787,7 +40989,15 @@ async function runAgenticTask(config, ctx, helpers) {
|
|
|
40787
40989
|
if (task === "maintain-docs" && hasCurrentDocsProposal(docsDir)) {
|
|
40788
40990
|
const reason = "pending proposal matches current docs";
|
|
40789
40991
|
helpers.recordRun("completed", null, { progress: reason });
|
|
40790
|
-
return {
|
|
40992
|
+
return {
|
|
40993
|
+
status: "completed",
|
|
40994
|
+
detail: reason,
|
|
40995
|
+
...changes?.recoveredAnchor ? {
|
|
40996
|
+
schedulePatch: {
|
|
40997
|
+
taskStateJson: JSON.stringify({ head: changes.recoveredAnchor })
|
|
40998
|
+
}
|
|
40999
|
+
} : {}
|
|
41000
|
+
};
|
|
40791
41001
|
}
|
|
40792
41002
|
const curateChunks = curateMemories ? chunkCurateMemories(curateMemories, Math.max(4000, Math.floor(resolveRetrospectiveUsableInputTokens(config, deps) * 2))) : [];
|
|
40793
41003
|
const batches = task === "curate" ? curateChunks : [{ memories: [], crossChunkCandidates: [] }];
|
|
@@ -42946,7 +43156,10 @@ class V2RevertMessageCleanup {
|
|
|
42946
43156
|
sessionId: sessionID,
|
|
42947
43157
|
isInHostStore: (id) => source.sequenceForId(sessionID, id) !== undefined,
|
|
42948
43158
|
removedByCommittedRevert: removed,
|
|
42949
|
-
onRetire: () =>
|
|
43159
|
+
onRetire: () => {
|
|
43160
|
+
clearRecompStaging(db, sessionID);
|
|
43161
|
+
return;
|
|
43162
|
+
}
|
|
42950
43163
|
});
|
|
42951
43164
|
if (result.kind !== "unresolved") {
|
|
42952
43165
|
this.pendingHistory = this.pendingHistory.filter((proof) => proof.sessionID !== sessionID);
|
|
@@ -43240,6 +43453,7 @@ function hasRequiredSessionAPI(session) {
|
|
|
43240
43453
|
import { randomUUID as randomUUID6 } from "node:crypto";
|
|
43241
43454
|
import { existsSync as existsSync8 } from "node:fs";
|
|
43242
43455
|
var LEASE_TTL_MS = 10 * 60 * 1000;
|
|
43456
|
+
var DEAD_DIRECTORY_RECHECK_MS = 24 * 60 * 60 * 1000;
|
|
43243
43457
|
var SESSION_PAGE_SIZE = 100;
|
|
43244
43458
|
var SESSION_QUERY_CHUNK_SIZE = 250;
|
|
43245
43459
|
var YIELD_EVERY_PROCESSED_SESSIONS = 25;
|
|
@@ -43283,13 +43497,27 @@ function withImmediateTransaction(db, fn) {
|
|
|
43283
43497
|
function defaultYieldFn() {
|
|
43284
43498
|
return new Promise((resolve) => setTimeout(resolve, 0));
|
|
43285
43499
|
}
|
|
43500
|
+
function readBackfillLease(db, harness) {
|
|
43501
|
+
return db.prepare(`SELECT status, lease_expires_at
|
|
43502
|
+
FROM session_project_backfill_state
|
|
43503
|
+
WHERE harness = ?`).get(harness);
|
|
43504
|
+
}
|
|
43505
|
+
function isCompletedAndNotDue(lease, now) {
|
|
43506
|
+
return lease?.status === "completed" && (lease.lease_expires_at === null || lease.lease_expires_at > now);
|
|
43507
|
+
}
|
|
43286
43508
|
function acquireBackfillLease(db, harness, holderId, now) {
|
|
43509
|
+
try {
|
|
43510
|
+
if (isCompletedAndNotDue(readBackfillLease(db, harness), now))
|
|
43511
|
+
return "already_completed";
|
|
43512
|
+
} catch (error) {
|
|
43513
|
+
if (!(error instanceof Error) || error.message !== "no such table: session_project_backfill_state") {
|
|
43514
|
+
throw error;
|
|
43515
|
+
}
|
|
43516
|
+
}
|
|
43287
43517
|
ensureBackfillStateTable(db);
|
|
43288
43518
|
return withImmediateTransaction(db, () => {
|
|
43289
|
-
const current = db
|
|
43290
|
-
|
|
43291
|
-
WHERE harness = ?`).get(harness);
|
|
43292
|
-
if (current?.status === "completed")
|
|
43519
|
+
const current = readBackfillLease(db, harness);
|
|
43520
|
+
if (isCompletedAndNotDue(current, now))
|
|
43293
43521
|
return "already_completed";
|
|
43294
43522
|
if (current?.status === "running" && current.lease_expires_at !== null && current.lease_expires_at > now) {
|
|
43295
43523
|
return "blocked_by_lease";
|
|
@@ -43318,11 +43546,11 @@ function renewBackfillLease(db, harness, holderId, now) {
|
|
|
43318
43546
|
SET lease_expires_at = ?
|
|
43319
43547
|
WHERE harness = ? AND status = 'running' AND holder_id = ?`).run(now + LEASE_TTL_MS, harness, holderId).changes === 1;
|
|
43320
43548
|
}
|
|
43321
|
-
function markBackfillCompleted(db, harness, holderId, now) {
|
|
43549
|
+
function markBackfillCompleted(db, harness, holderId, now, recheckAt) {
|
|
43322
43550
|
ensureBackfillStateTable(db);
|
|
43323
43551
|
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;
|
|
43552
|
+
SET status = 'completed', lease_expires_at = ?, completed_at = ?
|
|
43553
|
+
WHERE harness = ? AND status = 'running' AND holder_id = ?`).run(recheckAt, now, harness, holderId).changes === 1;
|
|
43326
43554
|
}
|
|
43327
43555
|
function markBackfillRetryPending(db, harness, holderId, now) {
|
|
43328
43556
|
ensureBackfillStateTable(db);
|
|
@@ -43365,9 +43593,10 @@ function createPageReader(source) {
|
|
|
43365
43593
|
if (typeof source === "function") {
|
|
43366
43594
|
return async (afterSessionId, limit) => source(afterSessionId, limit);
|
|
43367
43595
|
}
|
|
43368
|
-
|
|
43596
|
+
let sessions;
|
|
43369
43597
|
let offset = 0;
|
|
43370
43598
|
return async (_afterSessionId, limit) => {
|
|
43599
|
+
sessions ??= dedupeSessions(source);
|
|
43371
43600
|
const page = sessions.slice(offset, offset + limit);
|
|
43372
43601
|
offset += page.length;
|
|
43373
43602
|
return page;
|
|
@@ -43383,7 +43612,6 @@ async function runSessionProjectBackfillPass(db, source, options = {}) {
|
|
|
43383
43612
|
const resolveIdentity = options.resolveIdentity ?? ((directory) => resolveProjectIdentityForSession(directory, options.allowHomeProject));
|
|
43384
43613
|
const yieldFn = options.yieldFn ?? defaultYieldFn;
|
|
43385
43614
|
const holderId = options.holderId ?? randomUUID6();
|
|
43386
|
-
const readPage = createPageReader(source);
|
|
43387
43615
|
const result = {
|
|
43388
43616
|
status: "completed",
|
|
43389
43617
|
totalSessions: 0,
|
|
@@ -43394,13 +43622,15 @@ async function runSessionProjectBackfillPass(db, source, options = {}) {
|
|
|
43394
43622
|
skippedEmptyDirectories: 0,
|
|
43395
43623
|
durationMs: 0
|
|
43396
43624
|
};
|
|
43397
|
-
const
|
|
43625
|
+
const baseLeaseKey = options.leaseKey ?? harness;
|
|
43626
|
+
const leaseKey = options.allowHomeProject ? `${baseLeaseKey}:allow-home-project` : baseLeaseKey;
|
|
43398
43627
|
const leaseStatus = acquireBackfillLease(db, leaseKey, holderId, now());
|
|
43399
43628
|
if (leaseStatus !== "acquired") {
|
|
43400
43629
|
result.status = leaseStatus;
|
|
43401
43630
|
result.durationMs = performance.now() - startedAt;
|
|
43402
43631
|
return result;
|
|
43403
43632
|
}
|
|
43633
|
+
const readPage = createPageReader(source);
|
|
43404
43634
|
const finishWithLostLease = () => {
|
|
43405
43635
|
result.status = "lost_lease";
|
|
43406
43636
|
result.durationMs = performance.now() - startedAt;
|
|
@@ -43492,13 +43722,9 @@ async function runSessionProjectBackfillPass(db, source, options = {}) {
|
|
|
43492
43722
|
if (sourcePage.length < SESSION_PAGE_SIZE)
|
|
43493
43723
|
break;
|
|
43494
43724
|
}
|
|
43495
|
-
const
|
|
43496
|
-
|
|
43497
|
-
|
|
43498
|
-
return finishWithLostLease();
|
|
43499
|
-
}
|
|
43500
|
-
result.status = "retry_pending";
|
|
43501
|
-
} else if (!markBackfillCompleted(db, leaseKey, holderId, now())) {
|
|
43725
|
+
const completedAt = now();
|
|
43726
|
+
const recheckAt = result.skippedDeadDirectories > 0 ? completedAt + DEAD_DIRECTORY_RECHECK_MS : null;
|
|
43727
|
+
if (!markBackfillCompleted(db, leaseKey, holderId, completedAt, recheckAt)) {
|
|
43502
43728
|
return finishWithLostLease();
|
|
43503
43729
|
}
|
|
43504
43730
|
result.durationMs = performance.now() - startedAt;
|
|
@@ -55472,10 +55698,11 @@ function createCtxExpandTool(deps) {
|
|
|
55472
55698
|
}
|
|
55473
55699
|
const { start, end, verbose } = mode;
|
|
55474
55700
|
const lastCompartmentEnd = getLastCompartmentEndMessage(deps.db, sessionId);
|
|
55475
|
-
|
|
55476
|
-
|
|
55477
|
-
|
|
55478
|
-
const
|
|
55701
|
+
const refusal = unresolvedLiveTailRefusal2(deps.db, sessionId, start, end, lastCompartmentEnd);
|
|
55702
|
+
if (refusal)
|
|
55703
|
+
return refusal;
|
|
55704
|
+
const liveTailAfter = lastCompartmentEnd >= 0 && start > lastCompartmentEnd ? lastCompartmentEnd : undefined;
|
|
55705
|
+
const effectiveEnd = lastCompartmentEnd >= start ? Math.min(end, lastCompartmentEnd) : end;
|
|
55479
55706
|
if (verbose && source) {
|
|
55480
55707
|
if (!path)
|
|
55481
55708
|
throw new Error("Search archive worker unavailable: private archive has no off-thread source");
|
|
@@ -55484,13 +55711,14 @@ function createCtxExpandTool(deps) {
|
|
|
55484
55711
|
start,
|
|
55485
55712
|
end: effectiveEnd,
|
|
55486
55713
|
tokenBudget: CTX_EXPAND_TOKEN_BUDGET,
|
|
55487
|
-
expandTools: deps.expandTools
|
|
55714
|
+
expandTools: deps.expandTools,
|
|
55715
|
+
liveTailAfter
|
|
55488
55716
|
});
|
|
55489
55717
|
if (text === null)
|
|
55490
55718
|
throw new Error("Search archive worker unavailable: unexpected verbose reply");
|
|
55491
55719
|
return text;
|
|
55492
55720
|
}
|
|
55493
|
-
const archived = await renderSearchArchiveOffThread2(deps.db, sessionId, start, effectiveEnd, CTX_EXPAND_TOKEN_BUDGET);
|
|
55721
|
+
const archived = await renderSearchArchiveOffThread2(deps.db, sessionId, start, effectiveEnd, CTX_EXPAND_TOKEN_BUDGET, false, liveTailAfter);
|
|
55494
55722
|
if (archived)
|
|
55495
55723
|
return archived;
|
|
55496
55724
|
if (verbose) {
|
|
@@ -57279,8 +57507,7 @@ function createCtxSearchTool(deps) {
|
|
|
57279
57507
|
return `Error: ${error.message}`;
|
|
57280
57508
|
throw error;
|
|
57281
57509
|
}
|
|
57282
|
-
const
|
|
57283
|
-
const messageOrdinalCutoff = lastCompartmentEnd >= 0 ? lastCompartmentEnd : 0;
|
|
57510
|
+
const messageOrdinalCutoff = Math.max(0, getLastCompartmentEndMessage(deps.db, toolContext.sessionID));
|
|
57284
57511
|
const visibleMemoryIds = getVisibleMemoryIds(deps.db, toolContext.sessionID);
|
|
57285
57512
|
const diagnostics = createUnifiedSearchDiagnostics2();
|
|
57286
57513
|
const projectPath = deps.resolveProjectPath(toolContext.directory);
|
|
@@ -57316,6 +57543,7 @@ function createCtxSearchTool(deps) {
|
|
|
57316
57543
|
isEmbeddingRuntimeEnabled: () => embeddingEnabled === true,
|
|
57317
57544
|
readMessages: deps.readMessages,
|
|
57318
57545
|
maxMessageOrdinal: messageOrdinalCutoff,
|
|
57546
|
+
includeDroppedTailMessages: true,
|
|
57319
57547
|
gitCommitsEnabled,
|
|
57320
57548
|
sources: normalizeSources(args.sources),
|
|
57321
57549
|
visibleMemoryIds,
|
|
@@ -57923,7 +58151,10 @@ function checkHistoryBoundary(db, reader, sessionID) {
|
|
|
57923
58151
|
db,
|
|
57924
58152
|
sessionId: sessionID,
|
|
57925
58153
|
isInHostStore: (messageId) => storeHasSession ? reader.sequenceForId(sessionID, messageId) !== undefined : null,
|
|
57926
|
-
onRetire: () =>
|
|
58154
|
+
onRetire: () => {
|
|
58155
|
+
clearRecompStaging(db, sessionID);
|
|
58156
|
+
return;
|
|
58157
|
+
}
|
|
57927
58158
|
});
|
|
57928
58159
|
} catch (error) {
|
|
57929
58160
|
sessionLog2(sessionID, "history boundary check failed; continuing without repair", error);
|
|
@@ -59657,11 +59888,12 @@ async function setupContext(context, config, nativeRemove, compactionOff, cleanu
|
|
|
59657
59888
|
let recordedHead;
|
|
59658
59889
|
let upgradeCheckpointSequence;
|
|
59659
59890
|
let restoredFirstRow;
|
|
59891
|
+
let draftSourceIdentity;
|
|
59660
59892
|
try {
|
|
59661
59893
|
syntheticIDs = await readSyntheticProvenance(reader, draft.messages);
|
|
59662
59894
|
const cut = reader.latestCompaction(draft.sessionID);
|
|
59663
59895
|
if (nativeFoldReplay)
|
|
59664
|
-
await nativeFoldReplay.observeSource(draft.sessionID, reader);
|
|
59896
|
+
draftSourceIdentity = await nativeFoldReplay.observeSource(draft.sessionID, reader);
|
|
59665
59897
|
const boundaryRepair = !rustModeModuleClient && db && !compactionOff ? revertMessageCleanup.retireProvenHistory(db, draft.sessionID, reader) ?? checkHistoryBoundary(db, reader, draft.sessionID) : undefined;
|
|
59666
59898
|
if (boundaryRepair?.kind === "repaired" || boundaryRepair?.kind === "baseline-reset") {
|
|
59667
59899
|
historyRefreshSessions.add(draft.sessionID);
|
|
@@ -59701,13 +59933,14 @@ async function setupContext(context, config, nativeRemove, compactionOff, cleanu
|
|
|
59701
59933
|
}
|
|
59702
59934
|
}
|
|
59703
59935
|
let nativeRestored = localCut ? nativeFoldReplay?.legacyUpgradeInput(draft.sessionID, draft.model) : undefined;
|
|
59704
|
-
if (nativeRestored === undefined && cut && nativeFoldReplay && await nativeFoldReplay.admits(draft.sessionID, cut, reader)) {
|
|
59936
|
+
if (nativeRestored === undefined && cut && nativeFoldReplay && draftSourceIdentity !== undefined && await nativeFoldReplay.admits(draft.sessionID, cut, reader)) {
|
|
59937
|
+
const passSource = draftSourceIdentity;
|
|
59705
59938
|
try {
|
|
59706
|
-
nativeRestored = await nativeFoldReplay.restore(draft.sessionID, cut, `${draft.model.providerID}/${draft.model.id}`, { bounded: !rustModeModuleClient });
|
|
59939
|
+
nativeRestored = await nativeFoldReplay.restore(draft.sessionID, cut, `${draft.model.providerID}/${draft.model.id}`, passSource, { bounded: !rustModeModuleClient });
|
|
59707
59940
|
} catch (error) {
|
|
59708
59941
|
nativeFoldReplay.invalidate(draft.sessionID, true);
|
|
59709
59942
|
sessionLog2(draft.sessionID, "v2 host fold: cache unavailable; restoring host rows", error);
|
|
59710
|
-
nativeRestored = await nativeFoldReplay.restoreRead(draft.sessionID, cut, draft.model);
|
|
59943
|
+
nativeRestored = await nativeFoldReplay.restoreRead(draft.sessionID, cut, draft.model, passSource);
|
|
59711
59944
|
}
|
|
59712
59945
|
if (nativeRestored)
|
|
59713
59946
|
pass.nativeReplayCheckpointID = cut.id;
|
|
@@ -59856,8 +60089,8 @@ async function setupContext(context, config, nativeRemove, compactionOff, cleanu
|
|
|
59856
60089
|
const stripped = await folds.stripRecentContext(draft.sessionID, checkpointID);
|
|
59857
60090
|
if (stripped?.rendered) {
|
|
59858
60091
|
checkpoint = structuredClone(stripped.rendered);
|
|
59859
|
-
if (upgradeCheckpointSequence !== undefined)
|
|
59860
|
-
await nativeFoldReplay?.checkpointCovered(draft.sessionID, checkpointID);
|
|
60092
|
+
if (upgradeCheckpointSequence !== undefined && draftSourceIdentity !== undefined)
|
|
60093
|
+
await nativeFoldReplay?.checkpointCovered(draft.sessionID, checkpointID, draftSourceIdentity);
|
|
59861
60094
|
}
|
|
59862
60095
|
}
|
|
59863
60096
|
}
|
|
@@ -59875,11 +60108,11 @@ async function setupContext(context, config, nativeRemove, compactionOff, cleanu
|
|
|
59875
60108
|
} : null;
|
|
59876
60109
|
const servedHead = head && structuredClone(head);
|
|
59877
60110
|
const headApplied = head ? applyCheckpointHead(draft, head) : false;
|
|
59878
|
-
if (nativeMessages && (!checkpoint || upgradeCheckpointSequence !== undefined)) {
|
|
60111
|
+
if (nativeMessages && draftSourceIdentity !== undefined && (!checkpoint || upgradeCheckpointSequence !== undefined)) {
|
|
59879
60112
|
try {
|
|
59880
60113
|
const state = db && getOrCreateSessionMeta(db, draft.sessionID);
|
|
59881
60114
|
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);
|
|
60115
|
+
await nativeFoldReplay?.capture(draft, nativeMessages, draftSourceIdentity, boundary?.id && state?.cachedM0Bytes ? { id: boundary.id, summary: state.cachedM0Bytes.toString("utf8") } : undefined, restoredFirstRow);
|
|
59883
60116
|
} catch (error) {
|
|
59884
60117
|
nativeFoldReplay?.invalidate(draft.sessionID, true);
|
|
59885
60118
|
sessionLog2(draft.sessionID, "v2 host fold: optional capture unavailable", error);
|