Skip to content

Qwen3.8-Flash-Next on any consumer hardware: one-click install for Windows / Linux. Strata inference engine, OpenAI/Anthropic API on localhost, optional image input.

C++

Host: a model folder in Documents that cannot be made falls back to STRATA_HOME/models with a plain notice instead of crashing at start

Niko122152cc6b4af09d
diff --git a/apps/host/server/index.mjs b/apps/host/server/index.mjs
index fc3b1e861..56c7b3c23 100644
--- a/apps/host/server/index.mjs
+++ b/apps/host/server/index.mjs
@@ -269,7 +269,7 @@ function setupState() {
flowVersion: 2,
completedAt: s.setup.completedAt,
history: s.setup.history ?? [],
- app: { version: appVersion(), modelsDir: store.MODELS_DIR, dataDir: store.DATA_DIR },
+ app: { version: appVersion(), modelsDir: store.MODELS_DIR, dataDir: store.DATA_DIR, modelsDirNotice: store.MODELS_DIR_NOTICE },
};
}
diff --git a/apps/host/server/store.mjs b/apps/host/server/store.mjs
index 2b9ea02b5..46bee3e5b 100644
--- a/apps/host/server/store.mjs
+++ b/apps/host/server/store.mjs
@@ -58,21 +58,37 @@ function read() {
let state = read();
const DEFAULT_MODELS_DIRECTORY=defaultModelDirectory();
-function initialModelsDirectory() {
- if(state.modelsDir)return state.modelsDir;
- const legacy=realpathSync(join(HOME,'models'));
- // Keep an existing library in place. A new install uses Documents/Strata/Models.
+/**
+ * The model folder for a new install: the saved one, an existing library inside STRATA_HOME, else Documents/Strata/Models. A Documents folder
+ * that cannot be made (Controlled folder access, a disconnected share, an offline OneDrive known folder) must not stop the host from starting:
+ * the models go to STRATA_HOME/models instead, and `notice` says so in plain words.
+ */
+export function pickModelsDirectory({ saved, home, preferred, fixedByEnv = false }) {
+ if (saved) return { directory: saved, notice: '' };
+ const fallback = join(home, 'models');
+ let legacy = fallback;
+ try { legacy = realpathSync(fallback); } catch { /* the folder is made at start; keep the plain path */ }
function hasWeights(folder,depth=0){try{return readdirSync(folder,{withFileTypes:true}).some(entry=>entry.isFile()&&/\.gguf(?:\.part|\.partial)?$/i.test(entry.name)||entry.isDirectory()&&depth<4&&hasWeights(join(folder,entry.name),depth+1));}catch{return false;}}
- if(!process.env.STRATA_MODELS_DIR&&hasWeights(legacy))return legacy;
- const directory=DEFAULT_MODELS_DIRECTORY;
- mkdirSync(directory,{recursive:true});
- return realpathSync(directory);
+ // Keep an existing library in place. A new install uses Documents/Strata/Models.
+ if (!fixedByEnv && hasWeights(legacy)) return { directory: legacy, notice: '' };
+ try {
+ mkdirSync(preferred, { recursive: true });
+ accessSync(preferred, constants.R_OK | constants.W_OK | constants.X_OK);
+ return { directory: realpathSync(preferred), notice: '' };
+ } catch (error) {
+ return { directory: legacy, notice: `Strata could not use ${preferred} for models (${error.code ?? error.message}), so models go to ${legacy}. You can pick another folder in Settings.` };
+ }
}
-export let MODELS_DIR = initialModelsDirectory();
+const MODELS_PICK = pickModelsDirectory({ saved: state.modelsDir, home: HOME, preferred: DEFAULT_MODELS_DIRECTORY, fixedByEnv: !!process.env.STRATA_MODELS_DIR });
+/** Plain words for the person when the usual model folder could not be used (empty otherwise). */
+export const MODELS_DIR_NOTICE = MODELS_PICK.notice;
+if (MODELS_DIR_NOTICE) console.warn(`[strata] ${MODELS_DIR_NOTICE}`);
+export let MODELS_DIR = MODELS_PICK.directory;
/** Native setup writes weights to data_dir/models. Keep its data root one level up. */
export function nativeDataDirectory(input) {
if(!input||process.env.STRATA_MODELS_DIR||!existsSync(DEFAULT_MODELS_DIRECTORY))return input;
+ if(MODELS_DIR_NOTICE)return input;
const root=realpathSync(DEFAULT_MODELS_DIRECTORY);
if(resolve(input)!==resolve(DEFAULT_MODELS_DIRECTORY)&&realpathSync(input)!==root)return input;
const data=dirname(root),nativeModels=join(data,'models');
diff --git a/apps/host/tests/models-directory-fallback.test.mjs b/apps/host/tests/models-directory-fallback.test.mjs
new file mode 100644
index 000000000..78aa33b46
--- /dev/null
+++ b/apps/host/tests/models-directory-fallback.test.mjs
@@ -0,0 +1,33 @@
+import test from 'node:test';
+import assert from 'node:assert/strict';
+import { spawnSync } from 'node:child_process';
+import { mkdirSync, mkdtempSync, realpathSync, rmSync, writeFileSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import { join } from 'node:path';
+import { fileURLToPath } from 'node:url';
+
+const cwd = fileURLToPath(new URL('..', import.meta.url));
+function fixture(t) { const home = realpathSync(mkdtempSync(join(tmpdir(), 'strata-fallback-'))); t.after(() => rmSync(home, { recursive: true, force: true })); return home; }
+function load(env) {
+ const code = "const s = await import('./server/store.mjs'); console.log(JSON.stringify({ dir: s.MODELS_DIR, notice: s.MODELS_DIR_NOTICE }));";
+ const run = spawnSync(process.execPath, ['--input-type=module', '-e', code], { cwd, encoding: 'utf8', env: { ...process.env, ...env } });
+ assert.equal(run.status, 0, run.stderr);
+ return JSON.parse(run.stdout.trim().split('\n').pop());
+}
+
+test('a Documents folder that cannot be made does not stop the host: models go to STRATA_HOME/models with a notice', t => {
+ const home = fixture(t);
+ const blocker = join(home, 'not-a-folder'); writeFileSync(blocker, 'x'); // mkdir below a file fails like a blocked Documents folder
+ const { dir, notice } = load({ STRATA_HOME: join(home, 'h'), STRATA_MODELS_DIR: '', STRATA_DOCUMENTS_DIR: join(blocker, 'Documents') });
+ assert.equal(dir, realpathSync(join(home, 'h', 'models')));
+ assert.match(notice, /could not use .* for models/);
+ assert.match(notice, /Settings/);
+});
+
+test('a usable Documents folder is used and says nothing', t => {
+ const home = fixture(t);
+ const docs = join(home, 'Documents'); mkdirSync(docs);
+ const { dir, notice } = load({ STRATA_HOME: join(home, 'h'), STRATA_MODELS_DIR: '', STRATA_DOCUMENTS_DIR: docs });
+ assert.equal(dir, realpathSync(join(docs, 'Strata', 'Models')));
+ assert.equal(notice, '');
+});