Skip to content

The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.

fix(engine): die Antwort der Startprobe steht am Prozess, nicht nur im Rueckgabewert

purple51133c03f57c
diff --git a/src-tauri/src/commands/engine.rs b/src-tauri/src/commands/engine.rs
index d3f637aa..1f30de28 100644
--- a/src-tauri/src/commands/engine.rs
+++ b/src-tauri/src/commands/engine.rs
@@ -2118,6 +2118,7 @@ fn serve_or_heal_garbled(
);
answer["garbled"] = serde_json::json!(true);
answer["note"] = serde_json::json!(engine_sanity::GARBLED_ON_CPU_NOTE);
+ remember_sanity_note(state, engine_sanity::GARBLED_ON_CPU_NOTE);
return answer;
}
engine_sanity::AfterProbe::RestartWithoutFlashAttention => {
@@ -2163,6 +2164,7 @@ fn serve_or_heal_garbled(
let _ = spawn_engine_attempt(state, binary, args, model_path, port, ctx, auto_layers, false);
answer["garbled"] = serde_json::json!(true);
answer["note"] = serde_json::json!(engine_sanity::GARBLED_ON_CPU_NOTE);
+ remember_sanity_note(state, engine_sanity::GARBLED_ON_CPU_NOTE);
return answer;
}
answer["retried"] = serde_json::json!(true);
@@ -2172,17 +2174,29 @@ fn serve_or_heal_garbled(
// judged the new engine. Until then it says what was done, and the pass
// that finds the answer readable returns it; a pass that does not
// overwrites it.
- answer["note"] = serde_json::json!(if next.gpu_layers == 0 {
+ let healed = if cpu_rung {
engine_sanity::HEALED_ON_CPU_NOTE
} else {
engine_sanity::HEALED_WITHOUT_FLASH_ATTENTION_NOTE
- });
+ };
+ answer["note"] = serde_json::json!(healed);
+ remember_sanity_note(state, healed);
serving = next;
serving_args = next_args;
}
answer
}
+/// Pin the sanity probe's sentence to the process it is about, so a status
+/// read after the start call has returned can still say it. A slot that is
+/// empty here means the engine died between the probe and now, and there is
+/// nothing left to annotate.
+fn remember_sanity_note(state: &AppState, note: &'static str) {
+ if let Some(live) = state.bundled_engine.lock().unwrap().as_mut() {
+ live.sanity_note = Some(note);
+ }
+}
+
/// What one spawn-and-wait produced when it did not come up.
pub(crate) struct StartFailure {
/// The child was gone before the health budget ran out. Distinguishes a
@@ -2274,6 +2288,7 @@ fn spawn_engine_attempt(
args: args.to_vec(),
auto_layers,
cpu_fallback,
+ sanity_note: None,
});
let outcome = wait_for_health_or_exit(state, port, health_timeout_for(model_path));
@@ -2384,6 +2399,11 @@ pub async fn bundled_engine_status(app: AppHandle) -> Result<serde_json::Value,
// ran at a tenth of the speed.
"cpuOnly": live.cpu_fallback,
"gpuLayers": live.gpu_layers,
+ // The sanity probe's verdict about THIS process (bug a). The
+ // start call answered it once; the status keeps it, so the
+ // standing line can say why the card was taken away, and
+ // why an engine that kept its layers restarted at all.
+ "sanityNote": live.sanity_note,
}),
None => serde_json::json!({
"running": false,
@@ -2393,6 +2413,7 @@ pub async fn bundled_engine_status(app: AppHandle) -> Result<serde_json::Value,
"ctx": null,
"cpuOnly": false,
"gpuLayers": null,
+ "sanityNote": null,
}),
}
})
@@ -2946,6 +2967,8 @@ pub(crate) struct LiveSidecar {
/// The `-ngl` the process really carries, `None` when it asked for all of
/// them (`gpu_layers_reported`).
pub gpu_layers: Option<u32>,
+ /// The sentence the sanity probe left behind (`BundledEngine::sanity_note`).
+ pub sanity_note: Option<&'static str>,
}
pub(crate) fn live_sidecar(slot: &mut Option<BundledEngine>) -> Option<LiveSidecar> {
@@ -2956,6 +2979,7 @@ pub(crate) fn live_sidecar(slot: &mut Option<BundledEngine>) -> Option<LiveSidec
ctx: e.ctx,
cpu_fallback: e.cpu_fallback,
gpu_layers: gpu_layers_reported(&e.args),
+ sanity_note: e.sanity_note,
})
}
@@ -3150,6 +3174,7 @@ fn start_bundled_embed_blocking(
// whatever is there, so there is also no GPU start for it to lose.
auto_layers: false,
cpu_fallback: false,
+ sanity_note: None,
});
if let Err(e) = wait_for_health(port, health_timeout_for(&model_path)) {
@@ -4527,6 +4552,7 @@ mod tests {
args: Vec::new(),
auto_layers: false,
cpu_fallback: false,
+ sanity_note: None,
});
}
@@ -4758,6 +4784,7 @@ mod tests {
args: Vec::new(),
auto_layers: false,
cpu_fallback: false,
+ sanity_note: None,
})
}
@@ -4797,6 +4824,32 @@ mod tests {
let _ = engine.child.wait();
}
+ #[test]
+ #[cfg_attr(target_os = "windows", ignore = "uses sh")]
+ fn a_status_read_carries_what_the_sanity_probe_worked_around() {
+ // Bug a: the ladder answered its sentence ONCE, in the return value of
+ // the start call, and nobody reads that object past `.port`. The
+ // status is what every surface polls, so the sentence lives there.
+ let child = std::process::Command::new("sh")
+ .args(["-c", "sleep 30"])
+ .stdin(Stdio::null())
+ .stdout(Stdio::null())
+ .stderr(Stdio::null())
+ .spawn()
+ .expect("spawn a long lived child");
+ let mut slot = engine_around(child, DEFAULT_ENGINE_PORT);
+ slot.as_mut().unwrap().sanity_note = Some(engine_sanity::HEALED_WITHOUT_FLASH_ATTENTION_NOTE);
+
+ let seen = live_sidecar(&mut slot).expect("the engine is running");
+ assert_eq!(seen.sanity_note, Some(engine_sanity::HEALED_WITHOUT_FLASH_ATTENTION_NOTE));
+ // The flash attention rung keeps the card, so it is NOT a CPU fallback.
+ assert!(!seen.cpu_fallback);
+
+ let mut engine = slot.take().unwrap();
+ let _ = engine.child.kill();
+ let _ = engine.child.wait();
+ }
+
#[test]
#[cfg_attr(target_os = "windows", ignore = "uses sh")]
fn a_typed_cpu_setting_is_not_reported_as_a_failed_start() {
diff --git a/src-tauri/src/state.rs b/src-tauri/src/state.rs
index b58f9985..a5af9377 100644
--- a/src-tauri/src/state.rs
+++ b/src-tauri/src/state.rs
@@ -66,6 +66,15 @@ pub struct BundledEngine {
/// itself, which is the one the user never chose and until now could only
/// find in the log file.
pub cpu_fallback: bool,
+ /// What the start-time sanity probe (bug a, `engine_sanity.rs`) had to
+ /// work around for THIS process, as the one English sentence the user is
+ /// shown: restarted without Flash Attention, restarted on the processor,
+ /// or unreadable on the processor too. `None` on every ordinary start.
+ ///
+ /// Kept here for the same reason as `cpu_fallback`: the start call
+ /// answers it once, and a user who reads the window a minute later must
+ /// still be able to learn why the engine is not on the card.
+ pub sanity_note: Option<&'static str>,
}
#[derive(serde::Serialize, serde::Deserialize, Clone, Debug)]
diff --git a/src/api/engine.ts b/src/api/engine.ts
index be35a14c..404b255f 100644
--- a/src/api/engine.ts
+++ b/src/api/engine.ts
@@ -89,6 +89,10 @@ export interface EngineStatus {
/** The `-ngl` the running process carries, null when it asked for every
* layer. See lib/engine-offload. */
gpuLayers?: number | null
+ /** Bug a: what the start-time sanity probe worked around for this process,
+ * as the sentence the user is shown (engine_sanity.rs). Null on every
+ * ordinary start. Outlives the start call on purpose, see lib/engine-offload. */
+ sanityNote?: string | null
}
/** Loopback base URL of the managed embeddings server (P5). Mirrors the Rust
diff --git a/src/components/settings/__tests__/engine-offload-is-visible.test.ts b/src/components/settings/__tests__/engine-offload-is-visible.test.ts
index e3a4500f..73922155 100644
--- a/src/components/settings/__tests__/engine-offload-is-visible.test.ts
+++ b/src/components/settings/__tests__/engine-offload-is-visible.test.ts
@@ -53,6 +53,20 @@ const AUF_DER_KARTE = {
/** The same engine after the GPU attempt died and the retry took the card out. */
const AUF_DEM_PROZESSOR = { ...AUF_DER_KARTE, cpuOnly: true, gpuLayers: 0 }
+/** Bug a: the card came up, answered the sanity probe in question marks, and
+ * the ladder moved the engine to the processor. Sentence as Rust writes it. */
+const SALAT_AUF_DEM_PROZESSOR = {
+ ...AUF_DEM_PROZESSOR,
+ sanityNote: 'The GPU produced unreadable output, the engine was restarted on the CPU. Please send the log file from Settings > Troubleshoot.',
+}
+
+/** Bug a, first rung: the same card kept its layers and lost Flash Attention. */
+const OHNE_FLASH_ATTENTION = {
+ ...AUF_DER_KARTE,
+ gpuLayers: 18,
+ sanityNote: 'The GPU produced unreadable output, the engine was restarted with Flash Attention switched off and reads correctly now. Please send the log file from Settings > Troubleshoot.',
+}
+
beforeEach(() => {
backendCall.mockReset()
backendCall.mockResolvedValue({})
@@ -105,6 +119,16 @@ describe('the line itself', () => {
it('does not call a typed zero a failed start', () => {
expect(engineOffloadLine({ running: true, cpuOnly: false, gpuLayers: 0 })).toBe('GPU layers: 0')
})
+
+ // Bug a: a card that came up and then wrote question marks did not fail to
+ // start. Saying so would send the user looking for the wrong error.
+ it('tells a garbled card apart from a dead start', () => {
+ expect(engineOffloadLine(SALAT_AUF_DEM_PROZESSOR)).toBe('GPU layers: 0, the GPU answered unreadably')
+ })
+
+ it('keeps the layer count of an engine that only lost Flash Attention', () => {
+ expect(engineOffloadLine(OHNE_FLASH_ATTENTION)).toBe('GPU layers: 18')
+ })
})
describe('Built-in Engine (expert) shows the layer count', () => {
@@ -134,6 +158,30 @@ describe('the standing line above the composer', () => {
expect(await standingLine(AUF_DER_KARTE)).toBeNull()
})
+ // Bug a. The sentence Rust wrote names the cause (unreadable output) and the
+ // repair (CPU, or Flash Attention off); the generic fallback line would
+ // claim a start that failed, which is not what happened.
+ it('carries the sanity probe sentence instead of the generic fallback line', async () => {
+ const line = await standingLine(SALAT_AUF_DEM_PROZESSOR)
+ expect(line?.textContent).toContain(SALAT_AUF_DEM_PROZESSOR.sanityNote)
+ expect(line?.textContent).not.toContain(ENGINE_CPU_ONLY_NOTE)
+ expect(line?.getAttribute('data-tone')).toBe('info')
+ })
+
+ it('speaks for the flash attention rung, which keeps the card', async () => {
+ const line = await standingLine(OHNE_FLASH_ATTENTION)
+ expect(line?.textContent).toContain(OHNE_FLASH_ATTENTION.sanityNote)
+ })
+
+ it('speaks again when the same engine moves from one rung to the next', async () => {
+ await standingLine(OHNE_FLASH_ATTENTION)
+ useLuEngineSwitchStore.getState().dismiss()
+ backendCall.mockImplementation(async (cmd: string) =>
+ cmd === 'bundled_engine_status' ? SALAT_AUF_DEM_PROZESSOR : {})
+ await act(async () => { await bundledEngineStatus() })
+ expect(useLuEngineSwitchStore.getState().note).toBe(SALAT_AUF_DEM_PROZESSOR.sanityNote)
+ })
+
it('says it once per engine, not once per poll', async () => {
await standingLine(AUF_DEM_PROZESSOR)
useLuEngineSwitchStore.getState().dismiss()
diff --git a/src/lib/engine-offload.ts b/src/lib/engine-offload.ts
index 8e075af0..21477c77 100644
--- a/src/lib/engine-offload.ts
+++ b/src/lib/engine-offload.ts
@@ -44,6 +44,12 @@ export interface EngineOffloadStatus {
* them. Rust withholds the 999 sentinel rather than making every surface
* know what it means (`gpu_layers_reported`). */
gpuLayers?: number | null
+ /** Bug a: the sentence the start-time sanity probe left on this process
+ * (restarted without Flash Attention, restarted on the processor, or
+ * unreadable on the processor too). Written in Rust, shown as it is. The
+ * flash attention rung keeps the card, so this can be set with `cpuOnly`
+ * false and a real layer count. */
+ sanityNote?: string | null
}
/** The sentence the standing line carries after a fallback. */
@@ -61,8 +67,12 @@ export const ENGINE_CPU_ONLY_NOTE =
export function engineOffloadLine(status: EngineOffloadStatus | null | undefined): string | null {
if (!status?.running) return null
// A zero the app chose is not the same sentence as a zero the user typed, so
- // the fallback is named before the number is.
- if (status.cpuOnly) return 'GPU layers: 0, the GPU start failed'
+ // the fallback is named before the number is. Two ways the app chooses it:
+ // the first start died with layers on the card, or the card came up and
+ // answered the sanity probe in question marks (bug a).
+ if (status.cpuOnly) {
+ return status.sanityNote ? 'GPU layers: 0, the GPU answered unreadably' : 'GPU layers: 0, the GPU start failed'
+ }
const layers = status.gpuLayers
if (typeof layers !== 'number' || !Number.isInteger(layers) || layers < 0) return null
return `GPU layers: ${layers}`
@@ -76,8 +86,19 @@ export function engineOffloadLine(status: EngineOffloadStatus | null | undefined
* polled every three seconds is not.
*/
export function engineCpuFallbackKey(status: EngineOffloadStatus | null | undefined): string | null {
- if (!status?.running || !status.cpuOnly) return null
- return `${status.port ?? '?'}|${status.model_path ?? '?'}`
+ if (!status?.running) return null
+ if (!status.cpuOnly && !status.sanityNote) return null
+ // The sentence is part of the key: an engine that was first healed without
+ // Flash Attention and then, on the next pass, moved to the processor has
+ // something new to say about the same port and model.
+ return `${status.port ?? '?'}|${status.model_path ?? '?'}|${status.sanityNote ?? ''}`
+}
+
+/** The sentence the standing line carries for this status. */
+export function engineStandingNote(status: EngineOffloadStatus): string {
+ // Rust wrote the sanity sentence with the cause in it, so it wins over the
+ // generic fallback line whenever it is there.
+ return status.sanityNote || ENGINE_CPU_ONLY_NOTE
}
/**
@@ -126,7 +147,7 @@ export function announceEngineCpuFallback(status: EngineOffloadStatus | null | u
angesagt = key
const ende = Date.now() + ENGINE_NOTE_UNSEEN_HOLD_MS
useLuEngineSwitchStore.getState().announce(
- ENGINE_CPU_ONLY_NOTE,
+ engineStandingNote(status as EngineOffloadStatus),
'info',
() => Date.now() < ende && !VIEWS_WITH_THE_ENGINE_NOTE.has(useUIStore.getState().currentView),
)