Skip to content

ci(run_command): allow --failed rerun to reuse EC2 on first-attempt failure#1179

Closed
yokofly wants to merge 1 commit into
developfrom
chore/run-command-failed-rerun-support
Closed

ci(run_command): allow --failed rerun to reuse EC2 on first-attempt failure#1179
yokofly wants to merge 1 commit into
developfrom
chore/run-command-failed-rerun-support

Conversation

@yokofly

@yokofly yokofly commented May 22, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Change stop-runner.if from always() to success() || cancelled() || github.run_attempt > 1. On a first-attempt execute-command failure the EC2 is left alive so gh run rerun --failed can land on the same machine.
  • Add a step-summary notice on first-attempt failure with the runner label, instance id, and the manual aws ec2 terminate-instances fallback for users who do not plan to rerun.

Motivation

The release build run #26276953469 failed in Build_Linux_Arm64 / Execute Command with a transient unknown blob error during docker push ghcr.io/timeplus-io/proton:${SHA}_arm64v8. Build, Docker Hub push, and most of the GHCR push had already succeeded — only the final GHCR layer push failed.

gh run rerun --failed was the natural next step, but it produced a hang on attempt 2:

  • start-runner (succeeded on attempt 1) was not re-executed
  • stop-runner (succeeded on attempt 1 because of if: always()) had already terminated the EC2 and deregistered the runner
  • execute-command (attempt 2) queued indefinitely waiting for a runner label that no longer maps to a live machine

GitHub Actions --failed rerun semantics intentionally skip already-successful upstream jobs and reuse their outputs. With ephemeral self-hosted runners that is a footgun: outputs are durable, EC2 instances are not.

Behavior table

run_attempt execute result stop-runner runs? EC2 lifetime
1 success yes (success() true) terminate
1 failure no (new) kept alive for --failed rerun
1 cancelled yes (cancelled() true) terminate
≥2 any yes (run_attempt > 1 true) terminate

Trade-off: a terminal first-attempt failure with no rerun leaks the EC2 until manual cleanup or a sweeper runs. The step-summary notice surfaces this with a copy-pasteable terminate-instances command.

Caveat for review

This assumes the yokofly/ec2-github-runner agent is not registered with --ephemeral. If it is, the runner agent exits after the first job regardless of EC2 lifetime, so keeping the instance alive still leaves no runner to pick up the re-queued execute-command. In that case --failed rerun would still hang and the right fix is also to disable ephemeral mode on the start side (or restart the agent on rerun).

Worth confirming against the pinned fork (522cb941f0d76565385ce7aeb6771bf58451ba1b) and AMI bootstrap before merge.

Test plan

  • Validate the YAML parses (done locally with python3 -c 'yaml.safe_load(...)')
  • Confirm runner mode (ephemeral vs. persistent) on the pinned fork
  • Once confirmed, force a transient failure in a feature workflow run and verify gh run rerun --failed lands on the same EC2 and succeeds
  • Confirm the step summary renders correctly on a failed Build_Linux_* job
  • Decide whether to add a scheduled sweeper for orphan EC2s (probably follow-up PR)

🤖 Generated with Claude Code

…ailure

`gh run rerun --failed` re-runs failed and skipped jobs but never re-runs
already-successful upstream jobs. In `run_command.yml`, `start-runner`
succeeds and `stop-runner` previously ran with `if: ${{ always() }}`, so
on first failure the EC2 was terminated even when the user planned to
rerun. The re-queued `execute-command` then waited forever for the
already-deregistered runner label.

Skip `stop-runner` on first-attempt `execute-command` failure so the EC2
(and its runner registration) survives long enough for `--failed` rerun
to land on the same machine. Subsequent attempts (`run_attempt > 1`)
always terminate, so a second failure does not leak the instance.

Add a step-summary notice on first-attempt failure pointing the next
reader at the rerun behavior and at the manual `terminate-instances`
fallback if no rerun is planned.

Caveat for review: this assumes the ec2-github-runner agent is not
registered with `--ephemeral`. If it is, the agent exits after the
first job regardless of EC2 lifetime, and `--failed` rerun would still
hang — in that case we also need to disable ephemeral mode or restart
the agent on rerun. Worth confirming against the AMI / fork before
merging.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@yokofly yokofly closed this May 22, 2026
@yokofly yokofly deleted the chore/run-command-failed-rerun-support branch May 22, 2026 12:35
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