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

Summarize and continue asks for the answer instead of sending the refused message a second time; agent README describes the context pieces

Niko1221ebaeda85f1f8
diff --git a/apps/host/server/agent/README.md b/apps/host/server/agent/README.md
index 58dd4a801..c0bd3fc70 100644
--- a/apps/host/server/agent/README.md
+++ b/apps/host/server/agent/README.md
@@ -14,6 +14,7 @@ and talks to its Gateway. Nothing here downloads or builds anything.
| `children.mjs` | pure projection of one helper agent's events into its row and its approval card |
| `preset.mjs` | the agent preset (which tools the chat has) |
| `plugins/strata-gate.mjs` | the Manual-mode approval gate (a Harness plugin, loaded by path) |
+| `plugins/strata-context.mjs`, `context-budget.mjs`, `context-fit.mjs` | measured context pressure, summaries that fit the window, the check before a message goes out |
| `agent-bridge.mjs` | the chat-to-session map, turns, approvals, Stop, status |
## Frames sent on `/api/chat/stream` for an agent turn
@@ -132,3 +133,14 @@ A turn that keeps failing the same way is stopped by the app, never left to the
- **Compaction:** after a guard stop (and after a turn the model server refused because the context was full) the bridge asks the Harness for `/compact` on that session, so the next message has room. Best effort and logged.
- **Never silent:** a turn that ends (`completed` or `max-tokens`) with no answer text gets "I ran out of room in this chat..." when the last request used 85% of the window or more, otherwise "I stopped without writing an answer..." (not when tool cards were shown, not after Stop, not after an error, which says why by itself). Goal runs have their own ending lines and are not guarded.
- Tests: `tests/agent-turn-guard.test.mjs` (counting, always; end to end with the real Harness, the scripted model's `searchloop` and `bloat` scripts and `searchMock: 'limited'` on the bridge, which runs the real search code on a pretend web that refuses, no network).
+
+## Context: measured pressure, summaries that fit, the check before a message goes out (2026-10-22)
+
+Found by the owner's hands-on test of the installed 0.2.1 (Gyro-S, 64K): a 118 KB log paste was 66,500 tokens to the engine and about 29,500 to the Harness (4 characters a token; logs and code are about 2); the engine refused it with a 400, the refusal stayed in the history, and then neither the next message nor `/compact` could go through, because the summary request carried the same history and was refused for its size too. `/compact` itself was never a command of the app: it went to the model as a question and the model answered "nothing to compact".
+
+- **`plugins/strata-context.mjs`** (inserted by the profile, like the gate) wraps `tokenMeter.measure` and `llm.stream` in place, once each. Pressure = the last prompt size the model server reported for an answer, plus what changed since priced at the density that measurement showed (`context-budget.mjs`: `pressureNow`, `densityOf`); never lower than the Harness's own price. Node prices are scaled the same way, so the retained tail is in real tokens. A summary request (`purpose: 'compaction'`) that would not fit the window is asked for in pieces: a message bigger than a piece is cut for the request only, each piece builds on the summary before it, a piece the server refuses is halved and tried again. `/strata-context` (a Harness command, like `/strata-gate`) answers `{tokens, window}` for a session so the host can tell the person true figures.
+- **`context-fit.mjs`**: before a message is sent the model server counts it (`POST /v1/messages/count_tokens`, its own tokenizer). `decideFit`: send; summarise first and then send (the message fits an otherwise empty chat); or never fits. The last one is not sent: the error frame has `code: 'CONTEXT_MESSAGE_TOO_LARGE'` and the page offers "Attach as a file" (`oversize.mjs`, `/api/chat/oversize`: the text is saved in the chat's folder, the assistant reads it in parts) or "Send a shortened preview". An engine that cannot count lets the message through; the Harness's own compact-and-retry is the net.
+- **`/compact`** is handled by the host (`compactCommand`): the Harness's `/compact`, then a plain line with the measured figures ("The chat was 90% full and is now 38% full"), or "nothing older to summarize" when the newest message is what fills the chat.
+- **Visible:** `compaction/start` shows "Summarizing earlier messages..." in the status line; `compaction/end` adds one plain line to the reply. The projector also sends a `context` frame after every model request, so the meter follows the running turn.
+- **A refusal that is left** (`CONTEXT_WINDOW_EXCEEDED`) is a plain sentence with the engine's text under Details and the buttons "Summarize and continue" and "Start a new chat". "Try sending the message again" is for other errors only.
+- Tests: `tests/agent-context.test.mjs` (arithmetic; the real Harness against the scripted worker with `window`, `charsPerToken` and `noCount`), `tests/oversize.test.mjs`, `tests/context-ui.test.mjs`. The run against a real engine is `scripts/context-e2e.mjs`.
diff --git a/apps/host/src/lib/store.ts b/apps/host/src/lib/store.ts
index b3f452038..3f925bf27 100644
--- a/apps/host/src/lib/store.ts
+++ b/apps/host/src/lib/store.ts
@@ -1381,14 +1381,13 @@ function dropFailedExchange(sessionId: string) {
/**
* The error card of a conversation that no longer fits the model's window: summarise the older messages (the same as typing /compact), then
- * ask the last question again in the same chat.
+ * ask the assistant to answer. The refused question is already in the assistant's conversation (it is the newest message, and a summary keeps
+ * the newest message as it is), so it is not sent a second time: a large one twice would not fit either.
*/
export async function summarizeAndContinue() {
- const failed = failedExchange();
- if (!failed) return;
- dropFailedExchange(failed.sessionId);
+ if (!failedExchange()) return;
await sendMessage('/compact');
- await sendMessage(failed.prompt);
+ await sendMessage('Please answer my last message now.');
}
/**
diff --git a/apps/host/tests/context-ui.test.mjs b/apps/host/tests/context-ui.test.mjs
index 8f68f642d..b9b8dfc42 100644
--- a/apps/host/tests/context-ui.test.mjs
+++ b/apps/host/tests/context-ui.test.mjs
@@ -73,8 +73,8 @@ test('the store keeps the code and the engine\'s text of an error, shows a sente
assert.match(store, /errorDetail: frame\.details/);
assert.match(store, /type === 'context'/);
const summarize = store.slice(store.indexOf('export async function summarizeAndContinue'), store.indexOf('export async function sendOversized'));
- assert.ok(summarize.indexOf("sendMessage('/compact')") > 0 && summarize.indexOf('sendMessage(failed.prompt)') > summarize.indexOf("sendMessage('/compact')"), 'summarise first, then ask the same question again');
- assert.ok(summarize.indexOf('dropFailedExchange') < summarize.indexOf("sendMessage('/compact')"), 'the failed question is not shown twice');
+ assert.ok(summarize.indexOf("sendMessage('/compact')") > 0 && summarize.indexOf("sendMessage('Please answer my last message now.')") > summarize.indexOf("sendMessage('/compact')"), 'summarise first, then ask for the answer');
+ assert.doesNotMatch(summarize, /failed.prompt|dropFailedExchange/, 'the refused question is not sent a second time (it is already in the conversation, and a large one twice would not fit)');
const oversized = store.slice(store.indexOf('export async function sendOversized'), store.indexOf('export function startNewChat'));
assert.match(oversized, /'\/api\/chat\/oversize'/);
assert.ok(oversized.indexOf('dropFailedExchange') > oversized.indexOf("'/api/chat/oversize'"), 'the failed message stays until the shorter one is ready');