Files
Strata/apps/host/tests/commit-warning.test.mjs
T
Niko1221 cde489b966 Models: the model card tells the person when the engine says Windows' memory limit is close and Strata may stop without a message (#1607)
On Windows the engine compares what a run plans to allocate on the host with the commit that is left (RAM plus page file) and, when it will not fit, writes one warning
line to its log ("strata serve: WARNING the Windows commit limit is 92.8 GiB ... 0.8 GiB of it is left, but this run plans 2.0 GiB ... it can end at the limit with no
message (exit code 0xC0000409, #1607) while RAM is still free"). The page's own plan said "ram: fits", so nobody was told. The engine has no structured field for the
warning (0.2.17: give it one), so serve/commit_limit.py reads the line from this start's log and engine.info["commit_warning"] = {limit_gib, left_gib, planned_gib,
floor_gib} carries the numbers in /metrics `engine` like the other INFO facts (cleared at each start). The loaded model's card on the Models page shows, with a warning sign:
"Windows is close to its memory limit (memory plus page file). Strata may stop without a message. Make the Windows page file larger, or choose a shorter context." and under
it "{0} GB of {1} GB are left." (two strings, guic47 and guic48 in ten languages through make-guic-locales.py, English approved by the coordinator). No host change: the
instance's metrics reach the page as they are. Not done: a warning before Load from the Windows fit check (it needs the planned-allocation arithmetic in Control; 0.2.17).

Tests: serve/test_commit_limit.py (7: the pattern pinned to the engine's exact text, both the Strix start's line from par/soak1117/evidence/engine-log-1304.txt and the engine's
format string in host_limits.hpp, last warning wins, no line no fact, and a real fake-engine process whose log carries the line: engine.info has the numbers, a start without it has
none); apps/host/tests/commit-warning.test.mjs (3). Linux host suite 1935 passed / 0 failed; py-serve 1874 passed / 0 failed and docs on p1004; live: throw-away host with the page's
native state answered with a ready model whose metrics carry commit_warning, headless Chrome (par/guie1117/live-commit2): the notice and the numbers line show, and are absent
without the field.
2026-11-17 13:27:35 +01:00

43 lines
3.3 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// #1607: on Windows the engine warns (in its log) that the commit limit (memory plus page file) is close and it may stop without a message. serve/commit_limit.py puts the
// numbers in /metrics engine.commit_warning; the loaded model's card says it in plain words with one next step.
import test from 'node:test';
import assert from 'node:assert/strict';
import { readFileSync } from 'node:fs';
import { transform } from 'esbuild';
const src = name => readFileSync(new URL(`../src/${name}`, import.meta.url), 'utf8').replace(/\r\n/g, '\n');
const { code } = await transform(src('lib/commit-warning.ts'), { loader: 'ts', format: 'esm' });
const { commitWarning } = await import(`data:text/javascript;base64,${Buffer.from(code).toString('base64')}`);
const LANGS = ['en', 'zh', 'ja', 'de', 'es', 'ru', 'pt', 'ko', 'fr', 'he'];
const NOTICE = 'Windows is close to its memory limit (memory plus page file). Strata may stop without a message. Make the Windows page file larger, or choose a shorter context.';
const LEFT = '{0} GB of {1} GB are left.';
test('the card reads the engine\'s warning from /metrics engine.commit_warning, with one decimal; no warning, no notice', () => {
assert.deepEqual(commitWarning({ commit_warning: { limit_gib: 92.8, left_gib: 0.8, planned_gib: 2, floor_gib: 4 } }), { left: '0.8', limit: '92.8' });
assert.deepEqual(commitWarning({ commit_warning: { limit_gib: 31.94, left_gib: 1.46 } }), { left: '1.5', limit: '31.9' });
for (const engine of [undefined, null, {}, { commit_warning: null }, { commit_warning: {} }, { commit_warning: { limit_gib: 0, left_gib: 0 } },
{ commit_warning: { limit_gib: 'x', left_gib: 1 } }, { commit_warning: { limit_gib: 10, left_gib: -1 } }, { commit_warning: 5 }, 'text', 7])
assert.equal(commitWarning(engine), null, JSON.stringify(engine));
});
test('the model card shows the notice for the loaded model only, with the numbers line', () => {
const card = src('components/NativeModels.tsx');
assert.match(card, /import \{ commitWarning \} from '\.\.\/lib\/commit-warning';/);
assert.ok(card.includes('const loadedCommit = commitWarning(loadedSelected?.metrics?.engine);'));
assert.ok(card.includes(`{tr(loadedCommit ? <div className="native-commit-note" role="status"><p className="small"><Icon name="warning" size={16}/>{tr("${NOTICE}")}</p><p className="small muted">{tr("${LEFT}", [loadedCommit.left, loadedCommit.limit])}</p></div> : null)}`));
});
test('both texts are in the catalog in all ten languages with the language rules', () => {
const cat = Object.fromEntries(LANGS.map(l => [l, JSON.parse(readFileSync(new URL(`../src/locales/guic-${l}.json`, import.meta.url), 'utf8'))]));
for (const text of [NOTICE, LEFT]) {
const key = Object.keys(cat.en).find(k => cat.en[k] === text);
assert.ok(key, `${text} is in guic-en.json`);
for (const l of LANGS) assert.ok(cat[l][key] && cat[l][key].trim(), `${l}: ${key}`);
assert.equal(/[^  ][;:?!]| [;:?!]/.test(cat.fr[key]), false, 'French: ; : ? ! only after a no-break space');
}
const left = Object.keys(cat.en).find(k => cat.en[k] === LEFT);
for (const l of LANGS) assert.ok(cat[l][left].includes('{0}') && cat[l][left].includes('{1}'), `${l} keeps both numbers`);
const notice = Object.keys(cat.en).find(k => cat.en[k] === NOTICE);
assert.match(cat.de[notice], /Vergrößern Sie/, 'German uses Sie');
});