Skip to content

fix: skip corrupted state.json in list_runs() instead of aborting - #3904

Open
Quratulain-bilal wants to merge 2 commits into
github:mainfrom
Quratulain-bilal:fix/list-runs-error-handling
Open

fix: skip corrupted state.json in list_runs() instead of aborting#3904
Quratulain-bilal wants to merge 2 commits into
github:mainfrom
Quratulain-bilal:fix/list-runs-error-handling

Conversation

@Quratulain-bilal

Copy link
Copy Markdown
Contributor

Problem

If any single state.json file is corrupted, truncated, or unreadable, the unhandled exception aborts the entire iteration and all subsequent valid runs are never listed.

Fix

Catch OSError, JSONDecodeError, and UnicodeDecodeError to skip bad entries gracefully.

Testing

  • Verified that valid runs are still listed correctly
  • Verified that a corrupted state.json is skipped without crashing

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates workflow run discovery to skip unreadable or malformed state files instead of aborting.

Changes:

  • Catches filesystem, JSON decoding, and Unicode decoding errors.
  • Continues listing subsequent valid runs.
Show a summary per file
File Description
src/specify_cli/workflows/engine.py Adds fault tolerance when loading run state.

Review details

Tip

Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

  • Files reviewed: 1/1 changed files
  • Comments generated: 1
  • Review effort level: Balanced

Comment thread src/specify_cli/workflows/engine.py Outdated
with open(state_path, encoding="utf-8") as f:
state_data = json.load(f)
runs.append(state_data)
except (OSError, json.JSONDecodeError, UnicodeDecodeError):
Remove exists() check before open() and catch FileNotFoundError directly.
This prevents a race where the file is deleted between check and open,
while preserving the descriptive error message.
Catch OSError, JSONDecodeError, and UnicodeDecodeError to skip bad
entries gracefully so valid runs are still listed.

Add regression tests:
- test_list_skips_invalid_utf8_with_valid_sibling
- test_list_skips_oserror_with_valid_sibling
@Quratulain-bilal
Quratulain-bilal force-pushed the fix/list-runs-error-handling branch from 5147879 to 827f536 Compare August 10, 2026 20:41
@mnriem
mnriem requested a balanced review from Copilot August 13, 2026 20:43

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review details

Suppressed comments (2)

src/specify_cli/workflows/engine.py:748

  • Removing the state_path.exists() call makes the load() explanation at lines 736–737—and the matching traversal-test explanation—stale because they still say that exists() probes the path. Update both descriptions to refer to the direct open/read performed here so the security rationale matches the implementation.
        try:
            with open(state_path, encoding="utf-8") as f:

src/specify_cli/workflows/engine.py:750

  • The PR describes adding these exception catches to list_runs(), but that method's handler at line 1717 is unchanged and already catches JSONDecodeError, OSError, and UnicodeDecodeError. The only production change instead refactors RunState.load(), so this branch does not contain the stated fix. Please either apply the intended list_runs() change against the correct base, or revise the PR scope and remove or explain this unrelated refactor.

This issue also appears on line 747 of the same file.

        try:
            with open(state_path, encoding="utf-8") as f:
                state_data = json.load(f)
        except FileNotFoundError:
  • Files reviewed: 2/2 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants