fix(strands-command): inline full PR diffs within a total budget#63
Open
yonib05 wants to merge 3 commits into
Open
fix(strands-command): inline full PR diffs within a total budget#63yonib05 wants to merge 3 commits into
yonib05 wants to merge 3 commits into
Conversation
get_pr_files capped every file's patch at 50 lines, so the reviewer silently lost the tail of any larger change and reasoned about code it never saw. Replace the per-file line cap with a total character budget: inline full patches until the budget is reached, then list remaining files for on-demand fetch instead of truncating mid-file.
…ping it A file whose patch alone exceeds the budget previously produced no inline diff at all, leaving the reviewer dependent on fetching it. Inline a line-trimmed head slice when enough budget remains so there is always some inline signal, and note the omitted remainder is fetchable. Adds tests for the partial-head and mixed inline/overflow cases.
Guard the partial-head branch so a patch starting with a newline (whose line-boundary trim leaves an empty head) is fully deferred instead of emitting an empty "Diff (head only):" block. Add tests covering the full-deferral branch, the exact budget boundary, and the empty-head edge, merge the two near-duplicate over-budget tests, and note the accepted file-order dependence of the diff budget.
This was referenced Jun 15, 2026
zastrowm
reviewed
Jun 19, 2026
| if head: | ||
| used += len(head) | ||
| omitted = len(patch) - len(head) | ||
| overflow.append(f"{filename} (+{additions} -{deletions}, partially shown)") |
Member
There was a problem hiding this comment.
Can we write the overflow to disk and let the agent know where it is?
|
|
||
| @tool | ||
| @log_inputs | ||
| def get_pr_files(pr_number: int, repo: str | None = None) -> str: |
Member
There was a problem hiding this comment.
This is PR output?
Can we just leverage the Strands Tool Offloader here and let it manage the truncation?
Member
Author
There was a problem hiding this comment.
Good call will swap it should simplify alot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
get_pr_filescapped every changed file's patch at 50 lines:The reviewer agent then reasons about a partial diff for any non-trivial
change. A bug introduced on line 60 of a changed file is simply invisible
to it, and the agent gets no signal that anything is missing beyond a
terse "truncated" note. This silently caps review quality on exactly the
larger PRs that most need a careful read.
Fix
Replace the blunt per-file line cap with a total diff character budget:
and instruct the agent to fetch them on demand via the shell tool,
rather than cutting a file off mid-diff.
This keeps the original intent (bounding how much diff goes into one
prompt) while ensuring that whatever is inlined is complete, and that
anything omitted is explicitly surfaced instead of hidden.
Tests
tests/test_github_tools.pyexercisesget_pr_filesacross the full budget behavior. Verbatim run output:What each case verifies:
truncatedmarker. This case fails against the old code, confirming the regression it guards.TOTAL_DIFF_BUDGET_CHARSis inlined (guards the<=boundary against off-by-one).Full module suite:
39 passed.Scope note: this is a unit-level fix to the diff-formatting helper. The budget path is deterministic and fully covered above; no live agent run is required to validate it.
Live validation (end-to-end)
Beyond the unit tests, this fix was exercised in a real reviewer run to prove the behavior that the old per-file truncation hid: a bug located past line 50 of a changed file.
Setup (on a fork, so reviewers can inspect everything):
validation/billing.py#L83-L86(test PR: yonib05/devtools#14).get_pr_files(the runner action was pinned to the fork branch carrying the fix). Run: actions/runs/27555498202.Result: the agent read the full diff and identified the bug at lines 83–86 — both the inverted
>= 0guard and the wrong+ fee_centssign — then explained the before/after behavior: review comment.With the pre-fix
get_pr_files, lines 51+ of that file were replaced with a... (truncated, N more lines)marker, so the overdraft logic would have been in the hidden tail and unreachable by the agent. Reading and acting on line 83 confirms the full diff is now inlined.Note: the live run resolved to the agent's implementer (write) mode rather than read-only review, so it committed a fix rather than only commenting — immaterial to what is being validated here (full-diff consumption past line 50). The fork validation scaffolding (branches, test PR #14, workflow) is intentionally left in place for reviewer inspection.