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++
A big message on a chat near the compaction threshold summarises first; the real-engine script can also run against a server that is already up
Niko12213ae6b3041b43
diff --git a/apps/host/scripts/context-e2e.mjs b/apps/host/scripts/context-e2e.mjsindex 2696f8880..02e87fe78 100644--- a/apps/host/scripts/context-e2e.mjs+++ b/apps/host/scripts/context-e2e.mjs@@ -33,6 +33,8 @@ const MIN_FREE_GB = Number(env('E2E_MIN_FREE_GB', '7'));const GGUF = join(DOCS, 'models', 'gyro-Gyro-S', 'Qwen3.8-Flash-Next-Gyro-S-TQ1_0.gguf');const CUDA_BIN = env('E2E_CUDA_BIN', 'C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v13.0\\bin');const WINDOW = 65536;+/** A model server that is already running (the scripted worker, to try this script without a GPU): nothing is started or stopped. */+const EXISTING = process.env.E2E_BASE_URL ?? '';const sleep = ms => new Promise(r => setTimeout(r, ms));const freeGb = () => {@@ -43,8 +45,8 @@ const rows = [];const note = (id, ok, detail) => { rows.push({ id, ok, detail }); console.log(`${ok ? 'PASS' : 'FAIL'} ${id} ${detail}`); };if (!process.env.STRATA_HARNESS_DIR) { console.error('STRATA_HARNESS_DIR is not set'); process.exit(2); }-for (const f of [ENGINE, GGUF]) if (!existsSync(f)) { console.error(`missing: ${f}`); process.exit(2); }-if (freeGb() < 20) { console.error(`only ${freeGb()} GB of RAM are free; wait for the other streams (lock.py status) and run again`); process.exit(2); }+if (!EXISTING) for (const f of [ENGINE, GGUF]) if (!existsSync(f)) { console.error(`missing: ${f}`); process.exit(2); }+if (!EXISTING && freeGb() < 20) { console.error(`only ${freeGb()} GB of RAM are free; wait for the other streams (lock.py status) and run again`); process.exit(2); }const scratch = mkdtempSync(join(tmpdir(), 'strata-ctx-e2e-'));const configFile = join(scratch, 'server.json');@@ -73,20 +75,19 @@ const finish = async (code) => {};process.on('SIGINT', () => finish(130));-server = spawn(PYTHON, ['serve/server.py', '--engine', 'strata', '--config', configFile, '--port', String(PORT), '--no-api-key', '--ready-file', readyFile], {+if (!EXISTING) server = spawn(PYTHON, ['serve/server.py', '--engine', 'strata', '--config', configFile, '--port', String(PORT), '--no-api-key', '--ready-file', readyFile], {cwd: REPO, env: { ...process.env, PATH: `${CUDA_BIN};${process.env.PATH}`, STRATA_DATA_DIR: join(scratch, 'data') }, stdio: ['ignore', 'pipe', 'pipe'], windowsHide: true,});const sink = [];-server.stdout.on('data', d => sink.push(String(d))); server.stderr.on('data', d => sink.push(String(d)));-server.on('exit', code => { sink.push(`[server exited ${code}]`); server = null; });+if (server) { server.stdout.on('data', d => sink.push(String(d))); server.stderr.on('data', d => sink.push(String(d))); server.on('exit', code => { sink.push(`[server exited ${code}]`); server = null; }); }// Memory alarm: this run must never be what freezes the PC. Under the floor the engine is stopped (by PID) and the run ends.-alarm = setInterval(() => { const free = freeGb(); if (free < MIN_FREE_GB) { console.error(`ALARM: ${free} GB of RAM free, stopping the engine`); finish(3); } }, 3000);-alarm.unref?.();+if (!EXISTING) alarm = setInterval(() => { const free = freeGb(); if (free < MIN_FREE_GB) { console.error(`ALARM: ${free} GB of RAM free, stopping the engine`); finish(3); } }, 3000);+alarm?.unref?.();-const base = `http://127.0.0.1:${PORT}`;+const base = EXISTING || `http://127.0.0.1:${PORT}`;let ready = false;for (let i = 0; i < 120 && !ready; i++) {- if (!server) break;+ if (!EXISTING && !server) break;try { ready = (await fetch(`${base}/health`, { signal: AbortSignal.timeout(2000) })).ok; } catch { /* still loading */ }if (!ready) await sleep(2000);}@@ -137,7 +138,7 @@ const needle = 'NOTE FROM OPS: the vault code is COBALT-27. Do not lose it.';const timeline = [];let notes = 0, refusedAny = false, peak = 0;{- for (let k = 0; k < 6; k++) {+ for (let k = 0; k < 5; k++) {const body = logText(34_000, k * 1000, k === 0 ? needle : '');const t = await turnsOf(`${body}\n\nReply with the single word OK.`);const note = noteOf(t.frames);@@ -149,7 +150,7 @@ let notes = 0, refusedAny = false, peak = 0;console.log(' ' + timeline.at(-1));if (t.last.type === 'error') break;}- note('B six dense messages (about 14K tokens each) in a 64K window: no error', !refusedAny, `peak context ${peak} of ${WINDOW}; ${notes} compaction note(s) in the chat`);+ note('B five dense messages (about 14K tokens each) in a 64K window: no error', !refusedAny, `peak context ${peak} of ${WINDOW}; ${notes} compaction note(s) in the chat`);note('B compaction ran and was announced', notes >= 1, timeline.join(' | '));}@@ -175,7 +176,7 @@ let notes = 0, refusedAny = false, peak = 0;rows.push({ id: 'D the needle', ok: /COBALT-27/.test(answer), detail: `reported only: answer "${answer.slice(0, 80)}"` });}-console.log('\n' + rows.map(r => `${r.ok ? 'PASS' : 'FAIL'} ${r.id}`).join('\n'));+console.log('\n' + rows.map(r => `${r.ok ? 'PASS' : r.id.startsWith('D') ? 'INFO' : 'FAIL'} ${r.id}${r.id.startsWith('D') ? ` ${r.detail}` : ''}`).join('\n'));const failed = rows.filter(r => !r.ok && !r.id.startsWith('D')).length;writeFileSync(join(scratch, 'result.json'), JSON.stringify(rows, null, 2));await finish(failed ? 1 : 0);diff --git a/apps/host/server/agent/agent-bridge.mjs b/apps/host/server/agent/agent-bridge.mjsindex 7f61de553..4a0ccbc83 100644--- a/apps/host/server/agent/agent-bridge.mjs+++ b/apps/host/server/agent/agent-bridge.mjs@@ -22,7 +22,7 @@ import { randomUUID } from 'node:crypto';import { GatewayClient } from './gateway-client.mjs';import { HarnessProcess, resolveHarness, redact, stopStaleAgent } from './harness-runtime.mjs';import { StatusReporter } from './status.mjs';-import { buildProfile, routeFor, MODE_PRESETS, modeOf, effortOf } from './profile.mjs';+import { buildProfile, routeFor, MODE_PRESETS, modeOf, effortOf, localOutputBudget, compactionHeadroom } from './profile.mjs';import { TurnProjector, parseArguments as parseArgs } from './events.mjs';import { ChildProjector } from './children.mjs';import { nearestBudget } from './llm-shape.mjs';@@ -1203,11 +1203,14 @@ export function createAgentBridge({ dataDir, componentsDir = null, bundledDir =const now = fresh ? null : await contextOf(runtime, sessionId);const window = now?.window || route.contextWindow;const pressure = now?.tokens ?? 0;- let verdict = decideFit({ window, pressure, messageTokens: tokens });+ // Where the Harness starts summarising by itself on this window (profile.mjs: the reply keeps its room, then the headroom).+ const reply = localOutputBudget(window);+ const threshold = Math.floor(Math.min(window * 0.8, window - reply - compactionHeadroom(window, reply)));+ let verdict = decideFit({ window, pressure, messageTokens: tokens, threshold });// The earlier conversation carried into a fresh session is what pushed it over: send the message alone instead.if (verdict.action === 'too-large' && carried !== message) {const alone = await count(message);- if (alone != null) { tokens = alone; verdict = decideFit({ window, pressure, messageTokens: alone }); }+ if (alone != null) { tokens = alone; verdict = decideFit({ window, pressure, messageTokens: alone, threshold }); }}return { ...verdict, tokens, window, pressure };}diff --git a/apps/host/server/agent/context-fit.mjs b/apps/host/server/agent/context-fit.mjsindex 04552cb29..0abcb08a2 100644--- a/apps/host/server/agent/context-fit.mjs+++ b/apps/host/server/agent/context-fit.mjs@@ -17,17 +17,23 @@ export const COUNT_ABOVE_CHARS = 3000;export const replyRoom = window => Math.max(512, Math.min(REPLY_FLOOR, Math.floor(window / 8)));/**- * @param {{window:number, pressure?:number, base?:number, messageTokens:number}} input- * `pressure` is what the chat holds now (measured), `base` what an empty chat holds, `messageTokens` the new message.+ * @param {{window:number, pressure?:number, base?:number, messageTokens:number, threshold?:number}} input+ * `pressure` is what the chat holds now (measured), `base` what an empty chat holds, `messageTokens` the new message, `threshold` where the+ * Harness starts summarising by itself. The Harness looks at that only before its NEXT step, so a big message that arrives now would otherwise+ * be sent on top of a chat already near the threshold (2026-10-22: 54K of 64K held by the time it was looked at): summarise first.* @returns {{action:'send'|'summarize'|'too-large', room:number, needs:number}}*/-export function decideFit({ window, pressure = 0, base: given = BASE_TOKENS, messageTokens }) {+export function decideFit({ window, pressure = 0, base: given = BASE_TOKENS, messageTokens, threshold = 0 }) {const reply = replyRoom(window);const base = Math.min(given, Math.floor(window * 0.6)); // on a small window the first prompt cannot be what the window is made of// A chat holds at least what an empty one does (the system prompt and the tools), so a new chat is not counted as empty.const needs = Math.max(pressure, base) + messageTokens + reply;if (!(window > 0) || !(messageTokens >= 0)) return { action: 'send', room: Infinity, needs: 0 };- if (needs <= window) return { action: 'send', room: window - needs, needs };+ if (needs <= window) {+ const worthIt = pressure > base + window * 0.1; // older messages worth summarising: more than a tenth of the window beyond the first prompt+ if (threshold > 0 && worthIt && pressure + messageTokens > threshold) return { action: 'summarize', room: window - needs, needs, why: 'threshold' };+ return { action: 'send', room: window - needs, needs };+ }// Not as it stands. Does the message fit in an otherwise empty chat (only the system prompt and the tools before it)?if (base + messageTokens + reply <= window) return { action: 'summarize', room: window - (base + messageTokens + reply), needs };return { action: 'too-large', room: window - (base + messageTokens + reply), needs };diff --git a/apps/host/tests/agent-context.test.mjs b/apps/host/tests/agent-context.test.mjsindex 923f695d4..600b1272f 100644--- a/apps/host/tests/agent-context.test.mjs+++ b/apps/host/tests/agent-context.test.mjs@@ -162,6 +162,17 @@ test('fit: a message that fits is sent, one that fits after a summary is summariassert.equal(decideFit({ window: 8192, pressure: 0, messageTokens: 5000 }).action, 'too-large', 'a small window has less room for a message');});+test('fit: a big message on a chat already near the compaction threshold summarises first, so the window is never come close to', () => {+ // 64K window: the Harness starts summarising at 40,142 (profile.mjs), but looks only before its NEXT step; a message that arrives now is not in that count.+ const at = { window: 65536, threshold: 40142, messageTokens: 14400 };+ const near = decideFit({ ...at, pressure: 39840 });+ assert.equal(near.action, 'summarize'); assert.equal(near.why, 'threshold');+ assert.equal(decideFit({ ...at, pressure: 15000 }).action, 'send', 'still under the threshold with the message on top');+ assert.equal(decideFit({ ...at, pressure: 13000, messageTokens: 30000 }).action, 'send', 'a chat that holds little beyond its first prompt has nothing worth summarising');+ assert.equal(decideFit({ window: 65536, messageTokens: 14400, pressure: 39840 }).action, 'send', 'no threshold given: only the window decides');+ assert.equal(decideFit({ ...at, pressure: 59048, messageTokens: 5000 }).why, undefined, 'a refusal-sized case is the old rule, not the threshold');+});+test('count: the engine\'s own number, or nothing when it cannot be had (then nothing is blocked)', async () => {const sent = [];const ok = async (url, init) => { sent.push([url, JSON.parse(init.body), init.headers]); return { ok: true, json: async () => ({ input_tokens: 70141 }) }; };