region HA: the take's receiver wake timeout reaches the drain
Branch review r1, Astra B1.1. The receiver bounds its wake wait at 30 s and answered a timeout as an ordinary "none", which the sender returned as ErrTakeNoHolder; the driver's lock re-read ran only on its own 40 s bound. A slow but healthy successor therefore failed the drain without the ruled re-read, while its detached wake went on and acquired. The receiver now marks a wake-wait timeout (TakeAnswer.WakeTimeout); the edge carries it as an additive outcome "wake_timeout" with holder none; the sender returns ErrTakeNoHolder wrapping ErrTakeWakeTimeout; the driver applies its single lock re-read to it as to its own deadline. A failed wake and refusals stay failures. Tests: the real receiver's timeout answer; the wire between real edges (timeout, plain none, refusal with the flag); the answer's JSON shape; the driver's re-read on a receiver timeout returned before its own bound (confirmed: lock; a draining, absent or out-of-view owner still fails). The sim's receiver answers at its 30 s wake wait. Spec §25.7.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
8 files changed,
+71
−13
docs/superpowers/specs/2026-10-26-region-ha-without-claims-design.md+1 −1internal/activator/hatake.go+4 −1internal/activator/hatake_test.go+1 −1internal/edge/hatake.go+25 −2internal/edge/hatake_test.go+16 −1internal/host/hadrain.go+5 −3internal/host/hadrain_test.go+12 −1internal/sim/regionha/handover_test.go+7 −3
diff --git a/docs/superpowers/specs/2026-10-26-region-ha-without-claims-design.md b/docs/superpowers/specs/2026-10-26-region-ha-without-claims-design.md| index 2d3149f93..788b6df7f 100644 |
| --- a/docs/superpowers/specs/2026-10-26-region-ha-without-claims-design.md |
| +++ b/docs/superpowers/specs/2026-10-26-region-ha-without-claims-design.md |
| @@ -1175,7 +1175,7 @@ The take is a new hop endpoint on every HA box, `/.carlos/ha-take`, signed with |
| - refuses unless it serves H's pool, is admitted and not draining, and holds a valid record for the host with that lifetime; |
| - runs the HA acquire for H, and never forwards. A lock in any state other than that marker gets the normal acquire decision; |
| - wakes H, and answers once H is awake or the wake has failed, within the wake wait bound; |
| -- answers with the owner it read or wrote in `lock.json`: itself, another box (held), or none. |
| +- answers with the owner it read or wrote in `lock.json`: itself, another box (held), or none. A "none" whose wake wait reached its bound also says `outcome: wake_timeout`, an additive field. The wake runs on, so A treats it as it treats its own 40 s bound: one coalesced lock re-read, and a non-draining owner in view is the confirmed holder (build ruling, 2026-11-09). Any other "none", a failed wake included, fails the move. |
| Both control paths, `/.carlos/ha-take` and `/.carlos/ha-drain`, are reserved on every ingress: a client request for either is refused at the front door and never forwarded. Each carries its own signature over the method, path, body, drain transaction and timestamp, as probe-burst notices do (`internal/edge/burst_notice.go:499-529`). The ordinary hop signature is not enough, because it binds only host and time (`internal/edge/mesh.go:188-190`). Bodies are bounded at 4 KiB (R3.8). A take is a forwarded wake without a visitor, and it authorizes nothing the acquire table does not already allow. A box advertises it with an additive edges field, `ha_take: 1`. |
diff --git a/internal/activator/hatake.go b/internal/activator/hatake.go| index 882e0b3f6..9cd6fe81c 100644 |
| --- a/internal/activator/hatake.go |
| +++ b/internal/activator/hatake.go |
| @@ -102,7 +102,10 @@ func (a *Service) TakeHost(ctx context.Context, rt registry.Route, lifetime stri |
| return edge.TakeAnswer{Holder: o.Ref, Gen: held.gen} |
| } |
| } |
| - return edge.TakeAnswer{Reason: fmt.Sprintf("the wake failed (marker generation %d): %v", markerGen, err)} |
| + // A wait that reached its bound is said so on the wire: the wake runs |
| + // on, detached, and the drain re-reads the lock once (Astra B1.1). |
| + timedOut := errors.Is(err, errWakeTimeout) || errors.Is(err, context.DeadlineExceeded) |
| + return edge.TakeAnswer{Reason: fmt.Sprintf("the wake failed (marker generation %d): %v", markerGen, err), WakeTimeout: timedOut} |
| } |
| // takeWake is the take's wake of rt: the ordinary request wake (begin, |
diff --git a/internal/activator/hatake_test.go b/internal/activator/hatake_test.go| index 25ea29ad0..1fd92796f 100644 |
| --- a/internal/activator/hatake_test.go |
| +++ b/internal/activator/hatake_test.go |
| @@ -368,7 +368,7 @@ func TestTakeWithinTheWakeBound(t *testing.T) { |
| if took := time.Since(began); took > 2*time.Second { |
| t.Fatalf("the take answered after %s", took) |
| } |
| - if ans.Holder != "" || ans.Refused != "" || !strings.Contains(ans.Reason, errWakeTimeout.Error()) { |
| + if ans.Holder != "" || ans.Refused != "" || !strings.Contains(ans.Reason, errWakeTimeout.Error()) || !ans.WakeTimeout { |
| t.Fatalf("take: %+v, want no holder: the wake timed out", ans) |
| } |
| } |
diff --git a/internal/edge/hatake.go b/internal/edge/hatake.go| index 80395db09..4b36a0e8b 100644 |
| --- a/internal/edge/hatake.go |
| +++ b/internal/edge/hatake.go |
| @@ -49,6 +49,11 @@ type TakeAnswer struct { |
| Refused string |
| // Reason says why there is no holder. |
| Reason string |
| + // WakeTimeout: no holder because the receiver's wake wait reached its |
| + // bound (branch review r1, Astra B1.1). The wake runs on, detached, and |
| + // may yet acquire, so the drain re-reads the lock once rather than |
| + // failing the move. |
| + WakeTimeout bool |
| } |
| // The receiver's refusals, made before any lock request. |
| @@ -99,8 +104,14 @@ type haTakeAnswer struct { |
| Gen int64 `json:"gen"` |
| Refused string `json:"refused,omitempty"` |
| Reason string `json:"reason,omitempty"` |
| + // Outcome is additive and machine-read: takeOutcomeWakeTimeout with |
| + // holder none. Absent from older receivers. |
| + Outcome string `json:"outcome,omitempty"` |
| } |
| +// takeOutcomeWakeTimeout is a take whose wake wait reached its bound. |
| +const takeOutcomeWakeTimeout = "wake_timeout" |
| + |
| // haTakeHost is a hostname a take may name: lower-case letters, digits, |
| // dots and hyphens, bounded. |
| func haTakeHost(s string) bool { |
| @@ -142,9 +153,13 @@ func (e *Edge) serveHATake(w http.ResponseWriter, r *http.Request, txn string, b |
| } |
| log.Printf("edge: ha-take %s from %s (txn %s, marker generation %d): holder %s, generation %d%s%s", |
| ask.Host, ask.From, ask.Txn, ask.MarkerGen, holder, ans.Gen, takeLogPart("refused", ans.Refused), takeLogPart("reason", reason)) |
| + var outcome string |
| + if ans.WakeTimeout && ans.Holder == "" && ans.Refused == "" { |
| + outcome = takeOutcomeWakeTimeout |
| + } |
| w.Header().Set("Content-Type", "application/json") |
| w.Header().Set("Cache-Control", "no-store") |
| - json.NewEncoder(w).Encode(haTakeAnswer{Holder: holder, Gen: ans.Gen, Refused: ans.Refused, Reason: reason}) |
| + json.NewEncoder(w).Encode(haTakeAnswer{Holder: holder, Gen: ans.Gen, Refused: ans.Refused, Reason: reason, Outcome: outcome}) |
| } |
| func takeLogPart(name, v string) string { |
| @@ -209,6 +224,11 @@ func (e *TakeRefusedError) Error() string { |
| // or the lock is in a state no acquire may take. |
| var ErrTakeNoHolder = errors.New("ha-take: no holder") |
| +// ErrTakeWakeTimeout is a take that names no holder because the receiver's |
| +// wake wait reached its bound. It also wraps ErrTakeNoHolder. The wake runs |
| +// on at the receiver; the caller may re-read the lock (§25.4 step 3.4). |
| +var ErrTakeWakeTimeout = errors.New("ha-take: the successor's wake wait timed out") |
| + |
| // ErrTakeUnsupported is a peer whose edges file does not say ha_take: 1. |
| var ErrTakeUnsupported = errors.New("ha-take: the peer does not answer take requests") |
| @@ -234,7 +254,8 @@ func (e *Edge) PeerTakes(ref string) bool { |
| // answers the confirmed holder, peer or a third box that won the marker |
| // first, and the lock's generation. An error is a take with no confirmed |
| // holder: one that could not be sent or got no answer, a |
| -// *TakeRefusedError, ErrTakeNoHolder (wrapped with the peer's reason), |
| +// *TakeRefusedError, ErrTakeNoHolder (wrapped with the peer's reason, and |
| +// with ErrTakeWakeTimeout when the receiver's wake wait timed out), |
| // ErrTakeUnsupported, or an answer naming this box. It is one request, |
| // never retried here. |
| func (e *Edge) Take(ctx context.Context, peer, host, lifetime string, markerGen int64, txn string) (holderRef string, lockGen int64, err error) { |
| @@ -293,6 +314,8 @@ func (e *Edge) Take(ctx context.Context, peer, host, lifetime string, markerGen |
| switch { |
| case ans.Refused != "": |
| return "", 0, &TakeRefusedError{Peer: peer, Reason: ans.Refused} |
| + case (ans.Holder == "" || ans.Holder == takeNone) && ans.Outcome == takeOutcomeWakeTimeout: |
| + return "", 0, fmt.Errorf("%w (%w): %s: %s", ErrTakeNoHolder, ErrTakeWakeTimeout, peer, ans.Reason) |
| case ans.Holder == "" || ans.Holder == takeNone: |
| return "", 0, fmt.Errorf("%w: %s: %s", ErrTakeNoHolder, peer, ans.Reason) |
| case !haControlField(ans.Holder) || ans.Gen <= 0: |
diff --git a/internal/edge/hatake_test.go b/internal/edge/hatake_test.go| index 219bba9f2..3171b52fd 100644 |
| --- a/internal/edge/hatake_test.go |
| +++ b/internal/edge/hatake_test.go |
| @@ -177,7 +177,17 @@ func TestTakeAnswersWithoutAHolder(t *testing.T) { |
| return errors.As(err, &re) && re.Peer == "betty" && re.Reason == TakeRefusedDraining |
| }}, |
| "none": {TakeAnswer{Reason: "the wake failed"}, func(err error) bool { |
| - return errors.Is(err, ErrTakeNoHolder) && strings.Contains(err.Error(), "the wake failed") |
| + return errors.Is(err, ErrTakeNoHolder) && !errors.Is(err, ErrTakeWakeTimeout) && strings.Contains(err.Error(), "the wake failed") |
| + }}, |
| + // The receiver's wake wait reached its bound: carried on the wire, |
| + // so the drain re-reads the lock (Astra B1.1). |
| + "wake timeout": {TakeAnswer{Reason: "the wake failed: timed out", WakeTimeout: true}, func(err error) bool { |
| + return errors.Is(err, ErrTakeNoHolder) && errors.Is(err, ErrTakeWakeTimeout) && strings.Contains(err.Error(), "timed out") |
| + }}, |
| + // A refusal is never a timeout, whatever else the answer says. |
| + "refused, timed out": {TakeAnswer{Refused: TakeRefusedPool, WakeTimeout: true}, func(err error) bool { |
| + var re *TakeRefusedError |
| + return errors.As(err, &re) && !errors.Is(err, ErrTakeWakeTimeout) |
| }}, |
| "the asker itself": {TakeAnswer{Holder: "annie", Gen: 6}, func(err error) bool { |
| return err != nil && strings.Contains(err.Error(), "this box still holds") |
| @@ -361,4 +371,9 @@ func TestTakeAnswerShape(t *testing.T) { |
| if err != nil || string(b) != `{"holder":"betty","gen":7}` { |
| t.Fatalf("answer %s %v", b, err) |
| } |
| + // The wake timeout is additive: an older sender ignores outcome. |
| + b, err = json.Marshal(haTakeAnswer{Holder: takeNone, Reason: "x", Outcome: takeOutcomeWakeTimeout}) |
| + if err != nil || string(b) != `{"holder":"none","gen":0,"reason":"x","outcome":"wake_timeout"}` { |
| + t.Fatalf("timeout answer %s %v", b, err) |
| + } |
| } |
diff --git a/internal/host/hadrain.go b/internal/host/hadrain.go| index c5c12d22c..fb4f0e006 100644 |
| --- a/internal/host/hadrain.go |
| +++ b/internal/host/hadrain.go |
| @@ -756,8 +756,10 @@ func (d *drainDriver) moveOne(ctx context.Context, txn string, h activator.Drain |
| // take chooses successors with ChooseRoomiest among the serving peers |
| // that answer takes, and asks them in turn while they refuse before any |
| -// acquire. A take that times out is checked with one lock re-read: a |
| -// non-draining owner in view is the confirmed holder. |
| +// acquire. A take that times out, here (the transport's bound) or at the |
| +// receiver (its wake wait, edge.ErrTakeWakeTimeout), is checked with one |
| +// lock re-read: a non-draining owner in view is the confirmed holder. Any |
| +// other failure, a wake that failed included, fails the move. |
| func (d *drainDriver) take(ctx context.Context, txn string, h activator.DrainHost) (string, int64, string, error) { |
| rt := h.Route |
| s := d.edge.DrainSnapshot(rt) |
| @@ -788,7 +790,7 @@ func (d *drainDriver) take(ctx context.Context, txn string, h activator.DrainHos |
| cands = slicesDeleteCandidate(cands, c.BoxID) |
| continue |
| } |
| - if timedOut || errors.Is(err, context.DeadlineExceeded) { |
| + if timedOut || errors.Is(err, context.DeadlineExceeded) || errors.Is(err, edge.ErrTakeWakeTimeout) { |
| if ref, g, ok := d.act.DrainTakeOwner(ctx, rt); ok && ref != s.Self && s.Peers[ref] && !d.edge.PeerDraining(ref) { |
| return ref, g, "lock", nil |
| } |
diff --git a/internal/host/hadrain_test.go b/internal/host/hadrain_test.go| index 54ea74458..8b5ca5ebb 100644 |
| --- a/internal/host/hadrain_test.go |
| +++ b/internal/host/hadrain_test.go |
| @@ -761,9 +761,17 @@ func TestDrainTakeRefusedTriesNext(t *testing.T) { |
| // A take that times out while the lock shows the successor counts as |
| // taken, with the lock's holder and generation. An owner that is draining, |
| -// or out of view, does not. |
| +// or out of view, does not. The timeout is this driver's own bound, or the |
| +// receiver's wake wait answered on the wire (edge.ErrTakeWakeTimeout, |
| +// Astra B1.1), which comes back well before the driver's bound. |
| func TestDrainTakeTimeoutConfirmedByTheLock(t *testing.T) { |
| defer shorten(&drainTakeBound, 50*time.Millisecond)() |
| + for _, receiver := range []bool{false, true} { |
| + t.Run(fmt.Sprintf("receiver timeout %v", receiver), func(t *testing.T) { drainTakeTimeoutCases(t, receiver) }) |
| + } |
| +} |
| + |
| +func drainTakeTimeoutCases(t *testing.T, receiver bool) { |
| for _, tc := range []struct { |
| owner string |
| ok bool |
| @@ -777,6 +785,9 @@ func TestDrainTakeTimeoutConfirmedByTheLock(t *testing.T) { |
| } { |
| act, ed, marks := healthyDrain() |
| ed.take = func(ctx context.Context, peer, host string) (string, int64, error) { |
| + if receiver { |
| + return "", 0, fmt.Errorf("%w (%w): %s: the wake failed", edge.ErrTakeNoHolder, edge.ErrTakeWakeTimeout, peer) |
| + } |
| <-ctx.Done() |
| return "", 0, ctx.Err() |
| } |
diff --git a/internal/sim/regionha/handover_test.go b/internal/sim/regionha/handover_test.go| index d9b043dd7..8a6bd4346 100644 |
| --- a/internal/sim/regionha/handover_test.go |
| +++ b/internal/sim/regionha/handover_test.go |
| @@ -73,7 +73,8 @@ const ( |
| hoInflight = 10 // s, a moving host's in-flight drain |
| hoAskEvery = 5 // s, between acknowledgement asks |
| hoAckBound = 120 // s, a missing acknowledgement fails the drain |
| - hoTakeWait = 40 // s, the take's wait |
| + hoTakeWait = 40 // s, the driver's own bound on a take (the transport) |
| + hoWakeWait = 30 // s, the receiver's wake wait; it answers wake_timeout at the bound |
| hoConnBound = 60 // s, the connection drain |
| hoLockEvery = 5 // s, the redirect's coalesced lock read |
| hoWidth = 4 // moves at a time |
| @@ -1353,8 +1354,11 @@ func (ho *hoWorld) startTake(m *hoMove) { |
| if res == "served" { |
| lat := k.TakeLat[h] |
| ho.ready[succ][h] = ho.sec + lat |
| - if lat > hoTakeWait { |
| - m.AnswerAt, m.Timeout = ho.sec+hoTakeWait, true |
| + if lat > hoWakeWait { |
| + // The receiver answers wake_timeout at its wake wait, before |
| + // the driver's own bound; either is a timeout the driver |
| + // checks with one lock re-read (Astra B1.1). |
| + m.AnswerAt, m.Timeout = ho.sec+min(hoWakeWait, hoTakeWait), true |
| } else { |
| m.AnswerAt = ho.sec + max(lat, 1) |
| } |