fix: normalize path separators in FilesystemBackend for cross-platform(OS:Window) compatibility #452
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.
PR Description
Problem
On Windows,
FilesystemBackendreturns paths with mixed separators (e.g.,/\.circleci/) causing display issues in agent tools.[AS-IS]
[TO-BE]
Why This Matters
DeepAgents provides essential filesystem capabilities for LangGraph-based agents, and cross-platform reliability is crucial for production deployments. Mixed path separators like
/\can negatively impact agent performance in two ways:This fix ensures POSIX-style paths across all platforms, improving both the developer experience and agent reliability.
Root Cause
There were two related but distinct issues affecting different modes:
Issue 1:
virtual_mode=True- Logic Bug (Functional Failure)String slicing logic in
ls_info()andglob_info()used raw string concatenation to construct virtual paths:The string slicing failed because:
cwd_strused backslashes:C:\workspace/created mixed separators:C:\workspace/abs_pathused different separators:C:\workspace\file.txt/\.circleci/Issue 2:
virtual_mode=False- Display Bug (UX Issue)In non-virtual mode, paths were functionally correct but displayed with Windows backslashes:
This was purely a display inconsistency - functionality was correct, but output didn't match POSIX conventions.
Solution
For
virtual_mode=True(Logic Fix):Replace fragile string slicing with robust
pathliboperations:Key improvements:
Path.relative_to()correctly handles path differences.as_posix()ensures forward slashes on all platforms_resolve_path()validationFor
virtual_mode=False(Display Fix):Simple normalization for consistent output:
Test Updates:
Updated test assertions to use platform-independent comparison:
Testing
pathlib.Path.as_posix()works consistently across platforms_resolve_path()validationlanggraph devon both Windows and WSL environmentsTest Results:
Changes
libs/deepagents/deepagents/backends/filesystem.py: Updatedls_info()andglob_info()methods to usepathlibfor path normalizationlibs/deepagents/tests/unit_tests/backends/test_filesystem_backend.py: Updated test assertions for platform-independent path comparisonRelationship to Issue #427
This PR and Issue #427 address complementary Windows path handling problems in different layers:
This PR (Backend Layer - Output):
FilesystemBackend.ls_info()/glob_info()- path output formatting/\) in displayed pathsPR #454 / Issue #427 (Middleware Layer - Input):
_validate_path()- user input validationF:\git\...) → invalid paths (/F:/git/...) → silent corruptionBoth fixes are necessary for robust Windows support:
Together, they provide end-to-end Windows path handling in DeepAgents' filesystem layer.