From 86840d5075ffde7f568d7a1e240d9a7b8d48af71 Mon Sep 17 00:00:00 2001 From: Carter Francis Date: Sat, 7 Nov 2026 08:41:44 -0600 Subject: [PATCH 1/2] Replace three operator texts that showed internals MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - First-run setup leaves out the PyTorch step for an app with no torch in its lock: main sends torch: false on the start message, read from the bundled uv.lock as setupEnv already does. - A failed setup says "Details are in the setup log below. Press Retry. If this PC has no internet, press Install from a folder…" instead of a tool's exit code; the raw error becomes the log's last line. - A failed message names the action ("find_vectors failed — details are in the log.") instead of showing the exception text, and the log record names it too. Part of #30. "Backend stopped" follows once #39, which rewrites how backend_exited is sent, is merged. --- de_shell/app.py | 16 +++++++++++++--- de_shell/js/main/envSetup.ts | 5 ++++- de_shell/js/main/envSetupMachine.test.ts | 24 ++++++++++++++++++++++++ de_shell/js/main/envSetupMachine.ts | 10 +++++++++- de_shell/js/renderer/EnvSetupOverlay.tsx | 12 +++++++++--- de_shell/js/renderer/envSetupView.ts | 8 +++++--- de_shell/js/renderer/shellModels.test.ts | 7 +++++++ de_shell/js/renderer/shellState.test.ts | 7 +++++++ de_shell/js/renderer/shellState.ts | 10 ++++++++-- tests/test_actions.py | 9 +++++++++ 10 files changed, 95 insertions(+), 13 deletions(-) diff --git a/de_shell/app.py b/de_shell/app.py index f7ee4fa..4f95c7d 100644 --- a/de_shell/app.py +++ b/de_shell/app.py @@ -134,13 +134,23 @@ async def _main( pass # the app claimed it else: log.warning("[backend] unknown message type: %s", msg_type) - except Exception as e: - log.exception("handling %s failed", msg_type) - ipc.emit_error(str(e)) + except Exception: + what = _what_failed(msg) + log.exception("%s failed", what) + ipc.emit_error(f"{what} failed — details are in the log.") session.shutdown() +def _what_failed(msg: dict) -> str: + """What the status bar names when handling ``msg`` raised: the action for an + action, else the message type. The exception text (a KeyError shows as just + 'name') goes to the log with its traceback instead.""" + if msg.get("type") == "action": + return str(msg.get("action")) + return str(msg.get("type")) + + def run( build_session: Callable[[], object], *, diff --git a/de_shell/js/main/envSetup.ts b/de_shell/js/main/envSetup.ts index 958ebdd..38856d3 100644 --- a/de_shell/js/main/envSetup.ts +++ b/de_shell/js/main/envSetup.ts @@ -13,12 +13,14 @@ * are buffered until the renderer listens — a progress line sent before React * mounted is not lost. */ +import { join } from 'path' + import { app, dialog, ipcMain } from 'electron' import { channel, shellConfig } from './config' import { runEnvSetupMachine } from './envSetupMachine' import type { EnvSetupAnswer } from './envSetupMachine' -import { resolvePythonEnv } from './pythonEnv' +import { readLockedTorchVersion, resolvePythonEnv } from './pythonEnv' import type { EnsureOptions, ResolvedPython } from './pythonEnv' import type { ShellWindow } from './window' @@ -56,6 +58,7 @@ export function runEnvSetup( listenForAnswers() return runEnvSetupMachine({ initialWheelhouse: opts.wheelhouse ?? null, + torch: readLockedTorchVersion(join(opts.resourcesPath, 'python')) !== null, run: (wheelhouse, onProgress) => resolvePythonEnv({ ...opts, wheelhouse, diff --git a/de_shell/js/main/envSetupMachine.test.ts b/de_shell/js/main/envSetupMachine.test.ts index c3c4ea1..62366f9 100644 --- a/de_shell/js/main/envSetupMachine.test.ts +++ b/de_shell/js/main/envSetupMachine.test.ts @@ -152,3 +152,27 @@ describe('the setup state machine', () => { assert.deepEqual(s.runs, ['E:/offline']) }) }) + +describe('the PyTorch step', () => { + async function startMessage(torch: boolean | undefined) { + const out: EnvSetupWireMessage[] = [] + await runEnvSetupMachine({ + run: async () => 'ok', + emit: (m) => out.push(m), + waitForAnswer: async () => 'quit' as EnvSetupAnswer, + pickFolder: async () => null, + quit: () => {}, + ...(torch === undefined ? {} : { torch }), + }) + return out.find((m) => m.state === 'start') + } + + test('start says so when the app has no torch', async () => { + assert.equal((await startMessage(false))?.torch, false) + }) + + test('start leaves the default alone otherwise', async () => { + assert.equal((await startMessage(true))?.torch, undefined) + assert.equal((await startMessage(undefined))?.torch, undefined) + }) +}) diff --git a/de_shell/js/main/envSetupMachine.ts b/de_shell/js/main/envSetupMachine.ts index 8eda693..f7410dc 100644 --- a/de_shell/js/main/envSetupMachine.ts +++ b/de_shell/js/main/envSetupMachine.ts @@ -31,6 +31,8 @@ export interface EnvSetupWireMessage { event?: EnvProgressEvent /** The raw lines of this batch, newline-joined (progress only). */ line?: string + /** False when setup has no PyTorch step (start only). */ + torch?: boolean /** Human-readable failure (error only). */ message?: string /** The wheelhouse folder being installed from, when there is one. */ @@ -117,6 +119,8 @@ export interface MachineDeps { /** Native folder picker; null when cancelled. */ pickFolder: () => Promise quit: () => void + /** False when the app's lock has no torch, so the overlay drops that step. */ + torch?: boolean /** Wheelhouse to start with (an app that already knows the machine is offline). */ initialWheelhouse?: string | null intervalMs?: number @@ -126,7 +130,11 @@ export async function runEnvSetupMachine(deps: MachineDeps): Promise { let wheelhouse = deps.initialWheelhouse ?? null for (;;) { const batcher = createProgressBatcher({ emit: deps.emit, intervalMs: deps.intervalMs }) - deps.emit({ type: 'env_setup', state: 'start', ...(wheelhouse ? { wheelhouse } : {}) }) + deps.emit({ + type: 'env_setup', state: 'start', + ...(wheelhouse ? { wheelhouse } : {}), + ...(deps.torch === false ? { torch: false } : {}), + }) try { const result = await deps.run(wheelhouse, batcher.push) batcher.flush() diff --git a/de_shell/js/renderer/EnvSetupOverlay.tsx b/de_shell/js/renderer/EnvSetupOverlay.tsx index d4cdf56..87589e1 100644 --- a/de_shell/js/renderer/EnvSetupOverlay.tsx +++ b/de_shell/js/renderer/EnvSetupOverlay.tsx @@ -36,7 +36,9 @@ export function EnvSetupOverlay({ setup, appName, envSetup, description }: EnvSe }, [setup.lines]) const failed = !!setup.error - const tail = logTail(setup.lines) + // The raw failure (often a tool's exit code) goes to the end of the log, + // where it stays on screen; the headline says what to do instead. + const tail = logTail(failed ? [...setup.lines, String(setup.error)] : setup.lines) return (
@@ -49,7 +51,7 @@ export function EnvSetupOverlay({ setup, appName, envSetup, description }: EnvSe
{failed ? ( -
{setup.error}
+
{SETUP_FAILED_TEXT}
) : (
{description ?? 'First launch only — downloading the analysis environment. ' @@ -61,7 +63,7 @@ export function EnvSetupOverlay({ setup, appName, envSetup, description }: EnvSe {!failed && ( <>
- {phasePills(setup.phase).map((p) => ( + {phasePills(setup.phase, setup.torch ?? true).map((p) => ( = [ export type PillState = 'done' | 'active' | 'todo' -export function phasePills(phase: EnvPhase) { +/** `torch` false leaves out the PyTorch pill, for an app with no torch in its lock. */ +export function phasePills(phase: EnvPhase, torch = true) { + const phases = torch ? ENV_PHASES : ENV_PHASES.filter(p => p.key !== 'torch') const active = phase === 'working' ? 'resolving' : phase - const activeIdx = ENV_PHASES.findIndex(p => p.key === active) - return ENV_PHASES.map((p, i) => ({ + const activeIdx = phases.findIndex(p => p.key === active) + return phases.map((p, i) => ({ key: p.key, label: p.label, state: (i < activeIdx ? 'done' : i === activeIdx ? 'active' : 'todo') as PillState, diff --git a/de_shell/js/renderer/shellModels.test.ts b/de_shell/js/renderer/shellModels.test.ts index 6626960..9e3406c 100644 --- a/de_shell/js/renderer/shellModels.test.ts +++ b/de_shell/js/renderer/shellModels.test.ts @@ -89,3 +89,10 @@ test('env_setup messages from runEnvSetup flow through the shell reducer', () => s = shellReducer(s, act({ state: 'done' })) assert.equal(s.envSetup, null) }) + +test('phasePills leaves out PyTorch for an app with no torch', () => { + assert.deepEqual(phasePills('installing', false).map(p => p.label), + ['Resolve', 'Download', 'Install', 'Build']) + assert.deepEqual(phasePills('installing', false).map(p => p.state), + ['done', 'done', 'active', 'todo']) +}) diff --git a/de_shell/js/renderer/shellState.test.ts b/de_shell/js/renderer/shellState.test.ts index 7333a46..dee5000 100644 --- a/de_shell/js/renderer/shellState.test.ts +++ b/de_shell/js/renderer/shellState.test.ts @@ -166,6 +166,13 @@ describe('computing overlays and action state', () => { }) describe('toShellAction', () => { + test('carries a setup with no PyTorch step through to the overlay state', () => { + const start = toShellAction({ type: 'env_setup', state: 'start', torch: false })! + assert.deepEqual(start, { type: 'ENV_SETUP_START', wheelhouse: null, torch: false }) + assert.equal(shellReducer(appState, start).envSetup?.torch, false) + assert.equal(shellReducer(appState, { type: 'ENV_SETUP_START' }).envSetup?.torch, true) + }) + test('maps the chrome messages', () => { assert.deepEqual(toShellAction({ type: 'status', text: 'hi' }), { type: 'STATUS', text: 'hi' }) diff --git a/de_shell/js/renderer/shellState.ts b/de_shell/js/renderer/shellState.ts index 81ca05e..54f35c1 100644 --- a/de_shell/js/renderer/shellState.ts +++ b/de_shell/js/renderer/shellState.ts @@ -71,6 +71,9 @@ export interface EnvSetupState { error?: string | null /** Folder being installed from, once the user picked one. */ wheelhouse?: string | null + /** Whether setup has a PyTorch step; false for an app with no torch in its + * lock. Absent means true, which is what older mains imply. */ + torch?: boolean } export interface ShellState { @@ -125,7 +128,7 @@ export type ShellAction = | { type: 'LOG_CLEAR' } | { type: 'LOG_LEVEL'; level: string } | { type: 'BACKEND_EXITED'; code: number | null; reason?: string } - | { type: 'ENV_SETUP_START'; wheelhouse?: string | null } + | { type: 'ENV_SETUP_START'; wheelhouse?: string | null; torch?: boolean } | { type: 'ENV_SETUP_ERROR'; message: string; wheelhouse?: string | null } | { type: 'ENV_SETUP_PROGRESS'; phase?: EnvPhase; step?: string; percent: number | null; raw: string } | { type: 'ENV_SETUP_DONE' } @@ -199,6 +202,7 @@ export function shellReducer(state: S, action: ShellAction lines: [], error: null, wheelhouse: action.wheelhouse ?? null, + torch: action.torch ?? true, }, status: 'Setting up the analysis environment…', } @@ -319,7 +323,9 @@ export function toShellAction(msg: Record): ShellAction | null // flat shape some apps still emit themselves. const wheelhouse = (msg.wheelhouse ?? null) as string | null const st = msg.state ?? (typeof msg.event === 'string' ? msg.event : 'progress') - if (st === 'start') return { type: 'ENV_SETUP_START', wheelhouse } + if (st === 'start') { + return { type: 'ENV_SETUP_START', wheelhouse, ...(msg.torch === false ? { torch: false } : {}) } + } if (st === 'done') return { type: 'ENV_SETUP_DONE' } if (st === 'error') { return { type: 'ENV_SETUP_ERROR', message: String(msg.message ?? 'Setup failed'), wheelhouse } diff --git a/tests/test_actions.py b/tests/test_actions.py index 9211c4e..590af8b 100644 --- a/tests/test_actions.py +++ b/tests/test_actions.py @@ -13,6 +13,7 @@ import pytest from de_shell.actions import figure_registry +from de_shell.app import _what_failed from de_shell.actions.lifecycle import ( bump_generation, is_current, progress_emitter, replace_tree_attr, run_on_worker, window_computing, @@ -292,3 +293,11 @@ def test_registering_the_same_evictor_twice_is_idempotent(self): assert seen == [4244], "a module importing twice must not double-evict" finally: figure_registry._EVICTORS.remove(seen.append) + + +class TestFailureText: + def test_an_action_is_named_by_its_action(self): + assert _what_failed({"type": "action", "action": "find_vectors"}) == "find_vectors" + + def test_another_message_is_named_by_its_type(self): + assert _what_failed({"type": "figure_event", "fig_id": "f"}) == "figure_event" From 6ad4f89fe37e4dcd554ccb27c9b22dbd89cb7fd4 Mon Sep 17 00:00:00 2001 From: Carter Francis Date: Sat, 7 Nov 2026 08:41:56 -0600 Subject: [PATCH 2/2] Add changelog fragments for #40 --- upcoming_changes/40.bugfix.1.rst | 1 + upcoming_changes/40.bugfix.2.rst | 1 + upcoming_changes/40.bugfix.rst | 1 + 3 files changed, 3 insertions(+) create mode 100644 upcoming_changes/40.bugfix.1.rst create mode 100644 upcoming_changes/40.bugfix.2.rst create mode 100644 upcoming_changes/40.bugfix.rst diff --git a/upcoming_changes/40.bugfix.1.rst b/upcoming_changes/40.bugfix.1.rst new file mode 100644 index 0000000..751f2d2 --- /dev/null +++ b/upcoming_changes/40.bugfix.1.rst @@ -0,0 +1 @@ +A failed first-run setup tells the user what to do next instead of showing a tool's exit code, which moves to the end of the setup log. diff --git a/upcoming_changes/40.bugfix.2.rst b/upcoming_changes/40.bugfix.2.rst new file mode 100644 index 0000000..636fda3 --- /dev/null +++ b/upcoming_changes/40.bugfix.2.rst @@ -0,0 +1 @@ +When handling a message fails, the status bar names the action that failed instead of showing the raw exception text. diff --git a/upcoming_changes/40.bugfix.rst b/upcoming_changes/40.bugfix.rst new file mode 100644 index 0000000..4eba74e --- /dev/null +++ b/upcoming_changes/40.bugfix.rst @@ -0,0 +1 @@ +First-run setup no longer shows a PyTorch step in apps that do not install PyTorch.