diff --git a/src/agents/pi-embedded-helpers.buildbootstrapcontextfiles.e2e.test.ts b/src/agents/pi-embedded-helpers.buildbootstrapcontextfiles.e2e.test.ts index 64203efd8fe..9cd60cb59e0 100644 --- a/src/agents/pi-embedded-helpers.buildbootstrapcontextfiles.e2e.test.ts +++ b/src/agents/pi-embedded-helpers.buildbootstrapcontextfiles.e2e.test.ts @@ -89,4 +89,14 @@ describe("buildBootstrapContextFiles", () => { }); expect(result).toEqual([]); }); + + it("keeps missing markers under small total budgets", () => { + const files = [makeFile({ missing: true, content: undefined })]; + const result = buildBootstrapContextFiles(files, { + totalMaxChars: 20, + }); + expect(result).toHaveLength(1); + expect(result[0]?.content.length).toBeLessThanOrEqual(20); + expect(result[0]?.content.startsWith("[MISSING]")).toBe(true); + }); }); diff --git a/src/agents/pi-embedded-helpers/bootstrap.ts b/src/agents/pi-embedded-helpers/bootstrap.ts index b2abbed7b4a..677c474b53d 100644 --- a/src/agents/pi-embedded-helpers/bootstrap.ts +++ b/src/agents/pi-embedded-helpers/bootstrap.ts @@ -198,12 +198,6 @@ export function buildBootstrapContextFiles( if (remainingTotalChars <= 0) { break; } - if (remainingTotalChars < MIN_BOOTSTRAP_FILE_BUDGET_CHARS) { - opts?.warn?.( - `remaining bootstrap budget is ${remainingTotalChars} chars (<${MIN_BOOTSTRAP_FILE_BUDGET_CHARS}); skipping additional bootstrap files`, - ); - break; - } if (file.missing) { const missingText = `[MISSING] Expected at: ${file.path}`; const cappedMissingText = clampToBudget(missingText, remainingTotalChars); @@ -217,6 +211,12 @@ export function buildBootstrapContextFiles( }); continue; } + if (remainingTotalChars < MIN_BOOTSTRAP_FILE_BUDGET_CHARS) { + opts?.warn?.( + `remaining bootstrap budget is ${remainingTotalChars} chars (<${MIN_BOOTSTRAP_FILE_BUDGET_CHARS}); skipping additional bootstrap files`, + ); + break; + } const fileMaxChars = Math.max(1, Math.min(maxChars, remainingTotalChars)); const trimmed = trimBootstrapContent(file.content ?? "", file.name, fileMaxChars); const contentWithinBudget = clampToBudget(trimmed.content, remainingTotalChars);