Files
Niko1221 aaabb73259 Launch of a Qwen model on an Inkling-only PC installs the Strata engine (rc1 fix #8)
On a PC whose only engine is a model shape's (Inkling), `strata update` leaves the Strata engine out
(qwen_engine_wanted, 3fe4a1c7a7: the Monitor's `u` must not install an engine nobody has). A Qwen launch
runs `strata update --no-control` to get it, so it got nothing, update exited 0 and the launch said there
was no engine for the graphics card although the feed has the package.

- updater: qwen_engine_wanted / decide_engine / check / run_update take want_engine; strata update and
  strata components update take --want-engine. A plain update and a plain --check still skip the engine
  (status not-used).
- launch runner: ensure_engine passes --want-engine; no_engine's words say what really happened (the engine
  step failed and why, the update left the engine out, or it was installed but is unusable) and keep the
  graphics-card sentence for a feed that truly has no package.
- app host: the model install job's engine step (Qwen models only) asks for the engine in the update check and
  the update (control-runtime updateCheck/update wantEngine). Starting a model never downloads an engine; the
  setup.py feed-engine path uses a fresh components store and was not affected.
- tests: Inkling-only Qwen launch gets the engine; plain update/check still skip it; the CLI flag; the launch
  argv; the three message cases; the app engine-step request.
2026-12-03 16:31:48 +01:00

115 lines
8.0 KiB
JavaScript

/**
* The engine comes with the model.
*
* A model install job (packaged app) also makes sure this PC has a usable engine: if none is installed, or the signed feed offers
* a newer compatible one, the job runs Control's component updater for the engine (same feed, signature and hash checks, staged
* test start) next to the model files. It reports through the job's own progress fields, so the UI shows one combined total.
*
* It never throws: a failed engine download leaves the model files alone and becomes `engine.state === 'failed'` with a retry
* message. Loading, starting and serving never download (STRATA_NO_ACQUIRE stays on for them); this runs only inside the install
* job the user started. Contract: see phaseA-tests/notes-split-s6.md ("Job contract").
*/
import { plainUpdateError, PHASE_TEXT } from './update-messages.mjs';
const GB = 1e9;
const round = (value, digits = 2) => Math.round(value * 10 ** digits) / 10 ** digits;
export const RETRY = 'Update engine';
export function createEngineStep({ control, signal = null, onChange = () => {} } = {}) {
const part = { kind: 'engine', name: 'Engine', version: null, state: 'pending', percent: 0, done_gb: 0, total_gb: 0, message: 'Waiting for the model download to start.' };
let note = null;
const set = patch => { Object.assign(part, patch); onChange({ ...part }); };
async function run() {
if (!control || typeof control.update !== 'function') { set({ state: 'skipped', message: 'This build has no component updater.' }); return { ...part }; }
try {
set({ state: 'checking', message: 'Checking the engine for this PC…' });
let usable = false;
try { usable = !!(await control.engine()).usable; } catch { /* treated as not usable */ }
let report = null;
try {
report = await control.updateCheck({ wantEngine: true }); // this step runs for a Qwen model: the Strata engine is wanted even on an Inkling-only PC (rc1 fix #8)
} catch (error) {
if (usable) { set({ state: 'skipped', message: 'The engine for this PC is installed.' }); return { ...part }; }
throw error;
}
const engine = report.engine ?? {};
/* #6830: an engine the person chose or went back to (`strata components rollback`, Settings > Engine, `components use`) is pinned. A model's install or a change
of its settings never switches it: the job used to run the updater for the newer engine still on disk, which dropped the pin and the skipped list and put the
broken release back. The newer one stays offered in Settings > Engine and by `strata update`. */
if (engine.status === 'available' && (engine.person_chose === true || (usable && engine.pinned))) { // person_chose: Control's own word for it (5907fe7ff); pinned alone covers a pin whose newer engine is not on disk
const here = engine.installed?.version ?? null, offered = engine.offered?.version ?? null;
set({ state: 'current', version: here, percent: 100, message: `The engine you chose${here ? ` (${here})` : ''} stays in use.${offered ? ` A newer one (${offered}) is offered: Settings > Engine switches to it.` : ''}` });
return { ...part };
}
const wanted = engine.status === 'install' || engine.status === 'available';
if (!wanted) {
if (!usable && engine.status !== 'current') throw new Error(engine.reasons?.[0] ?? 'The update feed has no engine for this PC.');
set({ state: 'current', version: engine.installed?.version ?? null, message: 'The engine for this PC is ready.', percent: 100 });
return { ...part };
}
const version = engine.offered?.version ?? null;
// An engine already works here: say what is about to change and that it can be undone (#4823), not only "downloading".
const before = engine.installed?.version ?? null;
const change = before && version && before !== version ? `Updating the engine from ${before} to ${version}. The engine you have now is kept, and Settings can go back to it.` : null;
set({ state: 'downloading', version, name: `Engine ${version ?? ''}`.trim(), total_gb: round((engine.download_bytes ?? 0) / GB), message: change ?? 'Downloading the engine for this PC…' });
const result = await control.update({
engine: true, control: false, wantEngine: true, signal,
onEvent: event => {
if (event.event === 'progress') {
set({ state: 'downloading', percent: event.percent ?? 0, done_gb: round((event.done ?? 0) / GB), total_gb: round((event.total ?? 0) / GB), message: `${change ? `Updating the engine from ${before} to ${version}` : 'Downloading the engine for this PC'}: ${event.percent ?? 0}%` });
} else if (event.event === 'phase') {
const state = { verify: 'verifying', test: 'testing', switch: 'switching' }[event.phase];
if (state) set({ state, message: PHASE_TEXT[event.phase] ?? part.message });
} else if (event.event === 'waiting') {
set({ message: 'Waiting for the model to stop before finishing the engine…' });
}
},
});
const done = (result.results ?? []).find(r => r.component === 'engine');
set({ state: 'done', percent: 100, done_gb: part.total_gb, version: done?.installed_after?.version ?? version, message: change ? `The engine was updated from ${before} to ${version}. Settings can go back to the one you had.` : 'The engine for this PC is ready.' });
} catch (error) {
const plain = plainUpdateError(error, 'engine');
note = `Your model is ready. The engine for this PC couldn't be downloaded. ${plain.next}`;
set({ state: 'failed', error: plain.headline, details: plain.details, retry: RETRY, message: note });
}
return { ...part };
}
/** The install progress with the engine part added and one combined download total. Pure: returns a new object. */
function merge(install) {
if (!install || typeof install !== 'object') return install;
const model = install.download ?? null;
const modelDone = Number.isFinite(model?.done_gb) ? model.done_gb : null;
const modelRemaining = Number.isFinite(model?.remaining_gb) ? model.remaining_gb : null;
const active = !['done', 'current', 'skipped', 'failed'].includes(part.state);
const engineRemaining = active || part.state === 'done' ? Math.max(0, part.total_gb - part.done_gb) : 0;
/* The install knows its files (strata_mcp files_progress): the model's parts and the picture reader, each counted. Without that, one
model part from the combined figures. The engine is added either way. */
const own = Array.isArray(install.parts) && install.parts.some(p => p?.kind === 'model') ? install.parts.filter(p => p?.kind !== 'engine') : null;
const parts = [
...(own ?? [{ kind: 'model', name: model?.file ?? install.model ?? 'Model', state: install.running === false ? 'done' : 'downloading', done_gb: modelDone ?? 0, total_gb: round((modelDone ?? 0) + (modelRemaining ?? 0)) }]),
{ ...part },
];
const merged = { ...install, engine: { ...part }, parts };
// setup checking files that are all on disk: its figure is the check's, the engine's bytes are not part of it (DL99)
if (model && model.file !== 'checking files') {
const done =round((modelDone ?? 0) + (part.state === 'pending' || part.state === 'checking' ? 0 : part.done_gb));
const remaining = round((modelRemaining ?? 0) + (part.state === 'pending' || part.state === 'checking' ? 0 : engineRemaining));
const total = done + remaining;
merged.download = { ...model, done_gb: done, remaining_gb: remaining, percent: total > 0 ? Math.min(100, Math.round(100 * done / total)) : model.percent,
file: active && part.state === 'downloading' && (modelRemaining ?? 0) <= 0 ? part.name : model.file };
}
return merged;
}
/** What to tell the user when the model is ready but the engine is not. Null when all is well. */
function summaryNote() {
return part.state === 'failed' ? note : null;
}
return { run, merge, summaryNote, part: () => ({ ...part }) };
}