Skip to content

fix(runners): preserve terminal status when Run returns after emergency stop#3972

Draft
cursor[bot] wants to merge 1 commit into
developfrom
cursor/critical-bug-investigation-a5e4
Draft

fix(runners): preserve terminal status when Run returns after emergency stop#3972
cursor[bot] wants to merge 1 commit into
developfrom
cursor/critical-bug-investigation-a5e4

Conversation

@cursor

@cursor cursor Bot commented Jun 17, 2026

Copy link
Copy Markdown

Bug and impact

When a remote runner job is emergency-stopped via terminated_jobs (force stop, reassignment, or server-side terminal status), applyTerminatedJobs kills the process and sets the job to stopped. If job.Run() then returns a non-nil error—as happens when the process is killed—the post-run handler could overwrite the correct terminal status with failed.

This can cause incorrect task status to be reported on the next progress sync, leading to user-facing status corruption (stopped/success tasks shown as failed) and incorrect downstream behavior (alerts, workflow progression).

Root cause

Commit 2a156b30 (fix(runners): logs) moved the IsFinished() early return into the success-only branch of the post-Run() handler. The error path no longer respected an already-terminal status set by applyTerminatedJobs.

Fix

  • Extract finalizeAfterRun on runningJob with an IsFinished() guard that applies to both error and success paths.
  • Add regression tests covering emergency-stop + error unwind, normal failure, success, and graceful stop.

Validation

  • go test ./services/runners/...
Open in Web View Automation 

…cy stop

Commit 2a156b3 moved the IsFinished() early return into the success-only
branch of the post-Run handler. When applyTerminatedJobs kills a job and
sets stopped while Run() is still unwinding, the error path overwrote the
correct terminal status with failed.

Restore the finished-status guard for both branches via finalizeAfterRun.

Co-authored-by: Denis Gukov <fiftin@outlook.com>
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.

1 participant