release: stamp a returning host's row from the link it left (DR-1)
A box keeps a host's live link after the host's row goes (an HA host moving to another box). When the host came back its row was minted with no Version, the link already named the channel head, and adoptHost's up-to-date return never stamped the row. The rollout planner refuses every wake of a row with no installed build, so the host 503'd on that box for good (dev 2026-11-07: hapair-a1 on sophie, and its g2-* hosts). The up-to-date branch now records the link's build on an unstamped row when the link predates the row, names this row's own account/app build and resolves, and the staged manifest reads; under the release work like every other stamp. A link newer than the row is an install in progress and is left to it. coldWakeInstall is materializeHook's closure, extracted so the witness runs the edge's real install options.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
4 files changed,
+254
−1
internal/host/agent.go+6 −1internal/host/coldwake_leftlink_test.go+58 −0internal/release/adopt.go+51 −0internal/release/unstamped_live_test.go+139 −0
diff --git a/internal/host/agent.go b/internal/host/agent.go| index f2eeab8c0..15811bbe9 100644 |
| --- a/internal/host/agent.go |
| +++ b/internal/host/agent.go |
| @@ -1664,7 +1664,12 @@ func materializeHook(reg *registry.Registry, dd string) func(context.Context, st |
| log.Printf("agent: cold-wake materialize disabled: %v", err) |
| return nil |
| } |
| - optDir := release.OptDir() |
| + return coldWakeInstall(reg, store, pub, release.OptDir(), dd) |
| +} |
| + |
| +// coldWakeInstall is the install a planned wake runs before it plans |
| +// (rollout.Deps.Materialize): one host's pass, with this process's options. |
| +func coldWakeInstall(reg *registry.Registry, store release.Store, pub ed25519.PublicKey, optDir, dd string) func(context.Context, string) error { |
| stageReq := stageRequester(dd) |
| return func(ctx context.Context, host string) error { |
| // The process's one proof gate (proofask.go), so a cold wake cannot |
diff --git a/internal/host/coldwake_leftlink_test.go b/internal/host/coldwake_leftlink_test.go| new file mode 100644 |
| index 000000000..2334469f5 |
| --- /dev/null |
| +++ b/internal/host/coldwake_leftlink_test.go |
| @@ -0,0 +1,58 @@ |
| +package host |
| + |
| +import ( |
| + "context" |
| + "runtime" |
| + "testing" |
| + "time" |
| + |
| + "github.com/carlosframework/platform/internal/registry" |
| + "github.com/carlosframework/platform/internal/release" |
| +) |
| + |
| +// DR-1 (2026-11-07 dev rehearsal), through the install the edge runs before |
| +// it plans a wake (coldWakeInstall, materializeHook's closure, with its real |
| +// options). An HA host left this box, which removed its row and kept its |
| +// live link, and came back: the row was minted again with no Version and |
| +// every later wake was refused as "no build is installed for this instance |
| +// yet". The install must stamp the returning row from the link it left. |
| +func TestColdWakeInstallStampsAReturningHostFromItsLeftLink(t *testing.T) { |
| + env := newFastFixture(t) |
| + ctx := context.Background() |
| + plat := runtime.GOOS + "-" + runtime.GOARCH |
| + host := "hapair.test" |
| + m := release.Manifest{App: "hapair", Version: "hc1", Kind: "binary", Artifacts: map[string]release.Artifact{plat: {}}} |
| + if err := release.Ship(ctx, env.store, "bab", m, map[string][]byte{plat: []byte("build hc1")}); err != nil { |
| + t.Fatalf("Ship: %v", err) |
| + } |
| + if err := release.Promote(ctx, env.store, env.priv, "bab", "hapair", "edge", "hc1"); err != nil { |
| + t.Fatalf("Promote: %v", err) |
| + } |
| + row := registry.Route{Host: host, Kind: "instance", App: "hapair", Account: "bab", Channel: "edge", |
| + Status: "ready", Hibernate: true, Pool: "hapair"} |
| + if err := env.reg.Upsert(row); err != nil { |
| + t.Fatalf("Upsert: %v", err) |
| + } |
| + install := coldWakeInstall(env.reg, env.store, env.pub, env.optDir, env.dataDir) |
| + if err := install(ctx, host); err != nil { |
| + t.Fatalf("first install: %v", err) |
| + } |
| + if rt, _ := env.reg.Get(host); rt == nil || rt.Version != "hc1" { |
| + t.Fatalf("first install: row = %+v; want Version hc1", rt) |
| + } |
| + |
| + if err := env.reg.Delete(host); err != nil { |
| + t.Fatalf("Delete: %v", err) |
| + } |
| + row.CreatedAt = time.Now().Add(time.Minute).Unix() // minted after the link was written |
| + if err := env.reg.Upsert(row); err != nil { |
| + t.Fatalf("Upsert again: %v", err) |
| + } |
| + if err := install(ctx, host); err != nil { |
| + t.Fatalf("install on return: %v", err) |
| + } |
| + rt, err := env.reg.Get(host) |
| + if err != nil || rt == nil || rt.Version != "hc1" { |
| + t.Fatalf("on return: row = %+v, %v; want Version hc1, the build its left link names", rt, err) |
| + } |
| +} |
diff --git a/internal/release/adopt.go b/internal/release/adopt.go| index b776ae376..aed6fd066 100644 |
| --- a/internal/release/adopt.go |
| +++ b/internal/release/adopt.go |
| @@ -1504,6 +1504,7 @@ func adoptHost(ctx context.Context, work hostwrite.Work, reg *registry.Registry, |
| _ = ClearRefusal(cfg.bakeDir, rt.Host) |
| } |
| } |
| + stampLeftLink(ctx, work, reg, optDir, rt, cur) |
| return // up to date — stay quiet on the periodic tick |
| } |
| // Two independent waivers, both root-signed in origin: ignore is the |
| @@ -2844,3 +2845,53 @@ func retainedRootfsAuthorised(optDir, acct, app, ver string, m *Manifest, author |
| } |
| return nil |
| } |
| + |
| +// stampLeftLink records cur as rt's installed build when the row records |
| +// none and the link is one an earlier row left behind (DR-1, 2026-11-07). |
| +// |
| +// A box keeps a host's live link after the host's row goes (an HA host |
| +// moving to another box removes the row, never the link). When the host |
| +// comes back its row is minted again with no Version, the link already |
| +// names the selected build, and the up-to-date return above would leave |
| +// the row unstamped for good: no pass ever moves the link again, and the |
| +// rollout planner refuses every wake of a row with no installed build. |
| +// |
| +// Only a link older than the row is stamped. A link written after the row |
| +// was minted is an install in progress (PointLive, then the restart, then |
| +// SetVersions), and that install stamps its own row or rolls the link back; |
| +// stamping it here could record a build whose restart is about to fail. |
| +// A link that does not resolve, or a staged manifest that does not read, |
| +// is left alone: the wake reports it, as before. |
| +func stampLeftLink(ctx context.Context, work hostwrite.Work, reg *registry.Registry, optDir string, rt registry.Route, cur string) { |
| + if rt.Version != "" || cur == "" || rt.CreatedAt == 0 { |
| + return |
| + } |
| + link := LiveLink(optDir, rt.Host) |
| + li, err := os.Lstat(link) |
| + if err != nil || !li.ModTime().Before(time.Unix(rt.CreatedAt, 0)) { |
| + return |
| + } |
| + // The link must name this row's own build (a host minted again for |
| + // another app or account keeps nothing of the old one's), and resolve. |
| + if target, err := os.Readlink(link); err != nil || target != VersionPath(optDir, RouteAccount(rt), cur, rt.App) { |
| + return |
| + } |
| + if _, err := os.Stat(link); err != nil { |
| + return |
| + } |
| + m, err := ReadStagedManifest(optDir, RouteAccount(rt), cur, rt.App) |
| + if err != nil || m == nil { |
| + fmt.Printf(" %s: its live link names %s, but the staged manifest does not read (%v); the row is left without an installed build\n", rt.Host, cur, err) |
| + return |
| + } |
| + id, err := releaseIdentity(m) |
| + if err != nil { |
| + fmt.Printf(" %s: release identity: %v\n", rt.Host, err) |
| + return |
| + } |
| + if err := withReleaseWork(ctx, work, id, func() error { return reg.SetVersions(rt.Host, cur, rt.PrevVersion) }); err != nil { |
| + fmt.Printf(" %s: recording %s, the build its live link already names: %v\n", rt.Host, cur, err) |
| + return |
| + } |
| + fmt.Printf(" %s: recorded %s as installed (its live link was left by an earlier route)\n", rt.Host, cur) |
| +} |
diff --git a/internal/release/unstamped_live_test.go b/internal/release/unstamped_live_test.go| new file mode 100644 |
| index 000000000..66c5fba08 |
| --- /dev/null |
| +++ b/internal/release/unstamped_live_test.go |
| @@ -0,0 +1,139 @@ |
| +package release |
| + |
| +import ( |
| + "context" |
| + "testing" |
| + "time" |
| + |
| + "github.com/carlosframework/platform/internal/registry" |
| +) |
| + |
| +// DR-1 (2026-11-07 dev rehearsal): a box that served a host once keeps the |
| +// host's live link after the row goes (an HA host moving to another box). |
| +// When the host comes back the row is minted again with no Version, the |
| +// link already names the channel head, and the pass's up-to-date |
| +// short-circuit returned before stamping the row. The rollout planner |
| +// refuses a wake for a row with no installed build, so the host could |
| +// never wake on that box again. Both the cold wake's install |
| +// (MaterializeHost) and the hourly pass must stamp the row from the link. |
| +func remintedRow(t *testing.T) *matFixture { |
| + t.Helper() |
| + env := newMatFixture(t) |
| + ctx := context.Background() |
| + shipRelease(t, env.store, "bab", "matapp", "abc1234", adoptPlatform, []byte("ha 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", true) |
| + if err := MaterializeHost(ctx, env.reg, env.store, env.pub, env.optDir, env.dataDir, "mat.test"); err != nil { |
| + t.Fatalf("first MaterializeHost: %v", err) |
| + } |
| + if rt, err := env.reg.Get("mat.test"); err != nil || rt == nil || rt.Version != "abc1234" { |
| + t.Fatalf("first install: row = %+v, %v; want Version abc1234", rt, err) |
| + } |
| + // The host leaves this box (its row goes, its link stays) and comes back. |
| + if err := env.reg.Delete("mat.test"); err != nil { |
| + t.Fatalf("Delete: %v", err) |
| + } |
| + // Minted again later than the link was written (CreatedAt has second |
| + // resolution, so the test dates the row rather than sleeping). |
| + if err := env.reg.Upsert(registry.Route{Host: "mat.test", Kind: "instance", App: "matapp", |
| + Channel: "canary/dev", Hibernate: true, CreatedAt: time.Now().Add(time.Minute).Unix()}); err != nil { |
| + t.Fatalf("Upsert: %v", err) |
| + } |
| + if v, _ := LiveVersion(env.optDir, "mat.test"); v != "abc1234" { |
| + t.Fatalf("live = %q, want the link left at abc1234", v) |
| + } |
| + return env |
| +} |
| + |
| +func TestMaterializeHostStampsARemintedRowFromItsLiveLink(t *testing.T) { |
| + env := remintedRow(t) |
| + if err := MaterializeHost(context.Background(), env.reg, env.store, env.pub, env.optDir, env.dataDir, "mat.test"); err != nil { |
| + t.Fatalf("MaterializeHost: %v", err) |
| + } |
| + rt, err := env.reg.Get("mat.test") |
| + if err != nil || rt == nil || rt.Version != "abc1234" { |
| + t.Fatalf("row = %+v, %v; want Version abc1234 (the build its link names)", rt, err) |
| + } |
| +} |
| + |
| +func TestPassStampsARemintedRowFromItsLiveLink(t *testing.T) { |
| + env := remintedRow(t) |
| + if err := Pass(context.Background(), env.reg, env.store, env.pub, env.optDir, nil, BakeDir(env.dataDir)); err != nil { |
| + t.Fatalf("Pass: %v", err) |
| + } |
| + rt, err := env.reg.Get("mat.test") |
| + if err != nil || rt == nil || rt.Version != "abc1234" { |
| + t.Fatalf("row = %+v, %v; want Version abc1234 (the build its link names)", rt, err) |
| + } |
| +} |
| + |
| +// An install in progress has written the link after the row was minted and |
| +// stamps its own row once its restart succeeds (or rolls the link back): |
| +// the pass must not stamp it first. |
| +func TestPassLeavesALinkNewerThanItsRowToItsInstall(t *testing.T) { |
| + env := newMatFixture(t) |
| + ctx := context.Background() |
| + shipRelease(t, env.store, "bab", "matapp", "abc1234", adoptPlatform, []byte("ha build")) |
| + if err := Promote(ctx, env.store, env.priv, "bab", "matapp", "canary/dev", "abc1234"); err != nil { |
| + t.Fatalf("Promote: %v", err) |
| + } |
| + if err := env.reg.Upsert(registry.Route{Host: "mat.test", Kind: "instance", App: "matapp", |
| + Channel: "canary/dev", Hibernate: true, CreatedAt: time.Now().Add(-time.Minute).Unix()}); err != nil { |
| + t.Fatalf("Upsert: %v", err) |
| + } |
| + if _, err := ensureStagedDigest(ctx, env.store, env.optDir, "bab", "matapp", "abc1234", "mat.test", "", stageCheck{}); err != nil { |
| + t.Fatalf("stage: %v", err) |
| + } |
| + if err := PointLive(env.optDir, "mat.test", "bab", "abc1234", "matapp"); err != nil { |
| + t.Fatalf("PointLive: %v", err) |
| + } |
| + if err := Pass(ctx, env.reg, env.store, env.pub, env.optDir, nil, BakeDir(env.dataDir)); err != nil { |
| + t.Fatalf("Pass: %v", err) |
| + } |
| + if rt, _ := env.reg.Get("mat.test"); rt == nil || rt.Version != "" { |
| + t.Fatalf("row = %+v; want no Version (the link is an install in progress)", rt) |
| + } |
| +} |
| + |
| +// A host minted again for another app keeps nothing of the old one's: a left |
| +// link that names another app's build, even under the same version name, |
| +// is not this row's install. |
| +func TestPassLeavesALeftLinkOfAnotherApp(t *testing.T) { |
| + env := remintedRow(t) |
| + ctx := context.Background() |
| + shipRelease(t, env.store, "bab", "otherapp", "abc1234", adoptPlatform, []byte("other build")) |
| + if err := Promote(ctx, env.store, env.priv, "bab", "otherapp", "canary/dev", "abc1234"); err != nil { |
| + t.Fatalf("Promote: %v", err) |
| + } |
| + // Staged here too, so only the link's target tells the two apart. |
| + if _, err := ensureStagedDigest(ctx, env.store, env.optDir, "bab", "otherapp", "abc1234", "mat.test", "", stageCheck{}); err != nil { |
| + t.Fatalf("stage: %v", err) |
| + } |
| + if err := env.reg.Delete("mat.test"); err != nil { |
| + t.Fatalf("Delete: %v", err) |
| + } |
| + if err := env.reg.Upsert(registry.Route{Host: "mat.test", Kind: "instance", App: "otherapp", |
| + Channel: "canary/dev", Hibernate: true, CreatedAt: time.Now().Add(time.Minute).Unix()}); err != nil { |
| + t.Fatalf("Upsert: %v", err) |
| + } |
| + if v, _ := LiveVersion(env.optDir, "mat.test"); v != "abc1234" { |
| + t.Fatalf("live = %q, want abc1234", v) |
| + } |
| + if err := Pass(ctx, env.reg, env.store, env.pub, env.optDir, nil, BakeDir(env.dataDir)); err != nil { |
| + t.Fatalf("Pass: %v", err) |
| + } |
| + if rt := mustRow(t, env, "mat.test"); rt.Version != "" { |
| + t.Fatalf("row = %+v; want no Version (the link names matapp's build)", rt) |
| + } |
| +} |
| + |
| +func mustRow(t *testing.T, env *matFixture, host string) registry.Route { |
| + t.Helper() |
| + rt, err := env.reg.Get(host) |
| + if err != nil || rt == nil { |
| + t.Fatalf("Get %s: %+v, %v", host, rt, err) |
| + } |
| + return *rt |
| +} |