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

Reply room 30 percent of the window and an eighth headroom: a 32K window no longer compacts every few steps

Niko1221af34f0a4b7a8
diff --git a/apps/host/server/agent/profile.mjs b/apps/host/server/agent/profile.mjs
index 9788c2667..8879aff89 100644
--- a/apps/host/server/agent/profile.mjs
+++ b/apps/host/server/agent/profile.mjs
@@ -105,20 +105,21 @@ function fingerprint(provider, secret) {
*/
export function localOutputBudget(context) {
const c = Number.isFinite(context) && context > 0 ? context : 32768;
- // Half the window, at most 32K: still far more than the old 8192 that cut big answers off, and it leaves the other half for the
- // conversation. The Harness's automatic compaction reads this number as the room the reply reserves: with nearly the whole window
- // reserved it had no room left to measure pressure in, and a long chat or a long helper task never compacted.
- return Math.max(4096, Math.min(32768, Math.floor(c / 2)));
+ // 30 percent of the window, at most 32K (9,830 tokens at 32K, 19,660 at 64K): far more than the old 8192 that cut big answers off, and it leaves
+ // the rest for the conversation. The Harness's automatic compaction reads this number as the room the reply reserves: with nearly the whole
+ // window reserved it had no room left to measure pressure in and never compacted; with half of it reserved a 32K window compacted every few
+ // steps (the system prompt and tool list alone are about 7K tokens), which slowed a long task to a crawl.
+ return Math.max(4096, Math.min(32768, Math.floor(c * 0.3)));
}
/**
* When the Harness's automatic compaction starts condensing old history, for one model: its own default keeps 64K tokens of headroom,
- * which on a local window of 32K to 128K leaves no room at all (it then reports a configuration error once and never compacts). A quarter
- * of what the window has left after the reply's room works from 16K up to the largest windows. Compaction then starts at about 70 percent.
+ * which on a local window of 32K to 128K leaves no room at all (it then reports a configuration error once and never compacts). An eighth
+ * of what the window has left after the reply's room works from 16K up to the largest windows. Compaction then starts at about 60 percent.
*/
export function compactionHeadroom(context, outputBudget) {
const room = Math.max(0, (Number.isFinite(context) && context > 0 ? context : 32768) - outputBudget);
- return Math.max(512, Math.min(65536, Math.floor(room * 0.25)));
+ return Math.max(512, Math.min(65536, Math.floor(room * 0.125)));
}
/**
diff --git a/apps/host/tests/agent-compaction.test.mjs b/apps/host/tests/agent-compaction.test.mjs
index e6c3cd5b3..61667be63 100644
--- a/apps/host/tests/agent-compaction.test.mjs
+++ b/apps/host/tests/agent-compaction.test.mjs
@@ -12,8 +12,8 @@ import { buildProfile, compactionHeadroom, localOutputBudget } from '../server/a
const HARNESS = process.env.STRATA_HARNESS_DIR;
const skip = !HARNESS || !resolveHarness({ env: process.env }).ok ? 'STRATA_HARNESS_DIR is not set to a built Harness' : false;
-test('the reply keeps half the window (at most 32K) and compaction gets a headroom that fits, for every window size', () => {
- assert.equal(localOutputBudget(32768), 16384); assert.equal(localOutputBudget(262144), 32768); assert.equal(localOutputBudget(8192), 4096); assert.equal(localOutputBudget(undefined), 16384);
+test('the reply keeps 30 percent of the window (at most 32K) and compaction gets a headroom that fits, for every window size', () => {
+ assert.equal(localOutputBudget(32768), 9830); assert.equal(localOutputBudget(262144), 32768); assert.equal(localOutputBudget(8192), 4096); assert.equal(localOutputBudget(undefined), 9830);
for (const w of [8192, 16384, 32768, 65536, 131072, 262144, 1_000_000]) {
const out = localOutputBudget(w), head = compactionHeadroom(w, out);
const threshold = Math.floor(Math.min(w * 0.8, w - out - head));
@@ -22,7 +22,7 @@ test('the reply keeps half the window (at most 32K) and compaction gets a headro
assert.ok(Math.floor((w - out) * 0.16) < threshold, `window ${w}: the verbatim tail is smaller than the start point`);
}
const profile = buildProfile({ local: [{ id: 'a', modelId: 'm', baseUrl: 'http://x', context: 32768 }], connections: [] });
- assert.match(profile.patch, /"modelPolicies": \[\s*\{\s*"provider": "strata-local",\s*"model": "m",\s*"headroomTokens": 4096/);
+ assert.match(profile.patch, /"modelPolicies": \[\s*\{\s*"provider": "strata-local",\s*"model": "m",\s*"headroomTokens": 2867/);
});
test('a long chat on a small window compacts before it overflows, and the conversation goes on', { skip }, async (t) => {
diff --git a/apps/host/tests/agent-events.test.mjs b/apps/host/tests/agent-events.test.mjs
index 401fc412c..ea0c5f077 100644
--- a/apps/host/tests/agent-events.test.mjs
+++ b/apps/host/tests/agent-events.test.mjs
@@ -18,7 +18,7 @@ test('the generated profile names credentials, never carries them, and declares
const providers = entries.find(e => e.id === 'llm-pi-ai').config.providers;
assert.deepEqual(Object.keys(providers).sort(), ['api-c0nn-1234-ab', 'strata-local']);
assert.equal(providers['strata-local'].models[0].contextWindow, 32768);
- assert.equal(providers['strata-local'].models[0].maxTokens, 16384, 'a local model gets half its window for a reply (it was 8192, which cut big answers off) and the rest stays for the conversation, so the Harness can compact it');
+ assert.equal(providers['strata-local'].models[0].maxTokens, 9830, 'a local model gets 30 percent of its window for a reply (it was 8192, which cut big answers off) and the rest stays for the conversation, so the Harness can compact it');
assert.equal(providers['strata-local'].models[0].reasoning, true);
assert.equal(providers['strata-local'].compat.thinkingFormat, 'chat-template');
assert.equal(providers['api-c0nn-1234-ab'].models[1].contextWindow, ASSUMED_API_CONTEXT, 'an unknown API window is a stated assumption, not a catalog default');
diff --git a/apps/host/tests/agent-shape.test.mjs b/apps/host/tests/agent-shape.test.mjs
index 05983a19d..0094aa933 100644
--- a/apps/host/tests/agent-shape.test.mjs
+++ b/apps/host/tests/agent-shape.test.mjs
@@ -56,7 +56,7 @@ test('the profile adds a response-settings copy of each shapeable route (local,
assert.equal(providers['api-cloud'].compat, undefined, 'a cloud service does not');
const small = buildProfile({ local: [], connections: [{ id: 'own', name: 'Own', baseUrl: 'http://127.0.0.1:18798/v1', protocol: 'openai-chat', apiKey: '', models: [{ id: 'm', contextMax: 32768 }] }] });
const own = JSON.parse(small.patch.slice(small.patch.indexOf('['))).find(e => e.id === 'llm-pi-ai').config.providers['api-own'];
- assert.equal(own.models[0].maxTokens, 16384, 'a server on this network keeps half its window for the reply so long tasks can be compacted (it was 28672 of 32768: no room, no compaction)');
+ assert.equal(own.models[0].maxTokens, 9830, 'a server on this network keeps 30 percent of its window for the reply so long tasks can be compacted (it was 28672 of 32768: no room, no compaction)');
assert.match(profile.patch, /"baseURL": "http:\/\/127\.0\.0\.1:8791\/api\/internal\/agent-llm\/strata-local~s8192\/v1"/);
assert.match(profile.patch, /"x-strata-budget": "8192"/);
assert.match(profile.patch, /"provider": "strata-local~s8192"/, 'compaction keeps its timing on the copy too');
diff --git a/apps/host/tests/agent-tools.test.mjs b/apps/host/tests/agent-tools.test.mjs
index baffeb311..b4d3b6acb 100644
--- a/apps/host/tests/agent-tools.test.mjs
+++ b/apps/host/tests/agent-tools.test.mjs
@@ -237,7 +237,7 @@ test('the output budget is not the old 8192, and the Reasoning menu reaches the
const off = await ask('think-off', 'Off');
assert.equal(ctk(off).enable_thinking, false); assert.equal(ctk(off).reasoning_effort, undefined);
assert.equal(off.enable_thinking, undefined, 'a top-level enable_thinking is the field the Strata server ignores');
- assert.ok(off.max_completion_tokens >= 32000 && off.max_completion_tokens <= 32768, `budget ${off.max_completion_tokens} (half the window, at most 32K: never the old 8192, and room is left for the conversation to be compacted)`);
+ assert.ok(off.max_completion_tokens === 19660, `budget ${off.max_completion_tokens} (half the window, at most 32K: never the old 8192, and room is left for the conversation to be compacted)`);
const high = await ask('think-high', 'High');
assert.equal(ctk(high).enable_thinking, true); assert.equal(ctk(high).reasoning_effort, 'high');
const low = await ask('think-low', 'Low');