Commit graph

28 commits

Author SHA1 Message Date
Nicolas De Loof
05e47b3065 docs(compose): drop the stale imperative-engine references of the tests
Same cleanup as the previous commit, for the comments of the unit tests:
they cite startService, isNotRunning and the "old imperative engine" as
the source of a behavior the plan now owns.

Comments only: the token stream of every Go file, comments excluded, is
unchanged.

Part of #14081

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
2026-10-27 11:20:26 +01:00
hiroto.toyoda
b1375cbd97 test(executor): stop timing the caller's cancel against the wait's first inspection
Signed-off-by: hiroto.toyoda <hiroto.toyoda@dena.com>
2026-10-27 11:06:08 +01:00
hiroto.toyoda
385ee60741 fix(up): check a depends_on condition before the first poll tick
Signed-off-by: hiroto.toyoda <hiroto.toyoda@dena.com>
2026-10-27 11:06:08 +01:00
Nicolas De Loof
d713e11a2c refactor(executor): hand the hook-log listener to runStart only
Some checks are pending
ci / validate (lint) (push) Waiting to run
ci / validate (relay-lint) (push) Waiting to run
ci / validate (relay-test) (push) Waiting to run
ci / validate (validate-docs) (push) Waiting to run
ci / validate (validate-go-mod) (push) Waiting to run
ci / validate (validate-headers) (push) Waiting to run
ci / validate (validate-mocks) (push) Waiting to run
ci / binary (push) Waiting to run
ci / binary-finalize (push) Blocked by required conditions
ci / bin-image-test (push) Waiting to run
ci / relay-image-test (push) Waiting to run
ci / test (push) Waiting to run
ci / e2e (plugin, oldstable, graphdriver) (push) Waiting to run
ci / e2e (standalone, oldstable, graphdriver) (push) Waiting to run
ci / e2e (plugin, stable, containerd) (push) Waiting to run
ci / e2e (plugin, stable, graphdriver) (push) Waiting to run
ci / e2e (standalone, stable, containerd) (push) Waiting to run
ci / e2e (standalone, stable, graphdriver) (push) Waiting to run
ci / coverage (push) Blocked by required conditions
ci / ci-ok (push) Blocked by required conditions
ci / release (push) Blocked by required conditions
merge / bin-image-prepare (push) Waiting to run
merge / bin-image (push) Blocked by required conditions
merge / relay-image (push) Waiting to run
merge / module-image (push) Waiting to run
Scorecards supply-chain security / Scorecards analysis (push) Waiting to run
zizmor / zizmor (push) Waiting to run
Epic #14081 moved the start phase into the plan engine. Since #14302 and
#14305, a caller that streams pre_start/post_start hook logs into an attached
session hands its listener to planRun.runStart when it enters the Start phase,
because its printer only exists once the Create phase is done. As a result
every production caller builds the executor with a nil listener, and only a
few tests still passed one at construction; runStart kept a "nil keeps the
construction-time listener" branch just for them.

Drop the listener parameter of newPlanExecutor and make runStart the only way
to give the executor a listener (nil means hook logs are not streamed). The
doc comments that described a construction-time listener now describe that
single path. Production behavior is unchanged.

In tests, the one that fed a listener at construction sets it on the executor
it exercises, the two that only pinned "construction-time listener kept or
replaced" are removed, and a test pins that a nil listener leaves hooks
running without one.

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
2026-10-26 17:17:16 +01:00
Nicolas De Loof
b601c0721f test(up): pin the monitor and the Create phase of interactive up, fix stale comments
Tests:
- the monitor goroutine runs before the Start phase: a fake container start
  holds until the events subscription is opened, so a Start phase run before
  it would show;
- an interruption met by the Create phase ends the up with it and sets up no
  session: the phase runs on the caller's context.
Both were found by mutation to survive the existing tests.

Comments and scenarios:
- useAPISocket's guard says what a second pass really does: duplicate volume
  and config entries that also change the service's config hash;
- the interactive up's doc says an early interruption starts nothing, the
  readDaemonTime's that callers decide how to report an interruption, and a
  test comment on the listener no longer announces what is already wired;
- the use_api_socket scenario links docker/compose#14386, as SCENARIO.md asks
  of a regression test, and the hook-runner scenario drops an output assertion
  its ExitCode already covers.

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
2026-10-26 16:28:51 +01:00
Nicolas De Loof
a5d9b3362d refactor(executor): let a caller drive the create and start phases itself
run() walked both phases in one call, keeping the state they share local
and unreachable. Split it into begin, which prepares the run without
dispatching anything, and a planRun whose runCreate and runStart each
dispatch their own phase, so a caller can act between the two -- the
interactive up will set up its attach/printer/monitor session there.

