Skip to content

Handle short writes when creating memory files - #1849

Open
sylvesterkaczmarek wants to merge 1 commit into
anthropics:mainfrom
sylvesterkaczmarek:fix/memory-create-short-write
Open

Handle short writes when creating memory files#1849
sylvesterkaczmarek wants to merge 1 commit into
anthropics:mainfrom
sylvesterkaczmarek:fix/memory-create-short-write

Conversation

@sylvesterkaczmarek

Copy link
Copy Markdown

Summary

Ensure the local filesystem memory tool writes complete file contents when os.write() performs a legal short write.

Both BetaLocalFilesystemMemoryTool.create() and BetaAsyncLocalFilesystemMemoryTool.create() currently call os.write() once and ignore its return value before reporting success. POSIX writes are allowed to consume fewer bytes than requested, so a short write can leave a newly created memory file truncated while the tool still returns File created successfully.

The existing atomic edit/insert paths already loop until the complete buffer has been written, so create currently has weaker data-integrity semantics than later updates to the same memory file.

Fix

Introduce a small shared _write_all() helper that retries writes until the complete byte buffer has been persisted and treats a zero-byte write as an error.

Use the helper consistently in synchronous and asynchronous memory creation and in the existing sync/async atomic replace paths.

Regression coverage

Adds deterministic sync and async tests that force os.write() to accept only three bytes per call. The tests use UTF-8 content containing a multibyte character and verify that multiple writes occur and the final file exactly matches the requested content.

The production change is confined to Anthropic's hand-maintained local filesystem memory tool.

@sylvesterkaczmarek
sylvesterkaczmarek requested a review from a team as a code owner August 17, 2026 08:34
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