Repository navigation
Conversation
`workflow run --json` and `workflow resume --json` printed nothing on stdout when a step raised instead of returning a failed result, for example `from_json` on invalid JSON in a condition, or an exception from a custom step. The engine had already saved the run as `failed` with that error before re-raising it, and `workflow status --json` reported it that way, but the CLI's ValueError and catch-all handlers only printed the message (to stderr under --json). A caller parsing stdout got an empty string and never learned the run ID it needs to resume. An I/O failure at the same point already prints the failed run's payload through `_fail_workflow_execution`. Send an exception through that reporter when the engine recorded it as the run's failure: the state is `failed` and its error is this exception's message. Errors raised before the run is recorded, such as a missing required input on `run` or an invalid `--input` on `resume`, keep their current output. In text mode the recorded failure is now labelled "Workflow failed:" or "Resume failed:", as I/O failures are, instead of "Error:". Assisted-by: Claude Code (model: Claude Opus 5.5, autonomous) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
docs/reference/workflows.mdsaysspecify workflow run --jsonprints a single object that "always parses". Forfailedruns, that object includes anerrorfield. When a step raises instead of returning a failed result,run --jsonandresume --jsonprint nothing on stdout. Examples:from_jsonon invalid JSON in a condition, or an exception from a custom step.The engine has already saved the run as
failedwith that error, soworkflow status --jsonreports it. But a caller parsing stdout gets an empty string and never learns the run ID it needs to resume.Root cause:
WorkflowEngine.execute()/resume()persist an exception raised while steps run as the run'sfailedstatus and error, then re-raise it.except ValueErrorand catch-all handlers incommand_run.pyandcommand_resume.pyonly print the message, which goes to stderr under--json.OSErrorat the same point already goes through_fail_workflow_execution(), which prints the failed run's payload.The fix:
_fail_recorded_run()inworkflows/_commands.py, called from both handlers inrunandresume.failedand its error equals the exception's message, it reports through_fail_workflow_execution().run, or an invalid--inputonresumeof an already-failed run.Testing
uv run specify --helpuv sync && uv run pytestmainand on this branchNew tests in
tests/specify_cli/workflows/test_command_run.py:test_run_json_step_exception_reports_failed_runtest_run_json_non_value_error_reports_failed_run(a step raisingRuntimeError)test_run_step_exception_reports_failed_run_in_texttest_run_json_missing_required_input_is_not_a_run_outcomeNew tests in
tests/specify_cli/workflows/test_command_resume.py:test_resume_json_step_exception_reports_failed_runtest_resume_json_refused_before_running_is_not_a_run_outcomeOn
main, the 4 positive tests fail: the JSON ones withjson.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0), the text one because "Workflow failed:" is missing. The 2 negative tests pass. With the change both files give 91 passed.tests/test_*_python_parity.pyfiles occur identically on unmodifiedmainon this machine under full-suite load; those files pass when run on their own (257 passed, 112 skipped).uvx ruff@0.15.0 check src tests: cleanAI Disclosure
AI disclosure: Claude Code (model: Claude Opus 5.5, max reasoning effort, autonomous agent mode) opened this PR on behalf of @yxshee. A Claude Code subagent (same model, autonomous) found the bug and wrote the fix and tests. The lead agent independently re-ran the new tests against
mainand the branch, reproduced the transcripts above with the real CLI, reviewed the diff, and wrote this description. No human reviewed the change line by line before it was opened.🤖 Generated with Claude Code