Skip to content

fix(tool): name missing paths in file_read_diff not-found error - #1836

Merged
lizhengfeng101 merged 3 commits into
alibaba:mainfrom
fcy222fcy:fix/file-read-diff-name-missing-paths
Nov 2, 2026
Merged

lizhengfeng101 merged 3 commits into
alibaba:mainfrom
fcy222fcy:fix/file-read-diff-name-missing-paths

Conversation

@fcy222fcy

@fcy222fcy fcy222fcy commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Description

During a review, file_read_diff answered with one sentence for every path it could not serve:

Error: diff not found for the requested paths

That sentence is the same whether the path is wrong or the diff simply is not part of the change set, so nothing in it lets the model correct the request. Its only remaining move is to re-read the same file under another spelling.

The message now names the paths it could not serve and lists the paths that do have diffs:

Error: diff not found for: src/db/queries.go
Diffs exist for: src/api/handler.go, src/db/models.go
Use one of those paths, or file_read for a file outside the reviewed set.

The list is capped at 10 paths with (and N more) for the remainder, since it exists to be read in one glance. A call where some paths hit still returns the diffs it found and names only the ones it could not serve; an empty request keeps its own message (Error: no files found).

Scope is the review path. ocr scan hides file_read_diff from the tool definitions (cmd/opencodereview/scan_cmd.go, excludeToolDef), and scan initialization fills the provider with full file contents (internal/scan/agent.go, injectScanContentMap), so a scan run never reaches this message. The message therefore does not try to tell the two modes apart: with no paths in the snapshot it says only that, and points at file_read.

Also adds DiffMap.Paths (sorted, so the message reads the same on every run). Diff is 248 insertions, 0 deletions.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Refactoring (no functional changes)
  • Documentation update
  • CI / Build / Tooling

How Has This Been Tested?

New tests in internal/tool/file_read_diff_missing_test.go and internal/tool/diffmap_test.go cover the wrong-path case, partial hits, the 10-path cap, the unchanged empty-request message, an empty snapshot (asserting the message names no mode), and snapshot replacement.

I verified the tests fail without the fix rather than passing vacuously. Forcing notFoundMessage back to the previous single-sentence behaviour and re-running:

--- FAIL: TestFileReadDiffNamesMissingPathAndAvailablePaths (0.00s)
    file_read_diff_missing_test.go:36: message should name the path it could not serve: "Error: diff not found for the requested paths"
    file_read_diff_missing_test.go:39: message should name a path that does have a diff: "Error: diff not found for the requested paths"
--- FAIL: TestFileReadDiffReportsPartialHits (0.00s)
    file_read_diff_missing_test.go:63: the missing path should be named: "==== FILE: a.go ====\n@@ -1 +1 @@\n-old\n+new\n\nError: diff not found for the requested paths"
--- FAIL: TestFileReadDiffCapsAvailablePathList (0.00s)
    file_read_diff_missing_test.go:83: the paths beyond the cap should be counted: "Error: diff not found for the requested paths"

With the fix restored, all of them pass, including the pre-existing TestFileReadDiffProvider_Execute cases (single path, multiple paths, missing path, empty and nil path_array), which are unchanged.

Full suite: go test ./internal/... ./cmd/... -- 25 packages OK, 0 failures. go build ./..., go vet ./internal/tool/, gofmt -l on the changed files, scripts/verify-license.sh and scripts/verify-english-only.go (796 files) all pass.

  • make test passes locally
  • Manual testing (describe below)

No manual run against a live LLM provider: the change is confined to the string the tool returns for paths it cannot serve, which the unit tests cover directly. The "model re-spells the path" symptom that motivates the change comes from reading the code path, not from a captured review transcript -- if evidence from a real run is wanted before this lands, say so.

Checklist

  • My code follows the project's coding style (go fmt, go vet)
  • I have performed a self-review of my code
  • I have added tests that prove my fix is effective or my feature works
  • New and existing unit tests pass locally with my changes
  • I have updated the documentation accordingly (if applicable)
  • I have signed the CLA
  • I did not use AI/LLM to create this PR, or I disclosed the tool/model below and reviewed its output; I did not attribute commits to AI and will answer maintainer questions and review comments myself without AI/LLM.

