Skip to content

fix(sdk): keep an oversize write in the in-memory file store - #6635

Merged
VascoSch92 merged 1 commit into
mainfrom
vasco/memory-filestore-oversize
Nov 9, 2026
Merged

VascoSch92 merged 1 commit into
mainfrom
vasco/memory-filestore-oversize

Conversation

@VascoSch92

@VascoSch92 VascoSch92 commented Nov 8, 2026 •

Copy link
Copy Markdown
Member

HUMAN:

just fixing a bug


AGENT:

Why

InMemoryFileStore keeps its only copy of the data in a MemoryLRUCache. The cache skips a value larger than max_memory so that one huge item does not evict everything, which is right for LocalFileStore, 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 next read("state.json") raises FileNotFoundError.

Summary

  • MemoryLRUCache takes keep_oversize (default False, so LocalFileStore is unchanged). InMemoryFileStore sets it, so an oversize write evicts everything older and is stored, the same LRU trade-off the store already makes for any other write.
  • The key's previous entry is now dropped before the size accounting. With an oversize value the eviction loop would otherwise reach that same key and subtract its size twice.

Issue Number

Part of #6348.

How to Test

uv run pytest tests/sdk/io tests/sdk/conversation -q

1010 passed. The new test_oversize_write_is_not_silently_dropped fails on main and passes here; after the oversize write files.current_memory equals the stored value's length.

Type

  • Bug fix
  • Feature
  • Refactor
  • Breaking change
  • Docs / chore

🐳 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

Variant Architectures Base Image Docs / Tags
java amd64, arm64 eclipse-temurin:17-jdk Link
python-slim amd64, arm64 python-node-runtime Link
python-minimal amd64, arm64 python-node-runtime Link
python amd64, arm64 python-node-runtime Link
golang amd64, arm64 golang:1.21-bookworm Link

Pull (multi-arch manifest)

# Each variant is a multi-arch manifest supporting both amd64 and arm64
docker pull ghcr.io/openhands/agent-server:6c4d7d1-python

Run

docker run -it --rm \
  -p 8000:8000 \
  --name agent-server-6c4d7d1-python \
  ghcr.io/openhands/agent-server:6c4d7d1-python

All tags pushed for this build

