carlos / platform Public

region HA sim: separate admission tickets from app entry (R3.2)

Task 7 fix round 1 (Astra P2-1). MoveState's "none" on A now issues an
admission ticket, and the request reaches A's app later (0 to 3 s, its
begin), so the move can start between the two. The move waits on
outstanding tickets, admitted or running, within the 10 s in-flight
bound; at the bound it cuts the app and answers admitted requests as a
stopping host does.

H1's oracle follows: entry needs a ticket, and a ticketed request may
enter while the host is holding, but never after its app was stopped.

New rule move-ignores-tickets (the move waits only on requests already
in the app), with a crossing witness: a request ticketed just before
the move enters A's app 3 s later.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 43d12df19ea5cc52c9c75f15cf7c5fcff974aa69 parent e1e10cf
2 files changed, +102 −18
  • internal/sim/regionha/handover_test.go +83 −17
  • internal/sim/regionha/handover_witness_test.go +19 −1

CI failed — run details

Intent

Human

<task-notification> <task-id>af98cd70b0fccc48d</task-id> <tool-use-id>toolu_01MEjv3o47j7AF5kvQHUxFeJ</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/283be278-5c6a-4a71-a8d6-b3d32c668985/tasks/af98cd70b0fccc48d.output</output-file> <status>completed</status> <summary>Agent "Implement Task 7: simulation" 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>Status: DONE_WITH_CONCERNS (modelling choices only, no open defect) Commit: e1e10cf4 `region HA sim: model the planned handover, I9 to I11 and its mutations` (not pushed) Tests: at 3,000 seeds the unmutated sweep had 0 failures (18.6 s), and all 13 new mutation rules were caught, each by both the sweep (12 to 2,851 failing seeds) and its witness (282 s total, serial, nice 19); the package tests, gofmt, vet and the census test pass. Concerns: - The handover runs as its own per-seed scenario, like the group and duty scenarios, not inside the minute-step lease walk. - With the fence in place, a restart after the report is harmless, so the incarnation check alone can't be caught. `action-on-stale-report` therefore skips the whole pre-action re-read and is caught through a reboot, which clears the tmpfs fence. - Lifting the fence on an unknown probe at `drain --cancel` breaks no invariant in the model, so `fence-lift-on-unknown` is caught during a delayed terminate instead. - Possible production gap, not modelled: a reboot while the terminate is landing would bring up an unfenced agent; worth a line in §25.15 at Task 8. - The FA and H1 checks sit close to the rules they guard. `handover-authorizes-acquire` (13 seeds) and `fence-lift-on-unknown` (12) are caught under 1 % by the sweep, but every time by their witnesses. Report: /home/paulca/amadan.net/carlos/platform/.claude/worktrees/region-ha-held-build/.superpowers/sdd/2026-11-08-region-ha-held-requests/task-7-report.md (evidence in task-7-mutate.out beside it)</result> <usage><subagent_tokens>365519</subagent_tokens><tool_uses>55</tool_uses><duration_ms>2518999</duration_ms></usage> </task-notification>

