@cortexkit/pi-magic-context 0.49.18 → 0.49.20
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 +53 -10
- package/dist/chunk-embedding-write-worker.js +29 -22
- package/dist/{compaction-marker-candidates-wjzqbspm.js → compaction-marker-candidates-fnm47jat.js} +3 -3
- package/dist/compaction-marker-candidates-worker.js +2 -2
- package/dist/compartment-chunk-embedding-81qesfjs.js +64 -0
- package/dist/embedding-backfill-56e871c6.js +24 -0
- package/dist/embedding-worker-process.js +2 -2
- package/dist/embedding-worker.js +5 -5
- package/dist/historian-calibration-extension.js +1 -1
- package/dist/index-54wmg4rj.js +82 -0
- package/dist/{index-xnch62s6.js → index-5n5zxs8e.js} +314 -127
- package/dist/{index-gdjv1nnd.js → index-5vgt1zeh.js} +6 -7
- package/dist/{index-qpq6w67c.js → index-6kb2xpw7.js} +2 -2
- package/dist/{index-d43hmn31.js → index-af9t637y.js} +68 -16
- package/dist/{index-z2rkv0mb.js → index-b8am7tns.js} +4 -4
- package/dist/{index-rhprywn6.js → index-bttctq07.js} +23 -5
- package/dist/{index-e1rza8gp.js → index-dzem6gn9.js} +1 -1
- package/dist/{index-2mmy81qt.js → index-e19qtjj0.js} +468 -18
- package/dist/{index-7bqrfyny.js → index-fgs78jyd.js} +12 -15
- package/dist/{index-d4dt19md.js → index-hqw0rt9k.js} +1 -1
- package/dist/{index-rrwv9y2k.js → index-hws5f0z9.js} +1 -1
- package/dist/{index-f18ec69t.js → index-jn44h81p.js} +1 -1
- package/dist/{index-xxn1tpnv.js → index-jt0g3hn0.js} +45 -28
- package/dist/{index-d8gc0112.js → index-jxjr7kz9.js} +3 -3
- package/dist/{index-4bv5bttd.js → index-kqb3d8bs.js} +9 -5
- package/dist/{index-gp928w10.js → index-mtvvhcw4.js} +10 -10
- package/dist/{index-1kcfwk9c.js → index-my0dn413.js} +1 -1
- package/dist/{index-apgwdby5.js → index-n4wyxcgr.js} +1 -1
- package/dist/{index-g7p75667.js → index-p63nwn5v.js} +2 -2
- package/dist/{index-svgkv4g2.js → index-qerzchrs.js} +2 -2
- package/dist/{index-vktahpdj.js → index-rfyvax95.js} +9 -3
- package/dist/{index-yygsh681.js → index-rgfb753z.js} +3 -3
- package/dist/{index-d21pdr8v.js → index-tb3d9trm.js} +2 -2
- package/dist/{index-vmcgew7x.js → index-v2epyzbm.js} +75 -57
- package/dist/{index-fvjthct0.js → index-vdy273xw.js} +107 -20
- package/dist/{index-jrap43gc.js → index-w1avzkdt.js} +1 -1
- package/dist/{index-r9f4f6s1.js → index-zhwwp8zz.js} +64 -8
- package/dist/index.js +1119 -247
- package/dist/{logger-dygt96rn.js → logger-shetp43v.js} +1 -1
- package/dist/{message-fts-rowid-map-cvpy2dmb.js → message-fts-rowid-map-bpexnsdj.js} +6 -5
- package/dist/{message-index-bounded-g9hgresf.js → message-index-bounded-d4r3weh0.js} +14 -13
- package/dist/{message-index-74qdqmq7.js → message-index-mvag9crh.js} +14 -13
- package/dist/{message-time-backfill-ssshbdy8.js → message-time-backfill-kc10yrcj.js} +3 -3
- package/dist/migration-worker.js +12 -11
- package/dist/{project-embedding-registry-vf1ncptn.js → project-embedding-registry-cfrg952x.js} +13 -12
- package/dist/raw-ordinal-warmup-worker.js +136 -101
- package/dist/{read-session-chunk-chepqmw5.js → read-session-chunk-7g4zvpd8.js} +9 -8
- package/dist/{read-session-raw-9s3xn7fc.js → read-session-raw-0fsjh10f.js} +4 -3
- package/dist/{safe-notification-target-2rkvkmw8.js → safe-notification-target-zcpchea6.js} +2 -2
- package/dist/search-archive-qbhp7e89.js +21 -0
- package/dist/{search-6ztbx25v.js → search-hp4g3g9v.js} +22 -21
- package/dist/{sqlite-fsp0sf3r.js → sqlite-d67n6dtr.js} +1 -1
- package/dist/{storage-memory-yxxc5v4n.js → storage-memory-9g882j7a.js} +2 -2
- package/dist/{storage-tags-1kets0q8.js → storage-tags-m2qcp1g2.js} +7 -5
- package/dist/subagent-entry.js +26 -25
- package/dist/tag-snapshot-worker-pi.js +66 -55
- package/package.json +1 -1
- package/dist/embedding-backfill-vwag34t0.js +0 -23
- package/dist/search-archive-jg4a1kcx.js +0 -20
|
@@ -4,54 +4,60 @@ import {
|
|
|
4
4
|
withSqliteBackgroundWriter2,
|
|
5
5
|
withoutSqliteTransformPass2,
|
|
6
6
|
isTransientSqliteError2
|
|
7
|
-
} from "./index-
|
|
7
|
+
} from "./index-hws5f0z9.js";
|
|
8
8
|
import {
|
|
9
9
|
estimateTokens
|
|
10
|
-
} from "./index-
|
|
10
|
+
} from "./index-my0dn413.js";
|
|
11
11
|
import {
|
|
12
12
|
getHarness2
|
|
13
13
|
} from "./index-0h2mkab2.js";
|
|
14
14
|
import {
|
|
15
15
|
sanitizeDiagnosticText,
|
|
16
16
|
log2
|
|
17
|
-
} from "./index-
|
|
17
|
+
} from "./index-fgs78jyd.js";
|
|
18
18
|
import {
|
|
19
19
|
SYNAPSE_DEFAULT_MODEL,
|
|
20
20
|
isSynapseEmbeddingTruncated,
|
|
21
21
|
getSynapseBatchRequestKey,
|
|
22
22
|
SynapseEmbeddingProvider
|
|
23
|
-
} from "./index-
|
|
23
|
+
} from "./index-jxjr7kz9.js";
|
|
24
24
|
import {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
25
|
+
createWorkerShutdown
|
|
26
|
+
} from "./index-54wmg4rj.js";
|
|
27
|
+
import {
|
|
28
|
+
DEFAULT_COMPARTMENT_CHUNK_MAX_INPUT_TOKENS2,
|
|
29
|
+
CHUNK_WINDOW_SAFETY_RATIO2,
|
|
30
|
+
normalizeCompartmentChunkMaxInputTokens2,
|
|
31
|
+
buildCanonicalChunkTextFromFts2,
|
|
32
|
+
buildCompartmentSummaryFallbackText2,
|
|
33
|
+
chunkCanonicalText2,
|
|
34
|
+
chunkEmbeddingWindowsAreCurrent2,
|
|
35
|
+
replaceCompartmentChunkEmbeddings2,
|
|
36
|
+
loadUnembeddedShadowChunkCandidates2,
|
|
37
|
+
loadUnembeddedCompartmentChunkCandidatesPolite2,
|
|
38
|
+
recordChunkEmbedBackoff2,
|
|
39
|
+
chunkWindowSourceKey2,
|
|
40
|
+
loadUnembeddedSessionChunkCandidatesPolite2,
|
|
41
|
+
countSessionCompartmentEmbedCoverage2,
|
|
42
|
+
countSessionCompartmentEmbedCoveragePolite2,
|
|
43
|
+
countUnembeddedSessionCompartmentsPolite2
|
|
44
|
+
} from "./index-5n5zxs8e.js";
|
|
42
45
|
import {
|
|
43
46
|
DEFAULT_LOCAL_EMBEDDING_MODEL
|
|
44
47
|
} from "./index-bxmf4dhr.js";
|
|
45
48
|
import {
|
|
46
49
|
embeddingModelsMatch,
|
|
47
50
|
resolveEmbeddingTextPrefixes,
|
|
51
|
+
getCachedLocalEmbeddingPooling,
|
|
52
|
+
logLocalEmbeddingPoolingDecisionOnce,
|
|
53
|
+
logLocalEmbeddingPoolingUnavailableOnce,
|
|
48
54
|
getEmbeddingProviderIdentity,
|
|
49
55
|
dominantEmbeddingFailure,
|
|
50
56
|
LocalEmbeddingProvider
|
|
51
|
-
} from "./index-
|
|
57
|
+
} from "./index-e19qtjj0.js";
|
|
52
58
|
import {
|
|
53
59
|
setBootQuietPeriodForTests
|
|
54
|
-
} from "./index-
|
|
60
|
+
} from "./index-p63nwn5v.js";
|
|
55
61
|
import {
|
|
56
62
|
isEmbeddingHostBusy2
|
|
57
63
|
} from "./index-9p40dgkm.js";
|
|
@@ -62,7 +68,7 @@ import {
|
|
|
62
68
|
acquireGitSweepLease,
|
|
63
69
|
renewGitSweepLease,
|
|
64
70
|
releaseGitSweepLease
|
|
65
|
-
} from "./index-
|
|
71
|
+
} from "./index-qerzchrs.js";
|
|
66
72
|
import {
|
|
67
73
|
saveEmbeddingIfHashMatches,
|
|
68
74
|
getMemoryEmbedCoverage,
|
|
@@ -70,7 +76,7 @@ import {
|
|
|
70
76
|
} from "./index-yhzhdp3m.js";
|
|
71
77
|
import {
|
|
72
78
|
logSlowWriteTransaction
|
|
73
|
-
} from "./index-
|
|
79
|
+
} from "./index-hqw0rt9k.js";
|
|
74
80
|
|
|
75
81
|
// ../plugin/src/hooks/magic-context/embed-session-state.ts
|
|
76
82
|
var embedPauseBySession = new Set;
|
|
@@ -252,7 +258,7 @@ function responseSlots(items, inputCount) {
|
|
|
252
258
|
return slots;
|
|
253
259
|
}
|
|
254
260
|
function capEmbeddingInput(input, maxInputTokens, purpose) {
|
|
255
|
-
const ratio = purpose === "query" ?
|
|
261
|
+
const ratio = purpose === "query" ? CHUNK_WINDOW_SAFETY_RATIO2 : 1;
|
|
256
262
|
const budget = Math.max(1, Math.floor(maxInputTokens * ratio));
|
|
257
263
|
if (estimateTokens(input) <= budget)
|
|
258
264
|
return input;
|
|
@@ -362,12 +368,12 @@ class OpenAICompatibleEmbeddingProvider {
|
|
|
362
368
|
this.truncate = options.truncate?.trim() ?? "";
|
|
363
369
|
this.rateLimitKey = rateLimitStateKey(this.endpoint, this.apiKey);
|
|
364
370
|
const maxInputTokensSet = typeof options.maxInputTokens === "number" && Number.isFinite(options.maxInputTokens);
|
|
365
|
-
this.maxInputTokens = maxInputTokensSet ? Math.max(1, Math.floor(options.maxInputTokens)) :
|
|
371
|
+
this.maxInputTokens = maxInputTokensSet ? Math.max(1, Math.floor(options.maxInputTokens)) : DEFAULT_COMPARTMENT_CHUNK_MAX_INPUT_TOKENS2;
|
|
366
372
|
if (!maxInputTokensSet && this.endpoint && this.model) {
|
|
367
373
|
const warningKey = `${this.endpoint}\x00${this.model}`;
|
|
368
374
|
if (!maxInputTokensWarnings.has(warningKey)) {
|
|
369
375
|
maxInputTokensWarnings.add(warningKey);
|
|
370
|
-
log2(`[magic-context] embedding.max_input_tokens is not set for openai-compatible model "${sanitizeDiagnosticText(this.model)}"; chunk embeddings use the ${
|
|
376
|
+
log2(`[magic-context] embedding.max_input_tokens is not set for openai-compatible model "${sanitizeDiagnosticText(this.model)}"; chunk embeddings use the ${DEFAULT_COMPARTMENT_CHUNK_MAX_INPUT_TOKENS2}-token default, which is sized for the bundled local model and splits history into small pieces. Set embedding.max_input_tokens to the model's input limit (changing it re-embeds stored chunks once).`);
|
|
371
377
|
}
|
|
372
378
|
}
|
|
373
379
|
this.modelId = getEmbeddingProviderIdentity({
|
|
@@ -711,6 +717,7 @@ function createChunkEmbeddingWriter(db) {
|
|
|
711
717
|
const entry = new URL(import.meta.url.endsWith(".ts") ? "./chunk-embedding-write-worker.ts" : "./chunk-embedding-write-worker.js", import.meta.url);
|
|
712
718
|
const timeout = db.prepare("PRAGMA busy_timeout").get().timeout;
|
|
713
719
|
const worker = inRootAsyncContext2(() => new Worker(entry, { workerData: { path, harness: getHarness2(), timeout } }));
|
|
720
|
+
const shutdown = createWorkerShutdown(worker, "chunk-embedding-writer", timeout + 2000);
|
|
714
721
|
let pending;
|
|
715
722
|
let failure;
|
|
716
723
|
let deadline;
|
|
@@ -741,7 +748,7 @@ function createChunkEmbeddingWriter(db) {
|
|
|
741
748
|
pending = { resolve, reject };
|
|
742
749
|
deadline = inRootAsyncContext2(() => setTimeout(() => {
|
|
743
750
|
fail(new Error("chunk embedding database operation timed out; coverage will be rechecked"));
|
|
744
|
-
|
|
751
|
+
shutdown.close();
|
|
745
752
|
}, 30000));
|
|
746
753
|
deadline.unref();
|
|
747
754
|
worker.postMessage(message);
|
|
@@ -773,7 +780,7 @@ function createChunkEmbeddingWriter(db) {
|
|
|
773
780
|
release: (project, holder) => request({ kind: "release", project, holder }),
|
|
774
781
|
async close() {
|
|
775
782
|
clearTimeout(deadline);
|
|
776
|
-
await
|
|
783
|
+
await shutdown.close();
|
|
777
784
|
}
|
|
778
785
|
};
|
|
779
786
|
}
|
|
@@ -1219,7 +1226,7 @@ function resolveEmbeddingConfig(config) {
|
|
|
1219
1226
|
model: config?.model?.trim() || DEFAULT_LOCAL_EMBEDDING_MODEL,
|
|
1220
1227
|
local_runtime: config?.local_runtime ?? "auto",
|
|
1221
1228
|
...config?.max_input_tokens ? {
|
|
1222
|
-
max_input_tokens:
|
|
1229
|
+
max_input_tokens: normalizeCompartmentChunkMaxInputTokens2(config.max_input_tokens)
|
|
1223
1230
|
} : {},
|
|
1224
1231
|
...config?.local_dtype ? { local_dtype: config.local_dtype } : {}
|
|
1225
1232
|
};
|
|
@@ -1240,7 +1247,7 @@ function resolveEmbeddingConfig(config) {
|
|
|
1240
1247
|
...config.document_prefix !== undefined ? { document_prefix: config.document_prefix } : {},
|
|
1241
1248
|
...truncate ? { truncate } : {},
|
|
1242
1249
|
...config.max_input_tokens ? {
|
|
1243
|
-
max_input_tokens:
|
|
1250
|
+
max_input_tokens: normalizeCompartmentChunkMaxInputTokens2(config.max_input_tokens)
|
|
1244
1251
|
} : {}
|
|
1245
1252
|
};
|
|
1246
1253
|
}
|
|
@@ -1253,7 +1260,7 @@ function resolveEmbeddingConfig(config) {
|
|
|
1253
1260
|
return {
|
|
1254
1261
|
provider: "synapse",
|
|
1255
1262
|
model: synapse.model?.trim() || "gte-modernbert-base-f16",
|
|
1256
|
-
max_input_tokens:
|
|
1263
|
+
max_input_tokens: normalizeCompartmentChunkMaxInputTokens2(descriptor?.max_tokens ?? synapse.max_input_tokens),
|
|
1257
1264
|
...synapse.synapse_connection_file ? { synapse_connection_file: synapse.synapse_connection_file } : {},
|
|
1258
1265
|
...synapse.synapse_fingerprint ? { synapse_fingerprint: synapse.synapse_fingerprint } : {},
|
|
1259
1266
|
...typeof synapse.synapse_table_epoch === "number" ? { synapse_table_epoch: synapse.synapse_table_epoch } : {},
|
|
@@ -1341,7 +1348,7 @@ function getChunkEmbeddingModelId(config, providerIdentity) {
|
|
|
1341
1348
|
const chunkIdentity = {
|
|
1342
1349
|
providerIdentity,
|
|
1343
1350
|
chunkerVersion: 2,
|
|
1344
|
-
maxInputTokens:
|
|
1351
|
+
maxInputTokens: normalizeCompartmentChunkMaxInputTokens2("max_input_tokens" in config ? config.max_input_tokens : undefined),
|
|
1345
1352
|
truncate: config.provider === "openai-compatible" ? config.truncate ?? "" : ""
|
|
1346
1353
|
};
|
|
1347
1354
|
return `${providerIdentity}:chunk:${sha256Prefix(stableStringify(chunkIdentity))}`;
|
|
@@ -1667,6 +1674,17 @@ async function drainStaleEmbeddingIdentitiesForProject2(db, projectIdentity, bud
|
|
|
1667
1674
|
}
|
|
1668
1675
|
function registerProjectEmbedding2(db, projectIdentity, config, features, sourceDirectory) {
|
|
1669
1676
|
const resolvedConfig = resolveEmbeddingConfig(config);
|
|
1677
|
+
if (resolvedConfig.provider === "local") {
|
|
1678
|
+
const pooling = getCachedLocalEmbeddingPooling(resolvedConfig.model?.trim() || DEFAULT_LOCAL_EMBEDDING_MODEL);
|
|
1679
|
+
if (pooling?.status === "unresolved" || !pooling) {
|
|
1680
|
+
logLocalEmbeddingPoolingUnavailableOnce(resolvedConfig.model?.trim() || DEFAULT_LOCAL_EMBEDDING_MODEL, pooling?.reason ?? "pooling metadata has not been resolved by the background embedding bootstrap", log2);
|
|
1681
|
+
} else {
|
|
1682
|
+
logLocalEmbeddingPoolingDecisionOnce(resolvedConfig.model?.trim() || DEFAULT_LOCAL_EMBEDDING_MODEL, pooling, log2);
|
|
1683
|
+
}
|
|
1684
|
+
if (pooling?.status === "unsupported") {
|
|
1685
|
+
return registerProjectInObservationMode2(db, projectIdentity, sourceDirectory, resolvedConfig, pooling ? `local model pooling is unsupported: ${pooling.reason}` : "local model pooling metadata has not been resolved");
|
|
1686
|
+
}
|
|
1687
|
+
}
|
|
1670
1688
|
const providerIdentity = getEmbeddingProviderIdentity(resolvedConfig);
|
|
1671
1689
|
const runtimeFingerprint = getRuntimeFingerprint(resolvedConfig);
|
|
1672
1690
|
const chunkModelId = getChunkEmbeddingModelId(resolvedConfig, providerIdentity);
|
|
@@ -1862,7 +1880,7 @@ function shadowBackfillMissingBase(scope, primaryModelId, shadowModelId, project
|
|
|
1862
1880
|
}
|
|
1863
1881
|
function shadowBackfillMissingIds(db, projectIdentity, scope, primaryModelId, shadowModelId, limit, shadowMaxInputTokens) {
|
|
1864
1882
|
if (scope === "chunk") {
|
|
1865
|
-
return
|
|
1883
|
+
return loadUnembeddedShadowChunkCandidates2(db, projectIdentity, primaryModelId, shadowModelId, limit, shadowMaxInputTokens).map((candidate) => String(candidate.id));
|
|
1866
1884
|
}
|
|
1867
1885
|
const { sql, params, orderBy } = shadowBackfillMissingBase(scope, primaryModelId, shadowModelId, projectIdentity);
|
|
1868
1886
|
const rows = db.prepare(`${sql}${orderBy} LIMIT ?`).all(...params, limit);
|
|
@@ -1870,7 +1888,7 @@ function shadowBackfillMissingIds(db, projectIdentity, scope, primaryModelId, sh
|
|
|
1870
1888
|
}
|
|
1871
1889
|
function countShadowBackfillMissing(db, projectIdentity, scope, primaryModelId, shadowModelId, shadowMaxInputTokens) {
|
|
1872
1890
|
if (scope === "chunk") {
|
|
1873
|
-
return
|
|
1891
|
+
return loadUnembeddedShadowChunkCandidates2(db, projectIdentity, primaryModelId, shadowModelId, Number.MAX_SAFE_INTEGER, shadowMaxInputTokens).length;
|
|
1874
1892
|
}
|
|
1875
1893
|
const { sql, params } = shadowBackfillMissingBase(scope, primaryModelId, shadowModelId, projectIdentity);
|
|
1876
1894
|
return db.prepare(`SELECT COUNT(*) AS count FROM (${sql})`).get(...params).count;
|
|
@@ -1879,7 +1897,7 @@ function shadowModelIdForScope(registration, scope) {
|
|
|
1879
1897
|
return scope === "chunk" ? registration.chunkModelId : registration.modelId;
|
|
1880
1898
|
}
|
|
1881
1899
|
function shadowMaxInputTokensFor(registration) {
|
|
1882
|
-
return
|
|
1900
|
+
return normalizeCompartmentChunkMaxInputTokens2("max_input_tokens" in registration.config ? registration.config.max_input_tokens : undefined);
|
|
1883
1901
|
}
|
|
1884
1902
|
function shadowBackfillCohortFingerprint(db, projectIdentity, scope, primaryModelId) {
|
|
1885
1903
|
if (scope === "memory") {
|
|
@@ -2217,14 +2235,14 @@ async function processShadowQueueItem(item) {
|
|
|
2217
2235
|
let ftsMappingIncomplete = false;
|
|
2218
2236
|
let emptyCanonicalText = false;
|
|
2219
2237
|
for (const candidate of candidates) {
|
|
2220
|
-
const mappedText =
|
|
2238
|
+
const mappedText = buildCanonicalChunkTextFromFts2(db, candidate.session_id, candidate.start_message, candidate.end_message);
|
|
2221
2239
|
if (mappedText === null) {
|
|
2222
2240
|
ftsMappingIncomplete = true;
|
|
2223
2241
|
} else {
|
|
2224
|
-
const text = mappedText ||
|
|
2242
|
+
const text = mappedText || buildCompartmentSummaryFallbackText2(db, candidate.id);
|
|
2225
2243
|
const shadowMaxInputTokens = shadowMaxInputTokensFor(registration);
|
|
2226
|
-
const windows =
|
|
2227
|
-
const windowSourceKey =
|
|
2244
|
+
const windows = chunkCanonicalText2(text, candidate.start_message, candidate.end_message, shadowMaxInputTokens);
|
|
2245
|
+
const windowSourceKey = chunkWindowSourceKey2(text, candidate.start_message, candidate.end_message, shadowMaxInputTokens);
|
|
2228
2246
|
if (windows.length > 0)
|
|
2229
2247
|
prepared.push({ candidate, windows, windowSourceKey });
|
|
2230
2248
|
else
|
|
@@ -2265,7 +2283,7 @@ async function processShadowQueueItem(item) {
|
|
|
2265
2283
|
] : [];
|
|
2266
2284
|
});
|
|
2267
2285
|
if (rows.length === item.windows.length) {
|
|
2268
|
-
|
|
2286
|
+
replaceCompartmentChunkEmbeddings2(db, rows, item.windowSourceKey);
|
|
2269
2287
|
writes += 1;
|
|
2270
2288
|
} else {
|
|
2271
2289
|
partialVectorSet = true;
|
|
@@ -2400,7 +2418,7 @@ function getProjectChunkEmbeddingModelId2(projectIdentity) {
|
|
|
2400
2418
|
function getProjectEmbeddingMaxInputTokens2(projectIdentity) {
|
|
2401
2419
|
const registration = projectRegistrations.get(projectIdentity);
|
|
2402
2420
|
const configMax = registration?.config && "max_input_tokens" in registration.config ? registration.config.max_input_tokens : undefined;
|
|
2403
|
-
return
|
|
2421
|
+
return normalizeCompartmentChunkMaxInputTokens2(registration?.provider?.maxInputTokens ?? configMax);
|
|
2404
2422
|
}
|
|
2405
2423
|
function getOrCreateProjectProvider(registration) {
|
|
2406
2424
|
if (registration.providerIdentity === OFF_PROVIDER_IDENTITY || registration.observationMode) {
|
|
@@ -2658,7 +2676,7 @@ async function embedCompartmentChunkBatch(db, projectIdentity, batchSize, signal
|
|
|
2658
2676
|
const priorModels = db.prepare(`SELECT COUNT(*) AS total,
|
|
2659
2677
|
COALESCE(MAX(model_id = ?), 0) AS current
|
|
2660
2678
|
FROM compartment_chunk_embeddings WHERE compartment_id = ?`);
|
|
2661
|
-
const candidates = await
|
|
2679
|
+
const candidates = await loadUnembeddedCompartmentChunkCandidatesPolite2(db, projectIdentity, snapshot.chunkModelId, batchSize, getProjectEmbeddingMaxInputTokens2(projectIdentity), true, (candidate) => {
|
|
2662
2680
|
const activity = activeEmbeddingSessions.get(candidate.sessionId);
|
|
2663
2681
|
if (activity?.project === projectIdentity && activity.model === snapshot.chunkModelId && !embedPauseBySession.has(candidate.sessionId))
|
|
2664
2682
|
return true;
|
|
@@ -2684,27 +2702,27 @@ async function embedCandidateChunkBatch(db, projectIdentity, modelId, candidates
|
|
|
2684
2702
|
const prepared = [];
|
|
2685
2703
|
for (const candidate of candidates) {
|
|
2686
2704
|
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
2687
|
-
const mappedText =
|
|
2705
|
+
const mappedText = buildCanonicalChunkTextFromFts2(db, candidate.sessionId, candidate.startMessage, candidate.endMessage);
|
|
2688
2706
|
if (mappedText === null)
|
|
2689
2707
|
continue;
|
|
2690
|
-
const canonicalText = mappedText ||
|
|
2708
|
+
const canonicalText = mappedText || buildCompartmentSummaryFallbackText2(db, candidate.id);
|
|
2691
2709
|
if (canonicalText.length === 0) {
|
|
2692
2710
|
if (writer)
|
|
2693
2711
|
await writer.backoff(candidate, projectIdentity, modelId);
|
|
2694
2712
|
else
|
|
2695
|
-
|
|
2713
|
+
recordChunkEmbedBackoff2(db, candidate, projectIdentity, modelId);
|
|
2696
2714
|
noWork.push(candidate.id);
|
|
2697
2715
|
continue;
|
|
2698
2716
|
}
|
|
2699
|
-
const windows =
|
|
2700
|
-
if (windows.length === 0 ||
|
|
2717
|
+
const windows = chunkCanonicalText2(canonicalText, candidate.startMessage, candidate.endMessage, maxInputTokens);
|
|
2718
|
+
if (windows.length === 0 || chunkEmbeddingWindowsAreCurrent2(db, candidate.id, modelId, windows, projectIdentity)) {
|
|
2701
2719
|
noWork.push(candidate.id);
|
|
2702
2720
|
continue;
|
|
2703
2721
|
}
|
|
2704
2722
|
prepared.push({
|
|
2705
2723
|
candidate,
|
|
2706
2724
|
windows,
|
|
2707
|
-
windowSourceKey:
|
|
2725
|
+
windowSourceKey: chunkWindowSourceKey2(canonicalText, candidate.startMessage, candidate.endMessage, maxInputTokens)
|
|
2708
2726
|
});
|
|
2709
2727
|
}
|
|
2710
2728
|
if (prepared.length === 0)
|
|
@@ -2768,7 +2786,7 @@ async function embedCandidateChunkBatch(db, projectIdentity, modelId, candidates
|
|
|
2768
2786
|
if (writer)
|
|
2769
2787
|
await writer.replace(rows, item.windowSourceKey);
|
|
2770
2788
|
else
|
|
2771
|
-
|
|
2789
|
+
replaceCompartmentChunkEmbeddings2(db, rows, item.windowSourceKey);
|
|
2772
2790
|
persistedIds.add(item.candidate.id);
|
|
2773
2791
|
enqueueShadowEmbeddingItems2(projectIdentity, "chunk", [
|
|
2774
2792
|
String(item.candidate.id)
|
|
@@ -2796,7 +2814,7 @@ async function embedCandidateChunkBatch(db, projectIdentity, modelId, candidates
|
|
|
2796
2814
|
if (writer)
|
|
2797
2815
|
await writer.backoff(item.candidate, projectIdentity, modelId);
|
|
2798
2816
|
else
|
|
2799
|
-
|
|
2817
|
+
recordChunkEmbedBackoff2(db, item.candidate, projectIdentity, modelId);
|
|
2800
2818
|
failed.push(item.candidate.id);
|
|
2801
2819
|
}
|
|
2802
2820
|
}
|
|
@@ -2870,7 +2888,7 @@ async function embedSessionCompartmentChunks2(db, projectIdentity, sessionId, op
|
|
|
2870
2888
|
else
|
|
2871
2889
|
recordSessionProjectIdentity(db, sessionId, projectIdentity);
|
|
2872
2890
|
const maxInputTokens = getProjectEmbeddingMaxInputTokens2(projectIdentity);
|
|
2873
|
-
const total = writer ? await writer.count(projectIdentity, sessionId, snapshot.chunkModelId, maxInputTokens) : await
|
|
2891
|
+
const total = writer ? await writer.count(projectIdentity, sessionId, snapshot.chunkModelId, maxInputTokens) : await countUnembeddedSessionCompartmentsPolite2(db, projectIdentity, sessionId, snapshot.chunkModelId, maxInputTokens);
|
|
2874
2892
|
const holderId = `session-embed-${randomUUID()}`;
|
|
2875
2893
|
const lease = writer ? await writer.acquire(projectIdentity, holderId) : acquireGitSweepLease(db, projectIdentity, holderId, { ignoreCooldown: true });
|
|
2876
2894
|
if (!lease.acquired)
|
|
@@ -2913,7 +2931,7 @@ async function embedSessionCompartmentChunks2(db, projectIdentity, sessionId, op
|
|
|
2913
2931
|
break;
|
|
2914
2932
|
}
|
|
2915
2933
|
}
|
|
2916
|
-
const candidates = writer ? await writer.candidates(projectIdentity, sessionId, snapshot.chunkModelId, batchSize, [...skipIds, ...failedIds], maxInputTokens) : await
|
|
2934
|
+
const candidates = writer ? await writer.candidates(projectIdentity, sessionId, snapshot.chunkModelId, batchSize, [...skipIds, ...failedIds], maxInputTokens) : await loadUnembeddedSessionChunkCandidatesPolite2(db, projectIdentity, sessionId, snapshot.chunkModelId, batchSize, [...skipIds, ...failedIds], maxInputTokens, true);
|
|
2917
2935
|
if (candidates.length === 0)
|
|
2918
2936
|
break;
|
|
2919
2937
|
const {
|
|
@@ -2963,7 +2981,7 @@ async function embedSessionCompartmentChunks2(db, projectIdentity, sessionId, op
|
|
|
2963
2981
|
if (aborted)
|
|
2964
2982
|
return { status: "aborted", embedded, total, failed: failedIds.length };
|
|
2965
2983
|
if (providerDown || failedIds.length > 0) {
|
|
2966
|
-
const remaining = Math.max(failedIds.length, (writer ? await writer.count(projectIdentity, sessionId, snapshot.chunkModelId, maxInputTokens) : await
|
|
2984
|
+
const remaining = Math.max(failedIds.length, (writer ? await writer.count(projectIdentity, sessionId, snapshot.chunkModelId, maxInputTokens) : await countUnembeddedSessionCompartmentsPolite2(db, projectIdentity, sessionId, snapshot.chunkModelId, maxInputTokens)) - skipIds.length);
|
|
2967
2985
|
if (remaining > 0) {
|
|
2968
2986
|
return {
|
|
2969
2987
|
status: "stalled",
|
|
@@ -2991,7 +3009,7 @@ function getEmbeddingCoverageStatus2(db, projectIdentity, sessionId) {
|
|
|
2991
3009
|
shadowBackfillStalls: listShadowBackfillStalls2(db, projectIdentity)
|
|
2992
3010
|
};
|
|
2993
3011
|
}
|
|
2994
|
-
const session =
|
|
3012
|
+
const session = countSessionCompartmentEmbedCoverage2(db, projectIdentity, sessionId, snapshot.chunkModelId, getProjectEmbeddingMaxInputTokens2(projectIdentity));
|
|
2995
3013
|
const memories = snapshot.enabled ? getMemoryEmbedCoverage(db, projectIdentity, snapshot.modelId) : { embedded: 0, total: 0, memoryEnabled: false };
|
|
2996
3014
|
const gitEnabled = snapshot.gitCommitEnabled;
|
|
2997
3015
|
const commits = gitEnabled ? {
|
|
@@ -3015,7 +3033,7 @@ async function getAutoEmbeddingSessionCoverage2(db, projectIdentity, sessionId)
|
|
|
3015
3033
|
if (!snapshot?.historyEnabled || snapshot.chunkModelId === "off") {
|
|
3016
3034
|
return { enabled: false, embedded: 0, total: 0 };
|
|
3017
3035
|
}
|
|
3018
|
-
const coverage = await
|
|
3036
|
+
const coverage = await countSessionCompartmentEmbedCoveragePolite2(db, projectIdentity, sessionId, snapshot.chunkModelId, getProjectEmbeddingMaxInputTokens2(projectIdentity));
|
|
3019
3037
|
return { enabled: true, ...coverage };
|
|
3020
3038
|
}
|
|
3021
3039
|
async function sweepAllRegisteredProjects2(db, batchSize = 10) {
|
|
@@ -3,11 +3,11 @@ import {
|
|
|
3
3
|
} from "./index-0h2mkab2.js";
|
|
4
4
|
import {
|
|
5
5
|
getMagicContextStorageDir
|
|
6
|
-
} from "./index-
|
|
6
|
+
} from "./index-fgs78jyd.js";
|
|
7
7
|
import {
|
|
8
8
|
isPidAlive,
|
|
9
9
|
readProcessStartTime
|
|
10
|
-
} from "./index-
|
|
10
|
+
} from "./index-n4wyxcgr.js";
|
|
11
11
|
import {
|
|
12
12
|
resolveOpenCodeDbPath,
|
|
13
13
|
assertOpenCodeStoreGeneration
|
|
@@ -18,23 +18,23 @@ import {
|
|
|
18
18
|
prepareCachedStatement2,
|
|
19
19
|
withSqliteBackgroundWriter2,
|
|
20
20
|
withoutSqliteTransformPass2
|
|
21
|
-
} from "./index-
|
|
21
|
+
} from "./index-hws5f0z9.js";
|
|
22
22
|
import {
|
|
23
23
|
removeSystemReminders,
|
|
24
24
|
removeNestedBlocks,
|
|
25
25
|
hasMeaningfulUserText2,
|
|
26
26
|
extractTexts2
|
|
27
|
-
} from "./index-
|
|
27
|
+
} from "./index-my0dn413.js";
|
|
28
28
|
import {
|
|
29
29
|
recordMessageFtsRowid2,
|
|
30
30
|
recordIndexedMessageTime2,
|
|
31
31
|
messageFtsOrdinalRangeIsMapped2,
|
|
32
32
|
getMessageFtsRowidMapBackfillProgress2,
|
|
33
33
|
deleteUnmappedMessageFtsRows2
|
|
34
|
-
} from "./index-
|
|
34
|
+
} from "./index-rgfb753z.js";
|
|
35
35
|
import {
|
|
36
|
-
|
|
37
|
-
} from "./index-
|
|
36
|
+
deleteChunkEmbedBackoffForSession2
|
|
37
|
+
} from "./index-5n5zxs8e.js";
|
|
38
38
|
import {
|
|
39
39
|
closeQuietly,
|
|
40
40
|
TAG_TOMBSTONE_OWNER_PREFIX,
|
|
@@ -43,16 +43,16 @@ import {
|
|
|
43
43
|
tagRevisionKey,
|
|
44
44
|
tagIdentityRevisionKey,
|
|
45
45
|
deleteTagIdentityRevisions
|
|
46
|
-
} from "./index-
|
|
46
|
+
} from "./index-w1avzkdt.js";
|
|
47
47
|
import {
|
|
48
48
|
cleanUserText2
|
|
49
|
-
} from "./index-
|
|
49
|
+
} from "./index-zhwwp8zz.js";
|
|
50
50
|
import {
|
|
51
51
|
sameProjectDirectory
|
|
52
52
|
} from "./index-wrr9rp9a.js";
|
|
53
53
|
import {
|
|
54
54
|
logSlowWriteTransaction
|
|
55
|
-
} from "./index-
|
|
55
|
+
} from "./index-hqw0rt9k.js";
|
|
56
56
|
import {
|
|
57
57
|
ensurePrivateStorageDirectorySync,
|
|
58
58
|
writeStorageFileSync,
|
|
@@ -63,7 +63,14 @@ import {
|
|
|
63
63
|
|
|
64
64
|
// ../plugin/src/hooks/magic-context/lkg-recovery-fence.ts
|
|
65
65
|
import { createHash as createHash2, randomUUID as randomUUID2 } from "node:crypto";
|
|
66
|
-
import {
|
|
66
|
+
import {
|
|
67
|
+
lstatSync,
|
|
68
|
+
opendirSync,
|
|
69
|
+
readdirSync as readdirSync2,
|
|
70
|
+
readFileSync as readFileSync2,
|
|
71
|
+
rmdirSync,
|
|
72
|
+
rmSync as rmSync2
|
|
73
|
+
} from "node:fs";
|
|
67
74
|
import { basename, dirname, join as join2 } from "node:path";
|
|
68
75
|
|
|
69
76
|
// ../plugin/src/shared/bounded-session-map.ts
|
|
@@ -250,6 +257,58 @@ var hash = (value) => createHash2("sha256").update(value).digest("hex");
|
|
|
250
257
|
function lkgRecoveryFencePath(sessionId) {
|
|
251
258
|
return join2(getMagicContextStorageDir(), "lkg-recovery-fences", `${hash(sessionId)}.json`);
|
|
252
259
|
}
|
|
260
|
+
var lockSweepDirectory;
|
|
261
|
+
function closeLkgLockSweepDirectory() {
|
|
262
|
+
lockSweepDirectory?.dir.closeSync();
|
|
263
|
+
lockSweepDirectory = undefined;
|
|
264
|
+
}
|
|
265
|
+
function takeLkgRecoveryLockSweepPage(maxEntries = 200) {
|
|
266
|
+
const path = join2(getMagicContextStorageDir(), "lkg-recovery-fences");
|
|
267
|
+
if (lockSweepDirectory?.path !== path)
|
|
268
|
+
closeLkgLockSweepDirectory();
|
|
269
|
+
const names = [];
|
|
270
|
+
try {
|
|
271
|
+
lockSweepDirectory ??= { path, dir: opendirSync(path) };
|
|
272
|
+
for (let i = 0;i < Math.min(200, Math.max(1, maxEntries)); i++) {
|
|
273
|
+
const entry = lockSweepDirectory.dir.readSync();
|
|
274
|
+
if (!entry) {
|
|
275
|
+
closeLkgLockSweepDirectory();
|
|
276
|
+
break;
|
|
277
|
+
}
|
|
278
|
+
if (entry.isDirectory() && /^[a-f0-9]{64}\.json\.locks$/.test(entry.name))
|
|
279
|
+
names.push(entry.name);
|
|
280
|
+
}
|
|
281
|
+
} catch {
|
|
282
|
+
closeLkgLockSweepDirectory();
|
|
283
|
+
}
|
|
284
|
+
return names;
|
|
285
|
+
}
|
|
286
|
+
function sweepEmptyLkgRecoveryLockDirectories(names, retainedSessionIds) {
|
|
287
|
+
if (!durableFencesSupported())
|
|
288
|
+
return 0;
|
|
289
|
+
const retainedHashes = new Set(Array.from(retainedSessionIds, hash));
|
|
290
|
+
const root = join2(getMagicContextStorageDir(), "lkg-recovery-fences");
|
|
291
|
+
let removed = 0;
|
|
292
|
+
for (const name of names.slice(0, 200)) {
|
|
293
|
+
if (!/^[a-f0-9]{64}\.json\.locks$/.test(name) || retainedHashes.has(name.slice(0, 64)))
|
|
294
|
+
continue;
|
|
295
|
+
const path = join2(root, name);
|
|
296
|
+
try {
|
|
297
|
+
try {
|
|
298
|
+
lstatSync(path.slice(0, -".locks".length));
|
|
299
|
+
continue;
|
|
300
|
+
} catch (error) {
|
|
301
|
+
if (error.code !== "ENOENT")
|
|
302
|
+
continue;
|
|
303
|
+
}
|
|
304
|
+
if (!lstatSync(path).isDirectory())
|
|
305
|
+
continue;
|
|
306
|
+
rmdirSync(path);
|
|
307
|
+
removed++;
|
|
308
|
+
} catch {}
|
|
309
|
+
}
|
|
310
|
+
return removed;
|
|
311
|
+
}
|
|
253
312
|
function metadata(slot) {
|
|
254
313
|
return [
|
|
255
314
|
slot.inputIdSeq,
|
|
@@ -631,6 +690,12 @@ function closeConnection(connection) {
|
|
|
631
690
|
counters.readersClosed += 1;
|
|
632
691
|
}
|
|
633
692
|
}
|
|
693
|
+
function messageTimesQuery(count) {
|
|
694
|
+
return `SELECT id, COALESCE(time_created, json_extract(data, '$.time.created')) AS created,
|
|
695
|
+
json_extract(data, '$.time.completed') AS completed
|
|
696
|
+
FROM session_message WHERE +session_id = ? AND id IN (${Array.from({ length: count }, () => "?").join(",")})`;
|
|
697
|
+
}
|
|
698
|
+
|
|
634
699
|
class V2StoreReader {
|
|
635
700
|
path;
|
|
636
701
|
pool;
|
|
@@ -853,9 +918,7 @@ class V2StoreReader {
|
|
|
853
918
|
const times = new Map;
|
|
854
919
|
for (let offset = 0;offset < ids.length; offset += 500) {
|
|
855
920
|
const batch = ids.slice(offset, offset + 500);
|
|
856
|
-
const rows = this.prepare(
|
|
857
|
-
json_extract(data, '$.time.completed') AS completed
|
|
858
|
-
FROM session_message WHERE session_id = ? AND id IN (${batch.map(() => "?").join(",")})`).all(sessionID, ...batch);
|
|
921
|
+
const rows = this.prepare(messageTimesQuery(batch.length)).all(sessionID, ...batch);
|
|
859
922
|
for (const row of rows)
|
|
860
923
|
times.set(row.id, {
|
|
861
924
|
created: typeof row.created === "number" ? row.created : undefined,
|
|
@@ -1248,7 +1311,7 @@ function deleteSessionScopedRows(db, sessionIds, harness, options = {}) {
|
|
|
1248
1311
|
fallback.run(tagTombstoneOwnerKey(id, getHarness2()), getHarness2(), ...tagTombstoneOwnerRange(id));
|
|
1249
1312
|
}
|
|
1250
1313
|
for (const sessionId of deletableSessionIds)
|
|
1251
|
-
|
|
1314
|
+
deleteChunkEmbedBackoffForSession2(db, sessionId);
|
|
1252
1315
|
for (const definition of SESSION_SCOPED_TABLES) {
|
|
1253
1316
|
if (definition.table === "message_history_fts") {
|
|
1254
1317
|
cleanupStatement(db, `DELETE FROM message_history_fts
|
|
@@ -1299,7 +1362,7 @@ function deleteSessionScopedRowsSlice(db, sessionId, harness) {
|
|
|
1299
1362
|
cleanupStatement(db, "INSERT OR IGNORE INTO schema_migrations_meta(key,value) VALUES (?,?)").run(tagTombstoneOwnerKey(sessionId, harness), harness);
|
|
1300
1363
|
let remaining = SESSION_CLEANUP_SLICE_ROWS;
|
|
1301
1364
|
const started = performance.now();
|
|
1302
|
-
remaining -=
|
|
1365
|
+
remaining -= deleteChunkEmbedBackoffForSession2(db, sessionId, remaining);
|
|
1303
1366
|
if (remaining <= 0)
|
|
1304
1367
|
return { complete: false, deleted: 0 };
|
|
1305
1368
|
for (const definition of SESSION_SCOPED_TABLES) {
|
|
@@ -1884,14 +1947,20 @@ function harnessSupportsOpenCodeOrphanSweep(harness) {
|
|
|
1884
1947
|
return harness === "opencode" || harness === "opencode2";
|
|
1885
1948
|
}
|
|
1886
1949
|
function getMessageHistoryOrphanSweepState(db, harness) {
|
|
1887
|
-
|
|
1950
|
+
const state = db.prepare("SELECT cursor_session_id, last_swept_at FROM message_history_orphan_sweep WHERE harness = ?").get(harness) ?? {};
|
|
1951
|
+
if (harness === "opencode2") {
|
|
1952
|
+
if (!state.cursor_session_id?.startsWith("session_v2:"))
|
|
1953
|
+
return {};
|
|
1954
|
+
return { ...state, cursor_session_id: state.cursor_session_id.slice("session_v2:".length) };
|
|
1955
|
+
}
|
|
1956
|
+
return state;
|
|
1888
1957
|
}
|
|
1889
1958
|
function persistMessageHistoryOrphanSweepState(db, cursor, lastSweptAt, harness) {
|
|
1890
1959
|
db.prepare(`INSERT INTO message_history_orphan_sweep (harness, cursor_session_id, last_swept_at)
|
|
1891
1960
|
VALUES (?, ?, ?)
|
|
1892
1961
|
ON CONFLICT(harness) DO UPDATE SET
|
|
1893
1962
|
cursor_session_id = excluded.cursor_session_id,
|
|
1894
|
-
last_swept_at = excluded.last_swept_at`).run(harness, cursor, lastSweptAt);
|
|
1963
|
+
last_swept_at = excluded.last_swept_at`).run(harness, harness === "opencode2" ? `session_v2:${cursor}` : cursor, lastSweptAt);
|
|
1895
1964
|
}
|
|
1896
1965
|
function getOpenCodeSessionScopedCandidateSourceSql(harness) {
|
|
1897
1966
|
const sources = SESSION_SCOPED_TABLES.filter((definition) => definition.harnessScoped === true).map((definition) => {
|
|
@@ -1939,13 +2008,14 @@ function* sweepOrphanedOpenCodeMessageIndexesInBackground(db, openReadableOpenCo
|
|
|
1939
2008
|
let v2Reader;
|
|
1940
2009
|
try {
|
|
1941
2010
|
let sessionExists;
|
|
2011
|
+
let liveIds;
|
|
1942
2012
|
if (harness === "opencode2") {
|
|
1943
2013
|
try {
|
|
1944
2014
|
const path = getSqliteDatabasePath2(openCodeDb);
|
|
1945
2015
|
if (!path)
|
|
1946
2016
|
throw new Error("OpenCode 2 source has no durable path");
|
|
1947
2017
|
v2Reader = new V2StoreReader(path);
|
|
1948
|
-
|
|
2018
|
+
liveIds = new Set(v2Reader.sessionIds());
|
|
1949
2019
|
if (liveIds.size === 0)
|
|
1950
2020
|
throw new Error("OpenCode 2 source has no sessions");
|
|
1951
2021
|
sessionExists = (id) => liveIds.has(id);
|
|
@@ -1954,9 +2024,26 @@ function* sweepOrphanedOpenCodeMessageIndexesInBackground(db, openReadableOpenCo
|
|
|
1954
2024
|
return { status: "source_unavailable", scanned: 0, deleted: 0, cursor };
|
|
1955
2025
|
}
|
|
1956
2026
|
} else {
|
|
2027
|
+
liveIds = new Set(openCodeDb.prepare("SELECT id FROM session").all().map((row) => row.id));
|
|
1957
2028
|
const query = openCodeDb.prepare("SELECT 1 FROM session WHERE id = ? LIMIT 1");
|
|
1958
2029
|
sessionExists = (id) => !!query.get(id);
|
|
1959
2030
|
}
|
|
2031
|
+
if (options.fenceLockNames?.length) {
|
|
2032
|
+
const retainedIds = new Set(liveIds);
|
|
2033
|
+
const sources = SESSION_SCOPED_TABLES.map((def) => `SELECT session_id FROM ${def.table}${def.extraPredicate ? ` WHERE ${def.extraPredicate}` : ""}`);
|
|
2034
|
+
for (const row of db.prepare(sources.join(" UNION ")).all()) {
|
|
2035
|
+
if (typeof row.session_id === "string")
|
|
2036
|
+
retainedIds.add(row.session_id);
|
|
2037
|
+
}
|
|
2038
|
+
for (const row of db.prepare("SELECT key FROM schema_migrations_meta WHERE key >= ? AND key < ?").all(TAG_TOMBSTONE_OWNER_PREFIX, "tag_revision_owner;")) {
|
|
2039
|
+
try {
|
|
2040
|
+
const id = JSON.parse(row.key.slice(TAG_TOMBSTONE_OWNER_PREFIX.length, row.key.lastIndexOf(":")));
|
|
2041
|
+
if (typeof id === "string")
|
|
2042
|
+
retainedIds.add(id);
|
|
2043
|
+
} catch {}
|
|
2044
|
+
}
|
|
2045
|
+
sweepEmptyLkgRecoveryLockDirectories(options.fenceLockNames, retainedIds);
|
|
2046
|
+
}
|
|
1960
2047
|
const cutoff = now - safetyAgeMs;
|
|
1961
2048
|
const candidateSourceSql = getOpenCodeSessionScopedCandidateSourceSql(harness);
|
|
1962
2049
|
const candidates = db.prepare(`SELECT session_id
|
|
@@ -2048,4 +2135,4 @@ async function sweepOrphanedOpenCodeMessageIndexesCooperatively2(db, openSource,
|
|
|
2048
2135
|
}));
|
|
2049
2136
|
}
|
|
2050
2137
|
|
|
2051
|
-
export { BoundedSessionMap, LkgRecoveryFenceError, clearLkgFenceProcessState, lkgFenceRequiresRebuild, lkgRecoveryFenceUnclean, ownsLkgDirtyFence, invalidateCleanLkgRecoveryFence, markLkgRecoveryDirty, commitLkgWithRecoveryFence, clearLkgRecoveryFence, gaDatabasePath, V2StoreReader, readSessionActivity, observeSessionActivity, backfillSessionActivity, deleteSessionScopedRows, clearCompressionDepth, clearCompressionDepthRange, cleanSearchText, keywordRelevance, matchedSearchSnippet, MESSAGE_INDEX_MAX_FTS_BYTES2, messageIndexSkipKey2, toMessageIndexSource2, getMessageIndexSourceIdentity2, isMessageIndexSourceCurrent2, getLastIndexedOrdinal2, getIndexedMessageCorpusSize2, markMessageIndexDirty2, getMessageIndexReconciliationStartOrdinal2, isMessageIndexReconciledThrough2, deleteIndexedMessage2, clearIndexedMessagesInTransaction2, clearIndexedMessages2, getIndexableContent2, indexSingleMessage2, indexMessagesAfterOrdinal2, indexSourcesAfterOrdinal2, sweepOrphanedOpenCodeMessageIndexesCooperatively2 };
|
|
2138
|
+
export { BoundedSessionMap, LkgRecoveryFenceError, clearLkgFenceProcessState, takeLkgRecoveryLockSweepPage, lkgFenceRequiresRebuild, lkgRecoveryFenceUnclean, ownsLkgDirtyFence, invalidateCleanLkgRecoveryFence, markLkgRecoveryDirty, commitLkgWithRecoveryFence, clearLkgRecoveryFence, gaDatabasePath, V2StoreReader, readSessionActivity, observeSessionActivity, backfillSessionActivity, deleteSessionScopedRows, clearCompressionDepth, clearCompressionDepthRange, cleanSearchText, keywordRelevance, matchedSearchSnippet, MESSAGE_INDEX_MAX_FTS_BYTES2, messageIndexSkipKey2, toMessageIndexSource2, getMessageIndexSourceIdentity2, isMessageIndexSourceCurrent2, getLastIndexedOrdinal2, getIndexedMessageCorpusSize2, markMessageIndexDirty2, getMessageIndexReconciliationStartOrdinal2, isMessageIndexReconciledThrough2, deleteIndexedMessage2, clearIndexedMessagesInTransaction2, clearIndexedMessages2, getIndexableContent2, indexSingleMessage2, indexMessagesAfterOrdinal2, indexSourcesAfterOrdinal2, sweepOrphanedOpenCodeMessageIndexesCooperatively2 };
|