diff --git a/apps/host/server/native-control.mjs b/apps/host/server/native-control.mjs index ea528954..e24d895d 100644 --- a/apps/host/server/native-control.mjs +++ b/apps/host/server/native-control.mjs @@ -223,24 +223,33 @@ return {summary:result.summary??'Deleted',removed:result.plan?.gb??null};} const DS_EXPERTS_MIN=[0,1,50]; function dsEngineVersion(config){const m=/engine-dsv41[\\/](\d+(?:\.\d+)+)-/.exec(String(config?.exe??''))||/engine-dsv41[\\/](\d+(?:\.\d+)+)-/.exec(String((config?.lib_dirs??[])[0]??''));return m?m[1].split('.').map(Number):null;} function dsExpertsSupported(config){const v=dsEngineVersion(config);if(!v)return false;for(let i=0;ib;}return true;} - /* Control's ceiling for one start wait, read from the Control this app actually found rather than guessed from its version: the owner - runtime takes MAX_START_WAIT (#3949), but `strata runtime start --wait` - the command the app starts a model with - validates the - wait itself, and that validator was left at 600 s by the same change (the app says `start wait must be finite seconds in 0..600`). - A wait above what that file accepts is refused before anything loads, so the app asks for the ceiling of the Control it has and - keeps today's 600 s whenever it cannot read one. Reading the installed Control to learn what it supports is what the field list - and the /v1/responses capability already do; here it reads Control's own validator instead of the server. */ + /* Control's ceiling for one start wait, read from the Control this app actually found rather than guessed from its version. The + app starts a model with `strata runtime start --wait`, and that wait is checked three times before the engine is reached: by + management.runtime_action, by the operation record written before the start (journal), and by runtime.start itself. 27cbbfe6 + raised only the runtime's, so a longer wait died with `start wait must be finite seconds in 0..600` and then with + `direct runtime intent has an invalid timeout`. The app therefore asks for the longer wait only when a Control's own sources + say all three agree, and keeps today's 600 s whenever one of them still names a ceiling of its own. Reading the installed + Control to learn what it supports is what the field list and the /v1/responses capability already do. */ const START_WAIT_CEILING=600; let ceilingCache={dir:'',time:0,value:START_WAIT_CEILING}; + function followsRuntimeCeiling(text,marker){ + /* The marker picks the one line that bounds the wait (`"wait_s": (` in the record's range table, `"start wait"` in the CLI + validator), because both files name those keys elsewhere. A line that still spells out 600 is a ceiling of its own. */ + const line=(String(text).split(/\r?\n/).find(l=>l.includes(marker))??''); + return /runtime\.MAX_START_WAIT|start_wait_max/.test(line)&&!/\b600\b/.test(line); + } function startWaitCeiling(){ const dir=control?.control?.dir??'';if(!dir)return START_WAIT_CEILING; - let time=0;const file=join(dir,'strata_control','management.py'); - try{time=statSync(file).mtimeMs;}catch{return START_WAIT_CEILING;} + const files=['management.py','journal.py','runtime.py'].map(name=>join(dir,'strata_control',name)); + let time=0; + try{time=Math.max(...files.map(f=>statSync(f).mtimeMs));}catch{return START_WAIT_CEILING;} if(ceilingCache.dir===dir&&ceilingCache.time===time)return ceilingCache.value; let value=START_WAIT_CEILING; try{ - const line=(readFileSync(file,'utf8').split(/\r?\n/).find(l=>l.includes('"start wait"'))??''); - if(/runtime\.MAX_START_WAIT/.test(line)){ // a Control whose CLI takes the runtime's own ceiling, whatever it is - const declared=Number(readFileSync(join(dir,'strata_control','runtime.py'),'utf8').match(/^MAX_START_WAIT\s*=\s*(\d+)/m)?.[1]); + const [management,journal]=files.slice(0,2).map(f=>readFileSync(f,'utf8')); + // both gates must hand the ceiling to the runtime, or the wait would be refused on the way to it + if(followsRuntimeCeiling(management,'"start wait"')&&followsRuntimeCeiling(journal,'"wait_s": (')){ + const declared=Number(readFileSync(files[2],'utf8').match(/^MAX_START_WAIT\s*=\s*(\d+)/m)?.[1]); if(Number.isFinite(declared)&&declared>value)value=declared; } }catch{value=START_WAIT_CEILING;} diff --git a/apps/host/tests/packaged-control.test.mjs b/apps/host/tests/packaged-control.test.mjs index 4b04d535..0203b7b6 100644 --- a/apps/host/tests/packaged-control.test.mjs +++ b/apps/host/tests/packaged-control.test.mjs @@ -92,16 +92,22 @@ function packagedFixture({ engineUsable = true, updater = null, repair = false, const root = mkdtempSync(join(tmpdir(), 'strata-packaged-test-')); const install = join(root, 'install'), data = join(root, 'data'); mkdirSync(install, { recursive: true }); - /* The Control this app found, as it is on disk: the app reads the start-wait ceiling out of these two files instead of - trusting the version, because the released Control validates the wait twice and the two numbers can disagree. - 'old': no runtime ceiling at all, CLI takes 600. 'split': the runtime takes 1800 but the CLI still stops at 600 - (what every Control up to 0.1.52 ships). 'runtime': the CLI follows the runtime's own ceiling. */ + /* The Control this app found, as it is on disk. The app reads the start-wait ceiling out of these files instead of trusting + the version, because a start wait is checked three times before the engine is reached and a released Control has those + three ceilings disagreeing: + 'old' no runtime ceiling at all, both gates 600 (Control before #3949) + 'split' the runtime takes 1800, the CLI and the record still stop at 600 (every Control 0.1.50 to 0.1.52) + 'cli-only' the CLI follows the runtime, the record still stops at 600 (`direct runtime intent has an invalid timeout`) + 'runtime' all three hand the wait to the runtime's own ceiling */ const controlSource = join(root, 'control', 'strata_control'); mkdirSync(controlSource, { recursive: true }); writeFileSync(join(controlSource, 'runtime.py'), cliStartWait === 'old' ? '' : 'MAX_START_WAIT = 1800\n'); - writeFileSync(join(controlSource, 'management.py'), cliStartWait === 'runtime' + writeFileSync(join(controlSource, 'management.py'), ['cli-only', 'runtime'].includes(cliStartWait) ? ' wait = _seconds(wait, 0, runtime.MAX_START_WAIT, "start wait")\n' : ' wait = _seconds(wait, 0, 600, "start wait")\n'); + writeFileSync(join(controlSource, 'journal.py'), cliStartWait === 'runtime' + ? ' ranges = {"wait_s": (0, start_wait_max) if kind == "runtime.start" else\n' + : ' ranges = {"wait_s": (0, 600) if kind == "runtime.start" else\n'); const earlierInstallEnv = process.env.STRATA_INSTALL_DIR; process.env.STRATA_INSTALL_DIR = install; // the app's own install folder (the host always tells Control which one; it never falls back to an older CLI folder) const configs = ids.map(id => { @@ -632,8 +638,9 @@ test('packaged: a big model is waited for by its size, inside the ceiling of the return { wait: start[2], ready: saved.engine_ready_s }; } finally { f.cleanup(); } }; - assert.equal((await run('old', 180)).wait, 600, 'a Control whose CLI takes 600 s at most is asked for 600 s, as today'); + assert.equal((await run('old', 180)).wait, 600, 'a Control with no long-wait ceiling at all is asked for 600 s, as today'); assert.equal((await run('split', 180)).wait, 600, 'a Control whose runtime takes 1800 s but whose CLI still stops at 600 is asked for 600 s: the CLI would refuse the start outright (#3949)'); + assert.equal((await run('cli-only', 180)).wait, 600, 'a Control whose CLI takes it but whose operation record still stops at 600 is asked for 600 s too: the record is written before the start runs'); const long = await run('runtime', 180); assert.equal(long.wait, 1720, '600 s + 8 s per GB above 40 GB, as in strata launch, once the CLI really takes it'); assert.equal(long.ready, 1780, 'the server readies after the start gave up, never before it');