edge: first held-stream heartbeat at one tick, not two (#432)
Seen on dev after v0.33.7: the first ': ping' on a held stream came at +50 s instead of +25 s. The tick handler judged due-ness against the timer's fire time and re-armed a full Tick when the remaining delay came out non-positive. Due-ness is now judged against the current clock; a due ping is written at once and the next tick armed from it. Census: internal/edge envelope re-pin, approved (Astra). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Squashed from edge-held-first-ping-432 into main.
6 files changed,
+69
−3
docs/superpowers/notes/census-edge-held-first-ping-claims.md+3 −0docs/superpowers/notes/census-proposal-edge-held-first-ping.md+11 −0internal/edge/heldstream.go+8 −3internal/edge/heldstream_test.go+43 −0internal/provision/testdata/plan14-root-reads-chain.tsv+1 −0internal/provision/testdata/plan14-root-reads-edge-held-first-ping.tsv+3 −0
CI cancelled โ superseded by a newer push — run details
diff --git a/docs/superpowers/notes/census-edge-held-first-ping-claims.md b/docs/superpowers/notes/census-edge-held-first-ping-claims.md| new file mode 100644 |
| index 000000000..9c82f93c1 |
| --- /dev/null |
| +++ b/docs/superpowers/notes/census-edge-held-first-ping-claims.md |
| @@ -0,0 +1,3 @@ |
| +# CLAIMS for the root-read census, branch edge-held-first-ping-432 (first held-stream heartbeat at one tick, #432). |
| +# Format (AGENTS.md "The census"): <file>:<unit><TAB><what changed>. Lines starting with # are ignored. |
| +# Envelopes re-pinned without a unit row: internal/edge (heldstream.go heldTask.run, the tick case; test file). The agent's edge: heartbeat timing only; no read added. Due-ness of the ": ping" is judged against time.Now() and the next tick is armed from the write just made; inputs are the in-memory lastWrite and the config. |
diff --git a/docs/superpowers/notes/census-proposal-edge-held-first-ping.md b/docs/superpowers/notes/census-proposal-edge-held-first-ping.md| new file mode 100644 |
| index 000000000..9ad3e5cee |
| --- /dev/null |
| +++ b/docs/superpowers/notes/census-proposal-edge-held-first-ping.md |
| @@ -0,0 +1,11 @@ |
| +# Census approval: edge-held-first-ping |
| + |
| +Ruling `census-ruling-edge-held-first-ping`. 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/edge`. |
| + |
| +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: `3b6cd29b87d2728254936722ab45fdadcfbb8c1f5b74fdfa19d1921b9dfd1dbe` โ `3b6cd29b87d2728254936722ab45fdadcfbb8c1f5b74fdfa19d1921b9dfd1dbe`. |
| + |
| +Overlay: `internal/provision/testdata/plan14-root-reads-edge-held-first-ping.tsv`, appended to `internal/provision/testdata/plan14-root-reads-chain.tsv`. |
diff --git a/internal/edge/heldstream.go b/internal/edge/heldstream.go| index 68c14487e..bccc48e3f 100644 |
| --- a/internal/edge/heldstream.go |
| +++ b/internal/edge/heldstream.go |
| @@ -510,19 +510,24 @@ func (t *heldTask) run() heldCloseReason { |
| if t.holding() { |
| t.scheduleReopen(true, 0) |
| } |
| - case now := <-tickT.C: |
| + case <-tickT.C: |
| + // Due-ness is judged against the clock now, not the timer's |
| + // fire time: a write that landed just after the timer started |
| + // (the commit) must not hide a heartbeat that is due. |
| + // |
| // No heartbeat inside a passed-through answer: its body goes to |
| // the browser byte for byte. |
| - if t.committed && !t.passThrough && now.Sub(t.lastWrite) >= t.cfg.Tick { |
| + next := time.Until(t.lastWrite.Add(t.cfg.Tick)) |
| + if next <= 0 && t.committed && !t.passThrough { |
| if err := t.write([]byte(": ping\n")); err != nil { |
| return heldCloseWriteFailed |
| } |
| + next = time.Until(t.lastWrite.Add(t.cfg.Tick)) |
| } |
| // The backstop for a lost wake signal (ยง3.7). |
| if t.holding() && t.e.act.HeldAdmissible(t.host) { |
| t.scheduleReopen(true, 0) |
| } |
| - next := time.Until(t.lastWrite.Add(t.cfg.Tick)) |
| if next <= 0 { |
| next = t.cfg.Tick |
| } |
diff --git a/internal/edge/heldstream_test.go b/internal/edge/heldstream_test.go| index 571b757ca..9b575509d 100644 |
| --- a/internal/edge/heldstream_test.go |
| +++ b/internal/edge/heldstream_test.go |
| @@ -229,6 +229,49 @@ func TestHeldAsleepCommitsAndPings(t *testing.T) { |
| } |
| } |
| +// The first heartbeat is due one Tick after the response headers, not two: |
| +// the commit's own write lands just after the tick timer starts, and the |
| +// first tick must not mistake that for a fresh write and skip a whole beat. |
| +func TestHeldFirstPingAtOneTick(t *testing.T) { |
| + cfg := heldTestConfig() |
| + cfg.Tick = 200 * time.Millisecond |
| + h := newHeldHarness(t, cfg, func(int, http.ResponseWriter, *http.Request) { t.Error("proxy called while asleep") }) |
| + h.act.asleep.Store(true) |
| + h.start(t) |
| + resp := h.get(t, "/live?carlos_hold=1", nil) |
| + start := time.Now() |
| + pings := make(chan time.Time, 4) |
| + go func() { |
| + br := bufio.NewReader(resp.Body) |
| + for { |
| + line, err := br.ReadString('\n') |
| + if err != nil { |
| + return |
| + } |
| + if line == ": ping\n" { |
| + pings <- time.Now() |
| + } |
| + } |
| + }() |
| + var first, second time.Time |
| + select { |
| + case first = <-pings: |
| + case <-time.After(4 * cfg.Tick): |
| + t.Fatal("no heartbeat in 4 ticks") |
| + } |
| + if d := first.Sub(start); d >= cfg.Tick*3/2 { |
| + t.Fatalf("first ping at %v, want before %v", d, cfg.Tick*3/2) |
| + } |
| + select { |
| + case second = <-pings: |
| + case <-time.After(4 * cfg.Tick): |
| + t.Fatal("no second heartbeat in 4 ticks") |
| + } |
| + if d := second.Sub(first); d < cfg.Tick/2 || d >= cfg.Tick*3/2 { |
| + t.Fatalf("second ping %v after the first, want about %v", d, cfg.Tick) |
| + } |
| +} |
| + |
| func TestHeldSeedsCursor(t *testing.T) { |
| h := newHeldHarness(t, heldTestConfig(), func(int, http.ResponseWriter, *http.Request) {}) |
| h.act.asleep.Store(true) |
diff --git a/internal/provision/testdata/plan14-root-reads-chain.tsv b/internal/provision/testdata/plan14-root-reads-chain.tsv| index ca0ea7b73..65cf22662 100644 |
| --- a/internal/provision/testdata/plan14-root-reads-chain.tsv |
| +++ b/internal/provision/testdata/plan14-root-reads-chain.tsv |
| @@ -61,3 +61,4 @@ plan14-root-reads-stateless-replicas-1.tsv df8bf8056d80b9d78edc957fe7f2adbc75885 |
| plan14-root-reads-domain-registration-1.tsv 8e7126042fef8cc99899a29e9e06c22763a24b6677110144035ec57fcc2de23e |
| plan14-root-reads-edge-held-streams.tsv c61b055182bf84e822fab92199432bd2d462c268c03ead17c3cfa18f09bd82cd |
| plan14-root-reads-edge-protect-hard-block.tsv 3b6cd29b87d2728254936722ab45fdadcfbb8c1f5b74fdfa19d1921b9dfd1dbe |
| +plan14-root-reads-edge-held-first-ping.tsv 3b6cd29b87d2728254936722ab45fdadcfbb8c1f5b74fdfa19d1921b9dfd1dbe |
diff --git a/internal/provision/testdata/plan14-root-reads-edge-held-first-ping.tsv b/internal/provision/testdata/plan14-root-reads-edge-held-first-ping.tsv| new file mode 100644 |
| index 000000000..6394388e9 |
| --- /dev/null |
| +++ b/internal/provision/testdata/plan14-root-reads-edge-held-first-ping.tsv |
| @@ -0,0 +1,3 @@ |
| +# Census overlay edge-held-first-ping, written by census-propose (#369). census-ruling-edge-held-first-ping, approved on #280 before the merge; the approval card is docs/superpowers/notes/census-proposal-edge-held-first-ping.md. |
| +# 0 body, 0 sites, 1 envelope: each changed unit re-frozen at its existing disposition with its claim appended. |
| +@coverage internal/edge 40b244d92ef00e3130b3202480e169ca84a83ad84fdd3261f65ef58b324d18b9 |