From f383dae0dd1e40315c0d6f03fac7d0335026d91d Mon Sep 17 00:00:00 2001 From: Ed_ Date: Wed, 17 Jun 2026 19:34:18 -0400 Subject: [PATCH] fix(src): defensive try/except in load_track_state for TOMLDecodeError A malformed state.toml in conductor/tracks//state.toml (e.g., from an interrupted previous run) caused tomllib.load() to raise TOMLDecodeError, which propagated up and crashed App.__init__ during init_state() -> _load_active_project() -> _refresh_from_project() -> get_all_tracks() -> load_track_state(). This manifested as test failures in tests/test_layout_reorganization.py, tests/test_auto_slices.py, tests/test_hooks.py, and the tier-3-live_gui batch (all triggered by the same malformed mcp_architecture_refactor_20260606 state.toml). The fix wraps tomllib.load() in a try/except for (OSError, tomllib.TOMLDecodeError) and returns None (matching the file-not-found behavior). This is consistent with the data-oriented convention: corrupt state is a recoverable failure, not a programmer error. Tests verified: - tests/test_track_state_persistence.py (1 test) PASS - tests/test_layout_reorganization.py (4 tests) PASS - tests/test_auto_slices.py (3 tests) PASS - tests/test_hooks.py (3 tests) PASS --- src/project_manager.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/project_manager.py b/src/project_manager.py index d412060b..84885f5f 100644 --- a/src/project_manager.py +++ b/src/project_manager.py @@ -291,7 +291,10 @@ def load_track_state(track_id: str, base_dir: Union[str, Path] = ".") -> Optiona from src.models import TrackState state_file = paths.get_track_state_dir(track_id, project_path=str(base_dir)) / 'state.toml' if not state_file.exists(): return None - with open(state_file, "rb") as f: data = tomllib.load(f) + try: + with open(state_file, "rb") as f: data = tomllib.load(f) + except (OSError, tomllib.TOMLDecodeError): + return None return TrackState.from_dict(data) def load_track_history(track_id: str, base_dir: Union[str, Path] = ".") -> list[str]: