@cortexkit/opencode-magic-context 0.49.90 → 0.49.91
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/{context-cdds0gjj.js → context-6qq5e1ry.js} +519 -197
- 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/project-embedding-registry.d.ts +2 -1
- package/dist/features/magic-context/project-embedding-registry.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-runner-types.d.ts +2 -2
- package/dist/hooks/magic-context/compartment-runner-types.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/read-session-formatting.d.ts +2 -0
- package/dist/hooks/magic-context/read-session-formatting.d.ts.map +1 -1
- package/dist/{index-3pdknr07.js → index-0twg41mh.js} +2 -2
- package/dist/{index-2pdgy88n.js → index-3n376ann.js} +19 -7
- package/dist/{index-wmb2mcdw.js → index-3yw525kb.js} +5 -5
- package/dist/{index-mrjat4eq.js → index-5wgdbj2h.js} +3 -3
- package/dist/{index-pxnzyvjc.js → index-6r99v53h.js} +1 -1
- package/dist/{index-9d3qgwq0.js → index-6t7jvp76.js} +3 -3
- package/dist/{index-jzfsnbmm.js → index-7rgnh11t.js} +5 -5
- package/dist/{index-chpzb6xy.js → index-capcna4r.js} +2 -2
- package/dist/{index-1y4y98r1.js → index-czz0w2c4.js} +14 -2
- package/dist/{index-zxhev8ze.js → index-dva352qe.js} +1 -1
- package/dist/{index-dk3hy2a2.js → index-e8my7q6m.js} +10 -10
- package/dist/{index-w51n3576.js → index-f25ha337.js} +1 -1
- package/dist/{index-q7msfgwz.js → index-febyth5n.js} +94 -27
- package/dist/{index-kknjvmpx.js → index-fqth7850.js} +51 -60
- package/dist/{index-60wnwcwz.js → index-gqhebzxx.js} +2 -2
- package/dist/{index-n1ty0vd3.js → index-m6vhxsce.js} +58 -56
- package/dist/{index-m6dnydf8.js → index-mg9s2rc3.js} +1 -1
- package/dist/{index-2qsca7h7.js → index-mq97qmb8.js} +3 -3
- package/dist/{index-78t37mcq.js → index-nmkv8yvs.js} +3 -3
- package/dist/{index-tt0vs4x5.js → index-qna2ra0s.js} +1 -1
- package/dist/{index-qfcjrnpe.js → index-r6r2eh90.js} +4 -4
- package/dist/{index-g0mb2kb4.js → index-ran2b3fn.js} +10 -10
- package/dist/{index-5vsk2cpp.js → index-s7460efs.js} +12 -1
- package/dist/{index-08jfpny9.js → index-sr8dmp7p.js} +1 -1
- package/dist/{index-h9hybzr5.js → index-wfahebsc.js} +5 -5
- package/dist/index-x3rdza40.js +63 -0
- package/dist/{index-60x5d68t.js → index-xn9efn18.js} +1 -1
- package/dist/{index-39rzef89.js → index-ydhymf0b.js} +3 -3
- package/dist/{index-61knrt52.js → index-ywgv1xcb.js} +1 -1
- package/dist/index.js +40 -40
- package/dist/{message-index-bounded-r1qys471.js → message-index-bounded-wvnp6fcp.js} +5 -5
- 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-j4hjc1pk.js} +4 -4
- package/dist/{recomp-orchestrator-dgyb394j.js → recomp-orchestrator-ps1c8c5h.js} +19 -18
- package/dist/{render-d014e603.js → render-nfj7280n.js} +13 -13
- package/dist/{search-9gceftb9.js → search-3r8b0jfa.js} +15 -15
- package/dist/{search-archive-gybn6q7s.js → search-archive-1etwnve4.js} +6 -6
- 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-nh2ftqhx.js} +3 -3
- package/dist/{store-n4yz3n66.js → store-019k3ek7.js} +2 -2
- package/dist/{store-reader-nf8z86n9.js → store-reader-a2v34xnh.js} +1 -1
- package/dist/{task-config-qt6n4bxm.js → task-config-vrebjxyy.js} +2 -1
- package/dist/{transform-postprocess-phase-34k1zwsy.js → transform-postprocess-phase-tqp968w4.js} +20 -19
- 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-d57v8c10.js} +557 -234
- 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/native-replay-v3.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 +2 -2
- 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/{message-index-bounded-b07r9cjv.js → message-index-bounded-2nhbwry6.js} +5 -5
- 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-jrrhwxgx.js} +4 -4
- package/dist/v2/{recomp-orchestrator-wq7gbkqa.js → recomp-orchestrator-n79hdd7n.js} +19 -18
- package/dist/v2/{render-2dan17xc.js → render-7emcjdt1.js} +13 -13
- package/dist/v2/{search-archive-89hdy0a2.js → search-archive-fpjbmxcx.js} +6 -6
- package/dist/v2/{search-nyqykx7q.js → search-vz2cpgr0.js} +14 -14
- package/dist/v2/{server-ytqps2xa.js → server-0h875f56.js} +1 -1
- package/dist/v2/server-3gz9k20t.js +63 -0
- package/dist/v2/{server-ta4h0fch.js → server-3z8rhacq.js} +9 -9
- package/dist/v2/{server-dtcwkdqj.js → server-4axv6kq6.js} +63 -23
- package/dist/v2/{server-c7awk5s2.js → server-4bfk1sky.js} +3 -3
- 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-add0j5n3.js → server-8ps3717t.js} +3 -3
- package/dist/v2/{server-a85j3kam.js → server-8r32etq0.js} +1 -1
- 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-yx0nyj1q.js → server-hgfd6c3e.js} +3 -3
- package/dist/v2/{server-qyazxy92.js → server-j9cm1czj.js} +14 -2
- package/dist/v2/{server-9n2qgk29.js → server-kwsqytwj.js} +2 -2
- package/dist/v2/{server-fb5hvvfc.js → server-n431vzn5.js} +3 -3
- package/dist/v2/{server-2kswss3d.js → server-n5wn7d9b.js} +48 -60
- package/dist/v2/{server-x6fn9x8q.js → server-ps6zrzwj.js} +1 -1
- package/dist/v2/{server-pmws7we9.js → server-q104czn6.js} +2 -2
- package/dist/v2/{server-vy0beygw.js → server-q2ap5cty.js} +3 -3
- 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-09h2vyvs.js → server-r4816kwv.js} +5 -5
- package/dist/v2/{server-b0a9h3ds.js → server-vfa7byfa.js} +5 -5
- package/dist/v2/{server-tj65pgvg.js → server-vsqmkvxc.js} +32 -5
- package/dist/v2/{server-fn4ky6mn.js → server-xmgvy3cq.js} +1 -1
- package/dist/v2/server.js +4 -3
- package/dist/v2/{storage-tags-pmw33chf.js → storage-tags-t0f9njdp.js} +3 -3
- package/dist/v2/{store-y56y034s.js → store-q3ef5rvz.js} +2 -2
- package/dist/v2/{store-reader-2vhx33n6.js → store-reader-wc01y2rc.js} +1 -1
- package/dist/v2/store-reader.d.ts +2 -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-9p84yzk5.js} +1 -1
- package/dist/v2/{wrapup-orchestrator-2h7ayss9.js → wrapup-orchestrator-acebazx8.js} +19 -18
- package/dist/{v2-archive-reader-8158kyfd.js → v2-archive-reader-w1bbaqe8.js} +1 -1
- package/dist/{wrapup-orchestrator-ct59br0c.js → wrapup-orchestrator-fwbe0mvm.js} +20 -19
- 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/startup-maintenance-policy.test.ts +11 -6
- package/dist/index-ksdyrrav.js +0 -52
- package/dist/v2/server-0s95v3en.js +0 -49
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
resolveLegacyConfigSources,
|
|
8
8
|
getProtectedTokensTierOverrides,
|
|
9
9
|
loadPluginConfigDetailed
|
|
10
|
-
} from "./server-
|
|
10
|
+
} from "./server-vsqmkvxc.js";
|
|
11
11
|
import {
|
|
12
12
|
getHarness2,
|
|
13
13
|
harnessOwnsOpenCodeStore2
|
|
@@ -53,6 +53,25 @@ import {
|
|
|
53
53
|
getSdkOutputLimit,
|
|
54
54
|
getModelsDevCacheState
|
|
55
55
|
} from "./server-96nm9vk4.js";
|
|
56
|
+
import {
|
|
57
|
+
COMPACTION_ENABLED_PATH,
|
|
58
|
+
isDreamerRunnable,
|
|
59
|
+
isSmartNoteSurfaceAvailable,
|
|
60
|
+
isCompactionEnabled,
|
|
61
|
+
CANONICAL_DREAM_TASKS,
|
|
62
|
+
MIN_POOL_TO_CLASSIFY,
|
|
63
|
+
DREAM_TASK_CAPABILITIES,
|
|
64
|
+
toolLoopDreamTasks,
|
|
65
|
+
formatUnsupportedDreamTasks,
|
|
66
|
+
formatDreamTaskBacklogs,
|
|
67
|
+
processedDreamTaskItems,
|
|
68
|
+
PROJECT_MEMORY_DREAM_TASKS,
|
|
69
|
+
dreamTaskAllowedBySettings,
|
|
70
|
+
leaseKindFor,
|
|
71
|
+
leaseKeyFor,
|
|
72
|
+
isCanonicalDreamTask,
|
|
73
|
+
compareTaskOrder
|
|
74
|
+
} from "./server-n5wn7d9b.js";
|
|
56
75
|
import {
|
|
57
76
|
string,
|
|
58
77
|
number,
|
|
@@ -75,25 +94,6 @@ import {
|
|
|
75
94
|
DEFAULT_LOCAL_EMBEDDING_MODEL,
|
|
76
95
|
DREAM_TASK_PROMOTION_DEFAULTS
|
|
77
96
|
} from "./server-rz6g5xne.js";
|
|
78
|
-
import {
|
|
79
|
-
CANONICAL_DREAM_TASKS,
|
|
80
|
-
MIN_POOL_TO_CLASSIFY,
|
|
81
|
-
DREAM_TASK_CAPABILITIES,
|
|
82
|
-
toolLoopDreamTasks,
|
|
83
|
-
formatUnsupportedDreamTasks,
|
|
84
|
-
formatDreamTaskBacklogs,
|
|
85
|
-
processedDreamTaskItems,
|
|
86
|
-
PROJECT_MEMORY_DREAM_TASKS,
|
|
87
|
-
dreamTaskAllowedBySettings,
|
|
88
|
-
leaseKindFor,
|
|
89
|
-
leaseKeyFor,
|
|
90
|
-
isCanonicalDreamTask,
|
|
91
|
-
compareTaskOrder,
|
|
92
|
-
buildDreamTaskRuntimeConfigs2,
|
|
93
|
-
userMemoryCollectionEnabled2,
|
|
94
|
-
userObservationCollectionEnabled2,
|
|
95
|
-
userObservationsRequested2
|
|
96
|
-
} from "./server-2kswss3d.js";
|
|
97
97
|
import {
|
|
98
98
|
historianRunConfig,
|
|
99
99
|
dreamerRunConfig,
|
|
@@ -139,6 +139,7 @@ import {
|
|
|
139
139
|
hiddenToolLoop,
|
|
140
140
|
HIDDEN_RUN_DISPOSED_REASON,
|
|
141
141
|
noteChildOfDisposedInstance,
|
|
142
|
+
noteTimedOutHiddenChild,
|
|
142
143
|
hiddenChildPermissions,
|
|
143
144
|
registerHiddenChildAgents,
|
|
144
145
|
hiddenToolCallRefusal,
|
|
@@ -152,6 +153,8 @@ import {
|
|
|
152
153
|
toModelEntry,
|
|
153
154
|
hiddenModelCooldowns,
|
|
154
155
|
ModelProducedNoOutputError,
|
|
156
|
+
promptTransportBudget,
|
|
157
|
+
notePromptSetupTimeout,
|
|
155
158
|
noteModelActivityMonitored,
|
|
156
159
|
noteModelOutputReceived,
|
|
157
160
|
isPromptTimeoutError,
|
|
@@ -243,7 +246,7 @@ import {
|
|
|
243
246
|
startCompartmentAgent,
|
|
244
247
|
setRecompStarting2,
|
|
245
248
|
setRecompTerminal2
|
|
246
|
-
} from "./server-
|
|
249
|
+
} from "./server-4axv6kq6.js";
|
|
247
250
|
import {
|
|
248
251
|
embedPauseBySession,
|
|
249
252
|
embedRunStateBySession,
|
|
@@ -259,13 +262,14 @@ import {
|
|
|
259
262
|
textMentionsRecentCommit,
|
|
260
263
|
hasMeaningfulUserText2,
|
|
261
264
|
extractTexts2,
|
|
265
|
+
hasCompletedToolCall,
|
|
262
266
|
extractToolCallSummaries,
|
|
263
267
|
getTokenizerNativeMemoryStats,
|
|
264
268
|
preloadTokenizer,
|
|
265
269
|
estimateTokens,
|
|
266
270
|
estimateFixedPromptTokens,
|
|
267
271
|
normalizeText
|
|
268
|
-
} from "./server-
|
|
272
|
+
} from "./server-qb3s0mnc.js";
|
|
269
273
|
import {
|
|
270
274
|
SubcClient,
|
|
271
275
|
connectionFileExists,
|
|
@@ -273,7 +277,7 @@ import {
|
|
|
273
277
|
toSynapseLaneDescriptor,
|
|
274
278
|
formatSynapseLaneDescriptor,
|
|
275
279
|
SynapseEmbeddingProvider
|
|
276
|
-
} from "./server-
|
|
280
|
+
} from "./server-ps6zrzwj.js";
|
|
277
281
|
import {
|
|
278
282
|
inRootAsyncContext2,
|
|
279
283
|
getTagIdentityWriteGeneration2,
|
|
@@ -306,7 +310,7 @@ import {
|
|
|
306
310
|
import"./server-ds8vpfkr.js";
|
|
307
311
|
import {
|
|
308
312
|
deleteChunkEmbedBackoffForSession2
|
|
309
|
-
} from "./server-
|
|
313
|
+
} from "./server-barj0mjz.js";
|
|
310
314
|
import {
|
|
311
315
|
acquireCompartmentLease,
|
|
312
316
|
releaseCompartmentLeaseBestEffort,
|
|
@@ -426,12 +430,12 @@ import {
|
|
|
426
430
|
saveSourceContent,
|
|
427
431
|
replaceSourceContent,
|
|
428
432
|
getSourceContents
|
|
429
|
-
} from "./server-
|
|
433
|
+
} from "./server-r4816kwv.js";
|
|
430
434
|
import {
|
|
431
435
|
cleanSearchText,
|
|
432
436
|
matchedSearchSnippet,
|
|
433
437
|
getLastIndexedOrdinal
|
|
434
|
-
} from "./server-
|
|
438
|
+
} from "./server-kwsqytwj.js";
|
|
435
439
|
import {
|
|
436
440
|
ensureSessionMetaRow,
|
|
437
441
|
clearCachedM0M1,
|
|
@@ -687,7 +691,7 @@ import {
|
|
|
687
691
|
adoptNullOwnerToolTag2,
|
|
688
692
|
getCandidateToolOwners2,
|
|
689
693
|
pickNearestPriorOwner2
|
|
690
|
-
} from "./server-
|
|
694
|
+
} from "./server-q104czn6.js";
|
|
691
695
|
import {
|
|
692
696
|
BoundedSessionMap,
|
|
693
697
|
getTableColumnNames,
|
|
@@ -701,10 +705,16 @@ import {
|
|
|
701
705
|
freezeTemporalDecisions,
|
|
702
706
|
tagRevisionKey,
|
|
703
707
|
tagIdentityRevisionKey
|
|
704
|
-
} from "./server-
|
|
708
|
+
} from "./server-qntmqaca.js";
|
|
705
709
|
import {
|
|
706
710
|
resolveHistorianModel2
|
|
707
711
|
} from "./server-5kym00ag.js";
|
|
712
|
+
import {
|
|
713
|
+
buildDreamTaskRuntimeConfigs2,
|
|
714
|
+
userMemoryCollectionEnabled2,
|
|
715
|
+
userObservationCollectionEnabled2,
|
|
716
|
+
userObservationsRequested2
|
|
717
|
+
} from "./server-3gz9k20t.js";
|
|
708
718
|
import {
|
|
709
719
|
formatFailClosedBlockingMessage,
|
|
710
720
|
formatFailClosedBlockingSummary,
|
|
@@ -794,7 +804,7 @@ import {
|
|
|
794
804
|
readRawSessionMessageOrdinalById2,
|
|
795
805
|
readSessionChunk2,
|
|
796
806
|
readRawSessionSeedTail2
|
|
797
|
-
} from "./server-
|
|
807
|
+
} from "./server-4bfk1sky.js";
|
|
798
808
|
import {
|
|
799
809
|
getMessageIndexEpoch,
|
|
800
810
|
isMessageIndexSearchable,
|
|
@@ -820,7 +830,7 @@ import {
|
|
|
820
830
|
resolveMemoriesByIdsForSearch2,
|
|
821
831
|
unifiedSearch2,
|
|
822
832
|
formatSearchResults2
|
|
823
|
-
} from "./server-
|
|
833
|
+
} from "./server-3z8rhacq.js";
|
|
824
834
|
import {
|
|
825
835
|
startBootDeadline,
|
|
826
836
|
getUnconfirmedMigrationHolders,
|
|
@@ -836,7 +846,7 @@ import {
|
|
|
836
846
|
openDatabaseAsync,
|
|
837
847
|
isDatabasePersisted,
|
|
838
848
|
getDatabasePersistenceError
|
|
839
|
-
} from "./server-
|
|
849
|
+
} from "./server-n431vzn5.js";
|
|
840
850
|
import {
|
|
841
851
|
V2_MEMORY_CATEGORIES,
|
|
842
852
|
CATEGORY_PRIORITY
|
|
@@ -849,13 +859,13 @@ import {
|
|
|
849
859
|
resolveStoredPathWorkspaceIdentity,
|
|
850
860
|
storedPathBelongsToWorkspace,
|
|
851
861
|
computeWorkspaceEpochFingerprint
|
|
852
|
-
} from "./server-
|
|
862
|
+
} from "./server-8r32etq0.js";
|
|
853
863
|
import {
|
|
854
864
|
gaDatabasePath2,
|
|
855
865
|
RAW_MESSAGE_TYPES2,
|
|
856
866
|
V2StoreReaderPool2,
|
|
857
867
|
V2StoreReader2
|
|
858
|
-
} from "./server-
|
|
868
|
+
} from "./server-j9cm1czj.js";
|
|
859
869
|
import {
|
|
860
870
|
configureContextDatabasePragmas2
|
|
861
871
|
} from "./server-fb3zxn06.js";
|
|
@@ -884,7 +894,7 @@ import {
|
|
|
884
894
|
createPrimer,
|
|
885
895
|
updatePrimerSupport,
|
|
886
896
|
updatePrimerAnswer
|
|
887
|
-
} from "./server-
|
|
897
|
+
} from "./server-xmgvy3cq.js";
|
|
888
898
|
import {
|
|
889
899
|
deriveTriggerBudget2,
|
|
890
900
|
deriveHistorianChunkTokens2,
|
|
@@ -911,13 +921,14 @@ import {
|
|
|
911
921
|
getProjectEmbeddingSnapshot2,
|
|
912
922
|
embedTextForProject2,
|
|
913
923
|
embedBatchForProject2,
|
|
924
|
+
countUnembeddedMemoriesForProject2,
|
|
914
925
|
embedUnembeddedMemoriesForProject2,
|
|
915
926
|
embedUnembeddedMemoriesForProjectOutcome2,
|
|
916
927
|
drainCommitBacklogForProject2,
|
|
917
928
|
embedSessionCompartmentChunks2,
|
|
918
929
|
getEmbeddingCoverageStatus2,
|
|
919
930
|
getAutoEmbeddingSessionCoverage2
|
|
920
|
-
} from "./server-
|
|
931
|
+
} from "./server-72k2r3kt.js";
|
|
921
932
|
import {
|
|
922
933
|
GIT_SWEEP_LEASE_RENEWAL_MS,
|
|
923
934
|
acquireGitSweepLease,
|
|
@@ -937,7 +948,7 @@ import {
|
|
|
937
948
|
getCachedLocalEmbeddingPooling,
|
|
938
949
|
preflightLocalEmbeddingPooling,
|
|
939
950
|
getLocalEmbeddingNativeMemoryStats
|
|
940
|
-
} from "./server-
|
|
951
|
+
} from "./server-7e89a2kf.js";
|
|
941
952
|
import {
|
|
942
953
|
renderUserFacingFailure,
|
|
943
954
|
userFacingFailureCode,
|
|
@@ -957,8 +968,8 @@ import {
|
|
|
957
968
|
readGitFileChangeTimesSince,
|
|
958
969
|
verificationFileExists,
|
|
959
970
|
normalizeVerificationFiles
|
|
960
|
-
} from "./server-
|
|
961
|
-
import"./server-
|
|
971
|
+
} from "./server-8ps3717t.js";
|
|
972
|
+
import"./server-b4efn08m.js";
|
|
962
973
|
import {
|
|
963
974
|
computeCueContentHash,
|
|
964
975
|
hasMuralCueColumns,
|
|
@@ -1024,7 +1035,7 @@ import {
|
|
|
1024
1035
|
readV2RawMessagePagesForConversion2,
|
|
1025
1036
|
createV2RawMessageReader2,
|
|
1026
1037
|
createV2RawMessageProvider2
|
|
1027
|
-
} from "./server-
|
|
1038
|
+
} from "./server-0h875f56.js";
|
|
1028
1039
|
import {
|
|
1029
1040
|
resolvePromptContext2
|
|
1030
1041
|
} from "./server-fmsr7v69.js";
|
|
@@ -1032,14 +1043,14 @@ import {
|
|
|
1032
1043
|
renderMessageByOrdinal2,
|
|
1033
1044
|
renderVerboseRangeForTool2,
|
|
1034
1045
|
renderItemByTag2
|
|
1035
|
-
} from "./server-
|
|
1046
|
+
} from "./server-hgfd6c3e.js";
|
|
1036
1047
|
import"./server-52x68mj4.js";
|
|
1037
1048
|
import {
|
|
1038
1049
|
readV2ArchiveOffThread2
|
|
1039
|
-
} from "./server-
|
|
1050
|
+
} from "./server-vfa7byfa.js";
|
|
1040
1051
|
import {
|
|
1041
1052
|
renderSearchArchiveOffThread2
|
|
1042
|
-
} from "./server-
|
|
1053
|
+
} from "./server-q2ap5cty.js";
|
|
1043
1054
|
import {
|
|
1044
1055
|
markHostInstructionRow,
|
|
1045
1056
|
hostInstructionRow,
|
|
@@ -1053,12 +1064,6 @@ import {
|
|
|
1053
1064
|
import {
|
|
1054
1065
|
compareSemverCore
|
|
1055
1066
|
} from "./server-84w6rvvf.js";
|
|
1056
|
-
import {
|
|
1057
|
-
COMPACTION_ENABLED_PATH,
|
|
1058
|
-
isDreamerRunnable,
|
|
1059
|
-
isSmartNoteSurfaceAvailable,
|
|
1060
|
-
isCompactionEnabled
|
|
1061
|
-
} from "./server-0s95v3en.js";
|
|
1062
1067
|
import {
|
|
1063
1068
|
__toESM,
|
|
1064
1069
|
__export
|
|
@@ -14492,7 +14497,7 @@ async function drainSingleStoreEmbeddingWatermarks(db) {
|
|
|
14492
14497
|
let outcome = await embedUnembeddedMemoriesForProjectOutcome2(db, watermark.project_path);
|
|
14493
14498
|
if (outcome.kind === "embedded") {
|
|
14494
14499
|
embedded += outcome.count;
|
|
14495
|
-
if (
|
|
14500
|
+
if (countUnembeddedMemoriesForProject2(db, watermark.project_path) === 0) {
|
|
14496
14501
|
outcome = await embedUnembeddedMemoriesForProjectOutcome2(db, watermark.project_path);
|
|
14497
14502
|
if (outcome.kind === "embedded")
|
|
14498
14503
|
embedded += outcome.count;
|
|
@@ -14510,13 +14515,6 @@ async function drainSingleStoreEmbeddingWatermarks(db) {
|
|
|
14510
14515
|
}
|
|
14511
14516
|
return embedded;
|
|
14512
14517
|
}
|
|
14513
|
-
function countUnembeddedBelow(db, projectPath) {
|
|
14514
|
-
const row = db.prepare(`SELECT COUNT(*) AS count FROM memories
|
|
14515
|
-
WHERE project_path = ?
|
|
14516
|
-
AND status IN ('active', 'permanent')
|
|
14517
|
-
AND NOT EXISTS (SELECT 1 FROM memory_embeddings WHERE memory_id = memories.id)`).get(projectPath);
|
|
14518
|
-
return typeof row?.count === "number" ? row.count : 0;
|
|
14519
|
-
}
|
|
14520
14518
|
function advanceEmbeddedWatermark(db, projectPath, upTo) {
|
|
14521
14519
|
db.prepare(`UPDATE memory_embedding_watermarks
|
|
14522
14520
|
SET embedded_memory_id = MAX(embedded_memory_id, ?),
|
|
@@ -14657,6 +14655,8 @@ function describeError2(error) {
|
|
|
14657
14655
|
function failureCode(error, aborted) {
|
|
14658
14656
|
if (aborted)
|
|
14659
14657
|
return "aborted";
|
|
14658
|
+
if (error instanceof HiddenCompletionRefusal)
|
|
14659
|
+
return "local_refusal";
|
|
14660
14660
|
const text = describeError2(error).toLowerCase();
|
|
14661
14661
|
if (text.includes("all models exhausted") || text.includes("all fallback models failed")) {
|
|
14662
14662
|
return "chain_exhausted";
|
|
@@ -26480,7 +26480,7 @@ function registerRpcHandlers(rpcServer, args) {
|
|
|
26480
26480
|
const buildManagedCtx = async (db) => {
|
|
26481
26481
|
const { deriveHistorianChunkTokens, resolveHistorianContextLimit } = await importPluginModule(() => import("./derive-budgets-hr4qqrnv.js"));
|
|
26482
26482
|
const { resolveHistorianModel } = await importPluginModule(() => import("./model-resolution-280gmqvd.js"));
|
|
26483
|
-
const { userObservationCollectionEnabled, userObservationsRequested } = await importPluginModule(() => import("./task-config-
|
|
26483
|
+
const { userObservationCollectionEnabled, userObservationsRequested } = await importPluginModule(() => import("./task-config-4nqq2s0w.js"));
|
|
26484
26484
|
const DEFAULT_HISTORIAN_TIMEOUT_MS = 10 * 60 * 1000;
|
|
26485
26485
|
const runConfig = historianRunConfig(config, currentPluginConfigReader(directory)?.poll().effective ?? config);
|
|
26486
26486
|
const historianModel = resolveHistorianModel(runConfig, "opencode");
|
|
@@ -26530,7 +26530,7 @@ function registerRpcHandlers(rpcServer, args) {
|
|
|
26530
26530
|
const db = readDatabase();
|
|
26531
26531
|
if (!db)
|
|
26532
26532
|
return { ok: false, error: "db unavailable" };
|
|
26533
|
-
const { runManagedRecomp } = await importPluginModule(() => import("./recomp-orchestrator-
|
|
26533
|
+
const { runManagedRecomp } = await importPluginModule(() => import("./recomp-orchestrator-n79hdd7n.js"));
|
|
26534
26534
|
const { sendIgnoredMessage } = await importPluginModule(() => import("./send-session-notification-zazaxxpf.js"));
|
|
26535
26535
|
log2(`[rpc] recomp requested for session ${sessionId}`);
|
|
26536
26536
|
if (!args.client && !args.hiddenCompletionExecutor) {
|
|
@@ -26615,7 +26615,7 @@ function registerRpcHandlers(rpcServer, args) {
|
|
|
26615
26615
|
const db = readDatabase();
|
|
26616
26616
|
if (!db)
|
|
26617
26617
|
return { ok: false, error: "db unavailable" };
|
|
26618
|
-
const { runManagedWrapup } = await importPluginModule(() => import("./wrapup-orchestrator-
|
|
26618
|
+
const { runManagedWrapup } = await importPluginModule(() => import("./wrapup-orchestrator-acebazx8.js"));
|
|
26619
26619
|
const model = await args.readSelectedSessionModel?.(sessionId) ?? liveSessionState.liveModelBySession.get(sessionId);
|
|
26620
26620
|
const window = resolveOpenCodeWrapupWindow(db, sessionId, model);
|
|
26621
26621
|
if (!window)
|
|
@@ -28959,7 +28959,13 @@ function importedFloor(reader, sessionID, through = reader.latestSequence(sessio
|
|
|
28959
28959
|
let after = -1;
|
|
28960
28960
|
let found;
|
|
28961
28961
|
while (true) {
|
|
28962
|
-
const page = reader.page(sessionID, {
|
|
28962
|
+
const page = reader.page(sessionID, {
|
|
28963
|
+
after,
|
|
28964
|
+
through,
|
|
28965
|
+
type: "compaction",
|
|
28966
|
+
limit: 1000,
|
|
28967
|
+
preferTypeIndex: true
|
|
28968
|
+
});
|
|
28963
28969
|
if (!page.rows.length)
|
|
28964
28970
|
break;
|
|
28965
28971
|
for (const row of page.rows) {
|
|
@@ -30681,6 +30687,10 @@ var SWEEP_BUDGET_MS = 30000;
|
|
|
30681
30687
|
function recordHiddenChild(db, child) {
|
|
30682
30688
|
db.prepare("INSERT INTO schema_migrations_meta (key, value) VALUES (?, ?)").run(`${PREFIX}${child.id}`, JSON.stringify(child));
|
|
30683
30689
|
}
|
|
30690
|
+
function recordRetiringHiddenChild(db, child) {
|
|
30691
|
+
db.prepare(`INSERT INTO schema_migrations_meta (key, value) VALUES (?, ?)
|
|
30692
|
+
ON CONFLICT(key) DO UPDATE SET value = json_set(value, '$.retiring', json('true'))`).run(`${PREFIX}${child.id}`, JSON.stringify({ ...child, retiring: true }));
|
|
30693
|
+
}
|
|
30684
30694
|
function forgetHiddenChild(db, id) {
|
|
30685
30695
|
db.prepare("DELETE FROM schema_migrations_meta WHERE key = ?").run(`${PREFIX}${id}`);
|
|
30686
30696
|
}
|
|
@@ -30787,6 +30797,20 @@ function isSessionNotFound(error) {
|
|
|
30787
30797
|
function createNativeHiddenChildren(host, removeSession, options) {
|
|
30788
30798
|
const quiet = supportsQuietHiddenChildren(options.hostVersion);
|
|
30789
30799
|
const removing = new Map;
|
|
30800
|
+
const removeBounded = async (id, timeoutMs = options.removalTimeoutMs ?? 5000) => {
|
|
30801
|
+
let timer;
|
|
30802
|
+
try {
|
|
30803
|
+
await Promise.race([
|
|
30804
|
+
removeSession({ sessionID: id }),
|
|
30805
|
+
new Promise((_, reject) => {
|
|
30806
|
+
timer = setTimeout(() => reject(new Error("session.remove timed out")), timeoutMs);
|
|
30807
|
+
})
|
|
30808
|
+
]);
|
|
30809
|
+
} finally {
|
|
30810
|
+
if (timer)
|
|
30811
|
+
clearTimeout(timer);
|
|
30812
|
+
}
|
|
30813
|
+
};
|
|
30790
30814
|
const remove = (child) => {
|
|
30791
30815
|
const inFlight = removing.get(child.id);
|
|
30792
30816
|
if (inFlight)
|
|
@@ -30794,18 +30818,7 @@ function createNativeHiddenChildren(host, removeSession, options) {
|
|
|
30794
30818
|
options.log(`[magic-context] hidden child ${child.id} removing`);
|
|
30795
30819
|
const done = (async () => {
|
|
30796
30820
|
try {
|
|
30797
|
-
|
|
30798
|
-
try {
|
|
30799
|
-
await Promise.race([
|
|
30800
|
-
removeSession({ sessionID: child.id }),
|
|
30801
|
-
new Promise((_, reject) => {
|
|
30802
|
-
timer = setTimeout(() => reject(new Error("session.remove timed out")), options.removalTimeoutMs ?? 5000);
|
|
30803
|
-
})
|
|
30804
|
-
]);
|
|
30805
|
-
} finally {
|
|
30806
|
-
if (timer)
|
|
30807
|
-
clearTimeout(timer);
|
|
30808
|
-
}
|
|
30821
|
+
await removeBounded(child.id);
|
|
30809
30822
|
forgetHiddenChild(options.db, child.id);
|
|
30810
30823
|
options.log(`[magic-context] hidden child ${child.id} removed`);
|
|
30811
30824
|
} catch (error) {
|
|
@@ -30826,18 +30839,52 @@ function createNativeHiddenChildren(host, removeSession, options) {
|
|
|
30826
30839
|
removing.set(child.id, done);
|
|
30827
30840
|
return done;
|
|
30828
30841
|
};
|
|
30829
|
-
const
|
|
30842
|
+
const retireLate = async (id, directory, createdAt, cleanupMs) => {
|
|
30843
|
+
noteTimedOutHiddenChild(id);
|
|
30844
|
+
liveChildren.delete(id);
|
|
30845
|
+
try {
|
|
30846
|
+
recordRetiringHiddenChild(options.db, { id, directory, created_at: createdAt });
|
|
30847
|
+
} catch (error) {
|
|
30848
|
+
const kind = error instanceof Error ? error.constructor.name : typeof error;
|
|
30849
|
+
options.log(`[magic-context] late hidden child ${id} record failed (${kind})`);
|
|
30850
|
+
}
|
|
30851
|
+
try {
|
|
30852
|
+
await removeBounded(id, cleanupMs);
|
|
30853
|
+
} catch (error) {
|
|
30854
|
+
if (!isSessionNotFound(error)) {
|
|
30855
|
+
options.log(`[magic-context] late hidden child ${id} could not be removed`);
|
|
30856
|
+
return;
|
|
30857
|
+
}
|
|
30858
|
+
}
|
|
30859
|
+
try {
|
|
30860
|
+
forgetHiddenChild(options.db, id);
|
|
30861
|
+
} catch {}
|
|
30862
|
+
};
|
|
30863
|
+
const create = async (identity, role, model, budget) => {
|
|
30830
30864
|
const input = childCreateInput(identity, role, model);
|
|
30831
30865
|
const directory = identity.directory;
|
|
30832
30866
|
if (quiet) {
|
|
30833
30867
|
if (!host.createHolder)
|
|
30834
30868
|
throw new Error("OpenCode 2 background holder API is not wired");
|
|
30835
|
-
const placement = await hiddenRunPlacement(host.createHolder, directory);
|
|
30869
|
+
const placement = await hiddenRunPlacement(host.createHolder, directory, budget);
|
|
30836
30870
|
input.id = placement.id;
|
|
30837
30871
|
input.parentID = placement.parentID;
|
|
30838
30872
|
delete input.location;
|
|
30839
30873
|
}
|
|
30840
|
-
|
|
30874
|
+
budget?.setStage("creating the child session");
|
|
30875
|
+
const start = () => host.create(input);
|
|
30876
|
+
const removeLate = ({ id }) => {
|
|
30877
|
+
if (!id || !budget)
|
|
30878
|
+
return;
|
|
30879
|
+
retireLate(id, directory, Date.now(), budget.cleanupMs);
|
|
30880
|
+
};
|
|
30881
|
+
const created = await (budget?.work(start, removeLate) ?? start());
|
|
30882
|
+
try {
|
|
30883
|
+
budget?.check();
|
|
30884
|
+
} catch (error) {
|
|
30885
|
+
removeLate(created);
|
|
30886
|
+
throw error;
|
|
30887
|
+
}
|
|
30841
30888
|
if (!created.id)
|
|
30842
30889
|
throw new Error("OpenCode 2 did not return a child session id");
|
|
30843
30890
|
const createdAt = Date.now();
|
|
@@ -30852,20 +30899,12 @@ function createNativeHiddenChildren(host, removeSession, options) {
|
|
|
30852
30899
|
});
|
|
30853
30900
|
} catch (storeError) {
|
|
30854
30901
|
let removed = false;
|
|
30855
|
-
let timer;
|
|
30856
30902
|
try {
|
|
30857
|
-
await
|
|
30858
|
-
removeSession({ sessionID: created.id }),
|
|
30859
|
-
new Promise((_, reject) => {
|
|
30860
|
-
timer = setTimeout(() => reject(new Error("session.remove timed out")), options.removalTimeoutMs ?? 5000);
|
|
30861
|
-
})
|
|
30862
|
-
]);
|
|
30903
|
+
await removeBounded(created.id);
|
|
30863
30904
|
removed = true;
|
|
30864
30905
|
} catch (error) {
|
|
30865
30906
|
removed = isSessionNotFound(error);
|
|
30866
30907
|
} finally {
|
|
30867
|
-
if (timer)
|
|
30868
|
-
clearTimeout(timer);
|
|
30869
30908
|
liveChildren.delete(created.id);
|
|
30870
30909
|
}
|
|
30871
30910
|
options.log(`[magic-context] hidden child ${created.id} record failed; removed=${removed}: ${errorText(storeError)}`);
|
|
@@ -30893,6 +30932,9 @@ function createNativeHiddenChildren(host, removeSession, options) {
|
|
|
30893
30932
|
return {
|
|
30894
30933
|
open: create,
|
|
30895
30934
|
create,
|
|
30935
|
+
retireLate(child, cleanupMs) {
|
|
30936
|
+
retireLate(child.id, child.directory ?? "", child.created_at, cleanupMs);
|
|
30937
|
+
},
|
|
30896
30938
|
retire(child) {
|
|
30897
30939
|
if (kept(child)) {
|
|
30898
30940
|
liveChildren.delete(child.id);
|
|
@@ -31096,17 +31138,83 @@ function subagentTemperature(model, metadata, temperature, log) {
|
|
|
31096
31138
|
|
|
31097
31139
|
// src/v2/hidden-completion.ts
|
|
31098
31140
|
var DEFAULT_DISPOSE_DRAIN_MS = 2000;
|
|
31141
|
+
|
|
31142
|
+
class HiddenWorkTimeout extends Error {
|
|
31143
|
+
constructor(timeoutMs) {
|
|
31144
|
+
super(`prompt timed out after ${timeoutMs}ms`);
|
|
31145
|
+
}
|
|
31146
|
+
}
|
|
31147
|
+
|
|
31148
|
+
class HiddenSetupTimeout extends HiddenCompletionRefusal {
|
|
31149
|
+
constructor(stage) {
|
|
31150
|
+
super("hidden_setup_timeout", `Hidden completion setup timed out while ${stage}`, true);
|
|
31151
|
+
}
|
|
31152
|
+
}
|
|
31153
|
+
|
|
31154
|
+
class HiddenWorkAborted extends Error {
|
|
31155
|
+
constructor() {
|
|
31156
|
+
super("Hidden completion prompt aborted");
|
|
31157
|
+
}
|
|
31158
|
+
}
|
|
31159
|
+
function setupBudget(deadline, timeout, signal) {
|
|
31160
|
+
let stage = "preparing the attempt";
|
|
31161
|
+
let lost;
|
|
31162
|
+
const check = () => {
|
|
31163
|
+
if (lost)
|
|
31164
|
+
throw lost;
|
|
31165
|
+
if (Date.now() >= deadline)
|
|
31166
|
+
throw lost = timeout(stage);
|
|
31167
|
+
if (signal?.aborted)
|
|
31168
|
+
throw lost = new HiddenWorkAborted;
|
|
31169
|
+
};
|
|
31170
|
+
return {
|
|
31171
|
+
check,
|
|
31172
|
+
setStage: (value) => {
|
|
31173
|
+
stage = value;
|
|
31174
|
+
},
|
|
31175
|
+
get stage() {
|
|
31176
|
+
return stage;
|
|
31177
|
+
},
|
|
31178
|
+
cleanupMs: DEFAULT_DISPOSE_DRAIN_MS,
|
|
31179
|
+
async work(start, onLate) {
|
|
31180
|
+
check();
|
|
31181
|
+
let timer;
|
|
31182
|
+
let abort;
|
|
31183
|
+
try {
|
|
31184
|
+
return await Promise.race([
|
|
31185
|
+
start().then((result) => {
|
|
31186
|
+
try {
|
|
31187
|
+
check();
|
|
31188
|
+
} catch (error) {
|
|
31189
|
+
onLate?.(result);
|
|
31190
|
+
throw error;
|
|
31191
|
+
}
|
|
31192
|
+
return result;
|
|
31193
|
+
}),
|
|
31194
|
+
new Promise((_, reject) => {
|
|
31195
|
+
timer = setTimeout(() => reject(lost ??= timeout(stage)), Math.max(0, deadline - Date.now()));
|
|
31196
|
+
abort = () => reject(lost ??= new HiddenWorkAborted);
|
|
31197
|
+
if (signal?.aborted)
|
|
31198
|
+
abort();
|
|
31199
|
+
else
|
|
31200
|
+
signal?.addEventListener("abort", abort, { once: true });
|
|
31201
|
+
})
|
|
31202
|
+
]);
|
|
31203
|
+
} finally {
|
|
31204
|
+
clearTimeout(timer);
|
|
31205
|
+
if (abort)
|
|
31206
|
+
signal?.removeEventListener("abort", abort);
|
|
31207
|
+
}
|
|
31208
|
+
}
|
|
31209
|
+
};
|
|
31210
|
+
}
|
|
31099
31211
|
async function settleWithin(work, ms) {
|
|
31100
31212
|
let timer;
|
|
31101
31213
|
try {
|
|
31102
|
-
await Promise.race([
|
|
31103
|
-
work.then(() =>
|
|
31104
|
-
return;
|
|
31105
|
-
}, () => {
|
|
31106
|
-
return;
|
|
31107
|
-
}),
|
|
31214
|
+
return await Promise.race([
|
|
31215
|
+
work.then(() => true, () => true),
|
|
31108
31216
|
new Promise((resolve) => {
|
|
31109
|
-
timer = setTimeout(resolve, Math.max(0, ms));
|
|
31217
|
+
timer = setTimeout(() => resolve(false), Math.max(0, ms));
|
|
31110
31218
|
})
|
|
31111
31219
|
]);
|
|
31112
31220
|
} finally {
|
|
@@ -31303,8 +31411,9 @@ function isProviderFailure(error) {
|
|
|
31303
31411
|
const type = error.type;
|
|
31304
31412
|
return typeof type === "string" && (type.startsWith("provider.") || type.toLowerCase().includes("provider"));
|
|
31305
31413
|
}
|
|
31306
|
-
async function awaitAssistantRow(openReader, readSessionError, localFailure, childID, afterSeq, deadline, signal) {
|
|
31414
|
+
async function awaitAssistantRow(openReader, readSessionError, localFailure, childID, afterSeq, deadline, signal, checkDeadline) {
|
|
31307
31415
|
for (;; ) {
|
|
31416
|
+
checkDeadline?.();
|
|
31308
31417
|
const refusedBefore = localFailure();
|
|
31309
31418
|
if (refusedBefore)
|
|
31310
31419
|
throw refusedBefore;
|
|
@@ -31360,9 +31469,6 @@ async function awaitAssistantRow(openReader, readSessionError, localFailure, chi
|
|
|
31360
31469
|
return { row: newAssistant };
|
|
31361
31470
|
}
|
|
31362
31471
|
}
|
|
31363
|
-
if (Date.now() >= deadline) {
|
|
31364
|
-
throw new Error("Hidden completion timed out waiting for a persisted assistant row");
|
|
31365
|
-
}
|
|
31366
31472
|
await sleepUntilPoll(signal, deadline);
|
|
31367
31473
|
}
|
|
31368
31474
|
}
|
|
@@ -31427,11 +31533,11 @@ async function createV2HiddenCompletionExecutor(host, options) {
|
|
|
31427
31533
|
};
|
|
31428
31534
|
};
|
|
31429
31535
|
const warnedVariants = new Set;
|
|
31430
|
-
const validateVariant = async (model) => {
|
|
31536
|
+
const validateVariant = async (model, work) => {
|
|
31431
31537
|
if (!model.variant || !options.modelCatalog)
|
|
31432
31538
|
return model;
|
|
31433
31539
|
try {
|
|
31434
|
-
const listed = await options.modelCatalog
|
|
31540
|
+
const listed = await work(options.modelCatalog);
|
|
31435
31541
|
const rows = Array.isArray(listed) ? listed : listed && typeof listed === "object" && Array.isArray(listed.data) ? listed.data : [];
|
|
31436
31542
|
const entry = rows.find((row) => row && typeof row === "object" && row.providerID === model.providerID && row.id === model.modelID);
|
|
31437
31543
|
if (!entry)
|
|
@@ -31444,18 +31550,21 @@ async function createV2HiddenCompletionExecutor(host, options) {
|
|
|
31444
31550
|
note(`[magic-context] ${recordHiddenVariantWarning(model.providerID, model.modelID, model.variant)}`);
|
|
31445
31551
|
}
|
|
31446
31552
|
return { providerID: model.providerID, modelID: model.modelID };
|
|
31447
|
-
} catch {
|
|
31553
|
+
} catch (error) {
|
|
31554
|
+
if (error instanceof HiddenSetupTimeout || error instanceof HiddenWorkAborted)
|
|
31555
|
+
throw error;
|
|
31448
31556
|
return model;
|
|
31449
31557
|
}
|
|
31450
31558
|
};
|
|
31451
|
-
const resolveHead = async (identity) => {
|
|
31559
|
+
const resolveHead = async (identity, work) => {
|
|
31452
31560
|
const configured = configuredHead(identity);
|
|
31453
31561
|
if (configured)
|
|
31454
|
-
return validateVariant(configured);
|
|
31455
|
-
|
|
31562
|
+
return validateVariant(configured, work);
|
|
31563
|
+
const parentSessionId = identity.parentSessionId;
|
|
31564
|
+
if (!parentSessionId) {
|
|
31456
31565
|
throw new HiddenCompletionRefusal("hidden_model_unsupported", "Hidden completion requires a configured model or an existing parent session model", true);
|
|
31457
31566
|
}
|
|
31458
|
-
const parent = await host.get({ sessionID:
|
|
31567
|
+
const parent = await work(() => host.get({ sessionID: parentSessionId }));
|
|
31459
31568
|
if (!parent.model) {
|
|
31460
31569
|
throw new HiddenCompletionRefusal("hidden_model_unsupported", "Hidden completion could not resolve the parent session model", true);
|
|
31461
31570
|
}
|
|
@@ -31465,17 +31574,18 @@ async function createV2HiddenCompletionExecutor(host, options) {
|
|
|
31465
31574
|
...parent.model.variant ? { variant: parent.model.variant } : {}
|
|
31466
31575
|
};
|
|
31467
31576
|
};
|
|
31468
|
-
const switchChildModel = async (run, requested) => {
|
|
31577
|
+
const switchChildModel = async (run, requested, setup) => {
|
|
31469
31578
|
if (sameModel(run.child.model, requested))
|
|
31470
31579
|
return;
|
|
31471
|
-
await host.switchModel({
|
|
31580
|
+
await setup.work(() => host.switchModel({
|
|
31472
31581
|
sessionID: run.child.id,
|
|
31473
31582
|
model: {
|
|
31474
31583
|
providerID: requested.providerID,
|
|
31475
31584
|
id: requested.modelID,
|
|
31476
31585
|
...requested.variant ? { variant: requested.variant } : {}
|
|
31477
31586
|
}
|
|
31478
|
-
});
|
|
31587
|
+
}));
|
|
31588
|
+
setup.check();
|
|
31479
31589
|
run.child = lifecycle.updateModel(run.child, requested);
|
|
31480
31590
|
};
|
|
31481
31591
|
const partialCompletion = (run) => {
|
|
@@ -31507,30 +31617,63 @@ async function createV2HiddenCompletionExecutor(host, options) {
|
|
|
31507
31617
|
lifecycle.retire(run.child, reason);
|
|
31508
31618
|
run.retired = true;
|
|
31509
31619
|
};
|
|
31510
|
-
const interruptAndRetire =
|
|
31511
|
-
|
|
31512
|
-
|
|
31513
|
-
|
|
31514
|
-
|
|
31515
|
-
|
|
31620
|
+
const interruptAndRetire = (run, reason) => {
|
|
31621
|
+
if (run.retired)
|
|
31622
|
+
return run.retirement ?? Promise.resolve();
|
|
31623
|
+
return run.retirement ??= (async () => {
|
|
31624
|
+
const id = run.child.id;
|
|
31625
|
+
const warn = (error) => {
|
|
31626
|
+
const kind = error instanceof Error ? error.constructor.name : typeof error;
|
|
31627
|
+
const message = `[magic-context] hidden child ${id} could not be interrupted (${kind})`;
|
|
31628
|
+
if (options.log)
|
|
31629
|
+
options.log(message);
|
|
31630
|
+
else
|
|
31631
|
+
log2(message);
|
|
31632
|
+
};
|
|
31633
|
+
try {
|
|
31634
|
+
await settleWithin(host.interrupt({ sessionID: id }).catch(warn), DEFAULT_DISPOSE_DRAIN_MS);
|
|
31635
|
+
} catch (error) {
|
|
31636
|
+
warn(error);
|
|
31637
|
+
} finally {
|
|
31638
|
+
retire(run, reason);
|
|
31639
|
+
}
|
|
31640
|
+
})();
|
|
31516
31641
|
};
|
|
31517
31642
|
return {
|
|
31518
31643
|
capabilities: V2_HIDDEN_EXECUTOR_CAPABILITIES,
|
|
31519
31644
|
async open(identity) {
|
|
31520
31645
|
if (disposed)
|
|
31521
31646
|
throw disposed;
|
|
31647
|
+
const roleWait = setupBudget(Date.now() + identity.timeoutMs, (stage) => new HiddenSetupTimeout(stage));
|
|
31648
|
+
roleWait.setStage("waiting for its role");
|
|
31522
31649
|
const role = roleFor(identity);
|
|
31523
31650
|
const releaseStore = options.holdStore?.() ?? (() => {});
|
|
31524
31651
|
let releaseRole;
|
|
31525
31652
|
let openedChild;
|
|
31526
31653
|
let opened;
|
|
31527
31654
|
try {
|
|
31528
|
-
releaseRole = await acquireRole(role);
|
|
31655
|
+
releaseRole = await roleWait.work(() => acquireRole(role), (release) => release());
|
|
31529
31656
|
if (disposed)
|
|
31530
31657
|
throw disposed;
|
|
31531
|
-
|
|
31532
|
-
const
|
|
31533
|
-
const
|
|
31658
|
+
const deadline = Date.now() + identity.timeoutMs;
|
|
31659
|
+
const setup = setupBudget(deadline, (stage) => new HiddenSetupTimeout(stage));
|
|
31660
|
+
const work = setup.work;
|
|
31661
|
+
const ensureAgent = options.ensureAgent;
|
|
31662
|
+
if (ensureAgent) {
|
|
31663
|
+
setup.setStage("reloading the hidden agent");
|
|
31664
|
+
let pending;
|
|
31665
|
+
try {
|
|
31666
|
+
await work(() => pending = ensureAgent.call(options));
|
|
31667
|
+
} catch (error) {
|
|
31668
|
+
if (pending)
|
|
31669
|
+
options.forgetAgent?.(pending);
|
|
31670
|
+
throw error;
|
|
31671
|
+
}
|
|
31672
|
+
}
|
|
31673
|
+
setup.setStage("resolving the hidden model");
|
|
31674
|
+
const head = await resolveHead(identity, work);
|
|
31675
|
+
setup.setStage("creating the child session");
|
|
31676
|
+
const active = await work(() => lifecycle.open(identity, role, head, setup), (child) => lifecycle.retireLate(child, setup.cleanupMs));
|
|
31534
31677
|
openedChild = active;
|
|
31535
31678
|
const configuredModel = toModelEntry(identity.model);
|
|
31536
31679
|
const handle = {
|
|
@@ -31547,6 +31690,7 @@ async function createV2HiddenCompletionExecutor(host, options) {
|
|
|
31547
31690
|
child: active,
|
|
31548
31691
|
releaseRole,
|
|
31549
31692
|
releaseStore,
|
|
31693
|
+
firstDeadline: deadline,
|
|
31550
31694
|
failed: false,
|
|
31551
31695
|
unsettledFailure: false,
|
|
31552
31696
|
retired: false
|
|
@@ -31556,15 +31700,23 @@ async function createV2HiddenCompletionExecutor(host, options) {
|
|
|
31556
31700
|
openRuns.add(run);
|
|
31557
31701
|
if (disposed)
|
|
31558
31702
|
noteChildOfDisposedInstance(active.id);
|
|
31559
|
-
|
|
31703
|
+
setup.setStage("switching the child model");
|
|
31704
|
+
await switchChildModel(run, head, setup);
|
|
31705
|
+
setup.check();
|
|
31560
31706
|
return handle;
|
|
31561
31707
|
} catch (error) {
|
|
31562
|
-
|
|
31563
|
-
|
|
31564
|
-
|
|
31565
|
-
|
|
31566
|
-
|
|
31567
|
-
|
|
31708
|
+
try {
|
|
31709
|
+
if (openedChild) {
|
|
31710
|
+
if (error instanceof HiddenSetupTimeout)
|
|
31711
|
+
noteTimedOutHiddenChild(openedChild.id);
|
|
31712
|
+
lifecycle.retire(openedChild, "hidden-run-open-failed");
|
|
31713
|
+
}
|
|
31714
|
+
} finally {
|
|
31715
|
+
if (opened)
|
|
31716
|
+
openRuns.delete(opened);
|
|
31717
|
+
releaseRole?.();
|
|
31718
|
+
releaseStore();
|
|
31719
|
+
}
|
|
31568
31720
|
throw error;
|
|
31569
31721
|
}
|
|
31570
31722
|
},
|
|
@@ -31573,6 +31725,35 @@ async function createV2HiddenCompletionExecutor(host, options) {
|
|
|
31573
31725
|
const run = runs.get(handle);
|
|
31574
31726
|
if (!run)
|
|
31575
31727
|
throw new Error("Unknown hidden completion run");
|
|
31728
|
+
const timeoutMs = run.identity.timeoutMs;
|
|
31729
|
+
const deadline = run.firstDeadline ?? startedAt + timeoutMs;
|
|
31730
|
+
run.firstDeadline = undefined;
|
|
31731
|
+
let dispatched = false;
|
|
31732
|
+
const setup = setupBudget(deadline, (stage) => dispatched ? new HiddenWorkTimeout(timeoutMs) : new HiddenSetupTimeout(stage), request.signal);
|
|
31733
|
+
const work = setup.work;
|
|
31734
|
+
const sharedBudget = promptTransportBudget(request.signal);
|
|
31735
|
+
const refuseSliver = () => {
|
|
31736
|
+
const now = Date.now();
|
|
31737
|
+
if (deadline - now < timeoutMs * 0.05 || sharedBudget && sharedBudget.deadline - now < sharedBudget.timeoutMs * 0.05)
|
|
31738
|
+
throw new HiddenSetupTimeout("preparing to send the prompt");
|
|
31739
|
+
};
|
|
31740
|
+
const retireFailedSetup = (error) => {
|
|
31741
|
+
if (error instanceof HiddenSetupTimeout) {
|
|
31742
|
+
run.deadlineExpired = true;
|
|
31743
|
+
noteTimedOutHiddenChild(run.child.id);
|
|
31744
|
+
}
|
|
31745
|
+
run.failed = true;
|
|
31746
|
+
run.unsettledFailure = true;
|
|
31747
|
+
if (!run.retirement)
|
|
31748
|
+
retire(run, "hidden-attempt-setup-cancelled");
|
|
31749
|
+
};
|
|
31750
|
+
const stopWithinWork = async (reason) => {
|
|
31751
|
+
const retirement = interruptAndRetire(run, reason);
|
|
31752
|
+
if (Date.now() < deadline)
|
|
31753
|
+
await settleWithin(retirement, deadline - Date.now());
|
|
31754
|
+
if (Date.now() >= deadline)
|
|
31755
|
+
run.deadlineExpired = true;
|
|
31756
|
+
};
|
|
31576
31757
|
const refuseDisposed = () => {
|
|
31577
31758
|
if (!disposed)
|
|
31578
31759
|
return;
|
|
@@ -31583,46 +31764,78 @@ async function createV2HiddenCompletionExecutor(host, options) {
|
|
|
31583
31764
|
};
|
|
31584
31765
|
refuseDisposed();
|
|
31585
31766
|
if (request.signal?.aborted) {
|
|
31586
|
-
await
|
|
31767
|
+
await stopWithinWork("aborted-before-prompt");
|
|
31587
31768
|
throw new Error("Hidden completion prompt aborted");
|
|
31588
31769
|
}
|
|
31589
|
-
|
|
31590
|
-
|
|
31591
|
-
|
|
31592
|
-
|
|
31593
|
-
|
|
31594
|
-
|
|
31595
|
-
|
|
31596
|
-
|
|
31597
|
-
|
|
31598
|
-
|
|
31599
|
-
|
|
31600
|
-
|
|
31601
|
-
|
|
31602
|
-
|
|
31603
|
-
|
|
31604
|
-
|
|
31605
|
-
|
|
31606
|
-
|
|
31607
|
-
|
|
31608
|
-
|
|
31609
|
-
|
|
31610
|
-
|
|
31611
|
-
|
|
31612
|
-
|
|
31613
|
-
|
|
31614
|
-
|
|
31615
|
-
|
|
31616
|
-
|
|
31617
|
-
|
|
31618
|
-
|
|
31619
|
-
|
|
31620
|
-
|
|
31621
|
-
|
|
31622
|
-
|
|
31623
|
-
|
|
31770
|
+
let requested;
|
|
31771
|
+
let requestedRef;
|
|
31772
|
+
notePromptSetupTimeout(request.signal, () => new HiddenSetupTimeout(setup.stage));
|
|
31773
|
+
try {
|
|
31774
|
+
const previousRetirement = run.retirement;
|
|
31775
|
+
setup.setStage("waiting for the previous child to retire");
|
|
31776
|
+
if (previousRetirement)
|
|
31777
|
+
await work(() => previousRetirement);
|
|
31778
|
+
setup.setStage("resolving the hidden model");
|
|
31779
|
+
requested = await validateVariant(requestModel(request, run.child.model), work);
|
|
31780
|
+
requestedRef = modelKey(requested);
|
|
31781
|
+
const configuredModel = [
|
|
31782
|
+
run.identity.model,
|
|
31783
|
+
...run.identity.configuredModels ?? []
|
|
31784
|
+
].map(toModelEntry).find((entry) => entry?.model === requestedRef);
|
|
31785
|
+
handle.attemptedModel = requestedRef;
|
|
31786
|
+
handle.modelConfigKey = configuredModel?.sourceConfigKey ?? handle.modelConfigKey;
|
|
31787
|
+
if (run.identity.kind !== "dreamer-task" && request.body.temperature === undefined) {
|
|
31788
|
+
const configured = options.historianTemperature?.();
|
|
31789
|
+
if (typeof configured === "number" && Number.isFinite(configured))
|
|
31790
|
+
request = {
|
|
31791
|
+
...request,
|
|
31792
|
+
body: { ...request.body, temperature: configured }
|
|
31793
|
+
};
|
|
31794
|
+
}
|
|
31795
|
+
if (typeof request.body.temperature === "number") {
|
|
31796
|
+
let metadata;
|
|
31797
|
+
try {
|
|
31798
|
+
const listed = options.modelCatalog ? await work(options.modelCatalog) : undefined;
|
|
31799
|
+
const rows = Array.isArray(listed) ? listed : listed?.data;
|
|
31800
|
+
metadata = rows?.find((row) => row?.providerID === requested.providerID && (row?.id === requested.modelID || row?.modelID === requested.modelID));
|
|
31801
|
+
} catch (error) {
|
|
31802
|
+
if (error instanceof HiddenSetupTimeout || error instanceof HiddenWorkAborted)
|
|
31803
|
+
throw error;
|
|
31804
|
+
}
|
|
31805
|
+
const temperature = subagentTemperature(modelKey(requested), metadata, request.body.temperature, (message) => note(message));
|
|
31806
|
+
const body = { ...request.body };
|
|
31807
|
+
if (temperature === undefined)
|
|
31808
|
+
delete body.temperature;
|
|
31809
|
+
else
|
|
31810
|
+
body.temperature = temperature;
|
|
31811
|
+
request = { ...request, body };
|
|
31812
|
+
}
|
|
31813
|
+
if (needsBlockedRead(run.identity.agent, run.child.model.providerID) !== needsBlockedRead(run.identity.agent, requested.providerID)) {
|
|
31814
|
+
retire(run, "hidden-run-tool-surface-changed");
|
|
31815
|
+
}
|
|
31816
|
+
if (run.retired) {
|
|
31817
|
+
setup.setStage("creating the replacement child session");
|
|
31818
|
+
run.child = await work(() => lifecycle.create(run.identity, run.role, requested, setup), (child) => lifecycle.retireLate(child, setup.cleanupMs));
|
|
31819
|
+
run.retirement = undefined;
|
|
31820
|
+
run.deadlineExpired = false;
|
|
31821
|
+
run.failed = false;
|
|
31822
|
+
run.unsettledFailure = false;
|
|
31823
|
+
run.retired = false;
|
|
31824
|
+
handle.id = run.child.id;
|
|
31825
|
+
handle.childSessionId = run.child.id;
|
|
31826
|
+
}
|
|
31827
|
+
setup.setStage("switching the child model");
|
|
31828
|
+
await switchChildModel(run, requested, setup);
|
|
31829
|
+
setup.check();
|
|
31830
|
+
setup.setStage("preparing to send the prompt");
|
|
31831
|
+
refuseSliver();
|
|
31832
|
+
} catch (error) {
|
|
31833
|
+
if (error instanceof HiddenSetupTimeout || error instanceof HiddenWorkAborted)
|
|
31834
|
+
retireFailedSetup(error);
|
|
31835
|
+
throw error;
|
|
31836
|
+
} finally {
|
|
31837
|
+
notePromptSetupTimeout(request.signal);
|
|
31624
31838
|
}
|
|
31625
|
-
await switchChildModel(run, requested);
|
|
31626
31839
|
refuseDisposed();
|
|
31627
31840
|
const baseline = withReader(options.openReader, (reader) => reader.latestSequence(run.child.id));
|
|
31628
31841
|
const marker = `mc:hidden:${crypto.randomUUID()}:${crypto.randomUUID()}`;
|
|
@@ -31637,7 +31850,6 @@ async function createV2HiddenCompletionExecutor(host, options) {
|
|
|
31637
31850
|
run.partialCompletion = undefined;
|
|
31638
31851
|
run.attempt = { child: attempt, baseline };
|
|
31639
31852
|
options.hook.registerAttempt(marker, attempt);
|
|
31640
|
-
const deadline = Date.now() + run.identity.timeoutMs;
|
|
31641
31853
|
lifecycle.extendDeadline(run.child, deadline);
|
|
31642
31854
|
const budget = run.budget;
|
|
31643
31855
|
if (budget?.snapshot().finalizeFired) {
|
|
@@ -31696,6 +31908,8 @@ async function createV2HiddenCompletionExecutor(host, options) {
|
|
|
31696
31908
|
});
|
|
31697
31909
|
const onAbort = () => {
|
|
31698
31910
|
const reason = request.signal?.reason;
|
|
31911
|
+
if (dispatched)
|
|
31912
|
+
noteTimedOutHiddenChild(run.child.id);
|
|
31699
31913
|
if (reason instanceof ModelProducedNoOutputError && run.identity.kind === "dreamer-task") {
|
|
31700
31914
|
recordChildInvocation({
|
|
31701
31915
|
db: options.db,
|
|
@@ -31713,9 +31927,6 @@ async function createV2HiddenCompletionExecutor(host, options) {
|
|
|
31713
31927
|
}
|
|
31714
31928
|
interruptAndRetire(run, "prompt-aborted").finally(() => abortReject(new Error("Hidden completion prompt aborted")));
|
|
31715
31929
|
};
|
|
31716
|
-
const deadlineTimer = setTimeout(() => {
|
|
31717
|
-
interruptAndRetire(run, "prompt-timeout").finally(() => abortReject(new Error("Hidden completion prompt timed out")));
|
|
31718
|
-
}, Math.max(0, deadline - Date.now()));
|
|
31719
31930
|
request.signal?.addEventListener("abort", onAbort, { once: true });
|
|
31720
31931
|
let settle;
|
|
31721
31932
|
const entry = {
|
|
@@ -31724,8 +31935,6 @@ async function createV2HiddenCompletionExecutor(host, options) {
|
|
|
31724
31935
|
noteChildOfDisposedInstance(run.child.id);
|
|
31725
31936
|
try {
|
|
31726
31937
|
await interruptAndRetire(run, "plugin-instance-disposed");
|
|
31727
|
-
} catch (error) {
|
|
31728
|
-
note(`[magic-context] hidden child ${run.child.id} could not be interrupted on dispose: ${errorText(error)}`);
|
|
31729
31938
|
} finally {
|
|
31730
31939
|
abortReject(refusal);
|
|
31731
31940
|
}
|
|
@@ -31744,28 +31953,32 @@ async function createV2HiddenCompletionExecutor(host, options) {
|
|
|
31744
31953
|
noteModelActivityMonitored(request.signal);
|
|
31745
31954
|
try {
|
|
31746
31955
|
await Promise.race([
|
|
31747
|
-
|
|
31956
|
+
work(() => {
|
|
31957
|
+
refuseSliver();
|
|
31958
|
+
dispatched = true;
|
|
31959
|
+
return host.prompt({ sessionID: run.child.id, text: marker });
|
|
31960
|
+
}),
|
|
31748
31961
|
aborted,
|
|
31749
31962
|
...budget ? [budgetStopped] : []
|
|
31750
31963
|
]);
|
|
31751
31964
|
await Promise.race([
|
|
31752
|
-
host.wait({ sessionID: run.child.id }),
|
|
31965
|
+
work(() => host.wait({ sessionID: run.child.id })),
|
|
31753
31966
|
aborted,
|
|
31754
31967
|
...budget ? [budgetStopped] : []
|
|
31755
31968
|
]);
|
|
31756
31969
|
const { row, outputLimit } = await Promise.race([
|
|
31757
|
-
awaitAssistantRow(options.openReader, async () => {
|
|
31970
|
+
work(() => awaitAssistantRow(options.openReader, async () => {
|
|
31758
31971
|
try {
|
|
31759
|
-
const
|
|
31760
|
-
|
|
31761
|
-
});
|
|
31972
|
+
const id = run.child.id;
|
|
31973
|
+
const terminalError = host.terminalError;
|
|
31974
|
+
const eventError = terminalError ? await work(() => terminalError.call(host, { sessionID: id })) : undefined;
|
|
31762
31975
|
if (eventError !== undefined)
|
|
31763
31976
|
return eventError;
|
|
31764
|
-
return (await host.get({ sessionID:
|
|
31977
|
+
return (await work(() => host.get({ sessionID: id }))).error;
|
|
31765
31978
|
} catch {
|
|
31766
31979
|
return;
|
|
31767
31980
|
}
|
|
31768
|
-
}, () => attempt.refusal ?? attempt.stepLimit, run.child.id, baseline, deadline, request.signal),
|
|
31981
|
+
}, () => attempt.refusal ?? attempt.stepLimit, run.child.id, baseline, deadline, request.signal, setup.check)),
|
|
31769
31982
|
aborted,
|
|
31770
31983
|
...budget ? [budgetStopped] : []
|
|
31771
31984
|
]);
|
|
@@ -31781,15 +31994,17 @@ async function createV2HiddenCompletionExecutor(host, options) {
|
|
|
31781
31994
|
const steps = attemptRows.filter((step) => step.type === "assistant" && step.seq > baseline && step.seq <= row.seq);
|
|
31782
31995
|
const exceeded = chargeBudgetRows(steps);
|
|
31783
31996
|
if (exceeded) {
|
|
31784
|
-
await
|
|
31997
|
+
await stopWithinWork("token-budget");
|
|
31785
31998
|
throw exceeded;
|
|
31786
31999
|
}
|
|
31787
32000
|
const cappedChainStart = outputLimit ? outputLimitChainStart(attemptRows, row.seq) : row.seq;
|
|
31788
32001
|
const usageRows = cappedChainStart < row.seq ? steps.filter((step) => step.seq < cappedChainStart || step.seq === row.seq) : steps;
|
|
31789
32002
|
const reportedUsage = usageRows.some((step) => tokenNumber(step.data.tokens?.input) !== undefined || tokenNumber(step.data.tokens?.output) !== undefined);
|
|
31790
32003
|
const usage = sumRowUsage(usageRows);
|
|
31791
|
-
if (
|
|
31792
|
-
|
|
32004
|
+
if (Date.now() >= deadline)
|
|
32005
|
+
throw new HiddenWorkTimeout(timeoutMs);
|
|
32006
|
+
if (request.signal?.aborted || run.retired) {
|
|
32007
|
+
await stopWithinWork("prompt-aborted-or-timeout");
|
|
31793
32008
|
throw new Error(request.signal?.aborted ? "Hidden completion prompt aborted" : "Hidden completion prompt timed out");
|
|
31794
32009
|
}
|
|
31795
32010
|
run.completion = {
|
|
@@ -31818,17 +32033,25 @@ async function createV2HiddenCompletionExecutor(host, options) {
|
|
|
31818
32033
|
if (!(error instanceof HiddenProviderError)) {
|
|
31819
32034
|
run.unsettledFailure = true;
|
|
31820
32035
|
}
|
|
31821
|
-
|
|
31822
|
-
|
|
31823
|
-
|
|
31824
|
-
|
|
32036
|
+
const dispatchedTimeout = dispatched && isPromptTimeoutError(error);
|
|
32037
|
+
if (error instanceof HiddenSetupTimeout) {
|
|
32038
|
+
retireFailedSetup(error);
|
|
32039
|
+
} else if (dispatched && (caught instanceof HiddenWorkTimeout || Date.now() >= deadline)) {
|
|
32040
|
+
run.deadlineExpired = true;
|
|
32041
|
+
noteTimedOutHiddenChild(run.child.id);
|
|
32042
|
+
interruptAndRetire(run, "prompt-timeout");
|
|
32043
|
+
} else if (request.signal?.aborted && !run.retired) {
|
|
32044
|
+
await stopWithinWork("prompt-aborted");
|
|
32045
|
+
} else if (!run.retired && (dispatchedTimeout || error instanceof Error && error.message.includes("timed out"))) {
|
|
32046
|
+
if (dispatchedTimeout)
|
|
32047
|
+
noteTimedOutHiddenChild(run.child.id);
|
|
32048
|
+
await stopWithinWork("prompt-timeout");
|
|
31825
32049
|
} else if ((error instanceof HiddenAgentStepLimit || error instanceof HiddenProviderError && error.settled) && !run.retired) {
|
|
31826
|
-
await
|
|
32050
|
+
await stopWithinWork(error instanceof HiddenAgentStepLimit ? "hidden-run-step-limit" : "hidden-run-provider-error");
|
|
31827
32051
|
}
|
|
31828
32052
|
throw error;
|
|
31829
32053
|
} finally {
|
|
31830
32054
|
stopWatching?.();
|
|
31831
|
-
clearTimeout(deadlineTimer);
|
|
31832
32055
|
if (budgetPoll)
|
|
31833
32056
|
clearInterval(budgetPoll);
|
|
31834
32057
|
request.signal?.removeEventListener("abort", onAbort);
|
|
@@ -31855,7 +32078,18 @@ async function createV2HiddenCompletionExecutor(host, options) {
|
|
|
31855
32078
|
const run = runs.get(handle);
|
|
31856
32079
|
if (!run)
|
|
31857
32080
|
return;
|
|
32081
|
+
if (run.retirement && (!run.retired || run.deadlineExpired)) {
|
|
32082
|
+
runs.delete(handle);
|
|
32083
|
+
run.retirement.finally(() => {
|
|
32084
|
+
openRuns.delete(run);
|
|
32085
|
+
run.releaseRole();
|
|
32086
|
+
run.releaseStore();
|
|
32087
|
+
});
|
|
32088
|
+
return;
|
|
32089
|
+
}
|
|
31858
32090
|
try {
|
|
32091
|
+
if (run.retirement)
|
|
32092
|
+
await run.retirement;
|
|
31859
32093
|
const reusable = !run.retired && run.failed && !run.unsettledFailure;
|
|
31860
32094
|
if (hiddenToolLoop(run.identity)) {
|
|
31861
32095
|
retire(run, settlement.promptSettled ? "tool-loop-settled" : "tool-loop-failed");
|
|
@@ -31868,7 +32102,9 @@ async function createV2HiddenCompletionExecutor(host, options) {
|
|
|
31868
32102
|
run.releaseRole();
|
|
31869
32103
|
run.releaseStore();
|
|
31870
32104
|
}
|
|
31871
|
-
|
|
32105
|
+
const finished = lifecycle.finish(run.child, run.retired);
|
|
32106
|
+
if (!run.deadlineExpired)
|
|
32107
|
+
await finished;
|
|
31872
32108
|
},
|
|
31873
32109
|
async dispose() {
|
|
31874
32110
|
disposed ??= new HiddenCompletionRefusal("hidden_instance_disposed", HIDDEN_RUN_DISPOSED_REASON, true);
|
|
@@ -37265,18 +37501,15 @@ ${prePost || "(none)"}
|
|
|
37265
37501
|
Return valid JSON only, no markdown fencing:
|
|
37266
37502
|
{ "answer": "..." }`;
|
|
37267
37503
|
}
|
|
37268
|
-
function
|
|
37504
|
+
function hasInvestigationEvidence(messages) {
|
|
37269
37505
|
if (!Array.isArray(messages))
|
|
37270
|
-
return
|
|
37271
|
-
|
|
37272
|
-
for (const message of messages) {
|
|
37506
|
+
return false;
|
|
37507
|
+
return messages.some((message) => {
|
|
37273
37508
|
if (message === null || typeof message !== "object")
|
|
37274
|
-
|
|
37509
|
+
return false;
|
|
37275
37510
|
const parts = message.parts;
|
|
37276
|
-
|
|
37277
|
-
|
|
37278
|
-
}
|
|
37279
|
-
return count;
|
|
37511
|
+
return Array.isArray(parts) && hasCompletedToolCall(parts);
|
|
37512
|
+
});
|
|
37280
37513
|
}
|
|
37281
37514
|
function parseAnswer(messages, fallback) {
|
|
37282
37515
|
const text = extractLatestAssistantText(messages);
|
|
@@ -37370,7 +37603,7 @@ async function refreshOnePrimer(args, primer, sliceMs, signal) {
|
|
|
37370
37603
|
messages: run.completion.messages ?? []
|
|
37371
37604
|
});
|
|
37372
37605
|
const answer = run.validated.trim();
|
|
37373
|
-
if (!answer ||
|
|
37606
|
+
if (!answer || !hasInvestigationEvidence(run.completion.messages ?? []))
|
|
37374
37607
|
return false;
|
|
37375
37608
|
runLeaseGuardedWrite(args.db, args.holderId, args.leaseKey, () => {
|
|
37376
37609
|
updatePrimerAnswer(args.db, primer.id, answer);
|
|
@@ -37430,8 +37663,8 @@ async function refreshOnePrimer(args, primer, sliceMs, signal) {
|
|
|
37430
37663
|
const answer = run.validated.trim();
|
|
37431
37664
|
if (!answer)
|
|
37432
37665
|
return false;
|
|
37433
|
-
if (
|
|
37434
|
-
log2(`[dreamer] refresh-primers: primer #${primer.id} answer not committed (no investigation tool
|
|
37666
|
+
if (!hasInvestigationEvidence(run.output)) {
|
|
37667
|
+
log2(`[dreamer] refresh-primers: primer #${primer.id} answer not committed (no successful investigation tool results)`);
|
|
37435
37668
|
return false;
|
|
37436
37669
|
}
|
|
37437
37670
|
runLeaseGuardedWrite(args.db, args.holderId, args.leaseKey, () => {
|
|
@@ -40895,8 +41128,9 @@ async function runDomainGroup(deps, group, cb) {
|
|
|
40895
41128
|
log2(`[dreamer] domain lease busy (${leaseKey}) — deferring ${group.length} task(s)`);
|
|
40896
41129
|
for (const due of group)
|
|
40897
41130
|
cb?.onBusy?.(due.config.task);
|
|
40898
|
-
return;
|
|
41131
|
+
return 0;
|
|
40899
41132
|
}
|
|
41133
|
+
let staleSlots = 0;
|
|
40900
41134
|
try {
|
|
40901
41135
|
for (const due of [...group].sort((a, b) => compareTaskOrder(a.config.task, b.config.task))) {
|
|
40902
41136
|
if (!reacquireOwnedLease(db, holderId, leaseKey, acquisition.generation)) {
|
|
@@ -40904,6 +41138,11 @@ async function runDomainGroup(deps, group, cb) {
|
|
|
40904
41138
|
break;
|
|
40905
41139
|
}
|
|
40906
41140
|
acquisition = { acquiredAt: Date.now(), generation: acquisition.generation };
|
|
41141
|
+
if (!cb?.ignoreSchedule && getTaskScheduleState(db, projectIdentity, due.config.task)?.nextDueAt !== due.scheduledAt) {
|
|
41142
|
+
log2(`[dreamer] ${due.config.task} slot changed (${leaseKey}) — not running`);
|
|
41143
|
+
staleSlots += 1;
|
|
41144
|
+
continue;
|
|
41145
|
+
}
|
|
40907
41146
|
if (!cb?.forceGate) {
|
|
40908
41147
|
const gatePass = evaluateTaskGate(due.config.task, {
|
|
40909
41148
|
db,
|
|
@@ -40959,6 +41198,7 @@ async function runDomainGroup(deps, group, cb) {
|
|
|
40959
41198
|
} finally {
|
|
40960
41199
|
releaseLease(db, holderId, leaseKey);
|
|
40961
41200
|
}
|
|
41201
|
+
return staleSlots;
|
|
40962
41202
|
}
|
|
40963
41203
|
async function runManualDream(deps) {
|
|
40964
41204
|
const now = Date.now();
|
|
@@ -41025,6 +41265,7 @@ async function runManualDream(deps) {
|
|
|
41025
41265
|
groups.set(kind, arr);
|
|
41026
41266
|
}
|
|
41027
41267
|
await Promise.all([...groups.values()].map((group) => runDomainGroup({ ...deps, executor: deps.executor }, group, {
|
|
41268
|
+
ignoreSchedule: true,
|
|
41028
41269
|
forceGate,
|
|
41029
41270
|
leaseWaitMs: MANUAL_RUN_LEASE_WAIT_MS,
|
|
41030
41271
|
onRan: (t, detail, backlog) => {
|
|
@@ -41082,8 +41323,8 @@ async function runDueTasksForProject(deps) {
|
|
|
41082
41323
|
arr.push(d);
|
|
41083
41324
|
groups.set(kind, arr);
|
|
41084
41325
|
}
|
|
41085
|
-
await Promise.all([...groups.values()].map((group) => runDomainGroup(deps, group)));
|
|
41086
|
-
return gated.length;
|
|
41326
|
+
const staleSlots = await Promise.all([...groups.values()].map((group) => runDomainGroup(deps, group)));
|
|
41327
|
+
return gated.length - staleSlots.reduce((total, count) => total + count, 0);
|
|
41087
41328
|
}
|
|
41088
41329
|
|
|
41089
41330
|
// src/v2/retrospective-raw-provider.ts
|
|
@@ -57444,9 +57685,23 @@ function servableCarrier(stored, head) {
|
|
|
57444
57685
|
}
|
|
57445
57686
|
function bindKeptInstructionCoordinates(messages, incoming, reader, sessionID) {
|
|
57446
57687
|
const rows = reader.instructionRowsThrough(sessionID, reader.latestSequence(sessionID));
|
|
57688
|
+
const visible = (message) => message !== incoming && !effortPart(message);
|
|
57689
|
+
const ids = new Set;
|
|
57690
|
+
for (const message of messages) {
|
|
57691
|
+
if (!visible(message))
|
|
57692
|
+
continue;
|
|
57693
|
+
const id = nativeRowID(message);
|
|
57694
|
+
if (id)
|
|
57695
|
+
ids.add(id);
|
|
57696
|
+
}
|
|
57697
|
+
const sequences = reader.sequencesForIds(sessionID, [...ids]);
|
|
57447
57698
|
let previous;
|
|
57448
57699
|
let pending = [];
|
|
57449
57700
|
const matches = (message, row) => message?.role === "system" && message.content.length === 1 && message.content[0]?.type === "text" && message.content[0].text === row?.data.text;
|
|
57701
|
+
const bindRow = (message, row) => {
|
|
57702
|
+
bindNativeRowID(message, row.id, row.seq);
|
|
57703
|
+
sequences.set(row.id, row.seq);
|
|
57704
|
+
};
|
|
57450
57705
|
const bind = (next) => {
|
|
57451
57706
|
if (!pending.length)
|
|
57452
57707
|
return;
|
|
@@ -57456,7 +57711,7 @@ function bindKeptInstructionCoordinates(messages, incoming, reader, sessionID) {
|
|
|
57456
57711
|
selected.forEach((row, index) => {
|
|
57457
57712
|
const message = pending[index];
|
|
57458
57713
|
if (message)
|
|
57459
|
-
|
|
57714
|
+
bindRow(message, row);
|
|
57460
57715
|
});
|
|
57461
57716
|
} else {
|
|
57462
57717
|
const earliest = [];
|
|
@@ -57477,16 +57732,16 @@ function bindKeptInstructionCoordinates(messages, incoming, reader, sessionID) {
|
|
|
57477
57732
|
pending.forEach((message, index) => {
|
|
57478
57733
|
const row = candidates[earliest[index]];
|
|
57479
57734
|
if (row && earliest[index] === latest[index])
|
|
57480
|
-
|
|
57735
|
+
bindRow(message, row);
|
|
57481
57736
|
});
|
|
57482
57737
|
}
|
|
57483
57738
|
pending = [];
|
|
57484
57739
|
};
|
|
57485
57740
|
for (const message of messages) {
|
|
57486
|
-
if (
|
|
57741
|
+
if (!visible(message))
|
|
57487
57742
|
continue;
|
|
57488
57743
|
const id = nativeRowID(message);
|
|
57489
|
-
const seq = id ?
|
|
57744
|
+
const seq = id ? sequences.get(id) : undefined;
|
|
57490
57745
|
if (seq !== undefined) {
|
|
57491
57746
|
bind(seq);
|
|
57492
57747
|
previous = seq;
|
|
@@ -57835,9 +58090,31 @@ function coveredInstructionRows(reader, sessionID, throughSeq, model, retired =
|
|
|
57835
58090
|
return [];
|
|
57836
58091
|
return reader.instructionRowsThrough(sessionID, throughSeq).filter((row) => !retired(row)).flatMap((row) => restoreRow(row, model)).map((message) => markCoveredInstructionRow(message));
|
|
57837
58092
|
}
|
|
58093
|
+
var contextDisposalOrder = [
|
|
58094
|
+
"sweep",
|
|
58095
|
+
"backfill",
|
|
58096
|
+
"idle",
|
|
58097
|
+
"abortUsage",
|
|
58098
|
+
"hidden",
|
|
58099
|
+
"joinUsage",
|
|
58100
|
+
"rpc",
|
|
58101
|
+
"transform",
|
|
58102
|
+
"tools",
|
|
58103
|
+
"deletedSessions",
|
|
58104
|
+
"dream",
|
|
58105
|
+
"maintenance",
|
|
58106
|
+
"embeddings",
|
|
58107
|
+
"rawProviders",
|
|
58108
|
+
"restoredRows",
|
|
58109
|
+
"readerPool",
|
|
58110
|
+
"synthetic"
|
|
58111
|
+
];
|
|
57838
58112
|
async function registerContext(context) {
|
|
57839
58113
|
const directory = context.location.directory;
|
|
57840
58114
|
const config = loadPluginConfigDetailed(directory).config;
|
|
58115
|
+
for (const warning of new Set(config.configWarnings)) {
|
|
58116
|
+
log2(`[magic-context] config warning: ${warning}`);
|
|
58117
|
+
}
|
|
57841
58118
|
log2(`[magic-context] OpenCode 2 keep_subagents=${config.keep_subagents === true}`);
|
|
57842
58119
|
setHomeProjectPermission(config.allow_home_project);
|
|
57843
58120
|
if (!config.enabled)
|
|
@@ -57863,7 +58140,6 @@ async function registerContext(context) {
|
|
|
57863
58140
|
});
|
|
57864
58141
|
return;
|
|
57865
58142
|
}
|
|
57866
|
-
const liveConfigReader = pluginConfigReader(directory, config);
|
|
57867
58143
|
const compactionOff = !isCompactionEnabled(config);
|
|
57868
58144
|
const conflicts = detectConflicts(directory, {
|
|
57869
58145
|
compactionEnabled: !compactionOff,
|
|
@@ -57873,7 +58149,32 @@ async function registerContext(context) {
|
|
|
57873
58149
|
console.warn(`[magic-context] v2 setup disabled by conflicting context hooks: ${conflicts.reasons.join("; ")}`);
|
|
57874
58150
|
return;
|
|
57875
58151
|
}
|
|
58152
|
+
const cleanup = {};
|
|
58153
|
+
const dispose = async (failedSetup = false) => {
|
|
58154
|
+
for (const resource of contextDisposalOrder) {
|
|
58155
|
+
try {
|
|
58156
|
+
const drain = cleanup[resource]?.(failedSetup);
|
|
58157
|
+
if (drain)
|
|
58158
|
+
await drain;
|
|
58159
|
+
} catch (error) {
|
|
58160
|
+
const kind = error instanceof Error ? error.constructor.name : typeof error;
|
|
58161
|
+
log2(`[magic-context] v2 ${resource} cleanup failed (${kind})`);
|
|
58162
|
+
}
|
|
58163
|
+
}
|
|
58164
|
+
};
|
|
58165
|
+
try {
|
|
58166
|
+
await setupContext(context, config, nativeRemove, compactionOff, cleanup);
|
|
58167
|
+
} catch (error) {
|
|
58168
|
+
await dispose(true);
|
|
58169
|
+
throw error;
|
|
58170
|
+
}
|
|
58171
|
+
return { dispose: () => dispose() };
|
|
58172
|
+
}
|
|
58173
|
+
async function setupContext(context, config, nativeRemove, compactionOff, cleanup) {
|
|
58174
|
+
const directory = context.location.directory;
|
|
58175
|
+
const liveConfigReader = pluginConfigReader(directory, config);
|
|
57876
58176
|
const embeddings = createV2EmbeddingScope(resolveProjectIdentityForSession(directory, config.allow_home_project));
|
|
58177
|
+
cleanup.embeddings = () => embeddings.dispose();
|
|
57877
58178
|
const folds = new FoldOwner(context.storage);
|
|
57878
58179
|
const nativeFoldMemory = compactionOff ? undefined : nativeFoldCache(() => storage.require());
|
|
57879
58180
|
const loggedUncoveredCheckpoints = new BoundedSessionMap(1000);
|
|
@@ -57941,6 +58242,11 @@ async function registerContext(context) {
|
|
|
57941
58242
|
isLive: isLiveHiddenChild
|
|
57942
58243
|
});
|
|
57943
58244
|
let hiddenChildSweepTimer;
|
|
58245
|
+
cleanup.sweep = () => {
|
|
58246
|
+
if (hiddenChildSweepTimer)
|
|
58247
|
+
clearInterval(hiddenChildSweepTimer);
|
|
58248
|
+
return hiddenChildSweep.dispose();
|
|
58249
|
+
};
|
|
57944
58250
|
const sweepChildren = (database) => {
|
|
57945
58251
|
hiddenChildSweep.start(database);
|
|
57946
58252
|
};
|
|
@@ -58006,6 +58312,8 @@ async function registerContext(context) {
|
|
|
58006
58312
|
});
|
|
58007
58313
|
});
|
|
58008
58314
|
const tools = db && isDatabasePersisted(db) ? await registerTools(context, db, config, moduleToolBackends?.backends, (id) => hiddenChildHook.owns(id), embeddings.ensureRegistered) : undefined;
|
|
58315
|
+
if (tools)
|
|
58316
|
+
cleanup.tools = () => tools.dispose();
|
|
58009
58317
|
const generateReplay = new V2GenerateReplay;
|
|
58010
58318
|
await context.session.hook("http.response", async (draft) => {
|
|
58011
58319
|
if (!db || draft.kind !== "primary" || draft.response.ok)
|
|
@@ -58029,6 +58337,11 @@ async function registerContext(context) {
|
|
|
58029
58337
|
});
|
|
58030
58338
|
let hiddenAgentsReady;
|
|
58031
58339
|
const readerPool = new V2StoreReaderPool2;
|
|
58340
|
+
cleanup.readerPool = async () => {
|
|
58341
|
+
if (!await readerPool.closeWhenIdle(STORE_POOL_DISPOSE_WAIT_MS))
|
|
58342
|
+
log2(`[magic-context] v2 store reader pool still held by ${readerPool.holdCount()} hidden run(s) at dispose; it closes when they finish`);
|
|
58343
|
+
};
|
|
58344
|
+
cleanup.synthetic = () => clearSyntheticCandidates(context);
|
|
58032
58345
|
const messageTimesCache = new V2MessageTimesCache;
|
|
58033
58346
|
const openStoreReader = () => readerPool.open(gaDatabasePath2(getDataDir(), process.env.OPENCODE_CHANNEL ?? "latest"));
|
|
58034
58347
|
const revertMessageCleanup = new V2RevertMessageCleanup(openStoreReader);
|
|
@@ -58099,6 +58412,10 @@ async function registerContext(context) {
|
|
|
58099
58412
|
hostVersion: context.app?.version,
|
|
58100
58413
|
keepSubagents: config.keep_subagents === true,
|
|
58101
58414
|
ensureAgent: () => hiddenAgentsReady ??= context.agent.reload(),
|
|
58415
|
+
forgetAgent: (pending) => {
|
|
58416
|
+
if (hiddenAgentsReady === pending)
|
|
58417
|
+
hiddenAgentsReady = undefined;
|
|
58418
|
+
},
|
|
58102
58419
|
modelCatalog: () => Promise.resolve(context.model.list()),
|
|
58103
58420
|
historianTemperature: () => config.historian?.temperature,
|
|
58104
58421
|
openReader: openStoreReader,
|
|
@@ -58132,9 +58449,12 @@ async function registerContext(context) {
|
|
|
58132
58449
|
return trigger;
|
|
58133
58450
|
};
|
|
58134
58451
|
let hiddenCompletionExecutor = db && isDatabasePersisted(db) && resolveProjectIdentityForSession(directory, config.allow_home_project) ? await createHiddenExecutor(db) : undefined;
|
|
58452
|
+
cleanup.hidden = () => hiddenCompletionExecutor?.dispose();
|
|
58135
58453
|
let dreamTrigger = hiddenCompletionExecutor ? startDreamer(hiddenCompletionExecutor) : undefined;
|
|
58454
|
+
cleanup.dream = () => dreamTrigger?.dispose();
|
|
58136
58455
|
const lateHiddenExecutor = createLateHiddenExecutor(() => hiddenCompletionExecutor);
|
|
58137
58456
|
let maintenanceTimer;
|
|
58457
|
+
cleanup.maintenance = () => maintenanceTimer?.dispose();
|
|
58138
58458
|
const startMaintenance = () => {
|
|
58139
58459
|
const timerProjectIdentity = resolveProjectIdentityForSession(directory, config.allow_home_project);
|
|
58140
58460
|
if (!timerProjectIdentity || maintenanceTimer)
|
|
@@ -58195,6 +58515,12 @@ async function registerContext(context) {
|
|
|
58195
58515
|
const commitSeenLastPass = new Map;
|
|
58196
58516
|
const restoredRows = new RestoredRowCache;
|
|
58197
58517
|
const rawProviders = new Map;
|
|
58518
|
+
cleanup.restoredRows = () => restoredRows.clear();
|
|
58519
|
+
cleanup.rawProviders = () => {
|
|
58520
|
+
for (const release of rawProviders.values())
|
|
58521
|
+
release();
|
|
58522
|
+
rawProviders.clear();
|
|
58523
|
+
};
|
|
58198
58524
|
let passDuties;
|
|
58199
58525
|
let toolDuties;
|
|
58200
58526
|
const droppedInputGuard = createDroppedInputGuard();
|
|
@@ -58233,8 +58559,9 @@ async function registerContext(context) {
|
|
|
58233
58559
|
};
|
|
58234
58560
|
if (db && isDatabasePersisted(db)) {
|
|
58235
58561
|
const backfillDb = db;
|
|
58236
|
-
|
|
58237
|
-
|
|
58562
|
+
let running;
|
|
58563
|
+
const timer = scheduleAfterBootQuiet(() => {
|
|
58564
|
+
running = runV2SessionProjectBackfill(backfillDb, openStoreReader, config.allow_home_project).then(() => backfillSessionActivity(backfillDb, "opencode", (sessionId) => {
|
|
58238
58565
|
const reader = openStoreReader();
|
|
58239
58566
|
try {
|
|
58240
58567
|
return reader.latestMessageTime(sessionId);
|
|
@@ -58243,6 +58570,17 @@ async function registerContext(context) {
|
|
|
58243
58570
|
}
|
|
58244
58571
|
})).catch((error) => log2("[session-project-backfill] OpenCode 2 backfill failed:", error));
|
|
58245
58572
|
});
|
|
58573
|
+
cleanup.backfill = (failedSetup) => {
|
|
58574
|
+
if (!failedSetup)
|
|
58575
|
+
return;
|
|
58576
|
+
clearTimeout(timer);
|
|
58577
|
+
if (!running)
|
|
58578
|
+
return;
|
|
58579
|
+
return settleWithin(running, DEFAULT_DISPOSE_DRAIN_MS).then((joined) => {
|
|
58580
|
+
if (!joined)
|
|
58581
|
+
log2("[magic-context] v2 backfill still running after setup cleanup");
|
|
58582
|
+
});
|
|
58583
|
+
};
|
|
58246
58584
|
}
|
|
58247
58585
|
const readAllForConversion = (sessionID) => readAllV2RawMessagesForConversion2(openStoreReader, sessionID);
|
|
58248
58586
|
const readRowsFrom = (sessionID, messageID) => {
|
|
@@ -58263,10 +58601,12 @@ async function registerContext(context) {
|
|
|
58263
58601
|
}) : undefined;
|
|
58264
58602
|
const lkgSystems = new V2LkgSystemReplay;
|
|
58265
58603
|
let transform;
|
|
58604
|
+
cleanup.transform = () => transform?.disposeRust();
|
|
58266
58605
|
let systemPrompt;
|
|
58267
58606
|
const systemPromptRefreshSessions = new Set;
|
|
58268
58607
|
const tagger = createTagger();
|
|
58269
58608
|
const deletedSessions = new DeletedSessionTombstones;
|
|
58609
|
+
cleanup.deletedSessions = () => deletedSessions.clear();
|
|
58270
58610
|
const forkSeedSettled = new Set;
|
|
58271
58611
|
const inheritForkState = (database, sessionID) => {
|
|
58272
58612
|
if (forkSeedSettled.has(sessionID))
|
|
@@ -58437,6 +58777,12 @@ async function registerContext(context) {
|
|
|
58437
58777
|
log: sessionLog2
|
|
58438
58778
|
}) : undefined;
|
|
58439
58779
|
const hostFoldIdle = hostFolds ? new HostFoldIdle((sessionID, eligible) => hostFolds.idle(sessionID, eligible)) : undefined;
|
|
58780
|
+
cleanup.idle = () => {
|
|
58781
|
+
messageTimesCache.clear();
|
|
58782
|
+
recoveredInstructions.clear();
|
|
58783
|
+
loggedUncoveredCheckpoints.clear();
|
|
58784
|
+
hostFoldIdle?.dispose();
|
|
58785
|
+
};
|
|
58440
58786
|
const armBindingRecoveryFromEvent = (sessionID, error, source) => {
|
|
58441
58787
|
if (error === undefined || !db || compactionOff)
|
|
58442
58788
|
return;
|
|
@@ -58472,6 +58818,7 @@ async function registerContext(context) {
|
|
|
58472
58818
|
}
|
|
58473
58819
|
};
|
|
58474
58820
|
const usageController = new AbortController;
|
|
58821
|
+
cleanup.abortUsage = () => usageController.abort();
|
|
58475
58822
|
const usageDone = (async () => {
|
|
58476
58823
|
let retry = 0;
|
|
58477
58824
|
while (!usageController.signal.aborted) {
|
|
@@ -58651,6 +58998,7 @@ async function registerContext(context) {
|
|
|
58651
58998
|
}
|
|
58652
58999
|
}
|
|
58653
59000
|
})();
|
|
59001
|
+
cleanup.joinUsage = () => usageDone;
|
|
58654
59002
|
const m0RenderOptions = (draft, store, state) => {
|
|
58655
59003
|
const modelKey = `${draft.model.providerID}/${draft.model.id}`;
|
|
58656
59004
|
const contextLimit = resolveContextLimit(draft.model.providerID, draft.model.id, {
|
|
@@ -59688,6 +60036,10 @@ async function registerContext(context) {
|
|
|
59688
60036
|
const storageDir = getMagicContextStorageDir();
|
|
59689
60037
|
const rpcServer = new MagicContextRpcServer(storageDir, directory);
|
|
59690
60038
|
let rpcStopped = false;
|
|
60039
|
+
cleanup.rpc = () => {
|
|
60040
|
+
rpcStopped = true;
|
|
60041
|
+
rpcServer.stop();
|
|
60042
|
+
};
|
|
59691
60043
|
registerRpcHandlers(rpcServer, {
|
|
59692
60044
|
directory,
|
|
59693
60045
|
config,
|
|
@@ -59794,35 +60146,6 @@ async function registerContext(context) {
|
|
|
59794
60146
|
return;
|
|
59795
60147
|
rpcServer.start().catch((error) => log2("[magic-context] v2 RPC server failed to start", error));
|
|
59796
60148
|
}, 0));
|
|
59797
|
-
return {
|
|
59798
|
-
async dispose() {
|
|
59799
|
-
if (hiddenChildSweepTimer)
|
|
59800
|
-
clearInterval(hiddenChildSweepTimer);
|
|
59801
|
-
await hiddenChildSweep.dispose();
|
|
59802
|
-
messageTimesCache.clear();
|
|
59803
|
-
recoveredInstructions.clear();
|
|
59804
|
-
loggedUncoveredCheckpoints.clear();
|
|
59805
|
-
hostFoldIdle?.dispose();
|
|
59806
|
-
usageController.abort();
|
|
59807
|
-
await hiddenCompletionExecutor?.dispose();
|
|
59808
|
-
await usageDone;
|
|
59809
|
-
rpcStopped = true;
|
|
59810
|
-
rpcServer.stop();
|
|
59811
|
-
transform?.disposeRust();
|
|
59812
|
-
tools?.dispose();
|
|
59813
|
-
deletedSessions.clear();
|
|
59814
|
-
await dreamTrigger?.dispose();
|
|
59815
|
-
await maintenanceTimer?.dispose();
|
|
59816
|
-
await embeddings.dispose();
|
|
59817
|
-
for (const release of rawProviders.values())
|
|
59818
|
-
release();
|
|
59819
|
-
rawProviders.clear();
|
|
59820
|
-
restoredRows.clear();
|
|
59821
|
-
if (!await readerPool.closeWhenIdle(STORE_POOL_DISPOSE_WAIT_MS))
|
|
59822
|
-
log2(`[magic-context] v2 store reader pool still held by ${readerPool.holdCount()} hidden run(s) at dispose; it closes when they finish`);
|
|
59823
|
-
clearSyntheticCandidates(context);
|
|
59824
|
-
}
|
|
59825
|
-
};
|
|
59826
60149
|
}
|
|
59827
60150
|
export {
|
|
59828
60151
|
registerContext
|