fix(agents): preserve missing markers under tight bootstrap caps

This commit is contained in:
Gustavo Madeira Santana 2026-02-14 18:21:37 -05:00
parent 9931fbeba4
commit 020e635ded
2 changed files with 16 additions and 6 deletions

View File

@ -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);
});
});

View File

@ -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);