carlos / platform Public

rollout: a fresh box's relayed install is an install wait (#1061)

Final review (Fable P2-1). A box with no live link for the host failed
MaterializeHost with an untyped error, so the planner answered "its
build could not be installed": the wake backed off as a crash and the
32 s bound still answered switched-failed.

MaterializeHost now returns ErrInstallRelayed when the link is absent
after a pass that relayed this host's stage to root (OnStageBlocked
fired for it). The planner marks that refusal Installing, with the
not-installed text. Other Materialize failures stay untyped.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 214b8f9cea83a20ff4d3d466a61dc227985967ac parent af5698b
4 files changed, +85 −1
  • internal/release/materialize.go +27 −1
  • internal/release/materialize_test.go +40 −0
  • internal/rollout/wakeplan.go +7 −0
  • internal/rollout/wakeplan_test.go +11 −0
diff --git a/internal/release/materialize.go b/internal/release/materialize.go
index 474fd9f31..533b587fe 100644
--- a/internal/release/materialize.go
+++ b/internal/release/materialize.go
@@ -3,6 +3,7 @@ package release
import (
"context"
"crypto/ed25519"
+ "errors"
"fmt"
"os"
@@ -45,14 +46,34 @@ import (
// stage to the root pass instead of just erroring (the agent's
// materializeHook does exactly this). BakeDir is always set first and is not
// the caller's to override.
+//
+// An absent link after a pass that relayed this host's stage to root (the
+// caller's OnStageBlocked fired for it) is ErrInstallRelayed: the install is
+// under way in root's pass, not failed, so a caller may wait for it.
func MaterializeHost(ctx context.Context, reg *registry.Registry, s Store, pub ed25519.PublicKey, optDir, dataDir, host string, opts ...PassOption) error {
only := func(rt registry.Route) bool { return rt.Host == host }
- if err := PassFilter(ctx, reg, s, pub, optDir, nil, only, append([]PassOption{BakeDir(dataDir)}, opts...)...); err != nil {
+ relayed := false
+ noteRelay := func(c *passConfig) {
+ inner := c.stageBlocked
+ if inner == nil {
+ return // no relay wired: nothing reaches root, so nothing to wait for
+ }
+ c.stageBlocked = func(h, ver string, err error) {
+ if h == host {
+ relayed = true
+ }
+ inner(h, ver, err)
+ }
+ }
+ passOpts := append(append([]PassOption{BakeDir(dataDir)}, opts...), noteRelay)
+ if err := PassFilter(ctx, reg, s, pub, optDir, nil, only, passOpts...); err != nil {
return fmt.Errorf("materialize %s: %w", host, err)
}
link := LiveLink(optDir, host)
target, err := os.Readlink(link)
switch {
+ case err != nil && os.IsNotExist(err) && relayed:
+ return fmt.Errorf("materialize %s: %w", host, ErrInstallRelayed)
case err != nil && os.IsNotExist(err):
return fmt.Errorf("materialize %s: %s", host, noHeadReason(ctx, reg, s, pub, host))
case err != nil:
@@ -66,6 +87,11 @@ func MaterializeHost(ctx context.Context, reg *registry.Registry, s Store, pub e
return nil
}
+// ErrInstallRelayed is MaterializeHost's error when the host has no live
+// link because its pass could not stage or point the build and relayed that
+// to root's pass (OnStageBlocked): an install in progress, not a failure.
+var ErrInstallRelayed = errors.New("its install is relayed to the root pass")
+
// noAdoptableHead is what an absent live link means when nothing more
// specific can be PROVEN: the channel has no pointer, the pointer would not
// verify, or its head is sitting out a bake window. All three leave the same
diff --git a/internal/release/materialize_test.go b/internal/release/materialize_test.go
index e9edf2b60..1032459c4 100644
--- a/internal/release/materialize_test.go
+++ b/internal/release/materialize_test.go
@@ -3,7 +3,9 @@ package release
import (
"context"
"crypto/ed25519"
+ "errors"
"os"
+ "runtime"
"strings"
"testing"
@@ -255,3 +257,41 @@ func TestMaterializeHostKeepsTheGenericReasonForABinaryApp(t *testing.T) {
t.Errorf("error %q blames a static head on an app that has only ever shipped binaries", err)
}
}
+
+// TestMaterializeHostTypesARelayedInstall (#1061, Fable final P2-1): a box
+// that never ran a build of the app has no live link, and when its pass
+// cannot write the version store it relays the stage to root. That absent
+// link is ErrInstallRelayed, an install under way, not a failed install.
+// Without a relay wired the same absence keeps its untyped reason.
+func TestMaterializeHostTypesARelayedInstall(t *testing.T) {
+ if os.Geteuid() == 0 || runtime.GOOS == "windows" {
+ t.Skip("requires Unix directory permissions enforced for a non-root user")
+ }
+ env := newMatFixture(t)
+ ctx := context.Background()
+ shipRelease(t, env.store, "bab", "matapp", "abc1234", adoptPlatform, []byte("fresh box build"))
+ if err := Promote(ctx, env.store, env.priv, "bab", "matapp", "canary/dev", "abc1234"); err != nil {
+ t.Fatalf("Promote: %v", err)
+ }
+ addRoute(t, env.reg, "mat.test", "matapp", "canary/dev", false)
+ addRoute(t, env.reg, "other.test", "matapp", "canary/dev", false)
+ t.Cleanup(func() { os.Chmod(env.optDir, 0o755) })
+ if err := os.Chmod(env.optDir, 0o555); err != nil {
+ t.Fatal(err)
+ }
+
+ var relays []string
+ relay := OnStageBlocked(func(h, _ string, _ error) { relays = append(relays, h) })
+ err := MaterializeHost(ctx, env.reg, env.store, env.pub, env.optDir, env.dataDir, "mat.test", relay)
+ if !errors.Is(err, ErrInstallRelayed) {
+ t.Fatalf("MaterializeHost = %v, want ErrInstallRelayed", err)
+ }
+ if len(relays) != 1 || relays[0] != "mat.test" {
+ t.Fatalf("relays = %v, want the caller's callback still called once for mat.test", relays)
+ }
+
+ err = MaterializeHost(ctx, env.reg, env.store, env.pub, env.optDir, env.dataDir, "mat.test")
+ if err == nil || errors.Is(err, ErrInstallRelayed) {
+ t.Fatalf("MaterializeHost with no relay = %v, want an untyped failure", err)
+ }
+}
diff --git a/internal/rollout/wakeplan.go b/internal/rollout/wakeplan.go
index 1586453d0..3e8c052bf 100644
--- a/internal/rollout/wakeplan.go
+++ b/internal/rollout/wakeplan.go
@@ -285,6 +285,13 @@ func (m *Manager) Plan(ctx context.Context, rt registry.Route) (plan activator.W
}
if err := m.d.Materialize(ctx, rt.Host); err != nil {
m.d.Logf("rollout: %s: install before its wake: %v", rt.Host, err)
+ if errors.Is(err, release.ErrInstallRelayed) {
+ // A box with no live link for the host relayed its stage
+ // to root (Fable final P2-1): root's install is under
+ // way, so this is the same install wait as a row with no
+ // installed build, not a failed install.
+ return notInstalledPlan()
+ }
return activator.WakePlan{Refuse: "its build could not be installed"}
}
fresh, err := m.d.Routes.Get(rt.Host)
diff --git a/internal/rollout/wakeplan_test.go b/internal/rollout/wakeplan_test.go
index 64bc5d84b..b1115d6e3 100644
--- a/internal/rollout/wakeplan_test.go
+++ b/internal/rollout/wakeplan_test.go
@@ -3,6 +3,7 @@ package rollout
import (
"context"
"errors"
+ "fmt"
"strings"
"sync/atomic"
"testing"
@@ -873,6 +874,16 @@ func TestNotInstalledRefusalsAreMarkedInstalling(t *testing.T) {
h.m.d.Materialize = func(context.Context, string) error { return nil }
installing(t, "row empty after install", h.m.Plan(context.Background(), h.rows.get("a")))
})
+ t.Run("Plan: cold, the install was relayed to root", func(t *testing.T) {
+ // A fresh box (no live link for the host) whose pass relayed its
+ // stage to root (Fable final P2-1): root's install is under way.
+ h := newHarness(t, "a")
+ cold(h)
+ h.m.d.Materialize = func(_ context.Context, host string) error {
+ return fmt.Errorf("materialize %s: %w", host, release.ErrInstallRelayed)
+ }
+ installing(t, "install relayed", h.m.Plan(context.Background(), h.rows.get("a")))
+ })
unconfirmed := func(t *testing.T, site string, p activator.WakePlan) {
t.Helper()
if p.Refuse != "no build is installed for this instance yet" || p.Installing || p.Boot.StagedPath != "" {