Skip to content

fix: skip corrupted run state files in list_runs - #3814

Open
Quratulain-bilal wants to merge 2 commits into
github:mainfrom
Quratulain-bilal:fix/workflow-runstate-json-error
Open

fix: skip corrupted run state files in list_runs#3814
Quratulain-bilal wants to merge 2 commits into
github:mainfrom
Quratulain-bilal:fix/workflow-runstate-json-error

Conversation

@Quratulain-bilal

Copy link
Copy Markdown
Contributor

Wrap json.load() in workflows/engine.py list_runs with ry/except (json.JSONDecodeError, OSError) so a single corrupted state.json doesn't crash the entire listing. Corrupted runs are silently skipped.

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

Improves workflow run listing resilience by skipping unreadable or malformed state files.

Changes:

  • Catches JSON parsing and file I/O errors in list_runs().
  • Skips affected workflow runs instead of aborting the listing.
Show a summary per file
File Description
src/specify_cli/workflows/engine.py Adds error handling when loading run state files.

Review details

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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

Comment thread src/specify_cli/workflows/engine.py
Comment thread src/specify_cli/workflows/engine.py Outdated
…n, 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 github#3814

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

Comments suppressed due to low confidence (2)

src/specify_cli/workflows/engine.py:1592

  • The guard still admits syntactically valid but corrupted states. For example, {"run_id":"x","workflow_id":"w","status":{}} passes here, but workflow inspect then uses that dict as a key in the status-color map (_commands.py:1349-1350) and raises TypeError, so one bad state can still abort the listing. Validate the required field types and status value before appending, and add this payload as a regression case.
                if not isinstance(state_data, dict) or "run_id" not in state_data:
                    continue

tests/test_workflows.py:6224

  • This does not reliably exercise the new OSError path: chmod(0o000) remains readable when tests run as root or with equivalent capabilities, while Windows attrib +R only makes the file read-only and this test explicitly expects it to be listed. The test can therefore fail in privileged CI and never verifies the behavior on Windows. Mock open for this specific path to raise PermissionError instead of relying on filesystem permissions.
        if sys.platform == "win32":
            subprocess.run(["attrib", "+R", str(state_file)], check=True)
        else:
            state_file.chmod(0o000)
  • Files reviewed: 2/2 changed files
  • Comments generated: 0 new
  • Review effort level: Medium

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