carlos / platform Public

fix: hold demo control acks until counters initialize

Withhold the revision acknowledgement after registry or counter storage
errors while continuing to process other entries. Keep permanent
refusals acknowledged and retry initialization idempotently.

Cover recovery after initialization and registry failures, permanent
refusal acknowledgements, and console initialization only after ack.
codex agent, operated by paul@keymail.dev pushed by claude agent, operated by paul@keymail.dev 62f9bad78aca2fc5b23322892a88834635e989c4 parent 2514f61
3 files changed, +148 −5
  • internal/console/demo_operator_test.go +16 −4
  • internal/host/demo_control_fix_test.go +118 −0
  • internal/host/demo_serving.go +14 −1

CI failed — run details

Intent

Human

<task-notification> <task-id>brglknu8g</task-id> <tool-use-id>toolu_01EWyckfStdbTAeJWfbN8Sin</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/6e566fe9-9aca-47cb-9753-64e881b0d285/tasks/brglknu8g.output</output-file> <status>completed</status> <summary>Background command "Wait for Task 4 fix run" completed (exit code 0)</summary> </task-notification>

Human

<task-notification> <task-id>a4e93d9504923f918</task-id> <tool-use-id>toolu_01JcWtyXkDximCD3RDLstvac</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/6e566fe9-9aca-47cb-9753-64e881b0d285/tasks/a4e93d9504923f918.output</output-file> <status>completed</status> <summary>Agent "Re-review Task 4 fix, round 2 (Opus)" 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>Round 2 verdict: **READY AFTER FIXES**. All five round-1 findings are resolved and there is no new P1, but the fix introduced one new P2 that should be fixed without another round. **Round-1 findings:** - **P1-1: resolved.** A cancelled request can no longer poison the traffic store or block retirement (`host/demo_traffic.go:77-97`, `:133-195`). - Only real SQLite storage errors set the poison flag, and it now blocks only debits. Fence, Purge and control writes still run. - Zero overservice holds when a debit's commit outcome is unknown. A failed or interrupted commit returns 0 bytes, and so does a committed debit whose caller has gone. - I checked the SQLite driver (modernc v1.55.0, `interruptOnDone`): a late cancellation cannot interrupt an unrelated statement. - **P2-1: resolved.** A new revision cancels only the lifetimes that lost authority. Off or protections-disabled still cancels everything (`host/demo_serving.go:189-199`, `:236`; `edge/demo_traffic.go:603-622`). - **P2-2: resolved.** The rollback check now reads the clock inside the serving mutex, so ordinary concurrency can't trip it (`host/demo_serving.go:274-287`). - **P2-3: resolved.** Bad entries are refused one at a time (`host/demo_serving.go:132-160`). A refused control no longer ends the stream (`demo_jobs.go:498`), and reconnect backoff resets after a healthy session. - **P2-4: resolved.** The 35-second timer now needs evidence the box is protected. Legacy rows and peers with no probe or no ack stay pending (`console/demo_serving.go:223-243`, `:333-339`). **New P2 (fault family: acknowledgement scope, i.e. R8 one-shot initialization):** - **N-P2-1: a single transient error can leave a new demo unserved for its whole life (up to 24 h).** 1. On the demo's first control, `Initialize` or the registry read fails once (`host/demo_serving.go:143-158`). The box now skips that entry but still acknowledges the whole revision (`:201`). 2. The console then marks every Initialize entry in that revision as initialized (`console/demo_serving.go:186-198`). 3. Later controls send `Initialize=false`. The box's `checkAssignment` finds no counter row (`host/demo_traffic.go:234-241`), so the demo gets 503 until expiry or takedown. - Before the fix, the whole control failed without an ack and the console retried `Initialize=true`, which is safe because `Initialize` is idempotent. It fails closed and can't overserve. - This is the round-1 per-lifetime family (P2-1/P2-2/P2-3), now on the acknowledgement side. - Suggested fix: skip entries one at a time only for permanent causes. On a transient `Initialize` or registry error, either fail the control without an ack or hold the ack until the entry installs. Add a witness: an Initialize that fails once, then a later control that serves the demo. **New P3s:** - **N-P3-1:** if the console clock briefly jumps forward, the stored ValidUntil deadline sticks. Same-revision renewals then fail and close serving box-wide until the revision changes. It affects availability only. - **N-P3-2:** for an offline box, `initialized=1` counts as proof of protection, which assumes the box is never downgraded to an old binary. This belongs in the Task 6 runbook. **Tests:** host and edge `TestDemo` passed. Console `TestDemo` failed only in `TestDemoSourceToLiveAndUpdate` and `TestDemoUsesRealReleasePathGET`, because the sandbox refuses unix-socket listens. The fix doesn't touch either test. The console operator, kill, takedown, expiry and retirement tests all passed. The full review is in `/home/paulca/amadan.net/carlos/platform/.claude/worktrees/agent-start-demo-2/.superpowers/sdd/2026-11-04-agent-start-demo-2-edge-protections/task-4-review-r2.md`.</result> <usage><subagent_tokens>106249</subagent_tokens><tool_uses>17</tool_uses><duration_ms>466616</duration_ms></usage> </task-notification>

