ha departures: page once for a bound member never observed
A pending termination whose identity the walk bound, but whose edges record was gone before this box observed it, failed enqueue with a scope error every pass and paged code=evidence hourly forever (dev IE, member g-03152630, #1192). Only an observation can change that state, so page once with code=evidence_no_observation, persist it in the hint's last_error so restarts stay quiet, and keep the hint pending: the member is never declared gone on this path.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
internal/host/hadepartures.go+14 −2internal/host/hadepartures_no_observation_test.go+112 −0internal/registry/ha_journal.go+47 −0
Intent
<paseo-system version="1" kind="agent-message" source-agent-id="8a3d302a-eac7-407c-b61c-f5ccc66b5544" message-id="69ecd4c0-49ce-488e-85e7-1c7c46f1cf9e"> From 8a3d302: clear diagnosis, thank you. Agreed on the product fix (page once with evidence_no_observation, persist it, never mark gone on this path). For the dev cleanup, prefer a supported operator path that can be reused: if no verb exists, add a small one in the same branch (e.g. carlos ops ha-departures forget <g-ref>), refused unless a termination proof for that iid exists and no lock or edges record names the member, dry-run by default, --yes to write; it removes the pending termination and the stale identity row. Astra review, census, merge; then send me the exact dev command before you run it. </paseo-system>
diff --git a/internal/host/hadepartures.go b/internal/host/hadepartures.go| index 4168c85a4..c1d97b03f 100644 |
| --- a/internal/host/hadepartures.go |
| +++ b/internal/host/hadepartures.go |
| @@ -423,7 +423,15 @@ func (c *Controller) step(ctx context.Context) error { |
| for _, h := range hints { |
| o, known, e := c.cfg.Identities.Resolve(ctx, "", h.IID) |
| code := "identity_unbound" |
| - if e == nil && known { |
| + once := false |
| + if e == nil && known && (!o.Known || o.PlacementNull) { |
| + // The identity is bound but this box never observed the member's |
| + // edges record (it was gone before the observation was saved). |
| + // Only an observation can change that, so page once, not hourly. |
| + // The member is not declared gone here; see ops ha-departures forget. |
| + code, once = "evidence_no_observation", true |
| + e = errDepartureScope |
| + } else if e == nil && known { |
| e = c.enqueue(ctx, o, "") |
| code = "evidence" |
| } |
| @@ -442,7 +450,11 @@ func (c *Controller) step(ctx context.Context) error { |
| } |
| continue |
| } |
| - page, e := c.cfg.Registry.RetryPendingTermination(ctx, h, c.now(), code) |
| + retry := c.cfg.Registry.RetryPendingTermination |
| + if once { |
| + retry = c.cfg.Registry.RetryPendingTerminationOnce |
| + } |
| + page, e := retry(ctx, h, c.now(), code) |
| if e != nil { |
| return e |
| } |
diff --git a/internal/host/hadepartures_no_observation_test.go b/internal/host/hadepartures_no_observation_test.go| new file mode 100644 |
| index 000000000..56d708da8 |
| --- /dev/null |
| +++ b/internal/host/hadepartures_no_observation_test.go |
| @@ -0,0 +1,112 @@ |
| +package host |
| + |
| +import ( |
| + "context" |
| + "strings" |
| + "testing" |
| + "time" |
| + |
| + "github.com/carlosframework/platform/internal/boxid" |
| + "github.com/carlosframework/platform/internal/boxid/boxidtest" |
| + "github.com/carlosframework/platform/internal/registry" |
| +) |
| + |
| +// A member bound by the identity walk whose edges record was gone before |
| +// this box ever observed it can never enroll: only an observation supplies |
| +// the scope enqueue needs. Its pending termination must page exactly once |
| +// with a reason that says so, survive a restart without re-paging, and stay |
| +// pending (the member is never declared gone on this path). |
| +func TestDeparturePendingWithoutObservationPagesOnce(t *testing.T) { |
| + x := newScanRig(t, 0) |
| + account, region := x.d.Box.Account, x.d.Box.Scope.CloudRegion |
| + iid := "i-2123456789abcdef0" |
| + ref := groupReferenceOf(account, iid) |
| + signer := boxidtest.NewSigner(t) |
| + _, raw := signer.Record(t, ref, account, region, iid) |
| + if _, err := x.store.Put(t.Context(), boxid.Key(ref), raw, ""); err != nil { |
| + t.Fatal(err) |
| + } |
| + repo := &departureIdentities{Registry: x.r, Store: x.store, Verifier: boxid.Verifier{Account: account, Certs: signer.Certs()}, Fixed: map[string]string{}, Region: region, Now: func() time.Time { return x.now }} |
| + x.c.cfg.Identities = repo |
| + for done := false; !done; { |
| + var err error |
| + if done, _, err = repo.Walk(t.Context()); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + if o, known, err := repo.Resolve(t.Context(), ref, iid); err != nil || !known || o.Known { |
| + t.Fatalf("want a bound, unobserved identity: %+v %v %v", o, known, err) |
| + } |
| + h := registry.HAPendingTermination{Account: account, Region: region, IID: iid, ReceivedAt: x.now} |
| + if err := x.r.ParkTermination(t.Context(), h, ""); err != nil { |
| + t.Fatal(err) |
| + } |
| + var codes []string |
| + page := func(_ context.Context, p registry.HAPendingTermination, code string) error { |
| + if p.IID != iid { |
| + t.Errorf("page for %s", p.IID) |
| + } |
| + codes = append(codes, code) |
| + return nil |
| + } |
| + x.c.cfg.PageIdentity = page |
| + run := func(c *Controller, d time.Duration) { |
| + t.Helper() |
| + end := x.now.Add(d) |
| + for ; x.now.Before(end); x.now = x.now.Add(30 * time.Second) { |
| + if err := c.step(t.Context()); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + } |
| + run(x.c, 3*time.Hour) |
| + // Restart: a fresh controller on the same journal. |
| + restarted := &Controller{cfg: x.c.cfg} |
| + run(restarted, 3*time.Hour) |
| + if len(codes) != 1 || !strings.HasPrefix(codes[0], "evidence_no_observation count=1") { |
| + t.Fatalf("pages=%q, want exactly one evidence_no_observation page", codes) |
| + } |
| + hints, err := x.r.PendingTerminations(t.Context(), x.now.Add(time.Hour), 32) |
| + if err != nil || len(hints) != 1 || hints[0].IID != iid || hints[0].LastError != "evidence_no_observation" { |
| + t.Fatalf("hint must stay pending with its reason: %+v %v", hints, err) |
| + } |
| + rows, err := x.r.PendingDepartures(t.Context(), x.now.Add(24*time.Hour), 32) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + for _, d := range rows { |
| + if d.Box.InstanceID == iid { |
| + t.Fatal("an unobserved member was enrolled as departed") |
| + } |
| + } |
| +} |
| + |
| +func TestPendingTerminationOnceRetriesWhenGloballyThrottled(t *testing.T) { |
| + r, err := registry.Open(t.TempDir() + "/registry.db") |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + defer r.Close() |
| + ctx, at := t.Context(), time.Now() |
| + a := registry.HAPendingTermination{Account: "111122223333", Region: "eu-west-1", IID: "i-1123456789abcdef0", ReceivedAt: at} |
| + b := a |
| + b.IID = "i-2123456789abcdef0" |
| + for _, h := range []registry.HAPendingTermination{a, b} { |
| + if err = r.ParkTermination(ctx, h, ""); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + if page, e := r.RetryPendingTermination(ctx, a, at, "evidence"); e != nil || !page { |
| + t.Fatal("first page", page, e) |
| + } |
| + // The global hourly bound withholds b's page; it must not be lost. |
| + if page, e := r.RetryPendingTerminationOnce(ctx, b, at.Add(time.Minute), "evidence_no_observation"); e != nil || page { |
| + t.Fatal("throttled page", page, e) |
| + } |
| + if page, e := r.RetryPendingTerminationOnce(ctx, b, at.Add(time.Hour+time.Minute), "evidence_no_observation"); e != nil || !page { |
| + t.Fatal("withheld page never sent", page, e) |
| + } |
| + if page, e := r.RetryPendingTerminationOnce(ctx, b, at.Add(3*time.Hour), "evidence_no_observation"); e != nil || page { |
| + t.Fatal("paged twice", page, e) |
| + } |
| +} |
diff --git a/internal/registry/ha_journal.go b/internal/registry/ha_journal.go| index df8135224..f800a3cd8 100644 |
| --- a/internal/registry/ha_journal.go |
| +++ b/internal/registry/ha_journal.go |
| @@ -52,6 +52,7 @@ type haJournalRequest struct { |
| At, Next time.Time |
| Limit int |
| Page bool |
| + Once bool |
| Departure HADeparture |
| Identity HABoxIdentity |
| Walk HAIdentityWalk |
| @@ -115,6 +116,16 @@ func (r *Registry) RetryPendingTermination(ctx context.Context, h HAPendingTermi |
| return out.Found, err |
| } |
| +// RetryPendingTerminationOnce is RetryPendingTermination for a state that |
| +// paging again cannot change (a bound identity this box never observed). It |
| +// pages at most once per hint and code: the code is persisted in last_error |
| +// only when the page is claimed, so restarts do not re-page, and a page |
| +// withheld by the global hourly bound is retried later. |
| +func (r *Registry) RetryPendingTerminationOnce(ctx context.Context, h HAPendingTermination, at time.Time, code string) (bool, error) { |
| + out, err := r.haJournal(ctx, haJournalRequest{Op: "retry_hint", Hint: h, At: at, Code: code, Once: true}) |
| + return out.Found, err |
| +} |
| + |
| func (r *Registry) ClaimHAIdentityPage(ctx context.Context, at time.Time) (bool, error) { |
| out, err := r.haJournal(ctx, haJournalRequest{Op: "identity_page", At: at}) |
| return out.Found, err |
| @@ -281,6 +292,42 @@ func (r *Registry) haJournal(ctx context.Context, q haJournalRequest) (out haJou |
| return out, e |
| } |
| defer tx.Rollback() |
| + if q.Once { |
| + if q.Code == "" { |
| + return out, ErrHAJournal |
| + } |
| + var last string |
| + if e = tx.QueryRowContext(ctx, `SELECT last_error FROM ha_pending_terminations WHERE account=? AND region=? AND iid=?`, h.Account, h.Region, h.IID).Scan(&last); e != nil { |
| + if errors.Is(e, sql.ErrNoRows) { |
| + return out, nil |
| + } |
| + return out, e |
| + } |
| + code := last |
| + if last != q.Code { |
| + res, e := tx.ExecContext(ctx, `INSERT INTO ha_identity_pages(id,last_page) VALUES(1,?) ON CONFLICT(id) DO UPDATE SET last_page=excluded.last_page WHERE last_page<=?`, journalTime(q.At), journalTime(q.At.Add(-time.Hour))) |
| + if e != nil { |
| + return out, e |
| + } |
| + n, e := res.RowsAffected() |
| + if e != nil { |
| + return out, e |
| + } |
| + if out.Found = n == 1; out.Found { |
| + code = q.Code |
| + } |
| + } |
| + if out.Found { |
| + _, e = tx.ExecContext(ctx, `UPDATE ha_pending_terminations SET next_attempt=?,last_page=?,last_error=? WHERE account=? AND region=? AND iid=?`, journalTime(q.At.Add(30*time.Second)), journalTime(q.At), code, h.Account, h.Region, h.IID) |
| + } else { |
| + _, e = tx.ExecContext(ctx, `UPDATE ha_pending_terminations SET next_attempt=?,last_error=? WHERE account=? AND region=? AND iid=?`, journalTime(q.At.Add(30*time.Second)), code, h.Account, h.Region, h.IID) |
| + } |
| + if e != nil { |
| + return out, e |
| + } |
| + err = tx.Commit() |
| + break |
| + } |
| res, e := tx.ExecContext(ctx, `UPDATE ha_pending_terminations SET last_page=? WHERE account=? AND region=? AND iid=? AND (last_page=0 OR last_page<=?)`, journalTime(q.At), h.Account, h.Region, h.IID, journalTime(q.At.Add(-time.Hour))) |
| if e != nil { |
| return out, e |