Skip to content

fix(workflows): save run state before logging in workflow run - #5583

Open
chuenchen309 wants to merge 1 commit into
github:mainfrom
chuenchen309:fix/workflow-run-persist-before-log
Open

chuenchen309 wants to merge 1 commit into
github:mainfrom
chuenchen309:fix/workflow-run-persist-before-log

Conversation

@chuenchen309

Copy link
Copy Markdown
Contributor

Description

#5492 fixed #5489 for workflow resume by saving the paused/failed/completed state before appending the lifecycle log event. WorkflowEngine.execute() still does it the other way round in the same three places, so workflow run can leave a run stuck as running the same way: if log.jsonl can't be written, the failure handler's workflow_failed append raises before the failed state is saved, and a failed workflow_finished append leaves a run whose steps all completed persisted as running. Either way a later workflow resume is refused with Cannot resume run '<id>' with status 'running'.

This applies the same ordering to execute(): save first, then log.

Testing

Set up this checkout's .venv and editable install using the local development guide. Run commands from the checkout root.

  • Tested locally with .venv/bin/specify --help (Windows PowerShell: .\.venv\Scripts\specify.exe --help)
  • Ran relevant existing tests with .venv/bin/python -m pytest tests -q (Windows PowerShell: .\.venv\Scripts\python.exe -m pytest tests -q); use affected test paths for focused checks and LC_ALL=en_US.UTF-8 on macOS
  • Tested with a sample project (if applicable)

Added two regressions next to the #5492 resume tests (a log that can't be written during execute(), and a failed workflow_finished append); both fail on main with the persisted status still running and pass with this change. tests/workflows passes (990 tests), as do the other 37 test files that drive WorkflowEngine or the workflow CLI commands (4403 passed, 62 skipped). ruff check is clean on the changed files.

AI Disclosure

  • I did not use AI assistance for this contribution
  • I did use AI assistance (fill in the disclosure below)

AI disclosure: This PR was written by an AI coding agent, Claude Code (model: Claude Opus 5.5), working autonomously on behalf of the account holder, with no human review before submission. The agent compared execute() with the resume path fixed in #5492, wrote the fix and the tests, ran the tests above, and wrote this description. The commit carries an Assisted-by: trailer.

execute() appended the workflow_interrupted, workflow_failed and
workflow_finished events before saving the matching state. When
log.jsonl cannot be written, the run stays persisted as running and
workflow resume refuses it. github#5492 fixed the same ordering in resume().

Assisted-by: Claude Code (model: Claude Opus 5.5, autonomous)
@chuenchen309
chuenchen309 requested a review from mnriem as a code owner November 26, 2026 04:40
Copilot AI adaptive review requested due to automatic review settings November 26, 2026 04:40

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.

🟡 Changes recommended

The reordered PAUSED transition lacks an execute() log-failure regression test verifying that PAUSED persists and execution resumes after logging is repaired, leaving the interrupted-run bug unguarded.

1 open issue
What changed in this PR

Extends the state-persistence fix from #5492 to workflow run, preventing lifecycle log failures from leaving paused, failed, or completed runs persisted as running.

Changes:

  • Saves run state before interruption, failure, and completion log events.
  • Adds regressions for failed-state persistence and completion-state preservation when logging fails.

Review analysis is AI-generated by GitHub Copilot (model: unknown; automated mode) for the requesting reviewer. Tests were not run during this review.

File Description
tests/​workflows/​test_composition_execution.py Adds two execute-path log-failure regression tests.
src/​specify_cli/​workflows/​engine.py Persists execute-path state transitions before lifecycle logging.

Review effort: Balanced (adaptive)

Comment on lines 1226 to +1227
state.save()
state.append_log({"event": "workflow_interrupted"})

This branch has not been deployed

No deployments
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.

[Bug]: A workflow log write failure can leave a resumed run stuck as running

2 participants