Attributed to this commit: 9.04 g CO₂e (1,082,954 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on agent-start-demo-2, 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/console/demo_operator_test.go b/internal/console/demo_operator_test.go
index c7fa01ae4..47bbb1dea 100644
--- a/internal/console/demo_operator_test.go
+++ b/internal/console/demo_operator_test.go
@@ -238,23 +238,35 @@ func TestDemoServingStreamConsole(t *testing.T) {
if err = s.ackDemoServing(t.Context(), &demoPeer{name: peer.name}, c.Revision); err == nil {
t.Fatal("foreign session ack")
}
- ready.ServingAck = c.Revision
ready.ServingProbe = 101
if err = websocket.JSON.Send(ws, ready); err != nil {
t.Fatal(err)
}
+ retry := read()
+ if retry.Revision != c.Revision || retry.Probe != 101 || !retry.Demos[0].Initialize {
+ t.Fatalf("unacknowledged initialization not retried: %+v", retry)
+ }
+ var initialized bool
+ if err = s.store.db.QueryRow(`SELECT initialized FROM demo_caps WHERE demo_id=?`, d.ID).Scan(&initialized); err != nil || initialized {
+ t.Fatalf("initialized before acknowledgement: %t %v", initialized, err)
+ }
+ ready.ServingAck = c.Revision
+ ready.ServingProbe = 102
+ if err = websocket.JSON.Send(ws, ready); err != nil {
+ t.Fatal(err)
+ }
next := read()
- if next.Revision != c.Revision || next.Probe != 101 || next.Demos[0].Initialize {
+ if next.Revision != c.Revision || next.Probe != 102 || next.Demos[0].Initialize {
t.Fatalf("ack/renewal %+v", next)
}
if err = s.setDemoServing(t.Context(), false, "operator@example.com", time.Now()); err != nil {
t.Fatal(err)
}
off := read()
- if off.Enabled || off.Revision <= c.Revision || off.Probe != 101 {
+ if off.Enabled || off.Revision <= c.Revision || off.Probe != 102 {
t.Fatalf("off %+v", off)
}
- ready.ServingProbe = 102
+ ready.ServingProbe = 103
ready.ServingAck = off.Revision
if err = websocket.JSON.Send(ws, ready); err != nil {
t.Fatal(err)
diff --git a/internal/host/demo_control_fix_test.go b/internal/host/demo_control_fix_test.go
index 1385201cc..6d6690c3f 100644
--- a/internal/host/demo_control_fix_test.go
+++ b/internal/host/demo_control_fix_test.go
@@ -190,10 +190,128 @@ func TestDemoServingStreamEntryIsolation(t *testing.T) {
if w.serving.until.After(now.Add(30 * time.Second)) {
t.Fatal("rounding extended probe bound")
}
+ if ack := w.demoHeartbeat(time.Now()).ServingAck; ack != c.Revision {
+ t.Fatalf("permanent refusal left revision unacknowledged: %d", ack)
+ }
})
}
}
+func TestDemoServingStreamInitializeRetry(t *testing.T) {
+ w, c, rt, now := demoControlFixFixture(t)
+ id := c.Demos[0].Identity
+ if err := w.traffic.Admit(t.Context(), id); err != nil {
+ t.Fatal(err)
+ }
+ next := c.Demos[0]
+ next.Identity = demo.TrafficIdentity{ID: "shop2", Lifetime: "life2", Host: "shop2.example.com"}
+ c.Demos = append([]demo.ServingDemo{next}, c.Demos...)
+ c.Revision++
+ // Fail only the new counter insert, leaving control persistence and the
+ // following entry usable. Removing the fault lets the next control retry.
+ if _, err := w.traffic.db.Exec(`CREATE TRIGGER fail_initialize BEFORE INSERT ON demo_traffic WHEN NEW.demo_id='shop2' BEGIN SELECT RAISE(ABORT, 'initialize storage failure'); END`); err != nil {
+ t.Fatal(err)
+ }
+ if err := w.applyDemoServing(c, now); err != nil {
+ t.Fatal(err)
+ }
+ ready := w.demoHeartbeat(time.Now())
+ if ready.ServingAck != 0 {
+ t.Errorf("failed initialization acknowledged: %d", ready.ServingAck)
+ }
+ if _, ok := w.serving.demos[next.Identity]; ok {
+ t.Fatal("failed initialization admitted demo")
+ }
+ if !w.demoServingAllowed(rt, time.Now()) {
+ t.Fatal("failed initialization blocked following entry")
+ }
+ if _, err := w.traffic.db.Exec(`DROP TRIGGER fail_initialize`); err != nil {
+ t.Fatal(err)
+ }
+ c.Probe = ready.ServingProbe
+ c.ValidUntil++
+ if err := w.applyDemoServing(c, time.Now()); err != nil {
+ t.Fatal(err)
+ }
+ rt.Host, rt.DemoHost, rt.DemoID, rt.DemoLifetime = next.Identity.Host, next.Identity.Host, next.Identity.ID, next.Identity.Lifetime
+ if !w.demoServingAllowed(rt, time.Now()) || w.demoHeartbeat(time.Now()).ServingAck != c.Revision {
+ t.Fatal("later control did not serve and acknowledge recovered demo")
+ }
+ if err := w.traffic.Admit(t.Context(), next.Identity); err != nil {
+ t.Fatalf("recovered demo cannot dispatch: %v", err)
+ }
+ var requests int64
+ if err := w.traffic.db.QueryRow(`SELECT requests FROM demo_traffic WHERE demo_id=? AND lifetime=?`, id.ID, id.Lifetime).Scan(&requests); err != nil || requests != 1 {
+ t.Fatalf("Initialize retry reset existing allowance: %d %v", requests, err)
+ }
+}
+
+func TestDemoServingStreamPermanentRefusalAcknowledged(t *testing.T) {
+ w, c, rt, _ := demoControlFixFixture(t)
+ bad := c.Demos[0]
+ bad.Identity = demo.TrafficIdentity{ID: "shop2", Lifetime: "life2", Host: "shop2.example.com"}
+ if err := w.traffic.Initialize(t.Context(), bad.Identity, bad.Caps); err != nil {
+ t.Fatal(err)
+ }
+ bad.Caps.Requests++ // A persisted assignment mismatch cannot be retried away.
+ c.Demos = append([]demo.ServingDemo{bad}, c.Demos...)
+ c.Revision++
+ for range 2 {
+ if err := w.applyDemoServing(c, time.Now()); err != nil {
+ t.Fatal(err)
+ }
+ ready := w.demoHeartbeat(time.Now())
+ if ready.ServingAck != c.Revision || !w.demoServingAllowed(rt, time.Now()) {
+ t.Fatal("permanent refusal blocked acknowledgement or healthy serving")
+ }
+ if _, ok := w.serving.demos[bad.Identity]; ok {
+ t.Fatal("mismatched assignment accepted")
+ }
+ // The console stops requesting initialization once this ack arrives.
+ for i := range c.Demos {
+ c.Demos[i].Initialize = false
+ }
+ c.Probe = ready.ServingProbe
+ c.ValidUntil++
+ }
+}
+
+func TestDemoServingStreamRegistryRetry(t *testing.T) {
+ w, c, rt, _ := demoControlFixFixture(t)
+ path := filepath.Join(t.TempDir(), "registry.db")
+ reg, err := registry.Open(path)
+ if err != nil {
+ t.Fatal(err)
+ }
+ w.reg = reg
+ if err := reg.Close(); err != nil {
+ t.Fatal(err)
+ }
+ // This revision was already acknowledged. A failed renewal must clear
+ // that ack too, so it cannot acknowledge the console's latest issuance.
+ c.ValidUntil++
+ if err := w.applyDemoServing(c, time.Now()); err != nil {
+ t.Fatal(err)
+ }
+ ready := w.demoHeartbeat(time.Now())
+ if ready.ServingAck != 0 || w.demoServingAllowed(rt, time.Now()) {
+ t.Fatal("registry error acknowledged or served")
+ }
+ w.reg, err = registry.Open(path)
+ if err != nil {
+ t.Fatal(err)
+ }
+ t.Cleanup(func() { w.reg.Close() })
+ c.Probe = ready.ServingProbe
+ c.ValidUntil++
+ if err := w.applyDemoServing(c, time.Now()); err != nil {
+ t.Fatal(err)
+ }
+ if w.demoHeartbeat(time.Now()).ServingAck != c.Revision || !w.demoServingAllowed(rt, time.Now()) {
+ t.Fatal("registry recovery did not serve and acknowledge")
+ }
+}
+
func TestDemoTrafficStoragePoisonStillRetires(t *testing.T) {
w, c, _, _ := demoControlFixFixture(t)
id := c.Demos[0].Identity
diff --git a/internal/host/demo_serving.go b/internal/host/demo_serving.go
index 7b4290a72..02518f9b4 100644
--- a/internal/host/demo_serving.go
+++ b/internal/host/demo_serving.go
@@ -129,6 +129,7 @@ func (w *demoWorker) applyDemoServing(c demo.ServingControl, now time.Time) erro
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
demos := make(map[demo.TrafficIdentity]demo.ServingDemo)
+ installed := true
hosts := make(map[string]int)
identities := make(map[demo.TrafficIdentity]int)
for _, d := range c.Demos {
@@ -143,6 +144,7 @@ func (w *demoWorker) applyDemoServing(c demo.ServingControl, now time.Time) erro
if w.reg != nil {
rt, err := w.reg.Get(id.Host)
if err != nil {
+ installed = false
continue
}
if rt != nil && (rt.FleetBox != w.box || rt.DemoID != id.ID || rt.DemoLifetime != id.Lifetime || rt.DemoExpiresAt != d.ExpiresAt) {
@@ -151,9 +153,15 @@ func (w *demoWorker) applyDemoServing(c demo.ServingControl, now time.Time) erro
}
if d.Initialize {
if err := w.traffic.Initialize(ctx, id, d.Caps); err != nil {
+ if !errors.Is(err, demo.ErrTrafficUnavailable) && !errors.Is(err, sql.ErrNoRows) {
+ installed = false
+ }
continue
}
} else if err := w.traffic.checkAssignment(ctx, id, d.Caps); err != nil {
+ if !errors.Is(err, demo.ErrTrafficUnavailable) && !errors.Is(err, sql.ErrNoRows) {
+ installed = false
+ }
continue
}
demos[id] = d
@@ -198,7 +206,12 @@ func (w *demoWorker) applyDemoServing(c demo.ServingControl, now time.Time) erro
}
}
s.demos = demos
- s.revision, s.ack, s.deadline = c.Revision, c.Revision, c.ValidUntil
+ s.revision, s.ack, s.deadline = c.Revision, 0, c.ValidUntil
+ // Storage failures must leave Initialize pending at the console. Clear
+ // even an earlier ack of this revision until a later control succeeds.
+ if installed {
+ s.ack = c.Revision
+ }
s.until = until
s.sessionHealthy = true
s.enabled = c.Enabled && w.cfg.EdgeProtections