run() is now begin followed by both phases, so every existing caller
behaves as before. The start phase takes its hook-log listener when it is
entered, since an attached caller only has one once its session exists,
and refuses to run before a successful create phase or twice, keeping the
create-phase barrier intact for callers that drive the phases themselves.

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
2026-10-26 12:32:04 +01:00
Nicolas De Loof
d30a1e729c fix(executor): keep a given up group's final event last
A start node whose group another node gave up while it was getting a slot
no longer goes on: it would emit a Working event after the group's final one,
and leave the row on it. The reason a node reads when it is given up now
follows its prerequisites through the chain (wait, start, post_start), so
that it does not depend on which node of the chain reports first, and a
post_start is only reported as started when its start succeeded.

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
2026-10-26 09:54:25 +01:00
Nicolas De Loof
d099a67bb8 fix(executor): name the failed wait and close every row a failed start leaves
Follow-up to the report of the services a failed start interrupts:

- When it is the wait itself that fails (the dependency is unhealthy, or
  exited with an error), the held service reads which condition was not met
  instead of an interruption by the internal name of the wait node.
- Only the start phase reports what it gives up: the create phase stays
  silent as before.
- An inspection cut short by the cancellation ends the wait as interrupted,
  and no longer marks the healthy dependency as failed. A caller canceled
  (Ctrl-C) at that point ends the wait as it always did.
- Two nodes failing together each end their own row with their own error,
  whichever one cancels the phase, instead of leaving one on "Starting" or
  reading "interrupted" for a failure that was its own.
- A replica whose start is behind it reads that only its post_start hooks
  were interrupted.

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
2026-10-26 09:54:25 +01:00
Nicolas De Loof
9a2d0d94ca fix(executor): report the services a failed start interrupts
When a node of a plan phase fails, the executor cancels the whole phase.
The nodes it interrupts, or had not dispatched yet, got no final event:
a service recreated by the command and held by a depends_on wait stayed on
"Recreated", as if it were up, and the row of the dependency it was
waiting for stayed on "Waiting". Nothing said the service was left created
and never started.

Such a node now ends on an Error event, "not started" when its group never
reported Working, which names the depends_on condition it was held by and
the resource whose failure interrupted the phase. A wait interrupted that
way is a failure of its own (the condition was not reached) and closes the
"Waiting" rows of its dependency with a Skipped event. A phase canceled by
its caller (Ctrl-C) is reported as before: silently.

docker/compose#14372

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
2026-10-26 09:54:25 +01:00
Nicolas De Loof
ea2284d712 fix(pre_start): capture a hook's output by opening its log stream once started
A pre_start hook's output never reached anyone. The follow log stream was
opened on the runner while it was still in "created" state, before
ContainerStart; the engine ends such a stream at once, empty. So a foreground
up never showed the hook's output, and the error of a failing hook carried no
tail, though both are built from that stream.

The stream is now opened once the hook is started. The runner is retained
after it exits (AutoRemove is off), so a fast-exiting hook cannot make the
stream hit a 404, which is what opening it first was meant to prevent. Once the
hook has exited, the stream gets a short, bounded delay to deliver what the
daemon buffered before it is cut, instead of being cut right away.

