hostexec: settle after a view answered past expiry (#1371)
TestPlan14ExecutionClientHasOneRenewalOwner flaked (18 of 900 under -race): Close returned "lease lost". The renewal goroutine's executionView was in flight when the lease expired; refresh saw the answer arrive past SafeUntil, lost the client and left the request uncertain. close() replayed the view; the broker refuses (and denies) a view past the cutoff, so close returned ErrLost and never sent executionSettle. Without a view in flight the same Close settles after expiry. A product race: whether an expired root execution settles depended on timing. close no longer replays an uncertain executionView sent with the known ControllerID: a view never changes the token, so the settle goes out with it. An uncertain begin or renew is still replayed to learn its token. TestPlan14ExecutionClientSettlesAfterAViewAnsweredPastExpiry holds the view's answer on a barrier while the clock passes the TTL; it fails without the fix (three views, no settle) and passes with it. Stress: both tests 300 x -cpu 1,4,16 under -race, 0 failures. Census: internal/hostexec envelope re-pinned. GO from 8a3d302.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
4 files changed,
+87
−0
docs/superpowers/notes/census-proposal-flake-hostexec-renewal.md+11 −0internal/hostexec/rootclient.go+9 −0internal/hostexec/rootclient_test.go+64 −0internal/provision/testdata/plan14-root-reads-flake-hostexec-renewal.tsv+3 −0
diff --git a/docs/superpowers/notes/census-proposal-flake-hostexec-renewal.md b/docs/superpowers/notes/census-proposal-flake-hostexec-renewal.md| new file mode 100644 |
| index 000000000..be381e8dc |
| --- /dev/null |
| +++ b/docs/superpowers/notes/census-proposal-flake-hostexec-renewal.md |
| @@ -0,0 +1,11 @@ |
| +# Census approval: flake-hostexec-renewal |
| + |
| +Ruling `census-ruling-flake-hostexec-renewal`. The independent reviewer approves or rejects every change below, 0 with a new disposition; nothing goes to the census owner (Paul, #280, 2026-10-26). |
| + |
| +Envelopes re-pinned: `internal/hostexec`. |
| + |
| +Review: a model from the other family than the author reads the branch's diff against main on the amadan.net remote (`origin` or `amadan`, whichever points at amadan.net) and gives a verdict for every unit and every re-pinned envelope above. For a unit, compare the change with its recorded disposition and basis below; for an envelope, read every changed function in the package and what it reaches. Reject if the change lets root open, run, query or follow anything it did not before from a path or input a tenant, an app or a box agent can create, write or name; if it weakens a check, refusal, validation, argument or environment the basis relies on; or if the diff cannot settle either. Otherwise approve. Record each verdict on #280 with the tip. A rejected unit goes back to the author to correct; nothing escalates to the census owner. |
| + |
| +Seal: `47ebd73418bcbe1bdf9cf34a2b94e3393a1279aea58f9ee0aca3f0cfe42b9132` → `47ebd73418bcbe1bdf9cf34a2b94e3393a1279aea58f9ee0aca3f0cfe42b9132`. |
| + |
| +Overlay: `internal/provision/testdata/plan14-root-reads-flake-hostexec-renewal.tsv`, appended to `internal/provision/testdata/plan14-root-reads-chain.tsv`. |
diff --git a/internal/hostexec/rootclient.go b/internal/hostexec/rootclient.go| index cc2c3b2b2..3123d4d72 100644 |
| --- a/internal/hostexec/rootclient.go |
| +++ b/internal/hostexec/rootclient.go |
| @@ -272,6 +272,15 @@ func (c *RootClient) close(ctx context.Context) error { |
| c.mu.Lock() |
| q, token, uncertain := c.request, c.state.ControllerID, c.uncertain |
| c.mu.Unlock() |
| + // The replay learns the token an uncertain begin or renew may have |
| + // changed. A view never changes it (the broker answers a view with the |
| + // record's token, and q.Token is the ControllerID it was sent with), so |
| + // an uncertain view settles with that token: replaying it after the |
| + // lease expired is refused and denied, and the settle would never go |
| + // out (#1371). |
| + if uncertain && q.Operation == "executionView" && q.Token != "" && q.Token == token { |
| + uncertain = false |
| + } |
| if uncertain { |
| if !q.Valid() { |
| return ErrLost |
diff --git a/internal/hostexec/rootclient_test.go b/internal/hostexec/rootclient_test.go| index 4e5dff928..3c5a6117a 100644 |
| --- a/internal/hostexec/rootclient_test.go |
| +++ b/internal/hostexec/rootclient_test.go |
| @@ -5,6 +5,7 @@ package hostexec |
| import ( |
| "context" |
| "errors" |
| + "sync" |
| "sync/atomic" |
| "testing" |
| "time" |
| @@ -138,3 +139,66 @@ func TestPlan14ExecutionClientLostTransitionResponseSettles(t *testing.T) { |
| t.Fatalf("transition recovery: %+v %v writes=%d", r, err, remote.calls) |
| } |
| } |
| + |
| +// #1371: a view whose answer arrives after the lease expired leaves the |
| +// request uncertain. Close must still settle, with the token the view was |
| +// sent with, rather than replay the view: the broker refuses and denies a |
| +// view past the cutoff, and the settle would never go out. Deterministic: |
| +// the view's answer is held on a barrier while the clock passes the TTL. |
| +// Begin and renew stay replayed (TestPlan14ExecutionClientLostBeginResponseSettles). |
| +func TestPlan14ExecutionClientSettlesAfterAViewAnsweredPastExpiry(t *testing.T) { |
| + b, _, _, clock, q, peer := brokerFixture(t) |
| + var hold atomic.Bool |
| + answered, release := make(chan struct{}), make(chan struct{}) |
| + var cleanup atomic.Int32 |
| + var ops []string |
| + var opsMu sync.Mutex |
| + c, err := OpenRootClient(t.Context(), RootClientConfig{ |
| + Binding: Binding{Host: q.Host, Incarnation: q.Incarnation, Op: q.Op, Box: "box", Enrollment: "en", BootID: peer.KernelBootID}, Clock: clock, |
| + Observe: func(context.Context) (ExecutionRequest, error) { return q, nil }, |
| + Call: func(ctx context.Context, q ExecutionRequest) (ExecutionResponse, error) { |
| + opsMu.Lock() |
| + ops = append(ops, q.Operation) |
| + opsMu.Unlock() |
| + out, err := b.Execute(ctx, peer, q) |
| + if q.Operation == "executionView" && hold.CompareAndSwap(true, false) { |
| + close(answered) |
| + <-release |
| + } |
| + return out, err |
| + }, |
| + CloseAdmission: func() {}, Cleanup: func(context.Context) error { cleanup.Add(1); return nil }, |
| + }) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + t.Cleanup(func() { _ = c.Close(context.Background()) }) |
| + hold.Store(true) |
| + refreshed := make(chan error, 1) |
| + go func() { refreshed <- c.Refresh(t.Context()) }() |
| + <-answered |
| + clock.advance(TTL) |
| + close(release) |
| + if err := <-refreshed; !errors.Is(err, ErrLost) { |
| + t.Fatalf("a view answered past expiry = %v, want ErrLost", err) |
| + } |
| + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) |
| + defer cancel() |
| + if err := c.Close(ctx); err != nil { |
| + t.Fatalf("Close = %v; ops %v", err, ops) |
| + } |
| + if cleanup.Load() != 1 { |
| + t.Fatalf("cleanup=%d", cleanup.Load()) |
| + } |
| + opsMu.Lock() |
| + defer opsMu.Unlock() |
| + views := 0 |
| + for _, op := range ops { |
| + if op == "executionView" { |
| + views++ |
| + } |
| + } |
| + if views != 1 || ops[len(ops)-1] != "executionSettle" { |
| + t.Fatalf("ops %v; want one view (no replay) and a settle last", ops) |
| + } |
| +} |
diff --git a/internal/provision/testdata/plan14-root-reads-flake-hostexec-renewal.tsv b/internal/provision/testdata/plan14-root-reads-flake-hostexec-renewal.tsv| new file mode 100644 |
| index 000000000..991f6c718 |
| --- /dev/null |
| +++ b/internal/provision/testdata/plan14-root-reads-flake-hostexec-renewal.tsv |
| @@ -0,0 +1,3 @@ |
| +# Census overlay flake-hostexec-renewal, written by census-propose (#369). census-ruling-flake-hostexec-renewal, approved on #280 before the merge; the approval card is docs/superpowers/notes/census-proposal-flake-hostexec-renewal.md. |
| +# 0 body, 0 sites, 1 envelope: each changed unit re-frozen at its existing disposition with its claim appended. |
| +@coverage internal/hostexec d8a88303a3559e931c1669cdc792c8bb527798cb9914eb7539d922b5ec03e73a |