Skip to content

Commit ec26da9

Browse files
nodeeeeeeclaude
andcommitted
Add pre-flight diagnostics for smart match to surface the actual error
Before spawning the Python script, the IPC handler now: 1. Logs Python path, script path, course dir, and dir existence 2. Runs a quick import check (numpy, fitz, sentence_transformers) and immediately returns a clear error if any are missing: "Python (/path) is missing packages: fitz. Reinstall ML environment." 3. On failure, shows full diagnostics in the terminal panel (not just a vague snackbar) with possible causes listed This should reveal exactly why smart match fails on the user's machine. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent b93f64c commit ec26da9

2 files changed

Lines changed: 47 additions & 5 deletions

File tree

electron/main.js

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -997,7 +997,41 @@ function registerIpc() {
997997
const python = getPythonPath();
998998
const script = SCRIPTS.align;
999999
const outDir = getOutputDir();
1000-
console.log(`[align:suggestMatches] python=${python} script=${script} course=${cid} model=${model} outDir=${outDir}`);
1000+
const courseDir = path.join(outDir, String(cid));
1001+
1002+
// Pre-flight diagnostics
1003+
const diag = [];
1004+
diag.push(`Python: ${python} (exists: ${fs.existsSync(python)})`);
1005+
diag.push(`Script: ${script} (exists: ${fs.existsSync(script)})`);
1006+
diag.push(`DATA_DIR: ${DATA_DIR}`);
1007+
diag.push(`OutputDir: ${outDir}`);
1008+
diag.push(`CourseDir: ${courseDir} (exists: ${fs.existsSync(courseDir)})`);
1009+
diag.push(`Captions: ${fs.existsSync(path.join(courseDir, 'captions'))}`);
1010+
diag.push(`Materials: ${fs.existsSync(path.join(courseDir, 'materials'))}`);
1011+
console.log(`[align:suggestMatches] ${diag.join(' | ')}`);
1012+
1013+
// Quick pre-check: can this Python import the needed packages?
1014+
const checkCode = "import sys; " +
1015+
"errs=[]; " +
1016+
"[errs.append(n) for n in ['numpy','fitz','sentence_transformers'] if not __import__('importlib').util.find_spec(n)]; " +
1017+
"print('MISSING:'+','.join(errs) if errs else 'OK'); " +
1018+
"print('PYTHON:'+sys.executable); " +
1019+
"print('PREFIX:'+sys.prefix)";
1020+
const chk = spawnSync(python, ['-c', checkCode], {
1021+
encoding: 'utf8', timeout: 10000,
1022+
env: { ...process.env, AUTONOTE_DATA_DIR: DATA_DIR },
1023+
});
1024+
const chkOut = (chk.stdout || '') + (chk.stderr || '');
1025+
diag.push(`PreCheck: ${chkOut.replace(/\n/g, ' | ').trim()}`);
1026+
console.log(`[align:suggestMatches] precheck: ${chkOut.trim()}`);
1027+
1028+
if (chkOut.includes('MISSING:') && !chkOut.includes('MISSING:OK') && !chkOut.includes('MISSING:\n')) {
1029+
const missing = chkOut.match(/MISSING:(.+)/)?.[1]?.trim();
1030+
if (missing) {
1031+
resolve({ __error: `Python (${python}) is missing packages: ${missing}. Reinstall ML environment with these components enabled.` });
1032+
return;
1033+
}
1034+
}
10011035

10021036
const cmd = [python, script, '--course', String(cid),
10031037
'--suggest-matches', '--match-model', model || 'bge-m3'];

electron/renderer/app.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,14 +1503,22 @@ async function attachPageHandlers() {
15031503
const matches = await window.api.alignSuggestMatches(cid, model);
15041504

15051505
if (matches?.__error) {
1506-
snack(`Smart match failed: ${matches.__error}`, false);
1507-
if (statusEl) statusEl.textContent = 'Smart match failed — see error above.';
1506+
// Show error in both snackbar and terminal for full diagnostics
1507+
Term.write(`\n✗ Smart match error:\n${matches.__error}\n`, 'err');
1508+
snack(`Smart match failed — see terminal for details.`, false);
1509+
if (statusEl) statusEl.textContent = 'Smart match failed — see terminal below.';
15081510
return;
15091511
}
15101512

15111513
if (!matches || !Object.keys(matches).length) {
1512-
snack('Embedding matching returned no results — using heuristic suggestions.', false);
1513-
if (statusEl) statusEl.textContent = 'No embedding matches found.';
1514+
Term.write('\n✗ Smart match returned empty results.\n'
1515+
+ 'Possible causes:\n'
1516+
+ ' - pymupdf not installed (cannot read PDF slide text)\n'
1517+
+ ' - sentence-transformers not installed (cannot embed text)\n'
1518+
+ ' - No captions or materials found for this course\n'
1519+
+ ` - Course dir: check if files exist under Output Dir / ${cid}\n`, 'warn');
1520+
snack('No embedding matches — see terminal for diagnostics.', false);
1521+
if (statusEl) statusEl.textContent = 'No matches — check terminal.';
15141522
return;
15151523
}
15161524

0 commit comments

Comments
 (0)