fix: resolve model-emitted short path prefixes in tool calls#29
Open
Archelunch wants to merge 2 commits into
Open
fix: resolve model-emitted short path prefixes in tool calls#29Archelunch wants to merge 2 commits into
Archelunch wants to merge 2 commits into
Conversation
b9f505b to
05c3cd6
Compare
The model emits paths prefixed with the last directory component of the workspace (e.g. /myrepo/backend/main.py instead of the full absolute path), causing every Grep, Glob, and Read call to fail the is_relative_to(cwd) permission check. The agent then returns an empty <final_answer> because all citations are filtered out. - add resolve_path() helper that rewrites the short prefix to the full absolute path, with a longest-existing-suffix fallback - apply it in Grep, Glob, Read, and citation validation - Read: return a clear error when the path is a directory - Glob: strip a path prefix from the pattern argument - add tests/test_path_resolution.py Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
05c3cd6 to
eb46dff
Compare
Author
|
@microsoft-github-policy-service agree |
When the model omits <final_answer> tags, parse_citations returned a dict instead of a list, causing format_citations to iterate the dict's string keys and crash with 'TypeError: string indices must be integers'. Return [] so get_final_answer produces an empty block instead of crashing. Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
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
My OS: MacOS
The FastContext model consistently uses the last directory component of the workspace path as a prefix in its tool calls. For example, when the workspace is
/home/user/projects/myrepo, the model emits paths like/myrepo/backend/src/worker.pyinstead of/home/user/projects/myrepo/backend/src/worker.py.This causes every Grep, Glob, and Read call to fail with a permission error:
The agent receives zero useful search results, hallucinates file paths in its final answer, and the citation validator filters them all out, producing an empty
<final_answer>block. This affects any workspace whose absolute path has more than one component.Reproduction
All tool calls fail with permission errors; the final answer is empty.
Changes
resolve_path()helper (agent/tool/utils.py): detects the/{cwd_name}/...short-prefix pattern and rewrites it to the full absolute path before theis_relative_to(cwd)check, with a longest-existing-suffix fallback. Returns the original path when nothing resolves, preserving the existing error behavior.format_citations()/get_final_answer()so short paths in the final answer pass the existence check.patternargument when the model passes a full path (e.g./myrepo/backend/**/*.py->backend/**/*.py).Tests
Added
tests/test_path_resolution.pycovering the resolver: passthrough for in-cwd paths, short-prefix rewrite, suffix-match fallback, and unresolvable-path passthrough. All pass; existing tests are unaffected.ruff checkis clean on all changed files.Verified against
microsoft/FastContext-1.0-4B-RLandmicrosoft/FastContext-1.0-4B-SFT, served via SGLang v0.5.13 (FP8, 262K context)<final_answer>, all tool calls fail with permission errors