Repository navigation
feat(pilot): show the LLM the relevant parts of large files, not just the head - #4
Merged
Aditya-XR merged 1 commit intoOct 13, 2026
Conversation
… the head The Patch Writer read each candidate file from line 1 and stopped at 400 lines / 12k chars, with a 16k-char budget handed out first come, first served. Code below the cut never reached the prompt, so a fix there could not be written as an exact `search` string and the Pilot spent its attempts for nothing. Files after a large one were often omitted entirely. The Code Explorer's rerank snippets had the same blind spot (first 50 lines only). Add app/agents/_shared/excerpts.py. A file that fits is kept whole. Otherwise it keeps the file head plus windows around the lines that mention the issue's keywords (rarer keywords rank higher) and their enclosing def/class lines, and each skipped stretch becomes one `... [lines a-b not shown] ...` marker. Shown lines are verbatim, so search text copied from an excerpt still matches the file. Patch Writer: split the 16k budget across candidates by confidence (water-filling, so small files stay whole), excerpt large files, and on a retry put the lines the previous failure points at (`File "x.py", line N`, `x.py:N`) first. The system prompt explains the markers. Code Explorer: snippets use the same excerpts within the same 50-line budget. Tests: 34 new. The three end-to-end prompt tests fail on main.
|
@Aditya-XR is attempting to deploy a commit to the Anish Mehta's projects Team on Vercel. A member of the Team first needs to authorize it. |
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
The Pilot only ever showed the LLM the top of each file.
(omitted — prompt size budget reached).searchtext matches the file exactly. If the bug sits below the cut (say line 900 of a 1,000-line file), the LLM never sees it and can't write a matchingsearch. The Reviewer then spends all its attempts and the run endsrejected, whatever the model.Change
New
app/agents/_shared/excerpts.py(pure functions, no LLM or network):reset_tokenoutranksuser. Each window brings its enclosingdef/class/functionlines.... [lines 120-480 not shown] .... Shown lines are verbatim, sosearchtext copied from an excerpt still matches, including CRLF files (same universal-newline read as the applier).Patch Writer
File "x.py", line N,x.py:N) are shown first, so the model sees the code its SyntaxError points at.search._read_file_for_promptand_MAX_FILE_LINESare removed. The char budgets (_MAX_FILE_CHARS,_MAX_TOTAL_FILE_CHARS) are unchanged, so prompt size and free-tier TPM limits are unaffected.Code Explorer:
read_snippet(..., keywords=...)builds the same kind of excerpt within the same 50-line budget. Withoutkeywordsit still returns the head of the file.Before / after
The three end-to-end prompt tests fail on
mainand pass here:maindef apply_discountand the buggy line are in the prompt; edit appliesomittedFile "big.py", line 1100Selecting excerpts takes 23 to 39 ms on a 5,000-line, 170 KB file with a match on every 7th line.
Tests
tests/test_excerpts.py(budgets never exceeded, verbatim lines in place, rare-keyword ranking, enclosing headers, anchors, CRLF) and additions totests/test_patcher.pyandtests/test_explorer_scanner.py.tests/test_pilot_api.pyalso happen on unmodifiedmainwithout an LLM key (503 fromget_llm_router).ruff checkis clean on the changed files.