carlos / platform Public

Region HA dead-holder backoff: a request that waited out its deadline behind another dial is not an unreachable holder

With every holder dial serialised through forwardDialGate (0de2bcd8), a
request queued behind a slow but successful dial could reach its 2 s
deadline without dialling. Its ctx.Err() was wrapped as a connect failure,
reported ForwardUnreachable, and marked a healthy holder suspect for 10 s.
Now the gate returns errForwardDialQueued (wrapping the deadline) to a
waiter whose time runs out while a dial is in flight; forwardHA answers it
with the unreachable 503 (Retry-After: 10, existing copy) but reports
ForwardDone with no status, which NoteForward leaves alone. Only a dial
that ran reports the holder unreachable. Witnesses:
TestForwardDialGate/"a waiter out of time behind a dial never reports it
unreachable" and TestForwardHAQueuedPastTheDeadlineIsNotUnreachable (both
RED with the change undone). Edge envelope re-pinned; census seal
unchanged (8f6a1865).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev 2d020f3c3b133411965a69652b9a4ac0fd37e116 parent 0de2bcd
3 files changed, +81 −3
  • internal/edge/forwardha.go +16 −2
  • internal/edge/forwardha_test.go +64 −0
  • internal/provision/testdata/plan14-root-reads-region-ha-dead-holder-backoff.tsv +1 −1

CI passed — run details

Intent

Human

<task-notification> <task-id>a00dd29cef729b733</task-id> <tool-use-id>toolu_018enc8R51Weg9hgFpEbABsy</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/953e7524-2e06-4308-b9ce-fd1b38579971/tasks/a00dd29cef729b733.output</output-file> <status>completed</status> <summary>Agent "Build dead-holder backoff follow-up" finished</summary> <note>A task-notification fires each time this agent stops with no live background children of its own. The user can send it another message and resume it, so the same task-id may notify more than once.</note> <result>The last P2-1 fix is in commit `0de2bcd8`, on top of your merge `68c172fc`. The branch was already there, so the fast-forward did nothing. Not pushed. **Diff stat:** 3 files, 120 insertions, 29 deletions. - `internal/edge/forwardha.go`: 38 lines changed - `internal/edge/forwardha_test.go`: 109 lines changed - `internal/provision/testdata/plan14-root-reads-region-ha-dead-holder-backoff.tsv`: 2 lines changed (the edge envelope re-pinned) **Change.** Every TCP dial to a holder address now goes through `forwardDialGate`, so at most one is ever in flight. After a dial connects, the next waiter takes the gate and dials while the rest keep waiting; a burst to a healthy holder dials one at a time. Each caller's own 2 s deadline bounds its whole wait, queueing and dial together: the dial in flight ignores its caller hanging up but keeps the caller's deadline. Connections are not shared across TLS server names. **One fix found during GREEN.** A black-holed dial fails at its deadline, which is also when its standing failure window for later arrivals ends. The released waiters saw the window already over and dialled again: the guard's black-holed case got 2 dials. Now every waiter on a dial that failed returns that dial's error, whenever the failure lands. The window still covers arrivals that come later. **RED** - On the old gate, the new `TestForwardDialGate` subtests failed: - "after a success the next waiter takes the gate": timed out waiting for the second dial, because released waiters dialled concurrently. - "a healthy burst dials one at a time": "10 dials, 9 at once". - In the version before the waiter fix, the black-holed `TestDeadHolderGuardRealWiring` failed: "2 dials and 0 lock reads, want 1 and 0". **GREEN** - `TestForwardDialGate` passes all six subtests with `-race`. The new one holds the second dial after the first connects, checks at most 1 dial at once, then fails it and checks the remaining waiters share the error with no further dial. - The targeted edge set (`TestFrontForward|TestForwardHA|TestForwardDialGate|TestDeadHolderGuardRealWiring|Backhaul`) passes with `-race` in 74 s. - The targeted activator set passes with `-race`. - `TestDeadHolderGuardRealWiring` and `TestForwardDialGate` together pass with `-count=8`. - `TestAgentActivatorForwards` and the provision census tests pass. - gofmt is clean. The darwin, windows and linux arm64 builds pass, as does `go vet` of the edge package on darwin and windows. **Census.** The card showed only the `internal/edge` envelope moving, with no unit changes. I re-ran `make census-propose NAME=region-ha-dead-holder-backoff` with the existing claims file, which re-pinned the edge envelope digest in the overlay. The seal is unchanged at `8f6a1865b0abcea9d4fb68232cc2a25263a106ec87f73bd4b3f2fb388971ebe5`. **Concerns** - If a healthy holder's dials are slow and a big burst queues, a waiter can run out its 2 s while still queued. Its forward then reports unreachable and the holder goes suspect. That is the cost of the serial ruling. With millisecond same-region dials it would take a very large burst. - A waiter that takes the gate late dials with whatever is left of its 2 s. If that short dial times out, the failure is shared and stands like any other.</result> <usage><subagent_tokens>343330</subagent_tokens><tool_uses>9</tool_uses><duration_ms>749383</duration_ms></usage> </task-notification>

