fix(editor): normalize paths in content cache to prevent duplicate entries#510
Open
Ashutosh0x wants to merge 1 commit into
Open
fix(editor): normalize paths in content cache to prevent duplicate entries#510Ashutosh0x wants to merge 1 commit into
Ashutosh0x wants to merge 1 commit into
Conversation
…tries Fixes strands-agents#345 The editor tool's CONTENT_HISTORY cache uses raw path strings as keys. When the same file is referenced via different path formats (e.g., './file.py' vs '/absolute/path/file.py' vs '~/file.py'), separate cache entries are created, leading to stale reads and missed updates. Fix: Apply os.path.normpath(os.path.abspath(...)) after expanduser() at the entry point of the editor function. This ensures all path variants resolve to the same canonical key in CONTENT_HISTORY.
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.
Issue
Fixes #345
Description
The editor tool's CONTENT_HISTORY cache uses raw path strings as dictionary keys. When the same file is referenced via different path formats, separate cache entries are created:
`python
These all point to the same file but create different cache entries:
editor(command='view', path='./file.py')
editor(command='view', path='/absolute/path/file.py')
editor(command='view', path='~/project/file.py')
``n
This causes:
Fix
Apply os.path.normpath(os.path.abspath(...)) after os.path.expanduser() at the entry point of the editor function (line 317). This ensures all path variants resolve to the same canonical absolute path before being used as cache keys.
`python
Before:
path = os.path.expanduser(path)
After:
path = os.path.normpath(os.path.abspath(os.path.expanduser(path)))
``n
This is a single-line, minimal-risk fix that normalizes the path once at the top of the function, so all downstream operations (cache reads, cache writes, file operations, backup paths) use the same canonical path.
Testing