AI disclosure: This PR was produced with AI/LLM assistance (WorkBuddy agent, Claude model). I reviewed every line myself, verified the red/green behaviour above by hand, and will answer maintainer questions and review comments from my own understanding. No commits are attributed to AI.

Related Issues

None. I found this by reading how file_read_diff answers a path that is not in the change set; I did not see an open issue covering it.

@CLAassistant

CLAassistant commented Oct 27, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@github-actions

Copy link
Copy Markdown
Contributor

✅ OpenCodeReview: Review complete: 0 finding(s) across 1 selected item(s).

@chaojixinren

Copy link
Copy Markdown
Contributor

The scan scenario described here doesn’t match the current implementation. The scan entry point already excludes file_read_diff from the tools exposed to the model. Scan initialization also calls injectScanContentMap() to populate the provider with full file contents, so even an accidental call for a scanned file would return its contents.

The empty-map test bypasses that initialization, so it doesn’t reproduce the reported scan issue. This leaves the scan-specific rationale unsupported. Improving missing-path feedback during ordinary reviews could still be useful, but please scope the change around that behavior and remove the scan claims and assumptions that contradict the existing implementation.

During a review, `file_read_diff` answers with one sentence for every path it
cannot serve:

    Error: diff not found for the requested paths

That sentence is the same whether the path is wrong or the diff simply is not
part of the change set, so nothing in it lets the model correct the request.
Its only remaining move is to re-read the same file under another spelling, and
nothing in the tool output can stop that.

The message now names the paths it could not serve and lists the paths that do
have diffs, so the model can pick one instead of guessing again:

    Error: diff not found for: src/db/queries.go
    Diffs exist for: src/api/handler.go, src/db/models.go
    Use one of those paths, or file_read for a file outside the reviewed set.

The list is capped at 10 paths with a count for the rest, since it exists to be
read in one glance. A call where some paths hit still returns the diffs it
found and names only the ones it could not serve, and an empty request keeps
its own message (`Error: no files found`).

Scope is the review path. `ocr scan` hides `file_read_diff` from the tool
definitions (`cmd/opencodereview/scan_cmd.go`) and scan initialization fills
the provider with full file contents (`internal/scan/agent.go`,
`injectScanContentMap`), so a scan run never reaches this message and the
message does not try to tell the two modes apart: when the snapshot holds no
paths it says only that, and offers `file_read`.

Adds `DiffMap.Paths` (sorted, so the message reads the same on every run) and
tests for a wrong path, partial hits, the list cap, the unchanged empty-request
message, an empty snapshot, and snapshot replacement.
@fcy222fcy
fcy222fcy force-pushed the fix/file-read-diff-name-missing-paths branch from 92d4132 to 4a9ee87 Compare October 28, 2026 14:43
@fcy222fcy

Copy link
Copy Markdown
Contributor Author

You're right on all three points. I re-checked them in the tree instead of relying on my earlier reading:

  • cmd/opencodereview/scan_cmd.go:196-199 strips file_read_diff from MainToolDefs for scan (excludeToolDef, shared.go:349), so the tool is not offered there.
  • internal/scan/agent.go:331 calls injectScanContentMap() right after Enumerate, and that fills this provider's DiffMap with full file contents for every enumerated path (agent.go:413-430). A call for a scanned file returns the file, not an error. scan_template.json never names file_read_diff either, so nothing in the scan prompt leads there.
  • So TestFileReadDiffExplainsEmptySnapshot only exercised a state I built by hand. Len() == 0 is unreachable in scan (contents are injected before any round) and in review (agent.go:355 returns before dispatch when the change set is empty).

Rescoped to the review path only:

  • The message names the paths it could not serve and lists the paths that do have diffs, capped at 10 with (and N more) for the rest. That is the case where the model can actually correct itself.
  • No mode is inferred. With an empty snapshot the message says only that there are no diffs and points at file_read; the test asserts no mode is named, so the claim cannot come back quietly.
  • Dropped DiffMap.Len and the DiffMap() accessor — nothing needs them once the message stops branching on mode. The change is now DiffMap.Paths (sorted, so the message is stable) plus the not-found message.
  • Test file renamed to file_read_diff_missing_test.go and rebuilt around the review case: wrong path, partial hits, list cap, unchanged empty request, snapshot replacement.

