Skip to content

fix(core): use resolved absolute path for file references in agent mode#1072

Merged
christso merged 3 commits intomainfrom
fix/agent-file-path-resolution
Apr 13, 2026
Merged

fix(core): use resolved absolute path for file references in agent mode#1072
christso merged 3 commits intomainfrom
fix/agent-file-path-resolution

Conversation

@christso
Copy link
Copy Markdown
Collaborator

Summary

  • formatSegment in agent mode was using segment.path (relative display path) instead of segment.resolvedPath (absolute) when rendering <file: path="..."> tags
  • This caused agents running in isolated workspaces (e.g. copilot CLI with isolation: per_test) to fail when trying to read input_files, since the relative paths did not exist in the workspace directory
  • Now uses segment.resolvedPath with a fallback to display path for synthetic/test segments

Root cause

In segment-formatter.ts, the agent mode branch read segment.path (the human-readable display path set by message-processor.ts) rather than segment.resolvedPath (the absolute path also set by message-processor.ts during file resolution). When the agent runs in an isolated workspace with a different cwd, the relative path doesn't resolve to any file.

Reproduction

# eval.yaml with isolation: per_test workspace
input_files:
  - snippets/data.csv
input: "Summarize this CSV."

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 with ERROR: missing-file.

Changes

File Change
packages/core/src/evaluation/formatting/segment-formatter.ts Use resolvedPath (absolute) in agent mode, fallback to path
packages/core/test/evaluation/formatting/segment-formatter.test.ts New test file covering formatSegment, formatFileContents, and hasVisibleContent

Refactoring note

The formatSegment function operates on JsonObject (untyped), making it easy to reference the wrong property (path vs resolvedPath). 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

  • New unit tests for formatSegment agent mode (resolvedPath, fallback, missing path)
  • Existing input-files-shorthand.test.ts passes (59 tests)
  • Full packages/core/ test suite passes (1626 tests)
  • Typecheck passes
  • Lint passes

🤖 Generated with Claude Code

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>
@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented Apr 13, 2026

Deploying agentv with  Cloudflare Pages  Cloudflare Pages

Latest commit: ca90e45
Status:⚡️  Build in progress...

View logs

christso and others added 2 commits April 13, 2026 14:52
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>
@christso christso merged commit 5e1c003 into main Apr 13, 2026
3 of 4 checks passed
@christso christso deleted the fix/agent-file-path-resolution branch April 13, 2026 04:55
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.

1 participant