From 44fcfeea48239ba782094ae513d9ade02b1f01df Mon Sep 17 00:00:00 2001 From: Niko1221 Date: Thu, 3 Dec 2026 16:38:08 +0100 Subject: [PATCH] App host: a Control that does not know --want-engine is called again without it (rc1 fix #8, skew) The host runs the newest of the bundled, the app's and the updated Control, so an app that carries this fix runs a Control that has --want-engine. Should an older one ever be run (a pre-fix Control from a feed), argparse exits 2 with "unrecognized arguments: --want-engine"; the update check and the update then repeat the call once without the flag. Such a Control has no "not-used" rule and installs the engine anyway. The launch runner always runs its own tree's strata.py, so it has no skew. Test: an old Control is retried once for the check and the update, a current one is called once, a plain update never carries the flag. --- app/host/server/control-runtime.mjs | 14 ++++++++++++-- app/host/tests/component-updates.test.mjs | 17 +++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/app/host/server/control-runtime.mjs b/app/host/server/control-runtime.mjs index 02e98633a9..7e83537322 100644 --- a/app/host/server/control-runtime.mjs +++ b/app/host/server/control-runtime.mjs @@ -243,6 +243,16 @@ export function createControl({ control = findControl(), env = process.env, run throw error; } }; + /* `--want-engine` (rc1 fix #8) exists in this app's Control and in every newer one. The host takes the newest of the bundled, the app's and the updated Control, so an older one + should not be run; but if one without the flag ever is (a Control from the feed that predates it), argparse says "unrecognized arguments" and exits 2. That older Control also + has no "not-used" rule (it installs the Strata engine anyway), so the same call without the flag does what is wanted: retry once without it. */ + const callWantingEngine = async (args, options) => { + const result = await call(args, options); + if (args.includes('--want-engine') && result.code === 2 && /unrecognized arguments?:?[^\n]*--want-engine/i.test(`${result.stderr ?? ''}\n${result.text ?? ''}`)) { + return call(args.filter(a => a !== '--want-engine'), options); + } + return result; + }; const feedArgs = feed => (feed ? ['--feed', feed] : []); return { control, @@ -291,7 +301,7 @@ export function createControl({ control = findControl(), env = process.env, run /* A check is short, so a lock held by someone else (a Terminal's `strata update`, the end of another check) is waited for, up to lockWaitMs, before it is an answer. */ for (let tries = 0; ; tries++) { try { - const result = await call(args, { timeoutMs: 90_000, acquire: true }); + const result = await callWantingEngine(args, { timeoutMs: 90_000, acquire: true }); if (result.json?.ok) return result.json; throw failure(result, 'The update check failed.'); } catch (error) { @@ -307,7 +317,7 @@ export function createControl({ control = findControl(), env = process.env, run async update({ feed = env.STRATA_UPDATE_FEED ?? null, engine = true, control: withControl = true, appVersion = env.STRATA_APP_VERSION ?? null, force = false, stopModel = false, wantEngine = false, onEvent = null, signal = null } = {}) { const args = ['update', '--output', 'jsonl', ...feedArgs(feed), ...(engine ? (wantEngine ? ['--want-engine'] : []) : ['--no-engine']), ...(withControl ? [] : ['--no-control']), ...(appVersion ? ['--app-version', appVersion] : []), ...(force ? ['--force'] : []), ...(stopModel ? ['--stop-model'] : [])]; - const result = await call(args, { timeoutMs: 3 * 3600_000, acquire: true, onLine: onEvent ?? (() => {}), signal }); + const result = await callWantingEngine(args, { timeoutMs: 3 * 3600_000, acquire: true, onLine: onEvent ?? (() => {}), signal }); if (result.json?.ok) return result.json; const failed = result.json?.results?.find?.(r => r.status === 'failed'); if (failed) throw Object.assign(new ControlError(failed.error, { exitCode: failed.exit_code ?? result.code, output: result.json }), { code: result.code === 7 && !UPDATE_LOCK_HELD.test(failed.error ?? '') ? 'engine_serving' : result.code === 7 ? 'update_busy' : 'update_failed' }); diff --git a/app/host/tests/component-updates.test.mjs b/app/host/tests/component-updates.test.mjs index 5f1d93a397..92bee6f27a 100644 --- a/app/host/tests/component-updates.test.mjs +++ b/app/host/tests/component-updates.test.mjs @@ -465,3 +465,20 @@ test('the app updater and the host never reach the network by themselves: only c await updater.check(); assert.equal(calls.length, 1); }); + +test('rc1 fix #8: --want-engine goes to Control; an older Control that rejects it (argparse exit 2) is called again without it, once, for the check and for the update', async () => { + const control = { dir: '/c', python: '/c/python/python3', cli: '/c/strata.py' }; + const seen = []; + const refuse = args => ({ code: 2, json: null, text: '', stderr: 'strata.py update: error: unrecognized arguments: --want-engine' }); + const old = createControl({ control, run: async args => { seen.push(args.slice()); return args.includes('--want-engine') ? refuse(args) : { code: 0, json: { ok: true, engine: { status: 'install' }, results: [{ component: 'engine', status: 'updated' }] }, text: '', stderr: '' }; } }); + const checked = await old.updateCheck({ feed: null, appVersion: null, wantEngine: true }); + assert.equal(checked.ok, true); + const done = await old.update({ feed: null, engine: true, control: false, wantEngine: true }); + assert.equal(done.ok, true); + assert.deepEqual(seen.map(a => a.includes('--want-engine')), [true, false, true, false], 'each call tried with the flag, then once without'); + const fresh = []; + const current = createControl({ control, run: async args => { fresh.push(args.slice()); return { code: 0, json: { ok: true, results: [] }, text: '', stderr: '' }; } }); + await current.update({ feed: null, engine: true, control: false, wantEngine: true }); + await current.update({ feed: null, engine: true, control: false }); + assert.deepEqual(fresh.map(a => a.includes('--want-engine')), [true, false], 'a Control that knows the flag is called once, and a plain update never carries it'); +});