Documented tree replacement (the history has no git-subtree metadata): 3-way merge of the old subtree (570201a:engine/strata) against upstream 41cf05a06a25dd29103b7b27a2279a3f60c21876 (2026-10-25), merge base = the old pin d9ab8435 (tree-identical to upstream 5b734e42; d9ab8435 is not an ancestor of upstream main). Local patches re-applied by hand where they conflicted (15 files): STRATA_CUDA_STATIC profile, experimental KAR experts and KAR PLE arms, keyless V-only arm (now beside upstream's K8V4 hybrid KV and fused norm+rope). Details, conflict table and left-out files are in docs/upstream.md. Left out (weights, captures, logs, media): new bench/results (2022 files), binary media and app assets (61), docs/work/evidence (24), *.bin / *.gguf data files, and the 7 files the first import already left out. scripts/build-cpu.sh: build the 11 CPU tests upstream registered since the old pin (they ran as "Not Run"). Checked: build-cpu.sh 16/16 ctest in WSL; sm_86 CUDA objects of the patched files compile, also with the KAR macros on. No GPU run, no quality gate. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
52 lines
3.8 KiB
JavaScript
52 lines
3.8 KiB
JavaScript
// Automatic compaction for a LOCAL model: it starts before the window is full, the chat goes on after it, and helpers get it too.
|
|
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { mkdtempSync, mkdirSync, rmSync } from 'node:fs';
|
|
import { tmpdir } from 'node:os';
|
|
import { join } from 'node:path';
|
|
import { startScriptedWorker } from './helpers/scripted-worker.mjs';
|
|
import { createAgentBridge } from '../server/agent/agent-bridge.mjs';
|
|
import { resolveHarness } from '../server/agent/harness-runtime.mjs';
|
|
import { buildProfile, compactionHeadroom, localOutputBudget } from '../server/agent/profile.mjs';
|
|
|
|
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 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));
|
|
assert.ok(threshold > 0, `window ${w}: a positive start point (${threshold})`);
|
|
assert.ok(threshold >= (w - out) * 0.5, `window ${w}: compaction starts after at least half of the room the conversation has (${threshold})`);
|
|
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": 2867/);
|
|
});
|
|
|
|
test('a long chat on a small window compacts before it overflows, and the conversation goes on', { skip }, async (t) => {
|
|
const worker = await startScriptedWorker({});
|
|
const dir = mkdtempSync(join(tmpdir(), 'strata-compact-'));
|
|
const ws = join(dir, 'ws'); mkdirSync(ws, { recursive: true });
|
|
const bridge = createAgentBridge({ dataDir: dir, localInstances: () => [{ id: 'i', label: 'S', baseUrl: worker.url, modelId: 'scripted-model', context: 16384, slots: 2 }], connections: () => [], env: process.env, startTimeoutMs: 90_000 });
|
|
t.after(async () => { await bridge.close(); await worker.close(); try { rmSync(dir, { recursive: true, force: true, maxRetries: 3 }); } catch { /* best effort */ } });
|
|
const big = 'alpha '.repeat(1500);
|
|
const replies = [];
|
|
for (let i = 0; i < 6; i++) {
|
|
const frames = [];
|
|
await bridge.runTurn({ chatId: 'long', message: `SCRIPT:echo round${i} ${big}`, workspacePath: ws, mode: 'bypass', onFrame: f => frames.push(f) });
|
|
replies.push(frames.filter(f => f.type === 'delta' && !f.noteReason).map(f => f.text).join('').slice(0, 12));
|
|
assert.equal(frames.at(-1).type, 'done', `round ${i} ended normally`);
|
|
}
|
|
assert.ok(replies.every(r => /^round\d/.test(r)), 'every round was answered: ' + replies.join(' | '));
|
|
const reqs = worker.requests;
|
|
const summaries = reqs.filter(r => r.summary);
|
|
assert.ok(summaries.length >= 1, 'the Harness asked for a summary of the old history');
|
|
const answers = reqs.filter(r => !r.summary && r.toolNames.length);
|
|
const peak = Math.max(...answers.map(r => r.promptChars));
|
|
assert.ok(peak < 16384 * 4, `no request was bigger than the window (about ${Math.round(peak / 4)} tokens of 16384)`);
|
|
const lastRoundPrompt = answers.at(-1).promptChars;
|
|
assert.ok(lastRoundPrompt < answers[Math.min(4, answers.length - 1)].promptChars + 1, 'the prompt stopped growing');
|
|
});
|