fix(core): use resolved absolute path for file references in agent mode#1072
Merged
fix(core): use resolved absolute path for file references in agent mode#1072
Conversation
formatSegment was using the display path (relative) instead of resolvedPath (absolute) when rendering <file: path="..."> tags in agent mode. This caused agents running in isolated workspaces to fail when trying to read input_files, since the relative paths did not exist in the workspace directory. Now uses segment.resolvedPath (set by message-processor.ts during file resolution) with a fallback to the display path for synthetic segments. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Remove tests for existing behavior already covered by the 1626 core tests. Keep only the two agent-mode file path tests that guard the fix. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add "Writing Tests" section to prevent over-engineering tests. Focus on regression-relevant tests over comprehensive coverage of existing behavior. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.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.
Summary
formatSegmentin agent mode was usingsegment.path(relative display path) instead ofsegment.resolvedPath(absolute) when rendering<file: path="...">tagsisolation: per_test) to fail when trying to readinput_files, since the relative paths did not exist in the workspace directorysegment.resolvedPathwith a fallback to display path for synthetic/test segmentsRoot cause
In
segment-formatter.ts, the agent mode branch readsegment.path(the human-readable display path set bymessage-processor.ts) rather thansegment.resolvedPath(the absolute path also set bymessage-processor.tsduring file resolution). When the agent runs in an isolated workspace with a different cwd, the relative path doesn't resolve to any file.Reproduction
The agent receives
<file: path="snippets/data.csv">instead of<file: path="/abs/path/to/evals/test/snippets/data.csv">, tries to read it relative to its workspace, and fails withERROR: missing-file.Changes
packages/core/src/evaluation/formatting/segment-formatter.tsresolvedPath(absolute) in agent mode, fallback topathpackages/core/test/evaluation/formatting/segment-formatter.test.tsformatSegment,formatFileContents, andhasVisibleContentRefactoring note
The
formatSegmentfunction operates onJsonObject(untyped), making it easy to reference the wrong property (pathvsresolvedPath). A typed file segment interface would prevent this class of bug at compile time. Kept this PR focused on the fix; happy to follow up with a typing improvement if desired.Test plan
formatSegmentagent mode (resolvedPath, fallback, missing path)input-files-shorthand.test.tspasses (59 tests)packages/core/test suite passes (1626 tests)🤖 Generated with Claude Code