Skip to content

feat(pilot): show the LLM the relevant parts of large files, not just the head - #4

Merged
Aditya-XR merged 1 commit into
anishmehta24:mainfrom
Aditya-XR:feat/patcher-relevant-windows
Oct 13, 2026
Merged

Aditya-XR merged 1 commit into
anishmehta24:mainfrom
Aditya-XR:feat/patcher-relevant-windows

Conversation

@Aditya-XR

Copy link
Copy Markdown
Collaborator

Problem

The Pilot only ever showed the LLM the top of each file.

  • The Patch Writer read each candidate from line 1 and stopped at 400 lines / 12k chars. The shared 16k-char budget was handed out first come, first served, so a large first file took 12k, the second got about 4k, and files 3 to 5 were usually (omitted — prompt size budget reached).
  • The applier only accepts an edit whose search text 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 matching search. The Reviewer then spends all its attempts and the run ends rejected, whatever the model.
  • The Code Explorer's rerank snippets had the same blind spot: the first 50 lines of each file, usually imports.

Change

New app/agents/_shared/excerpts.py (pure functions, no LLM or network):

  • A file that fits its budget is kept whole, so nothing changes for small files.
  • Otherwise it keeps the file head plus windows around the lines that mention the issue's keywords. Keywords are weighted 1 / (lines containing them), so reset_token outranks user. Each window brings its enclosing def / class / function lines.
  • Each skipped stretch becomes one marker line: ... [lines 120-480 not shown] .... Shown lines are verbatim, so search text copied from an excerpt still matches, including CRLF files (same universal-newline read as the applier).

Patch Writer

  • The 16k budget is split across candidates by Explorer confidence (water-filling), so small files stay whole and large ones share the rest.
  • On a retry, lines named in the previous failure (File "x.py", line N, x.py:N) are shown first, so the model sees the code its SyntaxError points at.
  • The system prompt explains the marker and says never to put it in search.
  • _read_file_for_prompt and _MAX_FILE_LINES are 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. Without keywords it still returns the head of the file.

Before / after

The three end-to-end prompt tests fail on main and pass here:

Test main This PR
Bug at line 901 of a ~35k-char file prompt stops at line 306 def apply_discount and the buggy line are in the prompt; edit applies
Two large files, then a small one small file omitted small file shown whole
Retry after File "big.py", line 1100 line 1100 never shown line 1100 shown

Selecting excerpts takes 23 to 39 ms on a 5,000-line, 170 KB file with a match on every 7th line.

Tests

  • 34 new tests: tests/test_excerpts.py (budgets never exceeded, verbatim lines in place, rare-keyword ranking, enclosing headers, anchors, CRLF) and additions to tests/test_patcher.py and tests/test_explorer_scanner.py.
  • Full suite: 550 passed, 2 skipped (Docker). The 8 failures in tests/test_pilot_api.py also happen on unmodified main without an LLM key (503 from get_llm_router).
  • ruff check is clean on the changed files.

… 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.
Copilot AI balanced review requested due to automatic review settings October 13, 2026 07:27
@vercel

vercel Bot commented Oct 13, 2026

Copy link
Copy Markdown

@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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@Aditya-XR
Aditya-XR merged commit a6782a3 into anishmehta24:main Oct 13, 2026
1 check failed
@Aditya-XR
Aditya-XR deleted the feat/patcher-relevant-windows branch October 13, 2026 09:42
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.

2 participants