Attributed to this commit: 20.3 g CO₂e (2,610,497 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on region-ha-held-build, 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/sim/regionha/handover_test.go b/internal/sim/regionha/handover_test.go
index 47500086b..6f6c1990d 100644
--- a/internal/sim/regionha/handover_test.go
+++ b/internal/sim/regionha/handover_test.go
@@ -94,6 +94,7 @@ func init() {
"action-on-stale-report", // the tool acts on the drain verb's report without reading again (H5, I11)
"place-before-acks", // the drain goes on before every acknowledgement (§25.4 step 1, WD)
"fence-lift-on-unknown", // the tool lifts the fence on an unknown edge state (R3.1, I11)
+ "move-ignores-tickets", // the move waits on requests in the app, not on outstanding tickets (R3.2, H1)
)
}
@@ -119,6 +120,7 @@ type hoReq struct {
Kind string // client, marked (an edge-held stream's request)
Body string // none, small (known length, at most 64 KiB), large, unknown
Work int // seconds it runs in A's app
+ Admit int // seconds from its admission ticket to A's app (begin)
First *hoNode
Whole bool // the first box read the body whole before its first send
Replayable bool // X-Carlos-Replayable: 1
@@ -222,6 +224,7 @@ type hoWorld struct {
moves map[string]*hoMove
latch map[string]bool
inApp []*hoApp
+ admitted []*hoApp // ticketed on A, not yet in the app (until: when it enters)
held []*hoReq
waiting []*hoWait
ready map[*box]map[string]int
@@ -405,6 +408,9 @@ func (ho *hoWorld) req(kind string, fb *hoNode, h, body string, work int) *hoReq
if kind == "marked" {
r.Body = "none"
}
+ if ho.rng != nil {
+ r.Admit = ho.rng.Intn(4)
+ }
ho.reqs = append(ho.reqs, r)
return r
}
@@ -879,6 +885,20 @@ func (ho *hoWorld) serve(x *box, r *hoReq) string {
ho.event("ho-wait-restore")
return "pending"
}
+ if x == ho.A {
+ // R3.2: the ticket is held from MoveState's "none" until the
+ // request finishes; it reaches the app r.Admit seconds later.
+ ho.admitted = append(ho.admitted, &hoApp{r: r, until: ho.sec + r.Admit})
+ return "pending"
+ }
+ ho.deliver(x, r)
+ ho.write(x, h)
+ return "app"
+}
+
+// deliver is r reaching x's tenant pipeline and app handler.
+func (ho *hoWorld) deliver(x *box, r *hoReq) {
+ h := r.Host
if r.GatedBy != x {
r.Pipeline++
}
@@ -889,18 +909,24 @@ func (ho *hoWorld) serve(x *box, r *hoReq) string {
if r.Truncated {
ho.fail("I9", "request %d for %s (body %s) was sent again without a whole copy; box%d's app got a truncated body", r.ID, h, r.Body, x.ID)
}
- if x == ho.A {
- if m := ho.moves[h]; m != nil && (m.State == "holding" || m.State == "releasing") {
- ho.fail("H1", "request %d (%s) entered A's app for %s while it was %s", r.ID, r.Kind, h, m.State)
- }
- if !r.Ticket {
- ho.fail("H1", "request %d (%s) entered A's app for %s with no admission ticket", r.ID, r.Kind, h)
- }
- ho.inApp = append(ho.inApp, &hoApp{r: r, until: ho.sec + r.Work})
- return "pending"
+}
+
+// enterApp is an admitted request reaching A's app: it needs a ticket, and
+// the app must not have been stopped under it (R3.2: every request
+// crossing a move is counted or held).
+func (ho *hoWorld) enterApp(r *hoReq) {
+ A, h := ho.A, r.Host
+ if !r.Ticket {
+ ho.fail("H1", "request %d (%s) entered A's app for %s with no admission ticket", r.ID, r.Kind, h)
}
- ho.write(x, h)
- return "app"
+ m := ho.moves[h]
+ if e := A.Entries[h]; e == nil || e.Releasing != nil || m != nil && m.Stage != "inflight" {
+ ho.fail("H1", "request %d (%s), ticketed, entered A's app for %s after the app was stopped", r.ID, r.Kind, h)
+ ho.finish(r.First, r, "today")
+ return
+ }
+ ho.deliver(A, r)
+ ho.inApp = append(ho.inApp, &hoApp{r: r, until: ho.sec + r.Work})
}
func (ho *hoWorld) write(x *box, h string) {
@@ -910,7 +936,8 @@ func (ho *hoWorld) write(x *box, h string) {
}
}
-// tickets is the number of admitted requests running in A's app for h.
+// tickets is the number of h's outstanding admission tickets on A: the
+// requests admitted and not yet in the app, and those running in it.
func (ho *hoWorld) tickets(h string) int {
n := 0
for _, a := range ho.inApp {
@@ -918,11 +945,36 @@ func (ho *hoWorld) tickets(h string) int {
n++
}
}
+ if !on("move-ignores-tickets") {
+ return n // the mutation: only what is already in the app
+ }
+ for _, a := range ho.admitted {
+ if a.r.Host == h && a.r.Ticket {
+ n++
+ }
+ }
return n
}
-// cutApp stops h's app on A: the requests still in it are cut.
+// cutApp stops h's app on A: the requests still in it are cut, and those
+// admitted but not yet in it meet a stopping host (today's answer).
func (ho *hoWorld) cutApp(h, why string) {
+ if on("move-ignores-tickets") || why != "the move's stop" {
+ var late []*hoApp
+ ak := ho.admitted[:0]
+ for _, a := range ho.admitted {
+ if a.r.Host == h {
+ late = append(late, a)
+ } else {
+ ak = append(ak, a)
+ }
+ }
+ ho.admitted = ak
+ for _, a := range late {
+ ho.event("ho-admitted-stopped")
+ ho.finish(a.r.First, a.r, "today")
+ }
+ }
keep := ho.inApp[:0]
for _, a := range ho.inApp {
if a.r.Host != h {
@@ -962,6 +1014,20 @@ func (ho *hoWorld) timers() {
for _, nd := range ho.nodes {
ho.fold(nd) // the change index: a fold that can succeed does
}
+ var enter []*hoApp
+ ak := ho.admitted[:0]
+ for _, a := range ho.admitted {
+ if ho.sec >= a.until {
+ enter = append(enter, a)
+ } else {
+ ak = append(ak, a)
+ }
+ }
+ ho.admitted = ak
+ for _, a := range enter {
+ ho.event("ho-admitted-entered")
+ ho.enterApp(a.r)
+ }
var doneApps []*hoApp
keep := ho.inApp[:0]
for _, a := range ho.inApp {
@@ -1043,8 +1109,8 @@ func (ho *hoWorld) agentDown(reboot bool) {
ho.latch = map[string]bool{}
ho.lockRead = map[string]hoLockRead{}
ho.endHolds("", "reset")
- apps := ho.inApp
- ho.inApp = nil
+ apps := append(ho.inApp, ho.admitted...)
+ ho.inApp, ho.admitted = nil, nil
for _, a := range apps {
ho.finish(a.r.First, a.r, "reset")
}
@@ -1682,7 +1748,7 @@ func (ho *hoWorld) second(background func()) {
// settle runs the clock with no new requests until every request is
// answered, then I10's last half: nothing is left unanswered.
func (ho *hoWorld) settle() {
- for i := 0; i < 200 && (len(ho.held) > 0 || len(ho.inApp) > 0 || len(ho.waiting) > 0 || ho.phase != "done"); i++ {
+ for i := 0; i < 200 && (len(ho.held) > 0 || len(ho.inApp) > 0 || len(ho.admitted) > 0 || len(ho.waiting) > 0 || ho.phase != "done"); i++ {
ho.second(nil)
}
for _, r := range ho.reqs {
@@ -1977,7 +2043,7 @@ func randomKnobs(rng *rand.Rand, n int, hosts []string, nodes []string) hoKnobs
if rng.Intn(2) == 0 {
k.Probe = "unknown"
}
- k.LocalRace = rng.Intn(3) == 0
+ k.LocalRace = rng.Intn(3) != 0
k.PendingAtDrain = rng.Intn(3) == 0
return k
}
diff --git a/internal/sim/regionha/handover_witness_test.go b/internal/sim/regionha/handover_witness_test.go
index b941d0c8e..b667a488e 100644
--- a/internal/sim/regionha/handover_witness_test.go
+++ b/internal/sim/regionha/handover_witness_test.go
@@ -33,6 +33,8 @@ func init() {
"roll: A reboots after its report, losing the fence, and acquires blog; acting on the old report applies while a lease names A", wHOStale},
witness{"place-before-acks", "place-before-acks", "WD",
"C's acknowledgement is slow; a drain that goes on without it closes A's gate while C still places blog on A (§6.3 rule 1)", wHOAcks},
+ witness{"move-ignores-tickets", "move-ignores-tickets", "H1",
+ "R3.2: a request gets its ticket just before shop's move and reaches A's app 3 s later; a move that waits only on the app stops first, and the ticketed request enters a stopped app", wHOTickets},
witness{"fence-lift-on-unknown", "fence-lift-on-unknown", "I11",
"replace: the stopped edge restarts while the terminate is delayed; lifting the fence on an unknown edge state lets it acquire blog before the terminate lands", wHOFence},
)
@@ -267,6 +269,22 @@ func wHOFence(t *testing.T, w *world) {
expect(t, "fence-lift-on-unknown", r.Answer == "today" && w.events["ho-start-refused-fenced"] == 1, "the restarted edge is fenced: %+v", r)
}
+func wHOTickets(t *testing.T, w *world) {
+ A, _, _ := w.abc()
+ ho := hoWitness(w, "roll")
+ w.wake(A, sh, wakeOpts{}, nil)
+ ho.until(t, "quiescence", func() bool { return ho.phase == "quiesce" })
+ if ho.moves[sh] != nil {
+ t.Errorf("setup: the move started before the ticket")
+ }
+ r := ho.req("client", ho.nodeOf[A], sh, "none", 1)
+ r.Admit = 3
+ ho.arrive(r)
+ expect(t, "move-ignores-tickets", r.Ticket && r.HeldAt < 0 && len(ho.admitted) == 1, "the request is ticketed, not held: %+v", r)
+ ho.finishAll()
+ expect(t, "move-ignores-tickets", r.Answer == "app" && len(r.Delivered) == 1 && w.events["ho-moved"] == 1, "the move waits for the ticket; the request is served on A: %+v", r)
+}
+
// TestHandoverEveryActionFires: over 200 seeds of the unmutated walk every
// handover action completes, and every path the handover rules guard is
// reached. ho-handover-not-followed is left out: A answers a second
@@ -304,7 +322,7 @@ func TestHandoverEveryActionFires(t *testing.T) {
"ho-standby", "ho-withdrawn", "ho-ack-slow", "ho-drain-failed-ack", "ho-pending-begun", "ho-pending-settled",
"ho-move-start", "ho-held", "ho-hold-released", "ho-hold-bound", "ho-refused-at-once", "ho-moved",
"ho-take-raced", "ho-take-lost-race", "ho-take-timeout", "ho-move-failed", "ho-unclean-release",
- "ho-lease-loss", "ho-fa", "ho-cut", "ho-wait-restore",
+ "ho-lease-loss", "ho-fa", "ho-cut", "ho-wait-restore", "ho-admitted-entered", "ho-admitted-stopped",
"ho-redirect", "ho-redirect-read", "ho-successor-slept", "ho-handover-answer", "ho-handover-followed",
"ho-handover-local", "ho-local-raced", "ho-retry-named",
"ho-reset-after-send", "ho-dial-before-send", "ho-placed-on-A", "ho-start-refused", "ho-start-refused-fenced",