fix: skip corrupted run state files in list_runs (#3814)

* fix: skip corrupted run state files in list_runs

* fix: address review comments - add UnicodeDecodeError, dict validation, and regression tests

- Catch UnicodeDecodeError for invalid UTF-8 encoding
- Validate loaded JSON is a dict with required 'run_id' key
- Add 5 regression tests for corrupted state files

Fixes #3814
This commit is contained in:
Quratulain-bilal
2026-08-05 08:11:38 -05:00
committed by GitHub
parent 03d71b3363
commit 1e85d4ff53
2 changed files with 95 additions and 2 deletions
+7 -2
View File
@@ -1710,8 +1710,13 @@ class WorkflowEngine:
continue
state_path = run_dir / "state.json"
if state_path.exists():
with open(state_path, encoding="utf-8") as f:
state_data = json.load(f)
try:
with open(state_path, encoding="utf-8") as f:
state_data = json.load(f)
except (json.JSONDecodeError, OSError, UnicodeDecodeError):
continue
if not isinstance(state_data, dict) or "run_id" not in state_data:
continue
runs.append(state_data)
return runs