store write credential phase 2: one abort rule for floor refusals
Paul's choice A of 2026-11-25, after Astra round 2. An attempt the floor refused before any effect is cancelled from root's local state only, in one function, release.AbortBeforeEffect, which every PointLive caller passes its error through with its local undo. Adoption's history attempt and Prepare's capture (a new Abort hook), active recovery's capture and the resumes' Recovering mark are undone; nothing reads the deployment store. The guard now covers every pointLive identifier and go:linkname, and paths returned or passed through by helpers. Witnesses keep the store down through the swap and the cleanup and retry the same build.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
13 files changed,
+667
−194
docs/superpowers/specs/2026-11-25-store-write-credential-design.md+72 −36internal/host/consolefloor_recovery_test.go+214 −73internal/host/namedrecovery.go+3 −1internal/host/namedrecovery_active.go+6 −9internal/host/plan14_canonical_restart_test.go+9 −1internal/host/roothistory_recovery.go+61 −3internal/host/rootrollback_resume.go+14 −2internal/release/adopt.go+3 −1internal/release/consolefloor.go+34 −0internal/release/consolefloor_guard_test.go+215 −39internal/release/materializeheld.go+2 −2internal/release/rollback.go+3 −1internal/release/roothistory_pass.go+31 −26
diff --git a/docs/superpowers/specs/2026-11-25-store-write-credential-design.md b/docs/superpowers/specs/2026-11-25-store-write-credential-design.md| index 4395fdb3a..ba3911833 100644 |
| --- a/docs/superpowers/specs/2026-11-25-store-write-credential-design.md |
| +++ b/docs/superpowers/specs/2026-11-25-store-write-credential-design.md |
| @@ -651,41 +651,72 @@ Paths that do not repoint, checked: |
| `before == target`, `carlos adopt -restart-only`, D1's start after an |
| admitted rollback) runs the same build. |
| -**What a refusal leaves.** A refused forward repoint leaves the box on what |
| -it runs, as §10 says, and counts as never tried (Astra phase 2 round 1, |
| -finding 1). Two paths ask the floor early and then again at the swap, with |
| -an attempt recorded in between: adoption under root history begins a |
| -history attempt (whose `Prepare` captures root's rollback attempt), and |
| -active named-unit recovery captures a rollback attempt. If the floor read |
| -at the swap fails after the early check passed, nothing was published, so |
| -adoption settles its history attempt with no refusal |
| -(`RootHistoryPass.abandon`) and recovery puts the rollback journal back as |
| -it was and drops the attempt's capability (`abandonRollbackCapture`). |
| -Root's resume then has nothing to settle as a recovery, and the next pass |
| -tries the same build. A refused rollback leaves the writer-aware build |
| -linked and its unit down, the state a rollback that cannot repoint already |
| -reaches (`could not roll the symlink back`); the next pass asks again, and |
| -promoting a writer-aware build is the way out. A box already running a |
| -console below the floor keeps it until its next repoint: the floor governs |
| -what is pointed live, as §10 defines it. |
| +**What a refusal leaves: the abort rule (Paul's choice A, 2026-11-25).** An |
| +attempt the floor refused before any effect, a failed floor read included, |
| +is cancelled from root's local state only. The cancellation never needs |
| +the deployment store, and nothing is recorded as a refusal of a build that |
| +ran. The rule lives in one function, `release.AbortBeforeEffect(err, |
| +undo...)`: every path whose repoint `PointLive` can refuse passes |
| +`PointLive`'s error through it, with the undo of whatever it recorded for |
| +the attempt before the swap. Only for `ErrConsoleFloor` do the undos run, |
| +each one even if another failed; any other error passes through untouched, |
| +because a repoint that failed otherwise may have moved the link. |
| + |
| +| Path | Recorded before the swap | Undo | |
| +|---|---|---| |
| +| Adoption under root history (`repointFailed`) | the history attempt (`begin`), and the rollback attempt `Prepare` captured | `RootHistoryPass.undo`: the host's `Abort` puts the rollback journal back as `Prepare` found it and drops the capture's capability, then the history attempt is settled with no refusal. Both are local; the old `abandon` re-read the deployment record first (Astra round 2) and is gone | |
| +| Active named-unit recovery | the rollback attempt it captured | `abandonRollbackCapture`: the journal as it was, the capability gone | |
| +| Root's rollback resume (`resumeRootRestart`) | the attempt's `Recovering` mark | the journal written back as it was; the attempt is also no longer settled by the resume's deferred settle, so the next resume retries | |
| +| Root's history rollback (`resumeHistoryRestart`) | the attempt's `Recovering` mark | the journal written back as it was | |
| +| Adoption without root history, adoption's D1 rollback, the D1 group, held publish and its restore, stopped-unit repair | nothing | none: they call the rule with no undo | |
| + |
| +Why no other path needs it: these are every caller of `PointLive`, and the |
| +compiler and the guard keep it so. A path that records nothing before its |
| +swap has nothing to cancel. Whatever those paths record after a refusal is |
| +about a build that did run: D1's poisoned version and refusals name the |
| +build whose restart failed, and the held stage's binding refusal names |
| +bytes that were published and then failed their second bind. Adoption's |
| +early `consoleFloorAdmits` and active recovery's `CheckConsoleFloor` refuse |
| +before anything is recorded. Superseding an older unsettled attempt in |
| +active recovery settles that older attempt, which ran; it is not part of |
| +the refused one. |
| **The guard.** `TestEveryRepointPassesTheConsoleFloor` |
| (`internal/release/consolefloor_guard_test.go`) reads every non-test Go file |
| -in the module and fails on any use of `pointLive` outside `PointLive`, and |
| -on any call that puts a live-link path (an expression naming `LiveLink`, |
| -`liveDir`, `liveLink` or a `live` path segment, a local assigned from one, |
| -or a path derived from one by concatenation, a path call, a conversion or |
| -its directory's descriptor) where a link or file is written: the |
| -destination of `os.Symlink`, `os.Rename`, `os.Link`, their `unix` and |
| -`syscall` forms or `instancefs.RenameBetween*`, or a parameter of any |
| -module function that carries its argument to one, through any number of |
| -helpers (summarised to a fixpoint across the module). Imports resolve |
| -through their local names; calls resolve by name, a method within its |
| -package. `release.PointLive` is the sanctioned path. The one function it |
| -flags today is `instancectl`'s `ensureExe`, an isolated instance's own |
| -`live/` linking to the host's live link, allowed by name with that reason. |
| -Its self-test covers a write inline, through a local, an aliased `os`, a |
| -directory descriptor, a helper, a method and another package's helper. |
| +in the module. Two rules: |
| + |
| +- The bare swap. Every occurrence of the identifier `pointLive` in package |
| + `release` outside `PointLive`'s body, in any declaration (a call, a |
| + function value, a package-level alias such as `var repoint = pointLive`), |
| + and any `go:linkname` naming it anywhere, fails. An unexported function |
| + is reachable from its own package only by its identifier and from any |
| + other only by `go:linkname`, so this rule is complete, not a heuristic. |
| +- The second door. Any call that puts a live-link path where a link or file |
| + is written fails: the destination of `os.Symlink`, `os.Rename`, `os.Link`, |
| + their `unix` and `syscall` forms or `instancefs.RenameBetween*`, or a |
| + parameter of any module function that carries its argument there. A |
| + live-link path is an expression naming `LiveLink`, `liveDir`, `liveLink` |
| + or a `live` path segment, a local assigned from one, a call to a function |
| + that returns one (a named result too), or one carried through a |
| + concatenation, a path call, a conversion, a directory's descriptor or a |
| + module function that passes its argument through to its result. |
| + Summaries (writing parameters, pass-through parameters, live returns) are |
| + found to a fixpoint across the module. Imports resolve through their |
| + local names. Calls resolve by name, without types: a function by its |
| + package, a method by its name within the caller's package. Return |
| + summaries are kept only for functions returning a `string` or an |
| + `*os.File`, and a field of a value is not a live path, so a struct that |
| + holds one in a field is data. This rule is a source scan, sound for |
| + direct calls but not for function values, interfaces or reflection; the |
| + first rule and the unexported swap are what make a bypass impossible |
| + rather than merely detected. |
| + |
| +The one function it flags today is `instancectl`'s `ensureExe`, an isolated |
| +instance's own `live/` linking to the host's live link, allowed by name |
| +with that reason. Its self-test covers a write inline, through a local, an |
| +aliased `os`, a directory descriptor, a helper, a method, another package's |
| +helper, a helper that returns the path, a named result, a pass-through |
| +helper, a package-level alias of the swap and a `go:linkname` to it. |
| **Witnesses**, each with a floor and a console build from before it, a |
| floor read that fails, and (host) a no-floor control: |
| @@ -698,10 +729,15 @@ floor read that fails, and (host) a no-floor control: |
| `TestRootRollbackResumeMeetsTheConsoleFloor`, |
| `TestRootHistoryRollbackMeetsTheConsoleFloor` (host), each with a no-floor |
| control on the same console builds. All of them fail with the admission |
| -disabled. `TestNamedActiveRecoveryFloorFailureAtTheSwapIsRetryable` and |
| -`TestAdoptionFloorFailureAtTheSwapIsRetryable` fail the floor read at the |
| -swap only, run root's resume, and retry the same build; both fail without |
| -the cleanup above. |
| +disabled. The abort rule: `TestAdoptionOutageThroughTheSwapLeavesNoPoison` (with |
| +production's `Prepare`, `Abort` and history callbacks) and |
| +`TestNamedActiveRecoveryOutageThroughTheSwapLeavesNoPoison` take the |
| +deployment store down at the swap's floor read and keep it down through |
| +the cleanup, run root's resume, and retry the same build once the store |
| +answers; `TestRootRollbackResumeOutageLeavesTheJournal` and |
| +`TestRootHistoryRollbackOutageLeavesTheJournal` refuse a resume's rollback |
| +at an outage, check the journal is as it was, and roll back once the store |
| +answers. All four fail with the rule disabled. |
| **The session policy** (§3): the core's `WriteScope`, rendered by AWS with |
| `NotAction` and by MinIO with action families. |
diff --git a/internal/host/consolefloor_recovery_test.go b/internal/host/consolefloor_recovery_test.go| index 071d1f745..94080a0bb 100644 |
| --- a/internal/host/consolefloor_recovery_test.go |
| +++ b/internal/host/consolefloor_recovery_test.go |
| @@ -261,95 +261,108 @@ func TestRootHistoryRollbackMeetsTheConsoleFloor(t *testing.T) { |
| } |
| } |
| -// consoleFloorFailsAt fails the floor's listing on exactly its nth read |
| -// (1-based) and on no other, so a check before an attempt passes and the |
| -// one at the swap fails. |
| -type consoleFloorFailsAt struct { |
| +// deploymentOutage is the deployment store going down at the floor's |
| +// downAt-th listing (1-based) and staying down, every call failing, until |
| +// up() is called: an outage that lasts through the swap and anything after |
| +// it, the cleanup included. |
| +type deploymentOutage struct { |
| release.Store |
| - n, reads int |
| + downAt, floorReads int |
| + down bool |
| } |
| -func (f *consoleFloorFailsAt) fail(prefix string) bool { |
| - if prefix != release.ConsoleStoreWritersFloorKey { |
| - return false |
| +func (o *deploymentOutage) up() { o.down, o.downAt = false, 0 } |
| + |
| +func (o *deploymentOutage) check(key string) error { |
| + if key == release.ConsoleStoreWritersFloorKey { |
| + o.floorReads++ |
| + if o.downAt > 0 && o.floorReads == o.downAt { |
| + o.down = true |
| + } |
| + } |
| + if o.down { |
| + return os.ErrDeadlineExceeded |
| } |
| - f.reads++ |
| - return f.reads == f.n |
| + return nil |
| } |
| -func (f *consoleFloorFailsAt) List(ctx context.Context, prefix string) ([]string, error) { |
| - if f.fail(prefix) { |
| - return nil, os.ErrDeadlineExceeded |
| +func (o *deploymentOutage) Get(ctx context.Context, key string) ([]byte, string, error) { |
| + if err := o.check(key); err != nil { |
| + return nil, "", err |
| } |
| - return f.Store.List(ctx, prefix) |
| + return o.Store.Get(ctx, key) |
| } |
| -func (f *consoleFloorFailsAt) ListPage(ctx context.Context, prefix, after string, limit int) ([]string, error) { |
| - if f.fail(prefix) { |
| - return nil, os.ErrDeadlineExceeded |
| +func (o *deploymentOutage) Put(ctx context.Context, key string, body []byte, ifMatch string) (string, error) { |
| + if err := o.check(key); err != nil { |
| + return "", err |
| } |
| - if pl, ok := f.Store.(release.PageLister); ok { |
| - return pl.ListPage(ctx, prefix, after, limit) |
| + return o.Store.Put(ctx, key, body, ifMatch) |
| +} |
| + |
| +func (o *deploymentOutage) List(ctx context.Context, prefix string) ([]string, error) { |
| + if err := o.check(prefix); err != nil { |
| + return nil, err |
| } |
| - return f.Store.List(ctx, prefix) |
| + return o.Store.List(ctx, prefix) |
| } |
| -// Astra phase 2 round 1, finding 1: active recovery's floor check passes, |
| -// the attempt is captured, and the floor read at the swap fails. Nothing |
| -// was published, so nothing may count as tried: no attempt is left for |
| -// root's resume, the resume changes nothing, and the same promotion |
| -// recovers on the next pass. |
| -func TestNamedActiveRecoveryFloorFailureAtTheSwapIsRetryable(t *testing.T) { |
| - // Not parallel: signedRecoveryFixture sets the release key with t.Setenv. |
| - old, aware := floorConsoles(t) |
| - e, u, c, source, pub := signedRecoveryFixtureWith(t, old, aware) |
| - rt, err := e.root.reg.Get(observedHost) |
| - if err != nil { |
| - t.Fatal(err) |
| +func (o *deploymentOutage) ListDirs(ctx context.Context, prefix string) ([]string, error) { |
| + if err := o.check(prefix); err != nil { |
| + return nil, err |
| } |
| - h := seedHostRootHistory(t, *rt) |
| - c.history = func() (*release.RootHistoryPass, error) { return &release.RootHistoryPass{History: h}, nil } |
| - source.store = &consoleFloorFailsAt{Store: e.store, n: 2} |
| - n := namedUnitRecovery{source: source, pub: pub, readLive: os.Readlink} |
| - handled, err := n.recover(t.Context(), observedHost, c, func(string) string { return "5s" }, e.root.reg) |
| - if live, _ := release.LiveVersion(u.opt, observedHost); !handled || !errors.Is(err, release.ErrConsoleFloor) || live != "v1" || len(u.effects) != 0 { |
| - t.Fatalf("refusal at the swap: handled %v, err %v, live %q, effects %v", handled, err, live, u.effects) |
| + return o.Store.ListDirs(ctx, prefix) |
| +} |
| + |
| +func (o *deploymentOutage) Delete(ctx context.Context, key string) error { |
| + if err := o.check(key); err != nil { |
| + return err |
| } |
| + return o.Store.Delete(ctx, key) |
| +} |
| + |
| +func (o *deploymentOutage) ListPage(ctx context.Context, prefix, after string, limit int) ([]string, error) { |
| + if err := o.check(prefix); err != nil { |
| + return nil, err |
| + } |
| + if pl, ok := o.Store.(release.PageLister); ok { |
| + return pl.ListPage(ctx, prefix, after, limit) |
| + } |
| + return o.Store.List(ctx, prefix) |
| +} |
| + |
| +// noPoison is the abort rule's promise after a refused attempt, once root's |
| +// resume has run: no rollback state left, no history attempt pending, no |
| +// refusal recorded. |
| +func noPoison(t *testing.T, c rootRestartChecks, h *release.RootHistory, b release.HistoryBinding) { |
| + t.Helper() |
| disk, err := c.attempts() |
| if err != nil { |
| t.Fatal(err) |
| } |
| - if _, err := readRollbackAttempt(disk, observedHost); !errors.Is(err, os.ErrNotExist) { |
| - t.Fatalf("an attempt that never published was left for root's resume: %v", err) |
| - } |
| if names, _ := disk.Names(); len(names) != 0 { |
| t.Fatalf("rollback state left behind: %v", names) |
| } |
| - c.started = &sync.Map{} |
| - if err := recoverRootRestarts(t.Context(), u, u.opt, func(string) string { return "5s" }, c, hostwrite.Config{}); err != nil || len(u.effects) != 0 { |
| - t.Fatalf("root's resume after the refusal: %v, effects %v", err, u.effects) |
| + if p, err := h.Pending(b); err != nil || p != nil { |
| + t.Fatalf("a history attempt left pending: %+v, %v", p, err) |
| } |
| - b := release.HistoryBinding{Host: observedHost, Account: "bab", App: "console"} |
| if refs, err := h.Refusals(b); err != nil || len(refs) != 0 { |
| - t.Fatalf("the untried promotion was refused: %+v, %v", refs, err) |
| - } |
| - // The floor reads again: the same signed head recovers. |
| - source.store = e.store |
| - handled, err = n.recover(t.Context(), observedHost, c, func(string) string { return "5s" }, e.root.reg) |
| - if live, _ := release.LiveVersion(u.opt, observedHost); !handled || err != nil || live != "v2" || len(u.effects) != 1 { |
| - t.Fatalf("retry: handled %v, err %v, live %q, effects %v", handled, err, live, u.effects) |
| + t.Fatalf("the untried build was refused: %+v, %v", refs, err) |
| } |
| } |
| -// The same for adoption under root history: the early floor check passes, |
| -// the history attempt is begun (and root's rollback attempt captured by its |
| -// Prepare), and the floor read at the swap fails. The history attempt is |
| -// settled with no refusal, root's resume changes nothing, and the next pass |
| -// adopts the same build. |
| -func TestAdoptionFloorFailureAtTheSwapIsRetryable(t *testing.T) { |
| +// Paul's choice A (2026-11-25), adoption under root history with |
| +// production's callbacks (linkRootHistory's Prepare and Abort, c.history): |
| +// the deployment store goes down at the swap's floor read and stays down |
| +// through the cleanup. The attempt is cancelled from local state alone and |
| +// nothing poisons the build; root's resume finds nothing to settle; once |
| +// the store answers, the next pass adopts the same build. |
| +func TestAdoptionOutageThroughTheSwapLeavesNoPoison(t *testing.T) { |
| t.Parallel() |
| old, aware := floorConsoles(t) |
| - e, rt, u, c, pub := plan14AdoptionFixtureWith(t, old, aware) |
| + e, rt, u, c, pub, source := plan14AdoptionFixtureSource(t, old, aware) |
| + outage := &deploymentOutage{Store: e.store, downAt: 2} |
| + source.store = outage |
| h := seedHostRootHistory(t, rt) |
| b := release.HistoryBinding{Host: rt.Host, Account: rt.Account, App: rt.App} |
| // This route has run the console (D2's program history). |
| @@ -357,30 +370,158 @@ func TestAdoptionFloorFailureAtTheSwapIsRetryable(t *testing.T) { |
| t.Fatal(err) |
| } |
| deps := boundRootHistory(h, c.resolve, e.root.obs) |
| - pass := func(s release.Store) error { |
| - forward := rootRestartRouteWith(e.root.reg, u, u.opt, func(string) string { return "5s" }, e.root.obs.recordSettled(e.bake), c) |
| - return release.Pass(context.Background(), e.root.reg, s, pub, u.opt, forward, |
| + getenv := func(string) string { return "5s" } |
| + linkRootHistory(deps, c, u.opt, getenv) |
| + c.history = func() (*release.RootHistoryPass, error) { return deps, nil } |
| + pass := func() error { |
| + forward := rootRestartRouteWith(e.root.reg, u, u.opt, getenv, e.root.obs.recordSettled(e.bake), c) |
| + return release.Pass(context.Background(), e.root.reg, outage, pub, u.opt, forward, |
| release.BakeDir(e.bake), release.WithRootHistory(deps), release.WithRestartFailurePropagation(), |
| - release.WithRollbackRestart(rollbackUnitRestart(e.root.reg, u, u.opt, func(string) string { return "5s" }, c))) |
| + release.WithRollbackRestart(rollbackUnitRestart(e.root.reg, u, u.opt, getenv, c))) |
| + } |
| + _ = pass() |
| + if !outage.down { |
| + t.Fatal("the outage never began: the swap's floor read was not reached") |
| } |
| - _ = pass(&consoleFloorFailsAt{Store: e.store, n: 2}) |
| if live, _ := release.LiveVersion(u.opt, rt.Host); live != "v1" || len(u.effects) != 0 { |
| t.Fatalf("refusal at the swap: live %q, effects %v", live, u.effects) |
| } |
| - if p, err := h.Pending(b); err != nil || p != nil { |
| - t.Fatalf("the history attempt was left pending: %+v, %v", p, err) |
| - } |
| + noPoison(t, c, h, b) |
| + outage.up() |
| c.started = &sync.Map{} |
| - if err := recoverRootRestarts(context.Background(), u, u.opt, func(string) string { return "5s" }, c, hostwrite.Config{}); err != nil || len(u.effects) != 0 { |
| + if err := recoverRootRestarts(context.Background(), u, u.opt, getenv, c, hostwrite.Config{}); err != nil || len(u.effects) != 0 { |
| t.Fatalf("root's resume after the refusal: %v, effects %v", err, u.effects) |
| } |
| - if refs, err := h.Refusals(b); err != nil || len(refs) != 0 { |
| - t.Fatalf("the untried build was refused: %+v, %v", refs, err) |
| - } |
| - if err := pass(e.store); err != nil { |
| + noPoison(t, c, h, b) |
| + if err := pass(); err != nil { |
| t.Fatalf("retry: %v", err) |
| } |
| if live, _ := release.LiveVersion(u.opt, rt.Host); live != "v2" || len(u.effects) != 1 { |
| t.Fatalf("retry: live %q, effects %v", live, u.effects) |
| } |
| } |
| + |
| +// The same for active named-unit recovery: its floor check passes, the |
| +// rollback attempt is captured, and the store goes down at the swap's |
| +// floor read and stays down. The capture is undone from local state; once |
| +// the store answers, the same signed head recovers. |
| +func TestNamedActiveRecoveryOutageThroughTheSwapLeavesNoPoison(t *testing.T) { |
| + // Not parallel: signedRecoveryFixture sets the release key with t.Setenv. |
| + old, aware := floorConsoles(t) |
| + e, u, c, source, pub := signedRecoveryFixtureWith(t, old, aware) |
| + rt, err := e.root.reg.Get(observedHost) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + h := seedHostRootHistory(t, *rt) |
| + b := release.HistoryBinding{Host: rt.Host, Account: rt.Account, App: rt.App} |
| + c.history = func() (*release.RootHistoryPass, error) { return &release.RootHistoryPass{History: h}, nil } |
| + outage := &deploymentOutage{Store: e.store, downAt: 2} |
| + source.store = outage |
| + n := namedUnitRecovery{source: source, pub: pub, readLive: os.Readlink} |
| + getenv := func(string) string { return "5s" } |
| + handled, err := n.recover(t.Context(), observedHost, c, getenv, e.root.reg) |
| + if live, _ := release.LiveVersion(u.opt, observedHost); !handled || !errors.Is(err, release.ErrConsoleFloor) || !outage.down || live != "v1" || len(u.effects) != 0 { |
| + t.Fatalf("refusal at the swap: handled %v, err %v, down %v, live %q, effects %v", handled, err, outage.down, live, u.effects) |
| + } |
| + noPoison(t, c, h, b) |
| + outage.up() |
| + c.started = &sync.Map{} |
| + if err := recoverRootRestarts(t.Context(), u, u.opt, getenv, c, hostwrite.Config{}); err != nil || len(u.effects) != 0 { |
| + t.Fatalf("root's resume after the refusal: %v, effects %v", err, u.effects) |
| + } |
| + noPoison(t, c, h, b) |
| + handled, err = n.recover(t.Context(), observedHost, c, getenv, e.root.reg) |
| + if live, _ := release.LiveVersion(u.opt, observedHost); !handled || err != nil || live != "v2" || len(u.effects) != 1 { |
| + t.Fatalf("retry: handled %v, err %v, live %q, effects %v", handled, err, live, u.effects) |
| + } |
| +} |
| + |
| +// Root's rollback resume (resumeRootRestart): adoption moved v1 to v2, both |
| +// writer-aware, and the root pass died during the restart. The resume's |
| +// rollback onto v1 meets a deployment outage at the floor read: the journal |
| +// is left exactly as it was (no Recovering mark for a rollback that never |
| +// ran), and once the store answers the next resume rolls back. |
| +func TestRootRollbackResumeOutageLeavesTheJournal(t *testing.T) { |
| + t.Parallel() |
| + _, aware := floorConsoles(t) |
| + e, rt, u, c, pub := plan14AdoptionFixtureWith(t, aware, append(aware[:len(aware):len(aware)], 0)) |
| + u.crashNew = true |
| + getenv := func(string) string { return "5s" } |
| + forward := rootRestartRouteWith(e.root.reg, u, u.opt, getenv, nil, c) |
| + crashed := errors.New("root process exited") |
| + func() { |
| + defer func() { |
| + if got := recover(); got != crashed { |
| + t.Fatalf("crash boundary: %v", got) |
| + } |
| + }() |
| + _ = release.Pass(t.Context(), e.root.reg, e.store, pub, u.opt, func(host string) error { |
| + _ = forward(host) |
| + panic(crashed) |
| + }, release.BakeDir(e.bake), release.WithRestartFailurePropagation()) |
| + }() |
| + outage := &deploymentOutage{Store: e.store, downAt: 1} |
| + c.floor = func(context.Context) (release.Store, error) { return outage, nil } |
| + disk, err := c.attempts() |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + before, err := disk.Read(rollbackJournalKey(rt.Host)) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + c.started = &sync.Map{} |
| + err = recoverRootRestarts(context.Background(), u, u.opt, getenv, c, hostwrite.Config{}) |
| + if live, _ := release.LiveVersion(u.opt, rt.Host); !errors.Is(err, release.ErrConsoleFloor) || live != "v2" { |
| + t.Fatalf("rollback at the outage: %v, live %q", err, live) |
| + } |
| + if after, _ := disk.Read(rollbackJournalKey(rt.Host)); string(after) != string(before) { |
| + t.Fatalf("the refused rollback changed the journal:\n before %s\n after %s", before, after) |
| + } |
| + outage.up() |
| + c.started = &sync.Map{} |
| + if err := recoverRootRestarts(context.Background(), u, u.opt, getenv, c, hostwrite.Config{}); err != nil { |
| + t.Fatalf("resume once the store answers: %v", err) |
| + } |
| + if live, _ := release.LiveVersion(u.opt, rt.Host); live != "v1" || u.exe != release.VersionPath(u.opt, rt.Account, "v1", rt.App) { |
| + t.Fatalf("resume once the store answers: live %q, exe %s", live, u.exe) |
| + } |
| +} |
| + |
| +// Root's history rollback (resumeHistoryRestart), from active recovery: v1 |
| +// runs, recovery moves it to the signed head v2 (both writer-aware), v2's |
| +// restart fails, and the rollback onto v1 meets a deployment outage at the |
| +// floor read. The attempt is left as it stood before the rollback began |
| +// (failed, not recovering); once the store answers, root's resume rolls |
| +// back. |
| +func TestRootHistoryRollbackOutageLeavesTheJournal(t *testing.T) { |
| + // Not parallel: signedRecoveryFixture sets the release key with t.Setenv. |
| + _, aware := floorConsoles(t) |
| + e, u, c, source, pub := signedRecoveryFixtureWith(t, aware, append(aware[:len(aware):len(aware)], 0)) |
| + u.crashNew = true |
| + outage := &deploymentOutage{Store: e.store, downAt: 1} |
| + c.floor = func(context.Context) (release.Store, error) { return outage, nil } |
| + n := namedUnitRecovery{source: source, pub: pub, readLive: os.Readlink} |
| + getenv := func(string) string { return "5s" } |
| + handled, err := n.recover(t.Context(), observedHost, c, getenv, e.root.reg) |
| + if live, _ := release.LiveVersion(u.opt, observedHost); !handled || !errors.Is(err, release.ErrConsoleFloor) || live != "v2" { |
| + t.Fatalf("history rollback at the outage: handled %v, err %v, live %q", handled, err, live) |
| + } |
| + disk, err := c.attempts() |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + a, err := readRollbackAttempt(disk, observedHost) |
| + if err != nil || !a.Failed || a.Recovering || a.Settled { |
| + t.Fatalf("the refused rollback changed the attempt: %+v, %v", a, err) |
| + } |
| + outage.up() |
| + c.started = &sync.Map{} |
| + if err := recoverRootRestarts(t.Context(), u, u.opt, getenv, c, hostwrite.Config{}); err != nil { |
| + t.Fatalf("resume once the store answers: %v", err) |
| + } |
| + if live, _ := release.LiveVersion(u.opt, observedHost); live != "v1" || u.exe != release.VersionPath(u.opt, "bab", "v1", "console") { |
| + t.Fatalf("resume once the store answers: live %q, exe %s", live, u.exe) |
| + } |
| +} |
diff --git a/internal/host/namedrecovery.go b/internal/host/namedrecovery.go| index 96a5c2240..da8b2f2f9 100644 |
| --- a/internal/host/namedrecovery.go |
| +++ b/internal/host/namedrecovery.go |
| @@ -120,7 +120,9 @@ func (n namedUnitRecovery) repair(ctx context.Context, host string) (bool, error |
| if hex.EncodeToString(hash.Sum(nil)) != m.Artifacts[release.AdoptPlatform()].SHA256 { |
| return os.ErrPermission |
| } |
| - if err := release.PointLive(ctx, n.source.store, n.source.optDir, host, rec.Account, pointer.Version, rec.App); err != nil { |
| + // Nothing is recorded before this swap, so a floor refusal has |
| + // nothing to undo (release.AbortBeforeEffect). |
| + if err := release.AbortBeforeEffect(release.PointLive(ctx, n.source.store, n.source.optDir, host, rec.Account, pointer.Version, rec.App)); err != nil { |
| return err |
| } |
| dir, err := os.Open(filepath.Dir(live)) |
diff --git a/internal/host/namedrecovery_active.go b/internal/host/namedrecovery_active.go| index 68a8d5bca..1a63ff2fb 100644 |
| --- a/internal/host/namedrecovery_active.go |
| +++ b/internal/host/namedrecovery_active.go |
| @@ -199,15 +199,12 @@ func (n namedUnitRecovery) recover(ctx context.Context, host string, c rootResta |
| if err != nil { |
| return err |
| } |
| - if err := release.PointLive(ctx, n.source.store, n.source.optDir, host, rec.Account, pointer.Version, rec.App); err != nil { |
| - if errors.Is(err, release.ErrConsoleFloor) { |
| - // The floor refused at the swap (a read that failed since |
| - // the check above): nothing was published, so the attempt |
| - // never ran. Undo the capture, or root's resume would settle |
| - // it as a recovery onto the build still running and block |
| - // this promotion for good (Astra phase 2 round 1). |
| - return errors.Join(err, abandonRollbackCapture(s, attempt, journal)) |
| - } |
| + // A floor refusal at the swap (a read that failed since the check |
| + // above) undoes the capture, or root's resume would settle it as a |
| + // recovery onto the build still running and block this promotion |
| + // for good (release.AbortBeforeEffect; Astra phase 2 round 1). |
| + if err := release.AbortBeforeEffect(release.PointLive(ctx, n.source.store, n.source.optDir, host, rec.Account, pointer.Version, rec.App), |
| + func() error { return abandonRollbackCapture(s, attempt, journal) }); err != nil { |
| return err |
| } |
| dir, err := os.Open(filepath.Dir(live)) |
diff --git a/internal/host/plan14_canonical_restart_test.go b/internal/host/plan14_canonical_restart_test.go| index 315338447..3a0c7db3b 100644 |
| --- a/internal/host/plan14_canonical_restart_test.go |
| +++ b/internal/host/plan14_canonical_restart_test.go |
| @@ -96,6 +96,14 @@ func plan14AdoptionFixture(t *testing.T) (*proofRootEnv, registry.Route, *plan14 |
| // plan14AdoptionFixtureWith is plan14AdoptionFixture with v1's and v2's |
| // bytes chosen. |
| func plan14AdoptionFixtureWith(t *testing.T, v1, v2 []byte) (*proofRootEnv, registry.Route, *plan14RestartUnits, rootRestartChecks, ed25519.PublicKey) { |
| + t.Helper() |
| + e, rt, u, c, pub, _ := plan14AdoptionFixtureSource(t, v1, v2) |
| + return e, rt, u, c, pub |
| +} |
| + |
| +// plan14AdoptionFixtureSource is plan14AdoptionFixtureWith with the proof |
| +// binding source the checks are bound to, so a test can change its store. |
| +func plan14AdoptionFixtureSource(t *testing.T, v1, v2 []byte) (*proofRootEnv, registry.Route, *plan14RestartUnits, rootRestartChecks, ed25519.PublicKey, *proofBindingSource) { |
| t.Helper() |
| e, rt, rec, source := plan14ProofFixtureWith(t, v1) |
| if got := e.root.observeAndRecord(rt, 15*time.Minute); got.err != nil { |
| @@ -131,7 +139,7 @@ func plan14AdoptionFixtureWith(t *testing.T, v1, v2 []byte) (*proofRootEnv, regi |
| now, sleep := settleClock() |
| mem := &rollbackMemory{files: map[string][]byte{}} |
| c := rootRestartChecks{targetFile: os.Open, started: &sync.Map{}, attempts: func() (rootstate.Store, error) { return mem, nil }, rollback: source.rollback, prepareRollback: source.prepareRollback, resolve: source.resolve, host: source.forHost, ready: e.root.obs.ready, now: now, sleep: sleep} |
| - return e, rt, u, c, pub |
| + return e, rt, u, c, pub, source |
| } |
| func TestPlan14AdoptionCanonicalReadiness(t *testing.T) { |
diff --git a/internal/host/roothistory_recovery.go b/internal/host/roothistory_recovery.go| index a89e91dc0..0e75cd9b0 100644 |
| --- a/internal/host/roothistory_recovery.go |
| +++ b/internal/host/roothistory_recovery.go |
| @@ -5,6 +5,7 @@ import ( |
| "errors" |
| "log" |
| "os" |
| + "sync" |
| "github.com/carlosframework/platform/internal/hostwrite" |
| "github.com/carlosframework/platform/internal/release" |
| @@ -18,7 +19,48 @@ type historyRollbackLink struct { |
| Independent bool |
| } |
| +// preparedCapture is what linkRootHistory's Prepare captured for one |
| +// history attempt, kept so Abort can undo it from local state alone. |
| +type preparedCapture struct { |
| + attempt rollbackAttempt |
| + journal []byte // the journal just before the capture; nil: none |
| +} |
| + |
| func linkRootHistory(h *release.RootHistoryPass, checks rootRestartChecks, optDir string, getenv func(string) string) { |
| + var mu sync.Mutex |
| + prepared := map[string]preparedCapture{} |
| + // Abort undoes Prepare for a history attempt the console floor refused |
| + // before any effect (release.AbortBeforeEffect): the rollback journal |
| + // goes back to what it held before the capture and the capture's |
| + // capability goes. Root's own attempts store only, never the deployment |
| + // store. A capture this pass did not make, or a journal that has moved |
| + // on to another attempt, is left alone. |
| + h.Abort = func(ctx context.Context, binding release.HistoryBinding, id string) error { |
| + mu.Lock() |
| + p, ok := prepared[id] |
| + delete(prepared, id) |
| + mu.Unlock() |
| + if !ok { |
| + return nil |
| + } |
| + s, err := checks.attempts() |
| + if err != nil { |
| + return err |
| + } |
| + defer s.Close() |
| + unlock, err := s.Lock(ctx, rollbackHostKey(binding.Host)+".lock") |
| + if err != nil { |
| + return err |
| + } |
| + defer unlock() |
| + current, err := readRollbackAttempt(s, binding.Host) |
| + if errors.Is(err, os.ErrNotExist) || err == nil && current.ID != p.attempt.ID { |
| + return nil |
| + } else if err != nil { |
| + return err |
| + } |
| + return abandonRollbackCapture(s, p.attempt, p.journal) |
| + } |
| h.Prepare = func(ctx context.Context, binding release.HistoryBinding, attempt release.HistoryAttempt, identity hostwrite.Identity) error { |
| b, err := checks.host(ctx, binding.Host) |
| if err != nil { |
| @@ -45,8 +87,20 @@ func linkRootHistory(h *release.RootHistoryPass, checks rootRestartChecks, optDi |
| if err != nil || live != release.VersionPath(optDir, binding.Account, b.Version, binding.App) { |
| return errors.Join(err, os.ErrPermission) |
| } |
| - _, err = captureRollback(s, b, checks.now(), unitSettleTimeout(getenv), release.VersionPath(optDir, binding.Account, attempt.Version, binding.App), identity, historyRollbackLink{Binding: binding, Attempt: attempt}) |
| - return err |
| + journal, err := s.Read(rollbackJournalKey(binding.Host)) |
| + if errors.Is(err, os.ErrNotExist) { |
| + journal = nil |
| + } else if err != nil { |
| + return err |
| + } |
| + captured, err := captureRollback(s, b, checks.now(), unitSettleTimeout(getenv), release.VersionPath(optDir, binding.Account, attempt.Version, binding.App), identity, historyRollbackLink{Binding: binding, Attempt: attempt}) |
| + if err != nil { |
| + return err |
| + } |
| + mu.Lock() |
| + prepared[attempt.ID] = preparedCapture{attempt: captured, journal: journal} |
| + mu.Unlock() |
| + return nil |
| } |
| } |
| @@ -208,12 +262,16 @@ func resumeHistoryRestart(ctx context.Context, sys unitSystem, optDir string, ge |
| } else if p.ActiveState != "failed" && p.MainPID != 0 && !a.Failed { |
| return os.ErrPermission |
| } |
| + before := a |
| a.Recovering = true |
| if err := writeRollbackState(s, rollbackJournalKey(a.Host), a); err != nil { |
| return err |
| } |
| if live != previous { |
| - return checks.repointLive(ctx, optDir, a.Host, old.Route.Account, old.Version, old.Route.App) |
| + // A floor refusal puts the journal back as it was: this rollback |
| + // never ran (release.AbortBeforeEffect). |
| + return release.AbortBeforeEffect(checks.repointLive(ctx, optDir, a.Host, old.Route.Account, old.Version, old.Route.App), |
| + func() error { return writeRollbackState(s, rollbackJournalKey(before.Host), before) }) |
| } |
| return nil |
| }) |
diff --git a/internal/host/rootrollback_resume.go b/internal/host/rootrollback_resume.go| index 6e8d2acc6..e483e2de8 100644 |
| --- a/internal/host/rootrollback_resume.go |
| +++ b/internal/host/rootrollback_resume.go |
| @@ -79,7 +79,15 @@ func resumeRootRestart(ctx context.Context, sys unitSystem, optDir string, geten |
| if a.ID != expected.ID { |
| return errors.Join(err, os.ErrPermission) |
| } |
| - defer func() { result = errors.Join(result, settleRollbackAttempt(s, a)) }() |
| + defer func() { |
| + // A rollback the console floor refused before any effect never ran |
| + // (release.AbortBeforeEffect put the journal back): the attempt is |
| + // left unsettled for the next resume to try again, not given up. |
| + if errors.Is(result, release.ErrConsoleFloor) { |
| + return |
| + } |
| + result = errors.Join(result, settleRollbackAttempt(s, a)) |
| + }() |
| if err != nil { |
| return err |
| } |
| @@ -117,12 +125,16 @@ func resumeRootRestart(ctx context.Context, sys unitSystem, optDir string, geten |
| } else if p.ActiveState != "failed" && p.MainPID != 0 && !a.Failed { |
| return os.ErrPermission |
| } |
| + before := a |
| a.Recovering = true |
| if err := writeRollbackState(s, rollbackJournalKey(a.Host), a); err != nil { |
| return err |
| } |
| if live != old { |
| - return checks.repointLive(ctx, optDir, a.Host, b.Route.Account, b.Version, b.Route.App) |
| + // A floor refusal puts the journal back as it was: this rollback |
| + // never ran (release.AbortBeforeEffect). |
| + return release.AbortBeforeEffect(checks.repointLive(ctx, optDir, a.Host, b.Route.Account, b.Version, b.Route.App), |
| + func() error { return writeRollbackState(s, rollbackJournalKey(before.Host), before) }) |
| } |
| return nil |
| }) |
diff --git a/internal/release/adopt.go b/internal/release/adopt.go| index 2608c25a3..bb1533b5f 100644 |
| --- a/internal/release/adopt.go |
| +++ b/internal/release/adopt.go |
| @@ -1988,7 +1988,9 @@ func adoptHost(ctx context.Context, work hostwrite.Work, reg *registry.Registry, |
| rolledBack := false |
| var rollbackErr error |
| if cur != "" { |
| - if perr := withReleaseWork(ctx, work, id, func() error { return PointLive(ctx, s, optDir, rt.Host, RouteAccount(rt), cur, rt.App) }); perr != nil { |
| + if perr := withReleaseWork(ctx, work, id, func() error { |
| + return AbortBeforeEffect(PointLive(ctx, s, optDir, rt.Host, RouteAccount(rt), cur, rt.App)) |
| + }); perr != nil { |
| fmt.Printf(" %s: could not roll the symlink back to %s: %v\n", rt.Host, cur, perr) |
| rollbackErr = perr |
| } else { |
diff --git a/internal/release/consolefloor.go b/internal/release/consolefloor.go| index ea079c5e2..29d7a65c8 100644 |
| --- a/internal/release/consolefloor.go |
| +++ b/internal/release/consolefloor.go |
| @@ -189,6 +189,40 @@ func admitConsoleFloor(ctx context.Context, s Store, optDir, host, acct, ver, ap |
| return &ConsoleFloorError{Host: host, Version: ver, Reason: why} |
| } |
| +// AbortBeforeEffect is the abort rule for an attempt the console floor |
| +// refused (store write credential design §14, Paul's choice A of |
| +// 2026-11-25), in one place. Every path whose repoint PointLive can refuse |
| +// passes PointLive's error through it, with the undo of whatever it |
| +// recorded for the attempt before the swap (most record nothing and pass |
| +// no undo). |
| +// |
| +// When err is the floor's refusal (ErrConsoleFloor, a floor read that |
| +// failed included), nothing was published: the attempt never ran. Each |
| +// undo then runs, in order, every one even if an earlier one failed. An |
| +// undo touches root's local state only, never the deployment store, so a |
| +// cancellation cannot wait on the outage that caused the refusal; and it |
| +// records no refusal, so the build counts as never tried and the next |
| +// pass asks again. Any other error is returned as it is and nothing is |
| +// undone: a repoint that failed for another reason may have moved the link. |
| +func AbortBeforeEffect(err error, undo ...func() error) error { |
| + if !errors.Is(err, ErrConsoleFloor) { |
| + return err |
| + } |
| + var failed []error |
| + for _, u := range undo { |
| + if u == nil { |
| + continue |
| + } |
| + if uerr := u(); uerr != nil { |
| + failed = append(failed, uerr) |
| + } |
| + } |
| + if len(failed) == 0 { |
| + return err |
| + } |
| + return errors.Join(err, fmt.Errorf("cancelling the refused attempt: %w", errors.Join(failed...))) |
| +} |
| + |
| // CheckConsoleFloor is admitConsoleFloor for a caller that must know the |
| // answer before work it would otherwise have to undo (named-unit recovery |
| // asks it before capturing a rollback attempt). It moves nothing; PointLive |
diff --git a/internal/release/consolefloor_guard_test.go b/internal/release/consolefloor_guard_test.go| index c07389a06..7f3483137 100644 |
| --- a/internal/release/consolefloor_guard_test.go |
| +++ b/internal/release/consolefloor_guard_test.go |
| @@ -63,7 +63,7 @@ func TestEveryRepointPassesTheConsoleFloor(t *testing.T) { |
| } |
| rel, _ := filepath.Rel(root, p) |
| rel = filepath.ToSlash(rel) |
| - f, err := parser.ParseFile(token.NewFileSet(), p, nil, parser.SkipObjectResolution) |
| + f, err := parser.ParseFile(token.NewFileSet(), p, nil, parser.SkipObjectResolution|parser.ParseComments) |
| if err != nil { |
| return err |
| } |
| @@ -167,8 +167,24 @@ type guardFunc struct { |
| pkg string |
| imports map[string]string |
| params []string |
| + results []string // named results, for a bare return |
| + // pathResult: a result is a string or an *os.File, the only kinds a |
| + // path takes. Only such functions get return summaries: a struct a |
| + // helper returns is data, whatever one of its fields holds. |
| + pathResult bool |
| body *ast.BlockStmt |
| paths map[string]bool |
| + sum *guardSummaries |
| +} |
| + |
| +// guardSummaries are what the module's functions do with paths, found to a |
| +// fixpoint: which parameters reach a write destination (writers), which |
| +// carry through to a result (passes), and which functions return a live |
| +// link's path (returnsLive). |
| +type guardSummaries struct { |
| + writers map[string]map[int]bool |
| + passes map[string]map[int]bool |
| + returnsLive map[string]bool |
| } |
| // callee resolves a call's function to the keys it may name. |
| @@ -228,7 +244,14 @@ func (g *guardFunc) tainted(e ast.Expr, taint map[string]bool, live bool) bool { |
| case *ast.IndexExpr: |
| return g.tainted(x.X, taint, live) |
| case *ast.SelectorExpr: |
| - return g.tainted(x.X, taint, live) || live && liveNames[x.Sel.Name] |
| + // A field of a tainted value carries a parameter's taint (a path |
| + // in a struct a helper writes), but not a live link's: a value |
| + // holding one in a field is data, and its other fields are not |
| + // that path. |
| + if live { |
| + return liveNames[x.Sel.Name] |
| + } |
| + return g.tainted(x.X, taint, live) |
| case *ast.CallExpr: |
| if sel, ok := x.Fun.(*ast.SelectorExpr); ok && sel.Sel.Name == "Fd" && g.tainted(sel.X, taint, live) { |
| return true |
| @@ -238,12 +261,13 @@ func (g *guardFunc) tainted(e ast.Expr, taint map[string]bool, live bool) bool { |
| if live && liveNames[name] { |
| return true |
| } |
| + if live && g.sum.returnsLive[c] { |
| + return true |
| + } |
| id, conv := x.Fun.(*ast.Ident) |
| - if g.paths[c] || conv && conversions[id.Name] { |
| - for _, a := range x.Args { |
| - if g.tainted(a, taint, live) { |
| - return true |
| - } |
| + for i, a := range x.Args { |
| + if (g.paths[c] || conv && conversions[id.Name] || g.sum.passes[c][i]) && g.tainted(a, taint, live) { |
| + return true |
| } |
| } |
| } |
| @@ -294,6 +318,29 @@ func (g *guardFunc) spread(taint map[string]bool, live bool) { |
| } |
| } |
| +// returns reports whether a result of g is tainted by taint (and live): |
| +// a return statement's value, or a named result at a bare return. |
| +func (g *guardFunc) returns(taint map[string]bool, live bool) bool { |
| + hit := false |
| + ast.Inspect(g.body, func(n ast.Node) bool { |
| + switch x := n.(type) { |
| + case *ast.FuncLit: |
| + return false |
| + case *ast.ReturnStmt: |
| + for _, r := range x.Results { |
| + hit = hit || g.tainted(r, taint, live) |
| + } |
| + if len(x.Results) == 0 { |
| + for _, r := range g.results { |
| + hit = hit || taint[r] |
| + } |
| + } |
| + } |
| + return !hit |
| + }) |
| + return hit |
| +} |
| + |
| // sinks calls hit for every argument of a call in g, tainted by taint (and |
| // live), that lands at a write destination: a primitive's, or a writer |
| // parameter of a module function in writers. |
| @@ -316,7 +363,7 @@ func (g *guardFunc) sinks(taint map[string]bool, live bool, prims map[string][]i |
| } |
| for _, i := range dests { |
| if i < len(call.Args) && g.tainted(call.Args[i], taint, live) { |
| - hit(c) |
| + hit(c + " (argument " + strconv.Itoa(i+1) + ")") |
| return true |
| } |
| } |
| @@ -328,8 +375,12 @@ func repointOffences(mod string, files []guardFile) []repointOffence { |
| prims := writeDests(mod) |
| paths := pathCalls(mod) |
| sanctioned := mod + "/internal/release.PointLive" |
| + sum := &guardSummaries{writers: map[string]map[int]bool{}, passes: map[string]map[int]bool{}, returnsLive: map[string]bool{}} |
| + writers := sum.writers |
| var funcs []*guardFunc |
| + var out []repointOffence |
| for _, gf := range files { |
| + out = append(out, bareSwapUses(mod, gf)...) |
| imports := map[string]string{} |
| for _, im := range gf.file.Imports { |
| p, _ := strconv.Unquote(im.Path.Value) |
| @@ -344,7 +395,7 @@ func repointOffences(mod string, files []guardFile) []repointOffence { |
| if !ok || fn.Body == nil { |
| continue |
| } |
| - g := &guardFunc{pkg: gf.pkg, imports: imports, body: fn.Body, paths: paths} |
| + g := &guardFunc{pkg: gf.pkg, imports: imports, body: fn.Body, paths: paths, sum: sum} |
| name := fn.Name.Name |
| g.key = gf.pkg + "." + name |
| if fn.Recv != nil && len(fn.Recv.List) == 1 { |
| @@ -360,12 +411,30 @@ func repointOffences(mod string, files []guardFile) []repointOffence { |
| g.params = append(g.params, n.Name) |
| } |
| } |
| + if fn.Type.Results != nil { |
| + for _, f := range fn.Type.Results.List { |
| + g.pathResult = g.pathResult || pathType(f.Type) |
| + for _, n := range f.Names { |
| + g.results = append(g.results, n.Name) |
| + } |
| + } |
| + } |
| funcs = append(funcs, g) |
| } |
| } |
| - // writers[key]: the parameters of the functions under key that reach a |
| - // write destination, to a fixpoint across the module. |
| - writers := map[string]map[int]bool{} |
| + // The summaries, to a fixpoint across the module: a parameter that |
| + // reaches a write destination, a parameter that reaches a result, and a |
| + // result that is a live link's path, each through the others. |
| + set := func(m map[string]map[int]bool, k string, i int) bool { |
| + if m[k][i] { |
| + return false |
| + } |
| + if m[k] == nil { |
| + m[k] = map[int]bool{} |
| + } |
| + m[k][i] = true |
| + return true |
| + } |
| for grew := true; grew; { |
| grew = false |
| for _, g := range funcs { |
| @@ -373,37 +442,31 @@ func repointOffences(mod string, files []guardFile) []repointOffence { |
| continue |
| } |
| for i, p := range g.params { |
| - if p == "_" || writers[g.key][i] { |
| + if p == "_" { |
| continue |
| } |
| taint := map[string]bool{p: true} |
| g.spread(taint, false) |
| reached := false |
| g.sinks(taint, false, prims, writers, sanctioned, func(string) { reached = true }) |
| - if reached { |
| - if writers[g.key] == nil { |
| - writers[g.key] = map[int]bool{} |
| - } |
| - writers[g.key][i], grew = true, true |
| + if reached && set(writers, g.key, i) { |
| + grew = true |
| + } |
| + if g.pathResult && g.returns(taint, false) && set(sum.passes, g.key, i) { |
| + grew = true |
| + } |
| + } |
| + if g.pathResult && !sum.returnsLive[g.key] { |
| + taint := map[string]bool{} |
| + g.spread(taint, true) |
| + if g.returns(taint, true) { |
| + sum.returnsLive[g.key], grew = true, true |
| } |
| } |
| } |
| } |
| - var out []repointOffence |
| for _, g := range funcs { |
| - isSwap := strings.HasSuffix(g.where, "internal/release/versions.go:pointLive") |
| - isGate := strings.HasSuffix(g.where, "internal/release/versions.go:PointLive") |
| - bare := false |
| - ast.Inspect(g.body, func(n ast.Node) bool { |
| - if id, ok := n.(*ast.Ident); ok && id.Name == "pointLive" { |
| - bare = true |
| - } |
| - return !bare |
| - }) |
| - if bare && !isGate && !isSwap { |
| - out = append(out, repointOffence{g.where, "uses pointLive, the swap without the console floor; call PointLive"}) |
| - } |
| - if isSwap { |
| + if strings.HasSuffix(g.where, "internal/release/versions.go:pointLive") { |
| continue |
| } |
| taint := map[string]bool{} |
| @@ -417,6 +480,86 @@ func repointOffences(mod string, files []guardFile) []repointOffence { |
| return out |
| } |
| +// pathType reports whether t is a string or an *os.File. |
| +func pathType(t ast.Expr) bool { |
| + if id, ok := t.(*ast.Ident); ok { |
| + return id.Name == "string" |
| + } |
| + if st, ok := t.(*ast.StarExpr); ok { |
| + if sel, ok := st.X.(*ast.SelectorExpr); ok { |
| + if pkg, ok := sel.X.(*ast.Ident); ok { |
| + return pkg.Name == "os" && sel.Sel.Name == "File" |
| + } |
| + } |
| + } |
| + return false |
| +} |
| + |
| +// bareSwapUses is the first rule, over the whole file: in package release, |
| +// every occurrence of the identifier pointLive outside PointLive's body and |
| +// pointLive's own name (a call, a function value, a package-level alias, a |
| +// method value), and anywhere, a go:linkname directive naming it. An |
| +// unexported function is reachable from its own package only by its |
| +// identifier and from another only by go:linkname, so this is all of them. |
| +func bareSwapUses(mod string, gf guardFile) []repointOffence { |
| + var out []repointOffence |
| + for _, cg := range gf.file.Comments { |
| + for _, c := range cg.List { |
| + if strings.HasPrefix(c.Text, "//go:linkname") && strings.Contains(c.Text, "pointLive") { |
| + out = append(out, repointOffence{gf.rel + ":go:linkname", "links to pointLive, the swap without the console floor"}) |
| + } |
| + } |
| + } |
| + if gf.pkg != mod+"/internal/release" { |
| + return out |
| + } |
| + for _, decl := range gf.file.Decls { |
| + var skip ast.Node |
| + if fn, ok := decl.(*ast.FuncDecl); ok && fn.Recv == nil { |
| + switch fn.Name.Name { |
| + case "PointLive": |
| + skip = fn.Body |
| + case "pointLive": |
| + skip = fn.Name |
| + } |
| + } |
| + found := false |
| + ast.Inspect(decl, func(n ast.Node) bool { |
| + if n == nil || n == skip { |
| + return false |
| + } |
| + if id, ok := n.(*ast.Ident); ok && id.Name == "pointLive" { |
| + found = true |
| + } |
| + return !found |
| + }) |
| + if found { |
| + out = append(out, repointOffence{gf.rel + ":" + declName(decl), "uses pointLive, the swap without the console floor; call PointLive"}) |
| + } |
| + } |
| + return out |
| +} |
| + |
| +func declName(d ast.Decl) string { |
| + switch x := d.(type) { |
| + case *ast.FuncDecl: |
| + if x.Recv != nil && len(x.Recv.List) == 1 { |
| + return recvName(x.Recv.List[0].Type) + "." + x.Name.Name |
| + } |
| + return x.Name.Name |
| + case *ast.GenDecl: |
| + for _, sp := range x.Specs { |
| + switch v := sp.(type) { |
| + case *ast.ValueSpec: |
| + return v.Names[0].Name |
| + case *ast.TypeSpec: |
| + return v.Name.Name |
| + } |
| + } |
| + } |
| + return "?" |
| +} |
| + |
| func recvName(e ast.Expr) string { |
| switch x := e.(type) { |
| case *ast.StarExpr: |
| @@ -435,14 +578,16 @@ func recvName(e ast.Expr) string { |
| // writer of the live link written inline, through a local, through an |
| // aliased "os", through its directory's descriptor, through a helper in the |
| // same package, through a method, and through a helper in another package; |
| -// and a use of the bare swap. It leaves alone PointLive's own callers, |
| -// writers that name no live link, and data derived from one (Astra phase 2 |
| -// round 1, finding 2). |
| +// through a helper that returns the path, a named result or a helper the |
| +// path passes through (Astra phase 2 round 2, finding 2); and a use of the |
| +// bare swap, including a package-level alias and a go:linkname. It leaves |
| +// alone PointLive's own callers, writers that name no live link, and data |
| +// derived from one (round 1, finding 2). |
| func TestRepointGuardCatchesASecondDoor(t *testing.T) { |
| const mod = "example.com/m" |
| parse := func(rel, src string) guardFile { |
| t.Helper() |
| - f, err := parser.ParseFile(token.NewFileSet(), rel, src, parser.SkipObjectResolution) |
| + f, err := parser.ParseFile(token.NewFileSet(), rel, src, parser.SkipObjectResolution|parser.ParseComments) |
| if err != nil { |
| t.Fatal(err) |
| } |
| @@ -487,6 +632,32 @@ func dataOnly(opt, host string) error { |
| func hash(string) string { return "" } |
| +func destination(opt, host string) string { |
| + return release.LiveLink(opt, host) |
| +} |
| + |
| +func viaReturnedPath(opt, host, target string) error { |
| + return os.Symlink(target, destination(opt, host)) |
| +} |
| + |
| +func named(opt, host string) (p string) { |
| + p = release.LiveLink(opt, host) |
| + return |
| +} |
| + |
| +func viaNamedResult(opt, host, target string) error { |
| + return os.Rename(target, named(opt, host)) |
| +} |
| + |
| +func beside(dir, name string) string { return dir + "/" + name } |
| + |
| +func viaPassThrough(opt, host, target string) error { |
| + return os.Rename(target, beside(filepath.Dir(release.LiveLink(opt, host)), host)) |
| +} |
| + |
| +//go:linkname sneakySwap example.com/m/internal/release.pointLive |
| +func sneakySwap(opt, host string) error |
| + |
| func inline(opt, host, target string) error { |
| return os.Symlink(target, release.LiveLink(opt, host)) |
| } |
| @@ -545,6 +716,10 @@ func LiveLink(opt, host string) string { return opt + "/live/" + host } |
| func PointLive(_, _ any, opt, host, acct, ver, app string) error { return pointLive(opt, host) } |
| func pointLive(opt, host string) error { return os.Symlink("x", LiveLink(opt, host)) } |
| func other(opt, host string) error { return pointLive(opt, host) } |
| + |
| +var repoint = pointLive |
| + |
| +func viaAlias(opt, host string) error { return repoint(opt, host) } |
| `), |
| } |
| var got []string |
| @@ -553,10 +728,11 @@ func other(opt, host string) error { return pointLive(opt, host) } |
| } |
| sort.Strings(got) |
| want := []string{ |
| - "internal/host/x.go:aliased", "internal/host/x.go:inline", "internal/host/x.go:literal", |
| + "internal/host/x.go:aliased", "internal/host/x.go:go:linkname", "internal/host/x.go:inline", "internal/host/x.go:literal", |
| "internal/host/x.go:viaDirFD", "internal/host/x.go:viaHelper", "internal/host/x.go:viaMethod", |
| - "internal/host/x.go:viaOtherPackage", "internal/host/x.go:viaVariable", |
| - "internal/release/versions.go:other", |
| + "internal/host/x.go:viaNamedResult", "internal/host/x.go:viaOtherPackage", "internal/host/x.go:viaPassThrough", |
| + "internal/host/x.go:viaReturnedPath", "internal/host/x.go:viaVariable", |
| + "internal/release/versions.go:other", "internal/release/versions.go:repoint", |
| } |
| if strings.Join(got, ",") != strings.Join(want, ",") { |
| t.Fatalf("offences =\n %s\nwant\n %s", strings.Join(got, "\n "), strings.Join(want, "\n ")) |
diff --git a/internal/release/materializeheld.go b/internal/release/materializeheld.go| index 11975758d..7d3fc0fc2 100644 |
| --- a/internal/release/materializeheld.go |
| +++ b/internal/release/materializeheld.go |
| @@ -457,7 +457,7 @@ func publishHeld(ctx context.Context, s Store, optDir string, rt registry.Route, |
| return notProven |
| } |
| heldBeforeSwap() |
| - if err := PointLive(ctx, s, optDir, rt.Host, RouteAccount(rt), version, rt.App); err != nil { |
| + if err := AbortBeforeEffect(PointLive(ctx, s, optDir, rt.Host, RouteAccount(rt), version, rt.App)); err != nil { |
| if StageBlocked(err) { |
| return fmt.Errorf("%w: %w", ErrStageBlocked, err) |
| } |
| @@ -491,7 +491,7 @@ func restoreLive(ctx context.Context, s Store, optDir string, rt registry.Route, |
| } |
| return nil |
| } |
| - return PointLive(ctx, s, optDir, rt.Host, RouteAccount(rt), cur, rt.App) |
| + return AbortBeforeEffect(PointLive(ctx, s, optDir, rt.Host, RouteAccount(rt), cur, rt.App)) |
| } |
| // Held refusals (final review finding 3) live in their own namespace, |
diff --git a/internal/release/rollback.go b/internal/release/rollback.go| index 57e104dd1..d1bc9e55c 100644 |
| --- a/internal/release/rollback.go |
| +++ b/internal/release/rollback.go |
| @@ -121,7 +121,9 @@ func rollbackGroup(ctx context.Context, reg *registry.Registry, s Store, optDir |
| fmt.Printf(" %s: not rolled back with its process: release work: %v\n", g.Host, err) |
| continue |
| } |
| - if err := with(func() error { return PointLive(ctx, s, optDir, g.Host, RouteAccount(g), restored, g.App) }); err != nil { |
| + if err := with(func() error { |
| + return AbortBeforeEffect(PointLive(ctx, s, optDir, g.Host, RouteAccount(g), restored, g.App)) |
| + }); err != nil { |
| fmt.Printf(" %s: could not roll the symlink back to %s with its process: %v\n", g.Host, restored, err) |
| continue |
| } |
diff --git a/internal/release/roothistory_pass.go b/internal/release/roothistory_pass.go| index 984cbeb05..a9c96b62a 100644 |
| --- a/internal/release/roothistory_pass.go |
| +++ b/internal/release/roothistory_pass.go |
| @@ -4,7 +4,6 @@ import ( |
| "context" |
| "crypto/rand" |
| "encoding/hex" |
| - "errors" |
| "fmt" |
| "os" |
| "slices" |
| @@ -15,11 +14,15 @@ import ( |
| ) |
| type RootHistoryPass struct { |
| - Creation func(context.Context, registry.Route) (string, error) |
| - History *RootHistory |
| - Resolve func(context.Context, registry.Route) (HistoryBinding, string, error) |
| - Installed func(context.Context, registry.Route, string) (string, error) |
| - Prepare func(context.Context, HistoryBinding, HistoryAttempt, hostwrite.Identity) error |
| + Creation func(context.Context, registry.Route) (string, error) |
| + History *RootHistory |
| + Resolve func(context.Context, registry.Route) (HistoryBinding, string, error) |
| + Installed func(context.Context, registry.Route, string) (string, error) |
| + Prepare func(context.Context, HistoryBinding, HistoryAttempt, hostwrite.Identity) error |
| + // Abort undoes Prepare for the attempt id, from root's local state |
| + // only, when the console floor refused the attempt before any effect |
| + // (AbortBeforeEffect). nil: Prepare recorded nothing to undo. |
| + Abort func(context.Context, HistoryBinding, string) error |
| Reconstruct func(context.Context, HistoryBinding) error |
| } |
| @@ -149,32 +152,34 @@ func (h *RootHistoryPass) CompleteAttempt(ctx context.Context, rt registry.Route |
| return h.complete(ctx, rt, sel, a.ID, a.Version) |
| } |
| -// repointFailed is adoptHost's history bookkeeping when its forward |
| -// repoint fails: the error is recorded (historyError), and a console floor |
| -// refusal at the swap (the floor read failed since adoptHost's early check) |
| -// also settles the history attempt id with no refusal, because it precedes |
| -// every effect of that attempt: the build counts as never tried and the |
| -// next pass asks again (Astra phase 2 round 1). Any other error, or no |
| -// attempt, leaves the attempt as it was. |
| +// repointFailed is adoptHost's bookkeeping when its forward repoint |
| +// fails. The error goes through AbortBeforeEffect with the undo of the |
| +// history attempt id begun for it (undo), and is then recorded |
| +// (historyError). Any error but the console floor's leaves the attempt as |
| +// it was. |
| func (c passConfig) repointFailed(ctx context.Context, rt registry.Route, id string, err error) { |
| - c.historyError(err) |
| - if id == "" || !errors.Is(err, ErrConsoleFloor) { |
| - return |
| + var undo []func() error |
| + if id != "" && c.rootHistory != nil { |
| + undo = c.rootHistory.undo(ctx, c.historySelected[rt.Host].binding, id) |
| } |
| - if serr := c.rootHistory.abandon(ctx, rt, c.historySelected[rt.Host], id); serr != nil { |
| - c.historyError(serr) |
| - fmt.Printf(" %s: settling the history attempt the console floor stopped: %v\n", rt.Host, serr) |
| + if aerr := AbortBeforeEffect(err, undo...); aerr != err { |
| + fmt.Printf(" %s: %v\n", rt.Host, aerr) |
| + err = aerr |
| } |
| + c.historyError(err) |
| } |
| -// abandon settles attempt id, begun for rt, with no refusal: for a refusal |
| -// known to precede every effect of the attempt (nothing repointed or |
| -// restarted), so the build counts as never tried. |
| -func (h *RootHistoryPass) abandon(ctx context.Context, rt registry.Route, sel historySelection, id string) error { |
| - if err := h.recheck(ctx, rt, sel); err != nil { |
| - return err |
| +// undo is the undo of history attempt id, begun under binding, for |
| +// AbortBeforeEffect: Prepare's capture undone (Abort), then the attempt |
| +// settled with no refusal. Both are root's local state; neither reads the |
| +// deployment store, so neither waits on the outage that made the floor |
| +// refuse (Astra phase 2 round 2). |
| +func (h *RootHistoryPass) undo(ctx context.Context, b HistoryBinding, id string) []func() error { |
| + var out []func() error |
| + if h.Abort != nil { |
| + out = append(out, func() error { return h.Abort(ctx, b, id) }) |
| } |
| - return h.History.Settle(sel.binding, id, nil) |
| + return append(out, func() error { return h.History.Settle(b, id, nil) }) |
| } |
| func (h *RootHistoryPass) complete(ctx context.Context, rt registry.Route, sel historySelection, id, version string) error { |