Skip to content

Commit 0b45001

Browse files
jalehmanclaude
andauthored
fix(agents): route CLI bootstrap truncation notice into the system prompt (#130325)
* fix(agents): route CLI bootstrap truncation notice into the system prompt CLI-backed runs appended the detailed bootstrap truncation warning to every turn's wire prompt, which surfaced the warning block inside user chat bubbles on transcript-rendering surfaces. The embedded runner already routes a compact notice through the shared system prompt builder's bootstrapTruncationNotice slot. Route the CLI runner through the same slot and delete the per-turn prompt append plus its context plumbing. Detailed per-file stats still land in the system prompt report for diagnostics. Co-Authored-By: Claude Fable 5 <[email protected]> * fix(agents): drift first-only CLI sessions when truncation state changes Fold bootstrap truncation-notice presence into the CLI session reuse fingerprint, mirroring the existing bootstrapMode hashing. Without this, a systemPromptWhen:"first" backend resuming an existing session never receives the updated system prompt when an AGENTS.md edit crosses the truncation threshold mid-session — a path the removed per-turn body append used to cover. Two-turn regression proves the drift resend. Co-Authored-By: Claude Fable 5 <[email protected]> --------- Co-authored-by: Claude Fable 5 <[email protected]>
1 parent 02a60e0 commit 0b45001

17 files changed

Lines changed: 155 additions & 158 deletions

‎src/agents/bootstrap-budget.test.ts‎

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import { describe, expect, it } from "vitest";
33
import { buildBootstrapPromptWarning } from "./bootstrap-budget-warning.js";
44
import {
5-
appendBootstrapPromptWarning,
65
analyzeBootstrapBudget,
76
buildBootstrapBudgetState,
87
buildBootstrapInjectionStats,
@@ -298,36 +297,6 @@ describe("bootstrap prompt warnings", () => {
298297
expect(lines.join("\n")).toContain("10 raw -> 1 injected");
299298
});
300299

301-
it("appends warning details to the turn prompt instead of mutating the system prompt", () => {
302-
const prompt = appendBootstrapPromptWarning("Please continue.", [
303-
"AGENTS.md: 200 raw -> 0 injected",
304-
]);
305-
expect(prompt.startsWith("Please continue.")).toBe(true);
306-
expect(prompt).toContain("[Bootstrap truncation warning]");
307-
expect(prompt).toContain("Treat Project Context as partial");
308-
expect(prompt).toContain("- AGENTS.md: 200 raw -> 0 injected");
309-
expect(prompt.endsWith("- AGENTS.md: 200 raw -> 0 injected")).toBe(true);
310-
});
311-
312-
it("preserves raw prompt whitespace when appending warning details", () => {
313-
const prompt = appendBootstrapPromptWarning(" indented\nkeep tail ", [
314-
"AGENTS.md: 200 raw -> 0 injected",
315-
]);
316-
317-
expect(prompt).toContain(" indented\nkeep tail ");
318-
expect(prompt.indexOf(" indented\nkeep tail ")).toBe(0);
319-
});
320-
321-
it("preserves exact heartbeat prompts without warning suffixes", () => {
322-
const heartbeatPrompt = "Follow the scheduled monitor context. If quiet, reply NO_REPLY.";
323-
324-
expect(
325-
appendBootstrapPromptWarning(heartbeatPrompt, ["AGENTS.md: 200 raw -> 0 injected"], {
326-
preserveExactPrompt: heartbeatPrompt,
327-
}),
328-
).toBe(heartbeatPrompt);
329-
});
330-
331300
it("builds a concise agent notice without raw truncation diagnostics", () => {
332301
const notice = buildBootstrapPromptWarningNotice([
333302
"AGENTS.md: 200 raw -> 0 injected",

‎src/agents/bootstrap-budget.ts‎

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -218,30 +218,6 @@ export function buildBootstrapBudgetState(params: {
218218
};
219219
}
220220

221-
/** Appends a detailed truncation warning block to the agent prompt when needed. */
222-
export function appendBootstrapPromptWarning(
223-
prompt: string,
224-
warningLines?: string[],
225-
options?: {
226-
preserveExactPrompt?: string;
227-
},
228-
): string {
229-
const normalizedLines = (warningLines ?? []).map((line) => line.trim()).filter(Boolean);
230-
if (normalizedLines.length === 0) {
231-
return prompt;
232-
}
233-
if (options?.preserveExactPrompt && prompt === options.preserveExactPrompt) {
234-
return prompt;
235-
}
236-
const warningBlock = [
237-
"[Bootstrap truncation warning]",
238-
"Some workspace bootstrap files were truncated before injection.",
239-
"Treat Project Context as partial and read the relevant files directly if details seem missing.",
240-
...normalizedLines.map((line) => `- ${line}`),
241-
].join("\n");
242-
return prompt ? `${prompt}\n\n${warningBlock}` : warningBlock;
243-
}
244-
245221
/** Builds the compact truncation notice mirrored into run metadata. */
246222
export function buildBootstrapPromptWarningNotice(warningLines?: string[]): string | undefined {
247223
const hasWarning = (warningLines ?? []).some((line) => line.trim().length > 0);

‎src/agents/cli-runner.before-agent-reply-cron.test.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ function makeStubContext(params: typeof baseRunParams & { trigger?: string }) {
151151
normalizedModel: params.model,
152152
systemPrompt: "",
153153
systemPromptReport: {},
154-
bootstrapPromptWarningLines: [],
155154
authEpochVersion: 0,
156155
backendResolved: {},
157156
preparedBackend: { backend: { sessionMode: "none" } },

‎src/agents/cli-runner.context-engine.test.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ function buildPreparedContext(contextEngine: ContextEngine): PreparedCliRunConte
131131
systemPrompt: "You are a helpful assistant.",
132132
systemPromptReport: {} as PreparedCliRunContext["systemPromptReport"],
133133
claudeSkillsPluginArgs: [],
134-
bootstrapPromptWarningLines: [],
135134
authEpochVersion: 2,
136135
};
137136
}

‎src/agents/cli-runner.reliability.test.ts‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,6 @@ function buildPreparedContext(params: PreparedContextOverrides = {}): PreparedCl
244244
},
245245
systemPrompt: "You are a helpful assistant.",
246246
systemPromptReport: {} as PreparedCliRunContext["systemPromptReport"],
247-
bootstrapPromptWarningLines: [],
248247
claudeSkillsPluginArgs: [],
249248
...(params?.openClawHistoryPrompt
250249
? { openClawHistoryPrompt: params.openClawHistoryPrompt }
@@ -2446,12 +2445,8 @@ describe("runCliAgent reliability", () => {
24462445
it("returns the assembled CLI prompt in meta for raw trace consumers", async () => {
24472446
supervisorSpawnMock.mockResolvedValueOnce(makeManagedRun({ stdout: "hello from cli" }));
24482447

2449-
const result = await runPreparedCliAgent({
2450-
...buildPreparedContext(),
2451-
bootstrapPromptWarningLines: ["Warning: prompt budget low."],
2452-
});
2448+
const result = await runPreparedCliAgent(buildPreparedContext());
24532449

2454-
expect(result.meta.finalPromptText).toContain("Warning: prompt budget low.");
24552450
expect(result.meta.finalPromptText).toContain("hi");
24562451
expect(result.meta.finalAssistantRawText).toBe("hello from cli");
24572452
const executionTrace = requireRecord(result.meta.executionTrace, "execution trace");
@@ -4366,7 +4361,6 @@ describe("runCliAgent reliability", () => {
43664361
expect(context.systemPrompt).toBe("");
43674362
expect(context.contextEngine).toBeUndefined();
43684363
expect(context.claudeSkillsPluginArgs).toEqual([]);
4369-
expect(context.bootstrapPromptWarningLines).toEqual([]);
43704364
} finally {
43714365
fs.rmSync(dir, { recursive: true, force: true });
43724366
}

‎src/agents/cli-runner.spawn.test.ts‎

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2333,41 +2333,5 @@ describe("runCliAgent spawn path", () => {
23332333
expect(authLog).not.toContain("/tmp/child-gemini-home");
23342334
expect(authLog).not.toContain("sk-openai-child");
23352335
});
2336-
2337-
it("prepends bootstrap warnings to the CLI prompt body", async () => {
2338-
supervisorSpawnMock.mockResolvedValueOnce(
2339-
createManagedRun({
2340-
reason: "exit",
2341-
exitCode: 0,
2342-
exitSignal: null,
2343-
durationMs: 50,
2344-
stdout: "ok",
2345-
stderr: "",
2346-
timedOut: false,
2347-
noOutputTimedOut: false,
2348-
}),
2349-
);
2350-
const context = buildPreparedCliRunContext({
2351-
provider: "codex-cli",
2352-
model: "gpt-5.4",
2353-
});
2354-
context.reusableCliSession = { mode: "reuse", sessionId: "thread-123" };
2355-
context.bootstrapPromptWarningLines = [
2356-
"[Bootstrap truncation warning]",
2357-
"- AGENTS.md: 200 raw -> 20 injected",
2358-
];
2359-
2360-
await executePreparedCliRun(context, "thread-123");
2361-
2362-
const input = mockCallArg(supervisorSpawnMock) as {
2363-
argv?: string[];
2364-
input?: string;
2365-
};
2366-
const promptCarrier = [input.input ?? "", ...(input.argv ?? [])].join("\n");
2367-
2368-
expect(promptCarrier).toContain("[Bootstrap truncation warning]");
2369-
expect(promptCarrier).toContain("- AGENTS.md: 200 raw -> 20 injected");
2370-
expect(promptCarrier).toContain("hi");
2371-
});
23722336
});
23732337
/* oxlint-disable max-lines -- TODO: split this grandfathered oversized file. */

‎src/agents/cli-runner.test-helpers.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,6 @@ export function buildPreparedCliRunContext(
242242
normalizedModel: model,
243243
systemPrompt: overrides.systemPrompt ?? "You are a helpful assistant.",
244244
systemPromptReport: {} as PreparedCliRunContext["systemPromptReport"],
245-
bootstrapPromptWarningLines: [],
246245
authEpochVersion: 2,
247246
claudeSkillsPluginArgs: [],
248247
...(overrides.mcpDeliveryCapture ? { mcpDeliveryCapture: true } : {}),

‎src/agents/cli-runner/execute-events.tool-result-args.test.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ function buildContext(runId: string): PreparedCliRunContext {
4040
normalizedModel: "claude-haiku-4-5",
4141
systemPrompt: "system",
4242
systemPromptReport: {} as PreparedCliRunContext["systemPromptReport"],
43-
bootstrapPromptWarningLines: [],
4443
claudeSkillsPluginArgs: [],
4544
authEpochVersion: 2,
4645
} as PreparedCliRunContext;

‎src/agents/cli-runner/execute.pending-cancellation.test.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ function createRunContext(params: {
9595
systemPrompt: "system",
9696
systemPromptReport: {} as PreparedCliRunContext["systemPromptReport"],
9797
claudeSkillsPluginArgs: [],
98-
bootstrapPromptWarningLines: [],
9998
authEpochVersion: 2,
10099
};
101100
}

‎src/agents/cli-runner/execute.supervisor-capture.test.ts‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ function buildPreparedCliRunContext(params: {
130130
systemPrompt: "system",
131131
systemPromptReport: {} as PreparedCliRunContext["systemPromptReport"],
132132
claudeSkillsPluginArgs: [],
133-
bootstrapPromptWarningLines: [],
134133
authEpochVersion: 2,
135134
};
136135
}
@@ -170,7 +169,6 @@ describe("executePreparedCliRun supervisor output capture", () => {
170169
const context = buildPreparedCliRunContext({ output: "jsonl", provider: "claude-cli" });
171170
context.params.prompt = "/compact";
172171
context.params.controlOperation = "compact";
173-
context.bootstrapPromptWarningLines = ["must not decorate the control command"];
174172
context.backendResolved.textTransforms = { input: [{ from: "/compact", to: "mutated" }] };
175173
context.backendResolved.manualCompaction = {
176174
input: "arg",

0 commit comments

Comments
 (0)