gitnexus 1.6.10-rc.5 → 1.6.10-rc.6

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.
@@ -5,6 +5,7 @@ import { getLocalEmbeddingRuntimeBlocker, localEmbeddingPrefixUnloadableMessage,
5
5
  import { isPrefixRuntimeLoadable, resolveEmbeddingRuntime, } from '../core/embeddings/runtime-install.js';
6
6
  import { cudaRedirectDoctorStatus } from '../core/embeddings/onnxruntime-node-resolver.js';
7
7
  import { checkLbugNative, probeFtsExtensionLoad } from '../core/lbug/native-check.js';
8
+ import { diagnoseExtensionLoad } from '../core/lbug/extension-load-error.js';
8
9
  import { getExtensionInstallPolicy } from '../core/lbug/extension-loader.js';
9
10
  import { t } from './i18n/index.js';
10
11
  function isCombiningMark(codePoint) {
@@ -116,6 +117,15 @@ export const doctorCommand = async () => {
116
117
  console.log(` ${label('doctor.labels.fullTextSearch', 18)}${ftsProbe.loaded ? 'available' : 'unavailable'}`);
117
118
  if (!ftsProbe.loaded && ftsProbe.reason) {
118
119
  console.log(` ${padDisplayEnd('', 18)}${ftsProbe.reason}`);
120
+ // Add an actionable remedy for recognized failure classes (#2374). The
121
+ // Windows missing-dependency case is the point of this: the raw error 126
122
+ // ("specified module could not be found") is opaque, so name the fix (VC++
123
+ // redist, then OpenSSL) instead of leaving the user to reinstall in vain.
124
+ // `unknown`'s remedy is "run doctor", which would be circular here.
125
+ const { kind, remedy } = diagnoseExtensionLoad(ftsProbe.reason);
126
+ if (kind !== 'unknown') {
127
+ console.log(` ${padDisplayEnd('', 18)}${remedy}`);
128
+ }
119
129
  }
120
130
  console.log(` ${label('doctor.labels.vectorIndex', 18)}${capabilities.vector}`);
121
131
  console.log(` ${label('doctor.labels.semanticMode', 18)}${capabilities.semanticMode}`);
@@ -0,0 +1,67 @@
1
+ export type ExtensionLoadErrorKind = 'missing_file' | 'corrupt_file' | 'missing_dependency' | 'unknown';
2
+ export interface ExtensionLoadDiagnosis {
3
+ readonly kind: ExtensionLoadErrorKind;
4
+ /** Actionable, literal-English remedy suited to the class. */
5
+ readonly remedy: string;
6
+ }
7
+ /**
8
+ * On-disk file corruption / wrong-platform. FORCE INSTALL re-downloads.
9
+ * Kept byte-identical to `FILE_CORRUPTION_SIGNATURES` in
10
+ * scripts/install-duckdb-extension.mjs (that `.mjs` cannot import this `.ts`;
11
+ * the duplication is deliberate — the two serve different call sites). Note
12
+ * `/not a valid/i` already covers Windows error 193 ("is not a valid Win32
13
+ * application"), so a truncated Windows download is caught here, before the
14
+ * missing-dependency branch.
15
+ */
16
+ export declare const FILE_CORRUPTION_SIGNATURES: readonly RegExp[];
17
+ /**
18
+ * Classify a collapsed LadybugDB LOAD error. Order is most-specific-first and is
19
+ * load-bearing: corrupt-file is tested before missing-dependency so a truncated
20
+ * Windows download (error 193, matched by `/not a valid/i`) routes to
21
+ * FORCE-reinstall rather than to the runtime-install remedy.
22
+ */
23
+ export declare function classifyExtensionLoadError(reason: string | undefined | null): ExtensionLoadDiagnosis;
24
+ /** Well-formedness of the extension binary for the host platform + arch. */
25
+ export type ExtensionBinaryState = 'absent' | 'corrupt' | 'valid' | 'indeterminate';
26
+ /**
27
+ * Pull the extension file path out of lbug's load error. lbug's wrapper is
28
+ * English regardless of OS language — `Failed to load library: {path} which is
29
+ * needed by extension: {name}` (real lbug), or the quoted `Failed to load
30
+ * library '{path}': {reason}` variant — so the path is recoverable in any locale.
31
+ * Only paths ending in `.lbug_extension` are accepted, so a regex misfire can
32
+ * never point the inspector at an arbitrary file.
33
+ */
34
+ export declare function extractExtensionPath(reason: string | undefined | null): string | null;
35
+ /**
36
+ * A structural verdict on a binary header. `indeterminate` means the probe could
37
+ * not prove validity OR corruption from what it read (e.g. the PE header sits past
38
+ * the BINARY_HEADER_BYTES window) — the caller defers to the string classifier
39
+ * rather than assert a false verdict.
40
+ */
41
+ type HeaderVerdict = 'valid' | 'corrupt' | 'indeterminate';
42
+ /**
43
+ * Decide whether a binary header is a well-formed shared library for the given
44
+ * platform + architecture — using only the file's structure, no localized text.
45
+ * Pure and injectable (platform/arch as params) so every format+arch combination
46
+ * is unit-testable regardless of the host it runs on.
47
+ */
48
+ export declare function classifyBinaryHeader(buf: Buffer, bytesRead: number, platform: NodeJS.Platform, arch: string): HeaderVerdict;
49
+ /**
50
+ * Best-effort language-independent inspection of the extension file. Reads the
51
+ * header and classifies it; never throws — a missing file is `absent`, an
52
+ * unreadable one is `indeterminate`.
53
+ */
54
+ export declare function inspectExtensionBinary(extensionPath: string | null | undefined): ExtensionBinaryState;
55
+ /**
56
+ * Diagnose a LadybugDB load failure, preferring a LANGUAGE-INDEPENDENT structural
57
+ * check of the extension binary over the localized error text:
58
+ * - file absent → missing_file
59
+ * - present but malformed → corrupt_file (bad magic / wrong architecture)
60
+ * - present and well-formed → missing_dependency (a valid binary the loader rejected)
61
+ * The path comes from lbug's own English wrapper, so this holds in any OS display
62
+ * language. When the file cannot be located or read, it falls back to the string
63
+ * classifier (which still carries the language-independent hedged fallback). This
64
+ * is the entry point every surface should call.
65
+ */
66
+ export declare function diagnoseExtensionLoad(reason: string | undefined | null): ExtensionLoadDiagnosis;
67
+ export {};
@@ -0,0 +1,320 @@
1
+ /**
2
+ * Classify a LadybugDB `LOAD EXTENSION` failure into one of four actionable
3
+ * classes and produce an accurate, literal-English remedy.
4
+ *
5
+ * Background (#2374): PR #2375 made the real LadybugDB LOAD error visible
6
+ * (instead of a false "not pre-installed" message). The rc.4 reproduction then
7
+ * showed the remaining defect — on Windows the extension file downloads and
8
+ * INSTALLs fine, but `LoadLibrary` fails with error 126 ("the specified module
9
+ * could not be found" / `找不到指定的模块`) because the extension dynamically
10
+ * imports OpenSSL 3 / MSVC 14 DLLs that ship nowhere. For that class, telling
11
+ * the user to reinstall/redownload is wrong — the file is fine; a *runtime
12
+ * dependency* is missing. This module decides which class an error is so each
13
+ * surface (doctor, --repair-fts, the analyze degrade warning, and
14
+ * ftsDegradedWarning) can emit the right remedy instead of a one-size-fits-all
15
+ * "reinstall over the network".
16
+ *
17
+ * `classifyExtensionLoadError` is pure string logic — no `@ladybugdb/core`
18
+ * import, no filesystem — which keeps `native-check.ts` free of a static lbug
19
+ * dependency. `diagnoseExtensionLoad` layers a LANGUAGE-INDEPENDENT structural
20
+ * check on top: it pulls the extension's file path out of lbug's own (English)
21
+ * wrapper and inspects the binary header directly (PE/ELF/Mach-O magic +
22
+ * architecture), so corrupt-vs-valid is decided by the file itself, not by the
23
+ * localized OS error tail. It reads the file (node:fs core module only, still no
24
+ * lbug) and never throws — any read failure degrades to the string classifier.
25
+ */
26
+ import { closeSync, openSync, readSync } from 'node:fs';
27
+ /** LadybugDB says the extension file was never installed. INSTALL can heal it. */
28
+ const MISSING_FILE_SIGNATURES = [
29
+ /has not been installed/i,
30
+ /not been installed/i,
31
+ ];
32
+ /**
33
+ * On-disk file corruption / wrong-platform. FORCE INSTALL re-downloads.
34
+ * Kept byte-identical to `FILE_CORRUPTION_SIGNATURES` in
35
+ * scripts/install-duckdb-extension.mjs (that `.mjs` cannot import this `.ts`;
36
+ * the duplication is deliberate — the two serve different call sites). Note
37
+ * `/not a valid/i` already covers Windows error 193 ("is not a valid Win32
38
+ * application"), so a truncated Windows download is caught here, before the
39
+ * missing-dependency branch.
40
+ */
41
+ // Exported so a parity test can assert this stays byte-identical to the copy in
42
+ // scripts/install-duckdb-extension.mjs (that `.mjs` cannot import this `.ts`), #2383 F5b.
43
+ export const FILE_CORRUPTION_SIGNATURES = [
44
+ /invalid elf/i,
45
+ /file too short/i,
46
+ /not a valid/i,
47
+ /bad magic/i,
48
+ /wrong architecture/i,
49
+ /mach-o/i,
50
+ /truncat/i,
51
+ ];
52
+ /**
53
+ * A *transitive dependency* of the extension is missing — the file loaded far
54
+ * enough to be found, but a library it needs is absent. Reinstalling the
55
+ * extension is a no-op for this class.
56
+ *
57
+ * WINDOWS CATCH-ALL GUARD (adversarial review): LadybugDB wraps *every* Windows
58
+ * load failure in `Failed to load library … which is needed by extension`, so
59
+ * that generic wrapper must NOT be sufficient — otherwise error 127 (wrong
60
+ * OpenSSL minor / unresolved procedure), 5 (AV/permission lock), and 1114
61
+ * (dependency DllMain failure) would all be mislabeled `missing_dependency` and
62
+ * told to install a runtime, the opposite of their real fix. We key strictly on
63
+ * the specific error-126 tail. Linux/macOS loaders name the missing library
64
+ * directly, so their signals are unambiguous.
65
+ *
66
+ * Localized Windows tails we do not enumerate (French, German, Japanese, …) and
67
+ * mojibake renderings of the Chinese text won't match here — but they still
68
+ * carry lbug's language-independent `Failed to load library` wrapper, so they
69
+ * are caught by the hedged fallback (LOAD_FAILURE_WRAPPER) with a non-committal
70
+ * remedy, never a wrong confident "reinstall" instruction.
71
+ */
72
+ const WINDOWS_MISSING_DEPENDENCY_SIGNATURES = [
73
+ /找不到指定的模块/,
74
+ /specified module could not be found/i,
75
+ ];
76
+ const POSIX_MISSING_DEPENDENCY_SIGNATURES = [
77
+ /cannot open shared object file/i, // Linux ld.so
78
+ /image not found/i, // macOS dyld
79
+ /library not loaded/i, // macOS dyld
80
+ ];
81
+ /**
82
+ * LadybugDB's own English wrapper for a dlopen/LoadLibrary failure
83
+ * (extension.cpp: `Failed to load library: {path} which is needed by extension:
84
+ * {name}`). It is emitted for EVERY extension load failure regardless of the OS
85
+ * display language — the only localized part is the OS-error tail after it. So
86
+ * it is the language-independent fallback signal once the specific tails miss: a
87
+ * French/German/Japanese Windows 126 has a localized tail we cannot enumerate,
88
+ * but it still carries this wrapper. See HEDGED_LOAD_FAILURE_REMEDY.
89
+ */
90
+ const LOAD_FAILURE_WRAPPER = /failed to load library/i;
91
+ const MISSING_FILE_REMEDY = 'The FTS extension is not installed. Re-run with network access and ' +
92
+ 'GITNEXUS_LBUG_EXTENSION_INSTALL=auto (or `gitnexus analyze --repair-fts`) to download it.';
93
+ const CORRUPT_FILE_REMEDY = 'The FTS extension file is present but unreadable (corrupt, truncated, or built for another ' +
94
+ 'platform). Re-download it with network access and GITNEXUS_LBUG_EXTENSION_INSTALL=auto ' +
95
+ '(`gitnexus analyze --repair-fts`).';
96
+ // Single source of truth for the VC++ runtime-install pointer, shared by the
97
+ // Windows-126 and structural missing-dependency remedies so the name/URL cannot
98
+ // drift between them (#2383 F5).
99
+ const VC_REDIST_INSTALL_HINT = 'the Microsoft Visual C++ 2015-2022 Redistributable (x64) from ' +
100
+ 'https://aka.ms/vs/17/release/vc_redist.x64.exe';
101
+ // MSVC-first per DuckDB's canonical answer for this exact error; OpenSSL second.
102
+ const WINDOWS_MISSING_DEPENDENCY_REMEDY = 'The FTS extension is present but a required runtime library is missing (Windows error 126). ' +
103
+ 'Reinstalling the extension will NOT help. Install ' +
104
+ VC_REDIST_INSTALL_HINT +
105
+ '; if the error persists, the extension also needs OpenSSL 3 ' +
106
+ '(libcrypto-3-x64.dll / libssl-3-x64.dll) on the DLL search path.';
107
+ const POSIX_MISSING_DEPENDENCY_REMEDY = 'The FTS extension is present but a shared library it depends on could not be loaded (named in ' +
108
+ 'the error above). Reinstalling the extension will NOT help — install that library or add it to ' +
109
+ 'your loader search path.';
110
+ // Language-independent fallback: we know the extension failed to load, but the
111
+ // OS-error tail is in a locale we did not enumerate, so we cannot say which class
112
+ // it is. Hedge honestly — point at the user's own localized error and give both
113
+ // branches — rather than confidently prescribing the wrong single fix. The clean
114
+ // long-term fix is upstream: have LadybugDB include the numeric GetLastError/errno
115
+ // in the message (as it already does elsewhere), so this becomes a code match.
116
+ const HEDGED_LOAD_FAILURE_REMEDY = 'The FTS extension file was found but could not be loaded — see the "Error:" text above (shown ' +
117
+ "in your system's language). Reinstalling usually will not help. If it names a missing module or " +
118
+ 'library, install the required runtime (on Windows: the Microsoft Visual C++ 2015-2022 ' +
119
+ 'Redistributable x64 and OpenSSL 3); if it names a corrupt or invalid file, run ' +
120
+ '`gitnexus analyze --repair-fts` to re-download.';
121
+ const UNKNOWN_REMEDY = 'The FTS extension failed to load for an unrecognized reason. Run `gitnexus doctor` for live ' +
122
+ 'FTS status and verify the extension file and platform.';
123
+ const matchesAny = (reason, signatures) => signatures.some((re) => re.test(reason));
124
+ /**
125
+ * Classify a collapsed LadybugDB LOAD error. Order is most-specific-first and is
126
+ * load-bearing: corrupt-file is tested before missing-dependency so a truncated
127
+ * Windows download (error 193, matched by `/not a valid/i`) routes to
128
+ * FORCE-reinstall rather than to the runtime-install remedy.
129
+ */
130
+ export function classifyExtensionLoadError(reason) {
131
+ const text = reason ?? '';
132
+ if (matchesAny(text, MISSING_FILE_SIGNATURES)) {
133
+ return { kind: 'missing_file', remedy: MISSING_FILE_REMEDY };
134
+ }
135
+ if (matchesAny(text, FILE_CORRUPTION_SIGNATURES)) {
136
+ return { kind: 'corrupt_file', remedy: CORRUPT_FILE_REMEDY };
137
+ }
138
+ if (matchesAny(text, WINDOWS_MISSING_DEPENDENCY_SIGNATURES)) {
139
+ return { kind: 'missing_dependency', remedy: WINDOWS_MISSING_DEPENDENCY_REMEDY };
140
+ }
141
+ if (matchesAny(text, POSIX_MISSING_DEPENDENCY_SIGNATURES)) {
142
+ return { kind: 'missing_dependency', remedy: POSIX_MISSING_DEPENDENCY_REMEDY };
143
+ }
144
+ // Language-independent fallback: the extension demonstrably failed to load
145
+ // (lbug's English wrapper is present) but the localized OS tail matched no
146
+ // specific class. Treat as a dependency/runtime load failure with a hedged
147
+ // remedy — strictly better than the generic `unknown` for non-English hosts,
148
+ // and it never prescribes the wrong fix.
149
+ if (LOAD_FAILURE_WRAPPER.test(text)) {
150
+ return { kind: 'missing_dependency', remedy: HEDGED_LOAD_FAILURE_REMEDY };
151
+ }
152
+ return { kind: 'unknown', remedy: UNKNOWN_REMEDY };
153
+ }
154
+ const STRUCTURAL_MISSING_DEPENDENCY_REMEDY = 'The FTS extension file is valid, so the failure is a missing or incompatible runtime dependency, ' +
155
+ 'not the extension itself — reinstalling will NOT help. On Windows, install ' +
156
+ VC_REDIST_INSTALL_HINT +
157
+ ' and ensure OpenSSL 3 is available; on Linux/macOS install the shared library named in the error above.';
158
+ /**
159
+ * Pull the extension file path out of lbug's load error. lbug's wrapper is
160
+ * English regardless of OS language — `Failed to load library: {path} which is
161
+ * needed by extension: {name}` (real lbug), or the quoted `Failed to load
162
+ * library '{path}': {reason}` variant — so the path is recoverable in any locale.
163
+ * Only paths ending in `.lbug_extension` are accepted, so a regex misfire can
164
+ * never point the inspector at an arbitrary file.
165
+ */
166
+ export function extractExtensionPath(reason) {
167
+ const text = reason ?? '';
168
+ const m = /failed to load library:?\s*['"]?(.+?\.lbug_extension)/i.exec(text);
169
+ const path = m?.[1]?.trim();
170
+ return path && path.length > 0 ? path : null;
171
+ }
172
+ /** Node `process.arch` → PE `Machine`. Undefined for arches we don't map. */
173
+ const PE_MACHINE = { x64: 0x8664, arm64: 0xaa64 };
174
+ /** Node `process.arch` → ELF `e_machine`. */
175
+ const ELF_MACHINE = { x64: 0x3e, arm64: 0xb7 };
176
+ /** Node `process.arch` → Mach-O `cputype`. */
177
+ const MACHO_CPUTYPE = { x64: 0x01000007, arm64: 0x0100000c };
178
+ function classifyPE(buf, bytesRead, arch) {
179
+ if (bytesRead < 0x40 || buf[0] !== 0x4d || buf[1] !== 0x5a)
180
+ return 'corrupt'; // 'MZ'
181
+ const peOffset = buf.readUInt32LE(0x3c);
182
+ // The PE header (e_lfanew) points beyond what we read. A large-DOS-stub VALID PE
183
+ // and a garbage e_lfanew are indistinguishable from here, so don't claim 'corrupt'
184
+ // — defer to the loader's own report (#2383 F1-secondary).
185
+ if (peOffset + 6 > bytesRead)
186
+ return 'indeterminate';
187
+ const isPE = buf[peOffset] === 0x50 &&
188
+ buf[peOffset + 1] === 0x45 &&
189
+ buf[peOffset + 2] === 0 &&
190
+ buf[peOffset + 3] === 0;
191
+ if (!isPE)
192
+ return 'corrupt';
193
+ const expected = PE_MACHINE[arch];
194
+ if (expected === undefined)
195
+ return 'valid'; // arch we don't map: don't claim corrupt
196
+ return buf.readUInt16LE(peOffset + 4) === expected ? 'valid' : 'corrupt';
197
+ }
198
+ function classifyELF(buf, bytesRead, arch) {
199
+ if (bytesRead < 20)
200
+ return 'corrupt';
201
+ if (buf[0] !== 0x7f || buf[1] !== 0x45 || buf[2] !== 0x4c || buf[3] !== 0x46)
202
+ return 'corrupt'; // 0x7F ELF
203
+ const littleEndian = buf[5] === 1; // EI_DATA
204
+ const eMachine = littleEndian ? buf.readUInt16LE(18) : buf.readUInt16BE(18);
205
+ const expected = ELF_MACHINE[arch];
206
+ if (expected === undefined)
207
+ return 'valid';
208
+ return eMachine === expected ? 'valid' : 'corrupt';
209
+ }
210
+ function classifyMachO(buf, bytesRead, arch) {
211
+ if (bytesRead < 8)
212
+ return 'corrupt';
213
+ const magicLE = buf.readUInt32LE(0);
214
+ const magicBE = buf.readUInt32BE(0);
215
+ // Universal ("fat") binary — assume it carries the host slice.
216
+ if (magicBE === 0xcafebabe || magicLE === 0xcafebabe)
217
+ return 'valid';
218
+ const thin = magicLE === 0xfeedfacf || magicLE === 0xfeedface;
219
+ const thinSwapped = magicBE === 0xfeedfacf || magicBE === 0xfeedface;
220
+ if (!thin && !thinSwapped)
221
+ return 'corrupt';
222
+ const cpuType = thin ? buf.readUInt32LE(4) : buf.readUInt32BE(4);
223
+ const expected = MACHO_CPUTYPE[arch];
224
+ if (expected === undefined)
225
+ return 'valid';
226
+ return cpuType === expected ? 'valid' : 'corrupt';
227
+ }
228
+ /**
229
+ * Decide whether a binary header is a well-formed shared library for the given
230
+ * platform + architecture — using only the file's structure, no localized text.
231
+ * Pure and injectable (platform/arch as params) so every format+arch combination
232
+ * is unit-testable regardless of the host it runs on.
233
+ */
234
+ export function classifyBinaryHeader(buf, bytesRead, platform, arch) {
235
+ if (platform === 'win32')
236
+ return classifyPE(buf, bytesRead, arch);
237
+ if (platform === 'linux')
238
+ return classifyELF(buf, bytesRead, arch);
239
+ if (platform === 'darwin')
240
+ return classifyMachO(buf, bytesRead, arch);
241
+ return 'valid'; // unknown host: never claim corrupt
242
+ }
243
+ const BINARY_HEADER_BYTES = 4096;
244
+ /**
245
+ * Best-effort language-independent inspection of the extension file. Reads the
246
+ * header and classifies it; never throws — a missing file is `absent`, an
247
+ * unreadable one is `indeterminate`.
248
+ */
249
+ export function inspectExtensionBinary(extensionPath) {
250
+ if (!extensionPath)
251
+ return 'indeterminate';
252
+ let fd;
253
+ try {
254
+ fd = openSync(extensionPath, 'r');
255
+ }
256
+ catch (err) {
257
+ return err?.code === 'ENOENT' ? 'absent' : 'indeterminate';
258
+ }
259
+ try {
260
+ const buf = Buffer.alloc(BINARY_HEADER_BYTES);
261
+ const bytesRead = readSync(fd, buf, 0, BINARY_HEADER_BYTES, 0);
262
+ return classifyBinaryHeader(buf, bytesRead, process.platform, process.arch);
263
+ }
264
+ catch {
265
+ return 'indeterminate';
266
+ }
267
+ finally {
268
+ try {
269
+ closeSync(fd);
270
+ }
271
+ catch {
272
+ /* closing the probe fd must never surface */
273
+ }
274
+ }
275
+ }
276
+ /**
277
+ * Diagnose a LadybugDB load failure, preferring a LANGUAGE-INDEPENDENT structural
278
+ * check of the extension binary over the localized error text:
279
+ * - file absent → missing_file
280
+ * - present but malformed → corrupt_file (bad magic / wrong architecture)
281
+ * - present and well-formed → missing_dependency (a valid binary the loader rejected)
282
+ * The path comes from lbug's own English wrapper, so this holds in any OS display
283
+ * language. When the file cannot be located or read, it falls back to the string
284
+ * classifier (which still carries the language-independent hedged fallback). This
285
+ * is the entry point every surface should call.
286
+ */
287
+ export function diagnoseExtensionLoad(reason) {
288
+ const text = reason ?? '';
289
+ const stringResult = classifyExtensionLoadError(text);
290
+ const fileState = inspectExtensionBinary(extractExtensionPath(text));
291
+ if (fileState === 'corrupt') {
292
+ return { kind: 'corrupt_file', remedy: CORRUPT_FILE_REMEDY };
293
+ }
294
+ if (fileState === 'valid') {
295
+ // The structural probe only inspects the first BINARY_HEADER_BYTES, so a file
296
+ // truncated AFTER its header still reads 'valid'. When the loader itself reported
297
+ // corruption (e.g. "file too short" / Windows error 193 "not a valid Win32
298
+ // application"), that whole-file verdict is stronger evidence than an intact-looking
299
+ // header — honor it and route to re-download, not a runtime-dependency install (#2383
300
+ // F1). Localized corrupt tails classify as hedged missing_dependency (not
301
+ // corrupt_file), so they still fall through to the dependency remedy below.
302
+ if (stringResult.kind === 'corrupt_file') {
303
+ return stringResult;
304
+ }
305
+ // A structurally sound binary that still failed to load ⇒ a dependency/runtime
306
+ // problem, decided WITHOUT the localized tail. Keep the string classifier's
307
+ // sharper remedy when it recognized the specific case (e.g. English 126).
308
+ const remedy = stringResult.kind === 'missing_dependency'
309
+ ? stringResult.remedy
310
+ : STRUCTURAL_MISSING_DEPENDENCY_REMEDY;
311
+ return { kind: 'missing_dependency', remedy };
312
+ }
313
+ // 'absent' or 'indeterminate' → no positive structural evidence, so defer to the
314
+ // string classifier. Note a real never-installed extension has NO path in its
315
+ // reason (lbug says "has not been installed"), so it lands here via
316
+ // 'indeterminate' and the string classifier reports missing_file correctly; a
317
+ // path that lbug named but that is now gone (stale/racy) is better judged by
318
+ // what lbug actually reported than by re-deriving from disk.
319
+ return stringResult;
320
+ }
@@ -1,3 +1,4 @@
1
+ import { type ExtensionLoadDiagnosis } from './extension-load-error.js';
1
2
  /**
2
3
  * Lifecycle policy for an optional DuckDB extension.
3
4
  *
@@ -20,6 +21,12 @@ export interface ExtensionCapability {
20
21
  loaded: boolean;
21
22
  /** Human-readable reason when `loaded` is false. */
22
23
  reason?: string;
24
+ /**
25
+ * Classified diagnosis of `reason`, computed ONCE at mark-unavailable time so
26
+ * per-request surfaces (ftsDegradedWarning on /api/search + MCP query) read the
27
+ * cached remedy instead of re-inspecting the extension file on every call (#2383 F3).
28
+ */
29
+ diagnosis?: ExtensionLoadDiagnosis;
23
30
  }
24
31
  /** Per-call overrides applied on top of `ExtensionManager` defaults. */
25
32
  export interface ExtensionEnsureOptions {
@@ -1,6 +1,7 @@
1
1
  import { spawn } from 'child_process';
2
2
  import { fileURLToPath } from 'node:url';
3
3
  import { LBUG_MAX_DB_SIZE } from './lbug-config.js';
4
+ import { diagnoseExtensionLoad } from './extension-load-error.js';
4
5
  import { logger } from '../logger.js';
5
6
  const DEFAULT_EXTENSION_INSTALL_TIMEOUT_MS = 15_000;
6
7
  const EXTENSION_NAME_PATTERN = /^[A-Za-z][A-Za-z0-9_]*$/;
@@ -208,7 +209,14 @@ export class ExtensionManager {
208
209
  this.capabilities.set(name, { name, loaded: true });
209
210
  }
210
211
  markUnavailable(name, label, reason, warn) {
211
- this.capabilities.set(name, { name, loaded: false, reason });
212
+ // Classify once here (the single load-failure sink, run per Database not per
213
+ // request) so the hot per-request warning path does no file I/O (#2383 F3).
214
+ this.capabilities.set(name, {
215
+ name,
216
+ loaded: false,
217
+ reason,
218
+ diagnosis: diagnoseExtensionLoad(reason),
219
+ });
212
220
  const key = `${name}:${reason}`;
213
221
  if (this.warnedKeys.has(key))
214
222
  return;
@@ -17,6 +17,7 @@ import { initLbug, loadGraphToLbug, getLbugStats, executeQuery, executeWithReuse
17
17
  import { createSearchFTSIndexes, initialiseSearchFTSStemmer, verifySearchFTSIndexes, } from './search/fts-indexes.js';
18
18
  import { cjkSegmentationModeMismatch, getSearchFTSCjkSegmentation, initialiseSearchFTSCjkSegmentation, } from './search/cjk-segmentation.js';
19
19
  import { getExtensionCapabilities, resolveAnalyzeInstallPolicy } from './lbug/extension-loader.js';
20
+ import { diagnoseExtensionLoad } from './lbug/extension-load-error.js';
20
21
  import { startWalCheckpointDriver, } from './lbug/wal-checkpoint-driver.js';
21
22
  import { getStoragePaths, resolveBranchPlacement, saveMeta, loadMeta, ensureGitNexusIgnored, registerRepo, adoptFlatBranchLabel, isReadOnlyFilesystemError, isRepoRegistered, cleanupOldKuzuFiles, reconcileMetadataFiles, isMissingFilesystemError, INDEX_METADATA_FILE, INCREMENTAL_SCHEMA_VERSION, } from '../storage/repo-manager.js';
22
23
  import { DEFAULT_PDG_MAX_FUNCTION_LINES } from './ingestion/cfg/collect.js';
@@ -41,7 +42,11 @@ import { STALE_HASH_SENTINEL } from './lbug/schema.js';
41
42
  * a full analyze. Kept as a named constant so the env-var/command guidance
42
43
  * stays in one place (mirrors the VECTOR message in embedding-pipeline.ts).
43
44
  */
44
- const FTS_UNAVAILABLE_MESSAGE = 'FTS extension unavailable; skipping search-index creation. ' +
45
+ // Class-neutral lead, reused for the missing-dependency degrade path (#2383 F2):
46
+ // its remedy already explains that reinstalling will NOT help, so appending the
47
+ // generic "install with network access" tail below would contradict it.
48
+ const FTS_UNAVAILABLE_LEAD = 'FTS extension unavailable; skipping search-index creation.';
49
+ const FTS_UNAVAILABLE_MESSAGE = `${FTS_UNAVAILABLE_LEAD} ` +
45
50
  'Full-text/BM25 search will be disabled until the LadybugDB FTS extension is ' +
46
51
  'installed once with network access (GITNEXUS_LBUG_EXTENSION_INSTALL=auto) or ' +
47
52
  'pre-installed for offline use. Run `gitnexus doctor` for details.';
@@ -368,13 +373,20 @@ export async function runFullAnalysis(repoPath, options, callbacks) {
368
373
  // Surface the load-side reason (#2374): "not pre-installed" was wrong
369
374
  // and doctor never installed anything, so the old message trapped
370
375
  // users in a query → repair-fts → doctor loop with no way out.
371
- const ftsReason = getExtensionCapabilities()
372
- .find((c) => c.name === 'fts')
373
- ?.reason?.replace(/\.$/, '');
376
+ const rawFtsReason = getExtensionCapabilities().find((c) => c.name === 'fts')?.reason;
377
+ const ftsReason = rawFtsReason?.replace(/\.$/, '');
378
+ // A missing runtime dependency (Windows error 126, #2374) is not healed
379
+ // by re-installing — the file is already present. Route that class to the
380
+ // classified remedy (install VC++ redist / OpenSSL) instead of the old
381
+ // "retry the network install" text that trapped the user in a loop.
382
+ const { kind, remedy } = diagnoseExtensionLoad(rawFtsReason);
383
+ const remedyTail = kind === 'missing_dependency'
384
+ ? ` ${remedy}`
385
+ : '. Retry with network access and GITNEXUS_LBUG_EXTENSION_INSTALL=auto to install it, ' +
386
+ 'or pre-install the extension file; run `gitnexus doctor` for live FTS status.';
374
387
  throw new Error('Cannot repair FTS indexes: the LadybugDB FTS extension failed to load' +
375
388
  (ftsReason ? ` — ${ftsReason}` : '') +
376
- '. Retry with network access and GITNEXUS_LBUG_EXTENSION_INSTALL=auto to install it, ' +
377
- 'or pre-install the extension file; run `gitnexus doctor` for live FTS status.');
389
+ remedyTail);
378
390
  }
379
391
  progress('fts', 85, 'Repairing search indexes...');
380
392
  await createSearchFTSIndexes({
@@ -963,7 +975,15 @@ export async function runFullAnalysis(repoPath, options, callbacks) {
963
975
  progress('fts', 90, 'Search indexes ready');
964
976
  }
965
977
  else {
966
- log(FTS_UNAVAILABLE_MESSAGE);
978
+ // For a missing runtime dependency (#2374) the file is present, so the
979
+ // generic "install it with network access" tail in FTS_UNAVAILABLE_MESSAGE
980
+ // contradicts the remedy's own "reinstalling will NOT help" (#2383 F2). Lead
981
+ // with the class-neutral sentence and append only the classified remedy.
982
+ const ftsReason = getExtensionCapabilities().find((c) => c.name === 'fts')?.reason;
983
+ const { kind, remedy } = diagnoseExtensionLoad(ftsReason);
984
+ log(kind === 'missing_dependency'
985
+ ? `${FTS_UNAVAILABLE_LEAD} ${remedy}`
986
+ : FTS_UNAVAILABLE_MESSAGE);
967
987
  progress('fts', 90, 'Search indexes skipped (FTS unavailable)');
968
988
  }
969
989
  // ── Phase 3.5: Re-insert cached embeddings ────────────────────────
@@ -1,5 +1,6 @@
1
1
  import { createFTSIndex, dropFTSIndex, DEFAULT_FTS_STEMMER } from '../lbug/lbug-adapter.js';
2
2
  import { getExtensionCapabilities } from '../lbug/extension-loader.js';
3
+ import { classifyExtensionLoadError } from '../lbug/extension-load-error.js';
3
4
  import { FTS_INDEXES } from './fts-schema.js';
4
5
  /**
5
6
  * Strip filesystem paths from a LadybugDB error before it reaches the HTTP
@@ -21,9 +22,18 @@ export const ftsDegradedWarning = () => {
21
22
  const fts = getExtensionCapabilities().find((c) => c.name === 'fts');
22
23
  if (fts && !fts.loaded) {
23
24
  const reason = fts.reason ? redactPaths(fts.reason).replace(/\.$/, '') : undefined;
25
+ // A missing *runtime dependency* (Windows error 126, etc.) is not healed by
26
+ // reinstalling (#2374) — surface the classified remedy instead of the generic
27
+ // reinstall tail. Read the diagnosis cached at mark-unavailable time so this
28
+ // per-request path (HTTP /api/search + MCP query) does NO file I/O (#2383 F3);
29
+ // fall back to the pure, no-I/O string classifier if it is somehow absent.
30
+ const { kind, remedy } = fts.diagnosis ?? classifyExtensionLoadError(fts.reason);
31
+ const tail = kind === 'missing_dependency'
32
+ ? ` ${remedy}`
33
+ : '. Run `gitnexus doctor` for details, then `gitnexus analyze --repair-fts` with network access to reinstall.';
24
34
  return ('FTS extension failed to load — keyword search degraded' +
25
35
  (reason ? ` (${reason})` : '') +
26
- '. Run `gitnexus doctor` for details, then `gitnexus analyze --repair-fts` with network access to reinstall.');
36
+ tail);
27
37
  }
28
38
  return 'FTS indexes missing — keyword search degraded. Run: gitnexus analyze --repair-fts (or gitnexus analyze --force) to rebuild indexes.';
29
39
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gitnexus",
3
- "version": "1.6.10-rc.5",
3
+ "version": "1.6.10-rc.6",
4
4
  "description": "Graph-powered code intelligence for AI agents. Index any codebase, query via MCP or CLI.",
5
5
  "author": "Abhigyan Patwari",
6
6
  "license": "PolyForm-Noncommercial-1.0.0",
@@ -61,6 +61,11 @@ const PLATFORM_LOGIC = [
61
61
  // array form. Runs on every platform (the ubuntu suite covers Linux; this
62
62
  // registration adds windows + macos).
63
63
  'test/unit/embedding-install-arg-delivery.test.ts',
64
+ // Structural FTS-extension classifier against REAL binaries (#2374): on this
65
+ // matrix `process.execPath` / `lbugjs.node` are a real PE (windows) and Mach-O
66
+ // (macos), so the header parsing is proven on genuine binaries, not synthetic
67
+ // buffers (the ubuntu suite covers the ELF path).
68
+ 'test/integration/extension-binary-real.test.ts',
64
69
  ];
65
70
 
66
71
  // Native LadybugDB integration tests — exercise the @ladybugdb/core
@@ -13,7 +13,9 @@ const EXTENSION_NAME_PATTERN = /^[A-Za-z][A-Za-z0-9_]*$/;
13
13
  // a missing file (plain INSTALL downloads it), or a permanent non-file failure a
14
14
  // re-download can never fix (missing runtime dep: "cannot open shared object") —
15
15
  // plain INSTALL avoids re-downloading ~2 MB on every analyze run forever.
16
- const FILE_CORRUPTION_SIGNATURES = [
16
+ // Exported so a parity test keeps this byte-identical to the copy in
17
+ // src/core/lbug/extension-load-error.ts (this `.mjs` cannot import that `.ts`), #2383 F5b.
18
+ export const FILE_CORRUPTION_SIGNATURES = [
17
19
  /invalid elf/i,
18
20
  /file too short/i,
19
21
  /not a valid/i,