Skip to content

fix: cap aggregate untracked content in review context (#405)#461

Open
ayobamiseun wants to merge 1 commit into
openai:mainfrom
ayobamiseun:fix/405-cap-untracked-aggregate
Open

fix: cap aggregate untracked content in review context (#405)#461
ayobamiseun wants to merge 1 commit into
openai:mainfrom
ayobamiseun:fix/405-cap-untracked-aggregate

Conversation

@ayobamiseun

Copy link
Copy Markdown

Fixes #405

Problem

collectReviewContext bounds the inline diff (256KB) and each untracked file (24KB), but never bounds the total Untracked Files section. The section is also inlined even in the lightweight includeDiff: false path, so the maxInlineDiffBytes heuristic never protects it. With enough untracked files the two independently-bounded sections compose into an unbounded prompt and adversarial-review dies with the opaque model-layer error:

Input exceeds the maximum length of 1048576 characters.

Repro

Repo with 300 untracked text files just under the 24KB per-file cap (mirrors the issue's real case of 309 files):

assembled context
before 7,086,684 chars (6.7x over the 1,048,576 limit → exit 1)
after 271,243 chars (review proceeds)

Fix

New formatUntrackedSection tracks a running byte budget across the untracked entries — default 256KB (DEFAULT_UNTRACKED_TOTAL_MAX_BYTES, matching the existing inline-diff cap), overridable via collectReviewContext(..., { maxUntrackedTotalBytes }). Once the next entry would exceed the budget, it stops inlining and appends a visible notice instead of failing downstream:

(N untracked file(s) omitted: aggregate untracked content exceeds the 262144 byte limit. See the Git Status section for the full file list; inspect the omitted files directly, or commit or gitignore them to narrow the review.)

Nothing becomes silently invisible: the Git Status section (--untracked-files=all) still names every untracked file, and skip markers (directory/binary/oversized) count toward the budget too. This is option 1 of the fixes suggested in the issue.

Tests

collectWorkingTreeContext inlined every untracked file (24KB per-file
cap, no total cap) into the Untracked Files section - in both the
inline-diff and lightweight paths. With enough untracked files the
assembled prompt exceeded Codex's 1,048,576-character input limit and
adversarial-review died with an opaque "Input exceeds the maximum
length" error.

Track a running byte budget (default 256KB, matching the inline diff
cap) across the untracked section. Once the next entry would exceed it,
stop inlining and append a visible notice with the omitted count,
pointing at the Git Status section (which still names every file) and
suggesting how to narrow the review.

Fixes openai#405
@ayobamiseun ayobamiseun requested a review from a team July 9, 2026 17:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

adversarial-review builds an unbounded prompt — large working trees fail with "Input exceeds the maximum length of 1048576 characters"

1 participant