@cortexkit/opencode-magic-context 0.49.35 → 0.49.36
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/README.md +1 -1
- package/dist/auto-search-worker.js +163 -160
- package/dist/chunk-embedding-write-worker.js +58 -56
- package/dist/{compaction-marker-candidates-g0p67ced.js → compaction-marker-candidates-5p1qkve9.js} +3 -1
- package/dist/compaction-marker-candidates-worker.js +24 -23
- package/dist/{compartment-chunk-embedding-y4136are.js → compartment-chunk-embedding-ypktm0tk.js} +5 -4
- package/dist/{conflict-warning-hook-hhw8z5ak.js → conflict-warning-hook-b75jn458.js} +6 -5
- package/dist/{context-fk8e3h9p.js → context-969z683s.js} +485 -91
- package/dist/{embedding-backfill-q6n72sy0.js → embedding-backfill-rma0v2ct.js} +9 -8
- package/dist/embedding-worker.js +2 -2
- package/dist/features/magic-context/compaction-marker-candidates.d.ts.map +1 -1
- package/dist/features/magic-context/compaction-marker.d.ts +5 -3
- package/dist/features/magic-context/compaction-marker.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/task-gates.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/verify-gate.d.ts +2 -0
- package/dist/features/magic-context/dreamer/verify-gate.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/verify-state.d.ts +9 -0
- package/dist/features/magic-context/dreamer/verify-state.d.ts.map +1 -0
- package/dist/features/magic-context/dreamer/verify.d.ts +2 -1
- package/dist/features/magic-context/dreamer/verify.d.ts.map +1 -1
- package/dist/features/magic-context/migration-worker-client.d.ts +3 -0
- package/dist/features/magic-context/migration-worker-client.d.ts.map +1 -1
- package/dist/features/magic-context/migration-worker.d.ts +15 -0
- package/dist/features/magic-context/migration-worker.d.ts.map +1 -1
- package/dist/features/magic-context/overflow-detection.d.ts +2 -2
- package/dist/features/magic-context/overflow-detection.d.ts.map +1 -1
- package/dist/features/magic-context/search-rerank.d.ts.map +1 -1
- package/dist/features/magic-context/storage-meta-persisted.d.ts +1 -0
- package/dist/features/magic-context/storage-meta-persisted.d.ts.map +1 -1
- package/dist/features/magic-context/storage-tags.d.ts +4 -0
- package/dist/features/magic-context/storage-tags.d.ts.map +1 -1
- package/dist/features/magic-context/work-metrics-carry-storage.d.ts +10 -0
- package/dist/features/magic-context/work-metrics-carry-storage.d.ts.map +1 -0
- package/dist/hooks/magic-context/auto-search-worker-client.d.ts +5 -1
- package/dist/hooks/magic-context/auto-search-worker-client.d.ts.map +1 -1
- package/dist/hooks/magic-context/compaction-marker-publication.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-runner-historian.d.ts.map +1 -1
- package/dist/hooks/magic-context/issue-423-fixture.d.ts +1 -1
- package/dist/hooks/magic-context/issue-423-fixture.d.ts.map +1 -1
- package/dist/hooks/magic-context/issue-424-fixture.d.ts +1 -1
- package/dist/hooks/magic-context/issue-424-fixture.d.ts.map +1 -1
- package/dist/hooks/magic-context/project-structural-sentinels.d.ts +25 -0
- package/dist/hooks/magic-context/project-structural-sentinels.d.ts.map +1 -0
- package/dist/hooks/magic-context/protected-tail-boundary.d.ts +8 -1
- package/dist/hooks/magic-context/protected-tail-boundary.d.ts.map +1 -1
- package/dist/hooks/magic-context/raw-ordinal-warmup.d.ts.map +1 -1
- package/dist/hooks/magic-context/read-session-true-raw-tokens.d.ts +2 -0
- package/dist/hooks/magic-context/read-session-true-raw-tokens.d.ts.map +1 -1
- package/dist/hooks/magic-context/release-recovery-prefix.d.ts +9 -0
- package/dist/hooks/magic-context/release-recovery-prefix.d.ts.map +1 -0
- package/dist/hooks/magic-context/strip-structural-noise.d.ts +6 -3
- package/dist/hooks/magic-context/strip-structural-noise.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform-context-state.d.ts +3 -0
- package/dist/hooks/magic-context/transform-context-state.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform-postprocess-phase.d.ts +3 -0
- package/dist/hooks/magic-context/transform-postprocess-phase.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform.d.ts.map +1 -1
- package/dist/{index-cpjk5jd2.js → index-1d042x6w.js} +16 -14
- package/dist/{index-jn0ddrhp.js → index-21fgrfrf.js} +8 -6
- package/dist/{index-pq0dpwrc.js → index-2rs7912w.js} +2 -2
- package/dist/{index-ezv6dz3y.js → index-4ks89h5a.js} +4 -4
- package/dist/{index-vzhhr1ht.js → index-4y35msh5.js} +1 -2
- package/dist/{index-f297z1n8.js → index-72czy45z.js} +5 -5
- package/dist/index-7v05d9b7.js +58 -0
- package/dist/{index-f9b3vtt1.js → index-850vthn3.js} +8 -2
- package/dist/{index-ksv0a31x.js → index-8jjjmhab.js} +12 -1
- package/dist/index-96ztjvkn.js +204 -0
- package/dist/{index-gyaa159j.js → index-9fgmkfaf.js} +6 -3
- package/dist/{index-4bgk5ztz.js → index-9tdvbdv1.js} +187 -90
- package/dist/{index-2v6nvy3k.js → index-ae1ar4v1.js} +1 -1
- package/dist/{index-faxb7mck.js → index-b1ydbp95.js} +1 -1
- package/dist/{index-nxrsns5x.js → index-c5dzns43.js} +75 -75
- package/dist/{index-zhqwda72.js → index-dcjkw41m.js} +1 -1
- package/dist/{index-x2mrq5xv.js → index-dfdg2cgg.js} +179 -49
- package/dist/{index-87ctnzz9.js → index-dz48h1wx.js} +2 -2
- package/dist/{index-b6xz3qbe.js → index-gnmhbyyc.js} +366 -83
- package/dist/{index-qx8j6kds.js → index-j105mf16.js} +2 -2
- package/dist/{index-p56dszfp.js → index-jggt5gf2.js} +1 -1
- package/dist/{index-xwwsbsd3.js → index-pp8vdn01.js} +5 -5
- package/dist/{index-dy7w6wm4.js → index-prw8apnc.js} +5 -5
- package/dist/{index-qncw9hey.js → index-r2epb000.js} +33 -3
- package/dist/{index-brg2w6qc.js → index-tn9drm1a.js} +16 -14
- package/dist/{index-pswsyf1w.js → index-ty4vhe4n.js} +3 -3
- package/dist/{index-pztqab6k.js → index-vd2ywmfe.js} +1 -1
- package/dist/{index-3j9t1v4n.js → index-wcwhhtdh.js} +10 -9
- package/dist/{index-1rhgxqs8.js → index-xd2p95m7.js} +1 -1
- package/dist/{index-0c7p8mq5.js → index-xnm0wq1r.js} +1 -1
- package/dist/{index-3d3872c6.js → index-ys7j6679.js} +4 -4
- package/dist/index.js +38 -37
- package/dist/{message-fts-rowid-map-xg7hr0mk.js → message-fts-rowid-map-t6qsyg9s.js} +4 -3
- package/dist/{message-index-bounded-narw7bnz.js → message-index-bounded-wfk6aqxk.js} +9 -8
- package/dist/migration-worker.js +45 -40
- package/dist/plugin/rpc-handlers.d.ts.map +1 -1
- package/dist/{project-embedding-registry-tdz7985n.js → project-embedding-registry-3yyegjma.js} +8 -7
- package/dist/raw-ordinal-warmup-worker.js +114 -118
- package/dist/{read-session-chunk-vmg1zjg0.js → read-session-chunk-26yrrhyz.js} +7 -6
- package/dist/{read-session-raw-mncmzbm9.js → read-session-raw-j7c9w57v.js} +3 -2
- package/dist/{recomp-orchestrator-qyyhnc9b.js → recomp-orchestrator-wk509qkp.js} +20 -19
- package/dist/{render-c5p0k846.js → render-h1qarr8a.js} +13 -12
- package/dist/{search-f6hwvcxk.js → search-5h9fydyq.js} +16 -15
- package/dist/{search-archive-0ny7p3bw.js → search-archive-q79hyqxs.js} +9 -8
- package/dist/{send-session-notification-0gwcz3fw.js → send-session-notification-14p3yje4.js} +5 -4
- package/dist/shared/model-suggestion-retry.d.ts +7 -0
- package/dist/shared/model-suggestion-retry.d.ts.map +1 -1
- package/dist/shared/prompt-async-transport.d.ts.map +1 -1
- package/dist/shared/reusable-worker-entry.d.ts +4 -0
- package/dist/shared/reusable-worker-entry.d.ts.map +1 -0
- package/dist/shared/reusable-worker.d.ts +6 -0
- package/dist/shared/reusable-worker.d.ts.map +1 -0
- package/dist/shared/reusable-worker.fixture.d.ts +2 -0
- package/dist/shared/reusable-worker.fixture.d.ts.map +1 -0
- package/dist/shared/worker-shutdown.d.ts +1 -1
- package/dist/shared/worker-shutdown.d.ts.map +1 -1
- package/dist/{storage-tags-zx1023km.js → storage-tags-vj0yj7ed.js} +1 -1
- package/dist/{store-620rjzt9.js → store-s3eykdjt.js} +1 -1
- package/dist/{transform-postprocess-phase-807ff6t2.js → transform-postprocess-phase-4gj0mtcg.js} +21 -20
- package/dist/v2/auto-search-worker.js +163 -160
- package/dist/v2/chunk-embedding-write-worker.js +59 -57
- package/dist/v2/compaction-marker-candidates-worker.js +24 -23
- package/dist/v2/{compaction-marker-candidates-t1aq6gsj.js → compaction-marker-candidates-yeb2ky46.js} +4 -2
- package/dist/v2/{compartment-chunk-embedding-ncsk0r9e.js → compartment-chunk-embedding-qfk791bd.js} +6 -5
- package/dist/v2/{context-znqfkap4.js → context-bxr039be.js} +1011 -209
- package/dist/v2/{embedding-backfill-11j425e0.js → embedding-backfill-00tw59rx.js} +10 -9
- package/dist/v2/embedding-worker.js +2 -2
- package/dist/v2/fold/code-mode-catalog.d.ts +3 -0
- package/dist/v2/fold/code-mode-catalog.d.ts.map +1 -0
- package/dist/v2/fold/idle.d.ts +1 -0
- package/dist/v2/fold/idle.d.ts.map +1 -1
- package/dist/v2/fold/manual-baseline.d.ts +8 -0
- package/dist/v2/fold/manual-baseline.d.ts.map +1 -0
- package/dist/v2/fold/native-replay-v3.d.ts +7 -0
- package/dist/v2/fold/native-replay-v3.d.ts.map +1 -1
- package/dist/v2/fold/native-replay.d.ts +24 -7
- package/dist/v2/fold/native-replay.d.ts.map +1 -1
- package/dist/v2/fold/restore.d.ts.map +1 -1
- package/dist/v2/fold/summary.d.ts +4 -0
- package/dist/v2/fold/summary.d.ts.map +1 -0
- package/dist/v2/hidden-completion.d.ts.map +1 -1
- package/dist/v2/hooks/channel2.d.ts +6 -0
- package/dist/v2/hooks/channel2.d.ts.map +1 -1
- package/dist/v2/hooks/context.d.ts.map +1 -1
- package/dist/v2/hooks/restore-rows.d.ts +12 -2
- package/dist/v2/hooks/restore-rows.d.ts.map +1 -1
- package/dist/v2/hooks/synthetic-admission.d.ts +7 -0
- package/dist/v2/hooks/synthetic-admission.d.ts.map +1 -0
- package/dist/v2/hooks/usage-persist.d.ts.map +1 -1
- package/dist/v2/{message-fts-rowid-map-rmk571mb.js → message-fts-rowid-map-z86avy0n.js} +5 -4
- package/dist/v2/{message-index-bounded-620bppw7.js → message-index-bounded-w14496s9.js} +9 -8
- package/dist/v2/migration-worker.js +46 -41
- package/dist/v2/{project-embedding-registry-bm5fe1a8.js → project-embedding-registry-jqq2qeqb.js} +9 -8
- package/dist/v2/raw-ordinal-warmup-worker.js +114 -118
- package/dist/v2/{read-session-chunk-qfwv1k71.js → read-session-chunk-tqnh1ret.js} +7 -6
- package/dist/v2/{read-session-raw-q294t8xs.js → read-session-raw-qpp6x9kg.js} +4 -3
- package/dist/v2/{recomp-orchestrator-fcnjref7.js → recomp-orchestrator-9cjk6aej.js} +19 -18
- package/dist/v2/{render-98a1qv0b.js → render-5dz1knf2.js} +13 -12
- package/dist/v2/{search-z1zqzsmh.js → search-8yfet25y.js} +15 -14
- package/dist/v2/{search-archive-r0y1bafr.js → search-archive-z6z9jqwf.js} +9 -8
- package/dist/v2/{send-session-notification-fst6hkg7.js → send-session-notification-kxp47tsw.js} +4 -3
- package/dist/v2/{server-cpjk5jd2.js → server-1d042x6w.js} +16 -14
- package/dist/v2/{server-fqj6ddpr.js → server-5by3vdzs.js} +186 -89
- package/dist/v2/{server-5jp38p98.js → server-6emy0v9a.js} +1 -2
- package/dist/v2/{server-rktnzs89.js → server-6vzh6wej.js} +1 -1
- package/dist/v2/{server-qa74bj91.js → server-7094pk3w.js} +9 -8
- package/dist/v2/{server-bxpz2dcn.js → server-7acq7815.js} +8 -6
- package/dist/v2/server-7v05d9b7.js +58 -0
- package/dist/v2/{server-24g8r2d0.js → server-7zacmty5.js} +75 -75
- package/dist/v2/server-96ztjvkn.js +204 -0
- package/dist/v2/{server-hnknwaz8.js → server-a9w5f0yw.js} +3 -3
- package/dist/v2/{server-9k0mjef7.js → server-avdveykk.js} +1 -1
- package/dist/v2/{server-hsf0qsn5.js → server-cp1a03vc.js} +1 -1
- package/dist/v2/{server-r3chnxs5.js → server-dfq5vb8j.js} +2 -2
- package/dist/v2/{server-x4m6xcn4.js → server-e51xmr4d.js} +6 -6
- package/dist/v2/{server-7ccxt4nq.js → server-g3gqq4ac.js} +6 -3
- package/dist/v2/{server-kkxzwa6w.js → server-gkse1wyz.js} +3 -3
- package/dist/v2/{server-1xesqm5h.js → server-jd7vzwn4.js} +15 -13
- package/dist/v2/{server-ws5exe6q.js → server-nmyganc8.js} +1 -1
- package/dist/v2/{server-q0z2q2dx.js → server-nq3cb7be.js} +1 -1
- package/dist/v2/{server-55v5hpth.js → server-qjyp27vf.js} +2 -2
- package/dist/v2/{server-xbtw0p9t.js → server-r4430x9m.js} +9 -3
- package/dist/v2/{server-qf2kzsh2.js → server-t8y64xj7.js} +4 -4
- package/dist/v2/{server-s9xgyyj9.js → server-tnzbk64q.js} +34 -4
- package/dist/v2/{server-51779zs2.js → server-v0p37hm2.js} +4 -1
- package/dist/v2/{server-bpvsvtph.js → server-xfjjbrkt.js} +12 -1
- package/dist/v2/server.js +4 -4
- package/dist/v2/{storage-tags-19s0ebf0.js → storage-tags-cw07ky67.js} +1 -1
- package/dist/v2/{store-vdm8v3jd.js → store-z3qe67cg.js} +1 -1
- package/dist/v2/{v2-archive-reader-t2c0eypn.js → v2-archive-reader-z7wr42ry.js} +3 -3
- package/dist/v2/{wrapup-orchestrator-aqpqsveg.js → wrapup-orchestrator-j1v62bkj.js} +19 -18
- package/dist/{v2-archive-reader-tm2eayp2.js → v2-archive-reader-028z6kck.js} +2 -2
- package/dist/{wrapup-orchestrator-k5yp19a6.js → wrapup-orchestrator-xg9avt2p.js} +21 -20
- package/package.json +1 -1
- package/src/shared/model-suggestion-retry.ts +1 -1
- package/src/shared/prompt-async-transport.test.ts +64 -3
- package/src/shared/prompt-async-transport.ts +61 -16
- package/src/shared/reusable-worker-entry.ts +58 -0
- package/src/shared/reusable-worker-reset.test.ts +108 -0
- package/src/shared/reusable-worker.fixture.ts +35 -0
- package/src/shared/reusable-worker.test.ts +253 -0
- package/src/shared/reusable-worker.ts +240 -0
- package/src/shared/worker-shutdown.ts +21 -17
|
@@ -72,7 +72,7 @@ import {
|
|
|
72
72
|
getRawSessionTagKeysThrough2,
|
|
73
73
|
getLegacyProtectedTailStartOrdinal2,
|
|
74
74
|
readSessionChunk2
|
|
75
|
-
} from "./index-
|
|
75
|
+
} from "./index-tn9drm1a.js";
|
|
76
76
|
import {
|
|
77
77
|
getHarness2,
|
|
78
78
|
harnessOwnsOpenCodeStore2
|
|
@@ -123,7 +123,7 @@ import {
|
|
|
123
123
|
ConfigProfilesSchema,
|
|
124
124
|
MagicContextConfigSchema,
|
|
125
125
|
LIVE_RELOAD_CONFIG_PATHS
|
|
126
|
-
} from "./index-
|
|
126
|
+
} from "./index-c5dzns43.js";
|
|
127
127
|
import {
|
|
128
128
|
providerMass,
|
|
129
129
|
calibrationForModelKey,
|
|
@@ -153,7 +153,7 @@ import {
|
|
|
153
153
|
LATEST_SUPPORTED_VERSION,
|
|
154
154
|
getPersistedSchemaVersion,
|
|
155
155
|
openDatabase
|
|
156
|
-
} from "./index-
|
|
156
|
+
} from "./index-9fgmkfaf.js";
|
|
157
157
|
import {
|
|
158
158
|
areRustHistorianSyntheticParts2,
|
|
159
159
|
isStrictGapHealingMessage2,
|
|
@@ -161,7 +161,7 @@ import {
|
|
|
161
161
|
RawOrdinalsNotReady2,
|
|
162
162
|
dropRawSessionOrdinalCheckpoints2,
|
|
163
163
|
runSessionWarmupWorker
|
|
164
|
-
} from "./index-
|
|
164
|
+
} from "./index-r2epb000.js";
|
|
165
165
|
import {
|
|
166
166
|
parseCompartmentOutput,
|
|
167
167
|
resolveWorkspaceShareCategories,
|
|
@@ -197,7 +197,7 @@ import {
|
|
|
197
197
|
replaceCompartmentChunkEmbeddings2,
|
|
198
198
|
deleteChunkEmbedBackoffForSession2,
|
|
199
199
|
chunkWindowSourceKey2
|
|
200
|
-
} from "./index-
|
|
200
|
+
} from "./index-dcjkw41m.js";
|
|
201
201
|
import {
|
|
202
202
|
COMPARTMENT_LEASE_RENEWAL_MS,
|
|
203
203
|
getCompartmentLeaseBlocker,
|
|
@@ -239,14 +239,14 @@ import {
|
|
|
239
239
|
getProjectState,
|
|
240
240
|
recordSubagentInvocation,
|
|
241
241
|
getLatestHistorianInvocationId
|
|
242
|
-
} from "./index-
|
|
242
|
+
} from "./index-72czy45z.js";
|
|
243
243
|
import {
|
|
244
244
|
clearCompressionDepth,
|
|
245
245
|
clearCompressionDepthRange,
|
|
246
246
|
toMessageIndexSource,
|
|
247
247
|
clearIndexedMessagesInTransaction,
|
|
248
248
|
indexSourcesAfterOrdinal
|
|
249
|
-
} from "./index-
|
|
249
|
+
} from "./index-2rs7912w.js";
|
|
250
250
|
import {
|
|
251
251
|
stripWellFormedLeadingTagPrefix,
|
|
252
252
|
peelLeadingMcTagNotation,
|
|
@@ -257,12 +257,12 @@ import {
|
|
|
257
257
|
foldShrunkPartTags2,
|
|
258
258
|
getTagNumberByMessageId2,
|
|
259
259
|
getActiveTagsBySession2
|
|
260
|
-
} from "./index-
|
|
260
|
+
} from "./index-8jjjmhab.js";
|
|
261
261
|
import {
|
|
262
262
|
openCodeDbExists,
|
|
263
263
|
withReadOnlySessionDb,
|
|
264
264
|
getMessageTimesFromOpenCodeDb
|
|
265
|
-
} from "./index-
|
|
265
|
+
} from "./index-vd2ywmfe.js";
|
|
266
266
|
import {
|
|
267
267
|
getSessionNotes,
|
|
268
268
|
getReadySmartNotes,
|
|
@@ -285,22 +285,22 @@ import {
|
|
|
285
285
|
getProjectChunkEmbeddingModelId2,
|
|
286
286
|
getProjectEmbeddingMaxInputTokens2,
|
|
287
287
|
embedItemsForProject2
|
|
288
|
-
} from "./index-
|
|
288
|
+
} from "./index-21fgrfrf.js";
|
|
289
289
|
import {
|
|
290
290
|
renderUserFacingFailure,
|
|
291
291
|
userFacingFailureCode,
|
|
292
292
|
promoteSessionFactsDurable,
|
|
293
293
|
embedPromotedFacts
|
|
294
|
-
} from "./index-
|
|
294
|
+
} from "./index-xnm0wq1r.js";
|
|
295
295
|
import {
|
|
296
296
|
isMarkerCandidateBasisCurrent2,
|
|
297
297
|
invalidateMarkerCandidateBasis2,
|
|
298
298
|
readMarkerCandidateBasis2,
|
|
299
299
|
prepareMarkerCandidateBasis2
|
|
300
|
-
} from "./index-
|
|
300
|
+
} from "./index-850vthn3.js";
|
|
301
301
|
import {
|
|
302
302
|
sendStatusNotification2
|
|
303
|
-
} from "./index-
|
|
303
|
+
} from "./index-ae1ar4v1.js";
|
|
304
304
|
import {
|
|
305
305
|
isCompactionEnabled,
|
|
306
306
|
migrateLegacyAgentEnabledInMemory
|
|
@@ -6083,6 +6083,18 @@ function messageId(message) {
|
|
|
6083
6083
|
const id = infoOf(message).id;
|
|
6084
6084
|
return typeof id === "string" ? id : null;
|
|
6085
6085
|
}
|
|
6086
|
+
function recordedAssistantError(message) {
|
|
6087
|
+
const info = infoOf(message);
|
|
6088
|
+
if (info.error != null)
|
|
6089
|
+
return info.error;
|
|
6090
|
+
if (isSettledAssistant(message))
|
|
6091
|
+
return;
|
|
6092
|
+
const parts = message?.parts;
|
|
6093
|
+
if (!Array.isArray(parts))
|
|
6094
|
+
return;
|
|
6095
|
+
const retry = parts.slice().reverse().find((part) => part !== null && typeof part === "object" && part.type === "retry");
|
|
6096
|
+
return retry?.error ?? undefined;
|
|
6097
|
+
}
|
|
6086
6098
|
function isSettledAssistant(message) {
|
|
6087
6099
|
const info = infoOf(message);
|
|
6088
6100
|
if (info.role !== "assistant")
|
|
@@ -6198,6 +6210,22 @@ async function promptAsyncAndWaitForIdle(client, request, options = {}) {
|
|
|
6198
6210
|
let completionBaseline = new Set((await readMessages(session, sessionId, dir, signal)).map(messageId).filter((id) => id !== null));
|
|
6199
6211
|
const initialBaseline = new Set(completionBaseline);
|
|
6200
6212
|
activeSessionErrors.set(sessionId, undefined);
|
|
6213
|
+
const failForHostError = async (hostError) => {
|
|
6214
|
+
await abortChildRun(client, sessionId);
|
|
6215
|
+
const error = new Error(`Host recorded session error: ${describeAssistantError(hostError)}`);
|
|
6216
|
+
Object.assign(error, {
|
|
6217
|
+
name: "DreamerProviderOutputFailureError",
|
|
6218
|
+
transient: true,
|
|
6219
|
+
[HOST_SESSION_ERROR]: true,
|
|
6220
|
+
hostError
|
|
6221
|
+
});
|
|
6222
|
+
annotateSubagentInvocationError(error, {
|
|
6223
|
+
attemptedModel: requestModelRef(request),
|
|
6224
|
+
modelConfigKey: options.modelConfigKey,
|
|
6225
|
+
hostError
|
|
6226
|
+
});
|
|
6227
|
+
throw error;
|
|
6228
|
+
};
|
|
6201
6229
|
try {
|
|
6202
6230
|
let sent;
|
|
6203
6231
|
try {
|
|
@@ -6232,22 +6260,17 @@ async function promptAsyncAndWaitForIdle(client, request, options = {}) {
|
|
|
6232
6260
|
await sleep(pollIntervalMs, signal);
|
|
6233
6261
|
const hostError = activeSessionErrors.get(sessionId);
|
|
6234
6262
|
if (hostError !== undefined) {
|
|
6235
|
-
|
|
6236
|
-
Object.assign(error, {
|
|
6237
|
-
name: "DreamerProviderOutputFailureError",
|
|
6238
|
-
transient: true,
|
|
6239
|
-
[HOST_SESSION_ERROR]: true,
|
|
6240
|
-
hostError
|
|
6241
|
-
});
|
|
6242
|
-
annotateSubagentInvocationError(error, {
|
|
6243
|
-
attemptedModel: requestModelRef(request),
|
|
6244
|
-
modelConfigKey: options.modelConfigKey,
|
|
6245
|
-
hostError
|
|
6246
|
-
});
|
|
6247
|
-
throw error;
|
|
6263
|
+
await failForHostError(hostError);
|
|
6248
6264
|
}
|
|
6249
6265
|
const status = await readStatus(session, sessionId, dir, signal);
|
|
6250
6266
|
const messages = await readMessages(session, sessionId, dir, signal);
|
|
6267
|
+
const latestAssistant = messages.slice().reverse().find((message) => {
|
|
6268
|
+
const id = messageId(message);
|
|
6269
|
+
return id !== null && !completionBaseline.has(id) && infoOf(message).role === "assistant";
|
|
6270
|
+
});
|
|
6271
|
+
const assistantError = recordedAssistantError(latestAssistant);
|
|
6272
|
+
if (assistantError !== undefined)
|
|
6273
|
+
await failForHostError(assistantError);
|
|
6251
6274
|
if (!sawOutput && messages.some((message) => {
|
|
6252
6275
|
const id = messageId(message);
|
|
6253
6276
|
return id !== null && !initialBaseline.has(id) && showsModelOutput(message);
|
|
@@ -8248,46 +8271,36 @@ function isCompactionMarkerIntentAbsent(marker, targetEndMessageId) {
|
|
|
8248
8271
|
function withCompactionMarkerPublicationLock(operation) {
|
|
8249
8272
|
return runMarkerWriteTransaction(getWritableOpenCodeDb(), "compaction-marker-replace", operation);
|
|
8250
8273
|
}
|
|
8251
|
-
function inspectCompactionMarkerPublication(sessionId, recognized, summaryText) {
|
|
8274
|
+
function inspectCompactionMarkerPublication(sessionId, recognized, summaryText, targetBoundaryMessageId, preferred) {
|
|
8252
8275
|
const db = getWritableOpenCodeDb();
|
|
8253
8276
|
const basis = readMarkerCandidateBasis2(db, sessionId);
|
|
8254
8277
|
if (!basis)
|
|
8255
8278
|
return { kind: "deferred" };
|
|
8256
8279
|
const pairs = [];
|
|
8257
8280
|
for (const id of basis.ids) {
|
|
8258
|
-
const rows = db.prepare(`SELECT m.id AS summaryId, p.message_id AS boundaryId, p.id AS partId
|
|
8259
|
-
|
|
8260
|
-
|
|
8261
|
-
|
|
8262
|
-
|
|
8263
|
-
AND json_extract(
|
|
8264
|
-
|
|
8265
|
-
|
|
8266
|
-
|
|
8267
|
-
return { kind: "ambiguous" };
|
|
8268
|
-
if (pairs.length === 0) {
|
|
8269
|
-
for (const marker of recognized) {
|
|
8270
|
-
if (db.prepare(`SELECT 1 FROM message WHERE id = ?
|
|
8271
|
-
UNION ALL SELECT 1 FROM part WHERE id IN (?, ?) LIMIT 1`).get(marker.summaryMessageId, marker.compactionPartId, marker.summaryPartId))
|
|
8272
|
-
return { kind: "ambiguous" };
|
|
8273
|
-
}
|
|
8274
|
-
return { kind: "verified", marker: null };
|
|
8275
|
-
}
|
|
8276
|
-
const pair = pairs[0];
|
|
8277
|
-
const marker = recognized.find((item) => item.summaryMessageId === pair.summaryId && item.boundaryMessageId === pair.boundaryId && item.compactionPartId === pair.partId);
|
|
8278
|
-
if (!marker)
|
|
8279
|
-
return { kind: "ambiguous" };
|
|
8280
|
-
for (const other of recognized) {
|
|
8281
|
-
if (other.summaryMessageId === marker.summaryMessageId && other.compactionPartId === marker.compactionPartId && other.summaryPartId === marker.summaryPartId)
|
|
8282
|
-
continue;
|
|
8283
|
-
if (db.prepare(`SELECT 1 FROM message WHERE id = ?
|
|
8284
|
-
UNION ALL SELECT 1 FROM part WHERE id IN (?, ?) LIMIT 1`).get(other.summaryMessageId, other.compactionPartId, other.summaryPartId))
|
|
8281
|
+
const rows = db.prepare(`SELECT m.id AS summaryId, p.message_id AS boundaryId, p.id AS partId,
|
|
8282
|
+
p.data AS compactionData
|
|
8283
|
+
FROM message m LEFT JOIN part p ON p.message_id = json_extract(m.data, '$.parentID')
|
|
8284
|
+
AND +p.session_id = m.session_id
|
|
8285
|
+
AND json_extract(p.data, '$.type') = 'compaction'
|
|
8286
|
+
WHERE m.id = ? AND m.session_id = ? AND json_extract(m.data, '$.summary') = 1
|
|
8287
|
+
AND json_extract(m.data, '$.providerID') = 'magic-context'`).all(id, sessionId);
|
|
8288
|
+
const canonical = rows.filter((row) => isMcCanonicalCompactionPartData(JSON.parse(row.compactionData ?? "null")));
|
|
8289
|
+
if (rows.length > 0 && canonical.length === 0)
|
|
8285
8290
|
return { kind: "ambiguous" };
|
|
8291
|
+
pairs.push(...canonical);
|
|
8286
8292
|
}
|
|
8287
|
-
const
|
|
8293
|
+
const verified = [];
|
|
8294
|
+
for (const pair of pairs) {
|
|
8295
|
+
if (pair.partId === null)
|
|
8296
|
+
return { kind: "ambiguous" };
|
|
8297
|
+
if (verified.some((marker) => marker.boundaryMessageId === pair.boundaryId))
|
|
8298
|
+
return { kind: "ambiguous" };
|
|
8299
|
+
const row = db.prepare(`SELECT c.data AS compactionData, t.id AS summaryPartId,
|
|
8300
|
+
m.time_created AS timeCreated FROM message m
|
|
8288
8301
|
JOIN message b ON b.id = ? AND b.session_id = m.session_id
|
|
8289
8302
|
JOIN part c ON c.id = ? AND c.message_id = b.id AND c.session_id = m.session_id
|
|
8290
|
-
JOIN part t ON t.
|
|
8303
|
+
JOIN part t ON t.message_id = m.id AND t.session_id = m.session_id
|
|
8291
8304
|
WHERE m.id = ? AND m.session_id = ?
|
|
8292
8305
|
AND json_extract(b.data, '$.role') = 'user'
|
|
8293
8306
|
AND json_extract(m.data, '$.role') = 'assistant'
|
|
@@ -8298,10 +8311,39 @@ function inspectCompactionMarkerPublication(sessionId, recognized, summaryText)
|
|
|
8298
8311
|
AND json_extract(m.data, '$.providerID') = 'magic-context'
|
|
8299
8312
|
AND json_extract(m.data, '$.modelID') = 'magic-context'
|
|
8300
8313
|
AND json_extract(t.data, '$.type') = 'text' AND json_extract(t.data, '$.text') = ?
|
|
8301
|
-
AND (SELECT COUNT(*) FROM part p WHERE p.message_id = m.id AND +p.session_id = m.session_id) = 1`).get(
|
|
8302
|
-
|
|
8303
|
-
|
|
8304
|
-
|
|
8314
|
+
AND (SELECT COUNT(*) FROM part p WHERE p.message_id = m.id AND +p.session_id = m.session_id) = 1`).get(pair.boundaryId, pair.partId, pair.summaryId, sessionId, summaryText);
|
|
8315
|
+
const order = compareOpenCodeMessagesByCanonicalOrder(sessionId, pair.boundaryId, targetBoundaryMessageId);
|
|
8316
|
+
const isRecorded = preferred && preferred.summaryMessageId === pair.summaryId && preferred.boundaryMessageId === pair.boundaryId && preferred.compactionPartId === pair.partId && preferred.summaryPartId === row?.summaryPartId;
|
|
8317
|
+
if (!row || !isMcCanonicalCompactionPartData(JSON.parse(row.compactionData)) || findBoundaryUserMessage(sessionId, pair.boundaryId)?.id !== pair.boundaryId || order === null || order > 0 && !isRecorded)
|
|
8318
|
+
return { kind: "ambiguous" };
|
|
8319
|
+
verified.push({
|
|
8320
|
+
boundaryMessageId: pair.boundaryId,
|
|
8321
|
+
summaryMessageId: pair.summaryId,
|
|
8322
|
+
compactionPartId: pair.partId,
|
|
8323
|
+
summaryPartId: row.summaryPartId,
|
|
8324
|
+
timeCreated: row.timeCreated
|
|
8325
|
+
});
|
|
8326
|
+
}
|
|
8327
|
+
const matches = (left, right) => left.summaryMessageId === right.summaryMessageId && left.boundaryMessageId === right.boundaryMessageId && left.compactionPartId === right.compactionPartId && left.summaryPartId === right.summaryPartId;
|
|
8328
|
+
for (const marker of recognized) {
|
|
8329
|
+
if (verified.some((item) => matches(item, marker)))
|
|
8330
|
+
continue;
|
|
8331
|
+
if (db.prepare(`SELECT 1 FROM message WHERE id = ?
|
|
8332
|
+
UNION ALL SELECT 1 FROM part WHERE id IN (?, ?) LIMIT 1`).get(marker.summaryMessageId, marker.compactionPartId, marker.summaryPartId))
|
|
8333
|
+
return { kind: "ambiguous" };
|
|
8334
|
+
}
|
|
8335
|
+
verified.sort((left, right) => right.timeCreated - left.timeCreated || (left.summaryMessageId < right.summaryMessageId ? 1 : -1));
|
|
8336
|
+
const state = (marker) => {
|
|
8337
|
+
if (!marker)
|
|
8338
|
+
return null;
|
|
8339
|
+
const { timeCreated: _, ...ids } = marker;
|
|
8340
|
+
return ids;
|
|
8341
|
+
};
|
|
8342
|
+
return {
|
|
8343
|
+
kind: "verified",
|
|
8344
|
+
marker: state(preferred && verified.find((item) => matches(item, preferred)) || verified[0]),
|
|
8345
|
+
markerAtTarget: state(verified.find((item) => item.boundaryMessageId === targetBoundaryMessageId))
|
|
8346
|
+
};
|
|
8305
8347
|
}
|
|
8306
8348
|
var LEGACY_MARKER_LINEAGE_SQL = `SELECT m.id
|
|
8307
8349
|
FROM message m
|
|
@@ -8341,7 +8383,7 @@ async function prepareCompactionMarkerCandidates(sessionId, options = {}) {
|
|
|
8341
8383
|
return false;
|
|
8342
8384
|
}
|
|
8343
8385
|
}
|
|
8344
|
-
function injectCompactionMarkerFromBasis(args, validatedBasis) {
|
|
8386
|
+
function injectCompactionMarkerFromBasis(args, validatedBasis, preserveExistingLineages = false) {
|
|
8345
8387
|
const db = getWritableOpenCodeDb();
|
|
8346
8388
|
if (!isOpenCodeSchemaCompatible(db, getOpenCodeDbPath())) {
|
|
8347
8389
|
return null;
|
|
@@ -8378,14 +8420,15 @@ function injectCompactionMarkerFromBasis(args, validatedBasis) {
|
|
|
8378
8420
|
runMarkerWriteTransaction(db, "compaction-marker-inject", () => {
|
|
8379
8421
|
if (!validatedBasis && !isMarkerCandidateBasisCurrent2(db, basis))
|
|
8380
8422
|
throw new Error("host store changed after marker candidate preparation; marker unchanged");
|
|
8381
|
-
|
|
8382
|
-
|
|
8383
|
-
|
|
8384
|
-
|
|
8385
|
-
|
|
8386
|
-
|
|
8387
|
-
|
|
8388
|
-
|
|
8423
|
+
if (!preserveExistingLineages)
|
|
8424
|
+
removeLegacyMarkerLineageRows(db, {
|
|
8425
|
+
sessionId: args.sessionId,
|
|
8426
|
+
boundaryMessageId: boundary.id,
|
|
8427
|
+
candidateIds: basis.ids,
|
|
8428
|
+
summaryText: args.summaryText,
|
|
8429
|
+
summaryMessageId: summaryMsgId,
|
|
8430
|
+
compactionPartId
|
|
8431
|
+
});
|
|
8389
8432
|
db.prepare(`INSERT INTO part (id, message_id, session_id, time_created, time_updated, data)
|
|
8390
8433
|
VALUES (?, ?, ?, ?, ?, ?)
|
|
8391
8434
|
ON CONFLICT(id) DO UPDATE SET
|
|
@@ -8427,7 +8470,7 @@ function injectCompactionMarkerFromBasis(args, validatedBasis) {
|
|
|
8427
8470
|
|
|
8428
8471
|
class MarkerCandidateUnavailableError extends Error {
|
|
8429
8472
|
}
|
|
8430
|
-
function replaceCompactionMarker(existing, args) {
|
|
8473
|
+
function replaceCompactionMarker(existing, args, preserveExistingLineages = false) {
|
|
8431
8474
|
let connection;
|
|
8432
8475
|
let entered = false;
|
|
8433
8476
|
let readyToCommit = false;
|
|
@@ -8446,11 +8489,25 @@ function replaceCompactionMarker(existing, args) {
|
|
|
8446
8489
|
if (!isMarkerCandidateBasisCurrent2(db, basis))
|
|
8447
8490
|
throw new MarkerCandidateUnavailableError("host store changed after marker candidate preparation; marker unchanged");
|
|
8448
8491
|
if (existing) {
|
|
8492
|
+
const referenced = db.prepare(`WITH deleted(id) AS (VALUES (?), (?), (?)), surviving(data) AS (
|
|
8493
|
+
SELECT data FROM part WHERE session_id = ?
|
|
8494
|
+
AND id NOT IN (SELECT id FROM deleted)
|
|
8495
|
+
AND json_extract(data, '$.type') = 'compaction'
|
|
8496
|
+
UNION ALL
|
|
8497
|
+
SELECT data FROM message WHERE session_id = ?
|
|
8498
|
+
AND id NOT IN (SELECT id FROM deleted)
|
|
8499
|
+
)
|
|
8500
|
+
SELECT 1 FROM surviving
|
|
8501
|
+
WHERE json_extract(data, '$.tail_start_id') IN (SELECT id FROM deleted)
|
|
8502
|
+
OR json_extract(data, '$.compaction.tail_start_id') IN (SELECT id FROM deleted)
|
|
8503
|
+
LIMIT 1`).get(existing.summaryMessageId, existing.summaryPartId, existing.compactionPartId, args.sessionId, args.sessionId);
|
|
8504
|
+
if (referenced)
|
|
8505
|
+
throw new Error("a surviving tail_start_id references a recorded marker row; marker unchanged");
|
|
8449
8506
|
db.prepare("DELETE FROM part WHERE id = ?").run(existing.summaryPartId);
|
|
8450
8507
|
db.prepare("DELETE FROM message WHERE id = ?").run(existing.summaryMessageId);
|
|
8451
8508
|
db.prepare("DELETE FROM part WHERE id = ?").run(existing.compactionPartId);
|
|
8452
8509
|
}
|
|
8453
|
-
const replacement = injectCompactionMarkerFromBasis(args, basis);
|
|
8510
|
+
const replacement = injectCompactionMarkerFromBasis(args, basis, preserveExistingLineages);
|
|
8454
8511
|
if (!replacement) {
|
|
8455
8512
|
throw new Error(`failed to inject replacement marker at ordinal ${args.endOrdinal}`);
|
|
8456
8513
|
}
|
|
@@ -8771,7 +8828,7 @@ function publishRecoverableCompactionMarker(db, args, targetIsCurrent) {
|
|
|
8771
8828
|
if (!validTarget || !pendingBoundary || !pendingTarget || !samePair(pending, planCompactionMarker({ ...args, endMessageId: pendingTarget }, pendingBoundary)))
|
|
8772
8829
|
pending = null;
|
|
8773
8830
|
}
|
|
8774
|
-
const inspection = inspectCompactionMarkerPublication(sessionId, [intended, ...previous ? [previous] : [], ...pending ? [pending] : []], args.summaryText);
|
|
8831
|
+
const inspection = inspectCompactionMarkerPublication(sessionId, [intended, ...previous ? [previous] : [], ...pending ? [pending] : []], args.summaryText, boundary.id, previous);
|
|
8775
8832
|
if (inspection.kind === "deferred") {
|
|
8776
8833
|
reason = "candidate-preparation";
|
|
8777
8834
|
return {
|
|
@@ -8788,22 +8845,34 @@ function publishRecoverableCompactionMarker(db, args, targetIsCurrent) {
|
|
|
8788
8845
|
}
|
|
8789
8846
|
cut = "definitely-no-cut";
|
|
8790
8847
|
const host = inspection.marker;
|
|
8791
|
-
if (
|
|
8792
|
-
const
|
|
8793
|
-
|
|
8848
|
+
if (inspection.markerAtTarget) {
|
|
8849
|
+
const hostOrder = host ? compareOpenCodeMessagesByCanonicalOrder(sessionId, host.boundaryMessageId, boundary.id) : 0;
|
|
8850
|
+
if (hostOrder === null || hostOrder > 0) {
|
|
8851
|
+
reason = "ahead-of-target-left-alone";
|
|
8852
|
+
return {
|
|
8853
|
+
kind: cut,
|
|
8854
|
+
error: new Error("a later recorded host cut prevents target adoption")
|
|
8855
|
+
};
|
|
8856
|
+
}
|
|
8857
|
+
intended = { ...intended, ...inspection.markerAtTarget };
|
|
8858
|
+
recovered = pending && samePair(intended, pending) ? "pending-intent-recovered" : "adopted-existing-pair";
|
|
8794
8859
|
cut = "uncertain";
|
|
8795
|
-
|
|
8796
|
-
|
|
8797
|
-
|
|
8860
|
+
return { kind: "committed", marker: inspection.markerAtTarget };
|
|
8861
|
+
}
|
|
8862
|
+
if (host && pending && samePair(host, pending)) {
|
|
8863
|
+
recovered = "pending-intent-recovered";
|
|
8864
|
+
cut = "uncertain";
|
|
8865
|
+
persist(pending);
|
|
8798
8866
|
}
|
|
8799
8867
|
writingState = true;
|
|
8800
8868
|
raw = compareAndSetCompactionMarkerPublicationState(db, sessionId, raw, previous, intended);
|
|
8801
8869
|
writingState = false;
|
|
8802
8870
|
cut = "uncertain";
|
|
8803
|
-
const
|
|
8871
|
+
const ownedHost = host && (previous && samePair(host, previous) || pending && samePair(host, pending)) ? host : null;
|
|
8872
|
+
const replacement = replaceCompactionMarker(ownedHost, {
|
|
8804
8873
|
...args,
|
|
8805
8874
|
resolvedBoundary: boundary
|
|
8806
|
-
});
|
|
8875
|
+
}, true);
|
|
8807
8876
|
if (recovered && replacement.kind !== "committed")
|
|
8808
8877
|
return { kind: "uncertain", error: replacement.error };
|
|
8809
8878
|
if (replacement.kind !== "committed")
|
|
@@ -14074,6 +14143,7 @@ function createV1HiddenCompletionExecutor(client, db, directory) {
|
|
|
14074
14143
|
async attempt(handle, request) {
|
|
14075
14144
|
if (!client)
|
|
14076
14145
|
throw new Error("Hidden completion client is unavailable");
|
|
14146
|
+
hostErrors.delete(handle.id);
|
|
14077
14147
|
const identity = runIdentities.get(handle.id);
|
|
14078
14148
|
const requestedModel = request.body?.model;
|
|
14079
14149
|
const requestedRef = requestedModel && typeof requestedModel.providerID === "string" && typeof requestedModel.modelID === "string" ? `${requestedModel.providerID}/${requestedModel.modelID}` : undefined;
|
|
@@ -14116,9 +14186,9 @@ function createV1HiddenCompletionExecutor(client, db, directory) {
|
|
|
14116
14186
|
});
|
|
14117
14187
|
const assistantFailure = extractLatestAssistantFailure(messages);
|
|
14118
14188
|
const hostError = hostErrors.get(handle.id);
|
|
14119
|
-
if (assistantFailure) {
|
|
14120
|
-
const finish = assistantFailure
|
|
14121
|
-
const error = new Error(`Historian host recorded an assistant error${finish}: ${describeAssistantFailure(assistantFailure
|
|
14189
|
+
if (assistantFailure || hostError !== undefined) {
|
|
14190
|
+
const finish = assistantFailure?.finish ? ` (finish=${assistantFailure.finish})` : "";
|
|
14191
|
+
const error = new Error(`Historian host recorded an assistant error${finish}: ${describeAssistantFailure(assistantFailure?.error ?? hostError)}`, hostError === undefined ? undefined : { cause: hostError });
|
|
14122
14192
|
annotateSubagentInvocationError(error, {
|
|
14123
14193
|
attemptedModel: handle.attemptedModel,
|
|
14124
14194
|
modelConfigKey: handle.modelConfigKey,
|
|
@@ -16095,7 +16165,9 @@ function resolveProtectedTailBoundary(ctx) {
|
|
|
16095
16165
|
const offset = Math.max(1, ctx.lastCompartmentEndOrdinal + 1);
|
|
16096
16166
|
const absoluteMessageCount = getCachedAbsoluteMessageCount2(ctx.sessionId) ?? getRawSessionMessageOrdinalCount2(ctx.sessionId);
|
|
16097
16167
|
const messages = readRawSessionMessageRange2(ctx.sessionId, Math.max(1, offset - 1), absoluteMessageCount);
|
|
16098
|
-
const
|
|
16168
|
+
const storedWeights = ctx.storedTokenTotalsForMessages?.(messages.map((m) => m.id), messages);
|
|
16169
|
+
const storedTotals = storedWeights?.totals ?? ctx.storedTokenTotals;
|
|
16170
|
+
const storedRemovedTotals = storedWeights?.summaryRemovedTotals ?? ctx.storedSummaryRemovedTokenTotals;
|
|
16099
16171
|
const index = buildTrueRawTokenIndex(ctx.sessionId, messages, {
|
|
16100
16172
|
providerShapeVersion: ctx.providerShapeVersion,
|
|
16101
16173
|
cacheNamespace: ctx.cacheNamespace,
|
|
@@ -16106,6 +16178,14 @@ function resolveProtectedTailBoundary(ctx) {
|
|
|
16106
16178
|
return v === undefined ? null : v;
|
|
16107
16179
|
} : undefined
|
|
16108
16180
|
});
|
|
16181
|
+
const summaryRemovedIndex = buildTrueRawTokenIndex(ctx.sessionId, messages, {
|
|
16182
|
+
providerShapeVersion: ctx.providerShapeVersion,
|
|
16183
|
+
cacheNamespace: ctx.cacheNamespace,
|
|
16184
|
+
calibration: ctx.calibration,
|
|
16185
|
+
absoluteMessageCount,
|
|
16186
|
+
measure: "summary-removed",
|
|
16187
|
+
storedTotalForMessage: storedRemovedTotals ? (m) => storedRemovedTotals.get(m.id) ?? null : undefined
|
|
16188
|
+
});
|
|
16109
16189
|
const rawMessageCount = index.rawMessageCount;
|
|
16110
16190
|
const usagePercentage = clampPercentage(ctx.usage?.percentage ?? 0);
|
|
16111
16191
|
const usageInputTokens = Math.max(0, Math.round(ctx.usage?.inputTokens ?? 0));
|
|
@@ -16137,6 +16217,7 @@ function resolveProtectedTailBoundary(ctx) {
|
|
|
16137
16217
|
createdAt,
|
|
16138
16218
|
rawRangeFingerprint: "",
|
|
16139
16219
|
trueRawEligibleTokens: 0,
|
|
16220
|
+
summaryRemovedEligibleTokens: 0,
|
|
16140
16221
|
oversizeAtomicUnit: false,
|
|
16141
16222
|
boundaryReason: "empty-session"
|
|
16142
16223
|
};
|
|
@@ -16180,6 +16261,7 @@ function resolveProtectedTailBoundary(ctx) {
|
|
|
16180
16261
|
createdAt,
|
|
16181
16262
|
rawRangeFingerprint,
|
|
16182
16263
|
trueRawEligibleTokens: index.rangeTokens(offset, protectedTailStart),
|
|
16264
|
+
summaryRemovedEligibleTokens: summaryRemovedIndex.rangeTokens(offset, protectedTailStart),
|
|
16183
16265
|
oversizeAtomicUnit: false,
|
|
16184
16266
|
boundaryReason: firstOpenArc ? "open-tool-arc" : "manual-full-recomp"
|
|
16185
16267
|
};
|
|
@@ -16256,7 +16338,7 @@ function resolveProtectedTailBoundary(ctx) {
|
|
|
16256
16338
|
observeDiagnostics: (value) => {
|
|
16257
16339
|
headDiagnostics = value;
|
|
16258
16340
|
},
|
|
16259
|
-
index,
|
|
16341
|
+
index: summaryRemovedIndex,
|
|
16260
16342
|
protectedTailStart,
|
|
16261
16343
|
offset,
|
|
16262
16344
|
arcs,
|
|
@@ -16295,6 +16377,7 @@ function resolveProtectedTailBoundary(ctx) {
|
|
|
16295
16377
|
createdAt,
|
|
16296
16378
|
rawRangeFingerprint,
|
|
16297
16379
|
trueRawEligibleTokens: index.rangeTokens(offset, eligibleEndOrdinal),
|
|
16380
|
+
summaryRemovedEligibleTokens: summaryRemovedIndex.rangeTokens(offset, eligibleEndOrdinal),
|
|
16298
16381
|
oversizeAtomicUnit: head.oversizeAtomicUnit,
|
|
16299
16382
|
boundaryReason,
|
|
16300
16383
|
diagnostics: boundaryDiagnostics({
|
|
@@ -16342,8 +16425,11 @@ function resolveBoundaryContext(args) {
|
|
|
16342
16425
|
const calibration = sessionDecisionCalibration(args.db, args.sessionId);
|
|
16343
16426
|
const storedTokenTotalsForMessages = (messageIds, messages = []) => {
|
|
16344
16427
|
try {
|
|
16345
|
-
const
|
|
16346
|
-
return
|
|
16428
|
+
const weights = getAllStatusTagTokenTotalsFlat2(args.db, args.sessionId, args.taggerFloor ?? 0, calibration, messageIds);
|
|
16429
|
+
return {
|
|
16430
|
+
totals: omitIncompleteFileTokenTotals(args.db, args.sessionId, messages, weights.totals),
|
|
16431
|
+
summaryRemovedTotals: weights.summaryRemovedTotals
|
|
16432
|
+
};
|
|
16347
16433
|
} catch (error) {
|
|
16348
16434
|
sessionLog2(args.sessionId, "protected-tail stored-token map unavailable (live fallback):", error);
|
|
16349
16435
|
return;
|
|
@@ -16379,7 +16465,9 @@ function resolveWrapupProtectedTailBoundary(args) {
|
|
|
16379
16465
|
const offset = Math.max(1, ctx.lastCompartmentEndOrdinal + 1);
|
|
16380
16466
|
const absoluteMessageCount = getCachedAbsoluteMessageCount2(ctx.sessionId) ?? getRawSessionMessageOrdinalCount2(ctx.sessionId);
|
|
16381
16467
|
const messages = readRawSessionMessageRange2(ctx.sessionId, Math.max(1, offset - 1), absoluteMessageCount);
|
|
16382
|
-
const
|
|
16468
|
+
const storedWeights = ctx.storedTokenTotalsForMessages?.(messages.map((m) => m.id), messages);
|
|
16469
|
+
const storedTotals = storedWeights?.totals ?? ctx.storedTokenTotals;
|
|
16470
|
+
const storedRemovedTotals = storedWeights?.summaryRemovedTotals ?? ctx.storedSummaryRemovedTokenTotals;
|
|
16383
16471
|
const index = buildTrueRawTokenIndex(ctx.sessionId, messages, {
|
|
16384
16472
|
providerShapeVersion: ctx.providerShapeVersion,
|
|
16385
16473
|
cacheNamespace: ctx.cacheNamespace,
|
|
@@ -16390,6 +16478,14 @@ function resolveWrapupProtectedTailBoundary(args) {
|
|
|
16390
16478
|
return value === undefined ? null : value;
|
|
16391
16479
|
} : undefined
|
|
16392
16480
|
});
|
|
16481
|
+
const summaryRemovedIndex = buildTrueRawTokenIndex(ctx.sessionId, messages, {
|
|
16482
|
+
providerShapeVersion: ctx.providerShapeVersion,
|
|
16483
|
+
cacheNamespace: ctx.cacheNamespace,
|
|
16484
|
+
calibration: ctx.calibration,
|
|
16485
|
+
absoluteMessageCount,
|
|
16486
|
+
measure: "summary-removed",
|
|
16487
|
+
storedTotalForMessage: storedRemovedTotals ? (m) => storedRemovedTotals.get(m.id) ?? null : undefined
|
|
16488
|
+
});
|
|
16393
16489
|
const rawMessageCount = index.rawMessageCount;
|
|
16394
16490
|
const anchorRawMessageCount = Math.max(0, Math.min(rawMessageCount, Math.floor(args.anchorRawMessageCount ?? rawMessageCount)));
|
|
16395
16491
|
const usagePercentage = clampPercentage(ctx.usage?.percentage ?? 0);
|
|
@@ -16451,7 +16547,7 @@ function resolveWrapupProtectedTailBoundary(args) {
|
|
|
16451
16547
|
observeDiagnostics: (value) => {
|
|
16452
16548
|
headDiagnostics = value;
|
|
16453
16549
|
},
|
|
16454
|
-
index,
|
|
16550
|
+
index: summaryRemovedIndex,
|
|
16455
16551
|
protectedTailStart: targetProtectedTailStart,
|
|
16456
16552
|
offset,
|
|
16457
16553
|
arcs: buildToolArcs(messages),
|
|
@@ -16488,6 +16584,7 @@ function resolveWrapupProtectedTailBoundary(args) {
|
|
|
16488
16584
|
createdAt,
|
|
16489
16585
|
rawRangeFingerprint,
|
|
16490
16586
|
trueRawEligibleTokens: index.rangeTokens(offset, targetProtectedTailStart),
|
|
16587
|
+
summaryRemovedEligibleTokens: summaryRemovedIndex.rangeTokens(offset, eligibleEndOrdinal),
|
|
16491
16588
|
oversizeAtomicUnit: head.oversizeAtomicUnit,
|
|
16492
16589
|
boundaryReason,
|
|
16493
16590
|
diagnostics: boundaryDiagnostics({
|
|
@@ -17094,7 +17191,7 @@ async function runCompartmentAgent(deps) {
|
|
|
17094
17191
|
db,
|
|
17095
17192
|
sessionId,
|
|
17096
17193
|
runId: crypto.randomUUID(),
|
|
17097
|
-
trueRawTokens: boundarySnapshot.
|
|
17194
|
+
trueRawTokens: boundarySnapshot.summaryRemovedEligibleTokens,
|
|
17098
17195
|
usagePercentage: boundarySnapshot.usagePercentage,
|
|
17099
17196
|
usable,
|
|
17100
17197
|
perRunCap,
|