The unit tests that pinned the old call order now pin the new one, and a
scenario locks that a failing hook reports what it printed.

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
2026-10-16 15:11:33 +02:00
Nicolas De Loof
280f6a454d test(start): pin how start() wires its plan and the provider start path
Some checks are pending
ci / validate (lint) (push) Waiting to run
ci / validate (relay-lint) (push) Waiting to run
ci / validate (relay-test) (push) Waiting to run
ci / validate (validate-docs) (push) Waiting to run
ci / validate (validate-go-mod) (push) Waiting to run
ci / validate (validate-headers) (push) Waiting to run
ci / validate (validate-mocks) (push) Waiting to run
ci / binary (push) Waiting to run
ci / binary-finalize (push) Blocked by required conditions
ci / bin-image-test (push) Waiting to run
ci / relay-image-test (push) Waiting to run
ci / test (push) Waiting to run
ci / e2e (plugin, oldstable, graphdriver) (push) Waiting to run
ci / e2e (standalone, oldstable, graphdriver) (push) Waiting to run
ci / e2e (plugin, stable, containerd) (push) Waiting to run
ci / e2e (plugin, stable, graphdriver) (push) Waiting to run
ci / e2e (standalone, stable, containerd) (push) Waiting to run
ci / e2e (standalone, stable, graphdriver) (push) Waiting to run
ci / coverage (push) Blocked by required conditions
ci / ci-ok (push) Blocked by required conditions
ci / release (push) Blocked by required conditions
merge / bin-image-prepare (push) Waiting to run
merge / bin-image (push) Blocked by required conditions
merge / relay-image (push) Waiting to run
merge / module-image (push) Waiting to run
Scorecards supply-chain security / Scorecards analysis (push) Waiting to run
zizmor / zizmor (push) Waiting to run
Cover what the removed imperative tests used to: a no-op start is silent and
only lists containers, --wait-timeout bounds the dependency waits, secrets and
configs are injected before ContainerStart, a failing post_start fails the
start, pre_start is skipped on a stale relay, deploy.replicas: 0 starts
nothing, and the project-wide no-container check. On the provider path: the
restart is a chain end, a relay gets no post_start, pre_start is gated on
running replicas and runs once, before the chain, after the dependencies.

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
2026-10-16 10:52:52 +02:00
Nicolas De Loof
97943ec9fb fix(executor): record a dependency wait canceled by its phase as a failure
A node that leaves its dependency wait because its phase was canceled
closes its done channel (deferred) without recording any failure. In
X -> A -> B with X failing, B could select done[A] before it saw the
cancellation, find no failure recorded for A, emit its "Starting" event
and enter executeNode on a canceled context, leaving the row never
finalized.

Record the cancellation as the node's failure at that exit, so a
dependent that wins the race is skipped like any other dependent of a
failed node. The regression test pins GOMAXPROCS to 1, which makes the
bad interleaving the usual one.

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
2026-10-15 14:52:20 +02:00
Nicolas De Loof
cdbfe54617 test(executor): bound the phase-cancellation test with its own deadline
Copilot review finding on #14300: if a sibling Create-phase failure ever
stopped canceling the other node, VolumeCreate's mock blocks on its ctx
while exec.run waits for it, so the test's own five-second guard could
never fire and the regression would hang until the suite-wide timeout.
Give run a deadline of its own and assert the cancellation is the
sibling's (context.Canceled), not that fallback.

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
2026-10-15 14:52:20 +02:00
Nicolas De Loof
23d3081f55 fix(up): report a depends_on wait timeout as a dependency timeout, with --wait too
Copilot review finding on #14296: a wait node's own timeout is a
depends_on condition that did not become satisfied during the plan, not
the final --wait readiness check, which runs after the plan and has its
own "application not healthy" translation. The imperative path reported
"timeout waiting for dependencies" for the former regardless of --wait,
but translateWaitTimeout rewrote it as "application not healthy" when
--wait was set. It now always reports the dependency timeout.

Also mark the test nodes that stand for the Start phase as PhaseStart
(the recreate-then-start plan and the wait whose timeout survives a
skipped dependent), so they exercise the Create->Start barrier the way
the reconciler's plans do instead of running everything in one phase.

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
2026-10-15 14:52:20 +02:00
Nicolas De Loof
9a4983a34a fix(executor): mark a wait node's own timeout instead of guessing from DeadlineExceeded
up translated any DeadlineExceeded surfacing from the plan into "timeout
waiting for dependencies" or "application not healthy" whenever
--wait-timeout was set, even one coming from an engine call, a hook or
the secret injection, none of which is a dependency-readiness failure.

A wait node whose own --wait-timeout window expired now returns
errWaitTimeout (still satisfying DeadlineExceeded), and up keys its
message on that. A deadline inherited from the caller is never marked.

