@cortexkit/pi-magic-context 0.49.19 → 0.49.21
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 +48 -9
- package/dist/chunk-embedding-write-worker.js +29 -22
- package/dist/{compaction-marker-candidates-wjzqbspm.js → compaction-marker-candidates-p1kqkqhq.js} +3 -3
- package/dist/compaction-marker-candidates-worker.js +2 -2
- package/dist/compartment-chunk-embedding-y01m95c2.js +64 -0
- package/dist/embedding-backfill-2vh6m3bg.js +24 -0
- package/dist/embedding-worker-process.js +2 -2
- package/dist/embedding-worker.js +6 -6
- package/dist/historian-calibration-extension.js +1 -1
- package/dist/{index-e1rza8gp.js → index-29nw7n1r.js} +1 -1
- package/dist/{index-rrwv9y2k.js → index-2qtx0q6h.js} +214 -5
- package/dist/{index-msqrs4nf.js → index-3c3ztwgc.js} +5 -5
- package/dist/index-54wmg4rj.js +82 -0
- package/dist/{index-yygsh681.js → index-579m1751.js} +3 -3
- package/dist/{index-rc1dez8m.js → index-5j6vwg4z.js} +154 -13
- package/dist/{index-qpq6w67c.js → index-6wdwv3a6.js} +2 -2
- package/dist/{index-vktahpdj.js → index-at6py2k3.js} +9 -3
- package/dist/{index-bxmf4dhr.js → index-ccanzg8p.js} +2367 -1243
- package/dist/{index-sqt2haap.js → index-dbgg6hsf.js} +28 -14
- package/dist/{index-7bqrfyny.js → index-fgs78jyd.js} +12 -15
- package/dist/{index-58mj0dzc.js → index-ftvm2acc.js} +181 -46
- package/dist/{index-wveb51es.js → index-gqjxy2p7.js} +74 -9
- package/dist/{index-d8gc0112.js → index-gwxaz0z5.js} +4 -6
- package/dist/{index-d4dt19md.js → index-hqw0rt9k.js} +1 -1
- package/dist/{index-g7p75667.js → index-hxp6q5f8.js} +2 -2
- package/dist/{index-svgkv4g2.js → index-j3pz3a1b.js} +2 -2
- package/dist/{index-f18ec69t.js → index-jn44h81p.js} +1 -1
- package/dist/{index-1kcfwk9c.js → index-my0dn413.js} +1 -1
- package/dist/{index-apgwdby5.js → index-n4wyxcgr.js} +1 -1
- package/dist/{index-rhprywn6.js → index-n8e5e9fp.js} +28 -7
- package/dist/{index-z2rkv0mb.js → index-pe5gz5c4.js} +5 -5
- package/dist/{index-dtp1efvf.js → index-st4gwt64.js} +2 -2
- package/dist/{index-xnch62s6.js → index-vx6f7wff.js} +314 -127
- package/dist/{index-jrap43gc.js → index-w1avzkdt.js} +1 -1
- package/dist/{index-vmcgew7x.js → index-w1twp2kp.js} +78 -58
- package/dist/{index-ek9zvs4f.js → index-w6r3ggnp.js} +57 -27
- package/dist/{index-ym6nh2gk.js → index-wgmhk91m.js} +113 -20
- package/dist/{index-2mmy81qt.js → index-wqpjhx1p.js} +501 -20
- package/dist/index.js +1178 -417
- package/dist/{logger-dygt96rn.js → logger-shetp43v.js} +1 -1
- package/dist/{message-fts-rowid-map-cvpy2dmb.js → message-fts-rowid-map-59y476bk.js} +6 -5
- package/dist/{message-index-rc2x41k4.js → message-index-3snxf11x.js} +15 -14
- package/dist/{message-index-bounded-66saeq5j.js → message-index-bounded-4ngt600v.js} +15 -14
- package/dist/{message-time-backfill-ssshbdy8.js → message-time-backfill-e3r8ddh1.js} +3 -3
- package/dist/migration-worker.js +12 -11
- package/dist/{project-embedding-registry-vf1ncptn.js → project-embedding-registry-hfyzs654.js} +14 -13
- package/dist/raw-ordinal-warmup-worker.js +136 -101
- package/dist/{read-session-chunk-h5bzj91r.js → read-session-chunk-5dmc77q2.js} +10 -9
- package/dist/{read-session-raw-9s3xn7fc.js → read-session-raw-yxv2fv34.js} +4 -3
- package/dist/{safe-notification-target-2rkvkmw8.js → safe-notification-target-zcpchea6.js} +2 -2
- package/dist/search-archive-3daj5ttc.js +21 -0
- package/dist/{search-wh7b9zht.js → search-jhfh3tsj.js} +23 -22
- package/dist/{sqlite-fsp0sf3r.js → sqlite-v89bj0yy.js} +7 -1
- package/dist/{storage-memory-yxxc5v4n.js → storage-memory-0ndn65fm.js} +2 -2
- package/dist/{storage-tags-1kets0q8.js → storage-tags-r48vxthe.js} +7 -5
- package/dist/subagent-entry.js +28 -26
- package/dist/tag-snapshot-worker-pi.js +22 -14
- package/package.json +5 -2
- package/dist/embedding-backfill-vwag34t0.js +0 -23
- package/dist/search-archive-4817pqev.js +0 -20
|
@@ -3,12 +3,12 @@ import {
|
|
|
3
3
|
} from "./index-135e8hvg.js";
|
|
4
4
|
import {
|
|
5
5
|
log2
|
|
6
|
-
} from "./index-
|
|
6
|
+
} from "./index-fgs78jyd.js";
|
|
7
7
|
import {
|
|
8
8
|
ensureColumn,
|
|
9
9
|
healAllNullColumns,
|
|
10
10
|
installV95PerfSchema
|
|
11
|
-
} from "./index-
|
|
11
|
+
} from "./index-w1avzkdt.js";
|
|
12
12
|
import {
|
|
13
13
|
resolveOpenCodeDbPath,
|
|
14
14
|
openCodeDbPathExists,
|
|
@@ -16,14 +16,14 @@ import {
|
|
|
16
16
|
} from "./index-8976mezv.js";
|
|
17
17
|
import {
|
|
18
18
|
Database2
|
|
19
|
-
} from "./index-
|
|
19
|
+
} from "./index-2qtx0q6h.js";
|
|
20
20
|
import {
|
|
21
21
|
normalizeStoredProjectPath,
|
|
22
22
|
storedPathBelongsToIdentity
|
|
23
|
-
} from "./index-
|
|
23
|
+
} from "./index-hxp6q5f8.js";
|
|
24
24
|
import {
|
|
25
25
|
logSlowWriteTransaction
|
|
26
|
-
} from "./index-
|
|
26
|
+
} from "./index-hqw0rt9k.js";
|
|
27
27
|
|
|
28
28
|
// ../plugin/src/features/magic-context/migrations.ts
|
|
29
29
|
import { isMainThread } from "node:worker_threads";
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// ../plugin/src/shared/worker-shutdown.ts
|
|
2
|
+
var WORKER_CLOSE_MESSAGE = { kind: "close" };
|
|
3
|
+
function isWorkerCloseMessage(message) {
|
|
4
|
+
return typeof message === "object" && message !== null && message.kind === WORKER_CLOSE_MESSAGE.kind;
|
|
5
|
+
}
|
|
6
|
+
function exitOnWorkerClose(port, closeConnections) {
|
|
7
|
+
const listener = (message) => {
|
|
8
|
+
if (!isWorkerCloseMessage(message))
|
|
9
|
+
return;
|
|
10
|
+
try {
|
|
11
|
+
closeConnections();
|
|
12
|
+
} finally {
|
|
13
|
+
process.exit(0);
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
if (!port)
|
|
17
|
+
return { closePort() {} };
|
|
18
|
+
port.on("message", listener);
|
|
19
|
+
let closed = false;
|
|
20
|
+
return {
|
|
21
|
+
closePort() {
|
|
22
|
+
if (closed)
|
|
23
|
+
return;
|
|
24
|
+
closed = true;
|
|
25
|
+
setTimeout(() => {
|
|
26
|
+
port.off("message", listener);
|
|
27
|
+
port.close();
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
var outcomes = new Map;
|
|
33
|
+
function createWorkerShutdown(worker, site, deadlineMs) {
|
|
34
|
+
let exited = false;
|
|
35
|
+
let forced = false;
|
|
36
|
+
let closing;
|
|
37
|
+
const exit = new Promise((resolve) => {
|
|
38
|
+
worker.once("exit", () => {
|
|
39
|
+
exited = true;
|
|
40
|
+
resolve();
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
const record = () => {
|
|
44
|
+
const counts = outcomes.get(site) ?? { graceful: 0, forced: 0 };
|
|
45
|
+
if (forced)
|
|
46
|
+
counts.forced += 1;
|
|
47
|
+
else
|
|
48
|
+
counts.graceful += 1;
|
|
49
|
+
outcomes.set(site, counts);
|
|
50
|
+
};
|
|
51
|
+
const terminate = () => {
|
|
52
|
+
forced = true;
|
|
53
|
+
worker.terminate().catch(() => {});
|
|
54
|
+
};
|
|
55
|
+
return {
|
|
56
|
+
close() {
|
|
57
|
+
if (closing)
|
|
58
|
+
return closing;
|
|
59
|
+
if (exited) {
|
|
60
|
+
closing = Promise.resolve();
|
|
61
|
+
return closing;
|
|
62
|
+
}
|
|
63
|
+
try {
|
|
64
|
+
worker.postMessage(WORKER_CLOSE_MESSAGE);
|
|
65
|
+
} catch {
|
|
66
|
+
terminate();
|
|
67
|
+
}
|
|
68
|
+
const fallback = setTimeout(() => {
|
|
69
|
+
if (!exited)
|
|
70
|
+
terminate();
|
|
71
|
+
}, deadlineMs);
|
|
72
|
+
fallback.unref?.();
|
|
73
|
+
closing = exit.then(() => {
|
|
74
|
+
clearTimeout(fallback);
|
|
75
|
+
record();
|
|
76
|
+
});
|
|
77
|
+
return closing;
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export { isWorkerCloseMessage, exitOnWorkerClose, createWorkerShutdown };
|
|
@@ -2,13 +2,13 @@ import {
|
|
|
2
2
|
getSqliteDatabasePath2,
|
|
3
3
|
withSqliteBackgroundWriter2,
|
|
4
4
|
withoutSqliteTransformPass2
|
|
5
|
-
} from "./index-
|
|
5
|
+
} from "./index-2qtx0q6h.js";
|
|
6
6
|
import {
|
|
7
7
|
runSessionWarmupWorker
|
|
8
|
-
} from "./index-
|
|
8
|
+
} from "./index-at6py2k3.js";
|
|
9
9
|
import {
|
|
10
10
|
logSlowWriteTransaction
|
|
11
|
-
} from "./index-
|
|
11
|
+
} from "./index-hqw0rt9k.js";
|
|
12
12
|
|
|
13
13
|
// ../plugin/src/features/magic-context/message-fts-rowid-map.ts
|
|
14
14
|
import { createHash } from "node:crypto";
|
|
@@ -3,18 +3,139 @@ import {
|
|
|
3
3
|
tagRevisionCountSql,
|
|
4
4
|
tagRevisionKey,
|
|
5
5
|
TAG_INSERT_CONFLICT_ROWS
|
|
6
|
-
} from "./index-
|
|
6
|
+
} from "./index-w1avzkdt.js";
|
|
7
7
|
import {
|
|
8
8
|
getTagsBySession2,
|
|
9
9
|
getTagsByNumbers2
|
|
10
|
-
} from "./index-
|
|
10
|
+
} from "./index-n8e5e9fp.js";
|
|
11
11
|
import {
|
|
12
12
|
inRootAsyncContext2,
|
|
13
|
-
getSqliteDatabasePath2
|
|
14
|
-
|
|
13
|
+
getSqliteDatabasePath2,
|
|
14
|
+
withSqliteTurnDeadline2
|
|
15
|
+
} from "./index-2qtx0q6h.js";
|
|
15
16
|
import {
|
|
16
17
|
createFailClosedBlockingError
|
|
17
|
-
} from "./index-
|
|
18
|
+
} from "./index-dbgg6hsf.js";
|
|
19
|
+
import {
|
|
20
|
+
createWorkerShutdown
|
|
21
|
+
} from "./index-54wmg4rj.js";
|
|
22
|
+
|
|
23
|
+
// src/pi-context-budget.ts
|
|
24
|
+
var PI_CONTEXT_BUDGET = {
|
|
25
|
+
hostDeadlineMs: 30000,
|
|
26
|
+
hostMarginMs: 5000,
|
|
27
|
+
outcomeMs: 25000,
|
|
28
|
+
fallbackObservedMs: 4,
|
|
29
|
+
workMs: 21000,
|
|
30
|
+
writerMs: 16500,
|
|
31
|
+
completionReserveMs: 2000,
|
|
32
|
+
searchMs: 3000
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
class PiContextDeadlineError extends Error {
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
class PiContextSupersededError extends Error {
|
|
39
|
+
origin;
|
|
40
|
+
constructor(message, origin = "context ownership") {
|
|
41
|
+
super(message);
|
|
42
|
+
this.origin = origin;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
class PiContextBudget {
|
|
47
|
+
startedAt;
|
|
48
|
+
now;
|
|
49
|
+
sideTurn = false;
|
|
50
|
+
stage = "entry";
|
|
51
|
+
recovery = "not attempted";
|
|
52
|
+
abandoned = false;
|
|
53
|
+
completed = false;
|
|
54
|
+
failureReason;
|
|
55
|
+
signal;
|
|
56
|
+
cancelled = false;
|
|
57
|
+
isCancelled(error) {
|
|
58
|
+
return this.cancelled || this.signal?.aborted === true || !this.signal && typeof error === "object" && error !== null && "name" in error && error.name === "AbortError";
|
|
59
|
+
}
|
|
60
|
+
cancel() {
|
|
61
|
+
this.cancelled = true;
|
|
62
|
+
this.abandoned = true;
|
|
63
|
+
this.completed = false;
|
|
64
|
+
this.failureReason = undefined;
|
|
65
|
+
}
|
|
66
|
+
assertOwner = () => {};
|
|
67
|
+
constructor(startedAt = performance.now(), now = () => performance.now()) {
|
|
68
|
+
this.startedAt = startedAt;
|
|
69
|
+
this.now = now;
|
|
70
|
+
}
|
|
71
|
+
elapsed() {
|
|
72
|
+
return this.now() - this.startedAt;
|
|
73
|
+
}
|
|
74
|
+
remainingWork = () => {
|
|
75
|
+
return Math.max(0, PI_CONTEXT_BUDGET.workMs - this.elapsed());
|
|
76
|
+
};
|
|
77
|
+
remainingOutcome = () => Math.max(0, PI_CONTEXT_BUDGET.outcomeMs - this.elapsed());
|
|
78
|
+
writerAllowance() {
|
|
79
|
+
return Math.max(0, Math.min(PI_CONTEXT_BUDGET.writerMs, this.remainingWork() - PI_CONTEXT_BUDGET.completionReserveMs));
|
|
80
|
+
}
|
|
81
|
+
hydrationAllowance() {
|
|
82
|
+
return Math.max(0, Math.min(this.remainingWork() - PI_CONTEXT_BUDGET.completionReserveMs, this.remainingOutcome() - PI_CONTEXT_BUDGET.completionReserveMs));
|
|
83
|
+
}
|
|
84
|
+
assertOutcome = () => {
|
|
85
|
+
this.assertOwner();
|
|
86
|
+
this.signal?.throwIfAborted();
|
|
87
|
+
if (this.abandoned || this.elapsed() >= PI_CONTEXT_BUDGET.outcomeMs)
|
|
88
|
+
throw new PiContextDeadlineError(this.diagnostic());
|
|
89
|
+
};
|
|
90
|
+
assert = () => {
|
|
91
|
+
this.assertOutcome();
|
|
92
|
+
if (this.elapsed() >= PI_CONTEXT_BUDGET.workMs)
|
|
93
|
+
throw new PiContextDeadlineError(this.diagnostic());
|
|
94
|
+
};
|
|
95
|
+
assertDecisionPublication = () => {
|
|
96
|
+
this.signal?.throwIfAborted();
|
|
97
|
+
if (!this.completed)
|
|
98
|
+
this.assertOwner();
|
|
99
|
+
if (this.abandoned || !this.completed && this.elapsed() >= PI_CONTEXT_BUDGET.outcomeMs)
|
|
100
|
+
throw new PiContextDeadlineError(this.diagnostic());
|
|
101
|
+
};
|
|
102
|
+
diagnostic() {
|
|
103
|
+
return `stage=${this.stage} elapsed=${Math.round(this.elapsed())}ms recovery=${this.recovery}`;
|
|
104
|
+
}
|
|
105
|
+
waitUntil = async (pending, assert, remaining) => {
|
|
106
|
+
try {
|
|
107
|
+
assert();
|
|
108
|
+
} catch (error) {
|
|
109
|
+
pending.catch(() => {});
|
|
110
|
+
throw error;
|
|
111
|
+
}
|
|
112
|
+
let timer;
|
|
113
|
+
let onAbort;
|
|
114
|
+
try {
|
|
115
|
+
return await Promise.race([
|
|
116
|
+
pending,
|
|
117
|
+
...this.signal ? [
|
|
118
|
+
new Promise((_, reject) => {
|
|
119
|
+
onAbort = () => reject(this.signal?.reason);
|
|
120
|
+
this.signal?.addEventListener("abort", onAbort, {
|
|
121
|
+
once: true
|
|
122
|
+
});
|
|
123
|
+
})
|
|
124
|
+
] : [],
|
|
125
|
+
new Promise((_, reject) => {
|
|
126
|
+
timer = setTimeout(() => reject(new PiContextDeadlineError(this.diagnostic())), remaining());
|
|
127
|
+
})
|
|
128
|
+
]);
|
|
129
|
+
} finally {
|
|
130
|
+
clearTimeout(timer);
|
|
131
|
+
if (onAbort)
|
|
132
|
+
this.signal?.removeEventListener("abort", onAbort);
|
|
133
|
+
assert();
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
wait = (pending) => this.waitUntil(pending, this.assert, () => this.remainingWork());
|
|
137
|
+
waitMandatory = (pending) => this.waitUntil(pending, this.assertOutcome, this.remainingOutcome);
|
|
138
|
+
}
|
|
18
139
|
|
|
19
140
|
// src/tag-snapshot-worker-client-pi.ts
|
|
20
141
|
import { setImmediate as yieldImmediate } from "node:timers/promises";
|
|
@@ -228,6 +349,7 @@ function startPiTagSnapshotWorker(request, options = {}) {
|
|
|
228
349
|
const started = performance.now();
|
|
229
350
|
const consumer = createPiHydrationPacketConsumer(request, options.cached, options.byteLimit);
|
|
230
351
|
const worker = inRootAsyncContext2(() => new Worker(entry, { workerData: request }));
|
|
352
|
+
const shutdown = createWorkerShutdown(worker, "pi-tag-snapshot", 1000);
|
|
231
353
|
let exited = false;
|
|
232
354
|
let settled = false;
|
|
233
355
|
let consumption = Promise.resolve();
|
|
@@ -292,7 +414,7 @@ function startPiTagSnapshotWorker(request, options = {}) {
|
|
|
292
414
|
clearTimeout(timer);
|
|
293
415
|
rejectResult(error);
|
|
294
416
|
if (!exited)
|
|
295
|
-
|
|
417
|
+
shutdown.close();
|
|
296
418
|
}
|
|
297
419
|
const timer = inRootAsyncContext2(() => setTimeout(() => abort(new PiTagHydrationError("job deadline exceeded", "deadline")), options.deadlineMs ?? 1e4));
|
|
298
420
|
timer.unref();
|
|
@@ -306,6 +428,13 @@ function createPiTagSnapshotReader(db) {
|
|
|
306
428
|
const existing = readers.get(db);
|
|
307
429
|
if (existing)
|
|
308
430
|
return existing;
|
|
431
|
+
const nativeWaiters = new Set;
|
|
432
|
+
const inSnapshotRoot = (operation) => inRootAsyncContext2(() => withSqliteTurnDeadline2(() => {
|
|
433
|
+
let remaining = Infinity;
|
|
434
|
+
for (const waiter of nativeWaiters)
|
|
435
|
+
remaining = Math.min(remaining, waiter());
|
|
436
|
+
return remaining;
|
|
437
|
+
}, operation));
|
|
309
438
|
db.exec(`
|
|
310
439
|
CREATE TEMP TABLE IF NOT EXISTS pi_tag_revision (revision INTEGER NOT NULL);
|
|
311
440
|
INSERT INTO pi_tag_revision SELECT 0 WHERE NOT EXISTS (SELECT 1 FROM pi_tag_revision);
|
|
@@ -399,7 +528,8 @@ function createPiTagSnapshotReader(db) {
|
|
|
399
528
|
const ownFirstAllocation = db.prepare(`SELECT 1 FROM pi_tag_first_allocation allocation
|
|
400
529
|
WHERE session_id = ? AND seen = 1 AND incarnation || ':0' = ?
|
|
401
530
|
AND EXISTS (SELECT 1 FROM pi_tag_watch WHERE session_id = allocation.session_id)
|
|
402
|
-
AND EXISTS (SELECT 1 FROM
|
|
531
|
+
AND EXISTS (SELECT 1 FROM pi_tag_changes WHERE session_id = allocation.session_id)
|
|
532
|
+
AND (? = 'legacy' OR EXISTS (SELECT 1 FROM pi_tag_first_rows WHERE session_id = allocation.session_id))
|
|
403
533
|
AND NOT EXISTS (SELECT 1 FROM pi_tag_first_rows first_row WHERE first_row.session_id = allocation.session_id
|
|
404
534
|
AND NOT EXISTS (SELECT 1 FROM pi_tag_changes change WHERE change.session_id = first_row.session_id AND change.tag_number IS first_row.tag_number))`);
|
|
405
535
|
const managed = new Set;
|
|
@@ -410,6 +540,7 @@ function createPiTagSnapshotReader(db) {
|
|
|
410
540
|
let desiredSession;
|
|
411
541
|
let failedUntil = 0;
|
|
412
542
|
let lastFailure;
|
|
543
|
+
let failedSession;
|
|
413
544
|
const totalRevision = db.prepare("SELECT COALESCE(value, '0') AS revision, value IS NOT NULL AS present FROM (SELECT 1) LEFT JOIN schema_migrations_meta ON key = ?");
|
|
414
545
|
const assertOutsideTransaction = () => {
|
|
415
546
|
const connection = db;
|
|
@@ -454,7 +585,7 @@ function createPiTagSnapshotReader(db) {
|
|
|
454
585
|
if (current?.sessionId === sessionId)
|
|
455
586
|
current.cancel();
|
|
456
587
|
};
|
|
457
|
-
const load = (sessionId) =>
|
|
588
|
+
const load = (sessionId) => inSnapshotRoot(async () => {
|
|
458
589
|
managed.add(sessionId);
|
|
459
590
|
if (ready(sessionId))
|
|
460
591
|
return;
|
|
@@ -468,7 +599,7 @@ function createPiTagSnapshotReader(db) {
|
|
|
468
599
|
throw new PiTagHydrationError("session hydration superseded", "stale");
|
|
469
600
|
return load(sessionId);
|
|
470
601
|
}
|
|
471
|
-
if (performance.now() < failedUntil)
|
|
602
|
+
if (failedSession === sessionId && performance.now() < failedUntil)
|
|
472
603
|
throw lastFailure;
|
|
473
604
|
watch.run(sessionId);
|
|
474
605
|
const token = stamps(sessionId, ++jobId);
|
|
@@ -512,7 +643,7 @@ function createPiTagSnapshotReader(db) {
|
|
|
512
643
|
if (current !== destination || desiredSession !== sessionId || !samePiTagSnapshotToken(token, live) || token.totalRevision !== live.totalRevision || generation.revision !== token.totalRevision || generation.durable !== token.durableVersion)
|
|
513
644
|
throw new PiTagHydrationError("owner generation or lifetime changed", "stale");
|
|
514
645
|
const snapshot = {
|
|
515
|
-
firstAllocationPending:
|
|
646
|
+
firstAllocationPending: live.revisionPresent ? undefined : candidate.tags.length === 0 && !db.prepare("SELECT 1 FROM tags WHERE session_id = ? LIMIT 1").get(sessionId) ? "empty" : "legacy",
|
|
516
647
|
revision: legacyFallbackOnly ? previous.revision : live.localRevision,
|
|
517
648
|
foreignRevision: live.foreignRevision,
|
|
518
649
|
tags: legacyFallbackOnly ? previous.tags : candidate.tags,
|
|
@@ -541,6 +672,7 @@ function createPiTagSnapshotReader(db) {
|
|
|
541
672
|
if (error instanceof PiTagHydrationError && error.code === "stale")
|
|
542
673
|
destination.stale = true;
|
|
543
674
|
if (current === destination && desiredSession === sessionId && token.sessionEpoch === (sessionEpochs.get(sessionId) ?? 0)) {
|
|
675
|
+
failedSession = sessionId;
|
|
544
676
|
lastFailure = error;
|
|
545
677
|
failedUntil = performance.now() + (error instanceof PiTagHydrationError && error.code === "stale" ? 0 : 500);
|
|
546
678
|
}
|
|
@@ -558,6 +690,12 @@ function createPiTagSnapshotReader(db) {
|
|
|
558
690
|
owners.set(db, {
|
|
559
691
|
ready,
|
|
560
692
|
load,
|
|
693
|
+
addNativeWaiter: (remaining) => {
|
|
694
|
+
nativeWaiters.add(remaining);
|
|
695
|
+
return () => {
|
|
696
|
+
nativeWaiters.delete(remaining);
|
|
697
|
+
};
|
|
698
|
+
},
|
|
561
699
|
manage: (sessionId) => managed.add(sessionId),
|
|
562
700
|
cancel
|
|
563
701
|
});
|
|
@@ -574,9 +712,9 @@ function createPiTagSnapshotReader(db) {
|
|
|
574
712
|
];
|
|
575
713
|
const stamp = versionStamp.get(sessionId, sessionId);
|
|
576
714
|
let snapshot = cache.get(sessionId);
|
|
577
|
-
if (snapshot?.firstAllocationPending && snapshot.foreignRevision !== external && snapshot.revision !== local && stamp.durable - snapshot.durableVersion === stamp.own - snapshot.ownVersion && ownFirstAllocation.get(sessionId, external)) {
|
|
715
|
+
if (snapshot?.firstAllocationPending && snapshot.foreignRevision !== external && snapshot.revision !== local && stamp.durable - snapshot.durableVersion === stamp.own - snapshot.ownVersion && ownFirstAllocation.get(sessionId, external, snapshot.firstAllocationPending)) {
|
|
578
716
|
snapshot.foreignRevision = external;
|
|
579
|
-
snapshot.firstAllocationPending =
|
|
717
|
+
snapshot.firstAllocationPending = undefined;
|
|
580
718
|
db.prepare("DELETE FROM pi_tag_first_watch WHERE session_id = ?").run(sessionId);
|
|
581
719
|
db.prepare("DELETE FROM pi_tag_first_rows WHERE session_id = ?").run(sessionId);
|
|
582
720
|
}
|
|
@@ -658,6 +796,7 @@ function createPiTagSnapshotReader(db) {
|
|
|
658
796
|
writable: true,
|
|
659
797
|
value: (...args) => {
|
|
660
798
|
desiredSession = undefined;
|
|
799
|
+
nativeWaiters.clear();
|
|
661
800
|
current?.cancel();
|
|
662
801
|
cache.clear();
|
|
663
802
|
entryReaders.delete(db);
|
|
@@ -881,6 +1020,7 @@ function ensurePiTagSnapshotReady(db, sessionId, budget) {
|
|
|
881
1020
|
if (allowance <= 0)
|
|
882
1021
|
throw new PiTagHydrationError("remaining pass budget exhausted waiting for tag snapshot; turn not sent, retry", "deadline");
|
|
883
1022
|
let timer;
|
|
1023
|
+
const releaseNativeWaiter = owner.addNativeWaiter(() => budget.remainingOutcome() - PI_CONTEXT_BUDGET.completionReserveMs);
|
|
884
1024
|
try {
|
|
885
1025
|
await budget.wait(Promise.race([
|
|
886
1026
|
owner.load(sessionId),
|
|
@@ -897,9 +1037,10 @@ function ensurePiTagSnapshotReady(db, sessionId, budget) {
|
|
|
897
1037
|
throw error;
|
|
898
1038
|
} finally {
|
|
899
1039
|
clearTimeout(timer);
|
|
1040
|
+
releaseNativeWaiter();
|
|
900
1041
|
}
|
|
901
1042
|
}
|
|
902
1043
|
})();
|
|
903
1044
|
}
|
|
904
1045
|
|
|
905
|
-
export { encodePiHydrationOperation, PiTagHydrationError, PI_FALLBACK_ROW_COLUMNS, PI_FALLBACK_ROW_PREDICATE, getPiTagSnapshotView, getPiActiveTagSnapshotView, readPiFallbackTagRows, prewarmPiTagSnapshot, cancelPiTagSnapshotSession, drainPiTagSnapshotSession, assertPiTagSnapshotReady, ensurePiTagSnapshotReady };
|
|
1046
|
+
export { PI_CONTEXT_BUDGET, PiContextDeadlineError, PiContextSupersededError, PiContextBudget, encodePiHydrationOperation, PiTagHydrationError, PI_FALLBACK_ROW_COLUMNS, PI_FALLBACK_ROW_PREDICATE, getPiTagSnapshotView, getPiActiveTagSnapshotView, readPiFallbackTagRows, prewarmPiTagSnapshot, cancelPiTagSnapshotSession, drainPiTagSnapshotSession, assertPiTagSnapshotReady, ensurePiTagSnapshotReady };
|
|
@@ -3,11 +3,11 @@ import {
|
|
|
3
3
|
} from "./index-399p688g.js";
|
|
4
4
|
import {
|
|
5
5
|
log2
|
|
6
|
-
} from "./index-
|
|
6
|
+
} from "./index-fgs78jyd.js";
|
|
7
7
|
import {
|
|
8
8
|
inRootAsyncContext2,
|
|
9
9
|
getSqliteDatabasePath2
|
|
10
|
-
} from "./index-
|
|
10
|
+
} from "./index-2qtx0q6h.js";
|
|
11
11
|
|
|
12
12
|
// ../plugin/src/features/magic-context/compaction-marker-candidates.ts
|
|
13
13
|
import { existsSync, realpathSync } from "node:fs";
|
|
@@ -2,13 +2,16 @@ import {
|
|
|
2
2
|
inRootAsyncContext2,
|
|
3
3
|
getSqliteDatabasePath2,
|
|
4
4
|
releaseIndexOwner2
|
|
5
|
-
} from "./index-
|
|
5
|
+
} from "./index-2qtx0q6h.js";
|
|
6
6
|
import {
|
|
7
7
|
registerExitAbort
|
|
8
8
|
} from "./index-399p688g.js";
|
|
9
9
|
import {
|
|
10
10
|
log2
|
|
11
|
-
} from "./index-
|
|
11
|
+
} from "./index-fgs78jyd.js";
|
|
12
|
+
import {
|
|
13
|
+
createWorkerShutdown
|
|
14
|
+
} from "./index-54wmg4rj.js";
|
|
12
15
|
|
|
13
16
|
// ../plugin/src/hooks/magic-context/read-session-raw.ts
|
|
14
17
|
import { isMainThread } from "node:worker_threads";
|
|
@@ -17,6 +20,7 @@ import { isMainThread } from "node:worker_threads";
|
|
|
17
20
|
import { Worker } from "node:worker_threads";
|
|
18
21
|
var ACCEPT_TIMEOUT_MS = 2000;
|
|
19
22
|
var RESULT_TIMEOUT_MS = 10 * 60000;
|
|
23
|
+
var WARMUP_CLOSE_DEADLINE_MS = 2000;
|
|
20
24
|
var FAILURE_BACKOFF_MS = 5 * 60000;
|
|
21
25
|
var inFlight = new Map;
|
|
22
26
|
var connectionIds = new WeakMap;
|
|
@@ -45,6 +49,7 @@ function runSessionWarmupWorker(input, options) {
|
|
|
45
49
|
return new Promise((resolve) => {
|
|
46
50
|
const openCancellation = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT));
|
|
47
51
|
let worker;
|
|
52
|
+
let shutdown;
|
|
48
53
|
let deadline;
|
|
49
54
|
let settled = false;
|
|
50
55
|
const finish = (result) => {
|
|
@@ -56,7 +61,7 @@ function runSessionWarmupWorker(input, options) {
|
|
|
56
61
|
options.signal?.removeEventListener("abort", abort);
|
|
57
62
|
if (worker) {
|
|
58
63
|
activeWorkers.delete(worker);
|
|
59
|
-
const stopped = worker.terminate();
|
|
64
|
+
const stopped = shutdown?.close() ?? worker.terminate();
|
|
60
65
|
worker.unref();
|
|
61
66
|
stopped.finally(() => {
|
|
62
67
|
releaseIndexOwner2(input);
|
|
@@ -82,6 +87,7 @@ function runSessionWarmupWorker(input, options) {
|
|
|
82
87
|
worker = inRootAsyncContext2(() => new Worker(options.entry ?? defaultEntry(), {
|
|
83
88
|
workerData: { ...input, openCancellation: openCancellation.buffer }
|
|
84
89
|
}));
|
|
90
|
+
shutdown = createWorkerShutdown(worker, "raw-ordinal-warmup", WARMUP_CLOSE_DEADLINE_MS);
|
|
85
91
|
} catch (error) {
|
|
86
92
|
finish({ failure: "start-failed", detail: String(error) });
|
|
87
93
|
return;
|