mirror of
https://github.com/headroomlabs-ai/headroom.git
synced 2026-11-22 13:29:19 +08:00
fix(plugins/openclaw): keep compression system-prompt notice cache-stable (#3811)
## Description `HeadroomContextEngine.assemble()` in the OpenClaw plugin returns a `systemPromptAddition` string that OpenClaw prepends to the system prompt every turn. It interpolated the per-turn `tokensSaved` count, so the system prompt — the start of the provider's cached prefix — changed on every compressing turn, defeating prompt caching. Reported cost: a turn saving 267 tokens caused a ~93K-token cache miss on Bedrock/Claude Opus 5.5, roughly 4,000x the tokens the compression saved. Refs #3809 ## Type of Change - [x] Bug fix (non-breaking change that fixes an issue) - [ ] New feature (non-breaking change that adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) - [ ] Documentation update - [ ] Performance improvement - [ ] Code refactoring (no functional changes) ## Changes Made - `plugins/openclaw/src/engine.ts`: replaced the interpolated `${result.tokensSaved}` notice with a fixed constant (`HEADROOM_COMPRESSION_NOTICE`), so any turn that includes it is byte-identical to any other. Added a `hasAnnouncedCompression` instance flag so the notice, once shown (tokensSaved > 100), stays present and unchanged on later turns even when a given turn has nothing new to compress - `plugins/openclaw/src/engine.ts`: added `announceCompression` (boolean, default `true`) to `HeadroomEngineConfig` to disable the notice entirely. - `plugins/openclaw/openclaw.plugin.json`: added `announceCompression` to `configSchema.properties` (required — schema has `additionalProperties: false`) and a matching `uiHints` entry. - `plugins/openclaw/README.md`: documented the new option in the configuration table. - `plugins/openclaw/test/engine.test.ts`: 5 new tests, static notice with no interpolated count, byte-identical notices across differing `tokensSaved`, notice staying present on a turn with nothing to compress (the flap-prevention regression case), `announceCompression: false` opt-out, and the existing below-threshold no-op case. ## Testing - [x] Unit tests pass (`pytest`) - [x] Linting passes (`ruff check .`) - [x] Type checking passes (`mypy headroom`) - [x] New tests added for new functionality - [x] Manual testing performed ### Test Output ```text $ npx vitest run test/engine.test.ts RUN v4.1.10 /Users/sarah_ling/Documents/GitHub/headroom/plugins/openclaw Test Files 1 passed (1) Tests 27 passed (27) Start at 18:17:43 Duration 527ms $ npx vitest run Test Files 1 failed | 6 passed (7) Tests 3 failed | 104 passed (107) # The 3 failures are in test/advancement-key-store.test.ts, unrelated to this change ``` ## Real Behavior Proof - Environment: local vitest run against `plugins/openclaw` (mocked `compress()`/proxy — no live OpenClaw host or real Bedrock/Anthropic request). - Exact command / steps: added a temporary test that mocks a 6-turn session mirroring the reported scenario (tokensSaved: 0, 267, 0, 9000, 0, 50) and recorded `assemble()`'s `systemPromptAddition` per turn. - Observed result: notice absent on turn 1, appears static and identical on turns 2–6 (including turns 3/5 with nothing to compress, and turn 6's below-threshold 50-token save) — 1 total transition across 6 turns, versus the old behavior's distinct string on every compressing turn. - Not tested: no live OpenClaw + real provider run to directly observe the Bedrock cache-read/cache-write fields improve, as the original issue's report did. The fix is verified at the unit level (the exact value the plugin hands to OpenClaw), not against a real provider cache. ## Runtime Rollout Safety - Rollout-managed feature(s): None - Minimum rollout channel: N/A - Stable/default behavior changed: yes, the notice text changes (no longer reports a live token count) and stays present for the rest of the session instead of tracking that turn's compression state. Default (`announceCompression` unset) still shows the notice, matching prior default-on behavior. - Kill switch / disable path: set `announceCompression: false` in the plugin config to fully disable the notice. - Unsafe override required: None - Qualification impact: None - Rollback path: Revert this PR ## Review Readiness - [x] I have performed a self-review - [x] This PR is ready for human review ## Checklist - [x] My code follows the project's style guidelines - [x] I have performed a self-review of my code - [x] I have commented my code, particularly in hard-to-understand areas - [x] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [x] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [x] I did **not** edit `CHANGELOG.md` — it is generated by release-please from my Conventional Commit PR title (a CI guard enforces this) <!-- devin-review-badge-begin --> --- <a href="https://app.devin.ai/review/headroomlabs-ai/headroom/pull/3811" target="_blank"><picture><source media="(prefers-color-scheme: dark)" srcset="https://static.devin.ai/assets/gh-devin-review-dark.svg?v=4"><img src="https://static.devin.ai/assets/gh-devin-review-light.svg?v=4" alt="Devin Review"></picture></a> <!-- devin-review-badge-end --> --------- Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com> Co-authored-by: JD Davis <mxjerrett@gmail.com>
This commit is contained in:
co-authored by
Claude Sonnet 5
JD Davis
parent
aba75cbf6d
commit
f8851878a4
@@ -210,6 +210,7 @@ Compression is lossless via CCR (Compress-Cache-Retrieve): originals are stored
|
||||
| `circuitBreakerCooldownMs` | `60000` | How long (ms) the circuit breaker stays open after the threshold is reached. After the cool-down the breaker resets automatically and the next request re-probes the proxy via `/health`. |
|
||||
| `routeCodexViaProxy` | `true` | Rewrite OpenClaw's built-in `openai-codex` provider to use the active Headroom proxy in memory so upstream Codex requests pass through Headroom. |
|
||||
| `gatewayProviderIds` | `[]` | Optional explicit list of OpenClaw provider ids to route through the active Headroom proxy in memory. Friendly aliases `codex`, `claude`, `copilot`, and `gemini` are also accepted. When set, this overrides the default `openai-codex` routing list. |
|
||||
| `announceCompression` | `true` | Adds a static, cache-stable notice to the system prompt the first time a session compresses more than 100 tokens, then keeps it unchanged for the rest of the session. Set to `false` to guarantee Headroom never modifies the system prompt. |
|
||||
|
||||
## Comparison with lossless-claw
|
||||
|
||||
|
||||
@@ -41,6 +41,10 @@
|
||||
"gatewayProviderIds": {
|
||||
"label": "Gateway Provider IDs",
|
||||
"help": "Optional list of OpenClaw provider ids to route through the active Headroom proxy in memory. Friendly aliases codex, claude, copilot, and gemini are also accepted. When set, this overrides the default openai-codex-only routing."
|
||||
},
|
||||
"announceCompression": {
|
||||
"label": "Announce Compression In System Prompt",
|
||||
"help": "When enabled, a static, cache-stable notice is added to the system prompt the first time a session compresses more than 100 tokens. Disable to guarantee the plugin never modifies the system prompt."
|
||||
}
|
||||
},
|
||||
"configSchema": {
|
||||
@@ -106,6 +110,10 @@
|
||||
"type": "string"
|
||||
},
|
||||
"default": []
|
||||
},
|
||||
"announceCompression": {
|
||||
"type": "boolean",
|
||||
"default": true
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -28,6 +28,10 @@ function withTimeout<T>(promise: Promise<T>, ms: number): Promise<T> {
|
||||
});
|
||||
}
|
||||
|
||||
// Must stay static — OpenClaw prepends it to the cached system prompt.
|
||||
const HEADROOM_COMPRESSION_NOTICE =
|
||||
"[Headroom is compressing tool outputs in this session. Use headroom_retrieve if you need the original, uncompressed content.]";
|
||||
|
||||
export interface HeadroomEngineConfig extends ProxyManagerConfig {
|
||||
enabled?: boolean;
|
||||
requestTimeoutMs?: number;
|
||||
@@ -36,6 +40,7 @@ export interface HeadroomEngineConfig extends ProxyManagerConfig {
|
||||
/** Where to durably record committed turn-advancement keys (see
|
||||
* `DurableAdvancementKeyStore`). Defaults to `defaultCommitLogPath()`. */
|
||||
commitLogPath?: string;
|
||||
announceCompression?: boolean;
|
||||
}
|
||||
|
||||
export class HeadroomContextEngine {
|
||||
@@ -69,6 +74,10 @@ export class HeadroomContextEngine {
|
||||
compactions: 0,
|
||||
};
|
||||
private circuit = { errors: 0, openUntilMs: 0 };
|
||||
// Sessions shown the compression notice. Bounded via insertion-order
|
||||
// eviction — no session lifecycle callback exists here to bound it otherwise.
|
||||
private announcedSessions = new Set<string>();
|
||||
private static readonly MAX_ANNOUNCED_SESSIONS = 1000;
|
||||
|
||||
constructor(config: HeadroomEngineConfig = {}, logger?: ProxyManagerLogger) {
|
||||
this.config = config;
|
||||
@@ -132,12 +141,20 @@ export class HeadroomContextEngine {
|
||||
if (!this.proxyUrl || this.config.enabled === false) {
|
||||
this.ensureProxyStarted();
|
||||
// Fallback: return messages unchanged
|
||||
return { messages: normalizeAgentMessages(params.messages), estimatedTokens: 0 };
|
||||
return {
|
||||
messages: normalizeAgentMessages(params.messages),
|
||||
estimatedTokens: 0,
|
||||
systemPromptAddition: this.sessionCompressionNotice(params.sessionId),
|
||||
};
|
||||
}
|
||||
|
||||
if (this.isCircuitOpen()) {
|
||||
this.logger.warn("[headroom] Circuit open — using uncompressed messages");
|
||||
return { messages: normalizeAgentMessages(params.messages), estimatedTokens: 0 };
|
||||
return {
|
||||
messages: normalizeAgentMessages(params.messages),
|
||||
estimatedTokens: 0,
|
||||
systemPromptAddition: this.sessionCompressionNotice(params.sessionId),
|
||||
};
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -155,11 +172,19 @@ export class HeadroomContextEngine {
|
||||
this.config.requestTimeoutMs ?? 30_000,
|
||||
);
|
||||
|
||||
const shouldAnnounceCompression =
|
||||
(this.hasAnnouncedCompression(params.sessionId) || result.tokensSaved > 100) &&
|
||||
this.config.announceCompression !== false;
|
||||
if (shouldAnnounceCompression) {
|
||||
this.markCompressionAnnounced(params.sessionId);
|
||||
}
|
||||
|
||||
if (!result.compressed || result.tokensSaved === 0) {
|
||||
this.resetCircuit();
|
||||
return {
|
||||
messages: normalizeAgentMessages(params.messages),
|
||||
estimatedTokens: result.tokensBefore,
|
||||
systemPromptAddition: this.sessionCompressionNotice(params.sessionId),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -179,16 +204,17 @@ export class HeadroomContextEngine {
|
||||
return {
|
||||
messages: compressedAgentMessages,
|
||||
estimatedTokens: result.tokensAfter,
|
||||
systemPromptAddition:
|
||||
result.tokensSaved > 100
|
||||
? `[Context compressed by Headroom: ${result.tokensSaved} tokens saved. Use headroom_retrieve with the hash to get full details.]`
|
||||
: undefined,
|
||||
systemPromptAddition: this.sessionCompressionNotice(params.sessionId),
|
||||
};
|
||||
} catch (error) {
|
||||
this.logger.error(`Assemble failed: ${error}`);
|
||||
this.tripCircuit(error);
|
||||
// Graceful fallback: return original messages
|
||||
return { messages: normalizeAgentMessages(params.messages), estimatedTokens: 0 };
|
||||
return {
|
||||
messages: normalizeAgentMessages(params.messages),
|
||||
estimatedTokens: 0,
|
||||
systemPromptAddition: this.sessionCompressionNotice(params.sessionId),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -295,6 +321,26 @@ export class HeadroomContextEngine {
|
||||
this.circuit = { errors: 0, openUntilMs: 0 };
|
||||
}
|
||||
|
||||
private hasAnnouncedCompression(sessionId: string): boolean {
|
||||
return this.announcedSessions.has(sessionId);
|
||||
}
|
||||
|
||||
private markCompressionAnnounced(sessionId: string): void {
|
||||
if (this.announcedSessions.has(sessionId)) return;
|
||||
if (this.announcedSessions.size >= HeadroomContextEngine.MAX_ANNOUNCED_SESSIONS) {
|
||||
const oldest = this.announcedSessions.values().next().value;
|
||||
if (oldest !== undefined) this.announcedSessions.delete(oldest);
|
||||
}
|
||||
this.announcedSessions.add(sessionId);
|
||||
}
|
||||
|
||||
/** The sticky notice if this session already earned it and announcements aren't opted out. */
|
||||
private sessionCompressionNotice(sessionId: string): string | undefined {
|
||||
return this.hasAnnouncedCompression(sessionId) && this.config.announceCompression !== false
|
||||
? HEADROOM_COMPRESSION_NOTICE
|
||||
: undefined;
|
||||
}
|
||||
|
||||
ensureProxyStarted(): void {
|
||||
if (this.config.enabled === false || this.proxyUrl || this.proxyStartupPromise) {
|
||||
return;
|
||||
|
||||
@@ -33,7 +33,7 @@ vi.mock("../src/proxy-manager.js", () => ({
|
||||
defaultLogger: mocked.logger,
|
||||
}));
|
||||
|
||||
import { HeadroomContextEngine } from "../src/engine.js";
|
||||
import { HeadroomContextEngine, type HeadroomEngineConfig } from "../src/engine.js";
|
||||
import { compress } from "headroom-ai";
|
||||
|
||||
afterEach(() => {
|
||||
@@ -428,3 +428,207 @@ describe("HeadroomContextEngine transcriptSemantics contract", () => {
|
||||
expect(entries["turn-1"].messages).toEqual(messages);
|
||||
});
|
||||
});
|
||||
|
||||
describe("HeadroomContextEngine assemble() compression notice", () => {
|
||||
const HEADROOM_COMPRESSION_NOTICE =
|
||||
"[Headroom is compressing tool outputs in this session. Use headroom_retrieve if you need the original, uncompressed content.]";
|
||||
const messages = [{ role: "user", content: "hello" }];
|
||||
|
||||
function mockCompressResult(overrides: Partial<{
|
||||
compressed: boolean;
|
||||
tokensSaved: number;
|
||||
tokensBefore: number;
|
||||
tokensAfter: number;
|
||||
}>) {
|
||||
const tokensSaved = overrides.tokensSaved ?? 0;
|
||||
return {
|
||||
compressed: overrides.compressed ?? tokensSaved > 0,
|
||||
messages: [{ role: "user", content: "hello" }],
|
||||
tokensBefore: overrides.tokensBefore ?? 1000,
|
||||
tokensAfter: overrides.tokensAfter ?? 1000 - tokensSaved,
|
||||
tokensSaved,
|
||||
};
|
||||
}
|
||||
|
||||
function readyEngine(config?: HeadroomEngineConfig) {
|
||||
const engine = new HeadroomContextEngine(config);
|
||||
(engine as unknown as { proxyUrl: string | null }).proxyUrl = "http://127.0.0.1:8787";
|
||||
return engine;
|
||||
}
|
||||
|
||||
it("returns the static notice, with no interpolated count, once tokensSaved crosses the threshold", async () => {
|
||||
vi.mocked(compress).mockResolvedValueOnce(mockCompressResult({ tokensSaved: 150 }));
|
||||
|
||||
const engine = readyEngine();
|
||||
const result = await engine.assemble({ sessionId: "s1", messages });
|
||||
|
||||
expect(result.systemPromptAddition).toBe(HEADROOM_COMPRESSION_NOTICE);
|
||||
});
|
||||
|
||||
it("returns byte-identical notices across turns with different tokensSaved amounts", async () => {
|
||||
vi.mocked(compress)
|
||||
.mockResolvedValueOnce(mockCompressResult({ tokensSaved: 150 }))
|
||||
.mockResolvedValueOnce(mockCompressResult({ tokensSaved: 9000 }));
|
||||
|
||||
const engine = readyEngine();
|
||||
const first = await engine.assemble({ sessionId: "s1", messages });
|
||||
const second = await engine.assemble({ sessionId: "s1", messages });
|
||||
|
||||
expect(first.systemPromptAddition).toBe(HEADROOM_COMPRESSION_NOTICE);
|
||||
expect(second.systemPromptAddition).toBe(first.systemPromptAddition);
|
||||
});
|
||||
|
||||
it("keeps the notice present on a later turn that has nothing to compress", async () => {
|
||||
vi.mocked(compress)
|
||||
.mockResolvedValueOnce(mockCompressResult({ tokensSaved: 150 }))
|
||||
.mockResolvedValueOnce(mockCompressResult({ compressed: false, tokensSaved: 0 }));
|
||||
|
||||
const engine = readyEngine();
|
||||
const first = await engine.assemble({ sessionId: "s1", messages });
|
||||
const second = await engine.assemble({ sessionId: "s1", messages });
|
||||
|
||||
expect(first.systemPromptAddition).toBe(HEADROOM_COMPRESSION_NOTICE);
|
||||
expect(second.systemPromptAddition).toBe(HEADROOM_COMPRESSION_NOTICE);
|
||||
});
|
||||
|
||||
it("never returns a notice when announceCompression is false", async () => {
|
||||
vi.mocked(compress).mockResolvedValueOnce(mockCompressResult({ tokensSaved: 500 }));
|
||||
|
||||
const engine = readyEngine({ announceCompression: false });
|
||||
const result = await engine.assemble({ sessionId: "s1", messages });
|
||||
|
||||
expect(result.systemPromptAddition).toBeUndefined();
|
||||
});
|
||||
|
||||
it("does not announce for compression below the noise threshold", async () => {
|
||||
vi.mocked(compress).mockResolvedValueOnce(mockCompressResult({ tokensSaved: 50 }));
|
||||
|
||||
const engine = readyEngine();
|
||||
const result = await engine.assemble({ sessionId: "s1", messages });
|
||||
|
||||
expect(result.systemPromptAddition).toBeUndefined();
|
||||
});
|
||||
|
||||
it("does not leak a session's announcement to a different session on the same engine", async () => {
|
||||
vi.mocked(compress)
|
||||
.mockResolvedValueOnce(mockCompressResult({ tokensSaved: 150 }))
|
||||
.mockResolvedValueOnce(mockCompressResult({ compressed: false, tokensSaved: 0 }));
|
||||
|
||||
const engine = readyEngine();
|
||||
const sessionA = await engine.assemble({ sessionId: "a", messages });
|
||||
const sessionB = await engine.assemble({ sessionId: "b", messages });
|
||||
|
||||
expect(sessionA.systemPromptAddition).toBe(HEADROOM_COMPRESSION_NOTICE);
|
||||
expect(sessionB.systemPromptAddition).toBeUndefined();
|
||||
});
|
||||
|
||||
it("keeps announcing for the session that earned the notice even after another session is seen", async () => {
|
||||
vi.mocked(compress)
|
||||
.mockResolvedValueOnce(mockCompressResult({ tokensSaved: 150 }))
|
||||
.mockResolvedValueOnce(mockCompressResult({ compressed: false, tokensSaved: 0 }))
|
||||
.mockResolvedValueOnce(mockCompressResult({ compressed: false, tokensSaved: 0 }));
|
||||
|
||||
const engine = readyEngine();
|
||||
await engine.assemble({ sessionId: "a", messages });
|
||||
await engine.assemble({ sessionId: "b", messages });
|
||||
const sessionAAgain = await engine.assemble({ sessionId: "a", messages });
|
||||
|
||||
expect(sessionAAgain.systemPromptAddition).toBe(HEADROOM_COMPRESSION_NOTICE);
|
||||
});
|
||||
|
||||
it("evicts the oldest tracked session once the announced-session bound is exceeded", async () => {
|
||||
vi.mocked(compress).mockResolvedValue(mockCompressResult({ tokensSaved: 150 }));
|
||||
|
||||
const engine = readyEngine();
|
||||
for (let i = 0; i < 1000; i++) {
|
||||
await engine.assemble({ sessionId: `session-${i}`, messages });
|
||||
}
|
||||
const overflow = await engine.assemble({ sessionId: "session-overflow", messages });
|
||||
|
||||
vi.mocked(compress).mockResolvedValueOnce(mockCompressResult({ compressed: false, tokensSaved: 0 }));
|
||||
const oldest = await engine.assemble({ sessionId: "session-0", messages });
|
||||
vi.mocked(compress).mockResolvedValueOnce(mockCompressResult({ compressed: false, tokensSaved: 0 }));
|
||||
const newest = await engine.assemble({ sessionId: "session-overflow", messages });
|
||||
|
||||
expect(overflow.systemPromptAddition).toBe(HEADROOM_COMPRESSION_NOTICE);
|
||||
expect(oldest.systemPromptAddition).toBeUndefined();
|
||||
expect(newest.systemPromptAddition).toBe(HEADROOM_COMPRESSION_NOTICE);
|
||||
});
|
||||
|
||||
it("keeps the earned notice byte-identical through a timeout, a circuit-open turn, and recovery", async () => {
|
||||
vi.useFakeTimers();
|
||||
try {
|
||||
const requestTimeoutMs = 5_000;
|
||||
const circuitBreakerCooldownMs = 10_000;
|
||||
const engine = readyEngine({
|
||||
requestTimeoutMs,
|
||||
circuitBreakerThreshold: 1,
|
||||
circuitBreakerCooldownMs,
|
||||
});
|
||||
|
||||
vi.mocked(compress).mockResolvedValueOnce(mockCompressResult({ tokensSaved: 150 }));
|
||||
const turn1 = await engine.assemble({ sessionId: "s1", messages });
|
||||
const firstNotice = turn1.systemPromptAddition;
|
||||
expect(firstNotice).toBe(HEADROOM_COMPRESSION_NOTICE);
|
||||
|
||||
vi.mocked(compress).mockImplementationOnce(() => new Promise(() => {}));
|
||||
const turn2Promise = engine.assemble({ sessionId: "s1", messages });
|
||||
await vi.advanceTimersByTimeAsync(requestTimeoutMs);
|
||||
const turn2 = await turn2Promise;
|
||||
expect(turn2.systemPromptAddition).toBe(firstNotice);
|
||||
|
||||
const turn3 = await engine.assemble({ sessionId: "s1", messages });
|
||||
expect(turn3.systemPromptAddition).toBe(firstNotice);
|
||||
expect(compress).toHaveBeenCalledTimes(2);
|
||||
|
||||
await vi.advanceTimersByTimeAsync(circuitBreakerCooldownMs);
|
||||
vi.mocked(compress).mockResolvedValueOnce(mockCompressResult({ compressed: false, tokensSaved: 0 }));
|
||||
const turn4 = await engine.assemble({ sessionId: "s1", messages });
|
||||
expect(turn4.systemPromptAddition).toBe(firstNotice);
|
||||
expect(turn4.systemPromptAddition).toBe(HEADROOM_COMPRESSION_NOTICE);
|
||||
} finally {
|
||||
vi.useRealTimers();
|
||||
}
|
||||
});
|
||||
|
||||
it("preserves an earned notice when the proxy becomes unavailable", async () => {
|
||||
vi.mocked(compress).mockResolvedValueOnce(mockCompressResult({ tokensSaved: 150 }));
|
||||
|
||||
const engine = readyEngine();
|
||||
const first = await engine.assemble({ sessionId: "s1", messages });
|
||||
expect(first.systemPromptAddition).toBe(HEADROOM_COMPRESSION_NOTICE);
|
||||
|
||||
(engine as unknown as { proxyUrl: string | null }).proxyUrl = null;
|
||||
const second = await engine.assemble({ sessionId: "s1", messages });
|
||||
|
||||
expect(second.systemPromptAddition).toBe(HEADROOM_COMPRESSION_NOTICE);
|
||||
});
|
||||
|
||||
it("never surfaces a notice in any fallback path when announceCompression is false", async () => {
|
||||
vi.useFakeTimers();
|
||||
try {
|
||||
const requestTimeoutMs = 5_000;
|
||||
const engine = readyEngine({
|
||||
announceCompression: false,
|
||||
requestTimeoutMs,
|
||||
circuitBreakerThreshold: 1,
|
||||
circuitBreakerCooldownMs: 10_000,
|
||||
});
|
||||
|
||||
vi.mocked(compress).mockResolvedValueOnce(mockCompressResult({ tokensSaved: 150 }));
|
||||
const turn1 = await engine.assemble({ sessionId: "s1", messages });
|
||||
expect(turn1.systemPromptAddition).toBeUndefined();
|
||||
|
||||
vi.mocked(compress).mockImplementationOnce(() => new Promise(() => {}));
|
||||
const turn2Promise = engine.assemble({ sessionId: "s1", messages });
|
||||
await vi.advanceTimersByTimeAsync(requestTimeoutMs);
|
||||
const turn2 = await turn2Promise;
|
||||
expect(turn2.systemPromptAddition).toBeUndefined();
|
||||
|
||||
const turn3 = await engine.assemble({ sessionId: "s1", messages });
|
||||
expect(turn3.systemPromptAddition).toBeUndefined();
|
||||
} finally {
|
||||
vi.useRealTimers();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user