Skip to content

feat: a playbook job can be paused and resumed - #47

Merged
blaipr merged 5 commits into
mainfrom
feat/pause-resume
Dec 2, 2026
Merged

blaipr merged 5 commits into
mainfrom
feat/pause-resume

Conversation

@blaipr

@blaipr blaipr commented Dec 2, 2026 •

Copy link
Copy Markdown
Member

Part of ansibleforms/ansibleforms 7.10.0 pause and resume (ansibleforms/ansibleforms#1625, ansibleforms/ansibleforms#1626).

A playbook job on a Go Runner can now be paused and resumed as on the controller's own Node.js Runner: the playbook finishes the task it runs, holds before its next one with its process alive, and goes on there after a resume. A playbook whose container is lost (its host rebooted) can start again at its first unfinished task from its checkpoints. The socket contract stays 3, so the controller works with it unchanged.

Protocol messages handled

  • pause (controller to Runner): { jobId, paused, by }. paused: true holds the playbook before its next task, false lets it go on; by is who asked (the plugin prints "Paused by" and "Resumed by"). A pause for a job the Runner does not run is left, a pause that comes while the container starts is written once it runs.
  • hello now says paused: the jobs it holds paused, so the controller node that takes its socket resumes the ones it no longer wants paused. The pauses are kept in pauses.json beside the spools, so a restarted Runner says them too and writes them again on the containers it follows.
  • Items paused (after, next) and resumed: the af_events plugin's pause and resume events, taken out of the events in their place, as writeEventsAndPauses does.
  • Item checkpoints (sealed): the plugins' facts, variables and progress, sealed for the controller in the job's container with the job's own key (HKDF of the token and the job id, the same key the controller's bundles use). The container never gets the Runner's token.
  • run with resume: opened like the secrets; the playbook starts at --start-at-task, its failed hosts left out of its limit, its facts (af_facts cache plugin) and variables (af_events) restored. A resume that does not open refuses the job.

How it works in each mode

The Runner has no shared disk with a job's container, so the pause travels into it: the agent in the container makes or removes the playbook's pause file, which the af_events plugin polls before each task. How the pause gets to the agent depends on the engine (Engine.Send):

  • Docker and Podman: an exec of the Runner's own binary in the container (ansibleforms-rte-runner control <line>), which writes the line on the job's control pipe (a named pipe the agent reads). Podman closes a container's stdin once its first attach ends, whatever StdinOnce says, so the stdin cannot carry it there; the exec works the same on both and after a Runner restart.
  • Kubernetes (a pod per job): the line is written on the pod's stdin after the job, through an attach of its own; the pod keeps its stdin open (stdinOnce: false). No new permission: pods/attach create and get were there already (no pods/exec).

Limitations:

  • A job started on Kubernetes by an earlier Runner version (its pod's stdin closed after the job) cannot be paused after the upgrade: the pause does not reach it and the job runs on. On Docker and Podman any running job can.
  • A paused job that is aborted, or aborted by the controller's pause time limit, stops as any aborted job (its container stopped).
  • The controller has no refusal message for a pause: a pause that cannot reach a job is logged by the Runner, and the job runs on with its pause asked.

Other changes

  • The af_events plugin of 7.10.0 and the new af_facts cache plugin are shipped unchanged.
  • PAUSED_JOBS_CRON and JOB_PAUSE_MAX_HOURS are kept out of a playbook's environment, as the controller does.
  • A control command of the binary (used inside a job's container only).
  • CI: a pause and resume e2e on Docker, Podman and Kubernetes (TestRealPause); on Docker and Podman it also starts a playbook again from checkpoints and checks it begins at its second task with the variable they restore.

Tests keep statement coverage at 100.0%.

The af_events callback plugin and the af_facts cache plugin of the
controller's 7.10.0, a job's own key that seals its checkpoints, and
the controls that come on a job's stdin after it.
The agent makes or removes the playbook's pause file as the pauses and
resumes come on its stdin, says the plugin's pause and resume as items,
sends its checkpoints sealed, and starts a playbook again at its first
unfinished task with what its checkpoints restore.
Docker, Podman and Kubernetes start a job's container with its stdin
left open after the job (StdinOnce false), and Send writes a pause or a
resume on it through an attach of its own.
It handles the controller's pause message, says the jobs it holds
paused in its hello, keeps them on disk across a restart, and opens a
run message's resume for a playbook that starts again from its
checkpoints.
Podman closes a container's stdin once its first attach ends, whatever
StdinOnce says. On Docker and Podman a pause or a resume is now handed
to the job by an exec of the Runner's control command, which writes it
on the job's control pipe; the containers keep StdinOnce true.
Kubernetes keeps writing it on the pod's stdin.
@blaipr
blaipr merged commit 7e09d49 into main Dec 2, 2026
10 checks passed
@blaipr
blaipr deleted the feat/pause-resume branch December 2, 2026 23:04
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