Attributed to this commit: 38.4 g CO₂e (4,540,061 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on region-ha-dead-holder-backoff, never backward from it. A turn that produced more than one commit books all of its tokens to the last one, and a concurrent session on this branch can add to the same figure. Some of it was priced using the shared default rate, because no model-specific factor row exists yet for at least one model involved. The Carbon view has the repo total, which is never derived from this attribution.

diff --git a/internal/edge/forwardha.go b/internal/edge/forwardha.go
index c2bfd4bd1..103eba4d6 100644
--- a/internal/edge/forwardha.go
+++ b/internal/edge/forwardha.go
@@ -68,7 +68,9 @@ const (
// (answerHolderUnreachable).
ForwardUnreachable
// ForwardDone: the request went to the named box and its answer, whatever
- // it was, was relayed, or this box refused the hop itself (Status 0).
+ // it was, was relayed, or this box refused the hop itself (Status 0), or
+ // the request waited out its deadline behind another dial (Status 0,
+ // errForwardDialQueued: it says nothing about the holder).
ForwardDone
)
@@ -127,6 +129,13 @@ type forwardConnectError struct{ err error }
func (e *forwardConnectError) Error() string { return "connect: " + e.err.Error() }
func (e *forwardConnectError) Unwrap() error { return e.err }
+// errForwardDialQueued is a request whose deadline passed while it waited
+// behind another request's dial to the holder. It never dialled, so it says
+// nothing about whether the holder is reachable: the visitor gets the
+// unreachable answer, but the forward is not reported unreachable (the dial
+// it waited on reports its own outcome).
+var errForwardDialQueued = errors.New("waited out the deadline behind another dial to the holder")
+
// frontForwardHA is the front-door decision, called in ServeHTTP right after
// route lookup. It reports whether it answered. False, serve here, unless the
// request has a local route (the caller's ok), is not a verified hop, a door
@@ -187,6 +196,11 @@ func (e *Edge) forwardHA(w http.ResponseWriter, r *http.Request, host string, d
res.Outcome = ForwardDone
onError := func(w http.ResponseWriter, r *http.Request, err error) {
var connect *forwardConnectError
+ if errors.Is(err, errForwardDialQueued) && r.Context().Err() == nil {
+ e.logThrottled("forward-queued "+ref, fmt.Sprintf("forward %s → %s (%s): %v; answering 503 + Retry-After: 10", host, ref, dial, err))
+ answerHolderUnreachable(w, r)
+ return
+ }
if errors.As(err, &connect) && r.Context().Err() == nil {
e.logThrottled("forward-unreachable "+ref, fmt.Sprintf("forward %s → %s (%s): %v; answering 503 + Retry-After: 10", host, ref, dial, err))
res.Outcome = ForwardUnreachable
@@ -311,7 +325,7 @@ func (g *forwardDialGate) dial(ctx context.Context, connect func(context.Context
select {
case <-c.done:
case <-ctx.Done():
- return nil, ctx.Err()
+ return nil, fmt.Errorf("%w: %w", errForwardDialQueued, ctx.Err())
}
if c.err != nil {
return nil, c.err // the dial waited on failed: so do its waiters
diff --git a/internal/edge/forwardha_test.go b/internal/edge/forwardha_test.go
index ef18d4d4b..b12ae1356 100644
--- a/internal/edge/forwardha_test.go
+++ b/internal/edge/forwardha_test.go
@@ -724,6 +724,44 @@ func TestForwardDialGate(t *testing.T) {
t.Fatalf("after the failure's time: %d dials, want 2", n)
}
})
+ t.Run("a waiter out of time behind a dial never reports it unreachable", func(t *testing.T) {
+ g := &forwardDialGate{}
+ var dials atomic.Int64
+ release := make(chan struct{})
+ connect := func(context.Context) (net.Conn, error) {
+ dials.Add(1)
+ <-release
+ a, b := net.Pipe()
+ b.Close()
+ return a, nil
+ }
+ first := make(chan error, 1)
+ go func() {
+ conn, err := g.dial(ctx, connect)
+ if conn != nil {
+ conn.Close()
+ }
+ first <- err
+ }()
+ laWaitFor(t, "the first dial", func() bool { return dials.Load() == 1 })
+ short, cancel := context.WithTimeout(ctx, 50*time.Millisecond)
+ defer cancel()
+ _, err := g.dial(short, connect)
+ if !errors.Is(err, errForwardDialQueued) || !errors.Is(err, context.DeadlineExceeded) {
+ t.Fatalf("a waiter out of time got %v, want errForwardDialQueued wrapping the deadline", err)
+ }
+ var connectErr *forwardConnectError
+ if errors.As(err, &connectErr) {
+ t.Fatalf("the queued waiter's error %v is a connect failure", err)
+ }
+ close(release)
+ if err := <-first; err != nil {
+ t.Fatalf("the first dial: %v", err)
+ }
+ if n := dials.Load(); n != 1 {
+ t.Fatalf("%d dials, want 1: the waiter must not dial", n)
+ }
+ })
// countingConnect is a connect that records the most dials in flight at
// once; each dial n waits on hold(n), then answers with fail(n).
countingConnect := func(hold func(n int64), fail func(n int64) error) (func(context.Context) (net.Conn, error), *atomic.Int64, *atomic.Int64) {
@@ -1118,6 +1156,32 @@ func TestForwardHADialFailureIs503RetryTen(t *testing.T) {
})
}
+// TestForwardHAQueuedPastTheDeadlineIsNotUnreachable: a request that waited
+// out its deadline behind another request's dial gets the unreachable answer,
+// but the forward is not reported unreachable, so a healthy holder whose dials
+// are slow under a burst is never marked suspect by requests that never
+// dialled it.
+func TestForwardHAQueuedPastTheDeadlineIsNotUnreachable(t *testing.T) {
+ x := newFwScene(t, fwOpts{})
+ old := forwardDial
+ forwardDial = func(context.Context, string, string) (net.Conn, error) {
+ return nil, fmt.Errorf("%w: %w", errForwardDialQueued, context.DeadlineExceeded)
+ }
+ t.Cleanup(func() { forwardDial = old })
+ resp, body := x.fetch(t, fwHost, "/")
+ if resp.StatusCode != http.StatusServiceUnavailable || resp.Header.Get("Retry-After") != "10" ||
+ body != "instance is waking elsewhere; retry shortly\n" {
+ t.Fatalf("GET = %d Retry-After %q %q, want the unreachable 503", resp.StatusCode, resp.Header.Get("Retry-After"), body)
+ }
+ notes := x.aAct.noted()
+ if len(notes) == 0 || notes[len(notes)-1] != (fwNote{fwHost, ForwardResult{Outcome: ForwardDone, Ref: "betty"}}) {
+ t.Fatalf("notes = %+v, want ForwardDone with no status last (not ForwardUnreachable)", notes)
+ }
+ if n := x.bApp.n.Load(); n != 0 {
+ t.Fatalf("betty's app saw %d requests", n)
+ }
+}
+
func TestForwardHAReadsHolderHeader(t *testing.T) {
x := newFwScene(t, fwOpts{})
n := 0
diff --git a/internal/provision/testdata/plan14-root-reads-region-ha-dead-holder-backoff.tsv b/internal/provision/testdata/plan14-root-reads-region-ha-dead-holder-backoff.tsv
index 2bf91c9a0..d57d4286a 100644
--- a/internal/provision/testdata/plan14-root-reads-region-ha-dead-holder-backoff.tsv
+++ b/internal/provision/testdata/plan14-root-reads-region-ha-dead-holder-backoff.tsv
@@ -5,4 +5,4 @@
internal/edge/forwardha.go Edge.frontForwardHA legacy accepted-legacy accepted-legacy;rev3=census-ruling-region-ha-p1b2;basis=new (region HA P1b-2): the agent's edge decides at the front door whether to forward a visitor request: reads the route's HA flag and host from the box's own registry row and asks the activator; forwards only to a box in view over the existing signed hop; root never calls it;rev3=census-ruling-region-ha-dead-holder-backoff;basis=ForwardTarget returns a ForwardDecision (Ref, Refuse, Gen); a Refuse is answered at the front door with the existing unreachable answer (503, Retry-After: 10, same body, via answerHolderUnreachable), with no forward, dial, note or per-request step. A forward passes the decision to forwardHA and NoteForward carries Ref and Gen back. The round-1 connection callback (NoteConnected) is gone: the dial bound now lives in forwardTransport's forwardDialGate, which coalesces TCP dials per holder address in memory. The same 5 read sites; no new read; root never calls it. registry:HA@225,registry:Host@563,whole:Route@228,whole:Route@405,whole:Route@566 c5b342e1a71cff53bdc6666821708f962c5b2fc73bd6cba2e983cff54c839626
internal/activator/haforward.go Service.ForwardTarget legacy accepted-legacy accepted-legacy;rev3=census-ruling-region-ha-p1b2;basis=new (region HA P1b-2): the agent's activator answers the edge with a holder box ref for an HA route not awake here, from its in-memory holder cache or one bounded (2 s) lock.json read through readHolderView; reads the route's HA flag and host from its own registry row; root never calls it;rev3=census-ruling-region-ha-dead-holder-backoff;basis=Returns edge.ForwardDecision (Ref, Refuse, Gen) from holderCache.resolve, in memory only: a suspect holder refuses; a positive entry forwards under its generation; a failed read that revalidates an expired suspect keeps it suspect and refuses. The round-1 cache connection gate is removed. The same single bounded (2 s) lock.json read through readHolderView on a miss; no new read and no new S3 request; root never calls it. registry:HA@100,registry:Host@1000,registry:Host@262,registry:Host@383,whole:Route@176,whole:Route@741 da8dcb16995990c9fb3c7107cd0d1ef8d5424bddea08a70ad8133801b186cc53
@coverage internal/activator d57a02d4526ac697a1885db1ffd483e922cb5529a0e90ba4c5a325c0f684f1a7
-@coverage internal/edge 2e63066e08c06ee36ad0ec6c7391b26d73fac07ce0fb341a431e06ae919a55c9
+@coverage internal/edge 047409d8e9c6445bdb0a16a189ce4c88db09a8949d23892662547c42521296c5