Skip to content

Commit 373882f

Browse files
fix: verify fresh dist output
1 parent 16c33a0 commit 373882f

4 files changed

Lines changed: 44 additions & 10 deletions

File tree

dist/src/retriever.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -876,8 +876,9 @@ export class MemoryRetriever {
876876
const model = this.config.rerankModel || "jina-reranker-v3";
877877
const endpoint = this.config.rerankEndpoint || "https://api.jina.ai/v1/rerank";
878878
const documents = results.map((r) => r.entry.text);
879+
const rerankTopN = Math.min(results.length, Math.max(1, this.config.candidatePoolSize));
879880
// Build provider-specific request
880-
const { headers, body } = buildRerankRequest(provider, this.config.rerankApiKey || "", model, query, documents, results.length);
881+
const { headers, body } = buildRerankRequest(provider, this.config.rerankApiKey || "", model, query, documents, rerankTopN);
881882
// Timeout: configurable via rerankTimeoutMs (default: 5000ms)
882883
const controller = new AbortController();
883884
const timeout = setTimeout(() => controller.abort(), this.config.rerankTimeoutMs ?? 5000);

dist/src/store.js

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,21 @@ export function __setLockfileModuleForTests(module) {
2929
}
3030
export const loadLanceDB = async () => {
3131
if (!lancedbImportPromise) {
32+
// @lancedb/lancedb's napi-rs loader (dist/native.js) detects musl via
33+
// process.report.getReport(). The report's network section performs
34+
// reverse-DNS lookups for every network interface, synchronously on the
35+
// calling thread; on hosts with several interfaces and a slow or flaky
36+
// DNS path (measured on WSL2 + Tailscale) this blocks the event loop for
37+
// 110-250s on the FIRST LanceDB load — the host app's HTTP server and
38+
// pollers freeze with CPU at 0% (main thread stuck in poll()). Excluding
39+
// the network section turns the measured 235s hang into ~3ms and loses
40+
// nothing: isMusl() only reads report.header.glibcVersionRuntime.
41+
try {
42+
process.report.excludeNetwork = true;
43+
}
44+
catch {
45+
/* Node < 22 without the flag — keep the previous behavior */
46+
}
3247
// Use a createRequire-built require() so LanceDB's CommonJS native bindings
3348
// keep Windows-safe CJS semantics while still working in pure ESM runtimes.
3449
// Do not name this binding "require": bundlers may rewrite bare require()
@@ -50,7 +65,11 @@ function clampInt(value, min, max) {
5065
return min;
5166
return Math.min(max, Math.max(min, Math.floor(value)));
5267
}
68+
const LEGACY_STABLE_MEMORY_ID_REGEX = /^[A-Za-z0-9][A-Za-z0-9._:-]{2,127}$/;
5369
const LEGACY_SECONDS_TIMESTAMP_MAX = 1_000_000_000_000;
70+
function isLegacyStableMemoryId(id) {
71+
return LEGACY_STABLE_MEMORY_ID_REGEX.test(id);
72+
}
5473
export function normalizeMemoryTimestamp(value, fallback = Date.now()) {
5574
const raw = value instanceof Date
5675
? value.getTime()
@@ -1704,20 +1723,19 @@ export class MemoryStore {
17041723
throw new Error(`Memory ${id} is outside accessible scopes`);
17051724
}
17061725
return this.runWithFileLock(() => this.runSerializedUpdate(async () => {
1707-
// Support both full UUID and short prefix (8+ hex chars), same as delete()
1708-
// Also support legacy mem-md-N format from older memory-lancedb-pro versions
1726+
// Support full UUID, short hex prefixes, and constrained exact legacy IDs imported
1727+
// from older stores (for example "mem-md-..." or "data-pointer-...").
17091728
const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
17101729
const prefixRegex = /^[0-9a-f]{8,}$/i;
1711-
const legacyRegex = /^mem-md-\d+$/i;
17121730
const isFullId = uuidRegex.test(id);
17131731
const isPrefix = !isFullId && prefixRegex.test(id);
1714-
const isLegacy = !isFullId && !isPrefix && legacyRegex.test(id);
1715-
if (!isFullId && !isPrefix && !isLegacy) {
1732+
const isLegacyStableId = !isFullId && !isPrefix && isLegacyStableMemoryId(id);
1733+
if (!isFullId && !isPrefix && !isLegacyStableId) {
17161734
throw new Error(`Invalid memory ID format: ${id}`);
17171735
}
17181736
let rows;
1719-
if (isFullId || isLegacy) {
1720-
// Legacy IDs use exact string match like full UUIDs
1737+
if (isFullId || isLegacyStableId) {
1738+
// Legacy IDs use exact string match like full UUIDs.
17211739
const safeId = escapeSqlLiteral(id);
17221740
rows = await this.table.query()
17231741
.where(`id = '${safeId}'`)

scripts/verify-package-runtime.mjs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { existsSync, readFileSync, statSync } from "node:fs";
2+
import { spawnSync } from "node:child_process";
23
import path from "node:path";
34
import { fileURLToPath } from "node:url";
45

@@ -14,6 +15,18 @@ function readJson(relativePath) {
1415
return JSON.parse(readFileSync(path.join(repoRoot, relativePath), "utf8"));
1516
}
1617

18+
function verifyDistFreshness() {
19+
const result = spawnSync("git", ["diff", "--quiet", "--", "dist"], {
20+
cwd: repoRoot,
21+
encoding: "utf8",
22+
});
23+
if (result.status === 0) return;
24+
if (result.status === 1) {
25+
fail("dist/ is stale after build; run npm run build and commit the generated dist output");
26+
}
27+
fail(`could not verify dist freshness with git diff: ${result.stderr || result.stdout || `exit ${result.status}`}`);
28+
}
29+
1730
function normalizeRuntimePath(value) {
1831
if (typeof value !== "string" || value.trim().length === 0) {
1932
fail(`invalid runtime path ${JSON.stringify(value)}`);
@@ -54,4 +67,6 @@ if (!files.includes("dist/**/*")) {
5467
fail('package.json files must include "dist/**/*" so compiled runtime output is published');
5568
}
5669

57-
console.log("Package runtime entries point to compiled dist output");
70+
verifyDistFreshness();
71+
72+
console.log("Package runtime entries point to compiled fresh dist output");

test/package-runtime.test.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ const result = spawnSync(process.execPath, ["scripts/verify-package-runtime.mjs"
2525
assert.equal(
2626
result.status,
2727
0,
28-
result.stderr || result.stdout || "verify-package-runtime.mjs should pass",
28+
result.stderr || result.stdout || "verify-package-runtime.mjs should pass and dist should be fresh",
2929
);

0 commit comments

Comments
 (0)