carlos / platform Public

host: keep settle's not-up verdict for a show that fails to the deadline

Reverts the unknown-observation half of 888c4b88. Rolling the symlink
back and plain-starting the unit, which an unknown outcome would get,
leaves a new process that did come up running under the old link: the
round-1 P1's fault again. So a show that fails until the settle deadline
stays a UnitNotUpError, whose not-up recovery (reset-failed and restart)
replaces the process, as before this branch. With the 30 s query bound
that is what systemctl's own 25 s D-Bus timeout already produced.

errUnitUnobserved and checkedUnitRestart's branch are gone, with their
two tests. TestSettleShowErrorAtTheDeadline now pins the old rule for a
refused show and for one killed at its QueryTimeout. settleUnit and the
internal/systemd package comment name the follow-up (amadan discussion
#1214). Queries-only bounds, caps' %w, the guard and the counted
host-context sites stay.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 6b4c47eaa141f539fea5020506f62cb58bc54b93 parent c306f71
6 files changed, +25 −155
  • internal/host/rootrestart.go +0 −7
  • internal/host/settle_unobserved_root_test.go +0 −81
  • internal/host/{settle_unobserved_adopt_test.go => settle_verdict_adopt_test.go} +1 −24
  • internal/host/unitsettle.go +10 −27
  • internal/host/unitsettle_test.go +8 −15
  • internal/systemd/command.go +6 −1
diff --git a/internal/host/rootrestart.go b/internal/host/rootrestart.go
index 2429d33c0..b48302a30 100644
--- a/internal/host/rootrestart.go
+++ b/internal/host/rootrestart.go
@@ -272,13 +272,6 @@ func checkedUnitRestart(sys unitSystem, optDir string, getenv func(string) strin
if errors.Is(err, errRestartBinding) && !restartEffectFailed(err) {
return errors.Join(err, settleRollbackAttempt(s, attempt))
}
- if errors.Is(err, errUnitUnobserved) && !restartEffectFailed(err) {
- // Settle could not ask systemd about the unit: an unknown
- // observation, not a failed build. Settled like a stop, never
- // recorded failed or turned into a UnitNotUpError, so adoption
- // neither poisons the version nor runs the not-up recovery.
- return errors.Join(err, settleRollbackAttempt(s, attempt))
- }
attempt.Failed = true
var notUp *release.UnitNotUpError
if !errors.As(err, &notUp) {
diff --git a/internal/host/settle_unobserved_root_test.go b/internal/host/settle_unobserved_root_test.go
deleted file mode 100644
index 7d617aa97..000000000
--- a/internal/host/settle_unobserved_root_test.go
+++ /dev/null
@@ -1,81 +0,0 @@
-package host
-
-import (
- "encoding/json"
- "errors"
- "testing"
-
- "github.com/carlosframework/platform/internal/release"
- "github.com/carlosframework/platform/internal/rootstate"
-)
-
-// unobservedAfterRestart is plan14RestartUnits whose show fails once the
-// restart has been asked for: systemd took the job and then stopped
-// answering, so settle never sees the new invocation.
-type unobservedAfterRestart struct {
- *plan14RestartUnits
- restarted bool
-}
-
-func (u *unobservedAfterRestart) TryRestart(unit string) error {
- u.restarted = true
- return u.plan14RestartUnits.TryRestart(unit)
-}
-
-func (u *unobservedAfterRestart) Show(unit string) (unitProps, error) {
- if u.restarted {
- return unitProps{}, errors.New("Failed to get properties: Connection timed out")
- }
- return u.plan14RestartUnits.Show(unit)
-}
-
-// The root adopt pass's checked restart, when settle cannot observe the unit
-// by its deadline: the answer stays an unknown observation (not a
-// UnitNotUpError, temporary), and the rollback attempt is settled, not
-// recorded failed, so neither adoption nor a later root recovery treats the
-// build as one that crashed.
-func TestRootRestartUnobservedSettleIsNotAFailedAttempt(t *testing.T) {
- t.Parallel()
- e, rt, units, c, _ := plan14AdoptionFixture(t)
- sys := &unobservedAfterRestart{plan14RestartUnits: units}
- forward := rootRestartRouteWith(e.root.reg, sys, units.opt, func(string) string { return "5s" }, e.root.obs.recordSettled(e.bake), c)
- if err := release.StageArtifact(units.opt, "bab", "v2", "console", []byte("new build")); err != nil {
- t.Fatal(err)
- }
- if err := release.PointLive(units.opt, rt.Host, "bab", "v2", "console"); err != nil {
- t.Fatal(err)
- }
- err := forward(rt.Host)
- var nu *release.UnitNotUpError
- var temporary interface{ Temporary() bool }
- if err == nil || errors.As(err, &nu) || !errors.Is(err, errUnitUnobserved) {
- t.Fatalf("forward restart = %v, want the unknown observation, not UnitNotUpError", err)
- }
- if !errors.As(err, &temporary) || !temporary.Temporary() {
- t.Fatalf("forward restart = %v, want it temporary", err)
- }
- if !sys.restarted {
- t.Fatal("the restart was never asked for; the test proves nothing")
- }
- store, err := c.attempts()
- if err != nil {
- t.Fatal(err)
- }
- attempt := readAttempt(t, store, rt.Host)
- if attempt.Failed || !attempt.Settled {
- t.Fatalf("attempt = Failed %v Settled %v, want settled and not failed", attempt.Failed, attempt.Settled)
- }
-}
-
-func readAttempt(t *testing.T, s rootstate.Store, host string) rollbackAttempt {
- t.Helper()
- raw, err := s.Read(rollbackJournalKey(host))
- if err != nil {
- t.Fatalf("no rollback attempt for %s: %v", host, err)
- }
- var a rollbackAttempt
- if err := json.Unmarshal(raw, &a); err != nil {
- t.Fatal(err)
- }
- return a
-}
diff --git a/internal/host/settle_unobserved_adopt_test.go b/internal/host/settle_verdict_adopt_test.go
similarity index 73%
rename from internal/host/settle_unobserved_adopt_test.go
rename to internal/host/settle_verdict_adopt_test.go
index 5c859428c..d8fb123cc 100644
--- a/internal/host/settle_unobserved_adopt_test.go
+++ b/internal/host/settle_verdict_adopt_test.go
@@ -72,30 +72,7 @@ func settleOutcomeThroughAdoption(t *testing.T, first error) (restarted, recover
return restarted, recovered, started, live
}
-// A settle that could not observe the unit by its deadline is an unknown
-// outcome through adoption: the version is not poisoned (the pass still
-// adopts it on the other route) and the route gets no not-up recovery
-// (no reset-failed and restart of what runs). The symlink is still put
-// back and the plain start offered, as for any restart error.
-func TestUnobservedSettleNeitherPoisonsNorRecovers(t *testing.T) {
- unobserved := settleUnit(&showErrs{fakeUnits: &fakeUnits{}, err: errors.New("Failed to get properties: Connection timed out")},
- "console-a.service", "old", opts(func() error { return nil }))
- restarted, recovered, started, live := settleOutcomeThroughAdoption(t, unobserved)
- if len(restarted) != 2 {
- t.Fatalf("restarted %v, want both routes: an unknown observation must not poison v2 for the pass", restarted)
- }
- if len(recovered) != 0 {
- t.Fatalf("not-up recovery ran for %v, want none for an unknown observation", recovered)
- }
- if !slices.Equal(started, restarted[:1]) {
- t.Fatalf("started %v, want the plain start for %s alone", started, restarted[0])
- }
- if live[restarted[0]] != "v1" || live[restarted[1]] != "v2" {
- t.Fatalf("live = %v, want %s back on v1 and %s on v2", live, restarted[0], restarted[1])
- }
-}
-
-// The other side: a unit settle saw fail is a verdict. v2 is poisoned for
+// A unit settle saw fail is a verdict through adoption: v2 is poisoned for
// the pass (the second route is not tried) and the route gets the not-up
// recovery, not the plain start.
func TestFailedSettleStillPoisonsAndRecovers(t *testing.T) {
diff --git a/internal/host/unitsettle.go b/internal/host/unitsettle.go
index f87bbedea..f0bdfbe62 100644
--- a/internal/host/unitsettle.go
+++ b/internal/host/unitsettle.go
@@ -178,29 +178,6 @@ type settleOpts struct {
// nothing and restarts nothing.
var errUnitStopped = errors.New("unit was stopped during settle")
-// errUnitUnobserved is what settleUnit's answer wraps when its deadline
-// passed while systemd could not be asked about the unit (the last show
-// failed: refused, a D-Bus error, killed at its QueryTimeout). That is an
-// unknown observation, not evidence the build failed: it is not a
-// *release.UnitNotUpError, so adoption gives the route no not-up recovery,
-// and it is temporary, so adoption does not poison the version. A unit
-// settle did see fail, run the wrong executable or miss its readiness
-// keeps its UnitNotUpError.
-var errUnitUnobserved = errors.New("unit could not be observed before the settle deadline")
-
-// unitUnobservedError is errUnitUnobserved with the unit and the last show
-// error.
-type unitUnobservedError struct {
- unit string
- err error
-}
-
-func (e *unitUnobservedError) Error() string {
- return fmt.Sprintf("cannot observe %s before the settle deadline: %v", e.unit, e.err)
-}
-func (e *unitUnobservedError) Unwrap() []error { return []error{errUnitUnobserved, e.err} }
-func (e *unitUnobservedError) Temporary() bool { return true }
-
// settleUnit watches unit after a try-restart. beforeInvocation is the
// InvocationID before the restart; "" means the unit was not running, and an
// inactive unit is then "nothing started", not a failure. Otherwise a unit
@@ -226,11 +203,17 @@ func settleUnit(sys unitSystem, unit, beforeInvocation string, o settleOpts) err
p, err := sys.Show(unit)
if err != nil {
// One failed `systemctl show` says nothing about the build (a
- // busy bus, a timed-out D-Bus call). Retried until the deadline;
- // a deadline that still cannot observe the unit is an unknown
- // observation (errUnitUnobserved), never a verdict.
+ // busy bus, a timed-out D-Bus call, a show killed at its
+ // QueryTimeout). Retried until the deadline, and only a deadline
+ // that still cannot observe the unit fails, as UnitNotUpError:
+ // its not-up recovery (reset-failed and restart) replaces
+ // whatever runs. Reading this as an unknown outcome instead
+ // belongs to the outcome-reconciliation follow-up (amadan
+ // discussion #1214): adoption would roll the symlink back and
+ // plain-start the unit, which leaves a new process that did come
+ // up running under the old link.
if !o.Now().Before(deadline) {
- return &unitUnobservedError{unit: unit, err: err}
+ return notUp(fmt.Sprintf("cannot observe %s: %v", unit, err))
}
o.Sleep(o.Poll)
continue
diff --git a/internal/host/unitsettle_test.go b/internal/host/unitsettle_test.go
index 1b1917487..e8ec62f13 100644
--- a/internal/host/unitsettle_test.go
+++ b/internal/host/unitsettle_test.go
@@ -190,11 +190,12 @@ func TestSettleRetriesATransientShowError(t *testing.T) {
}
// A settle whose deadline passes while systemd cannot be asked about the
-// unit is an unknown observation, not a verdict on the build: no
-// UnitNotUpError (which would send adoption to the not-up recovery), and
-// temporary (so adoption does not poison the version), whether the show
-// was refused or killed at its bound. The error still names the unit and
-// why it could not be observed.
+// unit is a UnitNotUpError ("cannot observe"), whether the show was refused
+// or killed at its QueryTimeout: the not-up recovery (reset-failed and
+// restart) then replaces whatever runs, so the restored symlink and the
+// running process agree. Bounding the query must not change that verdict;
+// reading it as an unknown outcome waits for the outcome-reconciliation
+// follow-up (amadan discussion #1214).
func TestSettleShowErrorAtTheDeadline(t *testing.T) {
for name, showErr := range map[string]error{
"refused": errors.New("Access denied"),
@@ -203,16 +204,8 @@ func TestSettleShowErrorAtTheDeadline(t *testing.T) {
sys := &showErrs{fakeUnits: &fakeUnits{}, err: showErr}
err := settleUnit(sys, "console.service", "old", opts(func() error { return nil }))
var nu *release.UnitNotUpError
- var temporary interface{ Temporary() bool }
- if err == nil || errors.As(err, &nu) {
- t.Errorf("%s: settle = %v, want an unknown observation, not UnitNotUpError", name, err)
- continue
- }
- if !errors.As(err, &temporary) || !temporary.Temporary() {
- t.Errorf("%s: settle = %v, want it temporary", name, err)
- }
- if !strings.Contains(err.Error(), "console.service") || !strings.Contains(err.Error(), showErr.Error()) {
- t.Errorf("%s: settle = %v, want it to name the unit and the show's error", name, err)
+ if !errors.As(err, &nu) || nu.Reason != "cannot observe console.service: "+showErr.Error() {
+ t.Errorf("%s: settle = %v, want a deadline UnitNotUpError saying the unit could not be observed", name, err)
}
}
}
diff --git a/internal/systemd/command.go b/internal/systemd/command.go
index 657a14701..cb46b1763 100644
--- a/internal/systemd/command.go
+++ b/internal/systemd/command.go
@@ -20,7 +20,12 @@
// mutation's error as "it did not happen" (adoption rolls back and
// starts the old build, which is a no-op over a new process that did
// come up), so bounding mutations needs a way to reconcile the job's
-// outcome first. That is follow-up work with its own spec.
+// outcome first. That is follow-up work with its own spec (amadan
+// discussion #1214), and so is reading a query that failed until a
+// deadline as an unknown outcome rather than a failure: host's settle
+// check still calls that "not up", because its recovery replaces the
+// process, where a rollback with a plain start would leave a new
+// process running under the old link.
//
// When the caller's own context ends a call, the error is os/exec's,
// unchanged. Every other result (output, exit status, *exec.ExitError with