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++

Offline: the update check says there is no internet connection in plain words; offline start and load test

Niko1221321f1590320c
diff --git a/apps/host/server/update-messages.mjs b/apps/host/server/update-messages.mjs
index fea106571..008043751 100644
--- a/apps/host/server/update-messages.mjs
+++ b/apps/host/server/update-messages.mjs
@@ -13,6 +13,13 @@ export const PHASE_TEXT = {
done: 'Done.',
};
+/** True when the failure looks like a computer with no internet (no DNS, no route, refused), not a slow or broken server. */
+export function looksOffline(error) {
+ const text = [error?.message, error?.cause?.message, error?.cause?.code, error?.code, error].filter(x => typeof x === 'string').join(' ');
+ return /ENOTFOUND|EAI_AGAIN|ENETUNREACH|ENETDOWN|EHOSTUNREACH|ECONNREFUSED|getaddrinfo|fetch failed|network is unreachable|name or service not known|temporary failure in name resolution|nodename nor servname|No address associated|URLError/i.test(text);
+}
+export const OFFLINE_MESSAGE = "No internet connection. Try again when you're online.";
+
/** { message, details, next } for an error thrown by Control's update calls (or the shell bridge). `subject` is "engine" or "Strata". */
export function plainUpdateError(error, subject = 'engine') {
const raw = String(error?.message ?? error ?? '');
@@ -30,6 +37,9 @@ export function plainUpdateError(error, subject = 'engine') {
next = `Wait a moment, then press ${button} in Settings.`;
} else if (/test start|did not answer a one-token|did not become ready/i.test(raw)) {
message = `The new ${subject} didn't start correctly, so nothing was changed. ${keep}`;
+ } else if (looksOffline(error) || looksOffline(raw)) {
+ message = 'No internet connection.';
+ next = "Try again when you're online.";
} else if (/could not be read|interrupted|timed out|timeout|ECONN|ENOTFOUND|fetch failed|could not reach|server answered|not answer within/i.test(raw)) {
message = "Couldn't reach the update server.";
next = `Check your internet connection, then press ${button} in Settings.`;
diff --git a/apps/host/server/updates.mjs b/apps/host/server/updates.mjs
index 1d890b8d4..e87ddfafb 100644
--- a/apps/host/server/updates.mjs
+++ b/apps/host/server/updates.mjs
@@ -1,4 +1,4 @@
-import { plainUpdateError } from './update-messages.mjs';
+import { OFFLINE_MESSAGE, looksOffline, plainUpdateError } from './update-messages.mjs';
/** Read-only release checks. Installing/rolling back needs a managed installer. */
const RELEASES = 'https://api.github.com/repos/Niko1221/Strata/releases?per_page=30';
@@ -33,7 +33,7 @@ export async function checkUpdates({ appVersion, engineVersion }, fetcher = fetc
strata = { status: newer ? 'available' : 'current', latestVersion: latest.tag_name, releaseUrl, message: newer ? `Strata ${latest.tag_name} is available.` : 'Strata is up to date.' };
}
} catch (error) {
- strata = { status: 'error', message: error.name === 'TimeoutError' ? 'The release check timed out. Try again.' : error.message ?? 'Could not check for updates.' };
+ strata = { status: 'error', message: looksOffline(error) ? OFFLINE_MESSAGE : error.name === 'TimeoutError' ? 'The release check timed out. Try again.' : error.message ?? 'Could not check for updates.' };
}
return {
checkedAt: new Date().toISOString(),
@@ -56,7 +56,7 @@ export async function checkComponentUpdates({ control, appUpdater = null, appVer
report = await control.updateCheck({ appVersion });
} catch (error) {
const plain = plainUpdateError(error, 'Strata');
- const message = /update server|aren't available/.test(plain.headline) ? plain.message : `Couldn't check for updates. Try again in a moment.`;
+ const message = /update server|aren't available|No internet/.test(plain.headline) ? plain.message : `Couldn't check for updates. Try again in a moment.`;
return { checkedAt, strata: { installedVersion: appVersion ?? control.version ?? null, status: 'error', message, details: plain.details, canInstall: false }, engine: { installedVersion: null, status: 'error', message, details: plain.details, canInstall: false } };
}
const mib = bytes => `${Math.round((bytes ?? 0) / (1 << 20))} MB`;
diff --git a/apps/host/tests/component-updates.test.mjs b/apps/host/tests/component-updates.test.mjs
index d0d3c3f87..8a74ec91c 100644
--- a/apps/host/tests/component-updates.test.mjs
+++ b/apps/host/tests/component-updates.test.mjs
@@ -311,3 +311,23 @@ test('a failed update job shows plain words and keeps the technical reason as de
assert.match(job.details, /ConnectionResetError/);
} finally { await f.native.close(); f.cleanup(); }
});
+
+test('offline, the signed-feed check says there is no internet connection in plain words and keeps the reason in details', async () => {
+ for (const raw of ['fetch failed', '<urlopen error [Errno 11001] getaddrinfo failed>', 'getaddrinfo ENOTFOUND updates.example']) {
+ const control = { version: '0.1.45', async updateCheck() { throw new Error(raw); } };
+ const result = await checkComponentUpdates({ control, appVersion: '0.2.0' });
+ assert.equal(result.strata.status, 'error', raw);
+ assert.equal(result.strata.message, "No internet connection. Try again when you're online.", raw);
+ assert.equal(result.engine.message, "No internet connection. Try again when you're online.", raw);
+ assert.equal(result.strata.details, raw);
+ }
+});
+
+test('the app updater and the host never reach the network by themselves: only check() does', async () => {
+ const calls = [];
+ const updater = createAppUpdater({ env: { STRATA_SHELL_BRIDGE: 'http://127.0.0.1:4000', STRATA_SHELL_TOKEN: 'tok' }, fetcher: async url => { calls.push(url); return Response.json({ available: false }); } });
+ assert.ok(updater);
+ assert.equal(calls.length, 0, 'creating the updater makes no call');
+ await updater.check();
+ assert.equal(calls.length, 1);
+});
diff --git a/apps/host/tests/helpers/offline-preload.mjs b/apps/host/tests/helpers/offline-preload.mjs
new file mode 100644
index 000000000..abe4496f1
--- /dev/null
+++ b/apps/host/tests/helpers/offline-preload.mjs
@@ -0,0 +1,20 @@
+/**
+ * Preloaded into a host process (`node --import`) to make the network "unplugged": every fetch to an address that is not this
+ * computer is written to the file in STRATA_NET_LOG (one URL per line) and fails the way a machine with no internet does
+ * (TypeError: fetch failed). Loopback calls pass through, so the host's own engine and UI traffic still works.
+ */
+import { appendFileSync } from 'node:fs';
+
+const real = globalThis.fetch;
+const log = process.env.STRATA_NET_LOG;
+const loopback = host => host === '127.0.0.1' || host === 'localhost' || host === '[::1]' || host === '::1';
+
+globalThis.fetch = function offlineFetch(input, init) {
+ let url;
+ try { url = new URL(typeof input === 'string' ? input : input?.url ?? String(input)); } catch { return real(input, init); }
+ if (loopback(url.hostname)) return real(input, init);
+ if (log) appendFileSync(log, `${url.href}\n`);
+ const error = new TypeError('fetch failed');
+ error.cause = Object.assign(new Error(`getaddrinfo ENOTFOUND ${url.hostname}`), { code: 'ENOTFOUND' });
+ return Promise.reject(error);
+};
diff --git a/apps/host/tests/offline-start.test.mjs b/apps/host/tests/offline-start.test.mjs
new file mode 100644
index 000000000..dd53ee4df
--- /dev/null
+++ b/apps/host/tests/offline-start.test.mjs
@@ -0,0 +1,71 @@
+import test from 'node:test';
+import { ROOMY_HOST } from './helpers/hardware.mjs';
+import assert from 'node:assert/strict';
+import { spawn } from 'node:child_process';
+import { existsSync, readFileSync } from 'node:fs';
+import { mkdtemp, rm } from 'node:fs/promises';
+import { createServer } from 'node:net';
+import { tmpdir } from 'node:os';
+import { join } from 'node:path';
+import { fileURLToPath, pathToFileURL } from 'node:url';
+
+/**
+ * Strata works without internet. The host is started with every non-loopback fetch failing (and logged), the way a PC with the cable
+ * pulled behaves. Starting, reading the screens' data and loading a model make no outside call. The update check is the one
+ * thing that reaches out, and only when it is asked for: opening Settings does not ask.
+ */
+const root = fileURLToPath(new URL('..', import.meta.url));
+const preload = pathToFileURL(fileURLToPath(new URL('./helpers/offline-preload.mjs', import.meta.url))).href;
+const delay = ms => new Promise(r => setTimeout(r, ms));
+async function freePort() { const s = createServer(); await new Promise(r => s.listen(0, '127.0.0.1', r)); const p = s.address().port; await new Promise(r => s.close(r)); return p; }
+
+async function startOfflineHost() {
+ const home = await mkdtemp(join(tmpdir(), 'strata-offline-'));
+ const log = join(home, 'net.log');
+ const port = await freePort();
+ let output = '';
+ const host = spawn(process.execPath, ['--import', preload, 'server/index.mjs'], {
+ cwd: root, stdio: ['ignore', 'pipe', 'pipe'],
+ env: { ...process.env, STRATA_HOME: home, STRATA_MODELS_DIR: join(home, 'models'), STRATA_PORT: String(port), STRATA_SHARE_PORT: String(await freePort()), STRATA_TUNNEL_PORT: String(await freePort()), STRATA_PACKAGED: '1', STRATA_NET_LOG: log, STRATA_NO_ACQUIRE: '1', STRATA_REAL_ENGINE: '0', STRATA_TEST_HARDWARE: ROOMY_HOST },
+ });
+ host.stdout.on('data', d => { output += d; }); host.stderr.on('data', d => { output += d; });
+ let up = false;
+ for (let i = 0; i < 150 && !up; i++) { try { up = (await fetch(`http://127.0.0.1:${port}/api/health`)).ok; } catch { await delay(100); } }
+ assert.ok(up, `host started\n${output}`);
+ const calls = () => (existsSync(log) ? readFileSync(log, 'utf8').split('\n').filter(Boolean) : []);
+ const get = async path => { const r = await fetch(`http://127.0.0.1:${port}${path}`); return { status: r.status, data: await r.json().catch(() => null) }; };
+ const post = async path => { const r = await fetch(`http://127.0.0.1:${port}${path}`, { method: 'POST', headers: { 'content-type': 'application/json' }, body: '{}' }); return { status: r.status, data: await r.json().catch(() => null) }; };
+ return { host, get, post, calls, stop: async () => { host.kill(); await new Promise(r => host.once('exit', r)); await rm(home, { recursive: true, force: true }).catch(() => {}); } };
+}
+
+test('with no internet the host starts, serves its screens and loads a model without one outside call', async t => {
+ const h = await startOfflineHost();
+ t.after(h.stop);
+ assert.deepEqual(h.calls(), [], 'nothing reached out while starting');
+ for (const path of ['/api/native', '/api/setup', '/api/models', '/api/engine', '/api/health']) {
+ const r = await h.get(path);
+ assert.equal(r.status, 200, `${path} answers`);
+ }
+ const install = await h.post('/api/models/qwen38-q4_k_m/install');
+ assert.equal(install.status, 200);
+ let installed = false;
+ for (let i = 0; i < 150 && !installed; i++) { installed = (await h.get('/api/models')).data.variants.find(v => v.id === 'qwen38-q4_k_m').state === 'installed'; if (!installed) await delay(100); }
+ assert.ok(installed, 'the model is on this computer');
+ const load = await h.post('/api/models/qwen38-q4_k_m/load');
+ assert.equal(load.status, 200, JSON.stringify(load.data));
+ assert.equal(load.data.loaded, 'qwen38-q4_k_m');
+ assert.deepEqual(h.calls(), [], 'opening the screens and loading a model made no outside call');
+});
+
+test('the update check reaches out only when it is asked for, and offline it answers in plain words', async t => {
+ const h = await startOfflineHost();
+ t.after(h.stop);
+ await h.get('/api/setup'); await h.get('/api/native'); await h.get('/api/models');
+ assert.equal(h.calls().length, 0, 'opening the screens does not check');
+ const checked = await h.get('/api/updates/check');
+ assert.equal(checked.status, 200);
+ assert.equal(h.calls().length, 1, 'one check, from the click');
+ assert.equal(checked.data.strata.status, 'error');
+ assert.equal(checked.data.strata.message, "No internet connection. Try again when you're online.");
+ assert.doesNotMatch(JSON.stringify(checked.data), /fetch failed/);
+});
diff --git a/apps/host/tests/updates.test.mjs b/apps/host/tests/updates.test.mjs
index 1e92b5c88..56d3d43b5 100644
--- a/apps/host/tests/updates.test.mjs
+++ b/apps/host/tests/updates.test.mjs
@@ -25,3 +25,17 @@ test('release content cannot inject an external or script update link', async ()
assert.equal(result.strata.status, 'available');
assert.equal(result.strata.releaseUrl, undefined);
});
+
+test('offline, "Check for updates" says there is no internet connection instead of "fetch failed"', async () => {
+ const offline = async () => { throw Object.assign(new TypeError('fetch failed'), { cause: Object.assign(new Error('getaddrinfo ENOTFOUND api.github.com'), { code: 'ENOTFOUND' }) }); };
+ const result = await checkUpdates(installed, offline);
+ assert.equal(result.strata.status, 'error');
+ assert.equal(result.strata.message, "No internet connection. Try again when you're online.");
+ for (const reason of ['EAI_AGAIN', 'ECONNREFUSED', 'ENETUNREACH']) {
+ const r = await checkUpdates(installed, async () => { throw Object.assign(new Error('connect failed'), { code: reason }); });
+ assert.equal(r.strata.message, "No internet connection. Try again when you're online.", reason);
+ }
+ // a slow or broken server is not "offline"
+ const slow = await checkUpdates(installed, async () => { throw Object.assign(new Error('The operation was aborted due to timeout'), { name: 'TimeoutError' }); });
+ assert.equal(slow.strata.message, 'The release check timed out. Try again.');
+});