fix: guard json.loads() and use atomic writes for persistent state#29019
Open
annguyenNous wants to merge 1 commit into
Open
fix: guard json.loads() and use atomic writes for persistent state#29019annguyenNous wants to merge 1 commit into
annguyenNous wants to merge 1 commit into
Conversation
JSON decode guards (5 files): - weixin.py: wrap _api_post/_api_get json.loads in try/except - browser_cdp_tool.py: skip malformed CDP WebSocket frames - osv_check.py: return [] on non-JSON OSV API responses - api_server.py: return None on corrupted SQLite cache entries Atomic writes (6 files): - skills_hub.py: use atomic_json_write for lock/taps files - model_metadata.py: use atomic_yaml_write for context cache - delivery.py: use tempfile+fsync+os.replace for delivery output - run.py: use atomic_json_write for voice mode preferences - environments/base.py: use atomic_json_write for JSON store - checkpoint_manager.py: use atomic_json_write for project metadata Resource management (1 file): - vision_tools.py: close PIL Image in finally block to prevent fd leak
This was referenced May 23, 2026
Open
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.
Problem
Multiple files have unguarded
json.loads()calls that crash on malformed/non-JSON responses, and several persistent state files use non-atomicwrite_text()that can corrupt on crash.Fix
JSON decode guards (5 files):
_api_post()and_api_get()now catchjson.JSONDecodeErrorand raise descriptiveRuntimeError[]instead of crashingNoneinstead of propagatingJSONDecodeErrorAtomic writes (6 files):
atomic_json_write()(temp+fsync+replace)atomic_yaml_write()atomic_json_write()atomic_json_write()atomic_json_write()Resource management (1 file):
Image.open()handle now closed infinallyblock to prevent fd leak during resize loopsBefore vs After
json.JSONDecodeErrorcrash on non-200 HTMLRuntimeErrorwith contextTests
py_compilesyntax check