The test that checks --wait-timeout does not leak into non-wait nodes now
inspects the context those nodes receive, instead of a mock that would
have succeeded either way.

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
2026-10-15 14:52:20 +02:00
Nicolas De Loof
ebe25e3232 fix(executor): tell an optional wait's own timeout from an inherited deadline
Copilot review finding on #14290: waitDependency decided whether a
DeadlineExceeded on an optional dependency wait was safe to tolerate
using a bare boolean -- whether the caller had configured a timeout
for this wait at all (exec.waitTimeout > 0, or legacy waitDependencies'
timeout > 0). That can't distinguish THIS call's own timeout actually
firing from an earlier deadline inherited from the caller's own ctx
also firing: context.WithTimeout(parent, waitTimeout) still makes both
parent and child report DeadlineExceeded once the parent's earlier
deadline elapses, even though this wait's own timer never got there.
An unsatisfied optional wait could therefore swallow a real external
deadline (the process's own context, a test harness timeout) and
report success instead of propagating it.

Replaced the bool with an origCtx snapshot -- ctx as it stood right
before this call's own conditional context.WithTimeout wrap -- threaded
from executor.go's OpWaitCondition dispatch through execWaitCondition
down to waitDependency, and from waitDependencies' own wrap in
service_containers.go. waitDependency now checks origCtx.Err() == nil
at the moment ctx.Done() fires: only when the pre-wrap context hasn't
failed on its own is this wait's own timeout the one responsible.

TestExecutePlanOptionalWaitDoesNotSwallowInheritedDeadline pins the
negative case (inherited deadline must still propagate even though
exec.waitTimeout is set and the dependency is optional) and
TestExecutePlanOptionalWaitTimeoutIsToleratedWithoutInheritedDeadline
pins the positive one (this wait's own timeout, no inherited deadline,
still tolerated as before) -- both verified by ablation.

Verified: go build, go test ./pkg/compose/... (full suite, not just the
new tests) and golangci-lint clean. Local Copilot CLI review confirmed
the origCtx threading is correct and race-free across all three call
sites; its one actionable finding (missing positive-path coverage for
the plan-executor route specifically) is addressed by the second new
test above.

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
2026-10-15 14:52:20 +02:00
Nicolas De Loof
19aa3d8604 fix(executor): make Create->Start a hard sequential barrier
run() used to dispatch every node concurrently, with Create-phase and
Start-phase cancellation scoped separately via phaseCancel so a
Start-phase failure couldn't cancel unrelated in-flight Create work.
That stopped short of what the interactive up convergence (lot 2's
next step) actually needs: its attach/printer session takes exclusive
hold of the terminal for the Create phase's own progress display, and
hands it over to continuous container log streaming only once the
Create phase is entirely done project-wide -- a Start-phase node's log
output interleaving with Create's progress bars has nowhere consistent
to go. Phase-scoped cancellation alone still let an unrelated
Start-phase node begin (and start logging) while a sibling elsewhere
in the plan was still being created, or had just failed.

run() now splits plan.Nodes into createNodes/startNodes upfront and
runs them as two fully sequential runPhase() calls: Start-phase nodes
are never even dispatched until every Create-phase node has succeeded,
and a Create-phase failure returns immediately without calling
runPhase on startNodes at all. This matches the old create()-then-
start() sequence's own fail-fast behavior, which the single-plan
migration had implicitly relaxed.

Added a fast-fail validation: a Create-phase node depending on a
Start-phase node would otherwise deadlock forever (the Start phase
isn't dispatched until the Create phase blocked on it returns, so
nothing would ever close that dependency's done channel). Nothing in
the reconciler should produce that edge, but failing fast with a clear
error beats a silent hang if it ever does.

TestExecutePlanCreatePhaseIsABarrierBeforeStartPhase and
TestExecutePlanCreatePhaseFailureNeverDispatchesStartPhase cover both
directions of the barrier; both verified by ablation (reverting to a
single concurrent runPhase call reliably fails each, 5/5 runs).

Verified: go build, go test ./pkg/compose/... (incl. -race), and
golangci-lint all clean; full e2e suite re-run clean against a locally
built binary (same 3 pre-existing, environment-specific failures as
the stack's baseline: TestWatch, TestIPC, TestComposeModel). Local
Copilot CLI review found no correctness/deadlock issues in the barrier
logic itself; its two actionable findings (missing phase-ordering
guard, missing never-dispatched regression test) are both addressed
here.

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
2026-10-15 14:52:20 +02:00
Nicolas De Loof
382383d0c5 fix(executor): make phase cancellation race-free end to end
Three related findings from Copilot and docker-agent on the
phase-scoped cancellation commit, all stemming from the same root
cause: switching run() from errgroup.WithContext's own atomic
cancel-with-error-record to an explicit, separate cancelPhase() call
reopened timing windows that errgroup.WithContext used to close for
free.

- Copilot (high): cancelPhase() unblocks every sibling in that phase
  before this goroutine's own error reaches errgroup.Group's internal
  errOnce -- a sibling woken by the cancellation can return a bare
  context.Canceled of its own and win that race, hiding the actual
  daemon error or DeadlineExceeded (and making upDetached's own
  DeadlineExceeded translation unreliable with it).
- docker-agent (medium): the "is this my own genuine failure"
  nodeCtx.Err() == nil check and the cancellation it gates aren't
  atomic -- two genuinely concurrent same-phase failures can both pass
  it before either's cancelPhase() takes effect, both emitting a group
  Error event for the same resource.
- docker-agent (medium): the dependency-wait loop's early return on
  ctx cancellation skipped close(rs.done[node.ID]), the only exit path
  that did. Not reachable today (every dependent in the same phase
  shares that phase's ctx, already canceled by the time it would
  matter), but latent: nothing in runNode enforces that no future
  cross-phase dependency edge ever relies on this channel closing.

All three close around one new type, phaseCancel, bundling a phase's
context/cancel pair with a sync.Once: the first node in a phase to
fail records its error and emits the group event inside that Once,
cancels the phase's context, and every later caller -- genuine
concurrent failure or cancellation casualty alike -- is a silent
no-op. run() returns a phase's recorded error over whatever
eg.Wait() itself picked, so errgroup's own race can no longer surface
a cancellation casualty's error in its place. The done-channel close
moved to a single `defer` at the top of runNode, covering every exit
path uniformly instead of three separate explicit calls.

TestExecutePlanConcurrentPhaseFailureKeepsOriginatingError exercises
the first scenario under real concurrency (one immediately-failing
node alongside many siblings a dependency-wait unblocks via its
cancellation) -- see its own comment for why this specific race can't
be forced to fail by ablation in an in-process test (the Go scheduler
never actually lets a sibling win it here), so the fix's correctness
rests on reading errgroup's own errOnce.Do source directly, confirmed
independently by two reviewers, not on this test alone.

Verified: go test -race -count=10 ./pkg/compose/... clean; full e2e
suite re-run clean against a locally built binary (same 3
pre-existing, environment-specific failures as the stack's baseline).

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
2026-10-15 14:52:20 +02:00
Nicolas De Loof
0fc3d8c1c6 fix(executor): scope plan cancellation to each node's own phase
Copilot review (High) on #14290: run() dispatched every node -- Create
and Start phase alike -- under one errgroup.WithContext(ctx), so any
node failing canceled the shared context for every other goroutine
still in flight. A required OpWaitCondition node hitting
--wait-timeout is a Start-phase failure that can now happen while
unrelated Create-phase work (a sibling service's container or network
create) is still legitimately running -- and that work got aborted
too, with nothing to do with the dependency that timed out. The old
create()-then-start() sequence never had this failure mode: the whole
create phase always finished completely before any dependency wait
even began.

run() now derives two contexts instead of one shared errgroup-context:
createCtx at the root, startCtx as its child. A node picks nodeCtx
(and the matching cancelPhase) from its own node.Phase and calls
cancelPhase() only on its own genuine failure. A Start-phase failure
cancels only startCtx, leaving createCtx and everything still running
under it untouched. A Create-phase failure still cancels the whole
plan, Start phase included, via startCtx's derivation from createCtx
-- matching the old sequence, where start() was never even invoked
once create() failed.

The node-goroutine body moved out of run()'s loop into a runNode
method (golangci-lint's cognitive-complexity limit after this change)
taking a new runState struct bundling the per-run bookkeeping every
node shares.

Two smaller, unrelated fixes bundled in:
- upDetached (up.go) keeps an origCtx snapshot so its two
  DeadlineExceeded-to-friendly-message checks can tell its own
  WaitTimeout window expiring apart from an inherited, unrelated
  parent deadline propagating through the derived context -- both
  report DeadlineExceeded on Err(), only the former earned the
  "application not healthy" framing.
- waitDependency (service_containers.go), shared by the old
  waitDependencies and the new execWaitCondition -- the latter can now
  produce a real deadline for the first time via exec.waitTimeout --
  tolerates a timeout on an optional (BestEffort) dependency the same
  way it already tolerates every other definitive failure: skipped
  with a warning, not a hard failure.

Two regression tests pin both cancellation directions:
TestExecutePlanStartPhaseFailureDoesNotCancelCreatePhase (a
Start-phase wait timing out must not cancel a concurrent, unrelated
Create-phase node) and TestExecutePlanCreatePhaseFailureCancelsCreatePhase
(a Create-phase failure must still fail-fast its Create-phase
siblings, same as before this change). Both verified by ablation.

Full e2e suite re-run clean against a locally built binary -- same 3
pre-existing, environment-specific failures as the stack's baseline,
no new ones.

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
2026-10-15 14:52:20 +02:00
Nicolas De Loof
c1c897fbbb fix(up): give each wait its own fresh --wait-timeout window
Copilot review ("previously missed", code unchanged since an earlier
round): the prior fix (applyRemainingDeadline) replaced a confusing
raw DeadlineExceeded with a clearer message, but kept the underlying
design flaw it was reacting to -- a single absolute deadline
(time.Now().Add(WaitTimeout)) shared across the whole plan and the
final verification. Slow, unrelated create/start/hook work (never
meant to be bounded by --wait-timeout -- that's the entire point of
exec.waitDeadline existing) could still exhaust that shared budget on
its own, failing an otherwise healthy deployment as "not healthy" with
no health wait ever actually timing out.

start()'s real behavior never had this failure mode: waitDependencies
opens a fresh context.WithTimeout(ctx, timeout) every time it's
called, so each dependency wait gets its own full WaitTimeout window,
independent of how long anything before it took.

planExecutor.waitDeadline (an absolute time.Time) becomes waitTimeout
(a time.Duration): executeNode's OpWaitCondition case now derives a
fresh context.WithTimeout per wait node instead of a shared
context.WithDeadline. upDetached mirrors this for the final
verification -- its own fresh WaitTimeout window, not whatever's left
of one. applyRemainingDeadline's already-expired-deadline problem
disappears by construction: there's no longer a precomputed deadline
to have already expired.

Also fixes two sibling DeadlineExceeded-translation sites (the
post-plan container listing and waitDependencies' own check) that were
missing the WaitTimeout > 0 guard: without a --wait-timeout set, ctx
can still carry an external deadline (an upstream command timeout, a
cancellation) unrelated to --wait-timeout, and naming "application not
healthy after 0s" would blame a duration nobody configured.

TestExecutePlanWaitDeadlineOnlyBoundsWaitNodes and
TestExecutePlanWaitConditionRespectsContextDeadline updated for the
field rename; both still pin their original scenarios under the new
mechanism. Verified against the full e2e suite (TestUpWaitTimeout,
TestUpWait, TestRestartWithDependencies, the provider suite) on a
locally built binary.

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
2026-10-15 14:52:20 +02:00
Nicolas De Loof
7fb78f42b2 fix(up): scope the wait deadline to OpWaitCondition nodes only
Copilot review (Medium): wrapping the whole run() ctx with
WaitTimeout also capped Create-phase and Start-phase work that was
never subject to --wait-timeout in the old create()+start() sequence
-- a slow image pull or container create/recreate could now fail as
"application not healthy" with no health wait involved.

planExecutor gains a waitDeadline field, consulted only in
executeNode's OpWaitCondition case to derive a deadline-bound context
for that one call; every other operation type keeps running on the
plan's plain ctx. upDetached now builds its own planExecutor directly
(instead of going through executePlan) so it can set waitDeadline
before calling run(), and reuses the same deadline for the final
post-plan verification instead of wrapping the whole plan's ctx.

TestExecutePlanWaitDeadlineOnlyBoundsWaitNodes pins this: a plan
pairing a never-satisfied OpWaitCondition with an OpCreateNetwork
confirms the network create isn't raced by the same short deadline.
Verified by ablation that removing the OpWaitCondition dispatch's
deadline derivation makes the test hang instead of failing promptly.

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
2026-10-15 14:52:20 +02:00
Nicolas De Loof
d8f2273ca8 fix(up): apply --wait-timeout before executing the plan, not after
Copilot review (High): the plan's own OpWaitCondition nodes
(service_healthy / service_completed_successfully dependency waits,
executed as part of executePlan) have no timeout of their own -- they
block on whatever ctx they're given, unlike the imperative engine's
waitDependencies, which already threaded WaitTimeout through every
per-dependency wait, not just the final --wait check. upDetached only
wrapped ctx with WaitTimeout around that final check, established
after executePlan already returned -- so a condition that's never
satisfied hung `up -d --wait --wait-timeout N` forever instead of
failing after N seconds.

Move the deadline to wrap ctx before executePlan runs (gated on
Wait && WaitTimeout > 0, matching start()'s own gating), and reuse the
same ctx for the final verification instead of opening a second,
independent WaitTimeout window -- one overall budget for "becoming
healthy" covering both the plan's in-flight waits and the final check.
preparePlan is deliberately left outside the deadline: image pulls and
the rest of create()'s own work were never bounded by --wait-timeout
in the old create()+start() sequence either.

Regression-tested at two levels:
- TestExecutePlanWaitConditionRespectsContextDeadline drives a real
  OpWaitCondition node through executePlan/run() under a short
  deadline and asserts it returns promptly with ctx.Err(), proving the
  deadline propagates into the plan's blocking nodes.
- The existing e2e TestUpWaitTimeout (up --wait --wait-timeout on a
  service that never turns healthy) is what actually exercises
  upDetached's own wiring: verified by ablation that reverting this
  fix makes it hang (test timeout) instead of failing after 3s.

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
2026-10-15 14:52:20 +02:00
Nicolas De Loof
4e9477da30 feat: detached up runs on a single plan
Detached `up` used to run create() then start() back to back: two
separate daemon snapshots, the second blind to what the first just
created or recreated. preparePlan already supports planning both
phases in one pass (ScopeCreateStart, landed across lot 1) -- this
wires it in for the one caller that can use it outright: `up -d`.

preparePlan gains an explicit scope parameter (ScopeCreate for
create(), unchanged); Up()'s detached branch now calls a new
upDetached, which runs preparePlan(..., ScopeCreateStart) +
executePlan once instead of create() + start(). --wait stays a
post-plan verification: it re-lists containers after the plan runs
(the plan may have created or recreated some, so the pre-execution
snapshot can't be reused for this) and runs the same waitDependencies
check start() already does.

Interactive up is untouched: it still runs create() then start() with
its printer/monitor listener wired in between, converging onto the
plan engine separately (a riskier, later item of the same lot).

ScopeCreateStart landed in lot 1 as inert code with no real caller;
this is the first one, and it surfaced two latent bugs in the
container-recreate path that nothing had exercised end to end before:

- planRecreateContainer plans a container's recreation as Create
  (under a temporary "<shortID>_<name>" to avoid colliding with the
  old container still holding the final name) -> Stop -> Remove ->
  Rename(final name). The start phase's event naming and container-ID
  resolution (groupEventName, resolveContainerID) read the create
  node's published result by design (plannedReplica keeps every
  start-phase reference pointed at CreateNodeID, not the rename node),
  but execRenameContainer never updated that result after renaming --
  so a recreated container's Starting/Started events kept reporting
  the temporary name forever.
- execCreateContainer also publishes the new container into
  containersByService (the live view OpWaitCondition reads for
  depends_on health waits) under that same temporary name, with
  nothing refreshing it after rename either -- a dependent waiting on
  the recreated container's health reported Waiting/Healthy under the
  temporary name too.

Both fixed in execRenameContainer: it now updates the create node's
pctx result in place after a successful rename, and (via a new
Service field on the rename Operation) patches the matching
containersByService entry's name too. Each pinned by a regression
test, verified by reverting the fix locally and confirming the test
catches it.

Verified with the full e2e suite (`go test -tags e2e ./pkg/e2e/...`)
against a locally built binary -- including TestRestartWithDependencies,
which is what caught both bugs in the first place -- plus the existing
unit suite and lint.

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
2026-10-15 14:52:20 +02:00
Nicolas De Loof
55a8a88265 fix(executor): a failed pre_start no longer lets start fire its own event
Two review findings on the same root cause:

- docker-agent: a failing OpRunPreStart emitted a bare Error with no
  preceding Working/Starting event, since triggersWorking only fires
  on OpStartContainer. onNodeError now emits the group's Working event
  first when it hasn't fired yet, keeping the progression well-formed.

- glours (following up on the docker-agent thread): worse than a
  missing event -- OpStartContainer's own goroutine was unblocked by
  <-done[dep.ID] and ran anyway, since close(done[node.ID]) races
  ahead of errgroup's cancel() (same TOCTOU class as the ctx.Err()
  guards already tracked under #14081, but deterministic here with the
  default unset --parallel limiter: no semaphore wait gives cancel()
  time to land first). It fired a second, spurious Starting right
  after the sibling's Error, with no further event ever closing it.
  Reproduced 143/143 iterations against this PR's own regression test.

run() now records each node's terminal error in a shared, mutex-guarded
map as it closes done[node.ID], and a dependent checks that map right
after its dependency wait, treating a genuine dependency failure
exactly like a context cancellation: no slot acquired, no event
emitted, its own failure recorded and propagated to its own
dependents the same way. This closes the event-ordering race outright
for this specific chain, rather than narrowing it like the existing
ctx.Err() guards -- those stay in place and still guard actual engine
calls, unrelated to event emission.

TestExecutePlanFailedPreStartGatesStart now asserts the full event
sequence (Creating, Created, Starting, Error — nothing after),
verified by reverting the executor.go fix locally and confirming the
test catches the reintroduced spurious Starting.

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
2026-10-06 14:11:22 +02:00
Nicolas De Loof
f07cdafc3e fix: execRunPreStart bails out on a canceled context
Same interim narrowing as execStartContainer and execRunPostStart: the
node hangs off the replica's create node, so when that create fails the
pre_start hooks could still fire in the window before errgroup cancels
the context. The structural fix stays tracked in #14081.

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
2026-10-06 14:11:22 +02:00
Nicolas De Loof
51532f6d02 docs: spell out that the ctx.Err() guards narrow the race, not close it
docker-agent's review of the previous commit's fix correctly pointed
out that the ctx.Err() guard added to execStartContainer/execRunPostStart
narrows the race it targets but does not eliminate it: close(done[...])
still runs inside the failing node's own goroutine, strictly before
errgroup's cancel() on that goroutine's returned error. A dependent
unblocked from <-done[dep.ID] can observe ctx.Err() == nil for a brief
window even though its dependency just failed for a genuine reason.

This is exactly the structural gap the epic (#14081) already flagged
in its "failed-dependency semantics" comment before this PR existed:
the real fix carries each node's success/failure through what
dependents wait on (e.g. a chan error) instead of inferring it from
ctx.Err(), uniformly across every operation type - including the
already-merged execCreateHookContainer, which has the same limit.
That is a dedicated brick of the executor lot, not squeezed into this
PR's diff.

No behavior change: this documents the residual window explicitly at
both guard sites and in the regression test, so the next reader (and
the next PR) doesn't mistake "narrows" for "closes".

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
2026-10-06 14:11:22 +02:00
Nicolas De Loof
de85d399ee fix: a failed pre_start/start no longer lets its dependent run
A node's done-channel closes strictly before errgroup cancels its
derived context on that same error - the close happens synchronously
inside the failing node's goroutine, ctx cancellation only after it
returns. A dependent blocked in run()'s
select { case <-done[dep.ID]: ...; case <-ctx.Done(): ... } therefore
always sees its dependency's done-channel ready first, regardless of
whether that dependency failed for a genuine reason or was cancelled.

execCreateHookContainer already guarded against exactly this. The two
other new dispatch functions from the previous commit did not:
execStartContainer's enriched branch could call ContainerStart right
after its OpRunPreStart failed for real (e.g. "no hook runner
container found"), contradicting pre_start.go's documented guarantee
that a non-zero hook exit gates service start - and symmetrically for
execRunPostStart after a failed OpStartContainer.

Both now bail out on ctx.Err() first, mirroring the existing guard.
Pinned by a regression test reproducing the race deterministically: no
ContainerStart expectation is registered, so the unguarded code calls
it from inside the errgroup worker goroutine, where gomock's missing-
expectation failure hangs the test binary instead of failing it
cleanly - a stronger tell than a plain assertion failure would have
been.

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
2026-10-06 14:11:22 +02:00
Nicolas De Loof
fc7c1efa4b feat: executor runs start-phase operations
Wire the plan executor to the start-phase vocabulary the reconciler
already produces (#14200): OpWaitCondition, OpRunPreStart, the enriched
OpStartContainer, and OpRunPostStart all had no case in executeNode
and hit "unknown operation type".

Every operation reuses the exact imperative primitive it mirrors —
waitDependency, runPreStart, runHook, injectSecrets/injectConfigs — so
behavior and events cannot drift between the two engines: execWaitCondition
resolves the dependency's live containers and hands off to the same
polling/condition-check functions waitDependencies uses; the enriched
OpStartContainer resolves its target either from the observed container
or, for a replica the plan itself creates, from the CreateContainer
node's result (the mechanism OpRenameContainer already relies on), then
injects secrets/configs before ContainerStart; OpRunPreStart re-checks
the daemon first so a replica that started in the observe-to-execute
window skips a redundant hook run.

A replica's pre_start/start/post_start chain shares one event group,
reporting a single Starting→Started progression exactly like
startServiceContainer does today — Starting fires specifically at
StartContainer, not at the (silent) pre_start hooks preceding it.
pkg/api/event.go documents this per-resource progression contract.

Still inert in production: create() (executePlan's only caller never
builds a plan with start-phase scope, so none of this runs outside
tests until a later brick in epic #14081 wires a real caller.
EOF
)

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
2026-10-06 14:11:22 +02:00