@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
|
@@ -48,7 +48,7 @@ import {
|
|
|
48
48
|
clearNoteNudgeTriggerOnly,
|
|
49
49
|
nonNarrativeStoredGapRanges,
|
|
50
50
|
getActiveCompartmentRun
|
|
51
|
-
} from "./index-
|
|
51
|
+
} from "./index-2gewejcz.js";
|
|
52
52
|
import"./index-sd3egckz.js";
|
|
53
53
|
import {
|
|
54
54
|
getHarness2
|
|
@@ -143,7 +143,7 @@ import {
|
|
|
143
143
|
applyJsonSchemaParameterDescriptions,
|
|
144
144
|
MagicContextRpcServer,
|
|
145
145
|
subagentTemperature
|
|
146
|
-
} from "./index-
|
|
146
|
+
} from "./index-jm62g83a.js";
|
|
147
147
|
import {
|
|
148
148
|
invalidateAutoEmbedSession,
|
|
149
149
|
clearEmbedSessionState
|
|
@@ -153,7 +153,7 @@ import {
|
|
|
153
153
|
preloadTokenizer,
|
|
154
154
|
estimateTokens
|
|
155
155
|
} from "./index-s7460efs.js";
|
|
156
|
-
import"./index-
|
|
156
|
+
import"./index-j7n64sg4.js";
|
|
157
157
|
import {
|
|
158
158
|
inRootAsyncContext2,
|
|
159
159
|
withSqliteTransformPass2,
|
|
@@ -168,13 +168,15 @@ import"./index-q7q6qp1f.js";
|
|
|
168
168
|
import"./index-s32f8y67.js";
|
|
169
169
|
import {
|
|
170
170
|
deleteChunkEmbedBackoffForSession2
|
|
171
|
-
} from "./index-
|
|
171
|
+
} from "./index-ejgp0z9p.js";
|
|
172
172
|
import {
|
|
173
173
|
advanceSessionActivity,
|
|
174
174
|
backfillSessionActivity,
|
|
175
175
|
acquireCompartmentLease,
|
|
176
176
|
releaseCompartmentLeaseBestEffort,
|
|
177
177
|
isCompartmentLeaseHeld,
|
|
178
|
+
readSummaryCoverage,
|
|
179
|
+
markHistoryGapAfterCoverageChange,
|
|
178
180
|
queueM0Mutation,
|
|
179
181
|
getLastCompartmentEndMessageId,
|
|
180
182
|
clearRecompStaging,
|
|
@@ -206,8 +208,8 @@ import {
|
|
|
206
208
|
getSlot,
|
|
207
209
|
dropSlot,
|
|
208
210
|
copySessionStateForClone
|
|
209
|
-
} from "./index-
|
|
210
|
-
import"./index-
|
|
211
|
+
} from "./index-pc49a7zt.js";
|
|
212
|
+
import"./index-esacb9d0.js";
|
|
211
213
|
import {
|
|
212
214
|
stripPersistedAssistantText,
|
|
213
215
|
currentReclaimableToolOutputCount,
|
|
@@ -250,7 +252,7 @@ import {
|
|
|
250
252
|
estimateFinalWireInputTokens,
|
|
251
253
|
getMaxTagNumberBySession2,
|
|
252
254
|
getTagsBySession2
|
|
253
|
-
} from "./index-
|
|
255
|
+
} from "./index-zk6gtf43.js";
|
|
254
256
|
import {
|
|
255
257
|
BoundedSessionMap,
|
|
256
258
|
getTableColumnNames,
|
|
@@ -293,10 +295,10 @@ import {
|
|
|
293
295
|
cleanUserText2,
|
|
294
296
|
readRawSessionMessageIdOrdinalsForRange2,
|
|
295
297
|
readRawSessionMessageOrdinalById2
|
|
296
|
-
} from "./index-
|
|
298
|
+
} from "./index-7r11k4xr.js";
|
|
297
299
|
import {
|
|
298
300
|
scheduleClearAndReindex
|
|
299
|
-
} from "./index-
|
|
301
|
+
} from "./index-47hst5me.js";
|
|
300
302
|
import {
|
|
301
303
|
startBootDeadline,
|
|
302
304
|
getSchemaFenceRejection,
|
|
@@ -306,7 +308,7 @@ import {
|
|
|
306
308
|
openDatabaseAsync,
|
|
307
309
|
isDatabasePersisted,
|
|
308
310
|
getDatabasePersistenceError
|
|
309
|
-
} from "./index-
|
|
311
|
+
} from "./index-c81tggen.js";
|
|
310
312
|
import"./index-fr0wbhdn.js";
|
|
311
313
|
import"./index-jba6ny4m.js";
|
|
312
314
|
import {
|
|
@@ -314,7 +316,7 @@ import {
|
|
|
314
316
|
RAW_MESSAGE_TYPES2,
|
|
315
317
|
V2StoreReaderPool2,
|
|
316
318
|
V2StoreReader2
|
|
317
|
-
} from "./index-
|
|
319
|
+
} from "./index-tr4ep2ej.js";
|
|
318
320
|
import"./index-fb3zxn06.js";
|
|
319
321
|
import"./index-mjy2k9jr.js";
|
|
320
322
|
import {
|
|
@@ -335,20 +337,20 @@ import {
|
|
|
335
337
|
servedHeadChanged,
|
|
336
338
|
noteHostCheckpointCommit,
|
|
337
339
|
isSyntheticHeadMessage2
|
|
338
|
-
} from "./index-
|
|
340
|
+
} from "./index-3tmbvn0z.js";
|
|
339
341
|
import"./index-832w615x.js";
|
|
340
342
|
import"./index-qt1qqasc.js";
|
|
341
343
|
import {
|
|
342
344
|
retainProjectEmbedding2
|
|
343
|
-
} from "./index-
|
|
345
|
+
} from "./index-tedck05r.js";
|
|
344
346
|
import"./index-r4y0dczp.js";
|
|
345
347
|
import"./index-qjwpqvnf.js";
|
|
346
|
-
import"./index-
|
|
348
|
+
import"./index-xjaf9g90.js";
|
|
347
349
|
import {
|
|
348
350
|
renderUserFacingFailure,
|
|
349
351
|
userFacingFailureCode
|
|
350
|
-
} from "./index-
|
|
351
|
-
import"./index-
|
|
352
|
+
} from "./index-qmm8xpbc.js";
|
|
353
|
+
import"./index-3ywyr4zx.js";
|
|
352
354
|
import"./index-9emdjcb5.js";
|
|
353
355
|
import {
|
|
354
356
|
pushLiveNotification2,
|
|
@@ -357,8 +359,8 @@ import {
|
|
|
357
359
|
} from "./index-y14pawe1.js";
|
|
358
360
|
import"./index-e6ncz7a6.js";
|
|
359
361
|
import"./index-9ffntwyr.js";
|
|
360
|
-
import"./index-
|
|
361
|
-
import"./index-
|
|
362
|
+
import"./index-7skgrbsg.js";
|
|
363
|
+
import"./index-ewta5h87.js";
|
|
362
364
|
import"./index-cr483vx6.js";
|
|
363
365
|
import {
|
|
364
366
|
detectConflicts
|
|
@@ -388,12 +390,12 @@ import {
|
|
|
388
390
|
readV2RawMessagePagesForConversion2,
|
|
389
391
|
createV2RawMessageReader2,
|
|
390
392
|
createV2RawMessageProvider2
|
|
391
|
-
} from "./index-
|
|
393
|
+
} from "./index-tm799pq7.js";
|
|
392
394
|
import"./index-fmsr7v69.js";
|
|
393
|
-
import"./index-
|
|
394
|
-
import"./index-
|
|
395
|
-
import"./index-
|
|
396
|
-
import"./index-
|
|
395
|
+
import"./index-yzzxb5e1.js";
|
|
396
|
+
import"./index-xe34pwb6.js";
|
|
397
|
+
import"./index-7dzaamqg.js";
|
|
398
|
+
import"./index-wqwjawer.js";
|
|
397
399
|
import {
|
|
398
400
|
markHostInstructionRow,
|
|
399
401
|
hostInstructionRow,
|
|
@@ -474,11 +476,14 @@ function dropCompartmentsAfter(db, sessionId, anchor, holderId, activeBranch = f
|
|
|
474
476
|
return null;
|
|
475
477
|
}
|
|
476
478
|
const dropped = db.prepare("SELECT id, sequence FROM compartments WHERE session_id = ? AND sequence > ? ORDER BY sequence").all(sessionId, anchor?.sequence ?? -1);
|
|
477
|
-
|
|
479
|
+
const previousCoverage = readSummaryCoverage(db, sessionId);
|
|
480
|
+
const hostQueuedRecovery = onRetire?.() === true;
|
|
478
481
|
const deleteEmbeddings = db.prepare("DELETE FROM compartment_chunk_embeddings WHERE compartment_id = ?");
|
|
479
482
|
for (const row of dropped)
|
|
480
483
|
deleteEmbeddings.run(row.id);
|
|
481
484
|
db.prepare("DELETE FROM compartments WHERE session_id = ? AND sequence > ?").run(sessionId, anchor?.sequence ?? -1);
|
|
485
|
+
if (!hostQueuedRecovery)
|
|
486
|
+
markHistoryGapAfterCoverageChange(db, sessionId, previousCoverage);
|
|
482
487
|
db.prepare("DELETE FROM compression_depth WHERE session_id = ? AND message_ordinal > ?").run(sessionId, anchor?.endMessage ?? 0);
|
|
483
488
|
if (activeBranch) {
|
|
484
489
|
db.prepare("UPDATE session_meta SET prior_boundary_ordinal = ? WHERE session_id = ?").run((anchor?.endMessage ?? 0) + 1, sessionId);
|
|
@@ -1463,6 +1468,9 @@ class NativeFoldCache {
|
|
|
1463
1468
|
const kept = this.nativeRows.get(sessionID);
|
|
1464
1469
|
return ids.every((id) => kept?.has(id));
|
|
1465
1470
|
}
|
|
1471
|
+
holdsState(sessionID) {
|
|
1472
|
+
return this.tails.has(sessionID) || (this.nativeRows.get(sessionID)?.size ?? 0) > 0;
|
|
1473
|
+
}
|
|
1466
1474
|
rows(sessionID, after, through) {
|
|
1467
1475
|
if (this.retention.has(sessionID))
|
|
1468
1476
|
this.touch(sessionID);
|
|
@@ -2363,8 +2371,11 @@ class NativeFoldReplay {
|
|
|
2363
2371
|
stampMRU;
|
|
2364
2372
|
loaded = new Map;
|
|
2365
2373
|
sources = new Map;
|
|
2374
|
+
memorySources = new Map;
|
|
2366
2375
|
staleHeads = new Set;
|
|
2367
2376
|
unprovenControls = new Set;
|
|
2377
|
+
reportedCaptureReplacements = new Set;
|
|
2378
|
+
reportedForeignRefreshes = new Set;
|
|
2368
2379
|
editedAdmissions = new Map;
|
|
2369
2380
|
legacyUpgrades = new Map;
|
|
2370
2381
|
constructor(storage, openReader, admissions, options = {}) {
|
|
@@ -2388,6 +2399,7 @@ class NativeFoldReplay {
|
|
|
2388
2399
|
await this.forget(sessionID);
|
|
2389
2400
|
this.sources.set(sessionID, source);
|
|
2390
2401
|
this.account(sessionID);
|
|
2402
|
+
return source;
|
|
2391
2403
|
}
|
|
2392
2404
|
onEvent(event) {
|
|
2393
2405
|
const sessionID = event.data?.sessionID;
|
|
@@ -2460,6 +2472,18 @@ class NativeFoldReplay {
|
|
|
2460
2472
|
this.options.log?.(sessionID, `v3 host fold: ${reason}`);
|
|
2461
2473
|
} catch {}
|
|
2462
2474
|
}
|
|
2475
|
+
reportOnce(sessionID, reported, message) {
|
|
2476
|
+
if (reported.has(sessionID))
|
|
2477
|
+
return;
|
|
2478
|
+
reported.add(sessionID);
|
|
2479
|
+
const sessionLog = this.options.log;
|
|
2480
|
+
try {
|
|
2481
|
+
sessionLog?.(sessionID, message);
|
|
2482
|
+
} catch {}
|
|
2483
|
+
}
|
|
2484
|
+
reportCaptureReplacement(sessionID) {
|
|
2485
|
+
this.reportOnce(sessionID, this.reportedCaptureReplacements, "v3 host fold: capture skipped: host database file changed between readers");
|
|
2486
|
+
}
|
|
2463
2487
|
historyCoverage(sessionID, reader) {
|
|
2464
2488
|
if (!this.options.rendersHistory?.(sessionID))
|
|
2465
2489
|
return;
|
|
@@ -2476,13 +2500,15 @@ class NativeFoldReplay {
|
|
|
2476
2500
|
return false;
|
|
2477
2501
|
}
|
|
2478
2502
|
async floorState(sessionID, reader, boundary, served, preferCapture = false) {
|
|
2503
|
+
const source = reader.hostIdentity();
|
|
2504
|
+
await this.fenceMemory(sessionID, source);
|
|
2479
2505
|
const coverage = this.historyCoverage(sessionID, reader);
|
|
2480
2506
|
const retained = this.tail(sessionID)?.replay;
|
|
2481
2507
|
const controlsKnown = (replay) => replay.controls.every((control) => !control.after || reader.sequenceForId(sessionID, control.after) !== undefined);
|
|
2482
2508
|
const memory = retained && validReplayState(retained) && controlsKnown(retained) && validFloor(reader, sessionID, retained.floor) && this.floorCovered(sessionID, retained.floor, coverage, retained) ? retained : undefined;
|
|
2483
2509
|
const cut = reader.latestCompaction(sessionID);
|
|
2484
2510
|
const saved = await this.readV3(sessionID);
|
|
2485
|
-
const durable = saved && saved.proof.sourceDigest === foldDigest(
|
|
2511
|
+
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;
|
|
2486
2512
|
const marker = importedFloor(reader, sessionID, cut?.seq);
|
|
2487
2513
|
const imported = marker && this.floorCovered(sessionID, marker, coverage) ? marker : undefined;
|
|
2488
2514
|
const capturedRecord = await this.readCapturedReplay(sessionID, reader);
|
|
@@ -2542,11 +2568,11 @@ class NativeFoldReplay {
|
|
|
2542
2568
|
return;
|
|
2543
2569
|
}
|
|
2544
2570
|
}
|
|
2545
|
-
async saveCapturedReplay(sessionID, replay, reader) {
|
|
2571
|
+
async saveCapturedReplay(sessionID, replay, reader, sourceDigest) {
|
|
2546
2572
|
const value = {
|
|
2547
2573
|
version: 3,
|
|
2548
2574
|
sessionID,
|
|
2549
|
-
sourceDigest
|
|
2575
|
+
sourceDigest,
|
|
2550
2576
|
through: reader.latestSequence(sessionID),
|
|
2551
2577
|
replay
|
|
2552
2578
|
};
|
|
@@ -2576,11 +2602,33 @@ class NativeFoldReplay {
|
|
|
2576
2602
|
${cached}
|
|
2577
2603
|
</summary>`)))) ? cached : undefined;
|
|
2578
2604
|
}
|
|
2579
|
-
async retainReplay(sessionID, replay, model, sourceSeq) {
|
|
2605
|
+
async retainReplay(sessionID, replay, model, sourceSeq, source) {
|
|
2606
|
+
await this.fenceMemory(sessionID, source);
|
|
2580
2607
|
const tail = this.tail(sessionID) ?? { model, sourceSeq };
|
|
2581
2608
|
await this.storage.saveTail(sessionID, JSON.stringify({ ...tail, replay }), []);
|
|
2582
2609
|
if (!this.storage.tail(sessionID))
|
|
2583
2610
|
await this.storage.saveTail(sessionID, JSON.stringify({ model, sourceSeq, replay }), []);
|
|
2611
|
+
this.memorySources.set(sessionID, source);
|
|
2612
|
+
}
|
|
2613
|
+
async fenceMemory(sessionID, source) {
|
|
2614
|
+
const recorded = this.memorySources.get(sessionID);
|
|
2615
|
+
if (recorded === source)
|
|
2616
|
+
return;
|
|
2617
|
+
if (recorded === undefined && !this.storage.holdsState(sessionID) && !this.metadata.has(sessionID))
|
|
2618
|
+
return;
|
|
2619
|
+
await this.discardCapture(sessionID);
|
|
2620
|
+
this.reportCaptureReplacement(sessionID);
|
|
2621
|
+
}
|
|
2622
|
+
async discardCapture(sessionID) {
|
|
2623
|
+
if (this.stampMRU?.sessionID === sessionID)
|
|
2624
|
+
this.stampMRU = undefined;
|
|
2625
|
+
const source = this.sources.get(sessionID);
|
|
2626
|
+
const forgotten = this.storage.forget(sessionID);
|
|
2627
|
+
if (source !== undefined) {
|
|
2628
|
+
this.sources.set(sessionID, source);
|
|
2629
|
+
this.account(sessionID);
|
|
2630
|
+
}
|
|
2631
|
+
await forgotten;
|
|
2584
2632
|
}
|
|
2585
2633
|
async canFold(sessionID, reader) {
|
|
2586
2634
|
if (this.options.protocol !== 3) {
|
|
@@ -2681,7 +2729,7 @@ ${cached}
|
|
|
2681
2729
|
}
|
|
2682
2730
|
};
|
|
2683
2731
|
this.legacyUpgrades.set(draft.sessionID, { value, rows, started });
|
|
2684
|
-
await this.retainReplay(draft.sessionID, replay, `${draft.model.providerID}/${draft.model.id}`, cut.seq - 1);
|
|
2732
|
+
await this.retainReplay(draft.sessionID, replay, `${draft.model.providerID}/${draft.model.id}`, cut.seq - 1, reader.hostIdentity());
|
|
2685
2733
|
return true;
|
|
2686
2734
|
}
|
|
2687
2735
|
legacyUpgradeInput(sessionID, model) {
|
|
@@ -2689,8 +2737,16 @@ ${cached}
|
|
|
2689
2737
|
if (!pending)
|
|
2690
2738
|
return;
|
|
2691
2739
|
let reader;
|
|
2740
|
+
const open = () => {
|
|
2741
|
+
const opened = this.openReader(sessionID);
|
|
2742
|
+
if (foldDigest(opened.hostIdentity()) !== pending.value.proof.sourceDigest) {
|
|
2743
|
+
opened.close();
|
|
2744
|
+
throw new NativeReplayUnavailable("Host database file changed during upgrade");
|
|
2745
|
+
}
|
|
2746
|
+
return opened;
|
|
2747
|
+
};
|
|
2692
2748
|
const blobs = {
|
|
2693
|
-
mediaBlob: (hash) => (reader ??=
|
|
2749
|
+
mediaBlob: (hash) => (reader ??= open()).mediaBlob(hash)
|
|
2694
2750
|
};
|
|
2695
2751
|
try {
|
|
2696
2752
|
return pending.rows.filter((row) => row.seq > pending.value.replay.floor.after).flatMap((row) => {
|
|
@@ -2710,6 +2766,11 @@ ${cached}
|
|
|
2710
2766
|
const admissions = this.admissions;
|
|
2711
2767
|
if (!pending || !admissions)
|
|
2712
2768
|
return false;
|
|
2769
|
+
const recorded = this.memorySources.get(sessionID);
|
|
2770
|
+
if (recorded === undefined ? this.storage.holdsState(sessionID) || this.metadata.has(sessionID) : foldDigest(recorded) !== pending.value.proof.sourceDigest) {
|
|
2771
|
+
await this.discardCapture(sessionID);
|
|
2772
|
+
this.reportCaptureReplacement(sessionID);
|
|
2773
|
+
}
|
|
2713
2774
|
const replay = this.tail(sessionID)?.replay ?? pending.value.replay;
|
|
2714
2775
|
if (replay.blocked)
|
|
2715
2776
|
return false;
|
|
@@ -2747,13 +2808,16 @@ ${cached}
|
|
|
2747
2808
|
stripCheckpointRecentContext(rendered, row.data.summary ?? "");
|
|
2748
2809
|
return { row, rendered, submitted: row.data.summary ?? "" };
|
|
2749
2810
|
}
|
|
2750
|
-
async checkpointCovered(sessionID, checkpointID) {
|
|
2811
|
+
async checkpointCovered(sessionID, checkpointID, sourceIdentity) {
|
|
2751
2812
|
const admissions = this.admissions;
|
|
2752
2813
|
if (!admissions)
|
|
2753
2814
|
return;
|
|
2815
|
+
await this.fenceMemory(sessionID, sourceIdentity);
|
|
2754
2816
|
const pending = this.legacyUpgrades.get(sessionID);
|
|
2755
|
-
const
|
|
2756
|
-
|
|
2817
|
+
const sourceDigest = foldDigest(sourceIdentity);
|
|
2818
|
+
const saved = await this.readV3(sessionID);
|
|
2819
|
+
const value = saved?.proof.sourceDigest === sourceDigest ? saved : pending?.value;
|
|
2820
|
+
if (value?.proof.sourceDigest !== sourceDigest || value.replay.floor.kind !== "host-checkpoint" || value.replay.floor.id !== checkpointID || value.replay.withoutRecentContext)
|
|
2757
2821
|
return;
|
|
2758
2822
|
value.replay.withoutRecentContext = true;
|
|
2759
2823
|
const payload = encodeAdmissionV3(value);
|
|
@@ -2764,7 +2828,7 @@ ${cached}
|
|
|
2764
2828
|
});
|
|
2765
2829
|
const tail = this.tail(sessionID);
|
|
2766
2830
|
if (tail)
|
|
2767
|
-
await this.retainReplay(sessionID, value.replay, tail.model, tail.sourceSeq);
|
|
2831
|
+
await this.retainReplay(sessionID, value.replay, tail.model, tail.sourceSeq, sourceIdentity);
|
|
2768
2832
|
}
|
|
2769
2833
|
async removeAdmission(key) {
|
|
2770
2834
|
if (this.admissions?.remove)
|
|
@@ -2782,7 +2846,8 @@ ${cached}
|
|
|
2782
2846
|
if (!saved || !isLocalCheckpoint(cut) || cut.session_id !== sessionID)
|
|
2783
2847
|
return false;
|
|
2784
2848
|
const proof = saved.proof;
|
|
2785
|
-
|
|
2849
|
+
const source = reader.hostIdentity();
|
|
2850
|
+
if (proof.sourceDigest !== foldDigest(source) || proof.admissionID !== cut.id || proof.summaryDigest !== foldDigest(cut.data.summary ?? "")) {
|
|
2786
2851
|
this.report(sessionID, "replay refused: invalid checkpoint floor or provenance");
|
|
2787
2852
|
return false;
|
|
2788
2853
|
}
|
|
@@ -2798,17 +2863,17 @@ ${cached}
|
|
|
2798
2863
|
this.editedAdmissions.set(sessionID, { original: saved, replay });
|
|
2799
2864
|
this.staleHeads.add(sessionID);
|
|
2800
2865
|
this.invalidate(sessionID);
|
|
2801
|
-
await this.retainReplay(sessionID, replay, this.tail(sessionID)?.model ?? "", cut.seq - 1);
|
|
2866
|
+
await this.retainReplay(sessionID, replay, this.tail(sessionID)?.model ?? "", cut.seq - 1, source);
|
|
2802
2867
|
return false;
|
|
2803
2868
|
}
|
|
2804
2869
|
if (!this.floorCovered(sessionID, replay.floor, this.historyCoverage(sessionID, reader), replay))
|
|
2805
2870
|
return false;
|
|
2806
|
-
await this.retainReplay(sessionID, saved.replay, this.tail(sessionID)?.model ?? "", cut.seq - 1);
|
|
2871
|
+
await this.retainReplay(sessionID, saved.replay, this.tail(sessionID)?.model ?? "", cut.seq - 1, source);
|
|
2807
2872
|
if (proof.historyDigest !== historyDigest(reader, sessionID, cut.seq - 1, saved.replay.floor.after)) {
|
|
2808
2873
|
this.staleHeads.add(sessionID);
|
|
2809
2874
|
this.invalidate(sessionID);
|
|
2810
2875
|
this.editedAdmissions.set(sessionID, { original: saved, replay });
|
|
2811
|
-
await this.retainReplay(sessionID, saved.replay, this.tail(sessionID)?.model ?? "", cut.seq - 1);
|
|
2876
|
+
await this.retainReplay(sessionID, saved.replay, this.tail(sessionID)?.model ?? "", cut.seq - 1, source);
|
|
2812
2877
|
return false;
|
|
2813
2878
|
}
|
|
2814
2879
|
await this.storage.supply(sessionID, cut.id, JSON.stringify({
|
|
@@ -2860,6 +2925,7 @@ ${cached}
|
|
|
2860
2925
|
return false;
|
|
2861
2926
|
const reader = this.openReader(sessionID);
|
|
2862
2927
|
try {
|
|
2928
|
+
await this.fenceMemory(sessionID, reader.hostIdentity());
|
|
2863
2929
|
const cut = reader.latestCompaction(sessionID);
|
|
2864
2930
|
const proof = pending.original.proof;
|
|
2865
2931
|
const replay = this.tail(sessionID)?.replay ?? pending.replay;
|
|
@@ -3064,14 +3130,23 @@ ${cached}
|
|
|
3064
3130
|
}
|
|
3065
3131
|
return [...grouped].map(([row, messages]) => this.record(row, messages));
|
|
3066
3132
|
}
|
|
3067
|
-
async capture(draft, native, boundary, restoredFirstRow) {
|
|
3133
|
+
async capture(draft, native, draftSourceIdentity, boundary, restoredFirstRow) {
|
|
3068
3134
|
const release = this.storage.hold(draft.sessionID);
|
|
3069
3135
|
let replay;
|
|
3136
|
+
let capturedIdentity;
|
|
3070
3137
|
let sourceSeq = -1;
|
|
3071
3138
|
try {
|
|
3072
3139
|
rememberHostMedia(native);
|
|
3073
3140
|
const reader = this.openReader(draft.sessionID);
|
|
3074
3141
|
try {
|
|
3142
|
+
capturedIdentity = reader.hostIdentity();
|
|
3143
|
+
if (capturedIdentity !== draftSourceIdentity) {
|
|
3144
|
+
await this.discardCapture(draft.sessionID);
|
|
3145
|
+
this.reportCaptureReplacement(draft.sessionID);
|
|
3146
|
+
return;
|
|
3147
|
+
}
|
|
3148
|
+
await this.fenceMemory(draft.sessionID, capturedIdentity);
|
|
3149
|
+
this.memorySources.set(draft.sessionID, capturedIdentity);
|
|
3075
3150
|
if (this.options.protocol === 3) {
|
|
3076
3151
|
replay = await this.floorState(draft.sessionID, reader, boundary, draft);
|
|
3077
3152
|
if (!replay && restoredFirstRow) {
|
|
@@ -3121,6 +3196,7 @@ ${cached}
|
|
|
3121
3196
|
};
|
|
3122
3197
|
await this.storage.saveTail(draft.sessionID, JSON.stringify(tail), rows);
|
|
3123
3198
|
this.storage.truncate(draft.sessionID, through);
|
|
3199
|
+
this.memorySources.set(draft.sessionID, capturedIdentity);
|
|
3124
3200
|
this.loaded.set(draft.sessionID, through);
|
|
3125
3201
|
this.unavailable.delete(draft.sessionID);
|
|
3126
3202
|
this.changed.delete(draft.sessionID);
|
|
@@ -3143,13 +3219,24 @@ ${cached}
|
|
|
3143
3219
|
}
|
|
3144
3220
|
}
|
|
3145
3221
|
if (replay) {
|
|
3146
|
-
await this.retainReplay(draft.sessionID, replay, `${draft.model.providerID}/${draft.model.id}`, sourceSeq);
|
|
3222
|
+
await this.retainReplay(draft.sessionID, replay, `${draft.model.providerID}/${draft.model.id}`, sourceSeq, draftSourceIdentity);
|
|
3147
3223
|
const reader = this.openReader(draft.sessionID);
|
|
3148
3224
|
try {
|
|
3149
|
-
|
|
3225
|
+
const identity = reader.hostIdentity();
|
|
3226
|
+
if (identity !== capturedIdentity) {
|
|
3227
|
+
await this.discardCapture(draft.sessionID);
|
|
3228
|
+
this.reportCaptureReplacement(draft.sessionID);
|
|
3229
|
+
return;
|
|
3230
|
+
}
|
|
3231
|
+
const sourceDigest = foldDigest(identity);
|
|
3232
|
+
await this.saveCapturedReplay(draft.sessionID, replay, reader, sourceDigest);
|
|
3150
3233
|
const saved = await this.readV3(draft.sessionID);
|
|
3151
3234
|
const cut = reader.latestCompaction(draft.sessionID);
|
|
3152
3235
|
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)) {
|
|
3236
|
+
if (saved.proof.sourceDigest !== sourceDigest) {
|
|
3237
|
+
this.reportOnce(draft.sessionID, this.reportedForeignRefreshes, "v3 host fold: admission refresh skipped: admission belongs to a different host database file");
|
|
3238
|
+
return;
|
|
3239
|
+
}
|
|
3153
3240
|
const value = {
|
|
3154
3241
|
...saved,
|
|
3155
3242
|
replay: {
|
|
@@ -3192,6 +3279,8 @@ ${cached}
|
|
|
3192
3279
|
async supplyHeld(args) {
|
|
3193
3280
|
const { draft, reader, summary } = args;
|
|
3194
3281
|
const stored = args.checkpointText ?? summary;
|
|
3282
|
+
const source = reader.hostIdentity();
|
|
3283
|
+
await this.fenceMemory(draft.sessionID, source);
|
|
3195
3284
|
if (this.options.protocol === 3) {
|
|
3196
3285
|
if (this.unprovenControls.has(draft.sessionID))
|
|
3197
3286
|
return false;
|
|
@@ -3216,7 +3305,7 @@ ${cached}
|
|
|
3216
3305
|
if (!args.manual && this.tail(draft.sessionID)?.model !== model)
|
|
3217
3306
|
this.storage.replaceRows(draft.sessionID, reader.latestSequence(draft.sessionID), []);
|
|
3218
3307
|
if (!args.manual)
|
|
3219
|
-
await this.retainReplay(draft.sessionID, replay, model, reader.latestSequence(draft.sessionID));
|
|
3308
|
+
await this.retainReplay(draft.sessionID, replay, model, reader.latestSequence(draft.sessionID), source);
|
|
3220
3309
|
if (!args.manual)
|
|
3221
3310
|
await this.storage.supply(draft.sessionID, running.id, JSON.stringify({
|
|
3222
3311
|
source: this.storage.sourceID,
|
|
@@ -3278,7 +3367,7 @@ ${cached}
|
|
|
3278
3367
|
this.invalidate(draft.sessionID);
|
|
3279
3368
|
this.cancelLegacyUpgrade(draft.sessionID);
|
|
3280
3369
|
this.cancelEditedAdmission(draft.sessionID);
|
|
3281
|
-
await this.retainReplay(draft.sessionID, replay, model, running.seq - 1);
|
|
3370
|
+
await this.retainReplay(draft.sessionID, replay, model, running.seq - 1, source);
|
|
3282
3371
|
await this.storage.supply(draft.sessionID, running.id, JSON.stringify({
|
|
3283
3372
|
source: this.storage.sourceID,
|
|
3284
3373
|
sessionID: draft.sessionID,
|
|
@@ -3311,6 +3400,7 @@ ${cached}
|
|
|
3311
3400
|
baseline: tail?.baseline ?? summary,
|
|
3312
3401
|
sourceSeq: Math.max(tail?.sourceSeq ?? through, ...fresh.map((row) => row.seq))
|
|
3313
3402
|
}), records);
|
|
3403
|
+
this.memorySources.set(draft.sessionID, source);
|
|
3314
3404
|
this.dirty.delete(draft.sessionID);
|
|
3315
3405
|
this.metadata.delete(draft.sessionID);
|
|
3316
3406
|
this.metadataThrough.delete(draft.sessionID);
|
|
@@ -3339,13 +3429,16 @@ ${cached}
|
|
|
3339
3429
|
}
|
|
3340
3430
|
return true;
|
|
3341
3431
|
}
|
|
3342
|
-
async restore(sessionID, cut, model, options = {}) {
|
|
3432
|
+
async restore(sessionID, cut, model, passSource, options = {}) {
|
|
3343
3433
|
let replay;
|
|
3344
3434
|
let controls = [];
|
|
3345
3435
|
let after;
|
|
3436
|
+
await this.fenceMemory(sessionID, passSource);
|
|
3346
3437
|
if (this.options.protocol === 3) {
|
|
3347
3438
|
const reader = this.openReader(sessionID);
|
|
3348
3439
|
try {
|
|
3440
|
+
if (reader.hostIdentity() !== passSource)
|
|
3441
|
+
throw new NativeReplayUnavailable("Host database file changed during restore");
|
|
3349
3442
|
replay = await this.floorState(sessionID, reader);
|
|
3350
3443
|
if (replay) {
|
|
3351
3444
|
controls = controlsThrough(replay.controls, reader, sessionID, cut.seq - 1);
|
|
@@ -3369,7 +3462,7 @@ ${cached}
|
|
|
3369
3462
|
const release = this.storage.hold(sessionID);
|
|
3370
3463
|
let result;
|
|
3371
3464
|
try {
|
|
3372
|
-
result = await this.restoreHeld(sessionID, cut, model, options);
|
|
3465
|
+
result = await this.restoreHeld(sessionID, cut, model, options, passSource);
|
|
3373
3466
|
} finally {
|
|
3374
3467
|
try {
|
|
3375
3468
|
this.account(sessionID);
|
|
@@ -3378,14 +3471,23 @@ ${cached}
|
|
|
3378
3471
|
}
|
|
3379
3472
|
}
|
|
3380
3473
|
if (replay) {
|
|
3381
|
-
await this.retainReplay(sessionID, replay, model, cut.seq - 1);
|
|
3474
|
+
await this.retainReplay(sessionID, replay, model, cut.seq - 1, passSource);
|
|
3382
3475
|
return result && insertControls(result, controls, nativeRowID);
|
|
3383
3476
|
}
|
|
3384
3477
|
return result;
|
|
3385
3478
|
}
|
|
3386
|
-
async restoreHeld(sessionID, cut, model, options) {
|
|
3479
|
+
async restoreHeld(sessionID, cut, model, options, expected) {
|
|
3387
3480
|
if (!isLocalCheckpoint(cut))
|
|
3388
3481
|
return;
|
|
3482
|
+
const open = () => {
|
|
3483
|
+
const opened = this.openReader(sessionID);
|
|
3484
|
+
if (opened.hostIdentity() !== expected) {
|
|
3485
|
+
opened.close();
|
|
3486
|
+
throw new NativeReplayUnavailable("Host database file changed during restore");
|
|
3487
|
+
}
|
|
3488
|
+
this.memorySources.set(sessionID, expected);
|
|
3489
|
+
return opened;
|
|
3490
|
+
};
|
|
3389
3491
|
const resolvedModel = {
|
|
3390
3492
|
providerID: model.slice(0, model.indexOf("/")),
|
|
3391
3493
|
id: model.slice(model.indexOf("/") + 1)
|
|
@@ -3401,13 +3503,13 @@ ${cached}
|
|
|
3401
3503
|
const max = this.storage.db.prepare("SELECT COALESCE(MAX(id),0) AS id FROM m0_mutation_log WHERE session_id=?").get(sessionID);
|
|
3402
3504
|
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;
|
|
3403
3505
|
if (max.id <= (state.cachedM0MaxMutationId ?? 0) && boundary) {
|
|
3404
|
-
after = this.storage.sequenceForID(sessionID, boundary) ?? (reader =
|
|
3506
|
+
after = this.storage.sequenceForID(sessionID, boundary) ?? (reader = open()).sequenceForId(sessionID, boundary) ?? -1;
|
|
3405
3507
|
}
|
|
3406
3508
|
}
|
|
3407
3509
|
const through = cut.seq - 1;
|
|
3408
3510
|
let metadata = this.metadata.get(sessionID);
|
|
3409
3511
|
if (!metadata || (this.metadataThrough.get(sessionID) ?? -1) < through || this.options.protocol === 3 && this.options.rendersHistory?.(sessionID) && (this.metadataAfter.get(sessionID) ?? -1) > after) {
|
|
3410
|
-
reader ??=
|
|
3512
|
+
reader ??= open();
|
|
3411
3513
|
metadata = reader.rowStampsThrough(sessionID, through, this.options.protocol === 3 ? after : undefined).filter(conversational);
|
|
3412
3514
|
this.metadata.set(sessionID, metadata);
|
|
3413
3515
|
this.metadataThrough.set(sessionID, through);
|
|
@@ -3415,7 +3517,7 @@ ${cached}
|
|
|
3415
3517
|
}
|
|
3416
3518
|
const required = metadata.filter((row) => row.seq > after && row.seq <= through);
|
|
3417
3519
|
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))) {
|
|
3418
|
-
const source = reader ??=
|
|
3520
|
+
const source = reader ??= open();
|
|
3419
3521
|
const fresh = source.range(sessionID, after, through).filter(conversational);
|
|
3420
3522
|
const records = fresh.map((row) => this.record(row, this.rendered(row, resolvedModel, source)));
|
|
3421
3523
|
const restored = new Set(records.map((row) => row.id));
|
|
@@ -3445,9 +3547,11 @@ ${cached}
|
|
|
3445
3547
|
}
|
|
3446
3548
|
return messages;
|
|
3447
3549
|
}
|
|
3448
|
-
async restoreRead(sessionID, cut, model) {
|
|
3550
|
+
async restoreRead(sessionID, cut, model, passSource) {
|
|
3449
3551
|
const reader = this.openReader(sessionID);
|
|
3450
3552
|
try {
|
|
3553
|
+
if (reader.hostIdentity() !== passSource)
|
|
3554
|
+
throw new NativeReplayUnavailable("Host checkpoint replay boundary is unavailable");
|
|
3451
3555
|
const replay = this.options.protocol === 3 ? await this.floorState(sessionID, reader) : undefined;
|
|
3452
3556
|
if (this.options.protocol === 3 && !replay) {
|
|
3453
3557
|
this.report(sessionID, "replay refused: missing usable checkpoint boundary");
|
|
@@ -3474,6 +3578,7 @@ ${cached}
|
|
|
3474
3578
|
}
|
|
3475
3579
|
clear(sessionID) {
|
|
3476
3580
|
this.sources.delete(sessionID);
|
|
3581
|
+
this.memorySources.delete(sessionID);
|
|
3477
3582
|
this.metadata.delete(sessionID);
|
|
3478
3583
|
this.metadataThrough.delete(sessionID);
|
|
3479
3584
|
this.metadataAfter.delete(sessionID);
|
|
@@ -3488,6 +3593,8 @@ ${cached}
|
|
|
3488
3593
|
if (this.stampMRU?.sessionID === sessionID)
|
|
3489
3594
|
this.stampMRU = undefined;
|
|
3490
3595
|
this.unprovenControls.delete(sessionID);
|
|
3596
|
+
this.reportedCaptureReplacements.delete(sessionID);
|
|
3597
|
+
this.reportedForeignRefreshes.delete(sessionID);
|
|
3491
3598
|
this.cancelLegacyUpgrade(sessionID);
|
|
3492
3599
|
this.cancelEditedAdmission(sessionID);
|
|
3493
3600
|
if (this.admissions)
|
|
@@ -6662,7 +6769,10 @@ class V2RevertMessageCleanup {
|
|
|
6662
6769
|
sessionId: sessionID,
|
|
6663
6770
|
isInHostStore: (id) => source.sequenceForId(sessionID, id) !== undefined,
|
|
6664
6771
|
removedByCommittedRevert: removed,
|
|
6665
|
-
onRetire: () =>
|
|
6772
|
+
onRetire: () => {
|
|
6773
|
+
clearRecompStaging(db, sessionID);
|
|
6774
|
+
return;
|
|
6775
|
+
}
|
|
6666
6776
|
});
|
|
6667
6777
|
if (result.kind !== "unresolved") {
|
|
6668
6778
|
this.pendingHistory = this.pendingHistory.filter((proof) => proof.sessionID !== sessionID);
|
|
@@ -7345,7 +7455,10 @@ function checkHistoryBoundary(db, reader, sessionID) {
|
|
|
7345
7455
|
db,
|
|
7346
7456
|
sessionId: sessionID,
|
|
7347
7457
|
isInHostStore: (messageId) => storeHasSession ? reader.sequenceForId(sessionID, messageId) !== undefined : null,
|
|
7348
|
-
onRetire: () =>
|
|
7458
|
+
onRetire: () => {
|
|
7459
|
+
clearRecompStaging(db, sessionID);
|
|
7460
|
+
return;
|
|
7461
|
+
}
|
|
7349
7462
|
});
|
|
7350
7463
|
} catch (error) {
|
|
7351
7464
|
sessionLog2(sessionID, "history boundary check failed; continuing without repair", error);
|
|
@@ -9079,11 +9192,12 @@ async function setupContext(context, config, nativeRemove, compactionOff, cleanu
|
|
|
9079
9192
|
let recordedHead;
|
|
9080
9193
|
let upgradeCheckpointSequence;
|
|
9081
9194
|
let restoredFirstRow;
|
|
9195
|
+
let draftSourceIdentity;
|
|
9082
9196
|
try {
|
|
9083
9197
|
syntheticIDs = await readSyntheticProvenance(reader, draft.messages);
|
|
9084
9198
|
const cut = reader.latestCompaction(draft.sessionID);
|
|
9085
9199
|
if (nativeFoldReplay)
|
|
9086
|
-
await nativeFoldReplay.observeSource(draft.sessionID, reader);
|
|
9200
|
+
draftSourceIdentity = await nativeFoldReplay.observeSource(draft.sessionID, reader);
|
|
9087
9201
|
const boundaryRepair = !rustModeModuleClient && db && !compactionOff ? revertMessageCleanup.retireProvenHistory(db, draft.sessionID, reader) ?? checkHistoryBoundary(db, reader, draft.sessionID) : undefined;
|
|
9088
9202
|
if (boundaryRepair?.kind === "repaired" || boundaryRepair?.kind === "baseline-reset") {
|
|
9089
9203
|
historyRefreshSessions.add(draft.sessionID);
|
|
@@ -9123,13 +9237,14 @@ async function setupContext(context, config, nativeRemove, compactionOff, cleanu
|
|
|
9123
9237
|
}
|
|
9124
9238
|
}
|
|
9125
9239
|
let nativeRestored = localCut ? nativeFoldReplay?.legacyUpgradeInput(draft.sessionID, draft.model) : undefined;
|
|
9126
|
-
if (nativeRestored === undefined && cut && nativeFoldReplay && await nativeFoldReplay.admits(draft.sessionID, cut, reader)) {
|
|
9240
|
+
if (nativeRestored === undefined && cut && nativeFoldReplay && draftSourceIdentity !== undefined && await nativeFoldReplay.admits(draft.sessionID, cut, reader)) {
|
|
9241
|
+
const passSource = draftSourceIdentity;
|
|
9127
9242
|
try {
|
|
9128
|
-
nativeRestored = await nativeFoldReplay.restore(draft.sessionID, cut, `${draft.model.providerID}/${draft.model.id}`, { bounded: !rustModeModuleClient });
|
|
9243
|
+
nativeRestored = await nativeFoldReplay.restore(draft.sessionID, cut, `${draft.model.providerID}/${draft.model.id}`, passSource, { bounded: !rustModeModuleClient });
|
|
9129
9244
|
} catch (error) {
|
|
9130
9245
|
nativeFoldReplay.invalidate(draft.sessionID, true);
|
|
9131
9246
|
sessionLog2(draft.sessionID, "v2 host fold: cache unavailable; restoring host rows", error);
|
|
9132
|
-
nativeRestored = await nativeFoldReplay.restoreRead(draft.sessionID, cut, draft.model);
|
|
9247
|
+
nativeRestored = await nativeFoldReplay.restoreRead(draft.sessionID, cut, draft.model, passSource);
|
|
9133
9248
|
}
|
|
9134
9249
|
if (nativeRestored)
|
|
9135
9250
|
pass.nativeReplayCheckpointID = cut.id;
|
|
@@ -9278,8 +9393,8 @@ async function setupContext(context, config, nativeRemove, compactionOff, cleanu
|
|
|
9278
9393
|
const stripped = await folds.stripRecentContext(draft.sessionID, checkpointID);
|
|
9279
9394
|
if (stripped?.rendered) {
|
|
9280
9395
|
checkpoint = structuredClone(stripped.rendered);
|
|
9281
|
-
if (upgradeCheckpointSequence !== undefined)
|
|
9282
|
-
await nativeFoldReplay?.checkpointCovered(draft.sessionID, checkpointID);
|
|
9396
|
+
if (upgradeCheckpointSequence !== undefined && draftSourceIdentity !== undefined)
|
|
9397
|
+
await nativeFoldReplay?.checkpointCovered(draft.sessionID, checkpointID, draftSourceIdentity);
|
|
9283
9398
|
}
|
|
9284
9399
|
}
|
|
9285
9400
|
}
|
|
@@ -9297,11 +9412,11 @@ async function setupContext(context, config, nativeRemove, compactionOff, cleanu
|
|
|
9297
9412
|
} : null;
|
|
9298
9413
|
const servedHead = head && structuredClone(head);
|
|
9299
9414
|
const headApplied = head ? applyCheckpointHead(draft, head) : false;
|
|
9300
|
-
if (nativeMessages && (!checkpoint || upgradeCheckpointSequence !== undefined)) {
|
|
9415
|
+
if (nativeMessages && draftSourceIdentity !== undefined && (!checkpoint || upgradeCheckpointSequence !== undefined)) {
|
|
9301
9416
|
try {
|
|
9302
9417
|
const state = db && getOrCreateSessionMeta(db, draft.sessionID);
|
|
9303
9418
|
const boundary = db?.prepare("SELECT cached_m0_last_baseline_end_message_id AS id FROM session_meta WHERE session_id=?").get(draft.sessionID);
|
|
9304
|
-
await nativeFoldReplay?.capture(draft, nativeMessages, boundary?.id && state?.cachedM0Bytes ? { id: boundary.id, summary: state.cachedM0Bytes.toString("utf8") } : undefined, restoredFirstRow);
|
|
9419
|
+
await nativeFoldReplay?.capture(draft, nativeMessages, draftSourceIdentity, boundary?.id && state?.cachedM0Bytes ? { id: boundary.id, summary: state.cachedM0Bytes.toString("utf8") } : undefined, restoredFirstRow);
|
|
9305
9420
|
} catch (error) {
|
|
9306
9421
|
nativeFoldReplay?.invalidate(draft.sessionID, true);
|
|
9307
9422
|
sessionLog2(draft.sessionID, "v2 host fold: optional capture unavailable", error);
|