fix(src): defensive try/except in load_track_state for TOMLDecodeError
A malformed state.toml in conductor/tracks/<track>/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
This commit is contained in:
@@ -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]:
|
||||
|
||||
Reference in New Issue
Block a user