Repository navigation
Python: fix(core): quarantine an unreadable memory state file instead of failing every turn - #9547
Open
Yufeng He (he-yufeng) wants to merge 1 commit into
Open
Yufeng He (he-yufeng) wants to merge 1 commit into
Yufeng He (he-yufeng) wants to merge 1 commit into
Conversation
… of failing every turn MemoryFileStore.read_state parsed state.json without a guard, so a corrupt state file (interrupted editor, partial external write) raised out of the per-turn memory bookkeeping path forever. Move the unreadable file aside (the session store's corrupt-snapshot convention) and restart from a clean state; the next write recreates the file.
Yufeng He (he-yufeng)
requested review from
SergeyMenshykh,
Tao Chen (TaoChenOSU),
Eduard van Valkenburg (eavanvalkenburg),
Giles Odigwe (giles17),
Jose Alvarez (jpalvarezl),
Evan Mattson (moonbox3),
Roger Barreto (rogerbarreto),
sophia-ramsey and
westey (westey-m)
as code owners
October 19, 2026 21:15
Yufeng He (he-yufeng)
deployed
to
github-app-auth
October 19, 2026 21:15 — with
GitHub Actions
Active
Yufeng He (he-yufeng)
deployed
to
github-app-auth
October 19, 2026 21:15 — with
GitHub Actions
Active
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Quarantine can move aside a concurrently repaired file and reset valid maintenance metadata.
1 open issue
What changed in this PR
Improves Python memory-store recovery so corrupt state files do not repeatedly fail per-turn bookkeeping.
Changes:
- Quarantines unreadable state files, logs a warning, and returns defaults.
- Adds regression coverage for quarantine, content preservation, and subsequent writes.
| File | Description |
|---|---|
| python/packages/core/tests/core/test_harness_memory.py | Tests corrupt-state recovery and later write/read behavior. |
| python/packages/core/agent_framework/_harness/_memory.py | Adds quarantine and default-state recovery. |
Review effort: Balanced
| except ValueError as exc: | ||
| quarantine_path = state_path.with_name(f".{state_path.name}.{uuid.uuid4().hex}.corrupt") | ||
| try: | ||
| state_path.rename(quarantine_path) |
This branch was successfully deployed
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.

Summary
MemoryFileStore.read_stateparsedstate.jsonwith no guard, so a corrupt state file (interrupted editor, partial external write, hand edit) raisedJSONDecodeErrorout of the per-turn memory bookkeeping path — and kept raising on every later turn, since nothing ever removed the bad file.This follows the session store's existing corrupt-snapshot convention (
_quarantine_corrupt_snapshotin_sessions.py): an unreadable state file is moved aside to.<name>.<uuid>.corrupt, a warning is logged, and the store restarts from a clean default state. The nextwrite_staterecreates a clean file. The deliberateValueErrorfor a well-formed non-object document is unchanged.Tests
test_memory_file_store_quarantines_corrupt_state_file: writes state through the real path, corrupts the file, asserts a clean default comes back, the corrupt file was moved aside with its content preserved, and a later write/read round-trips normally.pytest tests/core/test_harness_memory.py: 34 passed.pyright agent_framework/_harness/_memory.pyand the test file: 0 errors.PYTHONPATHpinning confirmed byagent_framework.__file__), not the shared editable install.