Repository navigation
fix(sdk): keep an oversize write in the in-memory file store - #6635
Conversation
InMemoryFileStore keeps its only copy of the data in a MemoryLRUCache, which skips a value larger than max_memory. A write of such a value was dropped, and the next read raised FileNotFoundError. The store now keeps it and evicts everything older, as LRU eviction does for any other write.
REST API breakage checks (OpenAPI) — ✅ PASSEDResult: ✅ PASSED |
all-hands-bot
left a comment
There was a problem hiding this comment.
This review was posted by an AI agent (OpenHands).
Scope: In scope — MemoryLRUCache/InMemoryFileStore are SDK I/O owned by this repository, and this addresses one of the edge-case bugs tracked in #6348 (issue is open, labeled ready-for-dev).
Assessment: No material findings on 6c4d7d1f.
- The fix is minimal and correctly scoped:
keep_oversizedefaults toFalse, soLocalFileStore(where a skipped oversize write falls back to disk) keeps its current behavior, whileInMemoryFileStore(whose only copy lives in the cache) now keeps the value under the same LRU trade-off it already makes for any other write. - Dropping the key's previous entry before the size accounting preserves the stale-skip behavior for
LocalFileStoreoversize overwrites (existing regression testtest_oversize_overwrite_does_not_serve_stale_cachestill passes) and keepscurrent_memorycorrect for the keep-oversize path, including when the eviction loop reaches the key being written. - I verified by probing both
mainand this head: LRU eviction order, entry-count eviction, and memory accounting are unchanged outside the fixed path; onmainthe oversize write is silently dropped and the subsequent read raisesFileNotFoundError, while on this head the value is stored andcurrent_memoryequals the stored value's length. - The new regression test asserts observable behavior (the written value is readable) and fails on
mainwithout the fix, per repository testing guidance.
Verification: uv run pytest tests/sdk/io tests/sdk/conversation -q — 24 passed and 985 passed respectively on this head. The single failure observed (test_slow_mcp_servers_start_side_by_side) is a pre-existing timing flake in this environment: it failed and passed in isolation on both main and this head, and it exercises MCP startup, untouched by this diff. Current CI checks on 6c4d7d1f show no failed or pending checks. No agent-behavior or evaluation surface is affected (no prompts, tool descriptions, or agent loop changes).
✅ APPROVED
HUMAN:
just fixing a bug
AGENT:
Why
InMemoryFileStorekeeps its only copy of the data in aMemoryLRUCache. The cache skips a value larger thanmax_memoryso that one huge item does not evict everything, which is right forLocalFileStore, where the file is still on disk. For the in-memory store the skipped write is simply lost:write("state.json", big)returns normally and the nextread("state.json")raisesFileNotFoundError.Summary
MemoryLRUCachetakeskeep_oversize(defaultFalse, soLocalFileStoreis unchanged).InMemoryFileStoresets it, so an oversize write evicts everything older and is stored, the same LRU trade-off the store already makes for any other write.Issue Number
Part of #6348.
How to Test
1010 passed. The new
test_oversize_write_is_not_silently_droppedfails onmainand passes here; after the oversize writefiles.current_memoryequals the stored value's length.Type
🐳 Agent Server images for this PR — GHCR package, pull/run commands, and all pushed tags (click to expand)
• GHCR package: https://github.com/OpenHands/agent-sdk/pkgs/container/agent-server
Variants & Base Images
eclipse-temurin:17-jdkpython-node-runtimepython-node-runtimepython-node-runtimegolang:1.21-bookwormPull (multi-arch manifest)
# Each variant is a multi-arch manifest supporting both amd64 and arm64 docker pull ghcr.io/openhands/agent-server:6c4d7d1-pythonRun
All tags pushed for this build
About Multi-Architecture Support
6c4d7d1-python) is a multi-arch manifest supporting both amd64 and arm646c4d7d1-python-amd64) are also available if needed