@cortexkit/opencode-magic-context 0.49.35 → 0.49.37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/auto-search-worker.js +163 -160
- package/dist/chunk-embedding-write-worker.js +58 -56
- package/dist/{compaction-marker-candidates-g0p67ced.js → compaction-marker-candidates-5p1qkve9.js} +3 -1
- package/dist/compaction-marker-candidates-worker.js +24 -23
- package/dist/{compartment-chunk-embedding-y4136are.js → compartment-chunk-embedding-ypktm0tk.js} +5 -4
- package/dist/{conflict-warning-hook-hhw8z5ak.js → conflict-warning-hook-b75jn458.js} +6 -5
- package/dist/{context-fk8e3h9p.js → context-ngk2jz60.js} +501 -97
- package/dist/{embedding-backfill-q6n72sy0.js → embedding-backfill-rma0v2ct.js} +9 -8
- package/dist/embedding-worker.js +2 -2
- package/dist/features/magic-context/compaction-marker-candidates.d.ts.map +1 -1
- package/dist/features/magic-context/compaction-marker.d.ts +5 -3
- package/dist/features/magic-context/compaction-marker.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/task-gates.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/verify-gate.d.ts +2 -0
- package/dist/features/magic-context/dreamer/verify-gate.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/verify-state.d.ts +9 -0
- package/dist/features/magic-context/dreamer/verify-state.d.ts.map +1 -0
- package/dist/features/magic-context/dreamer/verify.d.ts +2 -1
- package/dist/features/magic-context/dreamer/verify.d.ts.map +1 -1
- package/dist/features/magic-context/migration-worker-client.d.ts +3 -0
- package/dist/features/magic-context/migration-worker-client.d.ts.map +1 -1
- package/dist/features/magic-context/migration-worker.d.ts +15 -0
- package/dist/features/magic-context/migration-worker.d.ts.map +1 -1
- package/dist/features/magic-context/overflow-detection.d.ts +2 -2
- package/dist/features/magic-context/overflow-detection.d.ts.map +1 -1
- package/dist/features/magic-context/search-rerank.d.ts.map +1 -1
- package/dist/features/magic-context/storage-meta-persisted.d.ts +1 -0
- package/dist/features/magic-context/storage-meta-persisted.d.ts.map +1 -1
- package/dist/features/magic-context/storage-tags.d.ts +4 -0
- package/dist/features/magic-context/storage-tags.d.ts.map +1 -1
- package/dist/features/magic-context/work-metrics-carry-storage.d.ts +10 -0
- package/dist/features/magic-context/work-metrics-carry-storage.d.ts.map +1 -0
- package/dist/hooks/magic-context/auto-search-worker-client.d.ts +5 -1
- package/dist/hooks/magic-context/auto-search-worker-client.d.ts.map +1 -1
- package/dist/hooks/magic-context/compaction-marker-publication.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-runner-historian.d.ts.map +1 -1
- package/dist/hooks/magic-context/issue-423-fixture.d.ts +1 -1
- package/dist/hooks/magic-context/issue-423-fixture.d.ts.map +1 -1
- package/dist/hooks/magic-context/issue-424-fixture.d.ts +1 -1
- package/dist/hooks/magic-context/issue-424-fixture.d.ts.map +1 -1
- package/dist/hooks/magic-context/project-structural-sentinels.d.ts +25 -0
- package/dist/hooks/magic-context/project-structural-sentinels.d.ts.map +1 -0
- package/dist/hooks/magic-context/protected-tail-boundary.d.ts +8 -1
- package/dist/hooks/magic-context/protected-tail-boundary.d.ts.map +1 -1
- package/dist/hooks/magic-context/raw-ordinal-warmup.d.ts.map +1 -1
- package/dist/hooks/magic-context/read-session-true-raw-tokens.d.ts +2 -0
- package/dist/hooks/magic-context/read-session-true-raw-tokens.d.ts.map +1 -1
- package/dist/hooks/magic-context/release-recovery-prefix.d.ts +9 -0
- package/dist/hooks/magic-context/release-recovery-prefix.d.ts.map +1 -0
- package/dist/hooks/magic-context/strip-structural-noise.d.ts +6 -3
- package/dist/hooks/magic-context/strip-structural-noise.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform-context-state.d.ts +3 -0
- package/dist/hooks/magic-context/transform-context-state.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform-postprocess-phase.d.ts +3 -0
- package/dist/hooks/magic-context/transform-postprocess-phase.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform.d.ts.map +1 -1
- package/dist/{index-cpjk5jd2.js → index-1d042x6w.js} +16 -14
- package/dist/{index-jn0ddrhp.js → index-21fgrfrf.js} +8 -6
- package/dist/{index-pq0dpwrc.js → index-2rs7912w.js} +2 -2
- package/dist/{index-ezv6dz3y.js → index-4ks89h5a.js} +4 -4
- package/dist/{index-vzhhr1ht.js → index-4y35msh5.js} +1 -2
- package/dist/{index-f297z1n8.js → index-72czy45z.js} +5 -5
- package/dist/index-7v05d9b7.js +58 -0
- package/dist/{index-f9b3vtt1.js → index-850vthn3.js} +8 -2
- package/dist/{index-ksv0a31x.js → index-8jjjmhab.js} +12 -1
- package/dist/index-96ztjvkn.js +204 -0
- package/dist/{index-gyaa159j.js → index-9fgmkfaf.js} +6 -3
- package/dist/{index-4bgk5ztz.js → index-9tdvbdv1.js} +187 -90
- package/dist/{index-2v6nvy3k.js → index-ae1ar4v1.js} +1 -1
- package/dist/{index-faxb7mck.js → index-b1ydbp95.js} +1 -1
- package/dist/{index-nxrsns5x.js → index-c5dzns43.js} +75 -75
- package/dist/{index-zhqwda72.js → index-dcjkw41m.js} +1 -1
- package/dist/{index-x2mrq5xv.js → index-dfdg2cgg.js} +179 -49
- package/dist/{index-87ctnzz9.js → index-dz48h1wx.js} +2 -2
- package/dist/{index-b6xz3qbe.js → index-gnmhbyyc.js} +366 -83
- package/dist/{index-qx8j6kds.js → index-j105mf16.js} +2 -2
- package/dist/{index-p56dszfp.js → index-jggt5gf2.js} +1 -1
- package/dist/{index-xwwsbsd3.js → index-pp8vdn01.js} +5 -5
- package/dist/{index-dy7w6wm4.js → index-prw8apnc.js} +5 -5
- package/dist/{index-qncw9hey.js → index-r2epb000.js} +33 -3
- package/dist/{index-brg2w6qc.js → index-tn9drm1a.js} +16 -14
- package/dist/{index-pswsyf1w.js → index-ty4vhe4n.js} +3 -3
- package/dist/{index-pztqab6k.js → index-vd2ywmfe.js} +1 -1
- package/dist/{index-3j9t1v4n.js → index-wcwhhtdh.js} +10 -9
- package/dist/{index-1rhgxqs8.js → index-xd2p95m7.js} +1 -1
- package/dist/{index-0c7p8mq5.js → index-xnm0wq1r.js} +1 -1
- package/dist/{index-3d3872c6.js → index-ys7j6679.js} +4 -4
- package/dist/index.js +38 -37
- package/dist/{message-fts-rowid-map-xg7hr0mk.js → message-fts-rowid-map-t6qsyg9s.js} +4 -3
- package/dist/{message-index-bounded-narw7bnz.js → message-index-bounded-wfk6aqxk.js} +9 -8
- package/dist/migration-worker.js +45 -40
- package/dist/plugin/rpc-handlers.d.ts.map +1 -1
- package/dist/{project-embedding-registry-tdz7985n.js → project-embedding-registry-3yyegjma.js} +8 -7
- package/dist/raw-ordinal-warmup-worker.js +114 -118
- package/dist/{read-session-chunk-vmg1zjg0.js → read-session-chunk-26yrrhyz.js} +7 -6
- package/dist/{read-session-raw-mncmzbm9.js → read-session-raw-j7c9w57v.js} +3 -2
- package/dist/{recomp-orchestrator-qyyhnc9b.js → recomp-orchestrator-wk509qkp.js} +20 -19
- package/dist/{render-c5p0k846.js → render-h1qarr8a.js} +13 -12
- package/dist/{search-f6hwvcxk.js → search-5h9fydyq.js} +16 -15
- package/dist/{search-archive-0ny7p3bw.js → search-archive-q79hyqxs.js} +9 -8
- package/dist/{send-session-notification-0gwcz3fw.js → send-session-notification-14p3yje4.js} +5 -4
- package/dist/shared/model-suggestion-retry.d.ts +7 -0
- package/dist/shared/model-suggestion-retry.d.ts.map +1 -1
- package/dist/shared/prompt-async-transport.d.ts.map +1 -1
- package/dist/shared/reusable-worker-entry.d.ts +4 -0
- package/dist/shared/reusable-worker-entry.d.ts.map +1 -0
- package/dist/shared/reusable-worker.d.ts +6 -0
- package/dist/shared/reusable-worker.d.ts.map +1 -0
- package/dist/shared/reusable-worker.fixture.d.ts +2 -0
- package/dist/shared/reusable-worker.fixture.d.ts.map +1 -0
- package/dist/shared/worker-shutdown.d.ts +1 -1
- package/dist/shared/worker-shutdown.d.ts.map +1 -1
- package/dist/{storage-tags-zx1023km.js → storage-tags-vj0yj7ed.js} +1 -1
- package/dist/{store-620rjzt9.js → store-s3eykdjt.js} +1 -1
- package/dist/{transform-postprocess-phase-807ff6t2.js → transform-postprocess-phase-4gj0mtcg.js} +21 -20
- package/dist/v2/auto-search-worker.js +163 -160
- package/dist/v2/chunk-embedding-write-worker.js +59 -57
- package/dist/v2/compaction-marker-candidates-worker.js +24 -23
- package/dist/v2/{compaction-marker-candidates-t1aq6gsj.js → compaction-marker-candidates-yeb2ky46.js} +4 -2
- package/dist/v2/{compartment-chunk-embedding-ncsk0r9e.js → compartment-chunk-embedding-qfk791bd.js} +6 -5
- package/dist/v2/{context-znqfkap4.js → context-05x7kr7f.js} +1027 -215
- package/dist/v2/{embedding-backfill-11j425e0.js → embedding-backfill-00tw59rx.js} +10 -9
- package/dist/v2/embedding-worker.js +2 -2
- package/dist/v2/fold/code-mode-catalog.d.ts +3 -0
- package/dist/v2/fold/code-mode-catalog.d.ts.map +1 -0
- package/dist/v2/fold/host-media.d.ts +7 -3
- package/dist/v2/fold/host-media.d.ts.map +1 -1
- package/dist/v2/fold/idle.d.ts +1 -0
- package/dist/v2/fold/idle.d.ts.map +1 -1
- package/dist/v2/fold/manual-baseline.d.ts +8 -0
- package/dist/v2/fold/manual-baseline.d.ts.map +1 -0
- package/dist/v2/fold/native-replay-v3.d.ts +7 -0
- package/dist/v2/fold/native-replay-v3.d.ts.map +1 -1
- package/dist/v2/fold/native-replay.d.ts +24 -7
- package/dist/v2/fold/native-replay.d.ts.map +1 -1
- package/dist/v2/fold/restore.d.ts.map +1 -1
- package/dist/v2/fold/summary.d.ts +4 -0
- package/dist/v2/fold/summary.d.ts.map +1 -0
- package/dist/v2/hidden-completion.d.ts.map +1 -1
- package/dist/v2/hooks/channel2.d.ts +6 -0
- package/dist/v2/hooks/channel2.d.ts.map +1 -1
- package/dist/v2/hooks/context.d.ts.map +1 -1
- package/dist/v2/hooks/restore-rows.d.ts +12 -2
- package/dist/v2/hooks/restore-rows.d.ts.map +1 -1
- package/dist/v2/hooks/synthetic-admission.d.ts +7 -0
- package/dist/v2/hooks/synthetic-admission.d.ts.map +1 -0
- package/dist/v2/hooks/usage-persist.d.ts.map +1 -1
- package/dist/v2/{message-fts-rowid-map-rmk571mb.js → message-fts-rowid-map-z86avy0n.js} +5 -4
- package/dist/v2/{message-index-bounded-620bppw7.js → message-index-bounded-w14496s9.js} +9 -8
- package/dist/v2/migration-worker.js +46 -41
- package/dist/v2/{project-embedding-registry-bm5fe1a8.js → project-embedding-registry-jqq2qeqb.js} +9 -8
- package/dist/v2/raw-ordinal-warmup-worker.js +114 -118
- package/dist/v2/{read-session-chunk-qfwv1k71.js → read-session-chunk-tqnh1ret.js} +7 -6
- package/dist/v2/{read-session-raw-q294t8xs.js → read-session-raw-qpp6x9kg.js} +4 -3
- package/dist/v2/{recomp-orchestrator-fcnjref7.js → recomp-orchestrator-9cjk6aej.js} +19 -18
- package/dist/v2/{render-98a1qv0b.js → render-5dz1knf2.js} +13 -12
- package/dist/v2/{search-z1zqzsmh.js → search-8yfet25y.js} +15 -14
- package/dist/v2/{search-archive-r0y1bafr.js → search-archive-z6z9jqwf.js} +9 -8
- package/dist/v2/{send-session-notification-fst6hkg7.js → send-session-notification-kxp47tsw.js} +4 -3
- package/dist/v2/{server-cpjk5jd2.js → server-1d042x6w.js} +16 -14
- package/dist/v2/{server-fqj6ddpr.js → server-5by3vdzs.js} +186 -89
- package/dist/v2/{server-5jp38p98.js → server-6emy0v9a.js} +1 -2
- package/dist/v2/{server-rktnzs89.js → server-6vzh6wej.js} +1 -1
- package/dist/v2/{server-qa74bj91.js → server-7094pk3w.js} +9 -8
- package/dist/v2/{server-bxpz2dcn.js → server-7acq7815.js} +8 -6
- package/dist/v2/server-7v05d9b7.js +58 -0
- package/dist/v2/{server-24g8r2d0.js → server-7zacmty5.js} +75 -75
- package/dist/v2/server-96ztjvkn.js +204 -0
- package/dist/v2/{server-hnknwaz8.js → server-a9w5f0yw.js} +3 -3
- package/dist/v2/{server-9k0mjef7.js → server-avdveykk.js} +1 -1
- package/dist/v2/{server-hsf0qsn5.js → server-cp1a03vc.js} +1 -1
- package/dist/v2/{server-r3chnxs5.js → server-dfq5vb8j.js} +2 -2
- package/dist/v2/{server-x4m6xcn4.js → server-e51xmr4d.js} +6 -6
- package/dist/v2/{server-7ccxt4nq.js → server-g3gqq4ac.js} +6 -3
- package/dist/v2/{server-kkxzwa6w.js → server-gkse1wyz.js} +3 -3
- package/dist/v2/{server-1xesqm5h.js → server-jd7vzwn4.js} +15 -13
- package/dist/v2/{server-ws5exe6q.js → server-nmyganc8.js} +1 -1
- package/dist/v2/{server-q0z2q2dx.js → server-nq3cb7be.js} +1 -1
- package/dist/v2/{server-55v5hpth.js → server-qjyp27vf.js} +2 -2
- package/dist/v2/{server-xbtw0p9t.js → server-r4430x9m.js} +9 -3
- package/dist/v2/{server-qf2kzsh2.js → server-t8y64xj7.js} +4 -4
- package/dist/v2/{server-s9xgyyj9.js → server-tnzbk64q.js} +34 -4
- package/dist/v2/{server-51779zs2.js → server-v0p37hm2.js} +4 -1
- package/dist/v2/{server-bpvsvtph.js → server-xfjjbrkt.js} +12 -1
- package/dist/v2/server.js +4 -4
- package/dist/v2/{storage-tags-19s0ebf0.js → storage-tags-cw07ky67.js} +1 -1
- package/dist/v2/{store-vdm8v3jd.js → store-z3qe67cg.js} +1 -1
- package/dist/v2/{v2-archive-reader-t2c0eypn.js → v2-archive-reader-z7wr42ry.js} +3 -3
- package/dist/v2/{wrapup-orchestrator-aqpqsveg.js → wrapup-orchestrator-j1v62bkj.js} +19 -18
- package/dist/{v2-archive-reader-tm2eayp2.js → v2-archive-reader-028z6kck.js} +2 -2
- package/dist/{wrapup-orchestrator-k5yp19a6.js → wrapup-orchestrator-xg9avt2p.js} +21 -20
- package/package.json +1 -1
- package/src/shared/model-suggestion-retry.ts +1 -1
- package/src/shared/prompt-async-transport.test.ts +64 -3
- package/src/shared/prompt-async-transport.ts +61 -16
- package/src/shared/reusable-worker-entry.ts +58 -0
- package/src/shared/reusable-worker-reset.test.ts +108 -0
- package/src/shared/reusable-worker.fixture.ts +35 -0
- package/src/shared/reusable-worker.test.ts +253 -0
- package/src/shared/reusable-worker.ts +240 -0
- package/src/shared/worker-shutdown.ts +21 -17
|
@@ -2554,7 +2554,9 @@ function getAllStatusTagTokenTotalsFlat2(db, sessionId, floor = 0, calibration =
|
|
|
2554
2554
|
FROM tags
|
|
2555
2555
|
WHERE session_id = ?`).all(sessionId);
|
|
2556
2556
|
const totals = new Map;
|
|
2557
|
+
const summaryRemovedTotals = new Map;
|
|
2557
2558
|
const nullMessageIds = new Set;
|
|
2559
|
+
const nullSummaryRemovedMessageIds = new Set;
|
|
2558
2560
|
for (const row of rows) {
|
|
2559
2561
|
if (row.type === "tool" && row.tool_owner_message_id === null)
|
|
2560
2562
|
continue;
|
|
@@ -2564,6 +2566,7 @@ function getAllStatusTagTokenTotalsFlat2(db, sessionId, floor = 0, calibration =
|
|
|
2564
2566
|
if (row.token_count === null) {
|
|
2565
2567
|
nullMessageIds.add(owner);
|
|
2566
2568
|
totals.delete(owner);
|
|
2569
|
+
summaryRemovedTotals.delete(owner);
|
|
2567
2570
|
continue;
|
|
2568
2571
|
}
|
|
2569
2572
|
if (nullMessageIds.has(owner))
|
|
@@ -2571,8 +2574,16 @@ function getAllStatusTagTokenTotalsFlat2(db, sessionId, floor = 0, calibration =
|
|
|
2571
2574
|
const ratio = row.type === "tool" ? calibration.toolsRatio : calibration.proseRatio;
|
|
2572
2575
|
const weight = ((row.token_count ?? 0) + (row.input_token_count ?? 0)) * ratio + (row.reasoning_token_count ?? 0) * calibration.proseRatio;
|
|
2573
2576
|
totals.set(owner, (totals.get(owner) ?? 0) + weight);
|
|
2577
|
+
if (row.type === "tool" && row.input_token_count === null) {
|
|
2578
|
+
nullSummaryRemovedMessageIds.add(owner);
|
|
2579
|
+
summaryRemovedTotals.delete(owner);
|
|
2580
|
+
}
|
|
2581
|
+
if (!nullSummaryRemovedMessageIds.has(owner)) {
|
|
2582
|
+
const removedWeight = row.type === "tool" ? (row.input_token_count ?? 0) * calibration.toolsRatio : row.type === "message" ? row.token_count * calibration.proseRatio : 0;
|
|
2583
|
+
summaryRemovedTotals.set(owner, (summaryRemovedTotals.get(owner) ?? 0) + removedWeight);
|
|
2584
|
+
}
|
|
2574
2585
|
}
|
|
2575
|
-
return { totals, nullMessageIds };
|
|
2586
|
+
return { totals, summaryRemovedTotals, nullMessageIds };
|
|
2576
2587
|
}
|
|
2577
2588
|
function getReasoningTokenEstimatesByMessage2(db, sessionId, proseRatio) {
|
|
2578
2589
|
const summary = readTagOwnerSummary(db, sessionId, proseRatio);
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import {
|
|
2
|
+
registerExitAbort,
|
|
3
|
+
unregisterExitAbort
|
|
4
|
+
} from "./index-v0p37hm2.js";
|
|
5
|
+
import {
|
|
6
|
+
inRootAsyncContext2
|
|
7
|
+
} from "./index-gzy5w8ya.js";
|
|
8
|
+
|
|
9
|
+
// src/shared/reusable-worker.ts
|
|
10
|
+
import { EventEmitter } from "node:events";
|
|
11
|
+
import * as timers from "node:timers";
|
|
12
|
+
import {
|
|
13
|
+
MessageChannel,
|
|
14
|
+
receiveMessageOnPort,
|
|
15
|
+
Worker
|
|
16
|
+
} from "node:worker_threads";
|
|
17
|
+
var pools = new Map;
|
|
18
|
+
var liveSlots = new Set;
|
|
19
|
+
var nextId = 0;
|
|
20
|
+
var IDLE_MS = 60000;
|
|
21
|
+
var sharedCloneWorks = (() => {
|
|
22
|
+
const source = new SharedArrayBuffer(1);
|
|
23
|
+
const clone = structuredClone(source);
|
|
24
|
+
new Uint8Array(source)[0] = 1;
|
|
25
|
+
return new Uint8Array(clone)[0] === 1;
|
|
26
|
+
})();
|
|
27
|
+
var cloneChannel;
|
|
28
|
+
function cloneJobValue(value, transferList) {
|
|
29
|
+
if (sharedCloneWorks)
|
|
30
|
+
return structuredClone(value, { transfer: transferList });
|
|
31
|
+
if (!cloneChannel) {
|
|
32
|
+
cloneChannel = inRootAsyncContext2(() => new MessageChannel);
|
|
33
|
+
cloneChannel.port1.unref();
|
|
34
|
+
cloneChannel.port2.unref();
|
|
35
|
+
}
|
|
36
|
+
cloneChannel.port1.postMessage(value, transferList);
|
|
37
|
+
const packet = receiveMessageOnPort(cloneChannel.port2);
|
|
38
|
+
if (!packet)
|
|
39
|
+
throw new Error("worker input clone did not arrive synchronously");
|
|
40
|
+
return packet.message;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
class Lease extends EventEmitter {
|
|
44
|
+
slot;
|
|
45
|
+
data;
|
|
46
|
+
id = ++nextId;
|
|
47
|
+
ended = false;
|
|
48
|
+
referenced = true;
|
|
49
|
+
outbox = [];
|
|
50
|
+
constructor(slot, data) {
|
|
51
|
+
super();
|
|
52
|
+
this.slot = slot;
|
|
53
|
+
this.data = data;
|
|
54
|
+
}
|
|
55
|
+
postMessage(value, transferList) {
|
|
56
|
+
if (this.ended)
|
|
57
|
+
return;
|
|
58
|
+
if (this.slot.active === this)
|
|
59
|
+
this.slot.worker.postMessage({ jobId: this.id, value }, transferList);
|
|
60
|
+
else
|
|
61
|
+
this.outbox.push(cloneJobValue({ value, transferList }, transferList));
|
|
62
|
+
}
|
|
63
|
+
start() {
|
|
64
|
+
if (this.referenced)
|
|
65
|
+
this.slot.worker.ref();
|
|
66
|
+
else
|
|
67
|
+
this.slot.worker.unref();
|
|
68
|
+
this.emit("online");
|
|
69
|
+
this.slot.worker.postMessage({ jobId: this.id, start: this.data });
|
|
70
|
+
for (const { value, transferList } of this.outbox.splice(0))
|
|
71
|
+
this.postMessage(value, transferList);
|
|
72
|
+
}
|
|
73
|
+
ref() {
|
|
74
|
+
this.referenced = true;
|
|
75
|
+
if (this.slot.active === this)
|
|
76
|
+
this.slot.worker.ref();
|
|
77
|
+
return this;
|
|
78
|
+
}
|
|
79
|
+
unref() {
|
|
80
|
+
this.referenced = false;
|
|
81
|
+
if (this.slot.active === this)
|
|
82
|
+
this.slot.worker.unref();
|
|
83
|
+
return this;
|
|
84
|
+
}
|
|
85
|
+
async terminate() {
|
|
86
|
+
if (this.ended)
|
|
87
|
+
return 0;
|
|
88
|
+
if (this.slot.active === this)
|
|
89
|
+
return await this.slot.worker.terminate();
|
|
90
|
+
this.ended = true;
|
|
91
|
+
this.slot.queue.splice(this.slot.queue.indexOf(this), 1);
|
|
92
|
+
this.emit("exit", 0);
|
|
93
|
+
return 0;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
function reuseWorker(entry, options, idleMs = IDLE_MS) {
|
|
97
|
+
const data = cloneJobValue(options.workerData);
|
|
98
|
+
const slot = acquireSlot(entry, options, idleMs);
|
|
99
|
+
const lease = new Lease(slot, data);
|
|
100
|
+
enqueue(slot, lease);
|
|
101
|
+
return lease;
|
|
102
|
+
}
|
|
103
|
+
function enqueue(slot, lease) {
|
|
104
|
+
timers.clearTimeout(slot.idle);
|
|
105
|
+
lease.slot = slot;
|
|
106
|
+
slot.queue.push(lease);
|
|
107
|
+
queueMicrotask(() => slot.advance());
|
|
108
|
+
}
|
|
109
|
+
function acquireSlot(entry, options, idleMs) {
|
|
110
|
+
const data = options.workerData;
|
|
111
|
+
const key = JSON.stringify([
|
|
112
|
+
String(entry),
|
|
113
|
+
data?.path ?? data?.dbPath,
|
|
114
|
+
data?.harness,
|
|
115
|
+
data?.job
|
|
116
|
+
]);
|
|
117
|
+
let slot = pools.get(key);
|
|
118
|
+
if (!slot) {
|
|
119
|
+
const worker = inRootAsyncContext2(() => new Worker(entry, { ...options, workerData: { reusableWorker: true } }));
|
|
120
|
+
const controller = new AbortController;
|
|
121
|
+
slot = { worker, controller, queue: [], advance: () => {} };
|
|
122
|
+
pools.set(key, slot);
|
|
123
|
+
liveSlots.add(slot);
|
|
124
|
+
const owned = slot;
|
|
125
|
+
const advance = () => {
|
|
126
|
+
if (controller.signal.aborted || owned.active)
|
|
127
|
+
return;
|
|
128
|
+
timers.clearTimeout(owned.idle);
|
|
129
|
+
const lease = owned.queue.shift();
|
|
130
|
+
owned.active = lease;
|
|
131
|
+
if (!lease) {
|
|
132
|
+
worker.unref();
|
|
133
|
+
owned.idle = timers.setTimeout(() => {
|
|
134
|
+
if (pools.get(key) === owned)
|
|
135
|
+
pools.delete(key);
|
|
136
|
+
worker.terminate();
|
|
137
|
+
}, idleMs);
|
|
138
|
+
owned.idle.unref();
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
lease.start();
|
|
142
|
+
};
|
|
143
|
+
owned.advance = advance;
|
|
144
|
+
worker.on("message", (message) => {
|
|
145
|
+
const lease = owned.active;
|
|
146
|
+
if (!lease || message.jobId !== lease.id)
|
|
147
|
+
return;
|
|
148
|
+
if (!message.finished) {
|
|
149
|
+
lease.emit("message", message.value);
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
lease.ended = true;
|
|
153
|
+
owned.active = undefined;
|
|
154
|
+
if (message.code) {
|
|
155
|
+
if (pools.get(key) === owned)
|
|
156
|
+
pools.delete(key);
|
|
157
|
+
lease.emit("exit", message.code);
|
|
158
|
+
worker.terminate();
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
lease.emit("exit", 0);
|
|
162
|
+
advance();
|
|
163
|
+
});
|
|
164
|
+
worker.on("error", (error) => {
|
|
165
|
+
if (pools.get(key) === owned)
|
|
166
|
+
pools.delete(key);
|
|
167
|
+
owned.active?.emit("error", error);
|
|
168
|
+
});
|
|
169
|
+
worker.on("exit", (code) => {
|
|
170
|
+
liveSlots.delete(owned);
|
|
171
|
+
timers.clearTimeout(owned.idle);
|
|
172
|
+
if (pools.get(key) === owned)
|
|
173
|
+
pools.delete(key);
|
|
174
|
+
const active = owned.active;
|
|
175
|
+
owned.active = undefined;
|
|
176
|
+
if (active && !active.ended) {
|
|
177
|
+
active.ended = true;
|
|
178
|
+
active.emit("exit", code);
|
|
179
|
+
}
|
|
180
|
+
for (const lease of owned.queue.splice(0)) {
|
|
181
|
+
if (controller.signal.aborted) {
|
|
182
|
+
lease.ended = true;
|
|
183
|
+
lease.emit("exit", code);
|
|
184
|
+
} else {
|
|
185
|
+
try {
|
|
186
|
+
enqueue(acquireSlot(entry, options, idleMs), lease);
|
|
187
|
+
} catch (error) {
|
|
188
|
+
lease.ended = true;
|
|
189
|
+
lease.emit("error", error);
|
|
190
|
+
lease.emit("exit", 1);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
controller.signal.addEventListener("abort", () => {
|
|
196
|
+
worker.terminate();
|
|
197
|
+
}, { once: true });
|
|
198
|
+
registerExitAbort(controller);
|
|
199
|
+
worker.once("exit", () => unregisterExitAbort(controller));
|
|
200
|
+
}
|
|
201
|
+
return slot;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export { reuseWorker };
|
|
@@ -44,9 +44,12 @@ import {
|
|
|
44
44
|
import {
|
|
45
45
|
attachFailClosedBlockingProcessEvidence
|
|
46
46
|
} from "./index-wh9fxds5.js";
|
|
47
|
+
import {
|
|
48
|
+
reuseWorker
|
|
49
|
+
} from "./index-96ztjvkn.js";
|
|
47
50
|
import {
|
|
48
51
|
startMessageFtsRowidMapBackfill2
|
|
49
|
-
} from "./index-
|
|
52
|
+
} from "./index-b1ydbp95.js";
|
|
50
53
|
import {
|
|
51
54
|
LKG_SLOT_CHUNKS_DDL,
|
|
52
55
|
SESSION_REPLAY_DECISIONS_DDL,
|
|
@@ -224,7 +227,7 @@ function runMigrationsOffThread(data) {
|
|
|
224
227
|
return new Promise((resolve, reject) => {
|
|
225
228
|
let worker;
|
|
226
229
|
try {
|
|
227
|
-
worker = inRootAsyncContext2(() => new Worker(workerEntryOverride
|
|
230
|
+
worker = inRootAsyncContext2(() => workerEntryOverride ? new Worker(workerEntryOverride, { workerData: data }) : reuseWorker(defaultWorkerEntry(), { workerData: data }));
|
|
228
231
|
} catch (error) {
|
|
229
232
|
reject(workerStartError(error instanceof Error ? error.message : String(error)));
|
|
230
233
|
return;
|
|
@@ -1021,7 +1024,7 @@ function finishDatabaseOpen(db, dbPath, explicitDbPath, latestSupportedVersion)
|
|
|
1021
1024
|
state.running = startMessageFtsRowidMapBackfill2(db, signal).then(async () => {
|
|
1022
1025
|
if (signal.aborted || !readsOpenCodeStore)
|
|
1023
1026
|
return;
|
|
1024
|
-
const { readRawSessionMessagePage, readRawSessionMessages } = await importPluginModule(() => import("./read-session-chunk-
|
|
1027
|
+
const { readRawSessionMessagePage, readRawSessionMessages } = await importPluginModule(() => import("./read-session-chunk-26yrrhyz.js"));
|
|
1025
1028
|
const { startMessageTimeBackfill } = await importPluginModule(() => import("./message-time-backfill-39bm498k.js"));
|
|
1026
1029
|
if (signal.aborted)
|
|
1027
1030
|
return;
|