app Load: a Drafting choice made on the Models screen is kept for the next start (0.2.15 release test)

0.2.15 release test T6-app (p1004, the C2 app, IQ3_XXS): Drafting set to Off on the Models screen; Load 1 started with no drafter; after
an unload and an app restart the page showed "Auto (recommended)" and Load 2 started with --draft dflash2. The run config had no
"drafting" key after Load 1.

loadEngine saves the choice in the run config (prepareDrafter -> rememberSetting, "drafting": "off" / "mtp" / "dflash2", Auto = no key),
but at ready it wrote the run config again from the copy it had read at the start of the Load (resources, picture and context choices),
which put the file back as it was before the choice was saved. The write at ready now starts from the file as it is on disk then
(savedNow), so the saved choice stays; a file that cannot be read falls back to the old copy. The same code is in 0.2.14 (since
b7196c23d, 10-22). No new text.

Test: apps/host/tests/drafting-kept.test.mjs (2 new).
This commit is contained in:
Niko1221 committed 2026-11-16 05:57:41 +01:00
1 parent 2a3e33b8e4
commit 15c14f6c4e
2 files changed
+31 -1

No files matched your search

+3 -1
View File
@@ -570,7 +570,7 @@ return {summary:result.summary??'Deleted',removed:result.plan?.gb??null};}
const deadline=Date.now()+(adopted?Math.max(300,startWait??300)*1000:300000);let lastAsked=0;while(Date.now()<deadline&&job.state==='running'){
if(instance.status==='error')throw new Error(instance.error);
if(adopted&&instance.profile&&Date.now()-lastAsked>10000){lastAsked=Date.now();const st=await control.status(instance.profile).catch(()=>null);if(st&&['failed','stopped','stale'].includes(st.state)){instance.status='error';instance.error=humanStartError({message:st.error||'server_exited',output:st});emit();throw new Error(instance.error);}}
try{const response=await fetcher(`http://127.0.0.1:${instance.port}/health`,{headers:{authorization:`Bearer ${key}`},signal:AbortSignal.timeout(2000)});if(job.state!=='running'){await unload(id);return;}if(response.ok){instance.status='ready';instance.phase='idle';await noteDrafting(job,instance,key);if(resources||args.vision!==undefined||args.contextChosen===true||JSON.stringify(cfg[USER_KEY]??null)!==JSON.stringify(config[USER_KEY]??null))writeModelConfig(record(args.model).path,{...config,...(resources?{...resources,ui_resource_profile:args.resourceProfile}:{}),...visionPreferences,...(args.contextChosen===true?{ui_context_chosen:true}:{}),...(cfg[USER_KEY]?{[USER_KEY]:cfg[USER_KEY]}:{})});emit();ensurePoll();instance.parallelNote=parallelNote;return {summary:retried?`${instance.label} is ready, after a second try: ${retried.words}`:`${instance.label} is ready.${parallelNote?' '+parallelNote:''}${picturesNote?' '+picturesNote:''}`,instanceId:id};}}catch{}
try{const response=await fetcher(`http://127.0.0.1:${instance.port}/health`,{headers:{authorization:`Bearer ${key}`},signal:AbortSignal.timeout(2000)});if(job.state!=='running'){await unload(id);return;}if(response.ok){instance.status='ready';instance.phase='idle';await noteDrafting(job,instance,key);if(resources||args.vision!==undefined||args.contextChosen===true||JSON.stringify(cfg[USER_KEY]??null)!==JSON.stringify(config[USER_KEY]??null))writeModelConfig(record(args.model).path,{...savedNow(record(args.model).path,config),...(resources?{...resources,ui_resource_profile:args.resourceProfile}:{}),...visionPreferences,...(args.contextChosen===true?{ui_context_chosen:true}:{}),...(cfg[USER_KEY]?{[USER_KEY]:cfg[USER_KEY]}:{})});emit();ensurePoll();instance.parallelNote=parallelNote;return {summary:retried?`${instance.label} is ready, after a second try: ${retried.words}`:`${instance.label} is ready.${parallelNote?' '+parallelNote:''}${picturesNote?' '+picturesNote:''}`,instanceId:id};}}catch{}
await new Promise(resolve=>setTimeout(resolve,1200));
}
if(job.state!=='running'){await unload(id);return;}
@@ -710,6 +710,8 @@ return {summary:result.summary??'Deleted',removed:result.plan?.gb??null};}
function dismissRestart(){stoppedForUpdate=null;emit();return state();}
function updateSummary(done){const r=(done.results??[]).filter(x=>x.status==='updated').map(x=>x.component==='engine'?'The engine is updated and ready.':'Strata is updated. It takes effect the next time you open the app.');return r.length?r.join(' '):'Everything is already up to date.';}
function execute(cmd,args,cwd){return new Promise((resolve,reject)=>{let output='';const process=spawnProcess(cmd,args,{cwd,stdio:['ignore','pipe','pipe']});process.stdout.on('data',c=>{output+=c;if(output.length>100000)process.kill();});process.stderr.on('data',c=>append('update',c.toString()));process.on('error',reject);process.on('exit',code=>code===0?resolve(output):reject(new Error('Git could not update this installation. Open diagnostics.')));});}
/* The run config as it is on disk now (the load wrote its Drafting choice there, prepareDrafter / rememberSetting, after this load read the file): the write at ready starts from it, so a chosen Off, MTP or DFlash2 is kept for the next start (0.2.15 release test T6-app). */
function savedNow(path,fallback){try{return checkedSettingsConfig(readFileSync(path,'utf8'));}catch{return fallback;}}
/* Every write of a model's run config keeps the person's options: those they wrote into "args" or "user_args" since the file was last written are read from the file itself, go over what the caller built, and "args_written" is refreshed. */
function writeModelConfig(path,next){const mine=mergeUserArgs(captureUserArgs(readJson(path)),next[USER_KEY]??[]);next=stampedUserArgs(next,mine);copyFileSync(path,path+'.bak');chmodSync(path+'.bak',0o600);const temp=path+'.ui-tmp';writeFileSync(temp,JSON.stringify(next,null,2)+'\n',{mode:0o600});renameSync(temp,path);}
async function tune(job,args){
+28
View File
@@ -0,0 +1,28 @@
// A Drafting choice made on the Models screen is kept for the next start (0.2.15 release test T6-app, p1004, C2 app): the Load saved
// "drafting": "off" into the model's run config (prepareDrafter / rememberSetting), and the write at ready then put back the copy of the
// run config the Load had read before that, so the key was gone: after an app restart the page showed Auto and the next Load ran DFlash2.
import test from 'node:test';
import assert from 'node:assert/strict';
import { readFileSync } from 'node:fs';
import { fileURLToPath } from 'node:url';
const source = readFileSync(fileURLToPath(new URL('../server/native-control.mjs', import.meta.url)), 'utf8').replace(/\r\n/g, '\n');
test('the Load saves the Drafting choice before the engine starts', () => {
const load = source.slice(source.indexOf('async function loadEngine'), source.indexOf('const fingerprint=createHash'));
assert.match(load, /await prepareDrafter\(job,args,cfg,configFile,drafts,\{noSplit\}\)/);
const prepare = source.slice(source.indexOf('async function prepareDrafter'), source.indexOf('function rememberSetting'));
assert.match(prepare, /rememberSetting\(configFile,'drafting',asked===null\|\|asked==='auto'\?null:asked\)/);
});
test('the run-config write at ready starts from the file as it is now, so the saved choice is kept', () => {
const at = source.indexOf("instance.status='ready';instance.phase='idle';await noteDrafting(job,instance,key);");
assert.ok(at > 0, 'the ready branch of loadEngine');
const ready = source.slice(at, source.indexOf('emit();ensurePoll();', at));
assert.match(ready, /writeModelConfig\(record\(args\.model\)\.path,\{\.\.\.savedNow\(record\(args\.model\)\.path,config\),/,
'the write at ready reads the run config again (it holds the Drafting choice the Load saved)');
assert.doesNotMatch(ready, /writeModelConfig\(record\(args\.model\)\.path,\{\.\.\.config,/, 'not the copy read before the choice was saved');
const helper = source.slice(source.indexOf('function savedNow('), source.indexOf('function writeModelConfig('));
assert.match(helper, /checkedSettingsConfig\(readFileSync\(path,'utf8'\)\)/);
assert.match(helper, /catch\{return fallback;\}/);
});