mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 17:50:45 +00:00
fix(cli): cap fresh session reseed size
This commit is contained in:
@@ -329,4 +329,16 @@ describe("buildCliSessionHistoryPrompt", () => {
|
|||||||
}),
|
}),
|
||||||
).toBeUndefined();
|
).toBeUndefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("caps rendered reseed history before adding the next user message", () => {
|
||||||
|
const prompt = buildCliSessionHistoryPrompt({
|
||||||
|
messages: [{ role: "compactionSummary", summary: "x".repeat(100) }],
|
||||||
|
prompt: "current ask must survive",
|
||||||
|
maxHistoryChars: 20,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(prompt).toContain("[OpenClaw reseed history truncated]");
|
||||||
|
expect(prompt).toContain("<next_user_message>\ncurrent ask must survive\n</next_user_message>");
|
||||||
|
expect(prompt).not.toContain("x".repeat(80));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import {
|
|||||||
|
|
||||||
export const MAX_CLI_SESSION_HISTORY_FILE_BYTES = 5 * 1024 * 1024;
|
export const MAX_CLI_SESSION_HISTORY_FILE_BYTES = 5 * 1024 * 1024;
|
||||||
export const MAX_CLI_SESSION_HISTORY_MESSAGES = MAX_AGENT_HOOK_HISTORY_MESSAGES;
|
export const MAX_CLI_SESSION_HISTORY_MESSAGES = MAX_AGENT_HOOK_HISTORY_MESSAGES;
|
||||||
|
export const MAX_CLI_SESSION_RESEED_HISTORY_CHARS = 12 * 1024;
|
||||||
|
|
||||||
type HistoryMessage = {
|
type HistoryMessage = {
|
||||||
role?: unknown;
|
role?: unknown;
|
||||||
@@ -48,8 +49,10 @@ function coerceHistoryText(content: unknown): string {
|
|||||||
export function buildCliSessionHistoryPrompt(params: {
|
export function buildCliSessionHistoryPrompt(params: {
|
||||||
messages: unknown[];
|
messages: unknown[];
|
||||||
prompt: string;
|
prompt: string;
|
||||||
|
maxHistoryChars?: number;
|
||||||
}): string | undefined {
|
}): string | undefined {
|
||||||
const renderedHistory = params.messages
|
const maxHistoryChars = params.maxHistoryChars ?? MAX_CLI_SESSION_RESEED_HISTORY_CHARS;
|
||||||
|
const renderedHistoryRaw = params.messages
|
||||||
.flatMap((message) => {
|
.flatMap((message) => {
|
||||||
if (!message || typeof message !== "object") {
|
if (!message || typeof message !== "object") {
|
||||||
return [];
|
return [];
|
||||||
@@ -74,6 +77,10 @@ export function buildCliSessionHistoryPrompt(params: {
|
|||||||
})
|
})
|
||||||
.join("\n\n")
|
.join("\n\n")
|
||||||
.trim();
|
.trim();
|
||||||
|
const renderedHistory =
|
||||||
|
renderedHistoryRaw.length > maxHistoryChars
|
||||||
|
? `${renderedHistoryRaw.slice(0, maxHistoryChars).trimEnd()}\n[OpenClaw reseed history truncated]`
|
||||||
|
: renderedHistoryRaw;
|
||||||
|
|
||||||
if (!renderedHistory) {
|
if (!renderedHistory) {
|
||||||
return undefined;
|
return undefined;
|
||||||
|
|||||||
Reference in New Issue
Block a user