Red/green re-run on the rescoped tests: forcing notFoundMessage back to the single sentence fails three of them (should name the path it could not serve, should name a path that does have a diff, the paths beyond the cap should be counted), and they pass with the fix. go test ./internal/... ./cmd/... is 25 packages OK; go build ./..., go vet ./internal/tool/, gofmt, verify-license.sh and verify-english-only.go (796 files) are clean.

To be explicit about what I did not verify: the "model re-reads the same file under different spellings" symptom comes from reading the code path, not from a captured review transcript — I have not run this against a live provider. If you'd rather see evidence from a real run before this lands, I'm happy to park it; the diff is small.

@chaojixinren

Copy link
Copy Markdown
Contributor

I reviewed the latest revision with open-code-review (ocr), using deepseek-flash, and checked the findings against the code and tests. The updated scope makes sense. There are a few remaining documentation and test coverage gaps:

  1. The tool documentation still describes the old behavior.
    All five translations of tools.md say missing paths are silently omitted and document the old generic error. These should reflect the new missing-path messages, available-path list, and file_read guidance.

  2. The tests do not ensure that successful paths stay out of the missing-path message.
    TestFileReadDiffReportsPartialHits only checks for the a.go header and the presence of b.go. I verified with a temporary Go overlay that incorrectly adding successful paths to the missing list still leaves the entire tool package’s tests passing. Please assert that only missing paths appear in the error, that successful diff content is preserved, and that an all-successful request produces no missing-path message.

  3. The file_read guidance is not asserted.
    I also verified that removing both guidance messages leaves the tool package’s tests passing. Since helping the model recover is part of this change, both the empty and non-empty snapshot cases should explicitly require that guidance.

The full make test suite passed, including race detection. I did not find a functional defect in the current implementation; these changes would bring the documentation into sync and make the regression tests more effective.

Review feedback on alibaba#1836: the tests did not fail if a served path was
reported as missing or if the file_read guidance was dropped, and the
tools.md translations still described the old behaviour.

- TestFileReadDiffReportsPartialHits now asserts the error line names
  exactly the missing paths and that the served diff is returned in
  full, not just its header.
- New TestFileReadDiffAllPathsFoundHasNoError: a fully served request
  carries no error line at all.
- The file_read guidance is asserted in both cases: the non-empty
  snapshot message must tell the model how to reach a file outside the
  change set, and the empty-snapshot message must name file_read.
- All five translations of tools.md now describe the missing-path
  message, the available-path list, and the file_read guidance instead
  of "silently omitted" plus the old generic error.

Verified the new assertions bite: re-introducing either behaviour the
reviewer demonstrated (served paths in the missing list, guidance
removed) turns four tests red; with the current implementation all of
internal/tool passes. Full suite: 25 packages OK. -race was not run
locally (no cgo toolchain on this machine); the reviewer already ran
the full suite with race detection successfully.
@fcy222fcy

Copy link
Copy Markdown
Contributor Author

All three points are addressed in ec17692.

  1. tools.md — all five translations now describe the missing-path message, the available-path list, and the file_read guidance, replacing "silently omitted" and the old generic error.

  2. Served paths can no longer leak into the missing list. TestFileReadDiffReportsPartialHits now asserts the error line is exactly Error: diff not found for: b.go (served a.go excluded) and that the served diff is returned in full, not just its header. A new TestFileReadDiffAllPathsFoundHasNoError asserts a fully served request carries no error line at all.

  3. The file_read guidance is asserted in both cases — the non-empty snapshot message must end with file_read for a file outside the reviewed set, and the empty-snapshot message must name file_read.

I re-did your overlay check as a regression step: re-introducing both behaviours you demonstrated (served paths appended to the missing list, both guidance lines removed) turns four tests red; with the current implementation internal/tool passes and the full suite is 25 packages OK. -race I could not run locally (no cgo toolchain on this machine) — your make test with race detection stands as the race-clean reference.

@chaojixinren chaojixinren left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@lizhengfeng101 lizhengfeng101 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@lizhengfeng101
lizhengfeng101 merged commit 76ab46a into alibaba:main Nov 2, 2026
15 checks passed
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.

4 participants