ghcr.io/openhands/agent-server:6c4d7d1-golang-amd64
ghcr.io/openhands/agent-server:6c4d7d1fa3297126923199a41a82af171b3bf7aa-golang-amd64
ghcr.io/openhands/agent-server:vasco-memory-filestore-oversize-golang-amd64
ghcr.io/openhands/agent-server:6c4d7d1-golang_tag_1.21-bookworm-amd64
ghcr.io/openhands/agent-server:6c4d7d1-golang-arm64
ghcr.io/openhands/agent-server:6c4d7d1fa3297126923199a41a82af171b3bf7aa-golang-arm64
ghcr.io/openhands/agent-server:vasco-memory-filestore-oversize-golang-arm64
ghcr.io/openhands/agent-server:6c4d7d1-golang_tag_1.21-bookworm-arm64
ghcr.io/openhands/agent-server:6c4d7d1-java-amd64
ghcr.io/openhands/agent-server:6c4d7d1fa3297126923199a41a82af171b3bf7aa-java-amd64
ghcr.io/openhands/agent-server:vasco-memory-filestore-oversize-java-amd64
ghcr.io/openhands/agent-server:6c4d7d1-eclipse-temurin_tag_17-jdk-amd64
ghcr.io/openhands/agent-server:6c4d7d1-java-arm64
ghcr.io/openhands/agent-server:6c4d7d1fa3297126923199a41a82af171b3bf7aa-java-arm64
ghcr.io/openhands/agent-server:vasco-memory-filestore-oversize-java-arm64
ghcr.io/openhands/agent-server:6c4d7d1-eclipse-temurin_tag_17-jdk-arm64
ghcr.io/openhands/agent-server:6c4d7d1-python-amd64
ghcr.io/openhands/agent-server:6c4d7d1fa3297126923199a41a82af171b3bf7aa-python-amd64
ghcr.io/openhands/agent-server:vasco-memory-filestore-oversize-python-amd64
ghcr.io/openhands/agent-server:6c4d7d1-python-node-runtime-amd64
ghcr.io/openhands/agent-server:6c4d7d1-python-arm64
ghcr.io/openhands/agent-server:6c4d7d1fa3297126923199a41a82af171b3bf7aa-python-arm64
ghcr.io/openhands/agent-server:vasco-memory-filestore-oversize-python-arm64
ghcr.io/openhands/agent-server:6c4d7d1-python-node-runtime-arm64
ghcr.io/openhands/agent-server:6c4d7d1-python-minimal-amd64
ghcr.io/openhands/agent-server:6c4d7d1fa3297126923199a41a82af171b3bf7aa-python-minimal-amd64
ghcr.io/openhands/agent-server:vasco-memory-filestore-oversize-python-minimal-amd64
ghcr.io/openhands/agent-server:6c4d7d1-python-node-runtime-minimal-amd64
ghcr.io/openhands/agent-server:6c4d7d1-python-minimal-arm64
ghcr.io/openhands/agent-server:6c4d7d1fa3297126923199a41a82af171b3bf7aa-python-minimal-arm64
ghcr.io/openhands/agent-server:vasco-memory-filestore-oversize-python-minimal-arm64
ghcr.io/openhands/agent-server:6c4d7d1-python-node-runtime-minimal-arm64
ghcr.io/openhands/agent-server:6c4d7d1-python-slim-amd64
ghcr.io/openhands/agent-server:6c4d7d1fa3297126923199a41a82af171b3bf7aa-python-slim-amd64
ghcr.io/openhands/agent-server:vasco-memory-filestore-oversize-python-slim-amd64
ghcr.io/openhands/agent-server:6c4d7d1-python-node-runtime-slim-amd64
ghcr.io/openhands/agent-server:6c4d7d1-python-slim-arm64
ghcr.io/openhands/agent-server:6c4d7d1fa3297126923199a41a82af171b3bf7aa-python-slim-arm64
ghcr.io/openhands/agent-server:vasco-memory-filestore-oversize-python-slim-arm64
ghcr.io/openhands/agent-server:6c4d7d1-python-node-runtime-slim-arm64
ghcr.io/openhands/agent-server:6c4d7d1-golang
ghcr.io/openhands/agent-server:6c4d7d1fa3297126923199a41a82af171b3bf7aa-golang
ghcr.io/openhands/agent-server:vasco-memory-filestore-oversize-golang
ghcr.io/openhands/agent-server:6c4d7d1-golang_tag_1.21-bookworm
ghcr.io/openhands/agent-server:6c4d7d1-java
ghcr.io/openhands/agent-server:6c4d7d1fa3297126923199a41a82af171b3bf7aa-java
ghcr.io/openhands/agent-server:vasco-memory-filestore-oversize-java
ghcr.io/openhands/agent-server:6c4d7d1-eclipse-temurin_tag_17-jdk
ghcr.io/openhands/agent-server:6c4d7d1-python-minimal
ghcr.io/openhands/agent-server:6c4d7d1fa3297126923199a41a82af171b3bf7aa-python-minimal
ghcr.io/openhands/agent-server:vasco-memory-filestore-oversize-python-minimal
ghcr.io/openhands/agent-server:6c4d7d1-python-node-runtime-minimal
ghcr.io/openhands/agent-server:6c4d7d1-python-slim
ghcr.io/openhands/agent-server:6c4d7d1fa3297126923199a41a82af171b3bf7aa-python-slim
ghcr.io/openhands/agent-server:vasco-memory-filestore-oversize-python-slim
ghcr.io/openhands/agent-server:6c4d7d1-python-node-runtime-slim
ghcr.io/openhands/agent-server:6c4d7d1-python
ghcr.io/openhands/agent-server:6c4d7d1fa3297126923199a41a82af171b3bf7aa-python
ghcr.io/openhands/agent-server:vasco-memory-filestore-oversize-python
ghcr.io/openhands/agent-server:6c4d7d1-python-node-runtime

About Multi-Architecture Support

  • Each variant tag (e.g., 6c4d7d1-python) is a multi-arch manifest supporting both amd64 and arm64
  • Docker automatically pulls the correct architecture for your platform
  • Individual architecture tags (e.g., 6c4d7d1-python-amd64) are also available if needed

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.
@VascoSch92
VascoSch92 marked this pull request as ready for review November 8, 2026 19:40
@github-actions

github-actions Bot commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

REST API breakage checks (OpenAPI) — ✅ PASSED

Result: ✅ PASSED

Action log

@github-actions

github-actions Bot commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Coverage

Coverage Report •
FileStmtsMissCoverMissing
openhands-sdk/openhands/sdk/io
   cache.py37781%52–53, 58–59, 61–63
   memory.py731284%42, 61, 65–69, 83–84, 94, 96, 105
TOTAL54581851184% 

@all-hands-bot all-hands-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_oversize defaults to False, so LocalFileStore (where a skipped oversize write falls back to disk) keeps its current behavior, while InMemoryFileStore (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 LocalFileStore oversize overwrites (existing regression test test_oversize_overwrite_does_not_serve_stale_cache still passes) and keeps current_memory correct for the keep-oversize path, including when the eviction loop reaches the key being written.
  • I verified by probing both main and this head: LRU eviction order, entry-count eviction, and memory accounting are unchanged outside the fixed path; on main the oversize write is silently dropped and the subsequent read raises FileNotFoundError, while on this head the value is stored and current_memory equals the stored value's length.
  • The new regression test asserts observable behavior (the written value is readable) and fails on main without 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

@VascoSch92
VascoSch92 merged commit d134332 into main Nov 9, 2026
52 of 53 checks passed
@VascoSch92
VascoSch92 deleted the vasco/memory-filestore-oversize branch November 9, 2026 07:58
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.

2 participants