Skip to content

fix: normalize paths in editor cache to prevent stale content#491

Open
xlyoung wants to merge 1 commit into
strands-agents:mainfrom
xlyoung:fix/editor-cache-path-normalization
Open

fix: normalize paths in editor cache to prevent stale content#491
xlyoung wants to merge 1 commit into
strands-agents:mainfrom
xlyoung:fix/editor-cache-path-normalization

Conversation

@xlyoung
Copy link
Copy Markdown

@xlyoung xlyoung commented Jun 4, 2026

Problem

The editor tool's content cache used raw path parameters as cache keys. When the same file was accessed via different path formats (relative vs absolute), separate cache entries were created:

# View with relative path - caches as 'test.md'
editor(command='view', path='test.md')

# Replace with absolute path - caches as '/full/path/test.md'  
editor(command='str_replace', path='/full/path/test.md', ...)

# View with relative path again - returns STALE content from 'test.md' key!
editor(command='view', path='test.md')  # Returns old content

This caused agents to retry edits unnecessarily, wasting LLM tokens.

Fix

Normalize paths with os.path.abspath() after expanduser() to ensure consistent cache keys:

path = os.path.expanduser(path)
if path:
    path = os.path.abspath(path)

Testing

All 32 editor tests pass.

Fixes #345

The editor tool's content cache used raw path parameters as keys. When
the same file was accessed via different path formats (relative vs
absolute), separate cache entries were created, causing stale content
to be returned after modifications.

Fix: normalize paths with os.path.abspath() after expanduser() to
ensure consistent cache keys regardless of how the path is specified.

This prevents agents from retrying edits unnecessarily due to seeing
stale content after modifications, saving LLM tokens.

Fixes strands-agents#345
@xlyoung xlyoung requested a deployment to manual-approval June 4, 2026 03:44 — with GitHub Actions Waiting
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.

[BUG] editor tool cache uses non-normalized paths

1 participant