@cortexkit/opencode-magic-context 0.49.45 → 0.49.47
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 +1 -1
- package/dist/chunk-embedding-write-worker.js +1 -1
- package/dist/{context-y85dvs6j.js → context-hvkjxqhs.js} +416 -106
- package/dist/{derive-budgets-htj16n4x.js → derive-budgets-nkw09vq7.js} +1 -1
- package/dist/features/magic-context/request-tool-definitions.d.ts +57 -0
- package/dist/features/magic-context/request-tool-definitions.d.ts.map +1 -1
- package/dist/hooks/magic-context/cache-busting-signals.d.ts +6 -3
- package/dist/hooks/magic-context/cache-busting-signals.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-runner-incremental.d.ts.map +1 -1
- package/dist/hooks/magic-context/host-checkpoint-ride.d.ts +80 -0
- package/dist/hooks/magic-context/host-checkpoint-ride.d.ts.map +1 -0
- package/dist/hooks/magic-context/inject-compartments.d.ts +21 -0
- package/dist/hooks/magic-context/inject-compartments.d.ts.map +1 -1
- package/dist/hooks/magic-context/latest-thinking-recovery.d.ts +19 -0
- package/dist/hooks/magic-context/latest-thinking-recovery.d.ts.map +1 -1
- package/dist/hooks/magic-context/pending-materialization.d.ts +3 -0
- package/dist/hooks/magic-context/pending-materialization.d.ts.map +1 -1
- package/dist/hooks/magic-context/priced-pass-sizing.d.ts +132 -0
- package/dist/hooks/magic-context/priced-pass-sizing.d.ts.map +1 -0
- package/dist/hooks/magic-context/reasoning-budget.d.ts.map +1 -1
- package/dist/hooks/magic-context/recovery-fit.d.ts +51 -0
- package/dist/hooks/magic-context/recovery-fit.d.ts.map +1 -0
- package/dist/hooks/magic-context/request-tools-release.d.ts +26 -0
- package/dist/hooks/magic-context/request-tools-release.d.ts.map +1 -0
- package/dist/hooks/magic-context/routine-cleanup-decision.d.ts +109 -0
- package/dist/hooks/magic-context/routine-cleanup-decision.d.ts.map +1 -0
- package/dist/hooks/magic-context/rust-mode-transform.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform-compartment-phase.d.ts +24 -0
- package/dist/hooks/magic-context/transform-compartment-phase.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform-context-state.d.ts +2 -1
- package/dist/hooks/magic-context/transform-context-state.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform-postprocess-phase.d.ts +22 -2
- package/dist/hooks/magic-context/transform-postprocess-phase.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform.d.ts +19 -2
- package/dist/hooks/magic-context/transform.d.ts.map +1 -1
- package/dist/{index-jwa5t1s4.js → index-1qmv26ga.js} +17 -4
- package/dist/{index-0a79y98x.js → index-2x3kd999.js} +301 -90
- package/dist/{index-qdx8dq60.js → index-37a9bfta.js} +4 -4
- package/dist/{index-tvd2j34s.js → index-44pp3vrj.js} +1 -1
- package/dist/{index-980brvjr.js → index-5jk4h64j.js} +3 -3
- package/dist/{index-66a50f3e.js → index-6athgjba.js} +66 -14
- package/dist/{index-dnqqqc5f.js → index-8cfnaagj.js} +10 -2
- package/dist/{index-z8dacvkt.js → index-b0xt5qz9.js} +1 -1
- package/dist/{index-xejh7cqv.js → index-bqhjzhv4.js} +173 -9
- package/dist/{index-fs3zfby1.js → index-c99tqfge.js} +724 -98
- package/dist/{index-dcdvyaeh.js → index-eej9kwad.js} +3 -3
- package/dist/{index-rk5hyc41.js → index-esr8qcc4.js} +2 -2
- package/dist/{index-bzq05g00.js → index-etn2hmb5.js} +1 -1
- package/dist/{index-gf1vx3bn.js → index-kw7azjmy.js} +2 -2
- package/dist/{index-29gd1zcx.js → index-w6fh4v87.js} +1 -1
- package/dist/{index-gxqr0sbd.js → index-x53gnmce.js} +10 -10
- package/dist/{index-7na94cjf.js → index-xgczbhyx.js} +5 -5
- package/dist/{index-wwg1je98.js → index-xgnh498s.js} +3 -2
- package/dist/index.js +20 -20
- package/dist/{message-index-bounded-d8xt6q5c.js → message-index-bounded-3qpg8dq5.js} +3 -3
- package/dist/migration-worker.js +1 -1
- package/dist/raw-ordinal-warmup-worker.js +4 -4
- package/dist/{read-session-chunk-k3fqshw8.js → read-session-chunk-7h9f32sz.js} +2 -2
- package/dist/{recomp-orchestrator-y75thsc3.js → recomp-orchestrator-43g9tjya.js} +9 -9
- package/dist/{render-3psbedzk.js → render-4m7x9cq4.js} +7 -7
- package/dist/{search-hd16c8gq.js → search-0a3hh5x6.js} +5 -5
- package/dist/{search-archive-rvr7j5gx.js → search-archive-f6kwv02s.js} +4 -4
- package/dist/shared/window-geometry.d.ts +5 -0
- package/dist/shared/window-geometry.d.ts.map +1 -1
- package/dist/{storage-tags-ye9aqrqy.js → storage-tags-q8erkn48.js} +3 -1
- package/dist/{store-pd1e9hnr.js → store-h20ny8b8.js} +2 -2
- package/dist/{store-reader-yh19h38c.js → store-reader-3eh1s1m8.js} +1 -1
- package/dist/tools/parameter-descriptions.d.ts +6 -6
- package/dist/tools/parameter-descriptions.d.ts.map +1 -1
- package/dist/{transform-postprocess-phase-1rzxmkhb.js → transform-postprocess-phase-5746a5b6.js} +10 -10
- package/dist/v2/auto-search-worker.js +1 -1
- package/dist/v2/chunk-embedding-write-worker.js +1 -1
- package/dist/v2/{context-0e946t63.js → context-e9n2mxax.js} +1424 -295
- package/dist/v2/{derive-budgets-sa0v7bz0.js → derive-budgets-b5cgrtp8.js} +2 -2
- package/dist/v2/fold/code-mode-catalog.d.ts +11 -3
- package/dist/v2/fold/code-mode-catalog.d.ts.map +1 -1
- package/dist/v2/fold/instruction-supersession.d.ts +13 -2
- package/dist/v2/fold/instruction-supersession.d.ts.map +1 -1
- package/dist/v2/fold/manual-baseline.d.ts +7 -0
- package/dist/v2/fold/manual-baseline.d.ts.map +1 -1
- package/dist/v2/fold/native-replay.d.ts +5 -0
- package/dist/v2/fold/native-replay.d.ts.map +1 -1
- package/dist/v2/fold/owner.d.ts +14 -0
- package/dist/v2/fold/owner.d.ts.map +1 -1
- package/dist/v2/fold/summary.d.ts +35 -0
- package/dist/v2/fold/summary.d.ts.map +1 -1
- package/dist/v2/hooks/context.d.ts +10 -1
- package/dist/v2/hooks/context.d.ts.map +1 -1
- package/dist/v2/hooks/lkg-system.d.ts +3 -0
- package/dist/v2/hooks/lkg-system.d.ts.map +1 -1
- package/dist/v2/{message-index-bounded-wt64v2rn.js → message-index-bounded-na8debr6.js} +3 -3
- package/dist/v2/migration-worker.js +1 -1
- package/dist/v2/raw-ordinal-warmup-worker.js +4 -4
- package/dist/v2/{read-session-chunk-4b31z6bz.js → read-session-chunk-x33xeg2g.js} +2 -2
- package/dist/v2/{recomp-orchestrator-6qrm2nea.js → recomp-orchestrator-jyjpn5jm.js} +10 -10
- package/dist/v2/{render-f8mw16pp.js → render-mp82ns36.js} +7 -7
- package/dist/v2/{search-archive-7d0xdp54.js → search-archive-d0fcqch9.js} +4 -4
- package/dist/v2/{search-ecjd7e50.js → search-ebd0yr40.js} +4 -4
- package/dist/v2/{server-wbxbk3za.js → server-1f03b92k.js} +2 -2
- package/dist/v2/{server-ymn9w46x.js → server-5zzt9rah.js} +1 -1
- package/dist/v2/{server-sd8hvzte.js → server-af1rmkyn.js} +1 -1
- package/dist/v2/{server-vnpnmrsv.js → server-c43zxc9k.js} +27 -3
- package/dist/v2/{server-hq7fdqfm.js → server-epvj1cey.js} +2 -2
- package/dist/v2/{server-39kzpp8q.js → server-fhxe5jgm.js} +2 -2
- package/dist/v2/{server-0ymsgh0j.js → server-gy26cwvw.js} +1 -1
- package/dist/v2/{server-zqzh2ybj.js → server-rg92e592.js} +175 -11
- package/dist/v2/{server-ef1mskas.js → server-rthnpmbp.js} +66 -14
- package/dist/v2/{server-gwqfwtzq.js → server-t4hk02v1.js} +10 -10
- package/dist/v2/{server-vjhk8v41.js → server-wa4qhryh.js} +1 -1
- package/dist/v2/{server-an1ff8d8.js → server-wwmaqtxy.js} +5 -5
- package/dist/v2/{server-2qyfev3b.js → server-xsrykjkj.js} +17 -4
- package/dist/v2/{server-qxzbmtqt.js → server-zt1m5rwj.js} +10 -2
- package/dist/v2/{server-ftyc8awt.js → server-zypeavf0.js} +1 -1
- package/dist/v2/server.js +4 -4
- package/dist/v2/{storage-tags-8nttt1sk.js → storage-tags-ztar1k0g.js} +3 -1
- package/dist/v2/{store-reader-cgx47zkp.js → store-reader-yaxtdy6f.js} +1 -1
- package/dist/v2/store-reader.d.ts +22 -1
- package/dist/v2/store-reader.d.ts.map +1 -1
- package/dist/v2/{store-pebs9m52.js → store-skkhh3rd.js} +2 -2
- package/dist/v2/{v2-archive-reader-53kp5mme.js → v2-archive-reader-gm6mygag.js} +1 -1
- package/dist/v2/{wrapup-orchestrator-bng0dfxy.js → wrapup-orchestrator-y9a02xpd.js} +10 -10
- package/dist/{v2-archive-reader-0fcxs5e9.js → v2-archive-reader-yp9956t8.js} +1 -1
- package/dist/{wrapup-orchestrator-r5cqgyrg.js → wrapup-orchestrator-ese0epyk.js} +10 -10
- package/package.json +1 -1
- package/src/agents/smart-notes-dreamer-gate.golden.json +169 -169
- package/src/shared/prompt-surface-a1-golden.md +4 -4
- package/src/shared/window-geometry.test.ts +85 -0
- package/src/shared/window-geometry.ts +29 -2
|
@@ -137,6 +137,7 @@ import {
|
|
|
137
137
|
getMural,
|
|
138
138
|
modelKeyAcceptsImages,
|
|
139
139
|
resolveMuralWire,
|
|
140
|
+
classifyRequestToolsChange,
|
|
140
141
|
USER_MEMORY_CANDIDATE_TTL_MS,
|
|
141
142
|
insertUserMemoryCandidates,
|
|
142
143
|
getUserMemoryCandidates,
|
|
@@ -164,6 +165,9 @@ import {
|
|
|
164
165
|
renderMemoryBlockV2,
|
|
165
166
|
findHostCompactionWindow,
|
|
166
167
|
capturePrefixTrimSourceOrder,
|
|
168
|
+
headMessagesForSizing,
|
|
169
|
+
rawTailAfterNewestCompartment,
|
|
170
|
+
hasCompleteCachedM0M1,
|
|
167
171
|
resolveHiddenCompletionExecutor,
|
|
168
172
|
createV1HiddenCompletionExecutor,
|
|
169
173
|
readCoordinateGeneration,
|
|
@@ -191,7 +195,7 @@ import {
|
|
|
191
195
|
snapRangeToCompartments,
|
|
192
196
|
getActiveCompartmentRun,
|
|
193
197
|
startCompartmentAgent
|
|
194
|
-
} from "./index-
|
|
198
|
+
} from "./index-bqhjzhv4.js";
|
|
195
199
|
import {
|
|
196
200
|
hasTrustedAbsoluteWall,
|
|
197
201
|
applyProvenInputFloor,
|
|
@@ -203,7 +207,7 @@ import {
|
|
|
203
207
|
deriveTriggerBudget2,
|
|
204
208
|
resolveKnownHistorianContextLimit2,
|
|
205
209
|
resolveHistorianProducerLimits2
|
|
206
|
-
} from "./index-
|
|
210
|
+
} from "./index-8cfnaagj.js";
|
|
207
211
|
import {
|
|
208
212
|
resolveModelCalibration,
|
|
209
213
|
calibrateBuckets,
|
|
@@ -244,6 +248,7 @@ import {
|
|
|
244
248
|
getTriggerTagTokenUpperBound2,
|
|
245
249
|
getActiveTagTokenTotalsByMessage2,
|
|
246
250
|
tryGetReasoningTokenEstimatesByMessage2,
|
|
251
|
+
TagOwnerSummaryNotReady2,
|
|
247
252
|
isTagOwnerSummaryReady2,
|
|
248
253
|
updateTagStatus2,
|
|
249
254
|
getInertWhitespaceAssistantTagsByNumbers2,
|
|
@@ -254,7 +259,7 @@ import {
|
|
|
254
259
|
getTagsByNumbers2,
|
|
255
260
|
getDroppedTagsByNumbers2,
|
|
256
261
|
getMaxDroppedTagNumber2
|
|
257
|
-
} from "./index-
|
|
262
|
+
} from "./index-x53gnmce.js";
|
|
258
263
|
import {
|
|
259
264
|
observeTemporalDecisions,
|
|
260
265
|
stableStringify
|
|
@@ -358,6 +363,7 @@ import {
|
|
|
358
363
|
getPersistedCompactionMarkerState,
|
|
359
364
|
setPersistedCompactionMarkerState,
|
|
360
365
|
getStrippedPlaceholderIds,
|
|
366
|
+
THINKING_BINDING_RECOVERY_FROZEN_PREFIX,
|
|
361
367
|
thinkingBindingRecoveryFrozenId,
|
|
362
368
|
getThinkingBindingRecoveryTarget,
|
|
363
369
|
armThinkingBindingRecovery,
|
|
@@ -371,6 +377,8 @@ import {
|
|
|
371
377
|
clearPendingCompactionMarkerStateIf,
|
|
372
378
|
getObservedEpochFloor,
|
|
373
379
|
resolveEpochFloorForPass,
|
|
380
|
+
getReasoningRemovalState,
|
|
381
|
+
detectThinkingBindingMismatch,
|
|
374
382
|
detectLatestTurnThinkingMismatch,
|
|
375
383
|
isPrefixBoundThinkingModel,
|
|
376
384
|
detectOverflow,
|
|
@@ -383,10 +391,12 @@ import {
|
|
|
383
391
|
stripClearedReasoning,
|
|
384
392
|
findReasoningBearingAssistantIds,
|
|
385
393
|
snapshotTrailingBlankSourceDecisions,
|
|
394
|
+
stripReasoningFromAssistantIds,
|
|
386
395
|
projectOpencodeReasoningBudgetCutoff,
|
|
387
396
|
resolveKeepReasoningTokens,
|
|
388
397
|
reasoningStepCost,
|
|
389
398
|
reasoningBudgetCutoff,
|
|
399
|
+
opencodeReasoningBudgetCutoff,
|
|
390
400
|
describeFinalWireTail,
|
|
391
401
|
estimateMessageTokens,
|
|
392
402
|
wireContentBytes,
|
|
@@ -416,7 +426,7 @@ import {
|
|
|
416
426
|
readRawSessionMessageById2,
|
|
417
427
|
readSessionChunk2,
|
|
418
428
|
readRawSessionSeedTail2
|
|
419
|
-
} from "./index-
|
|
429
|
+
} from "./index-xgnh498s.js";
|
|
420
430
|
import {
|
|
421
431
|
BoundedSessionMap,
|
|
422
432
|
getMeasuredToolDefinitionTokens
|
|
@@ -446,7 +456,7 @@ import {
|
|
|
446
456
|
runSqliteOptimize,
|
|
447
457
|
openDatabase,
|
|
448
458
|
openCurrentDatabase
|
|
449
|
-
} from "./index-
|
|
459
|
+
} from "./index-b0xt5qz9.js";
|
|
450
460
|
import {
|
|
451
461
|
unescapeXml,
|
|
452
462
|
resolveWorkspaceShareCategories,
|
|
@@ -555,10 +565,10 @@ import {
|
|
|
555
565
|
GLOBAL_USER_PROFILE_PROJECT_PATH,
|
|
556
566
|
getProjectState,
|
|
557
567
|
bumpProjectUserProfileVersion
|
|
558
|
-
} from "./index-
|
|
568
|
+
} from "./index-1qmv26ga.js";
|
|
559
569
|
import {
|
|
560
570
|
getLastIndexedOrdinal
|
|
561
|
-
} from "./index-
|
|
571
|
+
} from "./index-etn2hmb5.js";
|
|
562
572
|
import {
|
|
563
573
|
SESSION_NOTE_CONDITION_ERROR,
|
|
564
574
|
getNoteByIdInScope,
|
|
@@ -692,13 +702,13 @@ import {
|
|
|
692
702
|
resolveMemoriesByIdsForSearch2,
|
|
693
703
|
unifiedSearch2,
|
|
694
704
|
formatSearchResults2
|
|
695
|
-
} from "./index-
|
|
705
|
+
} from "./index-5jk4h64j.js";
|
|
696
706
|
import {
|
|
697
707
|
scheduleReconciliation,
|
|
698
708
|
scheduleIncrementalIndex,
|
|
699
709
|
getMessageIndexQueueHeapStats,
|
|
700
710
|
clearSessionTracking
|
|
701
|
-
} from "./index-
|
|
711
|
+
} from "./index-44pp3vrj.js";
|
|
702
712
|
import {
|
|
703
713
|
flushIgnoredMessages2,
|
|
704
714
|
clearIgnoredMessages2,
|
|
@@ -708,7 +718,7 @@ import {
|
|
|
708
718
|
import {
|
|
709
719
|
setRecompStarting2,
|
|
710
720
|
setRecompTerminal2
|
|
711
|
-
} from "./index-
|
|
721
|
+
} from "./index-eej9kwad.js";
|
|
712
722
|
import {
|
|
713
723
|
makeToolCompositeKey,
|
|
714
724
|
searchMessageHistoryOffThread,
|
|
@@ -746,12 +756,25 @@ import {
|
|
|
746
756
|
outgoingContextRefusal,
|
|
747
757
|
signedTurnContextRefusal,
|
|
748
758
|
EmergencyFailClosedError,
|
|
759
|
+
removeReasoningParts,
|
|
749
760
|
latestAssistantTurnStart,
|
|
750
761
|
latestAssistantTurnMessages,
|
|
751
762
|
hasActiveAnthropicThinkingTurn,
|
|
763
|
+
retainedActiveThinkingParts,
|
|
752
764
|
replayCavemanCompression,
|
|
753
765
|
DegradedPassRefusalError,
|
|
754
766
|
degradedPassError,
|
|
767
|
+
revertHostCheckpointPass,
|
|
768
|
+
forgetHostCheckpointPass,
|
|
769
|
+
hostInstructionRetentionEnabled,
|
|
770
|
+
isHostInstructionRetentionOn,
|
|
771
|
+
pressureBands,
|
|
772
|
+
forceRide,
|
|
773
|
+
heuristicsRunOnPass,
|
|
774
|
+
routineCleanupRunsOnPass,
|
|
775
|
+
heuristicsAlreadyRanThisTurn,
|
|
776
|
+
routinePressureAlreadyApplied,
|
|
777
|
+
safeReasoningCutoff,
|
|
755
778
|
isStructuralNoiseSentinel,
|
|
756
779
|
stripStructuralNoise,
|
|
757
780
|
prepareStructuralSentinelChoices,
|
|
@@ -773,7 +796,7 @@ import {
|
|
|
773
796
|
abortSessionFailClosed2,
|
|
774
797
|
evaluateEmergencyFailClosed2,
|
|
775
798
|
runPostTransformPhase2
|
|
776
|
-
} from "./index-
|
|
799
|
+
} from "./index-2x3kd999.js";
|
|
777
800
|
import {
|
|
778
801
|
ANNOUNCEMENT_VERSION2,
|
|
779
802
|
ANNOUNCEMENT_FEATURES2,
|
|
@@ -788,13 +811,13 @@ import {
|
|
|
788
811
|
renderMessageByOrdinal2,
|
|
789
812
|
renderVerboseRangeForTool2,
|
|
790
813
|
renderItemByTag2
|
|
791
|
-
} from "./index-
|
|
814
|
+
} from "./index-kw7azjmy.js";
|
|
792
815
|
import {
|
|
793
816
|
readV2ArchiveOffThread2
|
|
794
|
-
} from "./index-
|
|
817
|
+
} from "./index-xgczbhyx.js";
|
|
795
818
|
import {
|
|
796
819
|
renderSearchArchiveOffThread2
|
|
797
|
-
} from "./index-
|
|
820
|
+
} from "./index-esr8qcc4.js";
|
|
798
821
|
import {
|
|
799
822
|
COMPACTION_ENABLED_PATH,
|
|
800
823
|
isDreamerRunnable,
|
|
@@ -16352,7 +16375,7 @@ function registerRpcHandlers(rpcServer, args) {
|
|
|
16352
16375
|
return { count: buildCompartmentCount(db, sessionId, moduleStatus) };
|
|
16353
16376
|
});
|
|
16354
16377
|
const buildManagedCtx = async (db) => {
|
|
16355
|
-
const { deriveHistorianChunkTokens, resolveHistorianContextLimit } = await importPluginModule(() => import("./derive-budgets-
|
|
16378
|
+
const { deriveHistorianChunkTokens, resolveHistorianContextLimit } = await importPluginModule(() => import("./derive-budgets-nkw09vq7.js"));
|
|
16356
16379
|
const { resolveHistorianModel } = await importPluginModule(() => import("./model-resolution-280gmqvd.js"));
|
|
16357
16380
|
const { userObservationCollectionEnabled, userObservationsRequested } = await importPluginModule(() => import("./task-config-t6bpyka7.js"));
|
|
16358
16381
|
const DEFAULT_HISTORIAN_TIMEOUT_MS = 10 * 60 * 1000;
|
|
@@ -16404,7 +16427,7 @@ function registerRpcHandlers(rpcServer, args) {
|
|
|
16404
16427
|
const db = readDatabase();
|
|
16405
16428
|
if (!db)
|
|
16406
16429
|
return { ok: false, error: "db unavailable" };
|
|
16407
|
-
const { runManagedRecomp } = await importPluginModule(() => import("./recomp-orchestrator-
|
|
16430
|
+
const { runManagedRecomp } = await importPluginModule(() => import("./recomp-orchestrator-43g9tjya.js"));
|
|
16408
16431
|
const { sendIgnoredMessage } = await importPluginModule(() => import("./send-session-notification-j93pn2hn.js"));
|
|
16409
16432
|
log2(`[rpc] recomp requested for session ${sessionId}`);
|
|
16410
16433
|
if (!args.client && !args.hiddenCompletionExecutor) {
|
|
@@ -16489,7 +16512,7 @@ function registerRpcHandlers(rpcServer, args) {
|
|
|
16489
16512
|
const db = readDatabase();
|
|
16490
16513
|
if (!db)
|
|
16491
16514
|
return { ok: false, error: "db unavailable" };
|
|
16492
|
-
const { runManagedWrapup } = await importPluginModule(() => import("./wrapup-orchestrator-
|
|
16515
|
+
const { runManagedWrapup } = await importPluginModule(() => import("./wrapup-orchestrator-ese0epyk.js"));
|
|
16493
16516
|
const model = liveSessionState.liveModelBySession.get(sessionId);
|
|
16494
16517
|
const contextLimit = model ? resolveContextLimit(model.providerID, model.modelID, { db, sessionID: sessionId }) : 128000;
|
|
16495
16518
|
const ctx = {
|
|
@@ -17239,6 +17262,17 @@ function armLatestThinkingRecoveryFromError(args) {
|
|
|
17239
17262
|
dropSlot(args.sessionId, "latest-thinking-recovery-arm");
|
|
17240
17263
|
return true;
|
|
17241
17264
|
}
|
|
17265
|
+
function armThinkingBindingRecoveryFromError(args) {
|
|
17266
|
+
const mismatch = detectThinkingBindingMismatch(args.error);
|
|
17267
|
+
if (!mismatch.isBindingMismatch)
|
|
17268
|
+
return false;
|
|
17269
|
+
if (!isPrefixBoundThinkingModel(args.providerID, args.modelID))
|
|
17270
|
+
return true;
|
|
17271
|
+
armBindingRecoverySafely(args.db, args.sessionId);
|
|
17272
|
+
sessionLog2(args.sessionId, `thinking binding recovery armed from ${args.source} (provider paths: failing=${mismatch.failingBlockPath ?? "?"} firstChanged=${mismatch.firstChangedPath ?? "?"})`);
|
|
17273
|
+
dropSlot(args.sessionId, "thinking-binding-recovery-arm");
|
|
17274
|
+
return true;
|
|
17275
|
+
}
|
|
17242
17276
|
|
|
17243
17277
|
// src/hooks/magic-context/compaction-off-transition.ts
|
|
17244
17278
|
import { existsSync as existsSync7 } from "node:fs";
|
|
@@ -17497,6 +17531,192 @@ function createPassOutcome() {
|
|
|
17497
17531
|
};
|
|
17498
17532
|
}
|
|
17499
17533
|
|
|
17534
|
+
// src/hooks/magic-context/priced-pass-sizing.ts
|
|
17535
|
+
var REASONING_PART_TYPES = new Set(["reasoning", "thinking", "redacted_thinking"]);
|
|
17536
|
+
var WIDEST_PRICED_PASS_PLAN = {
|
|
17537
|
+
editsWholePrefix: true,
|
|
17538
|
+
clearsReasoning: false
|
|
17539
|
+
};
|
|
17540
|
+
function planPricedPass(input, usage) {
|
|
17541
|
+
const bands = pressureBands({
|
|
17542
|
+
percentage: usage.percentage,
|
|
17543
|
+
fromEstimate: usage.fromEstimate,
|
|
17544
|
+
forceMaterializationPercentage: input.forceMaterializationPercentage,
|
|
17545
|
+
compactionOff: input.compactionOff,
|
|
17546
|
+
fullFeatureMode: input.fullFeatureMode,
|
|
17547
|
+
schedulerDecision: input.schedulerDecision
|
|
17548
|
+
});
|
|
17549
|
+
const emergencySample = () => getEmergencyInputSample(input.db, input.sessionId);
|
|
17550
|
+
const rides = {
|
|
17551
|
+
hardFold: input.folds || input.firstRender,
|
|
17552
|
+
force: forceRide({
|
|
17553
|
+
bands,
|
|
17554
|
+
percentage: usage.percentage,
|
|
17555
|
+
fromEstimate: usage.fromEstimate,
|
|
17556
|
+
emergencySample
|
|
17557
|
+
}),
|
|
17558
|
+
explicitFlush: input.explicitFlush,
|
|
17559
|
+
publishedHistory: false,
|
|
17560
|
+
subagentExecute: !input.fullFeatureMode && input.schedulerDecision === "execute",
|
|
17561
|
+
executeReclaim: false,
|
|
17562
|
+
servedShapeRepair: false
|
|
17563
|
+
};
|
|
17564
|
+
const drainAllowed = !input.compactionOff && reclaimRidePermitted(rides, {
|
|
17565
|
+
signedThinkingHold: input.signedThinkingHold,
|
|
17566
|
+
firstRender: input.firstRender,
|
|
17567
|
+
emergency: bands.forceBandConfirmed
|
|
17568
|
+
});
|
|
17569
|
+
const materializationRequested = !input.signedThinkingHold && input.materializationRequested;
|
|
17570
|
+
const heuristics = heuristicsRunOnPass({
|
|
17571
|
+
compactionOff: input.compactionOff,
|
|
17572
|
+
drainAllowed,
|
|
17573
|
+
rides,
|
|
17574
|
+
materializationRequested,
|
|
17575
|
+
bands,
|
|
17576
|
+
foldBustsServedPrefix: input.folds,
|
|
17577
|
+
firstRender: input.firstRender,
|
|
17578
|
+
schedulerDecision: input.schedulerDecision,
|
|
17579
|
+
alreadyRanThisTurn: input.alreadyRanThisTurn,
|
|
17580
|
+
fullFeatureMode: input.fullFeatureMode
|
|
17581
|
+
});
|
|
17582
|
+
const routine = heuristics && routineCleanupRunsOnPass({
|
|
17583
|
+
bands,
|
|
17584
|
+
percentage: usage.percentage,
|
|
17585
|
+
emergencySample,
|
|
17586
|
+
fullFeatureMode: input.fullFeatureMode,
|
|
17587
|
+
routinePressureAlreadyApplied: routinePressureAlreadyApplied(input.sessionId, {
|
|
17588
|
+
fullFeatureMode: input.fullFeatureMode,
|
|
17589
|
+
executePressureEligible: bands.executePressureEligible,
|
|
17590
|
+
alreadyRanThisTurn: input.alreadyRanThisTurn
|
|
17591
|
+
}),
|
|
17592
|
+
materializationRequested,
|
|
17593
|
+
rewriteAlreadyPriced: input.folds || input.firstRender || input.historyRebuilt
|
|
17594
|
+
});
|
|
17595
|
+
return {
|
|
17596
|
+
editsWholePrefix: drainAllowed && !input.signedThinkingHold,
|
|
17597
|
+
clearsReasoning: routine && !input.signedThinkingHold
|
|
17598
|
+
};
|
|
17599
|
+
}
|
|
17600
|
+
function sameSizingPlan(input, a, b) {
|
|
17601
|
+
const rowsDiffer = a.editsWholePrefix !== b.editsWholePrefix && input.coveredInstructions.length > 0 && hostInstructionRetentionEnabled() && !isHostInstructionRetentionOn(input.db, input.sessionId);
|
|
17602
|
+
const reasoningDiffers = a.clearsReasoning !== b.clearsReasoning && input.reasoning !== undefined;
|
|
17603
|
+
return !rowsDiffer && !reasoningDiffers;
|
|
17604
|
+
}
|
|
17605
|
+
function protectedThinkingMessagesForSizing(args) {
|
|
17606
|
+
if (!args.activeThinkingTurn)
|
|
17607
|
+
return new Set;
|
|
17608
|
+
const mergedIds = getMergedReasoningStrippedIds(args.db, args.sessionId);
|
|
17609
|
+
const bindingIds = new Set([...mergedIds].filter((id) => id.startsWith(THINKING_BINDING_RECOVERY_FROZEN_PREFIX)).map((id) => id.slice(THINKING_BINDING_RECOVERY_FROZEN_PREFIX.length)));
|
|
17610
|
+
const retained = retainedActiveThinkingParts({
|
|
17611
|
+
messages: [...args.messages],
|
|
17612
|
+
providerID: args.providerID,
|
|
17613
|
+
modelID: args.modelID,
|
|
17614
|
+
mergedIds,
|
|
17615
|
+
bindingIds,
|
|
17616
|
+
removedIds: getReasoningRemovalState(args.db, args.sessionId).messageIds
|
|
17617
|
+
});
|
|
17618
|
+
return new Set(args.messages.filter((message) => message.parts.some((part) => retained.has(part))));
|
|
17619
|
+
}
|
|
17620
|
+
function servedRequestForSizing(input, plan) {
|
|
17621
|
+
const head = input.head ? headMessagesForSizing(input.head, input.headFolds) : [];
|
|
17622
|
+
const instructions = input.coveredInstructions.length > 0 && hostInstructionRetentionEnabled() && (plan.editsWholePrefix || isHostInstructionRetentionOn(input.db, input.sessionId)) ? input.coveredInstructions : [];
|
|
17623
|
+
const removals = replayedReasoningRemovals(input);
|
|
17624
|
+
const cutoff = plan.clearsReasoning && input.reasoning ? Math.min(safeReasoningCutoff(input.messageTagNumbers, input.reasoning.protectedThinkingMessages), clearedReasoningCutoff(input, input.reasoning, removals.messageIds)) : 0;
|
|
17625
|
+
let conversation = withoutReplayedRemovals(input.messages, removals, input);
|
|
17626
|
+
if (cutoff > 0)
|
|
17627
|
+
conversation = conversation.map((message, index) => withoutClearedReasoning(message, input.messages[index] ?? message, input, cutoff));
|
|
17628
|
+
return [...head, ...instructions, ...conversation];
|
|
17629
|
+
}
|
|
17630
|
+
function replayedReasoningRemovals(input) {
|
|
17631
|
+
const bindingIds = new Set;
|
|
17632
|
+
if (input.replayedRemovals.bindingStrips)
|
|
17633
|
+
for (const id of getMergedReasoningStrippedIds(input.db, input.sessionId)) {
|
|
17634
|
+
if (!id.startsWith(THINKING_BINDING_RECOVERY_FROZEN_PREFIX))
|
|
17635
|
+
continue;
|
|
17636
|
+
const messageId = id.slice(THINKING_BINDING_RECOVERY_FROZEN_PREFIX.length);
|
|
17637
|
+
if (messageId.length > 0)
|
|
17638
|
+
bindingIds.add(messageId);
|
|
17639
|
+
}
|
|
17640
|
+
return {
|
|
17641
|
+
messageIds: input.replayedRemovals.wholePartRemoval ? getReasoningRemovalState(input.db, input.sessionId).messageIds : new Set,
|
|
17642
|
+
bindingIds
|
|
17643
|
+
};
|
|
17644
|
+
}
|
|
17645
|
+
function withoutReplayedRemovals(messages, removals, input) {
|
|
17646
|
+
if (removals.messageIds.size === 0 && removals.bindingIds.size === 0)
|
|
17647
|
+
return [...messages];
|
|
17648
|
+
const copies = messages.map((message) => {
|
|
17649
|
+
const id = message.info.id;
|
|
17650
|
+
return typeof id === "string" && (removals.messageIds.has(id) || removals.bindingIds.has(id)) ? countingCopy(message) : message;
|
|
17651
|
+
});
|
|
17652
|
+
const providerID = input.replayedRemovals.providerID;
|
|
17653
|
+
stripReasoningFromAssistantIds(copies, providerID, removals.bindingIds);
|
|
17654
|
+
removeReasoningParts(copies, removals.messageIds, providerID);
|
|
17655
|
+
return copies;
|
|
17656
|
+
}
|
|
17657
|
+
function countingCopy(message) {
|
|
17658
|
+
return {
|
|
17659
|
+
...message,
|
|
17660
|
+
parts: message.parts.map((part) => {
|
|
17661
|
+
if (!isRecord(part) || !isRecord(part.metadata))
|
|
17662
|
+
return part;
|
|
17663
|
+
return {
|
|
17664
|
+
...part,
|
|
17665
|
+
metadata: {
|
|
17666
|
+
...part.metadata,
|
|
17667
|
+
...isRecord(part.metadata.openrouter) ? { openrouter: { ...part.metadata.openrouter } } : {}
|
|
17668
|
+
}
|
|
17669
|
+
};
|
|
17670
|
+
})
|
|
17671
|
+
};
|
|
17672
|
+
}
|
|
17673
|
+
function clearedReasoningCutoff(input, reasoning, removedIds) {
|
|
17674
|
+
try {
|
|
17675
|
+
return projectOpencodeReasoningBudgetCutoff(input.db, input.sessionId, [...input.messages], reasoning.keepTokens, reasoning.clearedThroughTag, reasoning.proseRatio);
|
|
17676
|
+
} catch (error) {
|
|
17677
|
+
if (!(error instanceof TagOwnerSummaryNotReady2))
|
|
17678
|
+
throw error;
|
|
17679
|
+
}
|
|
17680
|
+
const gone = new Set(removedIds);
|
|
17681
|
+
for (const [message, tag] of input.messageTagNumbers) {
|
|
17682
|
+
if (tag > 0 && tag <= reasoning.clearedThroughTag && typeof message.info.id === "string")
|
|
17683
|
+
gone.add(message.info.id);
|
|
17684
|
+
}
|
|
17685
|
+
const frozenMergedIds = getMergedReasoningStrippedIds(input.db, input.sessionId);
|
|
17686
|
+
return opencodeReasoningBudgetCutoff({
|
|
17687
|
+
messages: [...input.messages],
|
|
17688
|
+
messageTagNumbers: input.messageTagNumbers,
|
|
17689
|
+
budget: reasoning.keepTokens,
|
|
17690
|
+
alreadyRemoved: gone,
|
|
17691
|
+
proseRatio: reasoning.proseRatio,
|
|
17692
|
+
frozenMergedIds,
|
|
17693
|
+
alsoGone: new Set([...frozenMergedIds].filter((id) => id.startsWith(THINKING_BINDING_RECOVERY_FROZEN_PREFIX)).map((id) => id.slice(THINKING_BINDING_RECOVERY_FROZEN_PREFIX.length)))
|
|
17694
|
+
});
|
|
17695
|
+
}
|
|
17696
|
+
function withoutClearedReasoning(message, original, input, cutoff) {
|
|
17697
|
+
const tag = input.messageTagNumbers.get(original) ?? 0;
|
|
17698
|
+
if (tag === 0 || tag > cutoff)
|
|
17699
|
+
return message;
|
|
17700
|
+
const parts = message.parts.filter((part) => !isReasoningPart(part));
|
|
17701
|
+
return parts.length === message.parts.length ? message : { ...message, parts };
|
|
17702
|
+
}
|
|
17703
|
+
function isReasoningPart(part) {
|
|
17704
|
+
return typeof part === "object" && part !== null && REASONING_PART_TYPES.has(String(part.type));
|
|
17705
|
+
}
|
|
17706
|
+
|
|
17707
|
+
// src/hooks/magic-context/recovery-fit.ts
|
|
17708
|
+
var RECOVERY_REFUSAL_NOTICE = "Magic Context is still summarizing older history so this conversation fits the model's context window. Send your message again to continue.";
|
|
17709
|
+
var RECOVERY_NO_HISTORY_REFUSAL_NOTICE = "This conversation no longer fits the model's context window, and Magic Context has no more older history it can summarize. Switch to a model with a larger context window to continue.";
|
|
17710
|
+
function recoveryLineTokens(windowTokens) {
|
|
17711
|
+
return Math.floor(windowTokens * BLOCK_UNTIL_DONE_PERCENTAGE / 100);
|
|
17712
|
+
}
|
|
17713
|
+
function recoveryAdmissionLimitTokens(windowTokens, historyRemains) {
|
|
17714
|
+
return historyRemains ? recoveryLineTokens(windowTokens) : Math.floor(windowTokens);
|
|
17715
|
+
}
|
|
17716
|
+
function recoveryRefusalNotice(historyRemains) {
|
|
17717
|
+
return historyRemains ? RECOVERY_REFUSAL_NOTICE : RECOVERY_NO_HISTORY_REFUSAL_NOTICE;
|
|
17718
|
+
}
|
|
17719
|
+
|
|
17500
17720
|
// src/hooks/magic-context/release-recovery-prefix.ts
|
|
17501
17721
|
function groups(messages) {
|
|
17502
17722
|
const result = new Map;
|
|
@@ -17565,6 +17785,89 @@ function resolveHistoryBudgetTokens(historyBudgetPercentage, contextUsage, execu
|
|
|
17565
17785
|
}) / 100) * historyBudgetPercentage);
|
|
17566
17786
|
}
|
|
17567
17787
|
|
|
17788
|
+
// src/hooks/magic-context/request-tools-release.ts
|
|
17789
|
+
var NAMESPACE = "requestToolsRelease";
|
|
17790
|
+
var MAX_MODEL_RECORDS = 8;
|
|
17791
|
+
function parseEntry(value) {
|
|
17792
|
+
if (typeof value !== "object" || value === null)
|
|
17793
|
+
return null;
|
|
17794
|
+
const record = value;
|
|
17795
|
+
if (typeof record.modelKey !== "string" || typeof record.names !== "string" || typeof record.descriptions !== "string" || typeof record.schemas !== "string")
|
|
17796
|
+
return null;
|
|
17797
|
+
return {
|
|
17798
|
+
modelKey: record.modelKey,
|
|
17799
|
+
names: record.names,
|
|
17800
|
+
descriptions: record.descriptions,
|
|
17801
|
+
schemas: record.schemas
|
|
17802
|
+
};
|
|
17803
|
+
}
|
|
17804
|
+
function parseStored(value) {
|
|
17805
|
+
const models = value?.models;
|
|
17806
|
+
if (!Array.isArray(models))
|
|
17807
|
+
return [];
|
|
17808
|
+
const entries = [];
|
|
17809
|
+
for (const item of models) {
|
|
17810
|
+
const entry = parseEntry(item);
|
|
17811
|
+
if (entry)
|
|
17812
|
+
entries.push(entry);
|
|
17813
|
+
}
|
|
17814
|
+
return entries;
|
|
17815
|
+
}
|
|
17816
|
+
function sameEntry(left, right) {
|
|
17817
|
+
return left !== undefined && left.modelKey === right.modelKey && left.names === right.names && left.descriptions === right.descriptions && left.schemas === right.schemas;
|
|
17818
|
+
}
|
|
17819
|
+
function isLatest(entries, current) {
|
|
17820
|
+
return sameEntry(entries.at(-1), current);
|
|
17821
|
+
}
|
|
17822
|
+
function withLatest(entries, current) {
|
|
17823
|
+
const next = entries.filter((entry) => entry.modelKey !== current.modelKey);
|
|
17824
|
+
next.push(current);
|
|
17825
|
+
return next.slice(-MAX_MODEL_RECORDS);
|
|
17826
|
+
}
|
|
17827
|
+
function evaluateRequestToolsRelease(args) {
|
|
17828
|
+
const current = { modelKey: args.modelKey, ...args.fingerprint };
|
|
17829
|
+
let entries = [];
|
|
17830
|
+
let readable = true;
|
|
17831
|
+
try {
|
|
17832
|
+
entries = parseStored(readReplayEnvelope(args.db, args.sessionId, "read")[NAMESPACE]);
|
|
17833
|
+
} catch (error) {
|
|
17834
|
+
readable = false;
|
|
17835
|
+
sessionLog2(args.sessionId, "request tools record unreadable:", error);
|
|
17836
|
+
}
|
|
17837
|
+
const stored = entries.find((entry) => entry.modelKey === current.modelKey);
|
|
17838
|
+
const change = stored ? classifyRequestToolsChange(stored, current) : null;
|
|
17839
|
+
if (change !== null) {
|
|
17840
|
+
sessionLog2(args.sessionId, `request tools changed (kind=${change === "schemas" ? "schema-only" : change}, model=${current.modelKey}, schemas ${stored?.schemas.slice(0, 12)}→${current.schemas.slice(0, 12)}): releasing signed thinking`);
|
|
17841
|
+
} else if (readable && !stored) {
|
|
17842
|
+
sessionLog2(args.sessionId, `request tools fingerprint adopted for model=${current.modelKey}${entries.length > 0 ? ` (records kept for ${entries.map((entry) => entry.modelKey).join(",")})` : ""}`);
|
|
17843
|
+
}
|
|
17844
|
+
return {
|
|
17845
|
+
change,
|
|
17846
|
+
commit: () => {
|
|
17847
|
+
if (!readable || isLatest(entries, current))
|
|
17848
|
+
return;
|
|
17849
|
+
try {
|
|
17850
|
+
let next = entries;
|
|
17851
|
+
const written = updateReplayDocument(args.db, args.sessionId, (doc) => {
|
|
17852
|
+
const latest = parseStored(doc[NAMESPACE]);
|
|
17853
|
+
if (isLatest(latest, current))
|
|
17854
|
+
return false;
|
|
17855
|
+
next = withLatest(latest, current);
|
|
17856
|
+
doc.version = 2;
|
|
17857
|
+
doc[NAMESPACE] = { models: next };
|
|
17858
|
+
return true;
|
|
17859
|
+
});
|
|
17860
|
+
if (written)
|
|
17861
|
+
entries = next;
|
|
17862
|
+
else
|
|
17863
|
+
sessionLog2(args.sessionId, "request tools record not written");
|
|
17864
|
+
} catch (error) {
|
|
17865
|
+
sessionLog2(args.sessionId, "request tools record write failed:", error);
|
|
17866
|
+
}
|
|
17867
|
+
}
|
|
17868
|
+
};
|
|
17869
|
+
}
|
|
17870
|
+
|
|
17568
17871
|
// src/hooks/magic-context/rust-mode-transform.ts
|
|
17569
17872
|
import { createHash as createHash13, randomUUID as randomUUID6 } from "node:crypto";
|
|
17570
17873
|
|
|
@@ -20453,7 +20756,7 @@ function resolveUnknownUsageFromWireEstimate(input) {
|
|
|
20453
20756
|
const providerLimit = input.providerProvenLimitTokens;
|
|
20454
20757
|
const canUseProviderMass = input.wireEstimateTrusted === false && typeof providerTokens === "number" && Number.isFinite(providerTokens) && providerTokens > 0 && typeof providerLimit === "number" && Number.isFinite(providerLimit) && providerLimit > 0;
|
|
20455
20758
|
const tokens = canUseProviderMass ? Math.max(wireTokens, providerTokens) : wireTokens;
|
|
20456
|
-
const limit = input.
|
|
20759
|
+
const limit = input.windowTokens;
|
|
20457
20760
|
const estimatedPercentage = typeof limit === "number" && Number.isFinite(limit) && limit > 0 ? tokens / limit * 100 : input.usage.percentage;
|
|
20458
20761
|
return {
|
|
20459
20762
|
inputTokens: tokens,
|
|
@@ -21155,7 +21458,7 @@ function transformGeometryForWire(geometry) {
|
|
|
21155
21458
|
return;
|
|
21156
21459
|
const { window, reserve } = geometry.derivation;
|
|
21157
21460
|
let derivation;
|
|
21158
|
-
if (geometry.geometry === "separate" && geometry.usableSoft <
|
|
21461
|
+
if (geometry.geometry === "separate" && geometry.usableSoft < window) {
|
|
21159
21462
|
derivation = `s1-pre-carve/input=${geometry.usableSoft}`;
|
|
21160
21463
|
} else if (geometry.geometry === "separate") {
|
|
21161
21464
|
derivation = `s1-separate/context=${window}`;
|
|
@@ -23988,6 +24291,7 @@ function readServedTemporalDecisions(db, sessionId, runtime, messageIds) {
|
|
|
23988
24291
|
|
|
23989
24292
|
// src/hooks/magic-context/transform-compartment-phase.ts
|
|
23990
24293
|
var HISTORIAN_INLINE_JOIN_BUDGET_MS = 60000;
|
|
24294
|
+
var CHAINED_RECOVERY_RUN_MIN_BUDGET_MS = 15000;
|
|
23991
24295
|
function resolveHistorianInlineJoinBudget(configuredTimeoutMs) {
|
|
23992
24296
|
const requested = configuredTimeoutMs ?? HISTORIAN_INLINE_JOIN_BUDGET_MS;
|
|
23993
24297
|
return Math.max(0, Math.min(requested, HISTORIAN_INLINE_JOIN_BUDGET_MS));
|
|
@@ -24049,6 +24353,7 @@ async function runCompartmentPhaseImpl(args) {
|
|
|
24049
24353
|
let rebuiltHistoryThisPass = false;
|
|
24050
24354
|
let historianJoinTimedOut = false;
|
|
24051
24355
|
let historianJoinBudgetMs = null;
|
|
24356
|
+
let chainedRecoveryRuns = 0;
|
|
24052
24357
|
const historianRunnable = args.historianRunnable !== false;
|
|
24053
24358
|
if (args.compactionOff) {
|
|
24054
24359
|
if (args.sessionMeta.compartmentInProgress) {
|
|
@@ -24064,7 +24369,9 @@ async function runCompartmentPhaseImpl(args) {
|
|
|
24064
24369
|
justAwaitedPublication,
|
|
24065
24370
|
rebuiltHistoryThisPass,
|
|
24066
24371
|
historianJoinTimedOut,
|
|
24067
|
-
historianJoinBudgetMs
|
|
24372
|
+
historianJoinBudgetMs,
|
|
24373
|
+
chainedRecoveryRuns,
|
|
24374
|
+
recoveryHistoryRemains: false
|
|
24068
24375
|
};
|
|
24069
24376
|
}
|
|
24070
24377
|
let rawEligibility = args.preResolvedBoundarySnapshot ? {
|
|
@@ -24112,7 +24419,7 @@ async function runCompartmentPhaseImpl(args) {
|
|
|
24112
24419
|
const snapshot = getBoundarySnapshotForCompartment();
|
|
24113
24420
|
return snapshot !== null && hasRunnableCompartmentWindow(snapshot);
|
|
24114
24421
|
}
|
|
24115
|
-
async function awaitCompartmentRun(activeRun, reason) {
|
|
24422
|
+
async function awaitCompartmentRun(activeRun, reason, join = fullInlineJoinWindow()) {
|
|
24116
24423
|
await Promise.resolve();
|
|
24117
24424
|
if (activeRun.inlineJoinTimedOutBudgetMs !== undefined && !activeRun.settled) {
|
|
24118
24425
|
historianJoinTimedOut = true;
|
|
@@ -24121,8 +24428,8 @@ async function runCompartmentPhaseImpl(args) {
|
|
|
24121
24428
|
return "timed_out";
|
|
24122
24429
|
}
|
|
24123
24430
|
sessionLog2(args.sessionId, reason);
|
|
24124
|
-
const timeoutMs =
|
|
24125
|
-
historianJoinBudgetMs =
|
|
24431
|
+
const timeoutMs = join.timeoutMs;
|
|
24432
|
+
historianJoinBudgetMs = join.budgetMs;
|
|
24126
24433
|
let timer;
|
|
24127
24434
|
const timeout = new Promise((resolve) => {
|
|
24128
24435
|
timer = setTimeout(() => resolve("timeout"), timeoutMs);
|
|
@@ -24135,20 +24442,145 @@ async function runCompartmentPhaseImpl(args) {
|
|
|
24135
24442
|
clearTimeout(timer);
|
|
24136
24443
|
}
|
|
24137
24444
|
if (result === "timeout") {
|
|
24138
|
-
activeRun.inlineJoinTimedOutBudgetMs =
|
|
24445
|
+
activeRun.inlineJoinTimedOutBudgetMs = join.budgetMs;
|
|
24139
24446
|
historianJoinTimedOut = true;
|
|
24140
24447
|
sessionLog2(args.sessionId, `transform: compartment await timed out after ${timeoutMs}ms — proceeding without waiting`);
|
|
24141
24448
|
return "timed_out";
|
|
24142
24449
|
}
|
|
24143
|
-
|
|
24144
|
-
justAwaitedPublication = activeRun.published;
|
|
24450
|
+
justAwaitedPublication = justAwaitedPublication || activeRun.published;
|
|
24145
24451
|
published = published || activeRun.published;
|
|
24146
|
-
|
|
24452
|
+
return "completed";
|
|
24453
|
+
}
|
|
24454
|
+
function refreshCompartmentCoverage() {
|
|
24455
|
+
sessionLog2(args.sessionId, "transform: compartment agent completed, refreshing compartment coverage");
|
|
24456
|
+
const historyReprepareShouldBust = published && args.deferredHistoryRefreshSessions.has(args.sessionId);
|
|
24147
24457
|
pendingCompartmentInjection = prepareCompartmentInjection(args.db, args.resolvedSessionId, args.messages, historyReprepareShouldBust, args.coveredInstructions, args.projectPath, args.injectionBudgetTokens, args.experimentalTemporalAwareness);
|
|
24148
24458
|
if (historyReprepareShouldBust) {
|
|
24149
24459
|
rebuiltHistoryThisPass = true;
|
|
24150
24460
|
}
|
|
24151
|
-
|
|
24461
|
+
}
|
|
24462
|
+
function fullInlineJoinWindow() {
|
|
24463
|
+
const budgetMs = resolveHistorianInlineJoinBudget(args.historianTimeoutMs);
|
|
24464
|
+
return { timeoutMs: budgetMs, budgetMs };
|
|
24465
|
+
}
|
|
24466
|
+
function historianRunDeps(boundarySnapshot) {
|
|
24467
|
+
return {
|
|
24468
|
+
client: args.client,
|
|
24469
|
+
hiddenCompletionExecutor: args.hiddenCompletionExecutor,
|
|
24470
|
+
compactionMarkerStrategy: args.compactionMarkerStrategy,
|
|
24471
|
+
db: args.db,
|
|
24472
|
+
sessionId: args.sessionId,
|
|
24473
|
+
historianChunkTokens: args.historianChunkTokens,
|
|
24474
|
+
boundarySnapshot,
|
|
24475
|
+
currentContextLimit: args.boundaryContextLimit,
|
|
24476
|
+
historyBudgetTokens: args.historyBudgetTokens,
|
|
24477
|
+
historianTimeoutMs: args.historianTimeoutMs,
|
|
24478
|
+
model: args.historianModel,
|
|
24479
|
+
historianContextLimit: args.historianContextLimit,
|
|
24480
|
+
historianMaxOutputTokens: args.historianMaxOutputTokens,
|
|
24481
|
+
fallbackModels: args.fallbackModels,
|
|
24482
|
+
directory: args.compartmentDirectory,
|
|
24483
|
+
fallbackModelId: args.fallbackModelId,
|
|
24484
|
+
ensureProjectRegistered: args.ensureProjectRegistered,
|
|
24485
|
+
getNotificationParams: args.getNotificationParams,
|
|
24486
|
+
experimentalUserMemories: args.experimentalUserMemories,
|
|
24487
|
+
userObservationsRequested: args.userObservationsRequested,
|
|
24488
|
+
historianTwoPass: args.historianTwoPass,
|
|
24489
|
+
historianExpandTools: args.historianExpandTools,
|
|
24490
|
+
memoryEnabled: args.memoryEnabled,
|
|
24491
|
+
autoPromote: args.autoPromote,
|
|
24492
|
+
onCompartmentStatePublished: args.onCompartmentStatePublished,
|
|
24493
|
+
preserveInjectionCacheUntilConsumed: true
|
|
24494
|
+
};
|
|
24495
|
+
}
|
|
24496
|
+
function resolveNextRecoveryBoundary() {
|
|
24497
|
+
rawEligibility = null;
|
|
24498
|
+
cachedBoundarySnapshot = null;
|
|
24499
|
+
if (!hasNewRawHistoryForCompartment())
|
|
24500
|
+
return null;
|
|
24501
|
+
const resolve = args.resolveRecoveryBoundary ?? resolveBoundarySnapshot;
|
|
24502
|
+
let snapshot = resolve();
|
|
24503
|
+
if (!hasRunnableCompartmentWindow(snapshot)) {
|
|
24504
|
+
snapshot = resolve(args.contextUsage.percentage >= BLOCK_UNTIL_DONE_PERCENTAGE ? 0.25 : 0.5);
|
|
24505
|
+
}
|
|
24506
|
+
cachedBoundarySnapshot = snapshot;
|
|
24507
|
+
return hasRunnableCompartmentWindow(snapshot) ? snapshot : null;
|
|
24508
|
+
}
|
|
24509
|
+
async function chainRecoveryRuns(firstRun, project, deadline, budgetMs) {
|
|
24510
|
+
let lastRun = firstRun;
|
|
24511
|
+
const minimumRunBudgetMs = Math.min(CHAINED_RECOVERY_RUN_MIN_BUDGET_MS, budgetMs / 4);
|
|
24512
|
+
for (;; ) {
|
|
24513
|
+
if (!lastRun.published) {
|
|
24514
|
+
sessionLog2(args.sessionId, `transform: recovery chain stops: the last historian run published nothing (${chainedRecoveryRuns} chained runs)`);
|
|
24515
|
+
return "stopped";
|
|
24516
|
+
}
|
|
24517
|
+
let fit;
|
|
24518
|
+
try {
|
|
24519
|
+
fit = project();
|
|
24520
|
+
} catch (error) {
|
|
24521
|
+
sessionLog2(args.sessionId, "transform: recovery chain stops: the request could not be counted:", error);
|
|
24522
|
+
return "stopped";
|
|
24523
|
+
}
|
|
24524
|
+
if (!fit)
|
|
24525
|
+
return "stopped";
|
|
24526
|
+
if (Number.isFinite(fit.tokens) && fit.tokens <= fit.lineTokens) {
|
|
24527
|
+
sessionLog2(args.sessionId, `transform: recovery chain done: the request is about ${fit.tokens} tokens, under the 95% line ${fit.lineTokens} (${chainedRecoveryRuns} chained runs)`);
|
|
24528
|
+
return "stopped";
|
|
24529
|
+
}
|
|
24530
|
+
const remainingMs = deadline - Date.now();
|
|
24531
|
+
if (remainingMs < minimumRunBudgetMs) {
|
|
24532
|
+
sessionLog2(args.sessionId, `transform: recovery chain stops: ${Math.max(0, remainingMs)}ms of the ${budgetMs}ms inline join budget is left, under the ${minimumRunBudgetMs}ms a chained run needs; the request is still about ${fit.tokens} tokens, over the 95% line ${fit.lineTokens}`);
|
|
24533
|
+
return "stopped";
|
|
24534
|
+
}
|
|
24535
|
+
const boundary = resolveNextRecoveryBoundary();
|
|
24536
|
+
if (!boundary) {
|
|
24537
|
+
sessionLog2(args.sessionId, `transform: recovery chain stops: no eligible history before the protected tail; the request is still about ${fit.tokens} tokens, over the 95% line ${fit.lineTokens}`);
|
|
24538
|
+
return "stopped";
|
|
24539
|
+
}
|
|
24540
|
+
if (isHistorianDrainBudgetSpent({
|
|
24541
|
+
db: args.db,
|
|
24542
|
+
sessionId: args.sessionId,
|
|
24543
|
+
contextLimit: args.boundaryContextLimit,
|
|
24544
|
+
executeThresholdPercentage: args.boundaryExecuteThresholdPercentage,
|
|
24545
|
+
usagePercentage: args.boundaryUsage.percentage
|
|
24546
|
+
})) {
|
|
24547
|
+
sessionLog2(args.sessionId, `transform: recovery chain stops: the historian's drain budget is spent; the request is still about ${fit.tokens} tokens, over the 95% line ${fit.lineTokens}`);
|
|
24548
|
+
return "stopped";
|
|
24549
|
+
}
|
|
24550
|
+
startCompartmentAgent(historianRunDeps(boundary));
|
|
24551
|
+
const nextRun = getActiveCompartmentRun(args.sessionId);
|
|
24552
|
+
if (!nextRun || nextRun === lastRun) {
|
|
24553
|
+
sessionLog2(args.sessionId, "transform: recovery chain stops: the next historian run did not start");
|
|
24554
|
+
return "stopped";
|
|
24555
|
+
}
|
|
24556
|
+
chainedRecoveryRuns += 1;
|
|
24557
|
+
const result = await awaitCompartmentRun(nextRun, `transform: recovery request still about ${fit.tokens} tokens, over the 95% line ${fit.lineTokens}; blocking for historian run ${chainedRecoveryRuns + 1} on the next chunk`, { timeoutMs: remainingMs, budgetMs });
|
|
24558
|
+
if (result === "timed_out")
|
|
24559
|
+
return "timed_out";
|
|
24560
|
+
lastRun = nextRun;
|
|
24561
|
+
}
|
|
24562
|
+
}
|
|
24563
|
+
function recoveryHistoryRemainsAfterJoins() {
|
|
24564
|
+
if (!historianRunnable || !args.canRunCompartments)
|
|
24565
|
+
return false;
|
|
24566
|
+
if (getActiveCompartmentRun(args.sessionId))
|
|
24567
|
+
return true;
|
|
24568
|
+
if (!args.client && !args.hiddenCompletionExecutor)
|
|
24569
|
+
return false;
|
|
24570
|
+
try {
|
|
24571
|
+
if (resolveNextRecoveryBoundary() === null)
|
|
24572
|
+
return false;
|
|
24573
|
+
} catch (error) {
|
|
24574
|
+
sessionLog2(args.sessionId, "transform: recovery history check failed; keeping the 95% line:", error);
|
|
24575
|
+
return true;
|
|
24576
|
+
}
|
|
24577
|
+
return !isHistorianDrainBudgetSpent({
|
|
24578
|
+
db: args.db,
|
|
24579
|
+
sessionId: args.sessionId,
|
|
24580
|
+
contextLimit: args.boundaryContextLimit,
|
|
24581
|
+
executeThresholdPercentage: args.boundaryExecuteThresholdPercentage,
|
|
24582
|
+
usagePercentage: args.boundaryUsage.percentage
|
|
24583
|
+
});
|
|
24152
24584
|
}
|
|
24153
24585
|
if ((!historianRunnable || !args.canRunCompartments && !getActiveCompartmentRun(args.sessionId)) && args.sessionMeta.compartmentInProgress) {
|
|
24154
24586
|
sessionLog2(args.sessionId, "transform: historian unavailable; clearing stale compartmentInProgress flag");
|
|
@@ -24208,34 +24640,7 @@ async function runCompartmentPhaseImpl(args) {
|
|
|
24208
24640
|
let activeRun = getActiveCompartmentRun(args.sessionId);
|
|
24209
24641
|
if (!activeRun && hasEligibleHistoryForCompartment() && (args.client || args.hiddenCompletionExecutor)) {
|
|
24210
24642
|
sessionLog2(args.sessionId, `transform: 95% reached (${args.contextUsage.percentage.toFixed(1)}%), force-starting compartment agent and blocking`);
|
|
24211
|
-
startCompartmentAgent(
|
|
24212
|
-
client: args.client,
|
|
24213
|
-
hiddenCompletionExecutor: args.hiddenCompletionExecutor,
|
|
24214
|
-
compactionMarkerStrategy: args.compactionMarkerStrategy,
|
|
24215
|
-
db: args.db,
|
|
24216
|
-
sessionId: args.sessionId,
|
|
24217
|
-
historianChunkTokens: args.historianChunkTokens,
|
|
24218
|
-
boundarySnapshot: getBoundarySnapshotForCompartment() ?? undefined,
|
|
24219
|
-
currentContextLimit: args.boundaryContextLimit,
|
|
24220
|
-
historyBudgetTokens: args.historyBudgetTokens,
|
|
24221
|
-
historianTimeoutMs: args.historianTimeoutMs,
|
|
24222
|
-
model: args.historianModel,
|
|
24223
|
-
historianContextLimit: args.historianContextLimit,
|
|
24224
|
-
historianMaxOutputTokens: args.historianMaxOutputTokens,
|
|
24225
|
-
fallbackModels: args.fallbackModels,
|
|
24226
|
-
directory: args.compartmentDirectory,
|
|
24227
|
-
fallbackModelId: args.fallbackModelId,
|
|
24228
|
-
ensureProjectRegistered: args.ensureProjectRegistered,
|
|
24229
|
-
getNotificationParams: args.getNotificationParams,
|
|
24230
|
-
experimentalUserMemories: args.experimentalUserMemories,
|
|
24231
|
-
userObservationsRequested: args.userObservationsRequested,
|
|
24232
|
-
historianTwoPass: args.historianTwoPass,
|
|
24233
|
-
historianExpandTools: args.historianExpandTools,
|
|
24234
|
-
memoryEnabled: args.memoryEnabled,
|
|
24235
|
-
autoPromote: args.autoPromote,
|
|
24236
|
-
onCompartmentStatePublished: args.onCompartmentStatePublished,
|
|
24237
|
-
preserveInjectionCacheUntilConsumed: true
|
|
24238
|
-
});
|
|
24643
|
+
startCompartmentAgent(historianRunDeps(getBoundarySnapshotForCompartment() ?? undefined));
|
|
24239
24644
|
activeRun = getActiveCompartmentRun(args.sessionId);
|
|
24240
24645
|
} else if (!activeRun && hasEligibleHistoryForCompartment()) {
|
|
24241
24646
|
sessionLog2(args.sessionId, "transform: cannot force-start compartment agent without client");
|
|
@@ -24246,15 +24651,24 @@ async function runCompartmentPhaseImpl(args) {
|
|
|
24246
24651
|
const notifParams = args.getNotificationParams?.() ?? {};
|
|
24247
24652
|
withoutSqliteTransformPass2(() => sendStatusNotification2(args.client, args.sessionId, `⏳ Context at ${args.contextUsage.percentage.toFixed(0)}% — Magic Context is comparting history before continuing. This may take up to ${HISTORIAN_INLINE_JOIN_BUDGET_MS / 1000} seconds.`, notifParams));
|
|
24248
24653
|
}
|
|
24249
|
-
const
|
|
24654
|
+
const join = fullInlineJoinWindow();
|
|
24655
|
+
const joinDeadline = Date.now() + join.budgetMs;
|
|
24656
|
+
const awaitResult = await awaitCompartmentRun(activeRun, `transform: blocking at ${args.contextUsage.percentage.toFixed(1)}% until compartment agent completes`, join);
|
|
24250
24657
|
if (awaitResult === "completed") {
|
|
24251
24658
|
awaitedCompartmentRun = true;
|
|
24252
24659
|
compartmentInProgress = false;
|
|
24660
|
+
if (args.projectRecoveryRequest) {
|
|
24661
|
+
const chain = await chainRecoveryRuns(activeRun, args.projectRecoveryRequest, joinDeadline, join.budgetMs);
|
|
24662
|
+
if (chain === "timed_out")
|
|
24663
|
+
compartmentInProgress = true;
|
|
24664
|
+
}
|
|
24665
|
+
refreshCompartmentCoverage();
|
|
24253
24666
|
} else {
|
|
24254
24667
|
sessionLog2(args.sessionId, "transform: historian join timed out — reclaim and final fit checks continue; historian keeps running in the background");
|
|
24255
24668
|
}
|
|
24256
24669
|
}
|
|
24257
24670
|
}
|
|
24671
|
+
const recoveryHistoryRemains = args.projectRecoveryRequest !== undefined && recoveryHistoryRemainsAfterJoins();
|
|
24258
24672
|
return {
|
|
24259
24673
|
pendingCompartmentInjection,
|
|
24260
24674
|
awaitedCompartmentRun,
|
|
@@ -24263,7 +24677,9 @@ async function runCompartmentPhaseImpl(args) {
|
|
|
24263
24677
|
justAwaitedPublication,
|
|
24264
24678
|
rebuiltHistoryThisPass,
|
|
24265
24679
|
historianJoinTimedOut,
|
|
24266
|
-
historianJoinBudgetMs
|
|
24680
|
+
historianJoinBudgetMs,
|
|
24681
|
+
chainedRecoveryRuns,
|
|
24682
|
+
recoveryHistoryRemains
|
|
24267
24683
|
};
|
|
24268
24684
|
}
|
|
24269
24685
|
|
|
@@ -24812,6 +25228,7 @@ function createTransform(deps) {
|
|
|
24812
25228
|
sessionID: sessionId
|
|
24813
25229
|
}) : undefined;
|
|
24814
25230
|
const hostEstimate = deps.hostInputEstimate?.(sessionId);
|
|
25231
|
+
const recoveryHostAddedTokens = typeof hostEstimate?.hostAddedTokens === "number" && Number.isFinite(hostEstimate.hostAddedTokens) && hostEstimate.hostAddedTokens > 0 ? hostEstimate.hostAddedTokens : 0;
|
|
24815
25232
|
const hostOverWindow = fullFeatureMode && !compactionOff && resolvedContextLimit !== undefined && resolvedContextLimit > 0 && hostEstimate !== undefined && Number.isFinite(hostEstimate.tokens) && Number.isFinite(hostEstimate.pressureTokens) && hostEstimate.tokens > resolvedContextLimit;
|
|
24816
25233
|
if (hostOverWindow) {
|
|
24817
25234
|
contextUsageEarly = {
|
|
@@ -24874,7 +25291,15 @@ function createTransform(deps) {
|
|
|
24874
25291
|
return estimateTokens(text) * holdProseRatio;
|
|
24875
25292
|
}
|
|
24876
25293
|
}) : null;
|
|
24877
|
-
|
|
25294
|
+
const requestToolsFingerprint = modelForBudget && isPrefixBoundThinkingModel(modelForBudget.providerID, modelForBudget.modelID) ? deps.getRequestToolsFingerprint?.(sessionId) : undefined;
|
|
25295
|
+
const requestToolsRelease = modelForBudget && requestToolsFingerprint ? evaluateRequestToolsRelease({
|
|
25296
|
+
db,
|
|
25297
|
+
sessionId,
|
|
25298
|
+
modelKey: `${modelForBudget.providerID}/${modelForBudget.modelID}`,
|
|
25299
|
+
fingerprint: requestToolsFingerprint
|
|
25300
|
+
}) : undefined;
|
|
25301
|
+
const requestToolsChanged = requestToolsRelease?.change != null;
|
|
25302
|
+
activeThinkingPrefixHold = !requestToolsChanged && signedThinkingPrefixBound && (compactionOff || signedThinkingHold?.held === true);
|
|
24878
25303
|
freezeM0M1 ||= activeThinkingPrefixHold;
|
|
24879
25304
|
const originalForThinkingFit = takeSignedThinkingFitSnapshot({
|
|
24880
25305
|
sessionId,
|
|
@@ -25301,6 +25726,50 @@ Historian previously failed ${historianFailureState.failureCount} time(s), so Ma
|
|
|
25301
25726
|
const watermark = getMaxDroppedTagNumber2(db, sessionId);
|
|
25302
25727
|
let contextUsage = contextUsageEarly;
|
|
25303
25728
|
const rawGetNotifParams = runNotificationParams;
|
|
25729
|
+
const pricedPassSizingInputFor = (messagesToSize, options) => {
|
|
25730
|
+
const servesHead = (!!projectIdentity || !!sessionDirectory) && (fullFeatureMode || compactionOff);
|
|
25731
|
+
const prefixBoundModel = isPrefixBoundThinkingModel(modelForBudget?.providerID, modelForBudget?.modelID);
|
|
25732
|
+
return {
|
|
25733
|
+
db,
|
|
25734
|
+
sessionId,
|
|
25735
|
+
messages: messagesToSize,
|
|
25736
|
+
messageTagNumbers,
|
|
25737
|
+
head: servesHead ? {
|
|
25738
|
+
db,
|
|
25739
|
+
sessionId,
|
|
25740
|
+
state: options.meta,
|
|
25741
|
+
projectDirectory: sessionDirectory,
|
|
25742
|
+
...renderOptions,
|
|
25743
|
+
hardSignals: options.hardSignals,
|
|
25744
|
+
compactionOff
|
|
25745
|
+
} : undefined,
|
|
25746
|
+
headFolds: options.headFolds,
|
|
25747
|
+
coveredInstructions: deps.storeGeneration === "v2" && servesHead && !compactionOff ? coveredHostInstructions : [],
|
|
25748
|
+
replayedRemovals: {
|
|
25749
|
+
providerID: resolvedProviderID,
|
|
25750
|
+
wholePartRemoval: (!canUseEmptySentinels || prefixBoundModel) && !compactionOff,
|
|
25751
|
+
bindingStrips: !compactionOff
|
|
25752
|
+
},
|
|
25753
|
+
reasoning: options.reasoning
|
|
25754
|
+
};
|
|
25755
|
+
};
|
|
25756
|
+
const recoveryChainWindow = windowGeometry?.usableHard ?? resolvedContextLimit;
|
|
25757
|
+
const recoveryChainMeta = sessionMeta;
|
|
25758
|
+
const projectRecoveryRequest = fullFeatureMode && !compactionOff && emergencyRecoveryArmed && emergencyRecoveryOrigin !== null && typeof recoveryChainWindow === "number" && recoveryChainWindow > 0 ? () => {
|
|
25759
|
+
const served = servedRequestForSizing(pricedPassSizingInputFor(rawTailAfterNewestCompartment(db, sessionId, messages), { meta: recoveryChainMeta, headFolds: true, reasoning: undefined }), { editsWholePrefix: !activeThinkingPrefixHold, clearsReasoning: false });
|
|
25760
|
+
const estimate = estimateFinalWireInputTokens({
|
|
25761
|
+
messages: served,
|
|
25762
|
+
systemPromptTokens: recoveryChainMeta.systemPromptTokens,
|
|
25763
|
+
providerID: modelForBudget?.providerID,
|
|
25764
|
+
modelID: modelForBudget?.modelID,
|
|
25765
|
+
agentName: notificationParams.agent,
|
|
25766
|
+
sessionId
|
|
25767
|
+
});
|
|
25768
|
+
return {
|
|
25769
|
+
tokens: (estimate.pressureTokens ?? estimate.tokens) + recoveryHostAddedTokens,
|
|
25770
|
+
lineTokens: recoveryLineTokens(recoveryChainWindow)
|
|
25771
|
+
};
|
|
25772
|
+
} : undefined;
|
|
25304
25773
|
const tCompartmentPhase = performance.now();
|
|
25305
25774
|
const compartmentPhase = await runCompartmentPhase({
|
|
25306
25775
|
hiddenCompletionExecutor: deps.hiddenCompletionExecutor,
|
|
@@ -25316,6 +25785,17 @@ Historian previously failed ${historianFailureState.failureCount} time(s), so Ma
|
|
|
25316
25785
|
boundaryUsage: boundaryUsageForProtectedTail,
|
|
25317
25786
|
boundaryUsageSource,
|
|
25318
25787
|
preResolvedBoundarySnapshot: triggerBoundarySnapshot,
|
|
25788
|
+
projectRecoveryRequest,
|
|
25789
|
+
resolveRecoveryBoundary: (emergencyTailScale) => host.hostProtectedTailBoundary({
|
|
25790
|
+
db,
|
|
25791
|
+
sessionId: resolvedSessionId,
|
|
25792
|
+
mode: "transform-force",
|
|
25793
|
+
contextLimit: boundaryContextLimit,
|
|
25794
|
+
executeThresholdPercentage: boundaryExecuteThreshold,
|
|
25795
|
+
usage: boundaryUsageForProtectedTail,
|
|
25796
|
+
usageSource: boundaryUsageSource,
|
|
25797
|
+
emergencyTailScale
|
|
25798
|
+
}),
|
|
25319
25799
|
client: deps.client,
|
|
25320
25800
|
db,
|
|
25321
25801
|
sessionId,
|
|
@@ -25419,44 +25899,149 @@ Historian previously failed ${historianFailureState.failureCount} time(s), so Ma
|
|
|
25419
25899
|
contextLimit: resolvedContextLimit,
|
|
25420
25900
|
lastResponseTime: sessionMeta.lastResponseTime
|
|
25421
25901
|
});
|
|
25422
|
-
|
|
25902
|
+
const servesHead = (!!projectIdentity || !!sessionDirectory) && (fullFeatureMode || compactionOff);
|
|
25903
|
+
const prefixBoundModel = isPrefixBoundThinkingModel(modelForBudget?.providerID, modelForBudget?.modelID);
|
|
25904
|
+
let sizingInput;
|
|
25905
|
+
let planInput;
|
|
25423
25906
|
try {
|
|
25424
|
-
|
|
25425
|
-
|
|
25426
|
-
|
|
25427
|
-
|
|
25428
|
-
|
|
25429
|
-
|
|
25430
|
-
|
|
25907
|
+
sizingInput = pricedPassSizingInputFor(messages, {
|
|
25908
|
+
meta: sessionMeta,
|
|
25909
|
+
hardSignals: m0HardSignals,
|
|
25910
|
+
headFolds: protectionFoldWillBust,
|
|
25911
|
+
reasoning: !compactionOff && !activeThinkingPrefixHold && resolvedProviderID !== undefined && !prefixBoundModel ? {
|
|
25912
|
+
keepTokens: resolveKeepReasoningTokens(deps.keepReasoningTokens, currentModelKeyForBoundary),
|
|
25913
|
+
clearedThroughTag: sessionMeta.clearedReasoningThroughTag,
|
|
25914
|
+
proseRatio: sessionDecisionCalibration(db, sessionId).proseRatio,
|
|
25915
|
+
protectedThinkingMessages: protectedThinkingMessagesForSizing({
|
|
25916
|
+
db,
|
|
25917
|
+
sessionId,
|
|
25918
|
+
messages,
|
|
25919
|
+
activeThinkingTurn,
|
|
25920
|
+
providerID: resolvedProviderID,
|
|
25921
|
+
modelID: modelForBudget?.modelID
|
|
25922
|
+
})
|
|
25923
|
+
} : undefined
|
|
25431
25924
|
});
|
|
25925
|
+
planInput = {
|
|
25926
|
+
db,
|
|
25927
|
+
sessionId,
|
|
25928
|
+
compactionOff,
|
|
25929
|
+
fullFeatureMode,
|
|
25930
|
+
schedulerDecision,
|
|
25931
|
+
forceMaterializationPercentage,
|
|
25932
|
+
signedThinkingHold: activeThinkingPrefixHold,
|
|
25933
|
+
firstRender: servesHead && !(sessionMeta.cachedM0Bytes != null && sessionMeta.cachedM1Bytes != null) && !hasCompleteCachedM0M1(db, sessionId),
|
|
25934
|
+
folds: protectionFoldWillBust,
|
|
25935
|
+
explicitFlush: hasPendingMaterializationOrigin(deps.pendingMaterializationSessions, sessionId, "user_flush"),
|
|
25936
|
+
materializationRequested: deps.pendingMaterializationSessions.has(sessionId) || canConsumeDeferredLate && deferredMaterializationSessions.has(sessionId),
|
|
25937
|
+
historyRebuilt: historyRebuiltThisPass || pendingCompartmentInjection?.rebuiltFromDb === true || rebuiltHistoryFromInitialPrepare,
|
|
25938
|
+
alreadyRanThisTurn: heuristicsAlreadyRanThisTurn(deps.lastHeuristicsTurnId, sessionId, currentTurnId)
|
|
25939
|
+
};
|
|
25432
25940
|
} catch (error) {
|
|
25433
|
-
|
|
25434
|
-
|
|
25435
|
-
|
|
25436
|
-
const
|
|
25437
|
-
|
|
25438
|
-
|
|
25439
|
-
|
|
25440
|
-
|
|
25441
|
-
|
|
25941
|
+
sizingInput = undefined;
|
|
25942
|
+
sessionLog2(sessionId, `transform: priced-pass sizing counts the array without the parts the pass adds: ${getErrorMessage(error)}`);
|
|
25943
|
+
}
|
|
25944
|
+
const countRequest = (plan) => {
|
|
25945
|
+
let sizingMessages = messages;
|
|
25946
|
+
if (sizingInput) {
|
|
25947
|
+
try {
|
|
25948
|
+
sizingMessages = servedRequestForSizing(sizingInput, plan);
|
|
25949
|
+
} catch (error) {
|
|
25950
|
+
sessionLog2(sessionId, `transform: priced-pass sizing counts the array without the parts the pass adds: ${getErrorMessage(error)}`);
|
|
25951
|
+
}
|
|
25952
|
+
}
|
|
25953
|
+
try {
|
|
25954
|
+
return estimateFinalWireInputTokens({
|
|
25955
|
+
messages: sizingMessages,
|
|
25956
|
+
systemPromptTokens: sessionMeta.systemPromptTokens,
|
|
25957
|
+
providerID: modelForBudget?.providerID,
|
|
25958
|
+
modelID: modelForBudget?.modelID,
|
|
25959
|
+
agentName: notificationParams.agent,
|
|
25960
|
+
sessionId
|
|
25961
|
+
});
|
|
25962
|
+
} catch (error) {
|
|
25963
|
+
sessionLog2(sessionId, `transform: wire-estimate pressure fallback unavailable: ${getErrorMessage(error)}`);
|
|
25964
|
+
return;
|
|
25965
|
+
}
|
|
25966
|
+
};
|
|
25967
|
+
const usageBeforeSizing = contextUsage;
|
|
25968
|
+
const readingFrom = (pressureEstimate) => {
|
|
25969
|
+
const countPercentage = pressureEstimate?.pressureTokens !== undefined && Number.isFinite(pressureEstimate.pressureTokens) && typeof localReadingWindow === "number" && localReadingWindow > 0 ? pressureEstimate.pressureTokens / localReadingWindow * 100 : 0;
|
|
25970
|
+
const grewPastSavedReading = savedProviderReading !== null && countPercentage >= 95 && countPercentage > savedProviderReading.percentage;
|
|
25971
|
+
const unchanged = {
|
|
25972
|
+
source: "none",
|
|
25973
|
+
usage: usageBeforeSizing,
|
|
25974
|
+
fromEstimate: hostOverWindow,
|
|
25975
|
+
countPercentage,
|
|
25976
|
+
grewPastSavedReading,
|
|
25977
|
+
pressureEstimate,
|
|
25978
|
+
usedProviderInput: false
|
|
25442
25979
|
};
|
|
25443
|
-
|
|
25444
|
-
|
|
25445
|
-
|
|
25446
|
-
|
|
25447
|
-
|
|
25980
|
+
if (savedProviderReading && !grewPastSavedReading) {
|
|
25981
|
+
return {
|
|
25982
|
+
...unchanged,
|
|
25983
|
+
source: "saved",
|
|
25984
|
+
usage: {
|
|
25985
|
+
inputTokens: savedProviderReading.inputTokens,
|
|
25986
|
+
percentage: Math.max(usageBeforeSizing.percentage, savedProviderReading.percentage)
|
|
25987
|
+
}
|
|
25988
|
+
};
|
|
25989
|
+
}
|
|
25990
|
+
if (!pressureEstimate)
|
|
25991
|
+
return unchanged;
|
|
25992
|
+
const usage = resolveUnknownUsageFromWireEstimate({
|
|
25993
|
+
usage: usageBeforeSizing,
|
|
25448
25994
|
pricedPass: true,
|
|
25449
25995
|
wireEstimateTokens: overflowRecoveryPass ? pressureEstimate.tokens : pressureEstimate.pressureTokens,
|
|
25450
25996
|
wireEstimateTrusted: pressureEstimate.trusted,
|
|
25451
25997
|
providerProvenInputTokens: providerProvenInputForRecovery,
|
|
25452
25998
|
providerProvenLimitTokens: providerProvenLimitForRecovery,
|
|
25453
|
-
|
|
25999
|
+
windowTokens: localReadingWindow
|
|
25454
26000
|
});
|
|
25455
|
-
if (
|
|
25456
|
-
|
|
25457
|
-
|
|
25458
|
-
|
|
26001
|
+
if (usage.inputTokens <= 0)
|
|
26002
|
+
return { ...unchanged, usage };
|
|
26003
|
+
const usedProviderInput = !pressureEstimate.trusted && providerProvenLimitForRecovery !== undefined && providerProvenInputForRecovery !== undefined && usage.inputTokens >= providerProvenInputForRecovery;
|
|
26004
|
+
return {
|
|
26005
|
+
...unchanged,
|
|
26006
|
+
source: "estimate",
|
|
26007
|
+
usage,
|
|
26008
|
+
usedProviderInput,
|
|
26009
|
+
fromEstimate: !overflowRecoveryPass && !usedProviderInput && !usagePercentageSynthetic && usage.percentage > usageBeforeSizing.percentage
|
|
26010
|
+
};
|
|
26011
|
+
};
|
|
26012
|
+
const planAt = (usage) => {
|
|
26013
|
+
if (!sizingInput || !planInput)
|
|
26014
|
+
return;
|
|
26015
|
+
try {
|
|
26016
|
+
return planPricedPass(planInput, usage);
|
|
26017
|
+
} catch (error) {
|
|
26018
|
+
sessionLog2(sessionId, `transform: priced-pass sizing counts the widest request: ${getErrorMessage(error)}`);
|
|
26019
|
+
return;
|
|
25459
26020
|
}
|
|
26021
|
+
};
|
|
26022
|
+
let plan = planAt({
|
|
26023
|
+
percentage: usageBeforeSizing.percentage,
|
|
26024
|
+
fromEstimate: hostOverWindow
|
|
26025
|
+
}) ?? WIDEST_PRICED_PASS_PLAN;
|
|
26026
|
+
let reading = readingFrom(countRequest(plan));
|
|
26027
|
+
for (let attempt = 0;sizingInput && plan !== WIDEST_PRICED_PASS_PLAN; attempt++) {
|
|
26028
|
+
const next = planAt({
|
|
26029
|
+
percentage: reading.usage.percentage,
|
|
26030
|
+
fromEstimate: reading.fromEstimate
|
|
26031
|
+
});
|
|
26032
|
+
if (next && sameSizingPlan(sizingInput, next, plan))
|
|
26033
|
+
break;
|
|
26034
|
+
plan = next && attempt === 0 ? next : WIDEST_PRICED_PASS_PLAN;
|
|
26035
|
+
reading = readingFrom(countRequest(plan));
|
|
26036
|
+
}
|
|
26037
|
+
const sizedPlan = `sizedPlan=${plan.clearsReasoning ? "clears_reasoning" : "keeps_reasoning"}${plan.editsWholePrefix ? "+covered_rows" : ""}`;
|
|
26038
|
+
contextUsage = reading.usage;
|
|
26039
|
+
if (reading.source === "saved") {
|
|
26040
|
+
sessionLog2(sessionId, `transform: unknown provider usage; using saved provider reading for priced pass inputTokens=${contextUsage.inputTokens} percentage=${contextUsage.percentage.toFixed(1)} countPercentage=${reading.countPercentage.toFixed(1)} ${sizedPlan}`);
|
|
26041
|
+
} else if (reading.source === "estimate" && reading.pressureEstimate) {
|
|
26042
|
+
const pressureEstimate = reading.pressureEstimate;
|
|
26043
|
+
contextUsageFromEstimate = reading.fromEstimate;
|
|
26044
|
+
sessionLog2(sessionId, `transform: unknown provider usage; using ${reading.usedProviderInput ? "provider-proven input" : "wire estimate"} for priced pass inputTokens=${contextUsage.inputTokens} percentage=${contextUsage.percentage.toFixed(1)} trusted=${pressureEstimate.trusted} wireTokens=${pressureEstimate.tokens} pressureTokens=${pressureEstimate.pressureTokens}${reading.grewPastSavedReading ? ` grewPastSavedReading=${savedProviderReading?.percentage.toFixed(1)}` : ""} ${sizedPlan}`);
|
|
25460
26045
|
}
|
|
25461
26046
|
}
|
|
25462
26047
|
const protectionUsableSoft = windowGeometry?.usableSoft ?? boundaryContextLimit;
|
|
@@ -25520,6 +26105,7 @@ Historian previously failed ${historianFailureState.failureCount} time(s), so Ma
|
|
|
25520
26105
|
directoryPrefixHold: unresolvedDirectoryHold,
|
|
25521
26106
|
forceSignedRebuildForFit: thinkingFitRetries.has(sessionId) || !!recovery.rebuildReason,
|
|
25522
26107
|
compactionModeTransition: compactionModeTransitionPending.has(sessionId),
|
|
26108
|
+
requestToolsChange: requestToolsRelease?.change ?? null,
|
|
25523
26109
|
readLastServedMessages: () => {
|
|
25524
26110
|
const slot = getInMemorySlot(sessionId) ?? loadPersistedLkgSlot(db, sessionId);
|
|
25525
26111
|
try {
|
|
@@ -25578,6 +26164,7 @@ Historian previously failed ${historianFailureState.failureCount} time(s), so Ma
|
|
|
25578
26164
|
}
|
|
25579
26165
|
});
|
|
25580
26166
|
compactionModeTransitionPending.delete(sessionId);
|
|
26167
|
+
requestToolsRelease?.commit();
|
|
25581
26168
|
if (recovery.prefix && recoveryReleased && !recoveryNormalized) {
|
|
25582
26169
|
if (!recoveryBeforePostprocess)
|
|
25583
26170
|
throw new Error("Cannot release recovery without its pre-edit snapshot");
|
|
@@ -25638,8 +26225,9 @@ Historian previously failed ${historianFailureState.failureCount} time(s), so Ma
|
|
|
25638
26225
|
logIncompleteFinalWire(finalWireEstimate, messages);
|
|
25639
26226
|
sessionLog2(sessionId, `transform: final-wire telemetry estimate=${finalWireEstimate.tokens} trusted=${finalWireEstimate.trusted} conversation=${finalWireEstimate.messageTokens.conversation} tools=${finalWireEstimate.messageTokens.toolCall} system=${finalWireEstimate.systemTokens} toolDefinitions=${finalWireEstimate.toolDefinitionTokens ?? "unknown"} tail=${finalWireTail}`);
|
|
25640
26227
|
}
|
|
26228
|
+
const recoveryAdmissionPass = emergencyRecoveryArmed && emergencyRecoveryOrigin !== null && emergencyUsagePercentage >= 95;
|
|
25641
26229
|
let servedPressureTokens;
|
|
25642
|
-
if (providerReadingMissing) {
|
|
26230
|
+
if (providerReadingMissing || recoveryAdmissionPass) {
|
|
25643
26231
|
servedPressureTokens = finalWireEstimate?.pressureTokens;
|
|
25644
26232
|
if (servedPressureTokens === undefined) {
|
|
25645
26233
|
try {
|
|
@@ -25656,12 +26244,13 @@ Historian previously failed ${historianFailureState.failureCount} time(s), so Ma
|
|
|
25656
26244
|
}
|
|
25657
26245
|
}
|
|
25658
26246
|
}
|
|
26247
|
+
const recoveryAdmissionTokens = recoveryAdmissionPass && servedPressureTokens !== undefined ? servedPressureTokens + recoveryHostAddedTokens : undefined;
|
|
25659
26248
|
localWireReadings.record({
|
|
25660
26249
|
sessionId,
|
|
25661
26250
|
providerReadingMissing,
|
|
25662
26251
|
modelKey: localReadingModelKey,
|
|
25663
26252
|
usableWindow: localReadingWindow,
|
|
25664
|
-
pressureTokens: servedPressureTokens
|
|
26253
|
+
pressureTokens: providerReadingMissing ? servedPressureTokens : undefined
|
|
25665
26254
|
});
|
|
25666
26255
|
if ((finalWireEstimate?.refusalGrade || finalWireEstimate?.refusalBasis === "byte-bound" && finalWireEstimate.refusalTokens !== undefined) && boundaryContextLimit > 0 && (finalWireEstimate.refusalTokens ?? finalWireEstimate.tokens) > boundaryContextLimit) {
|
|
25667
26256
|
const signedFitRetryWanted = !thinkingFitRetries.has(sessionId) && activeThinkingPrefixHold && hasActiveAnthropicThinkingTurn(messages, resolvedProviderID, modelForBudget?.modelID);
|
|
@@ -25716,6 +26305,21 @@ Historian previously failed ${historianFailureState.failureCount} time(s), so Ma
|
|
|
25716
26305
|
unmanagedOverWindowSessions.delete(sessionId);
|
|
25717
26306
|
sessionLog2(sessionId, `over-window first pass reduced: the request is about ${servedTokens} tokens (history started at ${unmanagedOverWindowPass.tokens}), under the ${unmanagedOverWindowPass.limit}-token window`);
|
|
25718
26307
|
}
|
|
26308
|
+
const currentModelKeyForRecovery = deps.getModelKey?.(sessionId);
|
|
26309
|
+
const keepRecoveryArmed = () => {
|
|
26310
|
+
if (!emergencyRecoveryArmed || emergencyRecoveryOrigin === null)
|
|
26311
|
+
return;
|
|
26312
|
+
try {
|
|
26313
|
+
if (getOverflowState(db, sessionId).needsEmergencyRecovery)
|
|
26314
|
+
return;
|
|
26315
|
+
recordOverflowDetected(db, sessionId, undefined, currentModelKeyForRecovery, emergencyRecoveryOrigin);
|
|
26316
|
+
} catch (error) {
|
|
26317
|
+
throw new EmergencyFailClosedError("Emergency recovery re-arm failed", {
|
|
26318
|
+
cause: error
|
|
26319
|
+
});
|
|
26320
|
+
}
|
|
26321
|
+
sessionLog2(sessionId, `transform: recovery was cleared during a pass that is not sent; armed again (${emergencyRecoveryOrigin}) for the next turn`);
|
|
26322
|
+
};
|
|
25719
26323
|
const timedOutHistorianFailure = compartmentPhase.historianJoinTimedOut ? historianJoinFailClosedMessage({
|
|
25720
26324
|
timedOut: true,
|
|
25721
26325
|
budgetMs: compartmentPhase.historianJoinBudgetMs,
|
|
@@ -25725,14 +26329,21 @@ Historian previously failed ${historianFailureState.failureCount} time(s), so Ma
|
|
|
25725
26329
|
}) : null;
|
|
25726
26330
|
if (timedOutHistorianFailure) {
|
|
25727
26331
|
sessionLog2(sessionId, `transform: ${timedOutHistorianFailure}; finalEstimate=${finalWireEstimate?.tokens ?? "unavailable"} estimateTrusted=${finalWireEstimate?.trusted ?? false} contextLimit=${boundaryContextLimit} emergencyReclaimed=${postTransformResult.emergencyReclaimedTokens}`);
|
|
26332
|
+
keepRecoveryArmed();
|
|
25728
26333
|
throw new EmergencyFailClosedError(timedOutHistorianFailure);
|
|
25729
26334
|
}
|
|
25730
26335
|
if (compartmentPhase.historianJoinTimedOut) {
|
|
25731
26336
|
sessionLog2(sessionId, `transform: proceeding after bounded historian join; trusted final-wire ${finalWireEstimate?.tokens} fits context limit ${boundaryContextLimit} after emergency reclaim=${postTransformResult.emergencyReclaimedTokens}`);
|
|
25732
26337
|
}
|
|
25733
|
-
const currentModelKeyForRecovery = deps.getModelKey?.(sessionId);
|
|
25734
26338
|
const overflowStateForFinalWire = getOverflowState(db, sessionId, currentModelKeyForRecovery);
|
|
25735
26339
|
const providerProvenLimitTokens = typeof currentModelKeyForRecovery === "string" && currentModelKeyForRecovery.length > 0 && overflowStateForFinalWire.detectedContextLimit > 0 && piModelRefToCanonical(overflowStateForFinalWire.detectedContextLimitModelKey ?? "") === piModelRefToCanonical(currentModelKeyForRecovery) ? overflowStateForFinalWire.detectedContextLimit : undefined;
|
|
26340
|
+
const recoveryWindowTokens = windowGeometry?.usableHard ?? resolvedContextLimit;
|
|
26341
|
+
const recoveryHistoryRemains = compartmentPhase.recoveryHistoryRemains;
|
|
26342
|
+
const recoveryServedRequest = recoveryAdmissionTokens !== undefined && typeof recoveryWindowTokens === "number" && recoveryWindowTokens > 0 ? {
|
|
26343
|
+
tokens: recoveryAdmissionTokens,
|
|
26344
|
+
lineTokens: recoveryAdmissionLimitTokens(recoveryWindowTokens, recoveryHistoryRemains),
|
|
26345
|
+
historyRemains: recoveryHistoryRemains
|
|
26346
|
+
} : undefined;
|
|
25736
26347
|
const emergencyFailClosed = evaluateEmergencyFailClosed2({
|
|
25737
26348
|
usagePercentage: emergencyUsagePercentage,
|
|
25738
26349
|
emergencyRecoveryArmed,
|
|
@@ -25741,18 +26352,27 @@ Historian previously failed ${historianFailureState.failureCount} time(s), so Ma
|
|
|
25741
26352
|
finalWireEstimate,
|
|
25742
26353
|
providerProvenLimitTokens,
|
|
25743
26354
|
contextLimitTokens: boundaryContextLimit,
|
|
25744
|
-
protectedToolTokens: protectedToolTokenCount(getActiveTagsBySession2(db, sessionId), deps.protectedTools, resolveDecisionCalibration(modelForBudget?.providerID, modelForBudget?.modelID))
|
|
26355
|
+
protectedToolTokens: protectedToolTokenCount(getActiveTagsBySession2(db, sessionId), deps.protectedTools, resolveDecisionCalibration(modelForBudget?.providerID, modelForBudget?.modelID)),
|
|
26356
|
+
recoveryServedRequest
|
|
25745
26357
|
});
|
|
25746
26358
|
if (emergencyFailClosed.disarm) {
|
|
25747
26359
|
clearEmergencyRecovery(db, sessionId);
|
|
25748
26360
|
sessionLog2(sessionId, `emergency disarm: trusted final-wire ${emergencyFailClosed.disarm.finalWireTokens} under limit ${emergencyFailClosed.disarm.provenLimitTokens}`);
|
|
26361
|
+
} else if (recoveryAdmissionPass && !emergencyFailClosed.shouldAbort && recoveryServedRequest !== undefined) {
|
|
26362
|
+
clearEmergencyRecovery(db, sessionId);
|
|
26363
|
+
sessionLog2(sessionId, `transform: recovery request admitted: about ${recoveryServedRequest.tokens} tokens, within ${recoveryServedRequest.lineTokens} of ${recoveryWindowTokens}; ${emergencyRecoveryOrigin} recovery ends`);
|
|
25749
26364
|
}
|
|
25750
26365
|
if (emergencyFailClosed.shouldAbort) {
|
|
26366
|
+
keepRecoveryArmed();
|
|
25751
26367
|
if (emergencyFailClosed.refusalMessage) {
|
|
25752
26368
|
throw contextRefusalError(emergencyFailClosed.refusalMessage);
|
|
25753
26369
|
}
|
|
26370
|
+
const recoveryOverLimit = emergencyFailClosed.reason === "recovery-request-over-limit" && recoveryServedRequest !== undefined;
|
|
26371
|
+
if (recoveryOverLimit) {
|
|
26372
|
+
sessionLog2(sessionId, recoveryServedRequest.historyRemains ? `transform: recovery request still over the window: about ${recoveryServedRequest.tokens} tokens against the 95% line ${recoveryServedRequest.lineTokens} of ${recoveryWindowTokens}; not sending it, recovery stays armed for the next turn` : `transform: recovery request still over the window: about ${recoveryServedRequest.tokens} tokens against the whole window ${recoveryServedRequest.lineTokens}, with no older history left to summarize; not sending it`);
|
|
26373
|
+
}
|
|
25754
26374
|
try {
|
|
25755
|
-
await host.hostRefusalNotice(deps.client, sessionId, EMERGENCY_REFUSAL_NOTICE, notificationParams);
|
|
26375
|
+
await host.hostRefusalNotice(deps.client, sessionId, recoveryOverLimit ? recoveryRefusalNotice(recoveryServedRequest.historyRemains) : EMERGENCY_REFUSAL_NOTICE, notificationParams);
|
|
25756
26376
|
} catch (error) {
|
|
25757
26377
|
throw new EmergencyFailClosedError("Emergency recovery notification failed", {
|
|
25758
26378
|
cause: error
|
|
@@ -26010,9 +26630,15 @@ Historian previously failed ${historianFailureState.failureCount} time(s), so Ma
|
|
|
26010
26630
|
};
|
|
26011
26631
|
const timedTransform = (input, output) => withTransformTimingSummary(async () => {
|
|
26012
26632
|
const sessionId = findSessionId(output.messages);
|
|
26633
|
+
if (sessionId)
|
|
26634
|
+
forgetHostCheckpointPass(sessionId);
|
|
26013
26635
|
try {
|
|
26014
26636
|
await transform(input, output);
|
|
26637
|
+
if (sessionId)
|
|
26638
|
+
forgetHostCheckpointPass(sessionId);
|
|
26015
26639
|
} catch (error) {
|
|
26640
|
+
if (sessionId)
|
|
26641
|
+
revertHostCheckpointPass(sessionId, deps.pendingMaterializationSessions);
|
|
26016
26642
|
if (sessionId && !deps.compactionOff && error instanceof EmergencyFailClosedError)
|
|
26017
26643
|
recordUsageRefusal(deps.db, sessionId);
|
|
26018
26644
|
throw error;
|
|
@@ -29259,9 +29885,9 @@ var FULL_PARAMETER_DESCRIPTIONS = {
|
|
|
29259
29885
|
},
|
|
29260
29886
|
ctx_memory: {
|
|
29261
29887
|
action: "write | update | archive | merge | get",
|
|
29262
|
-
content: "The memory text — one standalone fact (write, update, merge).",
|
|
29263
|
-
category: "Kind of fact
|
|
29264
|
-
ids: "Memory ids from <project-memory>: one for update, one or more for archive, two or more for merge, 1–20 for get.",
|
|
29888
|
+
content: "The memory text — one standalone fact (write, update, merge). Archive and get take an empty string.",
|
|
29889
|
+
category: "Kind of fact: the new fact's kind for write; on update/merge, the memory's current category to keep it. Archive and get ignore it.",
|
|
29890
|
+
ids: "Memory ids from <project-memory>: one for update, one or more for archive, two or more for merge, 1–20 for get. Write takes an empty list.",
|
|
29265
29891
|
reason: "Why it is being archived (optional)."
|
|
29266
29892
|
},
|
|
29267
29893
|
ctx_search: {
|
|
@@ -29294,9 +29920,9 @@ var LIGHT_PARAMETER_DESCRIPTIONS = {
|
|
|
29294
29920
|
},
|
|
29295
29921
|
ctx_memory: {
|
|
29296
29922
|
action: "write | update | archive | merge | get",
|
|
29297
|
-
content: "One standalone fact (write, update, merge).",
|
|
29298
|
-
category: "Kind of fact (
|
|
29299
|
-
ids: "Ids from <project-memory>: one for update, 1+ for archive, 2+ for merge, 1–20 for get.",
|
|
29923
|
+
content: "One standalone fact (write, update, merge). Archive and get: empty string.",
|
|
29924
|
+
category: "Kind of fact (write; on update/merge pass the current category to keep it). Archive and get ignore it.",
|
|
29925
|
+
ids: "Ids from <project-memory>: one for update, 1+ for archive, 2+ for merge, 1–20 for get. Write: empty list.",
|
|
29300
29926
|
reason: "Why it is archived (optional)."
|
|
29301
29927
|
},
|
|
29302
29928
|
ctx_search: {
|
|
@@ -29773,4 +30399,4 @@ function applyHiddenSubagentTemperature(input, output, log) {
|
|
|
29773
30399
|
output.temperature = temperature;
|
|
29774
30400
|
}
|
|
29775
30401
|
|
|
29776
|
-
export { logConfigDependencyNotesOnce, openOpenCodeDb, DREAMER_SYSTEM_PROMPT, runSessionProjectBackfill, SMART_NOTE_COMPILER_SYSTEM_PROMPT, createLiveSessionState, RETROSPECTIVE_MAX_USER_MESSAGE_CHARS, RETROSPECTIVE_MESSAGE_TRUNCATION_MARKER, OpenCodeRetrospectiveRawProvider, createDreamTaskExecutor, runManualDream, runDueTasksForProject, startDreamScheduleTimer, createDreamTimerModuleClient, ensureProjectRegisteredFromOpenCodeDirectory, recordOpenCodeProvenInputFloor, resolveOpenCodeProvenInputFloor, resolveContextWindowGeometry, resolveContextLimit, resolveExecuteThresholdDetail, resolveModelKey, resolveSessionId, parseCacheTtl, createScheduler, computeHardCacheExpired, describeStorageUnavailability, resolveSessionCacheTtl, runEmbedHistoryDrain, pauseEmbedHistoryDrain, formatEmbedStatusText, getSessionProperties, getSessionCreatedInfo, getMessageUpdatedAssistantInfo, getMessageUpdatedInfo, getSessionErrorInfo, getMessageRemovedInfo, summarizeManualDream, createMagicContextCommandHandler, getLiveNotificationParams, createChatMessageHook, createEventHook, createCommandExecuteBeforeHook, createToolExecuteAfterHook, recordHiddenVariantWarning, buildStatusDetail, isDebugRpcEnabled, registerRpcHandlers, maybeAutoEmbedSessionBackfill, clearTransformDecisionSession, scheduleOpenCodeTransformDecisionWrite, stageOpenCodeV2TransformDecision, bindOpenCodeV2TransformDecision, maybeDeliverChannel2, armLatestThinkingRecovery, armBindingRecoverySafely, armLatestThinkingRecoveryFromError, createM0RenderOptions, lkgReplayLimit, measureLkgReplay, STORAGE_BUSY_MESSAGE, StorageBusyRefusalError, bindSystemDateRequestIdentity, bindSystemDateOutput, registerSystemDateRefresh, rustWrapupHistorianFields, UnmanagedOverWindowError, UnresolvedHistoryBoundaryError, clearMessageTokensCache, createTransform, createSubcModuleClient, createModuleToolBackends, createRustRefusalRecovery, createSystemPromptHashHandler, tryMessagesTransformLkgReplay, createMessagesTransformHandler, primaryOnlyToolIds, subagentToolRefusal, guardSubagentTools, hideSubagentTools, removePrimaryOnlyTools, storedSubagentMode, createCtxExpandTools, CTX_MEMORY_LIST_TOOL_NAME, CTX_MEMORY_ACTIONS, createCtxMemoryTools, createCtxMemoryListTools, CTX_NOTE_DESCRIPTION, withoutSmartNoteText, createCtxNoteTools, createCtxReduceTools, createCtxSearchTools, parameterDescriptionsFor, applyJsonSchemaParameterDescriptions, MagicContextRpcServer, subagentTemperature, applyHiddenSubagentTemperature };
|
|
30402
|
+
export { logConfigDependencyNotesOnce, openOpenCodeDb, DREAMER_SYSTEM_PROMPT, runSessionProjectBackfill, SMART_NOTE_COMPILER_SYSTEM_PROMPT, createLiveSessionState, RETROSPECTIVE_MAX_USER_MESSAGE_CHARS, RETROSPECTIVE_MESSAGE_TRUNCATION_MARKER, OpenCodeRetrospectiveRawProvider, createDreamTaskExecutor, runManualDream, runDueTasksForProject, startDreamScheduleTimer, createDreamTimerModuleClient, ensureProjectRegisteredFromOpenCodeDirectory, recordOpenCodeProvenInputFloor, resolveOpenCodeProvenInputFloor, resolveContextWindowGeometry, resolveContextLimit, resolveExecuteThresholdDetail, resolveModelKey, resolveSessionId, parseCacheTtl, createScheduler, computeHardCacheExpired, describeStorageUnavailability, resolveSessionCacheTtl, runEmbedHistoryDrain, pauseEmbedHistoryDrain, formatEmbedStatusText, getSessionProperties, getSessionCreatedInfo, getMessageUpdatedAssistantInfo, getMessageUpdatedInfo, getSessionErrorInfo, getMessageRemovedInfo, summarizeManualDream, createMagicContextCommandHandler, getLiveNotificationParams, createChatMessageHook, createEventHook, createCommandExecuteBeforeHook, createToolExecuteAfterHook, recordHiddenVariantWarning, buildStatusDetail, isDebugRpcEnabled, registerRpcHandlers, maybeAutoEmbedSessionBackfill, clearTransformDecisionSession, scheduleOpenCodeTransformDecisionWrite, stageOpenCodeV2TransformDecision, bindOpenCodeV2TransformDecision, maybeDeliverChannel2, armLatestThinkingRecovery, armBindingRecoverySafely, armLatestThinkingRecoveryFromError, armThinkingBindingRecoveryFromError, createM0RenderOptions, lkgReplayLimit, measureLkgReplay, STORAGE_BUSY_MESSAGE, StorageBusyRefusalError, bindSystemDateRequestIdentity, bindSystemDateOutput, registerSystemDateRefresh, rustWrapupHistorianFields, UnmanagedOverWindowError, UnresolvedHistoryBoundaryError, clearMessageTokensCache, createTransform, createSubcModuleClient, createModuleToolBackends, createRustRefusalRecovery, createSystemPromptHashHandler, tryMessagesTransformLkgReplay, createMessagesTransformHandler, primaryOnlyToolIds, subagentToolRefusal, guardSubagentTools, hideSubagentTools, removePrimaryOnlyTools, storedSubagentMode, createCtxExpandTools, CTX_MEMORY_LIST_TOOL_NAME, CTX_MEMORY_ACTIONS, createCtxMemoryTools, createCtxMemoryListTools, CTX_NOTE_DESCRIPTION, withoutSmartNoteText, createCtxNoteTools, createCtxReduceTools, createCtxSearchTools, parameterDescriptionsFor, applyJsonSchemaParameterDescriptions, MagicContextRpcServer, subagentTemperature, applyHiddenSubagentTemperature };
|