Skip to content

feat(tools): an edit to a Python function lists the project code it reaches - #4535

Merged
kovtcharov-amd merged 2 commits into
amd:mainfrom
kovtcharov:kalin/edit-impact
Oct 1, 2026
Merged

kovtcharov-amd merged 2 commits into
amd:mainfrom
kovtcharov:kalin/edit-impact

Conversation

@kovtcharov

Copy link
Copy Markdown
Contributor

When the agent changed a function's signature or a method, it fixed the place it was looking at and missed the same code elsewhere: a second caller in another folder, or a sibling class defining the same method. Now every Python edit result carries an impact note listing the other callers of a changed signature and the other definitions of an edited method, found by git grep across the checkout. On a 6-task set of hard SWE-bench Verified problems (DeepSeek V4.1 Flash), GAIA solved 5/6 with the note against 2/6 and 3/6 on two runs without it. It solved django-16256, which every earlier run had failed, Claude Code included.

6 hard SWE-bench tasks without (2 runs) with
Solved 2/6, 3/6 5/6
Time 45:10, 1:00:33 1:14:56
Cost (Fireworks meter) $0.52, $0.68 $0.71

The traces show the note doing the work. On matplotlib-24870 it listed tri/_tricontour.py:77 as a caller of the changed signature, and GAIA edited that line three steps later. It is silent for non-Python files, for unparsable code, and outside a git checkout. It adds no text to the system prompt.

Test plan

  • python -m pytest tests/unit/agents/test_edit_impact.py tests/unit/agents/test_file_edit_semantics.py
  • Edit a function's signature in a repo with a caller in another folder; the edit_file result names that caller

…eaches

A signature change now reports the function's callers elsewhere in the
checkout, and a method edit reports the other classes defining that method.
In SWE-bench runs the agent missed a second caller and a sibling manager
because it searched only the folder it was working in.
@github-actions github-actions Bot added tests Test changes agents labels Oct 1, 2026
@github-actions

github-actions Bot commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

Verdict: Approve with suggestions

After a successful Python edit, the result now includes a short list of the other places in the project that call or redefine the changed function. That way the agent stops fixing one caller and missing the rest. The idea is sound and the SWE-bench numbers back it up. Two gaps are worth closing before merge:

  • Relative paths get no note. Two of the three edit tools pass the path through as given. A relative path like lib.py, run from a subfolder of the repo, never finds the repo root, so the note silently doesn't appear. I reproduced this: the same edit gave no note with the relative path and a full caller list with the absolute one.
  • Common names make noisy notes. Changing the signature of __init__ (or any widely used name) fills the note with unrelated hits, such as every super().__init__(...) in the repo. The note then tells the agent to "check each site". The method-sibling search already skips dunders and caps very common names; the caller search should do the same.

Real-world evidence

N/A: no evidence bundle was produced for this run. This changes the content of agent tool results and has no CLI, REST or UI surface. The PR description gives a 6-task SWE-bench comparison and a trace excerpt as behavioral evidence. The verdict rests on static review, plus a local check of the helper against a scratch git repo.

🔍 Technical details

🟡 Relative paths never find the git root (src/gaia/agents/tools/edit_impact.py:52)
edit_python_file and replace_function call edit_impact(Path(file_path), …) with the raw path; only edit_file resolves it first via _resolve_target. Path("lib.py").parents is just [Path(".")], so _project_root never walks above the cwd. Verified: edit_impact(Path("lib.py"), …) from a/b/ of a scratch repo returned None, while Path("lib.py").resolve() returned the caller in a/c.py. Resolve once at the top:

def _project_root(path: Path) -> Optional[Path]:
    path = path.resolve()
    for parent in [path.parent, *path.parents]:

🟡 The caller search has no guard against common names (src/gaia/agents/tools/edit_impact.py:118-123)
other_definitions skips dunders and drops names defined in more than MAX_OTHER_DEFINITIONS places, but signature_changed greps \bname\b with no such guard. An __init__ signature change lists up to 12 unrelated __init__ references (super().__init__, other classes), and the note tells the model to justify each one. That can derail a run. Apply the same dunder skip, and consider a ceiling on uses beyond which only the count is reported.

        name = qualname.rsplit(".", 1)[-1]
        if name.startswith("__"):
            continue

🟢 A crash in the impact pass reports a completed write as failed (file_io_tools.py:702, :1227, :1537)
edit_impact runs after the file is written but inside the tool's try, so any exception it raises becomes {"status": "error"} even though the edit landed. SyntaxError is caught, but ast.parse raises ValueError on null bytes on Python 3.10/3.11 (the supported floor is 3.10), and deeply nested code can raise RecursionError. Catch (ValueError, RecursionError) in _functions and log a warning, so the write status stays truthful.

🟢 Regex portability (edit_impact.py:120, :143)
\b and \s in git grep -E are GNU regex extensions, and BSD/macOS regex builds may not honour them. git grep -w -F -e name for callers, and [[:space:]] for the def pattern, are portable and avoid regex escaping altogether.

🟢 No test through a tool
The unit tests cover edit_impact directly, but nothing asserts that edit_file / replace_function actually put impact in their result. A test like that would also have caught the relative-path gap above.

Strengths

  • The helper says nothing outside its scope: non-Python files, unparsable code and files outside a git checkout all return nothing rather than guessing, and a failed git call is logged instead of swallowed.
  • In edit_file, impact is placed ahead of the diff so it survives result truncation, and it adds no text to the system prompt.
  • The tests use a real git repo and check the real cross-folder case from the motivating trace.

Calling edit_impact() with a relative Path (as edit_python_file and
replace_function do) never found the git root, so the impact note
silently never appeared from a non-repo-root cwd. Resolve the path
before walking parents.

Also skip dunder names in the signature-changed scan, matching the
guard the sibling-method scan already has — an __init__ signature
change was listing every unrelated super().__init__() call in the
project.
@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Oct 1, 2026
Merged via the queue into amd:main with commit f88d364 Oct 1, 2026
37 of 40 checks passed
@kovtcharov-amd
kovtcharov-amd deleted the kalin/edit-impact branch October 1, 2026 16:45
grtninja pushed a commit to grtninja/gaia that referenced this pull request Oct 2, 2026
…PR (amd#4562)

Every open PR fails the Windows and macOS unit-test smoke jobs on code
that is already on main. Those jobs only run on PRs, so main looks green
while each PR inherits two red checks. After this, the smoke jobs only
fail on what a PR actually changed.

- **macOS:** the edit-impact check (amd#4535) found no callers of a changed
function, because macOS `git grep -E` has no `\b` or `\s`. The patterns
now use POSIX classes, so this is a real bug fix for macOS users, not
just a test fix.
- **Windows:** a store test asserted POSIX file mode `0600`. Windows has
no mode bits, and the store's Windows ACL is already tested in the same
file.

## Test plan
- [ ] CI: "Unit Tests (macOS smoke)" passes, including
`tests/unit/agents/test_edit_impact.py`
- [ ] CI: "Unit Tests (Windows smoke)" passes, including
`tests/unit/engineering/test_store.py`
- [x] Locally on Windows: both files pass (25 tests); the new patterns
match `levels(` and `def levels (` and skip `alevels`
- [x] `python util/lint.py --black --isort`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants