feat: thread a context through Plan and Execute - #503
Merged
josegonzalez merged 1 commit intoAug 31, 2026
Conversation
A task had no way to be cancelled. `Plan()` and `Execute()` took no arguments, so every task bottomed out in a `context.Background()` manufactured inside `subprocess`, and a long `git:sync`, a slow `letsencrypt:enable`, or an SSH connection that hung after the TCP handshake ran to completion no matter what the caller wanted. Both methods now take a context, as do the shared plan helpers, the `apply` closure on `PlanResult`, and the exporters. The closure takes one rather than capturing the one `Plan()` ran under, since `ExecutePlan` invokes it separately and should hand it the caller's current context. `DispatchPlan` keeps its argument-free branch signature and the branches capture the context lexically. The signal handler moves with it. Every subprocess call used to register its own handler with `signal.Notify` and never call `signal.Stop`, leaking a goroutine, a channel registration and a derived context per dokku command, and cancelling only the child in flight - so an interrupt aborted one task and the run marched on to the next. One `signal.NotifyContext` in `main.go` now cancels the run context instead: `apply` and `plan` stop at the next task, report `run cancelled`, and exit 1 rather than the `--detailed-exitcode` code for "completed with changes". A second interrupt kills the process, which was previously impossible. Nothing about the transport changes. The host, sudo setting and host-key policy still come from the package globals; making those per-invocation is #423, which this makes possible. Refs #424.
josegonzalez
force-pushed
the
424-thread-a-context-context-through-plan-and-execute
branch
from
August 31, 2026 05:17
05afa92 to
638c434
Compare
josegonzalez
deleted the
424-thread-a-context-context-through-plan-and-execute
branch
August 31, 2026 06:55
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.
A task had no way to be cancelled.
Plan()andExecute()took no arguments, so every task bottomed out in acontext.Background()manufactured insidesubprocess, and a longgit:sync, a slowletsencrypt:enable, or an SSH connection that hung after the TCP handshake ran to completion no matter what the caller wanted. Both methods now take a context, as do the shared plan helpers, theapplyclosure onPlanResult, and the exporters. The closure takes one rather than capturing the onePlan()ran under, sinceExecutePlaninvokes it separately and should hand it the caller's current context.DispatchPlankeeps its argument-free branch signature and the branches capture the context lexically.The signal handler moves with it. Every subprocess call used to register its own handler with
signal.Notifyand never callsignal.Stop, leaking a goroutine, a channel registration and a derived context per dokku command, and cancelling only the child in flight - so an interrupt aborted one task and the run marched on to the next. Onesignal.NotifyContextinmain.gonow cancels the run context instead:applyandplanstop at the next task, reportrun cancelled, and exit 1 rather than the--detailed-exitcodecode for "completed with changes". A second interrupt kills the process, which was previously impossible.Nothing about the transport changes. The host, sudo setting and host-key policy still come from the package globals; making those per-invocation is #423, which this makes possible.
Refs #424.