Description
Bug Description
WorkflowEngine.resume() persists running before appending to log.jsonl. If logging fails, the failure handler can try the same log again before it saves the failure state. The on-disk checkpoint stays running, and fixing the log path alone does not make the run resumable again.
Steps to Reproduce
- In a disposable Spec Kit project, start a workflow with a gate that pauses. Note the run ID.
- Move the run's
.specify/workflows/runs/<run_id>/log.jsonlaside and create a directory namedlog.jsonlin its place. - Run
specify workflow resume <run_id> --jsonand inspectstate.json. - Remove the empty directory, restore the original log, and try to resume again.
Expected Behavior
Resume should report the log error without leaving the persisted run stuck as running. Once the log path is repaired, the run should be resumable.
Actual Behavior
The first resume exits 1 (WorkflowEngine.resume() raises IsADirectoryError) and persists status: running. The second resume exits 1 with Cannot resume run '<run_id>' with status 'running'.
Specify CLI Version
1.4.3.dev0, reproduced from main at 4a8c7f1f.
AI Agent
Not applicable to the affected workflow behavior.
Operating System
Linux 6.17.0-1032-oem, x86_64.
Python Version
3.14.4
Additional Context
The directory case is reproducible on main and on #5480. The review finding on #5480 identifies another trigger on that branch: a symlinked log is correctly refused, but that refusal also occurs after the running checkpoint. main follows the symlink, so the symlink case does not trigger this symptom there. Handle log-write and log-policy failures without weakening the storage policy; this is a follow-up to #5480, not part of that PR.
AI Disclosure
Filed on behalf of @markuswondrak by the Pi Coding Agent (GPT-6.2 Sol via GitHub Copilot, high reasoning, interactive session with explicit approval to file). Source analysis, local reproduction, and issue text are AI-generated.
Activity
github-actions commentedon Nov 19, 2026
I’m blocked on the fix stage for this issue because there is currently no workflow-authored bug assessment comment to implement from (the expected
**Bug assessment — <slug>:** ...contract was not found in the issue comments).Please run the assessment stage first (apply/re-apply the
bug-assesslabel so thebug-assessworkflow can post its assessment comment), then re-run thebug-fixstage.I also checked for the
needs-assessmentlabel in this repository, but it does not currently exist, so I could not apply it.github-actions commentedon Nov 19, 2026
Bug assessment — resume-stuck-running: Valid · severity medium
Bug Assessment: A workflow log write failure can leave a resumed run stuck as running
Report (summarized)
Issue author @markuswondrak reports that
specify workflow resumecan persiststatus: runningand then fail while appending tolog.jsonl; after repairing the log path, a second resume is rejected withCannot resume run ... with status 'running'.Reported reproduction: replace
.specify/workflows/runs/<run_id>/log.jsonlwith a directory, run resume (fails withIsADirectoryError), restore the log path, run resume again (fails due to persistedrunningstatus).Symptom
On resume, the run is marked and saved as
runningbefore later logging/error-handling writes complete. If log writing then fails, the persisted state can remainrunning, butresume()only allowspaused/failed, so the run becomes non-resumable without manual state repair.Reproduction
.specify/workflows/runs/<run_id>/log.jsonlwith a directory.specify workflow resume <run_id> --json.state.jsonstatus asrunning.log.jsonlfile path and rerun resume.Cannot resume run '<run_id>' with status 'running'.Suspected Code Paths
src/specify_cli/workflows/engine.py:1325-1326—resume()setsstate.status = RunStatus.RUNNINGand immediatelystate.save()before executing remaining steps.src/specify_cli/workflows/engine.py:1350-1351— on resume failure, it triesstate.append_log({"event": "resume_failed", ...})beforestate.save()of failed status.src/specify_cli/workflows/engine.py:1045-1047—RunState.append_log()appends in-memory and opensruns_dir / "log.jsonl"for append; a directory/symlink-policy error raises before failure status is checkpointed.src/specify_cli/workflows/engine.py:1261-1263—resume()rejects anything notpaused/failed, producingCannot resume run ... with status 'running'.tests/workflows/test_composition_execution.py:664-694— existing test already demonstrates analogous stuck-runningbehavior after checkpoint failure (test_checkpoint_failure_leaves_running_run_not_resumable), supporting merit of this class of failure.Root Cause Hypothesis
resume()persists a transitionalrunningcheckpoint too early, then performs log writes in both normal and exception paths that can raiseOSError/IsADirectoryErrorbefore any compensating checkpoint tofailed/pausedis saved. Because resume admission is strict (paused/failedonly), that partially-persisted transitional state is terminal for CLI resume. Confidence: high.Proposed Remediation
Preferred: make resume failure handling checkpoint-first (or failure-atomic) with respect to log writes. Concretely, in
resume()exception paths, updatestate.status/state.errorand persist withstate.save()before any best-effort logging ofresume_failed; if logging then fails, preserve and re-raise while keeping on-disk status resumable (failed). For successful completion, either (a) save terminal status beforeworkflow_finishedlog append, or (b) treat terminal log append failures as non-fatal to persisted run status (policy choice, but must not strand run inrunning).Alternatives (optional):
resume()to acceptrunningonly when execution metadata indicates interrupted checkpoint/logging transition; trade-off is more complex state model and potential masking of truly active runs.Files likely to change:
src/specify_cli/workflows/engine.pytests/workflows/test_composition_execution.pytests/specify_cli/workflows/test_command_resume.py(CLI-level regression)Tests to add or update:
log.jsonlis a directory (or equivalent log-write failure), first resume fails but persistsfailed(notrunning), and second resume after repair succeeds.Risks & Considerations
save()andappend_log()can affect event chronology inlog.jsonl; callers/tests asserting strict ordering may need updates.state.erroror CLI output._checkpoint_failed) and avoid introducing silent partial writes.Open Questions
resume()ever tolerate persistedrunningas a recoverable interrupted-transition state, or remain strict and rely on stronger checkpoint ordering only?]Fix resume-stuck-running: persist resume state before log writes
github-actions commentedon Nov 19, 2026
Pull request created: #5492
github-actions commentedon Nov 19, 2026
Opened draft PR #5492 for
resume-stuck-running: it makesworkflow resumepersistpaused/failed/completedstate before lifecycle log appends so log-write failures no longer strand runs asrunning, and adds resume regressions for recovery/terminal-state behavior.Please review the draft PR, then validate it in the stage-3
bug-testworkflow if your repository has that stage configured.[bug-fix] Fix resume-stuck-running: persist resume state before log w…