@cortexkit/opencode-magic-context 0.49.90 → 0.49.92
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/auto-search-worker.js +4 -4
- package/dist/chunk-embedding-write-worker.js +6 -6
- package/dist/{compartment-chunk-embedding-fey2bsyf.js → compartment-chunk-embedding-rp4asvk0.js} +3 -3
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/migrate-dreamer-v2.d.ts +1 -0
- package/dist/config/migrate-dreamer-v2.d.ts.map +1 -1
- package/dist/{conflict-warning-hook-kbq6ppjf.js → conflict-warning-hook-exf96bpt.js} +3 -3
- package/dist/{context-cdds0gjj.js → context-e8qd2v00.js} +579 -245
- package/dist/{embedding-backfill-qjkaee9s.js → embedding-backfill-w0yq71q2.js} +6 -6
- package/dist/embedding-worker.js +3 -3
- package/dist/features/magic-context/dreamer/refresh-primers.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/task-scheduler.d.ts +2 -2
- package/dist/features/magic-context/dreamer/task-scheduler.d.ts.map +1 -1
- package/dist/features/magic-context/memory/single-store-embedding-drain.d.ts.map +1 -1
- package/dist/features/magic-context/overflow-detection.d.ts +7 -1
- package/dist/features/magic-context/overflow-detection.d.ts.map +1 -1
- package/dist/features/magic-context/project-embedding-registry.d.ts +2 -1
- package/dist/features/magic-context/project-embedding-registry.d.ts.map +1 -1
- package/dist/features/magic-context/storage-meta-persisted.d.ts +13 -3
- package/dist/features/magic-context/storage-meta-persisted.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-parser.d.ts +2 -0
- package/dist/hooks/magic-context/compartment-parser.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-runner-incremental.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-runner-types.d.ts +7 -7
- package/dist/hooks/magic-context/compartment-runner-types.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-runner-validation.d.ts +3 -0
- package/dist/hooks/magic-context/compartment-runner-validation.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-trigger.d.ts +2 -1
- package/dist/hooks/magic-context/compartment-trigger.d.ts.map +1 -1
- package/dist/hooks/magic-context/event-handler.d.ts +4 -0
- package/dist/hooks/magic-context/event-handler.d.ts.map +1 -1
- package/dist/hooks/magic-context/event-resolvers.d.ts +5 -0
- package/dist/hooks/magic-context/event-resolvers.d.ts.map +1 -1
- package/dist/hooks/magic-context/historian-drain-gate.d.ts +15 -0
- package/dist/hooks/magic-context/historian-drain-gate.d.ts.map +1 -1
- package/dist/hooks/magic-context/historian-host-runner.d.ts +1 -1
- package/dist/hooks/magic-context/historian-host-runner.d.ts.map +1 -1
- package/dist/hooks/magic-context/historian-prompt.generated.d.ts +1 -1
- package/dist/hooks/magic-context/historian-prompt.generated.d.ts.map +1 -1
- package/dist/hooks/magic-context/historian-publish-stage-logger.d.ts +5 -0
- package/dist/hooks/magic-context/historian-publish-stage-logger.d.ts.map +1 -1
- package/dist/hooks/magic-context/hook.d.ts.map +1 -1
- package/dist/hooks/magic-context/provider-overflow-notice.d.ts +8 -0
- package/dist/hooks/magic-context/provider-overflow-notice.d.ts.map +1 -0
- package/dist/hooks/magic-context/read-session-db.d.ts +2 -0
- package/dist/hooks/magic-context/read-session-db.d.ts.map +1 -1
- package/dist/hooks/magic-context/read-session-formatting.d.ts +2 -0
- package/dist/hooks/magic-context/read-session-formatting.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform-compartment-phase.d.ts +5 -0
- package/dist/hooks/magic-context/transform-compartment-phase.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform.d.ts.map +1 -1
- package/dist/{index-1y4y98r1.js → index-01h7tqe3.js} +25 -2
- package/dist/{index-3pdknr07.js → index-0twg41mh.js} +2 -2
- package/dist/{index-q7msfgwz.js → index-3f3d548g.js} +1503 -1371
- package/dist/{index-2pdgy88n.js → index-3n376ann.js} +19 -7
- package/dist/{index-78t37mcq.js → index-41bma6qs.js} +3 -3
- package/dist/{index-qfcjrnpe.js → index-5a9kwapd.js} +4 -4
- package/dist/{index-dk3hy2a2.js → index-5pmf4jpj.js} +10 -10
- package/dist/{index-2qsca7h7.js → index-5y9w2ax7.js} +4 -4
- package/dist/{index-pxnzyvjc.js → index-6r99v53h.js} +1 -1
- package/dist/{index-mrjat4eq.js → index-6rk44cer.js} +3 -3
- package/dist/{index-60wnwcwz.js → index-901exj0f.js} +91 -26
- package/dist/{index-6zewd2n5.js → index-9ffntwyr.js} +1 -1
- package/dist/{index-h9hybzr5.js → index-anwy2mfb.js} +6 -6
- package/dist/{index-83qd3n7s.js → index-et39x9k3.js} +1 -1
- package/dist/{index-w51n3576.js → index-f25ha337.js} +1 -1
- package/dist/{index-kknjvmpx.js → index-fqth7850.js} +51 -60
- package/dist/{index-zxhev8ze.js → index-hbn5g7rt.js} +1 -1
- package/dist/{index-chpzb6xy.js → index-hre29c1a.js} +2 -2
- package/dist/{index-08jfpny9.js → index-j2w79s9r.js} +76 -6
- package/dist/{index-tt0vs4x5.js → index-jba6ny4m.js} +28 -4
- package/dist/{index-m6dnydf8.js → index-mg9s2rc3.js} +1 -1
- package/dist/{index-61knrt52.js → index-mjy2k9jr.js} +1 -1
- package/dist/{index-wmb2mcdw.js → index-n71006wq.js} +6 -6
- package/dist/{index-n1ty0vd3.js → index-r3tdqqtq.js} +127 -101
- package/dist/{index-5vsk2cpp.js → index-s7460efs.js} +12 -1
- package/dist/{index-x40zr813.js → index-sp5pvs95.js} +9 -1
- package/dist/{index-9d3qgwq0.js → index-wvbg9m0h.js} +4 -4
- package/dist/index-x3rdza40.js +63 -0
- package/dist/{index-jzfsnbmm.js → index-xg1zjht5.js} +5 -5
- package/dist/{index-60x5d68t.js → index-xn9efn18.js} +1 -1
- package/dist/{index-39rzef89.js → index-ydhymf0b.js} +3 -3
- package/dist/{index-g0mb2kb4.js → index-zzhcshdk.js} +75 -67
- package/dist/index.js +97 -60
- package/dist/{message-index-bounded-r1qys471.js → message-index-bounded-f6fc00ze.js} +6 -6
- package/dist/migration-worker.js +4 -4
- package/dist/plugin/hooks/create-session-hooks.d.ts.map +1 -1
- package/dist/{project-embedding-registry-m3fp1pa4.js → project-embedding-registry-8je0xg18.js} +7 -5
- package/dist/raw-ordinal-warmup-worker.js +4 -4
- package/dist/{read-session-chunk-xv9f0wgb.js → read-session-chunk-y2ew3630.js} +5 -5
- package/dist/{recomp-orchestrator-dgyb394j.js → recomp-orchestrator-ggtcvb9g.js} +21 -20
- package/dist/{render-d014e603.js → render-q8c6wrq9.js} +14 -14
- package/dist/{search-archive-gybn6q7s.js → search-archive-pz1jf655.js} +7 -7
- package/dist/{search-9gceftb9.js → search-gjyrwapc.js} +16 -16
- package/dist/{send-session-notification-gzxz88vq.js → send-session-notification-0779tyd9.js} +2 -2
- package/dist/shared/model-suggestion-retry.d.ts +18 -0
- package/dist/shared/model-suggestion-retry.d.ts.map +1 -1
- package/dist/{storage-tags-f1ftvjpw.js → storage-tags-7raphcw6.js} +3 -3
- package/dist/{store-reader-nf8z86n9.js → store-reader-qbq6q4v0.js} +1 -1
- package/dist/{store-n4yz3n66.js → store-yr443ye8.js} +2 -2
- package/dist/{task-config-qt6n4bxm.js → task-config-vrebjxyy.js} +2 -1
- package/dist/{transform-postprocess-phase-34k1zwsy.js → transform-postprocess-phase-pmzdd3s2.js} +22 -21
- package/dist/v2/auto-search-worker.js +4 -4
- package/dist/v2/chunk-embedding-write-worker.js +6 -6
- package/dist/v2/{compartment-chunk-embedding-knt2468v.js → compartment-chunk-embedding-w7ht0t9v.js} +3 -3
- package/dist/v2/{context-satgm752.js → context-qqbpzk1q.js} +686 -323
- package/dist/v2/{embedding-backfill-0ar1bm97.js → embedding-backfill-95m72gxa.js} +6 -6
- package/dist/v2/embedding-worker.js +3 -3
- package/dist/v2/fold/host-media.d.ts.map +1 -1
- package/dist/v2/fold/native-replay-v3.d.ts.map +1 -1
- package/dist/v2/fold/native-replay.d.ts +1 -0
- package/dist/v2/fold/native-replay.d.ts.map +1 -1
- package/dist/v2/fold/restore.d.ts +15 -0
- package/dist/v2/fold/restore.d.ts.map +1 -1
- package/dist/v2/hidden-child-native.d.ts +1 -1
- package/dist/v2/hidden-child-native.d.ts.map +1 -1
- package/dist/v2/hidden-child-record.d.ts +11 -2
- package/dist/v2/hidden-child-record.d.ts.map +1 -1
- package/dist/v2/hidden-child-sweep.d.ts +3 -0
- package/dist/v2/hidden-child-sweep.d.ts.map +1 -1
- package/dist/v2/hidden-completion.d.ts +4 -0
- package/dist/v2/hidden-completion.d.ts.map +1 -1
- package/dist/v2/hidden-run-holder.d.ts +6 -6
- package/dist/v2/hidden-run-holder.d.ts.map +1 -1
- package/dist/v2/hooks/context.d.ts +2 -2
- package/dist/v2/hooks/context.d.ts.map +1 -1
- package/dist/v2/hooks/hidden-child.d.ts +2 -0
- package/dist/v2/hooks/hidden-child.d.ts.map +1 -1
- package/dist/v2/hooks/overflow-recovery.d.ts +6 -0
- package/dist/v2/hooks/overflow-recovery.d.ts.map +1 -1
- package/dist/v2/{message-index-bounded-b07r9cjv.js → message-index-bounded-70g28hyg.js} +6 -6
- package/dist/v2/migration-worker.js +4 -4
- package/dist/v2/{project-embedding-registry-gx2waee8.js → project-embedding-registry-fcxf4qht.js} +7 -5
- package/dist/v2/raw-ordinal-warmup-worker.js +4 -4
- package/dist/v2/{read-session-chunk-38wdy8nd.js → read-session-chunk-9rf0n9e6.js} +5 -5
- package/dist/v2/{recomp-orchestrator-wq7gbkqa.js → recomp-orchestrator-cwghhjc9.js} +21 -20
- package/dist/v2/{render-2dan17xc.js → render-e852zmxz.js} +14 -14
- package/dist/v2/{search-archive-89hdy0a2.js → search-archive-tmn6b5w8.js} +7 -7
- package/dist/v2/{search-nyqykx7q.js → search-jd3vczhn.js} +15 -15
- package/dist/v2/{send-session-notification-zazaxxpf.js → send-session-notification-v69y04f5.js} +2 -2
- package/dist/v2/server-3gz9k20t.js +63 -0
- package/dist/v2/{server-09h2vyvs.js → server-6t3asmx8.js} +6 -6
- package/dist/v2/{server-dgjqvpgd.js → server-72k2r3kt.js} +19 -7
- package/dist/v2/{server-pjk9spbf.js → server-7e89a2kf.js} +1 -1
- package/dist/v2/{server-dtcwkdqj.js → server-7x5a46hf.js} +1427 -1322
- package/dist/v2/{server-add0j5n3.js → server-8ps3717t.js} +3 -3
- package/dist/v2/{server-c7awk5s2.js → server-9011eteb.js} +4 -4
- package/dist/v2/{server-f7tzvmzs.js → server-b4efn08m.js} +1 -1
- package/dist/v2/{server-y17r5ryz.js → server-barj0mjz.js} +2 -2
- package/dist/v2/{server-b0a9h3ds.js → server-bvr9xs8h.js} +5 -5
- package/dist/v2/{server-pmws7we9.js → server-d4trxrj3.js} +91 -26
- package/dist/v2/{server-fb5hvvfc.js → server-fj3pekz2.js} +3 -3
- package/dist/v2/{server-6250cxzs.js → server-gs2251jr.js} +1 -1
- package/dist/v2/{server-a85j3kam.js → server-jkj1dq6j.js} +28 -4
- package/dist/v2/{server-ta4h0fch.js → server-js2v309w.js} +9 -9
- package/dist/v2/{server-9n2qgk29.js → server-mgxqfprb.js} +2 -2
- package/dist/v2/{server-2kswss3d.js → server-n5wn7d9b.js} +48 -60
- package/dist/v2/{server-vy0beygw.js → server-p4g021y5.js} +4 -4
- package/dist/v2/{server-x6fn9x8q.js → server-ps6zrzwj.js} +1 -1
- package/dist/v2/{server-y8xjr8rx.js → server-qb3s0mnc.js} +12 -1
- package/dist/v2/{server-stjy5dxv.js → server-qntmqaca.js} +1 -1
- package/dist/v2/{server-ytqps2xa.js → server-rkj44mez.js} +76 -6
- package/dist/v2/{server-tj65pgvg.js → server-vsqmkvxc.js} +32 -5
- package/dist/v2/{server-qyazxy92.js → server-vtgeyhq6.js} +25 -2
- package/dist/v2/{server-fn4ky6mn.js → server-x69fqsvz.js} +1 -1
- package/dist/v2/{server-yx0nyj1q.js → server-ysjjcatk.js} +3 -3
- package/dist/v2/server.js +4 -3
- package/dist/v2/{storage-tags-pmw33chf.js → storage-tags-wgsemtw1.js} +3 -3
- package/dist/v2/{store-y56y034s.js → store-enef5jcn.js} +2 -2
- package/dist/v2/{store-reader-2vhx33n6.js → store-reader-jbaqv1yp.js} +1 -1
- package/dist/v2/store-reader.d.ts +18 -0
- package/dist/v2/store-reader.d.ts.map +1 -1
- package/dist/v2/{task-config-ex2vajr2.js → task-config-4nqq2s0w.js} +2 -1
- package/dist/v2/{v2-archive-reader-gh1jghf7.js → v2-archive-reader-dm1aeqk2.js} +1 -1
- package/dist/v2/{wrapup-orchestrator-2h7ayss9.js → wrapup-orchestrator-cke368np.js} +21 -20
- package/dist/{v2-archive-reader-8158kyfd.js → v2-archive-reader-39ye0d3b.js} +1 -1
- package/dist/{wrapup-orchestrator-ct59br0c.js → wrapup-orchestrator-ggnk0r4r.js} +22 -21
- package/package.json +1 -1
- package/src/config/index.test.ts +58 -0
- package/src/config/index.ts +4 -1
- package/src/config/migrate-dreamer-v2.ts +42 -0
- package/src/shared/model-suggestion-retry.test.ts +37 -0
- package/src/shared/model-suggestion-retry.ts +38 -4
- package/src/shared/models-dev-cache.test.ts +15 -0
- package/src/shared/startup-maintenance-policy.test.ts +11 -6
- package/dist/index-ksdyrrav.js +0 -52
- package/dist/v2/server-0s95v3en.js +0 -49
- /package/dist/v2/{server-3ap5dmhc.js → server-5hwf5c7r.js} +0 -0
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
hiddenToolLoop,
|
|
18
18
|
HIDDEN_RUN_DISPOSED_REASON,
|
|
19
19
|
noteChildOfDisposedInstance,
|
|
20
|
+
noteTimedOutHiddenChild,
|
|
20
21
|
hiddenChildPermissions,
|
|
21
22
|
registerHiddenChildAgents,
|
|
22
23
|
hiddenToolCallRefusal,
|
|
@@ -25,8 +26,11 @@ import {
|
|
|
25
26
|
parseProviderModel,
|
|
26
27
|
toModelEntry,
|
|
27
28
|
ModelProducedNoOutputError,
|
|
29
|
+
promptTransportBudget,
|
|
30
|
+
notePromptSetupTimeout,
|
|
28
31
|
noteModelActivityMonitored,
|
|
29
32
|
noteModelOutputReceived,
|
|
33
|
+
isPromptTimeoutError,
|
|
30
34
|
annotateSubagentInvocationError,
|
|
31
35
|
recordChildInvocation,
|
|
32
36
|
CTX_NOTE_LIGHT_DESCRIPTION,
|
|
@@ -40,11 +44,11 @@ import {
|
|
|
40
44
|
materializeM0,
|
|
41
45
|
resetPrefixTrimFallbackState,
|
|
42
46
|
rebaseSessionCoordinatesAsync,
|
|
43
|
-
clearNoteNudgeTriggerOnly,
|
|
44
47
|
resolveOpenCodeProtectedTailBoundary,
|
|
48
|
+
clearNoteNudgeTriggerOnly,
|
|
45
49
|
nonNarrativeStoredGapRanges,
|
|
46
50
|
getActiveCompartmentRun
|
|
47
|
-
} from "./index-
|
|
51
|
+
} from "./index-3f3d548g.js";
|
|
48
52
|
import"./index-sd3egckz.js";
|
|
49
53
|
import {
|
|
50
54
|
getHarness2
|
|
@@ -69,16 +73,16 @@ import {
|
|
|
69
73
|
resolveKnownHistorianContextLimit2,
|
|
70
74
|
resolveHistorianContextLimit2
|
|
71
75
|
} from "./index-xsqw8kbd.js";
|
|
72
|
-
import"./index-6nqz8hsz.js";
|
|
73
76
|
import {
|
|
77
|
+
isDreamerRunnable,
|
|
78
|
+
isSmartNoteSurfaceAvailable,
|
|
79
|
+
isCompactionEnabled,
|
|
74
80
|
CANONICAL_DREAM_TASKS,
|
|
75
81
|
DREAM_TASK_CAPABILITIES,
|
|
76
82
|
formatUnsupportedDreamTasks,
|
|
77
|
-
isCanonicalDreamTask
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
userObservationsRequested2
|
|
81
|
-
} from "./index-kknjvmpx.js";
|
|
83
|
+
isCanonicalDreamTask
|
|
84
|
+
} from "./index-fqth7850.js";
|
|
85
|
+
import"./index-6nqz8hsz.js";
|
|
82
86
|
import {
|
|
83
87
|
logConfigDependencyNotesOnce,
|
|
84
88
|
runSessionProjectBackfill,
|
|
@@ -101,6 +105,9 @@ import {
|
|
|
101
105
|
maybeAutoEmbedSessionBackfill,
|
|
102
106
|
stageOpenCodeV2TransformDecision,
|
|
103
107
|
bindOpenCodeV2TransformDecision,
|
|
108
|
+
PROVIDER_OVERFLOW_NOTICE,
|
|
109
|
+
noteServedRecoveryForOverflowHint,
|
|
110
|
+
holdOverflowResendHint,
|
|
104
111
|
createM0RenderOptions,
|
|
105
112
|
lkgReplayLimit,
|
|
106
113
|
measureLkgReplay,
|
|
@@ -136,7 +143,7 @@ import {
|
|
|
136
143
|
applyJsonSchemaParameterDescriptions,
|
|
137
144
|
MagicContextRpcServer,
|
|
138
145
|
subagentTemperature
|
|
139
|
-
} from "./index-
|
|
146
|
+
} from "./index-r3tdqqtq.js";
|
|
140
147
|
import {
|
|
141
148
|
invalidateAutoEmbedSession,
|
|
142
149
|
clearEmbedSessionState
|
|
@@ -145,8 +152,8 @@ import {
|
|
|
145
152
|
hasMeaningfulUserText2,
|
|
146
153
|
preloadTokenizer,
|
|
147
154
|
estimateTokens
|
|
148
|
-
} from "./index-
|
|
149
|
-
import"./index-
|
|
155
|
+
} from "./index-s7460efs.js";
|
|
156
|
+
import"./index-6r99v53h.js";
|
|
150
157
|
import {
|
|
151
158
|
inRootAsyncContext2,
|
|
152
159
|
withSqliteTransformPass2,
|
|
@@ -161,7 +168,7 @@ import"./index-q7q6qp1f.js";
|
|
|
161
168
|
import"./index-s32f8y67.js";
|
|
162
169
|
import {
|
|
163
170
|
deleteChunkEmbedBackoffForSession2
|
|
164
|
-
} from "./index-
|
|
171
|
+
} from "./index-0twg41mh.js";
|
|
165
172
|
import {
|
|
166
173
|
advanceSessionActivity,
|
|
167
174
|
backfillSessionActivity,
|
|
@@ -199,8 +206,8 @@ import {
|
|
|
199
206
|
getSlot,
|
|
200
207
|
dropSlot,
|
|
201
208
|
copySessionStateForClone
|
|
202
|
-
} from "./index-
|
|
203
|
-
import"./index-
|
|
209
|
+
} from "./index-anwy2mfb.js";
|
|
210
|
+
import"./index-hre29c1a.js";
|
|
204
211
|
import {
|
|
205
212
|
stripPersistedAssistantText,
|
|
206
213
|
currentReclaimableToolOutputCount,
|
|
@@ -236,22 +243,28 @@ import {
|
|
|
236
243
|
getObservedEpochFloor,
|
|
237
244
|
isPrefixBoundThinkingModel,
|
|
238
245
|
detectOverflow,
|
|
246
|
+
isProviderRateLimit,
|
|
239
247
|
modelAcceptsEmptyContent,
|
|
240
248
|
markServedShapeRepair,
|
|
241
249
|
getEmptyImageParts,
|
|
242
250
|
estimateFinalWireInputTokens,
|
|
243
251
|
getMaxTagNumberBySession2,
|
|
244
252
|
getTagsBySession2
|
|
245
|
-
} from "./index-
|
|
253
|
+
} from "./index-901exj0f.js";
|
|
246
254
|
import {
|
|
247
255
|
BoundedSessionMap,
|
|
248
256
|
getTableColumnNames,
|
|
249
257
|
recordToolDefinitionSet,
|
|
250
258
|
getCurrentToolSetHash
|
|
251
|
-
} from "./index-
|
|
259
|
+
} from "./index-mg9s2rc3.js";
|
|
252
260
|
import {
|
|
253
261
|
resolveHistorianModel2
|
|
254
262
|
} from "./index-5kym00ag.js";
|
|
263
|
+
import {
|
|
264
|
+
buildDreamTaskRuntimeConfigs2,
|
|
265
|
+
userObservationCollectionEnabled2,
|
|
266
|
+
userObservationsRequested2
|
|
267
|
+
} from "./index-x3rdza40.js";
|
|
255
268
|
import {
|
|
256
269
|
formatFailClosedBlockingMessage,
|
|
257
270
|
formatFailClosedBlockingSummary,
|
|
@@ -267,7 +280,7 @@ import {
|
|
|
267
280
|
} from "./index-5pgyqgmx.js";
|
|
268
281
|
import"./index-1zx87sdm.js";
|
|
269
282
|
import"./index-58e3y90n.js";
|
|
270
|
-
import"./index-
|
|
283
|
+
import"./index-sp5pvs95.js";
|
|
271
284
|
import {
|
|
272
285
|
needsBlockedRead,
|
|
273
286
|
DreamTokenBudgetExceeded,
|
|
@@ -280,10 +293,10 @@ import {
|
|
|
280
293
|
cleanUserText2,
|
|
281
294
|
readRawSessionMessageIdOrdinalsForRange2,
|
|
282
295
|
readRawSessionMessageOrdinalById2
|
|
283
|
-
} from "./index-
|
|
296
|
+
} from "./index-5y9w2ax7.js";
|
|
284
297
|
import {
|
|
285
298
|
scheduleClearAndReindex
|
|
286
|
-
} from "./index-
|
|
299
|
+
} from "./index-hbn5g7rt.js";
|
|
287
300
|
import {
|
|
288
301
|
startBootDeadline,
|
|
289
302
|
getSchemaFenceRejection,
|
|
@@ -293,19 +306,20 @@ import {
|
|
|
293
306
|
openDatabaseAsync,
|
|
294
307
|
isDatabasePersisted,
|
|
295
308
|
getDatabasePersistenceError
|
|
296
|
-
} from "./index-
|
|
309
|
+
} from "./index-6rk44cer.js";
|
|
297
310
|
import"./index-fr0wbhdn.js";
|
|
298
|
-
import"./index-
|
|
311
|
+
import"./index-jba6ny4m.js";
|
|
299
312
|
import {
|
|
300
313
|
gaDatabasePath2,
|
|
301
314
|
RAW_MESSAGE_TYPES2,
|
|
302
315
|
V2StoreReaderPool2,
|
|
303
316
|
V2StoreReader2
|
|
304
|
-
} from "./index-
|
|
317
|
+
} from "./index-01h7tqe3.js";
|
|
305
318
|
import"./index-fb3zxn06.js";
|
|
306
|
-
import"./index-
|
|
319
|
+
import"./index-mjy2k9jr.js";
|
|
307
320
|
import {
|
|
308
321
|
resolveContextLimit,
|
|
322
|
+
resolveOpenCodeOverflowLimit,
|
|
309
323
|
resolveModelKey,
|
|
310
324
|
parseCacheTtl,
|
|
311
325
|
createScheduler,
|
|
@@ -321,20 +335,20 @@ import {
|
|
|
321
335
|
servedHeadChanged,
|
|
322
336
|
noteHostCheckpointCommit,
|
|
323
337
|
isSyntheticHeadMessage2
|
|
324
|
-
} from "./index-
|
|
338
|
+
} from "./index-zzhcshdk.js";
|
|
325
339
|
import"./index-832w615x.js";
|
|
326
340
|
import"./index-qt1qqasc.js";
|
|
327
341
|
import {
|
|
328
342
|
retainProjectEmbedding2
|
|
329
|
-
} from "./index-
|
|
343
|
+
} from "./index-3n376ann.js";
|
|
330
344
|
import"./index-r4y0dczp.js";
|
|
331
345
|
import"./index-qjwpqvnf.js";
|
|
332
|
-
import"./index-
|
|
346
|
+
import"./index-xn9efn18.js";
|
|
333
347
|
import {
|
|
334
348
|
renderUserFacingFailure,
|
|
335
349
|
userFacingFailureCode
|
|
336
|
-
} from "./index-
|
|
337
|
-
import"./index-
|
|
350
|
+
} from "./index-ydhymf0b.js";
|
|
351
|
+
import"./index-f25ha337.js";
|
|
338
352
|
import"./index-9emdjcb5.js";
|
|
339
353
|
import {
|
|
340
354
|
pushLiveNotification2,
|
|
@@ -342,9 +356,9 @@ import {
|
|
|
342
356
|
isTuiConnected2
|
|
343
357
|
} from "./index-y14pawe1.js";
|
|
344
358
|
import"./index-e6ncz7a6.js";
|
|
345
|
-
import"./index-
|
|
346
|
-
import"./index-
|
|
347
|
-
import"./index-
|
|
359
|
+
import"./index-9ffntwyr.js";
|
|
360
|
+
import"./index-5pmf4jpj.js";
|
|
361
|
+
import"./index-5a9kwapd.js";
|
|
348
362
|
import"./index-cr483vx6.js";
|
|
349
363
|
import {
|
|
350
364
|
detectConflicts
|
|
@@ -360,7 +374,7 @@ import {
|
|
|
360
374
|
rememberHostMedia,
|
|
361
375
|
hostMediaAsset,
|
|
362
376
|
hostMediaFromEncoded,
|
|
363
|
-
|
|
377
|
+
readerRestoreMedia,
|
|
364
378
|
restoreRow,
|
|
365
379
|
isToolError,
|
|
366
380
|
toolErrorText,
|
|
@@ -374,17 +388,12 @@ import {
|
|
|
374
388
|
readV2RawMessagePagesForConversion2,
|
|
375
389
|
createV2RawMessageReader2,
|
|
376
390
|
createV2RawMessageProvider2
|
|
377
|
-
} from "./index-
|
|
391
|
+
} from "./index-j2w79s9r.js";
|
|
378
392
|
import"./index-fmsr7v69.js";
|
|
379
|
-
import"./index-
|
|
393
|
+
import"./index-41bma6qs.js";
|
|
380
394
|
import"./index-52x68mj4.js";
|
|
381
|
-
import"./index-
|
|
382
|
-
import"./index-
|
|
383
|
-
import {
|
|
384
|
-
isDreamerRunnable,
|
|
385
|
-
isSmartNoteSurfaceAvailable,
|
|
386
|
-
isCompactionEnabled
|
|
387
|
-
} from "./index-ksdyrrav.js";
|
|
395
|
+
import"./index-xg1zjht5.js";
|
|
396
|
+
import"./index-wvbg9m0h.js";
|
|
388
397
|
import {
|
|
389
398
|
markHostInstructionRow,
|
|
390
399
|
hostInstructionRow,
|
|
@@ -2159,7 +2168,13 @@ function importedFloor(reader, sessionID, through = reader.latestSequence(sessio
|
|
|
2159
2168
|
let after = -1;
|
|
2160
2169
|
let found;
|
|
2161
2170
|
while (true) {
|
|
2162
|
-
const page = reader.page(sessionID, {
|
|
2171
|
+
const page = reader.page(sessionID, {
|
|
2172
|
+
after,
|
|
2173
|
+
through,
|
|
2174
|
+
type: "compaction",
|
|
2175
|
+
limit: 1000,
|
|
2176
|
+
preferTypeIndex: true
|
|
2177
|
+
});
|
|
2163
2178
|
if (!page.rows.length)
|
|
2164
2179
|
break;
|
|
2165
2180
|
for (const row of page.rows) {
|
|
@@ -2673,12 +2688,20 @@ ${cached}
|
|
|
2673
2688
|
const pending = this.legacyUpgrades.get(sessionID);
|
|
2674
2689
|
if (!pending)
|
|
2675
2690
|
return;
|
|
2676
|
-
|
|
2677
|
-
|
|
2678
|
-
|
|
2679
|
-
|
|
2680
|
-
|
|
2681
|
-
|
|
2691
|
+
let reader;
|
|
2692
|
+
const blobs = {
|
|
2693
|
+
mediaBlob: (hash) => (reader ??= this.openReader(sessionID)).mediaBlob(hash)
|
|
2694
|
+
};
|
|
2695
|
+
try {
|
|
2696
|
+
return pending.rows.filter((row) => row.seq > pending.value.replay.floor.after).flatMap((row) => {
|
|
2697
|
+
const messages = this.rendered(structuredClone(row), model, blobs);
|
|
2698
|
+
for (const message of messages)
|
|
2699
|
+
bindNativeRowID(message, row.id, row.seq);
|
|
2700
|
+
return messages;
|
|
2701
|
+
});
|
|
2702
|
+
} finally {
|
|
2703
|
+
reader?.close();
|
|
2704
|
+
}
|
|
2682
2705
|
}
|
|
2683
2706
|
async commitLegacyUpgrade(sessionID, prefixMutationPermitted) {
|
|
2684
2707
|
if (!prefixMutationPermitted)
|
|
@@ -2926,7 +2949,7 @@ ${cached}
|
|
|
2926
2949
|
if (!this.dirty.has(sessionID) && tail?.model === `${model.providerID}/${model.id}` && this.storage.containsRows(sessionID, required.map((row) => row.id))) {
|
|
2927
2950
|
records = this.storage.rows(sessionID, after, through);
|
|
2928
2951
|
} else {
|
|
2929
|
-
records = reader.range(sessionID, after, through).filter(conversational).map((row) => this.record(row, this.rendered(row, model)));
|
|
2952
|
+
records = reader.range(sessionID, after, through).filter(conversational).map((row) => this.record(row, this.rendered(row, model, reader)));
|
|
2930
2953
|
const restored = new Set(records.map((row) => row.id));
|
|
2931
2954
|
if (required.some((row) => !restored.has(row.id)))
|
|
2932
2955
|
return;
|
|
@@ -2943,8 +2966,8 @@ ${cached}
|
|
|
2943
2966
|
const replay = this.options.protocol === 3 ? await this.floorState(args.sessionID, args.reader) : undefined;
|
|
2944
2967
|
return this.replayInput(args, replay);
|
|
2945
2968
|
}
|
|
2946
|
-
rendered(row, model) {
|
|
2947
|
-
return restoreRow(row, model,
|
|
2969
|
+
rendered(row, model, blobs) {
|
|
2970
|
+
return restoreRow(row, model, readerRestoreMedia(blobs));
|
|
2948
2971
|
}
|
|
2949
2972
|
record(row, messages) {
|
|
2950
2973
|
const data = JSON.stringify(encodeNative(messages));
|
|
@@ -3273,7 +3296,7 @@ ${cached}
|
|
|
3273
3296
|
const through = reader.latestSequence(draft.sessionID);
|
|
3274
3297
|
const after = this.dirty.has(draft.sessionID) ? -1 : tail?.sourceSeq ?? through;
|
|
3275
3298
|
const fresh = tail ? reader.range(draft.sessionID, after, through).filter(conversational) : [];
|
|
3276
|
-
const records = fresh.map((row) => this.record(row, this.rendered(row, draft.model)));
|
|
3299
|
+
const records = fresh.map((row) => this.record(row, this.rendered(row, draft.model, reader)));
|
|
3277
3300
|
if (this.dirty.has(draft.sessionID))
|
|
3278
3301
|
this.storage.replaceRows(draft.sessionID, through, records);
|
|
3279
3302
|
await this.storage.saveTail(draft.sessionID, JSON.stringify({
|
|
@@ -3383,9 +3406,9 @@ ${cached}
|
|
|
3383
3406
|
}
|
|
3384
3407
|
const required = metadata.filter((row) => row.seq > after && row.seq <= through);
|
|
3385
3408
|
if (this.dirty.has(sessionID) || !tail || (this.loaded.get(sessionID) ?? -1) < through && !this.storage.admission(sessionID, cut.id) || !this.storage.containsRows(sessionID, required.map((row) => row.id))) {
|
|
3386
|
-
reader ??= this.openReader(sessionID);
|
|
3387
|
-
const fresh =
|
|
3388
|
-
const records = fresh.map((row) => this.record(row, this.rendered(row, resolvedModel)));
|
|
3409
|
+
const source = reader ??= this.openReader(sessionID);
|
|
3410
|
+
const fresh = source.range(sessionID, after, through).filter(conversational);
|
|
3411
|
+
const records = fresh.map((row) => this.record(row, this.rendered(row, resolvedModel, source)));
|
|
3389
3412
|
const restored = new Set(records.map((row) => row.id));
|
|
3390
3413
|
if (required.some((row) => !restored.has(row.id)))
|
|
3391
3414
|
throw new NativeReplayUnavailable("Host restore omitted a required source row");
|
|
@@ -3424,7 +3447,7 @@ ${cached}
|
|
|
3424
3447
|
const retired = instructionRetirement(replay);
|
|
3425
3448
|
const after = replay ? restoreAfter(this.storage.db, reader, sessionID, replay.floor) : -1;
|
|
3426
3449
|
const messages = reader.range(sessionID, after, cut.seq - 1).filter(conversational).filter((row) => !retired(row)).flatMap((row) => {
|
|
3427
|
-
const messages = this.rendered(row, model);
|
|
3450
|
+
const messages = this.rendered(row, model, reader);
|
|
3428
3451
|
for (const message of messages)
|
|
3429
3452
|
bindNativeRowID(message, row.id, row.seq);
|
|
3430
3453
|
return messages;
|
|
@@ -3881,6 +3904,10 @@ var SWEEP_BUDGET_MS = 30000;
|
|
|
3881
3904
|
function recordHiddenChild(db, child) {
|
|
3882
3905
|
db.prepare("INSERT INTO schema_migrations_meta (key, value) VALUES (?, ?)").run(`${PREFIX}${child.id}`, JSON.stringify(child));
|
|
3883
3906
|
}
|
|
3907
|
+
function recordRetiringHiddenChild(db, child) {
|
|
3908
|
+
db.prepare(`INSERT INTO schema_migrations_meta (key, value) VALUES (?, ?)
|
|
3909
|
+
ON CONFLICT(key) DO UPDATE SET value = json_set(value, '$.retiring', json('true'))`).run(`${PREFIX}${child.id}`, JSON.stringify({ ...child, retiring: true }));
|
|
3910
|
+
}
|
|
3884
3911
|
function forgetHiddenChild(db, id) {
|
|
3885
3912
|
db.prepare("DELETE FROM schema_migrations_meta WHERE key = ?").run(`${PREFIX}${id}`);
|
|
3886
3913
|
}
|
|
@@ -3966,6 +3993,7 @@ async function sweepHiddenChildren(db, remove, note, options = {}) {
|
|
|
3966
3993
|
|
|
3967
3994
|
// src/v2/hidden-child-native.ts
|
|
3968
3995
|
var liveChildren = new Set;
|
|
3996
|
+
var loggedMissingHolderAPI = false;
|
|
3969
3997
|
function isLiveHiddenChild(id) {
|
|
3970
3998
|
return liveChildren.has(id);
|
|
3971
3999
|
}
|
|
@@ -3987,6 +4015,20 @@ function isSessionNotFound(error) {
|
|
|
3987
4015
|
function createNativeHiddenChildren(host, removeSession, options) {
|
|
3988
4016
|
const quiet = supportsQuietHiddenChildren(options.hostVersion);
|
|
3989
4017
|
const removing = new Map;
|
|
4018
|
+
const removeBounded = async (id, timeoutMs = options.removalTimeoutMs ?? 5000) => {
|
|
4019
|
+
let timer;
|
|
4020
|
+
try {
|
|
4021
|
+
await Promise.race([
|
|
4022
|
+
removeSession({ sessionID: id }),
|
|
4023
|
+
new Promise((_, reject) => {
|
|
4024
|
+
timer = setTimeout(() => reject(new Error("session.remove timed out")), timeoutMs);
|
|
4025
|
+
})
|
|
4026
|
+
]);
|
|
4027
|
+
} finally {
|
|
4028
|
+
if (timer)
|
|
4029
|
+
clearTimeout(timer);
|
|
4030
|
+
}
|
|
4031
|
+
};
|
|
3990
4032
|
const remove = (child) => {
|
|
3991
4033
|
const inFlight = removing.get(child.id);
|
|
3992
4034
|
if (inFlight)
|
|
@@ -3994,18 +4036,7 @@ function createNativeHiddenChildren(host, removeSession, options) {
|
|
|
3994
4036
|
options.log(`[magic-context] hidden child ${child.id} removing`);
|
|
3995
4037
|
const done = (async () => {
|
|
3996
4038
|
try {
|
|
3997
|
-
|
|
3998
|
-
try {
|
|
3999
|
-
await Promise.race([
|
|
4000
|
-
removeSession({ sessionID: child.id }),
|
|
4001
|
-
new Promise((_, reject) => {
|
|
4002
|
-
timer = setTimeout(() => reject(new Error("session.remove timed out")), options.removalTimeoutMs ?? 5000);
|
|
4003
|
-
})
|
|
4004
|
-
]);
|
|
4005
|
-
} finally {
|
|
4006
|
-
if (timer)
|
|
4007
|
-
clearTimeout(timer);
|
|
4008
|
-
}
|
|
4039
|
+
await removeBounded(child.id);
|
|
4009
4040
|
forgetHiddenChild(options.db, child.id);
|
|
4010
4041
|
options.log(`[magic-context] hidden child ${child.id} removed`);
|
|
4011
4042
|
} catch (error) {
|
|
@@ -4026,18 +4057,53 @@ function createNativeHiddenChildren(host, removeSession, options) {
|
|
|
4026
4057
|
removing.set(child.id, done);
|
|
4027
4058
|
return done;
|
|
4028
4059
|
};
|
|
4029
|
-
const
|
|
4060
|
+
const retireLate = async (id, directory, createdAt, cleanupMs) => {
|
|
4061
|
+
noteTimedOutHiddenChild(id);
|
|
4062
|
+
liveChildren.delete(id);
|
|
4063
|
+
try {
|
|
4064
|
+
recordRetiringHiddenChild(options.db, { id, directory, created_at: createdAt });
|
|
4065
|
+
} catch (error) {
|
|
4066
|
+
const kind = error instanceof Error ? error.constructor.name : typeof error;
|
|
4067
|
+
options.log(`[magic-context] late hidden child ${id} record failed (${kind})`);
|
|
4068
|
+
}
|
|
4069
|
+
try {
|
|
4070
|
+
await removeBounded(id, cleanupMs);
|
|
4071
|
+
} catch (error) {
|
|
4072
|
+
if (!isSessionNotFound(error)) {
|
|
4073
|
+
options.log(`[magic-context] late hidden child ${id} could not be removed`);
|
|
4074
|
+
return;
|
|
4075
|
+
}
|
|
4076
|
+
}
|
|
4077
|
+
try {
|
|
4078
|
+
forgetHiddenChild(options.db, id);
|
|
4079
|
+
} catch {}
|
|
4080
|
+
};
|
|
4081
|
+
const create = async (identity, role, model, budget) => {
|
|
4030
4082
|
const input = childCreateInput(identity, role, model);
|
|
4031
4083
|
const directory = identity.directory;
|
|
4032
|
-
if (quiet) {
|
|
4033
|
-
|
|
4034
|
-
throw new Error("OpenCode 2 background holder API is not wired");
|
|
4035
|
-
const placement = await hiddenRunPlacement(host.createHolder, directory);
|
|
4084
|
+
if (quiet && host.createHolder) {
|
|
4085
|
+
const placement = await hiddenRunPlacement(host.createHolder, directory, budget);
|
|
4036
4086
|
input.id = placement.id;
|
|
4037
4087
|
input.parentID = placement.parentID;
|
|
4038
4088
|
delete input.location;
|
|
4089
|
+
} else if (quiet && !loggedMissingHolderAPI) {
|
|
4090
|
+
loggedMissingHolderAPI = true;
|
|
4091
|
+
options.log("[magic-context] OpenCode 2 background holder API is unavailable; background runs will be unparented");
|
|
4092
|
+
}
|
|
4093
|
+
budget?.setStage("creating the child session");
|
|
4094
|
+
const start = () => host.create(input);
|
|
4095
|
+
const removeLate = ({ id }) => {
|
|
4096
|
+
if (!id || !budget)
|
|
4097
|
+
return;
|
|
4098
|
+
retireLate(id, directory, Date.now(), budget.cleanupMs);
|
|
4099
|
+
};
|
|
4100
|
+
const created = await (budget?.work(start, removeLate) ?? start());
|
|
4101
|
+
try {
|
|
4102
|
+
budget?.check();
|
|
4103
|
+
} catch (error) {
|
|
4104
|
+
removeLate(created);
|
|
4105
|
+
throw error;
|
|
4039
4106
|
}
|
|
4040
|
-
const created = await host.create(input);
|
|
4041
4107
|
if (!created.id)
|
|
4042
4108
|
throw new Error("OpenCode 2 did not return a child session id");
|
|
4043
4109
|
const createdAt = Date.now();
|
|
@@ -4052,20 +4118,12 @@ function createNativeHiddenChildren(host, removeSession, options) {
|
|
|
4052
4118
|
});
|
|
4053
4119
|
} catch (storeError) {
|
|
4054
4120
|
let removed = false;
|
|
4055
|
-
let timer;
|
|
4056
4121
|
try {
|
|
4057
|
-
await
|
|
4058
|
-
removeSession({ sessionID: created.id }),
|
|
4059
|
-
new Promise((_, reject) => {
|
|
4060
|
-
timer = setTimeout(() => reject(new Error("session.remove timed out")), options.removalTimeoutMs ?? 5000);
|
|
4061
|
-
})
|
|
4062
|
-
]);
|
|
4122
|
+
await removeBounded(created.id);
|
|
4063
4123
|
removed = true;
|
|
4064
4124
|
} catch (error) {
|
|
4065
4125
|
removed = isSessionNotFound(error);
|
|
4066
4126
|
} finally {
|
|
4067
|
-
if (timer)
|
|
4068
|
-
clearTimeout(timer);
|
|
4069
4127
|
liveChildren.delete(created.id);
|
|
4070
4128
|
}
|
|
4071
4129
|
options.log(`[magic-context] hidden child ${created.id} record failed; removed=${removed}: ${errorText(storeError)}`);
|
|
@@ -4093,6 +4151,9 @@ function createNativeHiddenChildren(host, removeSession, options) {
|
|
|
4093
4151
|
return {
|
|
4094
4152
|
open: create,
|
|
4095
4153
|
create,
|
|
4154
|
+
retireLate(child, cleanupMs) {
|
|
4155
|
+
retireLate(child.id, child.directory ?? "", child.created_at, cleanupMs);
|
|
4156
|
+
},
|
|
4096
4157
|
retire(child) {
|
|
4097
4158
|
if (kept(child)) {
|
|
4098
4159
|
liveChildren.delete(child.id);
|
|
@@ -4191,17 +4252,83 @@ async function cleanupLegacyHiddenChildren(db, remove, note, options = {}) {
|
|
|
4191
4252
|
|
|
4192
4253
|
// src/v2/hidden-completion.ts
|
|
4193
4254
|
var DEFAULT_DISPOSE_DRAIN_MS = 2000;
|
|
4255
|
+
|
|
4256
|
+
class HiddenWorkTimeout extends Error {
|
|
4257
|
+
constructor(timeoutMs) {
|
|
4258
|
+
super(`prompt timed out after ${timeoutMs}ms`);
|
|
4259
|
+
}
|
|
4260
|
+
}
|
|
4261
|
+
|
|
4262
|
+
class HiddenSetupTimeout extends HiddenCompletionRefusal {
|
|
4263
|
+
constructor(stage) {
|
|
4264
|
+
super("hidden_setup_timeout", `Hidden completion setup timed out while ${stage}`, true);
|
|
4265
|
+
}
|
|
4266
|
+
}
|
|
4267
|
+
|
|
4268
|
+
class HiddenWorkAborted extends Error {
|
|
4269
|
+
constructor() {
|
|
4270
|
+
super("Hidden completion prompt aborted");
|
|
4271
|
+
}
|
|
4272
|
+
}
|
|
4273
|
+
function setupBudget(deadline, timeout, signal) {
|
|
4274
|
+
let stage = "preparing the attempt";
|
|
4275
|
+
let lost;
|
|
4276
|
+
const check = () => {
|
|
4277
|
+
if (lost)
|
|
4278
|
+
throw lost;
|
|
4279
|
+
if (Date.now() >= deadline)
|
|
4280
|
+
throw lost = timeout(stage);
|
|
4281
|
+
if (signal?.aborted)
|
|
4282
|
+
throw lost = new HiddenWorkAborted;
|
|
4283
|
+
};
|
|
4284
|
+
return {
|
|
4285
|
+
check,
|
|
4286
|
+
setStage: (value) => {
|
|
4287
|
+
stage = value;
|
|
4288
|
+
},
|
|
4289
|
+
get stage() {
|
|
4290
|
+
return stage;
|
|
4291
|
+
},
|
|
4292
|
+
cleanupMs: DEFAULT_DISPOSE_DRAIN_MS,
|
|
4293
|
+
async work(start, onLate) {
|
|
4294
|
+
check();
|
|
4295
|
+
let timer;
|
|
4296
|
+
let abort;
|
|
4297
|
+
try {
|
|
4298
|
+
return await Promise.race([
|
|
4299
|
+
start().then((result) => {
|
|
4300
|
+
try {
|
|
4301
|
+
check();
|
|
4302
|
+
} catch (error) {
|
|
4303
|
+
onLate?.(result);
|
|
4304
|
+
throw error;
|
|
4305
|
+
}
|
|
4306
|
+
return result;
|
|
4307
|
+
}),
|
|
4308
|
+
new Promise((_, reject) => {
|
|
4309
|
+
timer = setTimeout(() => reject(lost ??= timeout(stage)), Math.max(0, deadline - Date.now()));
|
|
4310
|
+
abort = () => reject(lost ??= new HiddenWorkAborted);
|
|
4311
|
+
if (signal?.aborted)
|
|
4312
|
+
abort();
|
|
4313
|
+
else
|
|
4314
|
+
signal?.addEventListener("abort", abort, { once: true });
|
|
4315
|
+
})
|
|
4316
|
+
]);
|
|
4317
|
+
} finally {
|
|
4318
|
+
clearTimeout(timer);
|
|
4319
|
+
if (abort)
|
|
4320
|
+
signal?.removeEventListener("abort", abort);
|
|
4321
|
+
}
|
|
4322
|
+
}
|
|
4323
|
+
};
|
|
4324
|
+
}
|
|
4194
4325
|
async function settleWithin(work, ms) {
|
|
4195
4326
|
let timer;
|
|
4196
4327
|
try {
|
|
4197
|
-
await Promise.race([
|
|
4198
|
-
work.then(() =>
|
|
4199
|
-
return;
|
|
4200
|
-
}, () => {
|
|
4201
|
-
return;
|
|
4202
|
-
}),
|
|
4328
|
+
return await Promise.race([
|
|
4329
|
+
work.then(() => true, () => true),
|
|
4203
4330
|
new Promise((resolve) => {
|
|
4204
|
-
timer = setTimeout(resolve, Math.max(0, ms));
|
|
4331
|
+
timer = setTimeout(() => resolve(false), Math.max(0, ms));
|
|
4205
4332
|
})
|
|
4206
4333
|
]);
|
|
4207
4334
|
} finally {
|
|
@@ -4398,8 +4525,9 @@ function isProviderFailure(error) {
|
|
|
4398
4525
|
const type = error.type;
|
|
4399
4526
|
return typeof type === "string" && (type.startsWith("provider.") || type.toLowerCase().includes("provider"));
|
|
4400
4527
|
}
|
|
4401
|
-
async function awaitAssistantRow(openReader, readSessionError, localFailure, childID, afterSeq, deadline, signal) {
|
|
4528
|
+
async function awaitAssistantRow(openReader, readSessionError, localFailure, childID, afterSeq, deadline, signal, checkDeadline) {
|
|
4402
4529
|
for (;; ) {
|
|
4530
|
+
checkDeadline?.();
|
|
4403
4531
|
const refusedBefore = localFailure();
|
|
4404
4532
|
if (refusedBefore)
|
|
4405
4533
|
throw refusedBefore;
|
|
@@ -4455,9 +4583,6 @@ async function awaitAssistantRow(openReader, readSessionError, localFailure, chi
|
|
|
4455
4583
|
return { row: newAssistant };
|
|
4456
4584
|
}
|
|
4457
4585
|
}
|
|
4458
|
-
if (Date.now() >= deadline) {
|
|
4459
|
-
throw new Error("Hidden completion timed out waiting for a persisted assistant row");
|
|
4460
|
-
}
|
|
4461
4586
|
await sleepUntilPoll(signal, deadline);
|
|
4462
4587
|
}
|
|
4463
4588
|
}
|
|
@@ -4522,11 +4647,11 @@ async function createV2HiddenCompletionExecutor(host, options) {
|
|
|
4522
4647
|
};
|
|
4523
4648
|
};
|
|
4524
4649
|
const warnedVariants = new Set;
|
|
4525
|
-
const validateVariant = async (model) => {
|
|
4650
|
+
const validateVariant = async (model, work) => {
|
|
4526
4651
|
if (!model.variant || !options.modelCatalog)
|
|
4527
4652
|
return model;
|
|
4528
4653
|
try {
|
|
4529
|
-
const listed = await options.modelCatalog
|
|
4654
|
+
const listed = await work(options.modelCatalog);
|
|
4530
4655
|
const rows = Array.isArray(listed) ? listed : listed && typeof listed === "object" && Array.isArray(listed.data) ? listed.data : [];
|
|
4531
4656
|
const entry = rows.find((row) => row && typeof row === "object" && row.providerID === model.providerID && row.id === model.modelID);
|
|
4532
4657
|
if (!entry)
|
|
@@ -4539,18 +4664,21 @@ async function createV2HiddenCompletionExecutor(host, options) {
|
|
|
4539
4664
|
note(`[magic-context] ${recordHiddenVariantWarning(model.providerID, model.modelID, model.variant)}`);
|
|
4540
4665
|
}
|
|
4541
4666
|
return { providerID: model.providerID, modelID: model.modelID };
|
|
4542
|
-
} catch {
|
|
4667
|
+
} catch (error) {
|
|
4668
|
+
if (error instanceof HiddenSetupTimeout || error instanceof HiddenWorkAborted)
|
|
4669
|
+
throw error;
|
|
4543
4670
|
return model;
|
|
4544
4671
|
}
|
|
4545
4672
|
};
|
|
4546
|
-
const resolveHead = async (identity) => {
|
|
4673
|
+
const resolveHead = async (identity, work) => {
|
|
4547
4674
|
const configured = configuredHead(identity);
|
|
4548
4675
|
if (configured)
|
|
4549
|
-
return validateVariant(configured);
|
|
4550
|
-
|
|
4676
|
+
return validateVariant(configured, work);
|
|
4677
|
+
const parentSessionId = identity.parentSessionId;
|
|
4678
|
+
if (!parentSessionId) {
|
|
4551
4679
|
throw new HiddenCompletionRefusal("hidden_model_unsupported", "Hidden completion requires a configured model or an existing parent session model", true);
|
|
4552
4680
|
}
|
|
4553
|
-
const parent = await host.get({ sessionID:
|
|
4681
|
+
const parent = await work(() => host.get({ sessionID: parentSessionId }));
|
|
4554
4682
|
if (!parent.model) {
|
|
4555
4683
|
throw new HiddenCompletionRefusal("hidden_model_unsupported", "Hidden completion could not resolve the parent session model", true);
|
|
4556
4684
|
}
|
|
@@ -4560,17 +4688,18 @@ async function createV2HiddenCompletionExecutor(host, options) {
|
|
|
4560
4688
|
...parent.model.variant ? { variant: parent.model.variant } : {}
|
|
4561
4689
|
};
|
|
4562
4690
|
};
|
|
4563
|
-
const switchChildModel = async (run, requested) => {
|
|
4691
|
+
const switchChildModel = async (run, requested, setup) => {
|
|
4564
4692
|
if (sameModel(run.child.model, requested))
|
|
4565
4693
|
return;
|
|
4566
|
-
await host.switchModel({
|
|
4694
|
+
await setup.work(() => host.switchModel({
|
|
4567
4695
|
sessionID: run.child.id,
|
|
4568
4696
|
model: {
|
|
4569
4697
|
providerID: requested.providerID,
|
|
4570
4698
|
id: requested.modelID,
|
|
4571
4699
|
...requested.variant ? { variant: requested.variant } : {}
|
|
4572
4700
|
}
|
|
4573
|
-
});
|
|
4701
|
+
}));
|
|
4702
|
+
setup.check();
|
|
4574
4703
|
run.child = lifecycle.updateModel(run.child, requested);
|
|
4575
4704
|
};
|
|
4576
4705
|
const partialCompletion = (run) => {
|
|
@@ -4602,30 +4731,63 @@ async function createV2HiddenCompletionExecutor(host, options) {
|
|
|
4602
4731
|
lifecycle.retire(run.child, reason);
|
|
4603
4732
|
run.retired = true;
|
|
4604
4733
|
};
|
|
4605
|
-
const interruptAndRetire =
|
|
4606
|
-
|
|
4607
|
-
|
|
4608
|
-
|
|
4609
|
-
|
|
4610
|
-
|
|
4734
|
+
const interruptAndRetire = (run, reason) => {
|
|
4735
|
+
if (run.retired)
|
|
4736
|
+
return run.retirement ?? Promise.resolve();
|
|
4737
|
+
return run.retirement ??= (async () => {
|
|
4738
|
+
const id = run.child.id;
|
|
4739
|
+
const warn = (error) => {
|
|
4740
|
+
const kind = error instanceof Error ? error.constructor.name : typeof error;
|
|
4741
|
+
const message = `[magic-context] hidden child ${id} could not be interrupted (${kind})`;
|
|
4742
|
+
if (options.log)
|
|
4743
|
+
options.log(message);
|
|
4744
|
+
else
|
|
4745
|
+
log2(message);
|
|
4746
|
+
};
|
|
4747
|
+
try {
|
|
4748
|
+
await settleWithin(host.interrupt({ sessionID: id }).catch(warn), DEFAULT_DISPOSE_DRAIN_MS);
|
|
4749
|
+
} catch (error) {
|
|
4750
|
+
warn(error);
|
|
4751
|
+
} finally {
|
|
4752
|
+
retire(run, reason);
|
|
4753
|
+
}
|
|
4754
|
+
})();
|
|
4611
4755
|
};
|
|
4612
4756
|
return {
|
|
4613
4757
|
capabilities: V2_HIDDEN_EXECUTOR_CAPABILITIES,
|
|
4614
4758
|
async open(identity) {
|
|
4615
4759
|
if (disposed)
|
|
4616
4760
|
throw disposed;
|
|
4761
|
+
const roleWait = setupBudget(Date.now() + identity.timeoutMs, (stage) => new HiddenSetupTimeout(stage));
|
|
4762
|
+
roleWait.setStage("waiting for its role");
|
|
4617
4763
|
const role = roleFor(identity);
|
|
4618
4764
|
const releaseStore = options.holdStore?.() ?? (() => {});
|
|
4619
4765
|
let releaseRole;
|
|
4620
4766
|
let openedChild;
|
|
4621
4767
|
let opened;
|
|
4622
4768
|
try {
|
|
4623
|
-
releaseRole = await acquireRole(role);
|
|
4769
|
+
releaseRole = await roleWait.work(() => acquireRole(role), (release) => release());
|
|
4624
4770
|
if (disposed)
|
|
4625
4771
|
throw disposed;
|
|
4626
|
-
|
|
4627
|
-
const
|
|
4628
|
-
const
|
|
4772
|
+
const deadline = Date.now() + identity.timeoutMs;
|
|
4773
|
+
const setup = setupBudget(deadline, (stage) => new HiddenSetupTimeout(stage));
|
|
4774
|
+
const work = setup.work;
|
|
4775
|
+
const ensureAgent = options.ensureAgent;
|
|
4776
|
+
if (ensureAgent) {
|
|
4777
|
+
setup.setStage("reloading the hidden agent");
|
|
4778
|
+
let pending;
|
|
4779
|
+
try {
|
|
4780
|
+
await work(() => pending = ensureAgent.call(options));
|
|
4781
|
+
} catch (error) {
|
|
4782
|
+
if (pending)
|
|
4783
|
+
options.forgetAgent?.(pending);
|
|
4784
|
+
throw error;
|
|
4785
|
+
}
|
|
4786
|
+
}
|
|
4787
|
+
setup.setStage("resolving the hidden model");
|
|
4788
|
+
const head = await resolveHead(identity, work);
|
|
4789
|
+
setup.setStage("creating the child session");
|
|
4790
|
+
const active = await work(() => lifecycle.open(identity, role, head, setup), (child) => lifecycle.retireLate(child, setup.cleanupMs));
|
|
4629
4791
|
openedChild = active;
|
|
4630
4792
|
const configuredModel = toModelEntry(identity.model);
|
|
4631
4793
|
const handle = {
|
|
@@ -4642,6 +4804,7 @@ async function createV2HiddenCompletionExecutor(host, options) {
|
|
|
4642
4804
|
child: active,
|
|
4643
4805
|
releaseRole,
|
|
4644
4806
|
releaseStore,
|
|
4807
|
+
firstDeadline: deadline,
|
|
4645
4808
|
failed: false,
|
|
4646
4809
|
unsettledFailure: false,
|
|
4647
4810
|
retired: false
|
|
@@ -4651,15 +4814,23 @@ async function createV2HiddenCompletionExecutor(host, options) {
|
|
|
4651
4814
|
openRuns.add(run);
|
|
4652
4815
|
if (disposed)
|
|
4653
4816
|
noteChildOfDisposedInstance(active.id);
|
|
4654
|
-
|
|
4817
|
+
setup.setStage("switching the child model");
|
|
4818
|
+
await switchChildModel(run, head, setup);
|
|
4819
|
+
setup.check();
|
|
4655
4820
|
return handle;
|
|
4656
4821
|
} catch (error) {
|
|
4657
|
-
|
|
4658
|
-
|
|
4659
|
-
|
|
4660
|
-
|
|
4661
|
-
|
|
4662
|
-
|
|
4822
|
+
try {
|
|
4823
|
+
if (openedChild) {
|
|
4824
|
+
if (error instanceof HiddenSetupTimeout)
|
|
4825
|
+
noteTimedOutHiddenChild(openedChild.id);
|
|
4826
|
+
lifecycle.retire(openedChild, "hidden-run-open-failed");
|
|
4827
|
+
}
|
|
4828
|
+
} finally {
|
|
4829
|
+
if (opened)
|
|
4830
|
+
openRuns.delete(opened);
|
|
4831
|
+
releaseRole?.();
|
|
4832
|
+
releaseStore();
|
|
4833
|
+
}
|
|
4663
4834
|
throw error;
|
|
4664
4835
|
}
|
|
4665
4836
|
},
|
|
@@ -4668,6 +4839,35 @@ async function createV2HiddenCompletionExecutor(host, options) {
|
|
|
4668
4839
|
const run = runs.get(handle);
|
|
4669
4840
|
if (!run)
|
|
4670
4841
|
throw new Error("Unknown hidden completion run");
|
|
4842
|
+
const timeoutMs = run.identity.timeoutMs;
|
|
4843
|
+
const deadline = run.firstDeadline ?? startedAt + timeoutMs;
|
|
4844
|
+
run.firstDeadline = undefined;
|
|
4845
|
+
let dispatched = false;
|
|
4846
|
+
const setup = setupBudget(deadline, (stage) => dispatched ? new HiddenWorkTimeout(timeoutMs) : new HiddenSetupTimeout(stage), request.signal);
|
|
4847
|
+
const work = setup.work;
|
|
4848
|
+
const sharedBudget = promptTransportBudget(request.signal);
|
|
4849
|
+
const refuseSliver = () => {
|
|
4850
|
+
const now = Date.now();
|
|
4851
|
+
if (deadline - now < timeoutMs * 0.05 || sharedBudget && sharedBudget.deadline - now < sharedBudget.timeoutMs * 0.05)
|
|
4852
|
+
throw new HiddenSetupTimeout("preparing to send the prompt");
|
|
4853
|
+
};
|
|
4854
|
+
const retireFailedSetup = (error) => {
|
|
4855
|
+
if (error instanceof HiddenSetupTimeout) {
|
|
4856
|
+
run.deadlineExpired = true;
|
|
4857
|
+
noteTimedOutHiddenChild(run.child.id);
|
|
4858
|
+
}
|
|
4859
|
+
run.failed = true;
|
|
4860
|
+
run.unsettledFailure = true;
|
|
4861
|
+
if (!run.retirement)
|
|
4862
|
+
retire(run, "hidden-attempt-setup-cancelled");
|
|
4863
|
+
};
|
|
4864
|
+
const stopWithinWork = async (reason) => {
|
|
4865
|
+
const retirement = interruptAndRetire(run, reason);
|
|
4866
|
+
if (Date.now() < deadline)
|
|
4867
|
+
await settleWithin(retirement, deadline - Date.now());
|
|
4868
|
+
if (Date.now() >= deadline)
|
|
4869
|
+
run.deadlineExpired = true;
|
|
4870
|
+
};
|
|
4671
4871
|
const refuseDisposed = () => {
|
|
4672
4872
|
if (!disposed)
|
|
4673
4873
|
return;
|
|
@@ -4678,46 +4878,78 @@ async function createV2HiddenCompletionExecutor(host, options) {
|
|
|
4678
4878
|
};
|
|
4679
4879
|
refuseDisposed();
|
|
4680
4880
|
if (request.signal?.aborted) {
|
|
4681
|
-
await
|
|
4881
|
+
await stopWithinWork("aborted-before-prompt");
|
|
4682
4882
|
throw new Error("Hidden completion prompt aborted");
|
|
4683
4883
|
}
|
|
4684
|
-
|
|
4685
|
-
|
|
4686
|
-
|
|
4687
|
-
|
|
4688
|
-
|
|
4689
|
-
|
|
4690
|
-
|
|
4691
|
-
|
|
4692
|
-
|
|
4693
|
-
|
|
4694
|
-
|
|
4695
|
-
|
|
4696
|
-
|
|
4697
|
-
|
|
4698
|
-
|
|
4699
|
-
|
|
4700
|
-
|
|
4701
|
-
|
|
4702
|
-
|
|
4703
|
-
|
|
4704
|
-
|
|
4705
|
-
|
|
4706
|
-
|
|
4707
|
-
|
|
4708
|
-
|
|
4709
|
-
|
|
4710
|
-
|
|
4711
|
-
|
|
4712
|
-
|
|
4713
|
-
|
|
4714
|
-
|
|
4715
|
-
|
|
4716
|
-
|
|
4717
|
-
|
|
4718
|
-
|
|
4884
|
+
let requested;
|
|
4885
|
+
let requestedRef;
|
|
4886
|
+
notePromptSetupTimeout(request.signal, () => new HiddenSetupTimeout(setup.stage));
|
|
4887
|
+
try {
|
|
4888
|
+
const previousRetirement = run.retirement;
|
|
4889
|
+
setup.setStage("waiting for the previous child to retire");
|
|
4890
|
+
if (previousRetirement)
|
|
4891
|
+
await work(() => previousRetirement);
|
|
4892
|
+
setup.setStage("resolving the hidden model");
|
|
4893
|
+
requested = await validateVariant(requestModel(request, run.child.model), work);
|
|
4894
|
+
requestedRef = modelKey(requested);
|
|
4895
|
+
const configuredModel = [
|
|
4896
|
+
run.identity.model,
|
|
4897
|
+
...run.identity.configuredModels ?? []
|
|
4898
|
+
].map(toModelEntry).find((entry) => entry?.model === requestedRef);
|
|
4899
|
+
handle.attemptedModel = requestedRef;
|
|
4900
|
+
handle.modelConfigKey = configuredModel?.sourceConfigKey ?? handle.modelConfigKey;
|
|
4901
|
+
if (run.identity.kind !== "dreamer-task" && request.body.temperature === undefined) {
|
|
4902
|
+
const configured = options.historianTemperature?.();
|
|
4903
|
+
if (typeof configured === "number" && Number.isFinite(configured))
|
|
4904
|
+
request = {
|
|
4905
|
+
...request,
|
|
4906
|
+
body: { ...request.body, temperature: configured }
|
|
4907
|
+
};
|
|
4908
|
+
}
|
|
4909
|
+
if (typeof request.body.temperature === "number") {
|
|
4910
|
+
let metadata;
|
|
4911
|
+
try {
|
|
4912
|
+
const listed = options.modelCatalog ? await work(options.modelCatalog) : undefined;
|
|
4913
|
+
const rows = Array.isArray(listed) ? listed : listed?.data;
|
|
4914
|
+
metadata = rows?.find((row) => row?.providerID === requested.providerID && (row?.id === requested.modelID || row?.modelID === requested.modelID));
|
|
4915
|
+
} catch (error) {
|
|
4916
|
+
if (error instanceof HiddenSetupTimeout || error instanceof HiddenWorkAborted)
|
|
4917
|
+
throw error;
|
|
4918
|
+
}
|
|
4919
|
+
const temperature = subagentTemperature(modelKey(requested), metadata, request.body.temperature, (message) => note(message));
|
|
4920
|
+
const body = { ...request.body };
|
|
4921
|
+
if (temperature === undefined)
|
|
4922
|
+
delete body.temperature;
|
|
4923
|
+
else
|
|
4924
|
+
body.temperature = temperature;
|
|
4925
|
+
request = { ...request, body };
|
|
4926
|
+
}
|
|
4927
|
+
if (needsBlockedRead(run.identity.agent, run.child.model.providerID) !== needsBlockedRead(run.identity.agent, requested.providerID)) {
|
|
4928
|
+
retire(run, "hidden-run-tool-surface-changed");
|
|
4929
|
+
}
|
|
4930
|
+
if (run.retired) {
|
|
4931
|
+
setup.setStage("creating the replacement child session");
|
|
4932
|
+
run.child = await work(() => lifecycle.create(run.identity, run.role, requested, setup), (child) => lifecycle.retireLate(child, setup.cleanupMs));
|
|
4933
|
+
run.retirement = undefined;
|
|
4934
|
+
run.deadlineExpired = false;
|
|
4935
|
+
run.failed = false;
|
|
4936
|
+
run.unsettledFailure = false;
|
|
4937
|
+
run.retired = false;
|
|
4938
|
+
handle.id = run.child.id;
|
|
4939
|
+
handle.childSessionId = run.child.id;
|
|
4940
|
+
}
|
|
4941
|
+
setup.setStage("switching the child model");
|
|
4942
|
+
await switchChildModel(run, requested, setup);
|
|
4943
|
+
setup.check();
|
|
4944
|
+
setup.setStage("preparing to send the prompt");
|
|
4945
|
+
refuseSliver();
|
|
4946
|
+
} catch (error) {
|
|
4947
|
+
if (error instanceof HiddenSetupTimeout || error instanceof HiddenWorkAborted)
|
|
4948
|
+
retireFailedSetup(error);
|
|
4949
|
+
throw error;
|
|
4950
|
+
} finally {
|
|
4951
|
+
notePromptSetupTimeout(request.signal);
|
|
4719
4952
|
}
|
|
4720
|
-
await switchChildModel(run, requested);
|
|
4721
4953
|
refuseDisposed();
|
|
4722
4954
|
const baseline = withReader(options.openReader, (reader) => reader.latestSequence(run.child.id));
|
|
4723
4955
|
const marker = `mc:hidden:${crypto.randomUUID()}:${crypto.randomUUID()}`;
|
|
@@ -4732,7 +4964,6 @@ async function createV2HiddenCompletionExecutor(host, options) {
|
|
|
4732
4964
|
run.partialCompletion = undefined;
|
|
4733
4965
|
run.attempt = { child: attempt, baseline };
|
|
4734
4966
|
options.hook.registerAttempt(marker, attempt);
|
|
4735
|
-
const deadline = Date.now() + run.identity.timeoutMs;
|
|
4736
4967
|
lifecycle.extendDeadline(run.child, deadline);
|
|
4737
4968
|
const budget = run.budget;
|
|
4738
4969
|
if (budget?.snapshot().finalizeFired) {
|
|
@@ -4791,6 +5022,8 @@ async function createV2HiddenCompletionExecutor(host, options) {
|
|
|
4791
5022
|
});
|
|
4792
5023
|
const onAbort = () => {
|
|
4793
5024
|
const reason = request.signal?.reason;
|
|
5025
|
+
if (dispatched)
|
|
5026
|
+
noteTimedOutHiddenChild(run.child.id);
|
|
4794
5027
|
if (reason instanceof ModelProducedNoOutputError && run.identity.kind === "dreamer-task") {
|
|
4795
5028
|
recordChildInvocation({
|
|
4796
5029
|
db: options.db,
|
|
@@ -4808,9 +5041,6 @@ async function createV2HiddenCompletionExecutor(host, options) {
|
|
|
4808
5041
|
}
|
|
4809
5042
|
interruptAndRetire(run, "prompt-aborted").finally(() => abortReject(new Error("Hidden completion prompt aborted")));
|
|
4810
5043
|
};
|
|
4811
|
-
const deadlineTimer = setTimeout(() => {
|
|
4812
|
-
interruptAndRetire(run, "prompt-timeout").finally(() => abortReject(new Error("Hidden completion prompt timed out")));
|
|
4813
|
-
}, Math.max(0, deadline - Date.now()));
|
|
4814
5044
|
request.signal?.addEventListener("abort", onAbort, { once: true });
|
|
4815
5045
|
let settle;
|
|
4816
5046
|
const entry = {
|
|
@@ -4819,8 +5049,6 @@ async function createV2HiddenCompletionExecutor(host, options) {
|
|
|
4819
5049
|
noteChildOfDisposedInstance(run.child.id);
|
|
4820
5050
|
try {
|
|
4821
5051
|
await interruptAndRetire(run, "plugin-instance-disposed");
|
|
4822
|
-
} catch (error) {
|
|
4823
|
-
note(`[magic-context] hidden child ${run.child.id} could not be interrupted on dispose: ${errorText(error)}`);
|
|
4824
5052
|
} finally {
|
|
4825
5053
|
abortReject(refusal);
|
|
4826
5054
|
}
|
|
@@ -4839,28 +5067,32 @@ async function createV2HiddenCompletionExecutor(host, options) {
|
|
|
4839
5067
|
noteModelActivityMonitored(request.signal);
|
|
4840
5068
|
try {
|
|
4841
5069
|
await Promise.race([
|
|
4842
|
-
|
|
5070
|
+
work(() => {
|
|
5071
|
+
refuseSliver();
|
|
5072
|
+
dispatched = true;
|
|
5073
|
+
return host.prompt({ sessionID: run.child.id, text: marker });
|
|
5074
|
+
}),
|
|
4843
5075
|
aborted,
|
|
4844
5076
|
...budget ? [budgetStopped] : []
|
|
4845
5077
|
]);
|
|
4846
5078
|
await Promise.race([
|
|
4847
|
-
host.wait({ sessionID: run.child.id }),
|
|
5079
|
+
work(() => host.wait({ sessionID: run.child.id })),
|
|
4848
5080
|
aborted,
|
|
4849
5081
|
...budget ? [budgetStopped] : []
|
|
4850
5082
|
]);
|
|
4851
5083
|
const { row, outputLimit } = await Promise.race([
|
|
4852
|
-
awaitAssistantRow(options.openReader, async () => {
|
|
5084
|
+
work(() => awaitAssistantRow(options.openReader, async () => {
|
|
4853
5085
|
try {
|
|
4854
|
-
const
|
|
4855
|
-
|
|
4856
|
-
});
|
|
5086
|
+
const id = run.child.id;
|
|
5087
|
+
const terminalError = host.terminalError;
|
|
5088
|
+
const eventError = terminalError ? await work(() => terminalError.call(host, { sessionID: id })) : undefined;
|
|
4857
5089
|
if (eventError !== undefined)
|
|
4858
5090
|
return eventError;
|
|
4859
|
-
return (await host.get({ sessionID:
|
|
5091
|
+
return (await work(() => host.get({ sessionID: id }))).error;
|
|
4860
5092
|
} catch {
|
|
4861
5093
|
return;
|
|
4862
5094
|
}
|
|
4863
|
-
}, () => attempt.refusal ?? attempt.stepLimit, run.child.id, baseline, deadline, request.signal),
|
|
5095
|
+
}, () => attempt.refusal ?? attempt.stepLimit, run.child.id, baseline, deadline, request.signal, setup.check)),
|
|
4864
5096
|
aborted,
|
|
4865
5097
|
...budget ? [budgetStopped] : []
|
|
4866
5098
|
]);
|
|
@@ -4876,15 +5108,17 @@ async function createV2HiddenCompletionExecutor(host, options) {
|
|
|
4876
5108
|
const steps = attemptRows.filter((step) => step.type === "assistant" && step.seq > baseline && step.seq <= row.seq);
|
|
4877
5109
|
const exceeded = chargeBudgetRows(steps);
|
|
4878
5110
|
if (exceeded) {
|
|
4879
|
-
await
|
|
5111
|
+
await stopWithinWork("token-budget");
|
|
4880
5112
|
throw exceeded;
|
|
4881
5113
|
}
|
|
4882
5114
|
const cappedChainStart = outputLimit ? outputLimitChainStart(attemptRows, row.seq) : row.seq;
|
|
4883
5115
|
const usageRows = cappedChainStart < row.seq ? steps.filter((step) => step.seq < cappedChainStart || step.seq === row.seq) : steps;
|
|
4884
5116
|
const reportedUsage = usageRows.some((step) => tokenNumber(step.data.tokens?.input) !== undefined || tokenNumber(step.data.tokens?.output) !== undefined);
|
|
4885
5117
|
const usage = sumRowUsage(usageRows);
|
|
4886
|
-
if (
|
|
4887
|
-
|
|
5118
|
+
if (Date.now() >= deadline)
|
|
5119
|
+
throw new HiddenWorkTimeout(timeoutMs);
|
|
5120
|
+
if (request.signal?.aborted || run.retired) {
|
|
5121
|
+
await stopWithinWork("prompt-aborted-or-timeout");
|
|
4888
5122
|
throw new Error(request.signal?.aborted ? "Hidden completion prompt aborted" : "Hidden completion prompt timed out");
|
|
4889
5123
|
}
|
|
4890
5124
|
run.completion = {
|
|
@@ -4913,17 +5147,25 @@ async function createV2HiddenCompletionExecutor(host, options) {
|
|
|
4913
5147
|
if (!(error instanceof HiddenProviderError)) {
|
|
4914
5148
|
run.unsettledFailure = true;
|
|
4915
5149
|
}
|
|
4916
|
-
|
|
4917
|
-
|
|
4918
|
-
|
|
4919
|
-
|
|
5150
|
+
const dispatchedTimeout = dispatched && isPromptTimeoutError(error);
|
|
5151
|
+
if (error instanceof HiddenSetupTimeout) {
|
|
5152
|
+
retireFailedSetup(error);
|
|
5153
|
+
} else if (dispatched && (caught instanceof HiddenWorkTimeout || Date.now() >= deadline)) {
|
|
5154
|
+
run.deadlineExpired = true;
|
|
5155
|
+
noteTimedOutHiddenChild(run.child.id);
|
|
5156
|
+
interruptAndRetire(run, "prompt-timeout");
|
|
5157
|
+
} else if (request.signal?.aborted && !run.retired) {
|
|
5158
|
+
await stopWithinWork("prompt-aborted");
|
|
5159
|
+
} else if (!run.retired && (dispatchedTimeout || error instanceof Error && error.message.includes("timed out"))) {
|
|
5160
|
+
if (dispatchedTimeout)
|
|
5161
|
+
noteTimedOutHiddenChild(run.child.id);
|
|
5162
|
+
await stopWithinWork("prompt-timeout");
|
|
4920
5163
|
} else if ((error instanceof HiddenAgentStepLimit || error instanceof HiddenProviderError && error.settled) && !run.retired) {
|
|
4921
|
-
await
|
|
5164
|
+
await stopWithinWork(error instanceof HiddenAgentStepLimit ? "hidden-run-step-limit" : "hidden-run-provider-error");
|
|
4922
5165
|
}
|
|
4923
5166
|
throw error;
|
|
4924
5167
|
} finally {
|
|
4925
5168
|
stopWatching?.();
|
|
4926
|
-
clearTimeout(deadlineTimer);
|
|
4927
5169
|
if (budgetPoll)
|
|
4928
5170
|
clearInterval(budgetPoll);
|
|
4929
5171
|
request.signal?.removeEventListener("abort", onAbort);
|
|
@@ -4950,7 +5192,18 @@ async function createV2HiddenCompletionExecutor(host, options) {
|
|
|
4950
5192
|
const run = runs.get(handle);
|
|
4951
5193
|
if (!run)
|
|
4952
5194
|
return;
|
|
5195
|
+
if (run.retirement && (!run.retired || run.deadlineExpired)) {
|
|
5196
|
+
runs.delete(handle);
|
|
5197
|
+
run.retirement.finally(() => {
|
|
5198
|
+
openRuns.delete(run);
|
|
5199
|
+
run.releaseRole();
|
|
5200
|
+
run.releaseStore();
|
|
5201
|
+
});
|
|
5202
|
+
return;
|
|
5203
|
+
}
|
|
4953
5204
|
try {
|
|
5205
|
+
if (run.retirement)
|
|
5206
|
+
await run.retirement;
|
|
4954
5207
|
const reusable = !run.retired && run.failed && !run.unsettledFailure;
|
|
4955
5208
|
if (hiddenToolLoop(run.identity)) {
|
|
4956
5209
|
retire(run, settlement.promptSettled ? "tool-loop-settled" : "tool-loop-failed");
|
|
@@ -4963,7 +5216,9 @@ async function createV2HiddenCompletionExecutor(host, options) {
|
|
|
4963
5216
|
run.releaseRole();
|
|
4964
5217
|
run.releaseStore();
|
|
4965
5218
|
}
|
|
4966
|
-
|
|
5219
|
+
const finished = lifecycle.finish(run.child, run.retired);
|
|
5220
|
+
if (!run.deadlineExpired)
|
|
5221
|
+
await finished;
|
|
4967
5222
|
},
|
|
4968
5223
|
async dispose() {
|
|
4969
5224
|
disposed ??= new HiddenCompletionRefusal("hidden_instance_disposed", HIDDEN_RUN_DISPOSED_REASON, true);
|
|
@@ -6065,26 +6320,21 @@ async function warmModelLimitCacheFromCatalog(context, options = {}) {
|
|
|
6065
6320
|
}
|
|
6066
6321
|
|
|
6067
6322
|
// src/v2/hooks/overflow-recovery.ts
|
|
6068
|
-
function
|
|
6069
|
-
|
|
6070
|
-
|
|
6071
|
-
|
|
6072
|
-
|
|
6073
|
-
|
|
6074
|
-
|
|
6075
|
-
|
|
6076
|
-
if (typeof value === "string") {
|
|
6077
|
-
try {
|
|
6078
|
-
pending.push(JSON.parse(value));
|
|
6079
|
-
} catch {}
|
|
6080
|
-
} else if (value && typeof value === "object") {
|
|
6081
|
-
const p = value;
|
|
6082
|
-
if (p.status === 429 || p.statusCode === 429 || [p.type, p.name, p.code, p._tag].some((tag) => typeof tag === "string" && /rate[_ .-]?limit|throttl/i.test(tag)))
|
|
6083
|
-
return true;
|
|
6084
|
-
pending.push(p.data, p.error, p.cause);
|
|
6323
|
+
function notifyV2ProviderOverflow(sessionID, openReader) {
|
|
6324
|
+
try {
|
|
6325
|
+
const reader = openReader();
|
|
6326
|
+
try {
|
|
6327
|
+
if (reader.isSubagent(sessionID) !== false)
|
|
6328
|
+
return;
|
|
6329
|
+
} finally {
|
|
6330
|
+
reader.close();
|
|
6085
6331
|
}
|
|
6332
|
+
} catch {
|
|
6333
|
+
return;
|
|
6086
6334
|
}
|
|
6087
|
-
|
|
6335
|
+
if (holdOverflowResendHint(sessionID))
|
|
6336
|
+
return;
|
|
6337
|
+
pushLiveNotification2("toast", { message: PROVIDER_OVERFLOW_NOTICE, variant: "error" }, sessionID);
|
|
6088
6338
|
}
|
|
6089
6339
|
|
|
6090
6340
|
class V2OverflowRecovery {
|
|
@@ -6107,6 +6357,7 @@ class V2OverflowRecovery {
|
|
|
6107
6357
|
}
|
|
6108
6358
|
forget(sessionID) {
|
|
6109
6359
|
this.requests.delete(sessionID);
|
|
6360
|
+
noteServedRecoveryForOverflowHint(sessionID);
|
|
6110
6361
|
}
|
|
6111
6362
|
observeTerminal(event, readStep) {
|
|
6112
6363
|
if (!["session.step.failed", "session.execution.failed", "session.error"].includes(event.type ?? ""))
|
|
@@ -6118,7 +6369,7 @@ class V2OverflowRecovery {
|
|
|
6118
6369
|
if (error === undefined)
|
|
6119
6370
|
return;
|
|
6120
6371
|
const prior = this.requests.get(sessionID);
|
|
6121
|
-
if (prior?.observed ||
|
|
6372
|
+
if (prior?.observed || isProviderRateLimit(error) || !detectOverflow(error).isOverflow)
|
|
6122
6373
|
return;
|
|
6123
6374
|
const messageID = event.data?.assistantMessageID;
|
|
6124
6375
|
const step = readStep(sessionID, messageID);
|
|
@@ -6149,7 +6400,7 @@ class V2OverflowRecovery {
|
|
|
6149
6400
|
const request = this.requests.get(input.sessionID);
|
|
6150
6401
|
if (!request || request.observed || this.deps.isHidden(input.sessionID) || request.model.providerID !== input.model.providerID || request.model.id !== input.model.id || input.assistantMessageID && request.assistantMessageID && input.assistantMessageID !== request.assistantMessageID)
|
|
6151
6402
|
return;
|
|
6152
|
-
if (input.status === 429 ||
|
|
6403
|
+
if (input.status === 429 || isProviderRateLimit(input.error))
|
|
6153
6404
|
return;
|
|
6154
6405
|
const detection = detectOverflow(input.error);
|
|
6155
6406
|
if (!detection.isOverflow)
|
|
@@ -6158,13 +6409,16 @@ class V2OverflowRecovery {
|
|
|
6158
6409
|
if (!db)
|
|
6159
6410
|
return;
|
|
6160
6411
|
const modelKey = `${input.model.providerID}/${input.model.id}`;
|
|
6412
|
+
const reportedLimit = resolveOpenCodeOverflowLimit(detection, input.model.providerID, input.model.id, { db, sessionID: input.sessionID });
|
|
6161
6413
|
if (this.deps.compactionOff) {
|
|
6162
|
-
if (
|
|
6163
|
-
recordDetectedContextLimit(db, input.sessionID,
|
|
6414
|
+
if (reportedLimit)
|
|
6415
|
+
recordDetectedContextLimit(db, input.sessionID, reportedLimit, modelKey, detection.reportedLimitProvenance);
|
|
6164
6416
|
} else {
|
|
6165
|
-
recordOverflowDetected(db, input.sessionID,
|
|
6417
|
+
recordOverflowDetected(db, input.sessionID, reportedLimit, modelKey, "provider_overflow", detection.reportedLimitProvenance, detection.reportedInputTokens);
|
|
6166
6418
|
}
|
|
6167
6419
|
request.observed = true;
|
|
6420
|
+
if (!this.deps.compactionOff)
|
|
6421
|
+
this.deps.onOverflow?.(input.sessionID);
|
|
6168
6422
|
if (!this.deps.compactionOff && detection.reportedInputTokens)
|
|
6169
6423
|
this.deps.onInputTokens?.(input.sessionID, detection.reportedInputTokens, getOverflowState(db, input.sessionID, modelKey).detectedContextLimit);
|
|
6170
6424
|
}
|
|
@@ -6893,9 +7147,23 @@ function servableCarrier(stored, head) {
|
|
|
6893
7147
|
}
|
|
6894
7148
|
function bindKeptInstructionCoordinates(messages, incoming, reader, sessionID) {
|
|
6895
7149
|
const rows = reader.instructionRowsThrough(sessionID, reader.latestSequence(sessionID));
|
|
7150
|
+
const visible = (message) => message !== incoming && !effortPart(message);
|
|
7151
|
+
const ids = new Set;
|
|
7152
|
+
for (const message of messages) {
|
|
7153
|
+
if (!visible(message))
|
|
7154
|
+
continue;
|
|
7155
|
+
const id = nativeRowID(message);
|
|
7156
|
+
if (id)
|
|
7157
|
+
ids.add(id);
|
|
7158
|
+
}
|
|
7159
|
+
const sequences = reader.sequencesForIds(sessionID, [...ids]);
|
|
6896
7160
|
let previous;
|
|
6897
7161
|
let pending = [];
|
|
6898
7162
|
const matches = (message, row) => message?.role === "system" && message.content.length === 1 && message.content[0]?.type === "text" && message.content[0].text === row?.data.text;
|
|
7163
|
+
const bindRow = (message, row) => {
|
|
7164
|
+
bindNativeRowID(message, row.id, row.seq);
|
|
7165
|
+
sequences.set(row.id, row.seq);
|
|
7166
|
+
};
|
|
6899
7167
|
const bind = (next) => {
|
|
6900
7168
|
if (!pending.length)
|
|
6901
7169
|
return;
|
|
@@ -6905,7 +7173,7 @@ function bindKeptInstructionCoordinates(messages, incoming, reader, sessionID) {
|
|
|
6905
7173
|
selected.forEach((row, index) => {
|
|
6906
7174
|
const message = pending[index];
|
|
6907
7175
|
if (message)
|
|
6908
|
-
|
|
7176
|
+
bindRow(message, row);
|
|
6909
7177
|
});
|
|
6910
7178
|
} else {
|
|
6911
7179
|
const earliest = [];
|
|
@@ -6926,16 +7194,16 @@ function bindKeptInstructionCoordinates(messages, incoming, reader, sessionID) {
|
|
|
6926
7194
|
pending.forEach((message, index) => {
|
|
6927
7195
|
const row = candidates[earliest[index]];
|
|
6928
7196
|
if (row && earliest[index] === latest[index])
|
|
6929
|
-
|
|
7197
|
+
bindRow(message, row);
|
|
6930
7198
|
});
|
|
6931
7199
|
}
|
|
6932
7200
|
pending = [];
|
|
6933
7201
|
};
|
|
6934
7202
|
for (const message of messages) {
|
|
6935
|
-
if (
|
|
7203
|
+
if (!visible(message))
|
|
6936
7204
|
continue;
|
|
6937
7205
|
const id = nativeRowID(message);
|
|
6938
|
-
const seq = id ?
|
|
7206
|
+
const seq = id ? sequences.get(id) : undefined;
|
|
6939
7207
|
if (seq !== undefined) {
|
|
6940
7208
|
bind(seq);
|
|
6941
7209
|
previous = seq;
|
|
@@ -7284,9 +7552,31 @@ function coveredInstructionRows(reader, sessionID, throughSeq, model, retired =
|
|
|
7284
7552
|
return [];
|
|
7285
7553
|
return reader.instructionRowsThrough(sessionID, throughSeq).filter((row) => !retired(row)).flatMap((row) => restoreRow(row, model)).map((message) => markCoveredInstructionRow(message));
|
|
7286
7554
|
}
|
|
7555
|
+
var contextDisposalOrder = [
|
|
7556
|
+
"sweep",
|
|
7557
|
+
"backfill",
|
|
7558
|
+
"idle",
|
|
7559
|
+
"abortUsage",
|
|
7560
|
+
"hidden",
|
|
7561
|
+
"joinUsage",
|
|
7562
|
+
"rpc",
|
|
7563
|
+
"transform",
|
|
7564
|
+
"tools",
|
|
7565
|
+
"deletedSessions",
|
|
7566
|
+
"dream",
|
|
7567
|
+
"maintenance",
|
|
7568
|
+
"embeddings",
|
|
7569
|
+
"rawProviders",
|
|
7570
|
+
"restoredRows",
|
|
7571
|
+
"readerPool",
|
|
7572
|
+
"synthetic"
|
|
7573
|
+
];
|
|
7287
7574
|
async function registerContext(context) {
|
|
7288
7575
|
const directory = context.location.directory;
|
|
7289
7576
|
const config = loadPluginConfigDetailed(directory).config;
|
|
7577
|
+
for (const warning of new Set(config.configWarnings)) {
|
|
7578
|
+
log2(`[magic-context] config warning: ${warning}`);
|
|
7579
|
+
}
|
|
7290
7580
|
log2(`[magic-context] OpenCode 2 keep_subagents=${config.keep_subagents === true}`);
|
|
7291
7581
|
setHomeProjectPermission(config.allow_home_project);
|
|
7292
7582
|
if (!config.enabled)
|
|
@@ -7312,7 +7602,6 @@ async function registerContext(context) {
|
|
|
7312
7602
|
});
|
|
7313
7603
|
return;
|
|
7314
7604
|
}
|
|
7315
|
-
const liveConfigReader = pluginConfigReader(directory, config);
|
|
7316
7605
|
const compactionOff = !isCompactionEnabled(config);
|
|
7317
7606
|
const conflicts = detectConflicts(directory, {
|
|
7318
7607
|
compactionEnabled: !compactionOff,
|
|
@@ -7322,7 +7611,32 @@ async function registerContext(context) {
|
|
|
7322
7611
|
console.warn(`[magic-context] v2 setup disabled by conflicting context hooks: ${conflicts.reasons.join("; ")}`);
|
|
7323
7612
|
return;
|
|
7324
7613
|
}
|
|
7614
|
+
const cleanup = {};
|
|
7615
|
+
const dispose = async (failedSetup = false) => {
|
|
7616
|
+
for (const resource of contextDisposalOrder) {
|
|
7617
|
+
try {
|
|
7618
|
+
const drain = cleanup[resource]?.(failedSetup);
|
|
7619
|
+
if (drain)
|
|
7620
|
+
await drain;
|
|
7621
|
+
} catch (error) {
|
|
7622
|
+
const kind = error instanceof Error ? error.constructor.name : typeof error;
|
|
7623
|
+
log2(`[magic-context] v2 ${resource} cleanup failed (${kind})`);
|
|
7624
|
+
}
|
|
7625
|
+
}
|
|
7626
|
+
};
|
|
7627
|
+
try {
|
|
7628
|
+
await setupContext(context, config, nativeRemove, compactionOff, cleanup);
|
|
7629
|
+
} catch (error) {
|
|
7630
|
+
await dispose(true);
|
|
7631
|
+
throw error;
|
|
7632
|
+
}
|
|
7633
|
+
return { dispose: () => dispose() };
|
|
7634
|
+
}
|
|
7635
|
+
async function setupContext(context, config, nativeRemove, compactionOff, cleanup) {
|
|
7636
|
+
const directory = context.location.directory;
|
|
7637
|
+
const liveConfigReader = pluginConfigReader(directory, config);
|
|
7325
7638
|
const embeddings = createV2EmbeddingScope(resolveProjectIdentityForSession(directory, config.allow_home_project));
|
|
7639
|
+
cleanup.embeddings = () => embeddings.dispose();
|
|
7326
7640
|
const folds = new FoldOwner(context.storage);
|
|
7327
7641
|
const nativeFoldMemory = compactionOff ? undefined : nativeFoldCache(() => storage.require());
|
|
7328
7642
|
const loggedUncoveredCheckpoints = new BoundedSessionMap(1000);
|
|
@@ -7390,6 +7704,11 @@ async function registerContext(context) {
|
|
|
7390
7704
|
isLive: isLiveHiddenChild
|
|
7391
7705
|
});
|
|
7392
7706
|
let hiddenChildSweepTimer;
|
|
7707
|
+
cleanup.sweep = () => {
|
|
7708
|
+
if (hiddenChildSweepTimer)
|
|
7709
|
+
clearInterval(hiddenChildSweepTimer);
|
|
7710
|
+
return hiddenChildSweep.dispose();
|
|
7711
|
+
};
|
|
7393
7712
|
const sweepChildren = (database) => {
|
|
7394
7713
|
hiddenChildSweep.start(database);
|
|
7395
7714
|
};
|
|
@@ -7437,6 +7756,7 @@ async function registerContext(context) {
|
|
|
7437
7756
|
database: () => db ?? null,
|
|
7438
7757
|
compactionOff,
|
|
7439
7758
|
isHidden: (sessionID) => hiddenChildHook.owns(sessionID),
|
|
7759
|
+
onOverflow: (sessionID) => notifyV2ProviderOverflow(sessionID, openStoreReader),
|
|
7440
7760
|
onInputTokens: (sessionID, inputTokens, limit) => usage.set(sessionID, {
|
|
7441
7761
|
usage: { inputTokens, percentage: limit > 0 ? inputTokens / limit * 100 : 100 },
|
|
7442
7762
|
hasUsageTokens: true,
|
|
@@ -7455,6 +7775,8 @@ async function registerContext(context) {
|
|
|
7455
7775
|
});
|
|
7456
7776
|
});
|
|
7457
7777
|
const tools = db && isDatabasePersisted(db) ? await registerTools(context, db, config, moduleToolBackends?.backends, (id) => hiddenChildHook.owns(id), embeddings.ensureRegistered) : undefined;
|
|
7778
|
+
if (tools)
|
|
7779
|
+
cleanup.tools = () => tools.dispose();
|
|
7458
7780
|
const generateReplay = new V2GenerateReplay;
|
|
7459
7781
|
await context.session.hook("http.response", async (draft) => {
|
|
7460
7782
|
if (!db || draft.kind !== "primary" || draft.response.ok)
|
|
@@ -7478,6 +7800,11 @@ async function registerContext(context) {
|
|
|
7478
7800
|
});
|
|
7479
7801
|
let hiddenAgentsReady;
|
|
7480
7802
|
const readerPool = new V2StoreReaderPool2;
|
|
7803
|
+
cleanup.readerPool = async () => {
|
|
7804
|
+
if (!await readerPool.closeWhenIdle(STORE_POOL_DISPOSE_WAIT_MS))
|
|
7805
|
+
log2(`[magic-context] v2 store reader pool still held by ${readerPool.holdCount()} hidden run(s) at dispose; it closes when they finish`);
|
|
7806
|
+
};
|
|
7807
|
+
cleanup.synthetic = () => clearSyntheticCandidates(context);
|
|
7481
7808
|
const messageTimesCache = new V2MessageTimesCache;
|
|
7482
7809
|
const openStoreReader = () => readerPool.open(gaDatabasePath2(getDataDir(), process.env.OPENCODE_CHANNEL ?? "latest"));
|
|
7483
7810
|
const revertMessageCleanup = new V2RevertMessageCleanup(openStoreReader);
|
|
@@ -7548,6 +7875,10 @@ async function registerContext(context) {
|
|
|
7548
7875
|
hostVersion: context.app?.version,
|
|
7549
7876
|
keepSubagents: config.keep_subagents === true,
|
|
7550
7877
|
ensureAgent: () => hiddenAgentsReady ??= context.agent.reload(),
|
|
7878
|
+
forgetAgent: (pending) => {
|
|
7879
|
+
if (hiddenAgentsReady === pending)
|
|
7880
|
+
hiddenAgentsReady = undefined;
|
|
7881
|
+
},
|
|
7551
7882
|
modelCatalog: () => Promise.resolve(context.model.list()),
|
|
7552
7883
|
historianTemperature: () => config.historian?.temperature,
|
|
7553
7884
|
openReader: openStoreReader,
|
|
@@ -7581,9 +7912,12 @@ async function registerContext(context) {
|
|
|
7581
7912
|
return trigger;
|
|
7582
7913
|
};
|
|
7583
7914
|
let hiddenCompletionExecutor = db && isDatabasePersisted(db) && resolveProjectIdentityForSession(directory, config.allow_home_project) ? await createHiddenExecutor(db) : undefined;
|
|
7915
|
+
cleanup.hidden = () => hiddenCompletionExecutor?.dispose();
|
|
7584
7916
|
let dreamTrigger = hiddenCompletionExecutor ? startDreamer(hiddenCompletionExecutor) : undefined;
|
|
7917
|
+
cleanup.dream = () => dreamTrigger?.dispose();
|
|
7585
7918
|
const lateHiddenExecutor = createLateHiddenExecutor(() => hiddenCompletionExecutor);
|
|
7586
7919
|
let maintenanceTimer;
|
|
7920
|
+
cleanup.maintenance = () => maintenanceTimer?.dispose();
|
|
7587
7921
|
const startMaintenance = () => {
|
|
7588
7922
|
const timerProjectIdentity = resolveProjectIdentityForSession(directory, config.allow_home_project);
|
|
7589
7923
|
if (!timerProjectIdentity || maintenanceTimer)
|
|
@@ -7644,6 +7978,12 @@ async function registerContext(context) {
|
|
|
7644
7978
|
const commitSeenLastPass = new Map;
|
|
7645
7979
|
const restoredRows = new RestoredRowCache;
|
|
7646
7980
|
const rawProviders = new Map;
|
|
7981
|
+
cleanup.restoredRows = () => restoredRows.clear();
|
|
7982
|
+
cleanup.rawProviders = () => {
|
|
7983
|
+
for (const release of rawProviders.values())
|
|
7984
|
+
release();
|
|
7985
|
+
rawProviders.clear();
|
|
7986
|
+
};
|
|
7647
7987
|
let passDuties;
|
|
7648
7988
|
let toolDuties;
|
|
7649
7989
|
const droppedInputGuard = createDroppedInputGuard();
|
|
@@ -7682,8 +8022,9 @@ async function registerContext(context) {
|
|
|
7682
8022
|
};
|
|
7683
8023
|
if (db && isDatabasePersisted(db)) {
|
|
7684
8024
|
const backfillDb = db;
|
|
7685
|
-
|
|
7686
|
-
|
|
8025
|
+
let running;
|
|
8026
|
+
const timer = scheduleAfterBootQuiet(() => {
|
|
8027
|
+
running = runV2SessionProjectBackfill(backfillDb, openStoreReader, config.allow_home_project).then(() => backfillSessionActivity(backfillDb, "opencode", (sessionId) => {
|
|
7687
8028
|
const reader = openStoreReader();
|
|
7688
8029
|
try {
|
|
7689
8030
|
return reader.latestMessageTime(sessionId);
|
|
@@ -7692,6 +8033,17 @@ async function registerContext(context) {
|
|
|
7692
8033
|
}
|
|
7693
8034
|
})).catch((error) => log2("[session-project-backfill] OpenCode 2 backfill failed:", error));
|
|
7694
8035
|
});
|
|
8036
|
+
cleanup.backfill = (failedSetup) => {
|
|
8037
|
+
if (!failedSetup)
|
|
8038
|
+
return;
|
|
8039
|
+
clearTimeout(timer);
|
|
8040
|
+
if (!running)
|
|
8041
|
+
return;
|
|
8042
|
+
return settleWithin(running, DEFAULT_DISPOSE_DRAIN_MS).then((joined) => {
|
|
8043
|
+
if (!joined)
|
|
8044
|
+
log2("[magic-context] v2 backfill still running after setup cleanup");
|
|
8045
|
+
});
|
|
8046
|
+
};
|
|
7695
8047
|
}
|
|
7696
8048
|
const readAllForConversion = (sessionID) => readAllV2RawMessagesForConversion2(openStoreReader, sessionID);
|
|
7697
8049
|
const readRowsFrom = (sessionID, messageID) => {
|
|
@@ -7712,10 +8064,12 @@ async function registerContext(context) {
|
|
|
7712
8064
|
}) : undefined;
|
|
7713
8065
|
const lkgSystems = new V2LkgSystemReplay;
|
|
7714
8066
|
let transform;
|
|
8067
|
+
cleanup.transform = () => transform?.disposeRust();
|
|
7715
8068
|
let systemPrompt;
|
|
7716
8069
|
const systemPromptRefreshSessions = new Set;
|
|
7717
8070
|
const tagger = createTagger();
|
|
7718
8071
|
const deletedSessions = new DeletedSessionTombstones;
|
|
8072
|
+
cleanup.deletedSessions = () => deletedSessions.clear();
|
|
7719
8073
|
const forkSeedSettled = new Set;
|
|
7720
8074
|
const inheritForkState = (database, sessionID) => {
|
|
7721
8075
|
if (forkSeedSettled.has(sessionID))
|
|
@@ -7886,6 +8240,12 @@ async function registerContext(context) {
|
|
|
7886
8240
|
log: sessionLog2
|
|
7887
8241
|
}) : undefined;
|
|
7888
8242
|
const hostFoldIdle = hostFolds ? new HostFoldIdle((sessionID, eligible) => hostFolds.idle(sessionID, eligible)) : undefined;
|
|
8243
|
+
cleanup.idle = () => {
|
|
8244
|
+
messageTimesCache.clear();
|
|
8245
|
+
recoveredInstructions.clear();
|
|
8246
|
+
loggedUncoveredCheckpoints.clear();
|
|
8247
|
+
hostFoldIdle?.dispose();
|
|
8248
|
+
};
|
|
7889
8249
|
const armBindingRecoveryFromEvent = (sessionID, error, source) => {
|
|
7890
8250
|
if (error === undefined || !db || compactionOff)
|
|
7891
8251
|
return;
|
|
@@ -7921,6 +8281,7 @@ async function registerContext(context) {
|
|
|
7921
8281
|
}
|
|
7922
8282
|
};
|
|
7923
8283
|
const usageController = new AbortController;
|
|
8284
|
+
cleanup.abortUsage = () => usageController.abort();
|
|
7924
8285
|
const usageDone = (async () => {
|
|
7925
8286
|
let retry = 0;
|
|
7926
8287
|
while (!usageController.signal.aborted) {
|
|
@@ -8100,6 +8461,7 @@ async function registerContext(context) {
|
|
|
8100
8461
|
}
|
|
8101
8462
|
}
|
|
8102
8463
|
})();
|
|
8464
|
+
cleanup.joinUsage = () => usageDone;
|
|
8103
8465
|
const m0RenderOptions = (draft, store, state) => {
|
|
8104
8466
|
const modelKey = `${draft.model.providerID}/${draft.model.id}`;
|
|
8105
8467
|
const contextLimit = resolveContextLimit(draft.model.providerID, draft.model.id, {
|
|
@@ -8290,10 +8652,7 @@ async function registerContext(context) {
|
|
|
8290
8652
|
if (moduleBoundarySeq !== undefined)
|
|
8291
8653
|
sessionLog2(draft.sessionID, `v2 restore: from the module boundary ${moduleBoundaryID} to the host checkpoint`);
|
|
8292
8654
|
const present = new Set(args.messages.map((message) => message.id));
|
|
8293
|
-
const restored = restoredRows.rows(reader, draft.sessionID, boundary, cut.seq).filter((row) => !retiredInstructions(row)).filter((row) => !present.has(row.id)).flatMap((row) => restoreRow(row, draft.model, {
|
|
8294
|
-
asset: hostMediaAsset,
|
|
8295
|
-
unavailable: (detail) => sessionLog2(draft.sessionID, `v2 restore: attachment replaced by a note row=${detail.rowID} name=${JSON.stringify(detail.name ?? null)} mediaType=${detail.mediaType} reason=${JSON.stringify(detail.reason)}`)
|
|
8296
|
-
}));
|
|
8655
|
+
const restored = restoredRows.rows(reader, draft.sessionID, boundary, cut.seq).filter((row) => !retiredInstructions(row)).filter((row) => !present.has(row.id)).flatMap((row) => restoreRow(row, draft.model, readerRestoreMedia(reader, (detail) => sessionLog2(draft.sessionID, `v2 restore: attachment replaced by a note row=${detail.rowID} name=${JSON.stringify(detail.name ?? null)} mediaType=${detail.mediaType} reason=${JSON.stringify(detail.reason)}`))));
|
|
8297
8656
|
return [
|
|
8298
8657
|
...rustModeModuleClient ? [] : coveredInstructionRows(reader, draft.sessionID, Math.min(boundary, cut.seq), draft.model, retiredInstructions),
|
|
8299
8658
|
...restored,
|
|
@@ -9137,6 +9496,10 @@ async function registerContext(context) {
|
|
|
9137
9496
|
const storageDir = getMagicContextStorageDir();
|
|
9138
9497
|
const rpcServer = new MagicContextRpcServer(storageDir, directory);
|
|
9139
9498
|
let rpcStopped = false;
|
|
9499
|
+
cleanup.rpc = () => {
|
|
9500
|
+
rpcStopped = true;
|
|
9501
|
+
rpcServer.stop();
|
|
9502
|
+
};
|
|
9140
9503
|
registerRpcHandlers(rpcServer, {
|
|
9141
9504
|
directory,
|
|
9142
9505
|
config,
|
|
@@ -9243,35 +9606,6 @@ async function registerContext(context) {
|
|
|
9243
9606
|
return;
|
|
9244
9607
|
rpcServer.start().catch((error) => log2("[magic-context] v2 RPC server failed to start", error));
|
|
9245
9608
|
}, 0));
|
|
9246
|
-
return {
|
|
9247
|
-
async dispose() {
|
|
9248
|
-
if (hiddenChildSweepTimer)
|
|
9249
|
-
clearInterval(hiddenChildSweepTimer);
|
|
9250
|
-
await hiddenChildSweep.dispose();
|
|
9251
|
-
messageTimesCache.clear();
|
|
9252
|
-
recoveredInstructions.clear();
|
|
9253
|
-
loggedUncoveredCheckpoints.clear();
|
|
9254
|
-
hostFoldIdle?.dispose();
|
|
9255
|
-
usageController.abort();
|
|
9256
|
-
await hiddenCompletionExecutor?.dispose();
|
|
9257
|
-
await usageDone;
|
|
9258
|
-
rpcStopped = true;
|
|
9259
|
-
rpcServer.stop();
|
|
9260
|
-
transform?.disposeRust();
|
|
9261
|
-
tools?.dispose();
|
|
9262
|
-
deletedSessions.clear();
|
|
9263
|
-
await dreamTrigger?.dispose();
|
|
9264
|
-
await maintenanceTimer?.dispose();
|
|
9265
|
-
await embeddings.dispose();
|
|
9266
|
-
for (const release of rawProviders.values())
|
|
9267
|
-
release();
|
|
9268
|
-
rawProviders.clear();
|
|
9269
|
-
restoredRows.clear();
|
|
9270
|
-
if (!await readerPool.closeWhenIdle(STORE_POOL_DISPOSE_WAIT_MS))
|
|
9271
|
-
log2(`[magic-context] v2 store reader pool still held by ${readerPool.holdCount()} hidden run(s) at dispose; it closes when they finish`);
|
|
9272
|
-
clearSyntheticCandidates(context);
|
|
9273
|
-
}
|
|
9274
|
-
};
|
|
9275
9609
|
}
|
|
9276
9610
|
export {
|
|
9277
9611
|
registerContext
|