fix(reconcile): gate the provider relay restart on its own depends_on

Copilot review finding on #14296: planProviderRelayRestart's node was
added as a sibling of the provider's own startPhaseDependencies, not
their dependent. Under pure ScopeStart there is no Create->Start
barrier separating a provider from its siblings the way ScopeCreateStart's
OpRunProvider gets one for free (always a create-phase node, run to
completion before any start-phase node begins) -- so a stopped relay
with a required depends_on condition could start immediately,
concurrently with (or before) that condition's own wait resolving.

planProviderRelayRestart now takes the provider's own depNodes
(startPhaseDependencies' result, already computed by the caller) and
passes them through as the restart node's own DependsOn, exactly like
an ordinary service's bare-restart-under-ScopeStart already does via
its replica chain's `prev := depNodes`.

New regression test TestPlanStart_ProviderRelayRestartWaitsOnDependencies,
verified by ablation (dropping the deps argument reproduces the
missing edge deterministically, 3/3 runs).

Verified: go build, go test ./pkg/compose/..., 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).

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
Nicolas De Loof 2026-10-07 16:29:16 +02:00 • committed by Guillaume Lours
parent 2969e964a8
commit 6efb45c866
2 changed files with 56 additions and 3 deletions

View file

@ -1405,7 +1405,7 @@ func (r *reconciler) planProviderStart(service types.ServiceConfig) error {
// rebuild): that is an explicit request to leave it alone, not the
// create phase never having run, so it must not fall through to
// planProviderRelayRestart.
if restart := r.planProviderRelayRestart(service); restart != nil {
if restart := r.planProviderRelayRestart(service, depNodes); restart != nil {
ends = append(ends, restart)
}
}
@ -1423,7 +1423,14 @@ func (r *reconciler) planProviderStart(service types.ServiceConfig) error {
// never a redeploy -- ensureServiceRelay's own convergence stays a create-phase
// concern, triggered by OpRunProvider, which a caller needing it re-run
// (e.g. config drift) gets via ScopeCreateStart, not this.
func (r *reconciler) planProviderRelayRestart(service types.ServiceConfig) *PlanNode {
//
// deps is the provider's own startPhaseDependencies: under pure ScopeStart
// there is no Create->Start barrier separating this provider from its
// siblings (unlike ScopeCreateStart's OpRunProvider, always a create-phase
// node), so without its own depends_on wired in here, the relay could start
// before a required dependency's health/condition wait resolves -- a Copilot
// review finding on the first version of this fix.
func (r *reconciler) planProviderRelayRestart(service types.ServiceConfig, deps []*PlanNode) *PlanNode {
for i := range r.observed.Containers[service.Name] {
oc := &r.observed.Containers[service.Name][i]
if !isRelayContainer(oc.Summary) || oc.State == container.StateRunning {
@ -1435,7 +1442,7 @@ func (r *reconciler) planProviderRelayRestart(service types.ServiceConfig) *Plan
ResourceID: resID,
Cause: "start",
Container: &oc.Summary,
}, startGroupID(resID))
}, startGroupID(resID), deps...)
node.Phase = PhaseStart
return node
}

View file

@ -817,6 +817,52 @@ func TestPlanStart_ProviderRelayRestartRespectsSkipProviders(t *testing.T) {
assert.Equal(t, len(plan.Nodes), 0, "SkipProviders must leave a stopped relay untouched:\n%s", plan)
}
// TestPlanStart_ProviderRelayRestartWaitsOnDependencies is a regression test
// for a Copilot review finding on planProviderRelayRestart: under pure
// ScopeStart there is no Create->Start barrier separating a provider from
// its siblings (unlike ScopeCreateStart's OpRunProvider, always a
// create-phase node run to completion before any start-phase node begins).
// Without its own depends_on wired into the relay-restart node, a stopped
// relay could start before a required dependency's health condition
// resolved.
func TestPlanStart_ProviderRelayRestartWaitsOnDependencies(t *testing.T) {
db := types.ServiceConfig{Name: "db"}
db.HealthCheck = &types.HealthCheckConfig{Test: []string{"CMD", "true"}}
prov := serviceWithDeps("prov", types.DependsOnConfig{
"db": {Condition: types.ServiceConditionHealthy, Required: true},
})
prov.Provider = &types.ServiceProviderConfig{Type: "test"}
project := &types.Project{
Name: "myproject",
Services: types.Services{"db": db, "prov": prov},
}
dbHash, err := serviceHashWithResolvedRefs(db, nil)
assert.NilError(t, err)
observed := emptyObserved()
observed.Containers["db"] = []ObservedContainer{observedServiceContainer("db", 1, container.StateRunning, dbHash)}
relay := observedServiceContainer("prov", 1, container.StateExited, "")
relay.Summary.Labels[api.RelayLabel] = "relay-abc123"
observed.Containers["prov"] = []ObservedContainer{relay}
plan, err := reconcile(t.Context(), project, observed, startScopeOptions(ScopeStart), noPrompt)
assert.NilError(t, err)
var wait, restart *PlanNode
for _, n := range plan.Nodes {
switch {
case n.Operation.Type == OpWaitCondition:
wait = n
case n.Operation.Type == OpStartContainer && n.Operation.ResourceID == "service:prov:1":
restart = n
}
}
if wait == nil || restart == nil {
t.Fatalf("expected db's wait node and prov's relay restart node:\n%s", plan)
}
assert.Assert(t, slices.Contains(restart.DependsOn, wait),
"the relay restart must depend on prov's own depends_on wait, not start unconditionally:\n%s", plan)
}
// An optional (required: false) condition marks the shared wait node
// best-effort — a missing dependency is skipped, not fatal; one required
// dependent upgrades the node for everyone.