fix: handle prompt-too-long by resetting session and continuing inline directives

This commit is contained in:
Peter Steinberger
2025-12-05 23:01:37 +00:00
parent 3241d81ce5
commit 36b0796976
3 changed files with 76 additions and 11 deletions

View File

@@ -677,18 +677,19 @@ export async function runCommandReply(
}
},
});
const rawStdout = stdout.trim();
const rpcAssistantText = extractRpcAssistantText(stdout);
let mediaFromCommand: string[] | undefined;
const trimmed = stripRpcNoise(rawStdout);
if (stderr?.trim()) {
logVerbose(`Command auto-reply stderr: ${stderr.trim()}`);
}
const rawStdout = stdout.trim();
const rpcAssistantText = extractRpcAssistantText(stdout);
let mediaFromCommand: string[] | undefined;
const trimmed = stripRpcNoise(rawStdout);
if (stderr?.trim()) {
logVerbose(`Command auto-reply stderr: ${stderr.trim()}`);
}
const promptTooLong = rawStdout.includes("prompt is too long");
const logFailure = () => {
const truncate = (s?: string) =>
s ? (s.length > 4000 ? `${s.slice(0, 4000)}` : s) : undefined;
logger.warn(
const logFailure = () => {
const truncate = (s?: string) =>
s ? (s.length > 4000 ? `${s.slice(0, 4000)}` : s) : undefined;
logger.warn(
{
code,
signal,
@@ -702,6 +703,21 @@ export async function runCommandReply(
);
};
if (promptTooLong) {
const text =
"⚠️ Session history is too long. Starting a fresh session — please resend your last message.";
const meta: CommandReplyMeta = {
durationMs: Date.now() - started,
queuedMs,
queuedAhead,
exitCode: code,
signal,
killed,
agentMeta: { extra: { promptTooLong: true } },
};
return { payloads: [{ text }], meta };
}
const parsed = trimmed ? agent.parseOutput(trimmed) : undefined;
// Collect assistant texts and tool results from parseOutput (tau RPC can emit many).