carlos / platform Public

cert warm: keep each hold's deadline across passes (#443, Astra R1 P1)

A pass run for another reason skipped a held name on its nextAttempt floor
and could return the hourly delay, leaving the name without a certificate
for an hour. settleUntil now keeps every hold's absolute deadline, and each
pass comes back for the soonest one still running. Ended holds do not
shorten the delay: the order cap and the DNS-miss schedule already bring
those names back. Regression tests for an intervening pass and two
deadlines; coverage for a held re-arm and a failed boot refresh.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev 115f29cee23625d619d0919d13a4f4307c9de391 parent 17349ef
4 files changed, +179 −8
  • docs/superpowers/reviews/CODEX-REVIEW-cert-warm-443-R1.md +20 −0
  • internal/edge/certsettle_test.go +120 −0
  • internal/edge/certwarm.go +38 −7
  • internal/provision/testdata/plan14-root-reads-cert-warm-propagation-443.tsv +1 −1
diff --git a/docs/superpowers/reviews/CODEX-REVIEW-cert-warm-443-R1.md b/docs/superpowers/reviews/CODEX-REVIEW-cert-warm-443-R1.md
new file mode 100644
index 000000000..9a3aa2a52
--- /dev/null
+++ b/docs/superpowers/reviews/CODEX-REVIEW-cert-warm-443-R1.md
@@ -0,0 +1,20 @@
+Reviewed `26578a2c..17349ef79a311d9f01113b0e40590a8d92fcd8e1`, round 1.
+
+- **P1 — Brief §6: a subsequent pass can discard a settling host’s retry deadline.**
+ `pass()` skips hosts whose `nextAttempt` remains in the future at [certwarm.go:473](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/cert-warm-443/internal/edge/certwarm.go:473), but updates `settleWait` only when it receives another settling error at [certwarm.go:519](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/cert-warm-443/internal/edge/certwarm.go:519). Consequently, a pass that skips outstanding holds can return the hourly delay at [certwarm.go:561](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/cert-warm-443/internal/edge/certwarm.go:561). The loop then replaces `passDue` at [certwarm.go:289](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/cert-warm-443/internal/edge/certwarm.go:289).
+
+ **Failure scenario:** A is held for 45 seconds. At 20 seconds, an existing DNS retry for baseline host B succeeds and triggers a pass. That pass skips A, warms B, and returns one hour. Without another qualifying wake or an issuer handshake, A remains without a certificate for approximately an hour. Different hold deadlines can produce the same failure when the earliest hold expires.
+
+ **Fix:** retain outstanding settlement deadlines across passes and include skipped settling hosts when calculating the next pass. Compute the remaining delay from absolute deadlines. Add clock-controlled regressions for an intervening DNS-triggered pass and multiple hold deadlines. The current test manually deletes `nextAttempt` before retrying at [certsettle_test.go:225](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/cert-warm-443/internal/edge/certsettle_test.go:225), so it cannot catch this.
+
+ **Fault family:** retry scheduling — every pending settlement must retain a scheduled retry through unrelated passes.
+
+No additional P2 or P3 findings.
+
+The other inspected paths preserve the existing admission checks. Mirror/local-cache fallback remains available during a hold; renewal timers require an existing certificate; wildcard issuance is unaffected. The tracker uses replaced snapshots, and the wire error is generic. Test coverage does not directly pin every requested case, including failed-boot baseline handling, an empty box label, and a held `seen == true` renewal re-arm.
+
+**Census — `internal/edge`: APPROVE** for this commit. Reviewed the new tracker and error helpers in [certsettle.go:54](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/cert-warm-443/internal/edge/certsettle.go:54), the policy change at [certsync.go:204](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/cert-warm-443/internal/edge/certsync.go:204), and the warm changes cited above. They add an in-memory refusal and retry bookkeeping, introduce no new external read targets or execution paths, and preserve the host and issuer checks. The scheduling defect does not expand root authority.
+
+The permitted targeted test command could not start: Go could not create its work directory on the read-only filesystem. `git diff --check` passed. No files were edited.
+
+**NOT READY**
\ No newline at end of file
diff --git a/internal/edge/certsettle_test.go b/internal/edge/certsettle_test.go
index 089db0cb5..a0b99557e 100644
--- a/internal/edge/certsettle_test.go
+++ b/internal/edge/certsettle_test.go
@@ -233,6 +233,126 @@ func TestWarmWaitsOutASettlingNameWithoutFailing(t *testing.T) {
}
}
+// Round 1 (Astra, P1): a pass that runs for some other reason while a name is
+// held skips that name on its backoff floor, and must still come back when
+// the hold ends rather than in an hour.
+func TestWarmKeepsAHoldsDeadlineThroughAnUnrelatedPass(t *testing.T) {
+ clk := &clockAt{t: time.Unix(1_800_000_000, 0)}
+ holdUntil := clk.now().Add(45 * time.Second)
+ w := newCertWarm(
+ func() []string { return []string{"held.test", "other.test"} },
+ func(h *tls.ClientHelloInfo) (*tls.Certificate, error) {
+ if h.ServerName == "held.test" && clk.now().Before(holdUntil) {
+ return nil, &settlingError{left: holdUntil.Sub(clk.now())}
+ }
+ return &tls.Certificate{}, nil
+ },
+ func(string) bool { return true },
+ nil,
+ nil,
+ )
+ w.now = clk.now
+ if d := w.pass(); d != 45*time.Second+warmSettleSlack {
+ t.Fatalf("first pass = %s, want the hold (45s) plus slack", d)
+ }
+ clk.advance(20 * time.Second)
+ if d := w.pass(); d != 25*time.Second+warmSettleSlack {
+ t.Fatalf("a pass during the hold = %s, want the 25s left plus slack, not %s", d, warmInterval)
+ }
+ clk.advance(25*time.Second + warmSettleSlack)
+ w.pass()
+ w.mu.Lock()
+ warmed := w.warmed["held.test"]
+ w.mu.Unlock()
+ if !warmed {
+ t.Fatal("the held name was not ordered once its hold ended")
+ }
+ if d := w.pass(); d != warmInterval {
+ t.Fatalf("after the hold = %s, want the hourly pass", d)
+ }
+}
+
+// Two holds with different deadlines: the pass comes back for the earlier,
+// then for the later.
+func TestWarmComesBackForEachHold(t *testing.T) {
+ clk := &clockAt{t: time.Unix(1_800_000_000, 0)}
+ start := clk.now()
+ until := map[string]time.Time{
+ "a.test": start.Add(10 * time.Second),
+ "b.test": start.Add(40 * time.Second),
+ }
+ w := newCertWarm(
+ func() []string { return []string{"a.test", "b.test"} },
+ func(h *tls.ClientHelloInfo) (*tls.Certificate, error) {
+ if u := until[h.ServerName]; clk.now().Before(u) {
+ return nil, &settlingError{left: u.Sub(clk.now())}
+ }
+ return &tls.Certificate{}, nil
+ },
+ func(string) bool { return true },
+ nil,
+ nil,
+ )
+ w.now = clk.now
+ if d := w.pass(); d != 10*time.Second+warmSettleSlack {
+ t.Fatalf("first pass = %s, want the earlier hold (10s) plus slack", d)
+ }
+ clk.advance(10*time.Second + warmSettleSlack)
+ if d := w.pass(); d != 28*time.Second+warmSettleSlack {
+ t.Fatalf("second pass = %s, want the later hold's 28s left plus slack", d)
+ }
+}
+
+// A name already warmed (a renewal re-arm) that is held is not charged to
+// the order budget and is not marked failed.
+func TestWarmHeldReArmSpendsNoBudget(t *testing.T) {
+ held := false
+ w := newCertWarm(
+ func() []string { return []string{"warm.test"} },
+ func(*tls.ClientHelloInfo) (*tls.Certificate, error) {
+ if held {
+ return nil, &settlingError{left: 30 * time.Second}
+ }
+ return &tls.Certificate{}, nil
+ },
+ func(string) bool { return true },
+ nil,
+ nil,
+ )
+ w.pass()
+ w.mu.Lock()
+ before := len(w.recentOrders)
+ w.mu.Unlock()
+ held = true
+ w.pass()
+ w.mu.Lock()
+ after := len(w.recentOrders)
+ w.mu.Unlock()
+ if after != before {
+ t.Fatalf("a held re-arm changed the order stamps %d -> %d", before, after)
+ }
+}
+
+// When the boot refresh failed, the map starts empty; the first snapshot
+// that is read is a baseline, not news about every name in it.
+func TestHostPolicyTakesTheFirstReadSnapshotAsABaseline(t *testing.T) {
+ clk := &clockAt{t: time.Unix(1_800_000_000, 0)}
+ e := testIssuerEdge("old.test")
+ e.issuer = func() (context.Context, bool) { return context.Background(), true }
+ m := newHomeMap(release.NewDirStore(t.TempDir()), "annie") // never refreshed
+ e.homes.Store(m)
+ pol := e.issuerHostPolicyAt(clk.now)
+
+ homedOn(t, m, "betty", "2.2.2.2", "remote.test")
+ if err := pol(context.Background(), "remote.test"); err != nil {
+ t.Fatalf("a name in the first snapshot read = %v, want no hold", err)
+ }
+ homedOn(t, m, "betty", "2.2.2.2", "remote.test", "remote-new.test")
+ if err := pol(context.Background(), "remote-new.test"); !errors.Is(err, errNameSettling) {
+ t.Fatalf("a name in a later snapshot = %v, want errNameSettling", err)
+ }
+}
+
// A wake arriving while the name settles must not trigger a pass that would
// only meet the hold again; the warm already has its own pass coming.
func TestWarmDoesNotTreatASettlingNameAsNew(t *testing.T) {
diff --git a/internal/edge/certwarm.go b/internal/edge/certwarm.go
index 966b6b11f..f9fd77434 100644
--- a/internal/edge/certwarm.go
+++ b/internal/edge/certwarm.go
@@ -155,6 +155,11 @@ type certWarm struct {
// recentOrders stamps the new orders placed in the last warmCappedDelay,
// the window warmOrdersPerPass is counted over.
recentOrders []time.Time
+ // settleUntil is each held name's absolute deadline (certsettle.go).
+ // Kept across passes so that a pass run for some other reason, which
+ // skips a held name on its nextAttempt floor, still comes back for it
+ // when the hold ends. Cleared on success, on failure and with the set.
+ settleUntil map[string]time.Time
// wake asks the loop for an early pass (nudge). Buffered one deep: a
// wake already pending covers any that arrive behind it.
@@ -187,6 +192,7 @@ func newCertWarm(hosts func() []string, getCert func(*tls.ClientHelloInfo) (*tls
nextAttempt: map[string]time.Time{},
warmed: map[string]bool{},
dnsMisses: map[string]dnsMiss{},
+ settleUntil: map[string]time.Time{},
wake: make(chan struct{}, 1),
now: time.Now,
gateTick: warmGateRecheck,
@@ -460,9 +466,6 @@ func (c *certWarm) pass() time.Duration {
inSet[h] = true
}
orders, capped := 0, false
- // settleWait is the shortest hold met this pass (certsettle.go); zero
- // when none was.
- var settleWait time.Duration
budget := c.orderBudget(c.now())
for _, h := range hosts {
now := c.now()
@@ -517,16 +520,17 @@ func (c *certWarm) pass() time.Duration {
orders--
}
c.settling(h, left)
- if settleWait == 0 || left < settleWait {
- settleWait = left
- }
continue
}
+ c.mu.Lock()
+ delete(c.settleUntil, h)
+ c.mu.Unlock()
c.fail(gctx, h, err, records[h])
continue
}
c.mu.Lock()
delete(c.nextAttempt, h)
+ delete(c.settleUntil, h)
first := !c.warmed[h]
c.warmed[h] = true
c.mu.Unlock()
@@ -550,6 +554,7 @@ func (c *certWarm) pass() time.Duration {
}
}
c.mu.Unlock()
+ settleWait := c.earliestSettle(inSet)
// Housekeeping last: it is the least urgent thing this pass does, and
// running it after the orders means a slow bucket delays litter removal
// rather than certificate issuance (certsweep.go).
@@ -572,11 +577,13 @@ func (c *certWarm) pass() time.Duration {
// settling puts a held name back for when its hold ends. nextAttempt is the
// floor pass() and hasNewHost already honour, so the name is neither retried
-// early nor counted as new by a wake in the meantime.
+// early nor counted as new by a wake in the meantime; settleUntil is what
+// brings every later pass back for it on time (earliestSettle).
func (c *certWarm) settling(host string, left time.Duration) {
until := c.now().Add(left)
c.mu.Lock()
c.nextAttempt[host] = until
+ c.settleUntil[host] = until
c.mu.Unlock()
log.Printf("edge: cert warm for %s waits %s for the other edges to learn the name", host, left.Round(time.Second))
}
@@ -925,3 +932,27 @@ func (c *certWarm) prune(ctx context.Context, records map[string]certwarm.Record
c.clearRecord(ctx, host, "detached")
}
}
+
+// earliestSettle is how long until the soonest hold still running ends,
+// among the names still in the set, and zero when there is none. It drops
+// holds for names that left the set. A hold that has already ended does not
+// count: this pass reached its name unless the order cap or the DNS gate
+// stopped it, and each of those brings the name back on its own schedule
+// (warmCappedDelay, dnsMissed). Counting it would bring the pass straight
+// back, over and over, with nothing new to do.
+func (c *certWarm) earliestSettle(inSet map[string]bool) time.Duration {
+ now := c.now()
+ c.mu.Lock()
+ defer c.mu.Unlock()
+ var soonest time.Duration
+ for h, until := range c.settleUntil {
+ if !inSet[h] {
+ delete(c.settleUntil, h)
+ continue
+ }
+ if left := until.Sub(now); left > 0 && (soonest == 0 || left < soonest) {
+ soonest = left
+ }
+ }
+ return soonest
+}
diff --git a/internal/provision/testdata/plan14-root-reads-cert-warm-propagation-443.tsv b/internal/provision/testdata/plan14-root-reads-cert-warm-propagation-443.tsv
index c7c9cea01..864c8a1cf 100644
--- a/internal/provision/testdata/plan14-root-reads-cert-warm-propagation-443.tsv
+++ b/internal/provision/testdata/plan14-root-reads-cert-warm-propagation-443.tsv
@@ -1,3 +1,3 @@
# Census overlay cert-warm-propagation-443, written by census-propose (#369). census-ruling-cert-warm-propagation-443, approved on #280 before the merge; the approval card is docs/superpowers/notes/census-proposal-cert-warm-propagation-443.md.
# 0 body, 0 sites, 1 envelope: each changed unit re-frozen at its existing disposition with its claim appended.
-@coverage internal/edge 387587cecc89fa53c8aa21177ee397b11551010ee69ea5ef2775cf9156b9395f
+@coverage internal/edge c82f99e34aa642e5c9b701f9505094a5f923c945f6c0281f92b9da7abd546667