@gmickel/gno 2.15.0 → 2.17.0
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/assets/skill/SKILL.md +27 -0
- package/assets/skill/cli-reference.md +24 -15
- package/assets/spa-production.json.gz +0 -0
- package/browser-extension/artifacts/{gno-browser-clipper-v2.15.0.zip → gno-browser-clipper-v2.17.0.zip} +0 -0
- package/browser-extension/artifacts/gno-browser-clipper-v2.17.0.zip.sha256 +1 -0
- package/browser-extension/dist/manifest.json +1 -1
- package/package.json +1 -1
- package/spec/cli.md +43 -3
- package/spec/db/schema.sql +53 -1
- package/spec/mcp.md +9 -3
- package/spec/output-schemas/doctor.schema.json +27 -0
- package/spec/output-schemas/retrieval-trace-payloads.schema.json +14 -0
- package/spec/output-schemas/search-results.schema.json +14 -0
- package/spec/output-schemas/status.schema.json +22 -0
- package/src/cli/commands/agents/commands.ts +1 -1
- package/src/cli/commands/ask.ts +1 -1
- package/src/cli/commands/context-build.ts +1 -1
- package/src/cli/commands/doctor.ts +101 -29
- package/src/cli/commands/embed.ts +2 -2
- package/src/cli/commands/links.ts +30 -6
- package/src/cli/commands/mcp/install.ts +2 -2
- package/src/cli/commands/mcp/status.ts +1 -1
- package/src/cli/commands/mcp/uninstall.ts +1 -1
- package/src/cli/commands/query.ts +1 -1
- package/src/cli/commands/shared.ts +4 -4
- package/src/cli/commands/skill/install.ts +1 -1
- package/src/cli/commands/skill/paths-cmd.ts +1 -1
- package/src/cli/commands/skill/uninstall.ts +1 -1
- package/src/cli/commands/status.ts +75 -58
- package/src/cli/commands/vec.ts +180 -8
- package/src/cli/config-cache.ts +86 -0
- package/src/cli/globals.ts +64 -0
- package/src/cli/program.ts +63 -36
- package/src/cli/run.ts +121 -67
- package/src/cli/runtime-health.ts +132 -122
- package/src/cli/session-binding.ts +11 -2
- package/src/config/saver.ts +8 -0
- package/src/config/types.ts +6 -0
- package/src/converters/adapters/browser-export/formats.ts +25 -15
- package/src/converters/adapters/email/adapter.ts +37 -53
- package/src/converters/adapters/email/html.ts +37 -20
- package/src/converters/adapters/email/mime.ts +71 -39
- package/src/converters/adapters/ical/adapter.ts +20 -12
- package/src/converters/adapters/jsonl/adapter.ts +8 -6
- package/src/converters/adapters/shared/html-text.ts +55 -37
- package/src/converters/adapters/shared/ooxml-protection.ts +5 -13
- package/src/converters/adapters/shared/utf8-lines.ts +69 -31
- package/src/converters/adapters/transcript/adapter.ts +12 -7
- package/src/converters/adapters/xlsx/adapter.ts +10 -7
- package/src/converters/adapters/xlsx/sheet-markdown.ts +93 -50
- package/src/converters/canonicalize.ts +17 -3
- package/src/converters/native/markdown.ts +24 -17
- package/src/converters/native/plaintext.ts +5 -6
- package/src/converters/registry.ts +130 -8
- package/src/core/activation-status.ts +4 -8
- package/src/core/change-diff.ts +38 -11
- package/src/core/context-compiler.ts +17 -18
- package/src/core/context-evidence.ts +116 -25
- package/src/core/context-verifier.ts +70 -31
- package/src/core/file-lock.ts +10 -2
- package/src/core/graph-analysis.ts +3 -3
- package/src/core/link-inventory-markdown.ts +2 -2
- package/src/core/links.ts +20 -87
- package/src/core/memory-fence.ts +16 -9
- package/src/core/memory-recall.ts +168 -34
- package/src/core/path-rules.ts +143 -0
- package/src/core/retrieval-trace-session.ts +3 -0
- package/src/core/retrieval-trace.ts +9 -0
- package/src/core/section-parse.ts +16 -6
- package/src/core/typed-metadata.ts +68 -0
- package/src/core/vector-partition-status.ts +13 -0
- package/src/core/wiki-link-syntax.ts +88 -0
- package/src/embed/backlog.ts +142 -60
- package/src/embed/retry.ts +39 -33
- package/src/embed/variant-backlog.ts +582 -116
- package/src/embed/variant-retry.ts +157 -48
- package/src/index.ts +3 -3
- package/src/ingestion/budget-error-codes.ts +13 -0
- package/src/ingestion/chunker.ts +60 -49
- package/src/ingestion/compiled-context.ts +4 -5
- package/src/ingestion/convert-file.ts +1 -1
- package/src/ingestion/document-metadata.ts +16 -9
- package/src/ingestion/excluded-ranges.ts +97 -0
- package/src/ingestion/file-processor.ts +122 -37
- package/src/ingestion/frontmatter.ts +35 -7
- package/src/ingestion/graph-reconciliation.ts +187 -51
- package/src/ingestion/language.ts +66 -61
- package/src/ingestion/position.ts +5 -5
- package/src/ingestion/prepare-file.ts +50 -29
- package/src/ingestion/record-adapter-canonical.ts +37 -26
- package/src/ingestion/record-adapter.ts +46 -26
- package/src/ingestion/record-container.ts +121 -53
- package/src/ingestion/record-path.ts +5 -2
- package/src/ingestion/source-availability/darwin-io.ts +10 -7
- package/src/ingestion/source-availability/darwin-path.ts +21 -3
- package/src/ingestion/source-availability/readers.ts +51 -0
- package/src/ingestion/strip.ts +39 -105
- package/src/ingestion/sync.ts +692 -386
- package/src/ingestion/typed-metadata.ts +10 -4
- package/src/ingestion/walker.ts +485 -158
- package/src/llm/cache.ts +128 -84
- package/src/llm/http-inference.ts +112 -35
- package/src/llm/http-policy.ts +101 -0
- package/src/llm/httpEmbedding.ts +8 -1
- package/src/llm/httpGeneration.ts +5 -1
- package/src/llm/httpRerank.ts +5 -1
- package/src/llm/inference-scope.ts +15 -2
- package/src/llm/lazy-ports.ts +33 -3
- package/src/llm/lockfile.ts +34 -7
- package/src/llm/model-cleanup.ts +24 -0
- package/src/llm/native-worker/client.ts +23 -12
- package/src/llm/native-worker/dispatcher.ts +19 -9
- package/src/llm/native-worker/embedding-identity.ts +42 -16
- package/src/llm/native-worker/entry.ts +2 -1
- package/src/llm/native-worker/owner.ts +1 -0
- package/src/llm/native-worker/ports.ts +86 -23
- package/src/llm/native-worker/protocol.ts +386 -55
- package/src/llm/nodeLlamaCpp/adapter.ts +46 -29
- package/src/llm/nodeLlamaCpp/embedding.ts +93 -40
- package/src/llm/nodeLlamaCpp/generation.ts +194 -30
- package/src/llm/nodeLlamaCpp/lifecycle.ts +2 -0
- package/src/llm/nodeLlamaCpp/rerank-capacity.ts +101 -23
- package/src/llm/nodeLlamaCpp/rerank.ts +253 -44
- package/src/llm/types.ts +14 -0
- package/src/mcp/context.ts +342 -23
- package/src/mcp/http-transport.ts +21 -3
- package/src/mcp/tool-profile-types.ts +62 -0
- package/src/mcp/tool-profile.ts +32 -56
- package/src/mcp/tools/context.ts +5 -1
- package/src/mcp/tools/index.ts +269 -191
- package/src/mcp/tools/links.ts +14 -6
- package/src/mcp/tools/query.ts +60 -37
- package/src/mcp/tools/vsearch.ts +25 -14
- package/src/pipeline/answer.ts +133 -40
- package/src/pipeline/claim-verification.ts +293 -189
- package/src/pipeline/claim-verifier.ts +6 -7
- package/src/pipeline/egress-lineage.ts +37 -26
- package/src/pipeline/exclude.ts +34 -11
- package/src/pipeline/expansion.ts +233 -19
- package/src/pipeline/explain.ts +17 -2
- package/src/pipeline/filters.ts +169 -33
- package/src/pipeline/graph-retrieval.ts +117 -61
- package/src/pipeline/hybrid.ts +626 -330
- package/src/pipeline/hydration.ts +86 -24
- package/src/pipeline/intent.ts +15 -7
- package/src/pipeline/owner-fusion.ts +61 -19
- package/src/pipeline/query-language.ts +15 -2
- package/src/pipeline/rerank.ts +15 -22
- package/src/pipeline/search.ts +193 -72
- package/src/pipeline/snippet.ts +15 -2
- package/src/pipeline/temporal.ts +51 -10
- package/src/pipeline/types.ts +7 -0
- package/src/pipeline/vsearch.ts +269 -154
- package/src/publish/attachment-raster.ts +2 -16
- package/src/publish/encrypted-export.ts +15 -5
- package/src/serve/browse-tree.ts +50 -42
- package/src/serve/connectors.ts +2 -1
- package/src/serve/context.ts +13 -4
- package/src/serve/doc-events.ts +3 -0
- package/src/serve/public/app.tsx +49 -21
- package/src/serve/public/components/BrowseTreeSidebar.tsx +163 -23
- package/src/serve/public/components/CaptureModal.tsx +14 -10
- package/src/serve/public/components/ai-elements/code-block.tsx +87 -50
- package/src/serve/public/components/editor/MarkdownPreview.tsx +99 -67
- package/src/serve/public/globals.built.css +1 -1
- package/src/serve/public/globals.css +19 -0
- package/src/serve/public/hooks/useCaptureModal.tsx +23 -10
- package/src/serve/public/lib/metadata-filter.ts +234 -9
- package/src/serve/public/pages/Browse.tsx +61 -27
- package/src/serve/public/pages/DocView.tsx +44 -25
- package/src/serve/public/pages/GraphView.tsx +8 -3
- package/src/serve/resident-runtime.ts +199 -48
- package/src/serve/routes/api.ts +98 -67
- package/src/serve/routes/links.ts +25 -5
- package/src/serve/server.ts +1370 -1180
- package/src/serve/spa-bundle-source.ts +52 -27
- package/src/serve/status.ts +101 -52
- package/src/serve/watch-reconciliation-fallback.ts +11 -7
- package/src/serve/watch-reconciliation-shared.ts +42 -4
- package/src/serve/watch-reconciliation.ts +21 -8
- package/src/serve/watch-service-events.ts +7 -1
- package/src/serve/watch-service-hosts.ts +3 -1
- package/src/serve/watch-service.ts +46 -21
- package/src/serve/watch-snapshot-scan.ts +6 -15
- package/src/sessions/archive.ts +20 -8
- package/src/sessions/sanitize.ts +38 -18
- package/src/sessions/service.ts +180 -102
- package/src/store/migrations/037-performance-indexes.ts +56 -0
- package/src/store/migrations/038-vector-mirror-null-cosine.ts +47 -0
- package/src/store/migrations/039-vector-mirror-v2.ts +94 -0
- package/src/store/migrations/index.ts +6 -0
- package/src/store/sqlite/adapter.ts +1260 -651
- package/src/store/sqlite/chunking-policy.ts +15 -1
- package/src/store/sqlite/eligibility.ts +110 -70
- package/src/store/sqlite/graph-neighbors.ts +71 -46
- package/src/store/sqlite/graph-reference-state.ts +27 -3
- package/src/store/sqlite/graph-similarity.ts +59 -12
- package/src/store/sqlite/metadata-predicate.ts +123 -28
- package/src/store/sqlite/retrieval-trace-management-store.ts +126 -33
- package/src/store/sqlite/retrieval-trace-retention.ts +88 -76
- package/src/store/sqlite/retrieval-trace-rows.ts +7 -3
- package/src/store/types.ts +32 -0
- package/src/store/vector/coarse-router.ts +312 -0
- package/src/store/vector/eligibility.ts +39 -0
- package/src/store/vector/lazy.ts +17 -0
- package/src/store/vector/partition-index.ts +333 -59
- package/src/store/vector/proof-cache.ts +209 -0
- package/src/store/vector/runtime-compat.ts +6 -0
- package/src/store/vector/sqlite-vec.ts +270 -162
- package/src/store/vector/stats.ts +37 -73
- package/src/store/vector/status.ts +169 -53
- package/src/store/vector/stored-vectors.ts +131 -45
- package/src/store/vector/types.ts +19 -0
- package/src/store/vector/v2-mirror.ts +669 -0
- package/src/store/vector/variant-search.ts +1187 -111
- package/src/store/vector/variants.ts +964 -160
- package/browser-extension/artifacts/gno-browser-clipper-v2.15.0.zip.sha256 +0 -1
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type { StoreResult } from "../store/types";
|
|
2
|
+
import type { VectorOwnerInput } from "../store/vector/types";
|
|
2
3
|
import type { VectorVariantStore } from "../store/vector/variants";
|
|
3
4
|
import type { EmbedBacklogDeps, EmbedBacklogResult } from "./backlog";
|
|
4
5
|
|
|
6
|
+
import { isHttpModelUri } from "../llm/httpEmbedding";
|
|
5
7
|
import {
|
|
6
8
|
assertInferenceActive,
|
|
7
9
|
isBackgroundInference,
|
|
@@ -9,6 +11,7 @@ import {
|
|
|
9
11
|
} from "../llm/inference-scope";
|
|
10
12
|
import { err, ok } from "../store/types";
|
|
11
13
|
import { getVectorStatsDatabase } from "../store/vector/stats";
|
|
14
|
+
import { embedTextsWithRecovery } from "./batch";
|
|
12
15
|
import {
|
|
13
16
|
compareOwnerCursor,
|
|
14
17
|
isOwnerCursor,
|
|
@@ -19,7 +22,16 @@ import {
|
|
|
19
22
|
} from "./resume-cursor";
|
|
20
23
|
import { inWriteTurn } from "./retry";
|
|
21
24
|
import { variantBacklogPage } from "./variant-plan";
|
|
22
|
-
import {
|
|
25
|
+
import {
|
|
26
|
+
commitVariantBatch,
|
|
27
|
+
embedVariantBatch,
|
|
28
|
+
type PreparedVariantBatch,
|
|
29
|
+
prepareVariantBatch,
|
|
30
|
+
type VariantBatchOutcome,
|
|
31
|
+
} from "./variant-retry";
|
|
32
|
+
|
|
33
|
+
const DEFAULT_FOREGROUND_BATCH_SIZE = 64;
|
|
34
|
+
const HTTP_EMBED_MAX_CONCURRENCY = 3;
|
|
23
35
|
|
|
24
36
|
/** One bounded owner pass plus one retry; mutations stay durably pending for the next pass. */
|
|
25
37
|
export async function embedVariantBacklog(
|
|
@@ -50,7 +62,7 @@ export async function embedVariantBacklog(
|
|
|
50
62
|
const background = isBackgroundInference();
|
|
51
63
|
const batchSize = background
|
|
52
64
|
? Math.min(deps.batchSize ?? 32, 32)
|
|
53
|
-
: (deps.batchSize ??
|
|
65
|
+
: (deps.batchSize ?? DEFAULT_FOREGROUND_BATCH_SIZE);
|
|
54
66
|
if (!Number.isSafeInteger(batchSize) || batchSize < 1)
|
|
55
67
|
return err("INVALID_INPUT", "Invalid embedding batch size");
|
|
56
68
|
const total = { embedded: 0, errors: 0, contentionErrors: 0 };
|
|
@@ -140,140 +152,560 @@ export async function embedVariantBacklog(
|
|
|
140
152
|
await saveResume(after);
|
|
141
153
|
return ok({ ...total, stopped: "limit" as const });
|
|
142
154
|
};
|
|
155
|
+
const handleForegroundOutcome = async (
|
|
156
|
+
ownersCount: number,
|
|
157
|
+
outcome: VariantBatchOutcome
|
|
158
|
+
): Promise<boolean> => {
|
|
159
|
+
if (outcome.deferred) return true;
|
|
160
|
+
if (!identityHolds()) {
|
|
161
|
+
total.errors += Math.max(
|
|
162
|
+
0,
|
|
163
|
+
ownersCount -
|
|
164
|
+
outcome.embedded -
|
|
165
|
+
outcome.errors -
|
|
166
|
+
outcome.contentionErrors -
|
|
167
|
+
outcome.retryOwners.length
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
total.embedded += outcome.embedded;
|
|
171
|
+
total.errors += outcome.errors;
|
|
172
|
+
total.contentionErrors += outcome.contentionErrors;
|
|
173
|
+
if (outcome.retryOwners.length && !limitReached()) {
|
|
174
|
+
const retrying = outcome.retryOwners.length;
|
|
175
|
+
const retryResult = await embedVariantBatch({
|
|
176
|
+
store,
|
|
177
|
+
embedPort: deps.embedPort,
|
|
178
|
+
owners: outcome.retryOwners,
|
|
179
|
+
identityStillCurrent,
|
|
180
|
+
force: deps.force,
|
|
181
|
+
onSubmit,
|
|
182
|
+
});
|
|
183
|
+
total.embedded += retryResult.embedded;
|
|
184
|
+
total.errors += retryResult.errors + retryResult.retryOwners.length;
|
|
185
|
+
total.contentionErrors += retryResult.contentionErrors;
|
|
186
|
+
if (!identityHolds())
|
|
187
|
+
total.errors += Math.max(
|
|
188
|
+
0,
|
|
189
|
+
retrying -
|
|
190
|
+
retryResult.embedded -
|
|
191
|
+
retryResult.errors -
|
|
192
|
+
retryResult.contentionErrors -
|
|
193
|
+
retryResult.retryOwners.length
|
|
194
|
+
);
|
|
195
|
+
} else {
|
|
196
|
+
total.errors += outcome.retryOwners.length;
|
|
197
|
+
}
|
|
198
|
+
deps.onProgress?.(total.embedded, total.errors);
|
|
199
|
+
return false;
|
|
200
|
+
};
|
|
201
|
+
|
|
143
202
|
try {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
203
|
+
const canPipelineForeground =
|
|
204
|
+
!background && !deps.acquireWriteTurn && !limits;
|
|
205
|
+
const isHttpPort = isHttpModelUri(deps.modelUri);
|
|
206
|
+
|
|
207
|
+
if (canPipelineForeground && isHttpPort) {
|
|
208
|
+
// Bounded concurrent in-flight HTTP batches (up to HTTP_EMBED_MAX_CONCURRENCY)
|
|
209
|
+
// with in-flight inputHash deduplication across the active window.
|
|
210
|
+
type HttpInFlight = {
|
|
211
|
+
owners: VectorOwnerInput[];
|
|
212
|
+
prepared: PreparedVariantBatch;
|
|
213
|
+
keys: string[];
|
|
214
|
+
dependentHashes: string[];
|
|
215
|
+
endCursor: OwnerCursor;
|
|
216
|
+
promise: ReturnType<typeof embedTextsWithRecovery>;
|
|
217
|
+
};
|
|
218
|
+
const inFlight: HttpInFlight[] = [];
|
|
219
|
+
const inFlightHashes = new Set<string>();
|
|
220
|
+
// Retain completed vectors ONLY while at least one queued page depends on
|
|
221
|
+
// them; evict each hash as soon as its last dependent page commits.
|
|
222
|
+
const queuedDependentCount = new Map<string, number>();
|
|
223
|
+
const completedVectors = new Map<string, Float32Array>();
|
|
224
|
+
let exhausted = false;
|
|
225
|
+
|
|
226
|
+
const fillWindow = async (): Promise<void> => {
|
|
227
|
+
while (!exhausted && inFlight.length < HTTP_EMBED_MAX_CONCURRENCY) {
|
|
228
|
+
if (!(await identityCurrent())) {
|
|
229
|
+
identityLost = true;
|
|
230
|
+
exhausted = true;
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
assertInferenceActive();
|
|
234
|
+
const pending = variantBacklogPage(deps, store, batchSize, after);
|
|
235
|
+
if (!pending.length) {
|
|
236
|
+
exhausted = true;
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
const last = pending.at(-1)!;
|
|
240
|
+
const endCursor: OwnerCursor = {
|
|
241
|
+
documentId: last.documentId,
|
|
242
|
+
seq: last.seq,
|
|
243
|
+
};
|
|
244
|
+
after = endCursor;
|
|
245
|
+
const prepared = prepareVariantBatch({
|
|
246
|
+
store,
|
|
247
|
+
owners: pending,
|
|
248
|
+
force: deps.force,
|
|
249
|
+
inFlightHashes,
|
|
250
|
+
});
|
|
251
|
+
const dependentHashes: string[] = [];
|
|
252
|
+
for (const [hash] of prepared.sharedFromInFlight) {
|
|
253
|
+
dependentHashes.push(hash);
|
|
254
|
+
queuedDependentCount.set(
|
|
255
|
+
hash,
|
|
256
|
+
(queuedDependentCount.get(hash) ?? 0) + 1
|
|
257
|
+
);
|
|
258
|
+
}
|
|
259
|
+
const keys = [...prepared.inputs.keys()];
|
|
260
|
+
for (const key of keys) inFlightHashes.add(key);
|
|
261
|
+
const promise = embedTextsWithRecovery(
|
|
262
|
+
deps.embedPort,
|
|
263
|
+
[...prepared.inputs.values()],
|
|
264
|
+
{ onSubmit }
|
|
155
265
|
);
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
266
|
+
inFlight.push({
|
|
267
|
+
owners: pending,
|
|
268
|
+
prepared,
|
|
269
|
+
keys,
|
|
270
|
+
dependentHashes,
|
|
271
|
+
endCursor,
|
|
272
|
+
promise,
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
await fillWindow();
|
|
278
|
+
while (inFlight.length > 0) {
|
|
279
|
+
const entry = inFlight.shift()!;
|
|
280
|
+
const result = await entry.promise;
|
|
281
|
+
for (const key of entry.keys) inFlightHashes.delete(key);
|
|
282
|
+
|
|
283
|
+
if (!identityHolds()) {
|
|
284
|
+
await Promise.allSettled(inFlight.map((item) => item.promise));
|
|
285
|
+
inFlight.length = 0;
|
|
286
|
+
inFlightHashes.clear();
|
|
287
|
+
completedVectors.clear();
|
|
288
|
+
queuedDependentCount.clear();
|
|
289
|
+
total.errors += entry.owners.length;
|
|
290
|
+
deps.onProgress?.(total.embedded, total.errors);
|
|
291
|
+
if (!(await identityCurrent())) {
|
|
176
292
|
identityLost = true;
|
|
177
293
|
break;
|
|
178
294
|
}
|
|
295
|
+
// Reloaded identity: rewind cursor to end of the failed batch so
|
|
296
|
+
// discarded in-flight pages are re-fetched cleanly and traversal
|
|
297
|
+
// continues across the rest of the backlog.
|
|
298
|
+
after = entry.endCursor;
|
|
299
|
+
exhausted = false;
|
|
300
|
+
await fillWindow();
|
|
301
|
+
continue;
|
|
179
302
|
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
303
|
+
|
|
304
|
+
const vectors = new Map<string, Float32Array>();
|
|
305
|
+
if (result.ok) {
|
|
306
|
+
for (const [index, key] of entry.keys.entries()) {
|
|
307
|
+
const vec = result.value.vectors[index];
|
|
308
|
+
if (vec) {
|
|
309
|
+
const typed = new Float32Array(vec);
|
|
310
|
+
vectors.set(key, typed);
|
|
311
|
+
if ((queuedDependentCount.get(key) ?? 0) > 0) {
|
|
312
|
+
completedVectors.set(key, typed);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
// Attach vectors produced by earlier batches in the same window and
|
|
318
|
+
// release ref-counts immediately so completedVectors stays bounded.
|
|
319
|
+
for (const hash of entry.dependentHashes) {
|
|
320
|
+
const shared = completedVectors.get(hash);
|
|
321
|
+
if (shared && !vectors.has(hash)) {
|
|
322
|
+
vectors.set(hash, shared);
|
|
323
|
+
}
|
|
324
|
+
const remaining = (queuedDependentCount.get(hash) ?? 1) - 1;
|
|
325
|
+
if (remaining <= 0) {
|
|
326
|
+
queuedDependentCount.delete(hash);
|
|
327
|
+
completedVectors.delete(hash);
|
|
328
|
+
} else {
|
|
329
|
+
queuedDependentCount.set(hash, remaining);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
const outcome = await commitVariantBatch({
|
|
198
333
|
store,
|
|
199
|
-
|
|
200
|
-
|
|
334
|
+
owners: entry.prepared.owners,
|
|
335
|
+
reusable: entry.prepared.reusable,
|
|
336
|
+
vectors,
|
|
201
337
|
identityStillCurrent,
|
|
202
|
-
force: deps.force,
|
|
203
|
-
acquireWriteTurn: deps.acquireWriteTurn,
|
|
204
|
-
onSubmit,
|
|
205
338
|
});
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
: await embedPage();
|
|
209
|
-
if (!result) {
|
|
210
|
-
// Past its deadline: this page stays pending for the next pass.
|
|
211
|
-
total.errors += owners.length;
|
|
212
|
-
deps.onProgress?.(total.embedded, total.errors);
|
|
213
|
-
const verdict = await stopAtLimit();
|
|
214
|
-
if (verdict === "limit") return await stop();
|
|
215
|
-
if (verdict === "incomplete") {
|
|
216
|
-
identityLost = true;
|
|
217
|
-
break;
|
|
218
|
-
}
|
|
219
|
-
await Bun.sleep(0);
|
|
220
|
-
continue;
|
|
339
|
+
await handleForegroundOutcome(entry.owners.length, outcome);
|
|
340
|
+
await fillWindow();
|
|
221
341
|
}
|
|
222
|
-
|
|
223
|
-
//
|
|
224
|
-
//
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
result.embedded -
|
|
231
|
-
result.errors -
|
|
232
|
-
result.contentionErrors -
|
|
233
|
-
result.retryOwners.length
|
|
234
|
-
);
|
|
342
|
+
} else if (canPipelineForeground) {
|
|
343
|
+
// Double-buffered foreground native embedding: overlap SQLite commit of
|
|
344
|
+
// page k-1 + prefetch/format of page k+1 with worker inference of page k.
|
|
345
|
+
interface PreparedPage {
|
|
346
|
+
owners: VectorOwnerInput[];
|
|
347
|
+
prepared: PreparedVariantBatch;
|
|
348
|
+
carriedVectors: Map<string, Float32Array>;
|
|
349
|
+
endCursor: OwnerCursor;
|
|
235
350
|
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
const
|
|
244
|
-
|
|
351
|
+
|
|
352
|
+
const fetchPreparedPage = (
|
|
353
|
+
inFlightHashes?: ReadonlySet<string>
|
|
354
|
+
): PreparedPage | null => {
|
|
355
|
+
assertInferenceActive();
|
|
356
|
+
const pending = variantBacklogPage(deps, store, batchSize, after);
|
|
357
|
+
if (!pending.length) return null;
|
|
358
|
+
const last = pending.at(-1)!;
|
|
359
|
+
const endCursor: OwnerCursor = {
|
|
360
|
+
documentId: last.documentId,
|
|
361
|
+
seq: last.seq,
|
|
362
|
+
};
|
|
363
|
+
after = endCursor;
|
|
364
|
+
const prepared = prepareVariantBatch({
|
|
245
365
|
store,
|
|
246
|
-
|
|
247
|
-
owners: result.retryOwners,
|
|
248
|
-
identityStillCurrent,
|
|
366
|
+
owners: pending,
|
|
249
367
|
force: deps.force,
|
|
250
|
-
|
|
368
|
+
inFlightHashes,
|
|
251
369
|
});
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
370
|
+
return {
|
|
371
|
+
owners: pending,
|
|
372
|
+
prepared,
|
|
373
|
+
carriedVectors: new Map<string, Float32Array>(),
|
|
374
|
+
endCursor,
|
|
375
|
+
};
|
|
376
|
+
};
|
|
377
|
+
|
|
378
|
+
const mergeCarriedVectors = (
|
|
379
|
+
page: PreparedPage,
|
|
380
|
+
inferred: Map<string, Float32Array>
|
|
381
|
+
): Map<string, Float32Array> => {
|
|
382
|
+
if (page.carriedVectors.size === 0) return inferred;
|
|
383
|
+
for (const [hash, vec] of page.carriedVectors) {
|
|
384
|
+
if (!inferred.has(hash)) inferred.set(hash, vec);
|
|
385
|
+
}
|
|
386
|
+
return inferred;
|
|
387
|
+
};
|
|
388
|
+
|
|
389
|
+
const handoffSharedVectors = (
|
|
390
|
+
sourceVectors: ReadonlyMap<string, Float32Array>,
|
|
391
|
+
targetPage: PreparedPage | null
|
|
392
|
+
): void => {
|
|
393
|
+
if (!targetPage) return;
|
|
394
|
+
for (const [hash, formatted] of targetPage.prepared
|
|
395
|
+
.sharedFromInFlight) {
|
|
396
|
+
const vec = sourceVectors.get(hash);
|
|
397
|
+
if (vec) {
|
|
398
|
+
// Carry the actual vector bytes instead of marking reusable before
|
|
399
|
+
// SQLite commits page k (page k's producer owners might go stale).
|
|
400
|
+
targetPage.carriedVectors.set(hash, vec);
|
|
401
|
+
} else {
|
|
402
|
+
targetPage.prepared.inputs.set(hash, formatted);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
targetPage.prepared.sharedFromInFlight.clear();
|
|
406
|
+
};
|
|
407
|
+
|
|
408
|
+
if (!(await identityCurrent())) {
|
|
409
|
+
identityLost = true;
|
|
410
|
+
} else {
|
|
411
|
+
let currentPage = fetchPreparedPage();
|
|
412
|
+
while (currentPage) {
|
|
413
|
+
const keys = [...currentPage.prepared.inputs.keys()];
|
|
414
|
+
const activeHashes = new Set(keys);
|
|
415
|
+
const inferencePromise = embedTextsWithRecovery(
|
|
416
|
+
deps.embedPort,
|
|
417
|
+
[...currentPage.prepared.inputs.values()],
|
|
418
|
+
{ onSubmit }
|
|
419
|
+
);
|
|
420
|
+
|
|
421
|
+
// While child worker runs inference for page k, prefetch and format page k+1.
|
|
422
|
+
const nextPage = fetchPreparedPage(activeHashes);
|
|
423
|
+
|
|
424
|
+
const result = await inferencePromise;
|
|
425
|
+
if (!identityHolds()) {
|
|
426
|
+
total.errors += currentPage.owners.length;
|
|
427
|
+
deps.onProgress?.(total.embedded, total.errors);
|
|
428
|
+
if (!(await identityCurrent())) {
|
|
429
|
+
identityLost = true;
|
|
430
|
+
break;
|
|
431
|
+
}
|
|
432
|
+
// Reloaded identity: rewind cursor to end of failed page so
|
|
433
|
+
// prefetched page k+1 is re-fetched cleanly with no skipped owners.
|
|
434
|
+
after = currentPage.endCursor;
|
|
435
|
+
currentPage = fetchPreparedPage();
|
|
436
|
+
continue;
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
const vectors = new Map<string, Float32Array>();
|
|
440
|
+
if (result.ok) {
|
|
441
|
+
for (const [index, key] of keys.entries()) {
|
|
442
|
+
const vec = result.value.vectors[index];
|
|
443
|
+
if (vec) vectors.set(key, new Float32Array(vec));
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
mergeCarriedVectors(currentPage, vectors);
|
|
447
|
+
handoffSharedVectors(vectors, nextPage);
|
|
448
|
+
|
|
449
|
+
// Launch page k+1's worker inference BEFORE committing page k to SQLite
|
|
450
|
+
// so SQLite commit of page k overlaps with worker inference of page k+1!
|
|
451
|
+
if (!nextPage) {
|
|
452
|
+
const outcome = await commitVariantBatch({
|
|
453
|
+
store,
|
|
454
|
+
owners: currentPage.prepared.owners,
|
|
455
|
+
reusable: currentPage.prepared.reusable,
|
|
456
|
+
vectors,
|
|
457
|
+
identityStillCurrent,
|
|
458
|
+
});
|
|
459
|
+
await handleForegroundOutcome(currentPage.owners.length, outcome);
|
|
460
|
+
break;
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
// Commit page k and continue the loop with page k+1 already started.
|
|
464
|
+
// When page k has retryOwners, finish page k's retry after page k+1's
|
|
465
|
+
// inference completes so only one worker inference runs at a time.
|
|
466
|
+
let pendingCommit: {
|
|
467
|
+
ownersCount: number;
|
|
468
|
+
prepared: PreparedVariantBatch;
|
|
469
|
+
vectors: Map<string, Float32Array>;
|
|
470
|
+
} | null = {
|
|
471
|
+
ownersCount: currentPage.owners.length,
|
|
472
|
+
prepared: currentPage.prepared,
|
|
473
|
+
vectors,
|
|
474
|
+
};
|
|
475
|
+
currentPage = nextPage;
|
|
476
|
+
|
|
477
|
+
while (currentPage) {
|
|
478
|
+
const nextKeys = [...currentPage.prepared.inputs.keys()];
|
|
479
|
+
const nextActiveHashes = new Set(nextKeys);
|
|
480
|
+
const nextInference = embedTextsWithRecovery(
|
|
481
|
+
deps.embedPort,
|
|
482
|
+
[...currentPage.prepared.inputs.values()],
|
|
483
|
+
{ onSubmit }
|
|
484
|
+
);
|
|
485
|
+
// Yield one microtask so the IPC frame is flushed before the
|
|
486
|
+
// synchronous SQLite commit runs on the parent thread.
|
|
487
|
+
if (nextKeys.length > 0) {
|
|
488
|
+
await Promise.resolve();
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
// Overlapped with worker inference of currentPage:
|
|
492
|
+
// 1. Commit previous page to SQLite.
|
|
493
|
+
let deferredRetries: VectorOwnerInput[] = [];
|
|
494
|
+
if (pendingCommit) {
|
|
495
|
+
const prevOutcome = await commitVariantBatch({
|
|
496
|
+
store,
|
|
497
|
+
owners: pendingCommit.prepared.owners,
|
|
498
|
+
reusable: pendingCommit.prepared.reusable,
|
|
499
|
+
vectors: pendingCommit.vectors,
|
|
500
|
+
identityStillCurrent,
|
|
501
|
+
});
|
|
502
|
+
total.embedded += prevOutcome.embedded;
|
|
503
|
+
total.errors += prevOutcome.errors;
|
|
504
|
+
total.contentionErrors += prevOutcome.contentionErrors;
|
|
505
|
+
deferredRetries = prevOutcome.retryOwners;
|
|
506
|
+
if (!deferredRetries.length) {
|
|
507
|
+
deps.onProgress?.(total.embedded, total.errors);
|
|
508
|
+
}
|
|
509
|
+
pendingCommit = null;
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
// 2. Prefetch & prepare page k+2 while worker still runs page k+1.
|
|
513
|
+
const followingPage = fetchPreparedPage(nextActiveHashes);
|
|
514
|
+
|
|
515
|
+
// Wait for currentPage inference to complete.
|
|
516
|
+
const nextResult = await nextInference;
|
|
517
|
+
if (deferredRetries.length) {
|
|
518
|
+
await handleForegroundOutcome(deferredRetries.length, {
|
|
519
|
+
embedded: 0,
|
|
520
|
+
errors: 0,
|
|
521
|
+
contentionErrors: 0,
|
|
522
|
+
retryOwners: deferredRetries,
|
|
523
|
+
});
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
if (!identityHolds()) {
|
|
527
|
+
total.errors += currentPage.owners.length;
|
|
528
|
+
deps.onProgress?.(total.embedded, total.errors);
|
|
529
|
+
if (!(await identityCurrent())) {
|
|
530
|
+
identityLost = true;
|
|
531
|
+
currentPage = null;
|
|
532
|
+
break;
|
|
533
|
+
}
|
|
534
|
+
after = currentPage.endCursor;
|
|
535
|
+
currentPage = fetchPreparedPage();
|
|
536
|
+
break;
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
const nextVectors = new Map<string, Float32Array>();
|
|
540
|
+
if (nextResult.ok) {
|
|
541
|
+
for (const [index, key] of nextKeys.entries()) {
|
|
542
|
+
const vec = nextResult.value.vectors[index];
|
|
543
|
+
if (vec) nextVectors.set(key, new Float32Array(vec));
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
mergeCarriedVectors(currentPage, nextVectors);
|
|
547
|
+
handoffSharedVectors(nextVectors, followingPage);
|
|
548
|
+
|
|
549
|
+
if (followingPage) {
|
|
550
|
+
pendingCommit = {
|
|
551
|
+
ownersCount: currentPage.owners.length,
|
|
552
|
+
prepared: currentPage.prepared,
|
|
553
|
+
vectors: nextVectors,
|
|
554
|
+
};
|
|
555
|
+
currentPage = followingPage;
|
|
556
|
+
} else {
|
|
557
|
+
const lastOutcome = await commitVariantBatch({
|
|
558
|
+
store,
|
|
559
|
+
owners: currentPage.prepared.owners,
|
|
560
|
+
reusable: currentPage.prepared.reusable,
|
|
561
|
+
vectors: nextVectors,
|
|
562
|
+
identityStillCurrent,
|
|
563
|
+
});
|
|
564
|
+
await handleForegroundOutcome(
|
|
565
|
+
currentPage.owners.length,
|
|
566
|
+
lastOutcome
|
|
567
|
+
);
|
|
568
|
+
currentPage = null;
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
if (identityLost) break;
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
} else {
|
|
575
|
+
while (true) {
|
|
576
|
+
// A failed request drops the port's cached identity (a timed-out native
|
|
577
|
+
// worker is retired); reload it so one failed page cannot end the pass.
|
|
578
|
+
if (background) {
|
|
579
|
+
const reloaded = await withInferencePage(() => deps.embedPort.init());
|
|
580
|
+
// Without an identity the pass cannot continue. Failing it schedules
|
|
581
|
+
// the scheduler's bounded retry instead of ending with pages pending.
|
|
582
|
+
if (!reloaded?.ok)
|
|
583
|
+
throw new Error(
|
|
584
|
+
reloaded?.error.message ??
|
|
585
|
+
"Embedding model reload exceeded its inference deadline"
|
|
586
|
+
);
|
|
587
|
+
}
|
|
588
|
+
if (!(await identityCurrent())) {
|
|
589
|
+
identityLost = true;
|
|
590
|
+
break;
|
|
591
|
+
}
|
|
592
|
+
assertInferenceActive();
|
|
593
|
+
let pending = variantBacklogPage(deps, store, batchSize, after);
|
|
594
|
+
// After wrapping, stop where this run started.
|
|
595
|
+
if (wrapped && resumeFrom)
|
|
596
|
+
pending = pending.filter(
|
|
597
|
+
(owner) => compareOwnerCursor(owner, resumeFrom) <= 0
|
|
598
|
+
);
|
|
599
|
+
if (!pending.length) {
|
|
600
|
+
// Time can run out while this page is read. Owners this run failed
|
|
601
|
+
// are still pending, so the same check as at a batch boundary decides
|
|
602
|
+
// between a stopped run and a finished traversal.
|
|
603
|
+
if (pagesStarted > 0) {
|
|
604
|
+
const verdict = await stopAtLimit();
|
|
605
|
+
if (verdict === "limit") return await stop();
|
|
606
|
+
if (verdict === "incomplete") {
|
|
607
|
+
identityLost = true;
|
|
608
|
+
break;
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
if (wrapped) break;
|
|
612
|
+
wrapped = true;
|
|
613
|
+
after = undefined;
|
|
614
|
+
continue;
|
|
615
|
+
}
|
|
616
|
+
// Time can run out while the page is fetched: stop before inference,
|
|
617
|
+
// keeping this page eligible for the next run (the cursor stays put).
|
|
618
|
+
// Every run processes at least one page, even one that submits nothing
|
|
619
|
+
// or follows a runtime verification that spent the budget, so bounded
|
|
620
|
+
// runs always progress.
|
|
621
|
+
if (pagesStarted > 0 && limitReached()) return await stop();
|
|
622
|
+
pagesStarted += 1;
|
|
623
|
+
const last = pending.at(-1)!;
|
|
624
|
+
after = { documentId: last.documentId, seq: last.seq };
|
|
625
|
+
// Pages are already limited to deps.collection in SQL.
|
|
626
|
+
const owners = pending;
|
|
627
|
+
const embedPage = () =>
|
|
628
|
+
embedVariantBatch({
|
|
629
|
+
store,
|
|
630
|
+
embedPort: deps.embedPort,
|
|
631
|
+
owners,
|
|
632
|
+
identityStillCurrent,
|
|
633
|
+
force: deps.force,
|
|
634
|
+
acquireWriteTurn: deps.acquireWriteTurn,
|
|
635
|
+
onSubmit,
|
|
636
|
+
});
|
|
637
|
+
let result = background
|
|
638
|
+
? await withInferencePage(embedPage)
|
|
639
|
+
: await embedPage();
|
|
640
|
+
if (!result) {
|
|
641
|
+
// Past its deadline: this page stays pending for the next pass.
|
|
642
|
+
total.errors += owners.length;
|
|
643
|
+
deps.onProgress?.(total.embedded, total.errors);
|
|
644
|
+
const verdict = await stopAtLimit();
|
|
645
|
+
if (verdict === "limit") return await stop();
|
|
646
|
+
if (verdict === "incomplete") {
|
|
647
|
+
identityLost = true;
|
|
648
|
+
break;
|
|
649
|
+
}
|
|
650
|
+
await Bun.sleep(0);
|
|
651
|
+
continue;
|
|
652
|
+
}
|
|
653
|
+
if (result.deferred) return ok({ ...total, deferred: true });
|
|
654
|
+
// The identity dropped during inference: the batch discarded its
|
|
655
|
+
// results. Its owners stay pending and count as this run's failures
|
|
656
|
+
// (the port is reloaded at the top of the loop).
|
|
657
|
+
if (!identityHolds()) {
|
|
257
658
|
total.errors += Math.max(
|
|
258
659
|
0,
|
|
259
|
-
|
|
660
|
+
owners.length -
|
|
260
661
|
result.embedded -
|
|
261
662
|
result.errors -
|
|
262
663
|
result.contentionErrors -
|
|
263
664
|
result.retryOwners.length
|
|
264
665
|
);
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
total.errors += result.
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
666
|
+
}
|
|
667
|
+
total.embedded += result.embedded;
|
|
668
|
+
total.errors += result.errors;
|
|
669
|
+
total.contentionErrors += result.contentionErrors;
|
|
670
|
+
if (background) total.errors += result.retryOwners.length;
|
|
671
|
+
// A retry counts toward the limits; once they are reached, failed
|
|
672
|
+
// owners stay pending for the next run instead of a further batch.
|
|
673
|
+
if (!background && result.retryOwners.length && !limitReached()) {
|
|
674
|
+
const retrying = result.retryOwners.length;
|
|
675
|
+
result = await embedVariantBatch({
|
|
676
|
+
store,
|
|
677
|
+
embedPort: deps.embedPort,
|
|
678
|
+
owners: result.retryOwners,
|
|
679
|
+
identityStillCurrent,
|
|
680
|
+
force: deps.force,
|
|
681
|
+
onSubmit,
|
|
682
|
+
});
|
|
683
|
+
total.embedded += result.embedded;
|
|
684
|
+
total.errors += result.errors + result.retryOwners.length;
|
|
685
|
+
total.contentionErrors += result.contentionErrors;
|
|
686
|
+
// Same accounting when the identity drops during the retry.
|
|
687
|
+
if (!identityHolds())
|
|
688
|
+
total.errors += Math.max(
|
|
689
|
+
0,
|
|
690
|
+
retrying -
|
|
691
|
+
result.embedded -
|
|
692
|
+
result.errors -
|
|
693
|
+
result.contentionErrors -
|
|
694
|
+
result.retryOwners.length
|
|
695
|
+
);
|
|
696
|
+
} else if (!background) {
|
|
697
|
+
// Failed in this run; left pending without a retry past the limit.
|
|
698
|
+
total.errors += result.retryOwners.length;
|
|
699
|
+
}
|
|
700
|
+
deps.onProgress?.(total.embedded, total.errors);
|
|
701
|
+
const verdict = await stopAtLimit();
|
|
702
|
+
if (verdict === "limit") return await stop();
|
|
703
|
+
if (verdict === "incomplete") {
|
|
704
|
+
identityLost = true;
|
|
705
|
+
break;
|
|
706
|
+
}
|
|
707
|
+
if (background) await Bun.sleep(0);
|
|
275
708
|
}
|
|
276
|
-
if (background) await Bun.sleep(0);
|
|
277
709
|
}
|
|
278
710
|
// A traversal that reached its end leaves nothing to resume.
|
|
279
711
|
if (!identityLost) await saveResume(undefined);
|
|
@@ -287,7 +719,38 @@ export async function embedVariantBacklog(
|
|
|
287
719
|
// sqlite-vec, keep the full check below.
|
|
288
720
|
if (identityStillCurrent() && store.hasActivated()) {
|
|
289
721
|
const mirror = store.mirrorState();
|
|
290
|
-
|
|
722
|
+
const v2Mirror = store.v2MirrorState();
|
|
723
|
+
const needsV2Repair = v2Mirror === "dirty" || v2Mirror === "missing";
|
|
724
|
+
if (mirror === "clean" && !needsV2Repair) {
|
|
725
|
+
if (v2Mirror === "clean") {
|
|
726
|
+
const checkTurn = await inWriteTurn(
|
|
727
|
+
deps.acquireWriteTurn,
|
|
728
|
+
async () => {
|
|
729
|
+
try {
|
|
730
|
+
store.ensureV2RecallSelfCheck();
|
|
731
|
+
return undefined;
|
|
732
|
+
} catch (cause) {
|
|
733
|
+
return cause instanceof Error ? cause.message : String(cause);
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
);
|
|
737
|
+
if (checkTurn.deferred) return ok({ ...total, deferred: true });
|
|
738
|
+
}
|
|
739
|
+
assertInferenceActive();
|
|
740
|
+
return ok(total);
|
|
741
|
+
}
|
|
742
|
+
if (mirror === "clean" && needsV2Repair) {
|
|
743
|
+
const turn = await inWriteTurn(deps.acquireWriteTurn, async () => {
|
|
744
|
+
try {
|
|
745
|
+
store.syncV2Index();
|
|
746
|
+
return undefined;
|
|
747
|
+
} catch (cause) {
|
|
748
|
+
return cause instanceof Error ? cause.message : String(cause);
|
|
749
|
+
}
|
|
750
|
+
});
|
|
751
|
+
if (turn.deferred) return ok({ ...total, deferred: true });
|
|
752
|
+
if (turn.value !== undefined)
|
|
753
|
+
return ok({ ...total, syncError: turn.value });
|
|
291
754
|
assertInferenceActive();
|
|
292
755
|
return ok(total);
|
|
293
756
|
}
|
|
@@ -316,7 +779,10 @@ export async function embedVariantBacklog(
|
|
|
316
779
|
const turn = await inWriteTurn(deps.acquireWriteTurn, async () => {
|
|
317
780
|
try {
|
|
318
781
|
if (!store.isActive()) store.syncIndex();
|
|
319
|
-
if (identityStillCurrent())
|
|
782
|
+
if (identityStillCurrent()) {
|
|
783
|
+
store.activate(epoch);
|
|
784
|
+
store.ensureV2RecallSelfCheck();
|
|
785
|
+
}
|
|
320
786
|
return undefined;
|
|
321
787
|
} catch (cause) {
|
|
322
788
|
return cause instanceof Error ? cause.message : String(cause);
|