oficina / equipo Public

design: a stale-notes replacement spends no Design run

Final review F6 (Fable 3; ledger T9 minor). refuseStaleDesign
replaced a Design attempt refused at its start for stale notes (or a
runner below 39) through dispatchStep, which counted the replacement
while the refused attempt kept its count. Writing notes never calls
personActed, and the revision is the whole notebook's, so three note
writes while a step waited parked it at design_limit for runs nobody
saw.

A refused-at-start attempt never launched: its run is taken back
(designUnran) before the replacement, which is counted when it is
dispatched. That holds for a first start, a failover's advanced
attempt at its own start, and a held attempt at its launch check; a
plain check from below 39 on an attempt that already started may come
after its launch, so it keeps its count.

Test (RED first):
  go test ./internal/equipo/chat/ -run TestStaleReplacementsSpendNoRun
    RED: "after 3 stale replacements: 3 runs, {...}"
    GREEN: ok; chat -run 'Design|Taste|Forget|Stale|Limit|Held|Run'

Mutations (each restored):
  first start refunds nothing       -> "after 3 stale replacements:
                                       3 runs" FAIL
  launch check refunds nothing      -> "after a stale launch: 2 runs"
                                       FAIL
  failover start refunds nothing    -> "after a stale advanced start:
                                       3 runs" FAIL
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev e2ea0a554fe9e92f080f8febab4a8bf8b0c69420 parent d3c7075
2 files changed, +74 −4
  • internal/equipo/chat/runners.go +15 −4
  • internal/equipo/chat/taste_dispatch_test.go +59 −0
diff --git a/internal/equipo/chat/runners.go b/internal/equipo/chat/runners.go
index c032e378..be6213fe 100644
--- a/internal/equipo/chat/runners.go
+++ b/internal/equipo/chat/runners.go
@@ -1013,7 +1013,11 @@ func (s *Store) Authorize(ctx context.Context, l Lease, stepID string, attempt i
if st.DispatchProtocol < wire.ProtocolDesignFeedback || !launch && (purpose != "" || st.StartedAttempt == st.Attempt) {
return nil
}
- if r, err := t.refuseStaleDesign(l, &st); err != nil || r != "" {
+ // Refused here, it never launched (a plain check from below
+ // 39 on an attempt that started may come after its launch:
+ // that one keeps its count).
+ unlaunched := purpose == wire.LeasePurposeLaunch || st.StartedAttempt != st.Attempt
+ if r, err := t.refuseStaleDesign(l, &st, unlaunched); err != nil || r != "" {
refused = r
return err
}
@@ -1041,7 +1045,7 @@ func (s *Store) Authorize(ctx context.Context, l Lease, stepID string, attempt i
refused = wire.CodeAbilityOff
return nil
}
- if r, err := t.refuseStaleDesign(l, &st); err != nil || r != "" {
+ if r, err := t.refuseStaleDesign(l, &st, true); err != nil || r != "" {
refused = r
return err
}
@@ -1067,8 +1071,10 @@ func (s *Store) Authorize(ctx context.Context, l Lease, stepID string, attempt i
// stand (designStale). Else it is refused ("withdrawn") and replaced, so
// this command never starts and the next attempt carries fresh notes or
// waits for a runner at 39; for a task already final or being cancelled
-// it is only refused. "" when it may start.
-func (t *txn) refuseStaleDesign(l Lease, st *stepRecord) (string, error) {
+// it is only refused. "" when it may start. An unlaunched attempt's run
+// is taken back (designUnran): the replacement is counted when it is
+// dispatched, so notes written while a step waits spend no run.
+func (t *txn) refuseStaleDesign(l Lease, st *stepRecord, unlaunched bool) (string, error) {
k, err := t.loadTask(st.TaskID)
if err != nil {
return "", err
@@ -1080,6 +1086,11 @@ func (t *txn) refuseStaleDesign(l Lease, st *stepRecord) (string, error) {
if wire.FinalStage(k.Stage) || k.CancelRequested {
return "withdrawn", nil
}
+ if unlaunched {
+ if err := t.designUnran(&k); err != nil {
+ return "", err
+ }
+ }
if err := t.replace(&k, st); err != nil {
return "", err
}
diff --git a/internal/equipo/chat/taste_dispatch_test.go b/internal/equipo/chat/taste_dispatch_test.go
index 30c7ea36..b1ad9cd7 100644
--- a/internal/equipo/chat/taste_dispatch_test.go
+++ b/internal/equipo/chat/taste_dispatch_test.go
@@ -694,3 +694,62 @@ func TestReconnectBelow39BeforeDelivery(t *testing.T) {
t.Fatalf("a started attempt was re-placed: %+v", now)
}
}
+
+// TestStaleReplacementsSpendNoRun (final review, F6 / Fable 3): an
+// attempt refused at its start for stale notes never launched, so it is
+// not counted against DesignRunLimit. Three notes written in a row while
+// the step waits replace it three times; the fourth attempt is still
+// dispatched (never held at design_limit), counted once, and starts.
+// The same holds for a held attempt refused at its launch check.
+func TestStaleReplacementsSpendNoRun(t *testing.T) {
+ r, l := designReady(t)
+ task := r.designTask(l, r.makerSpecialist(), wire.KindChange)
+ s := r.makerStep(task)
+ if k := r.load(task); k.DesignRuns != 1 {
+ t.Fatalf("dispatched: %d runs", k.DesignRuns)
+ }
+ for i := 0; i < wire.DesignRunLimit; i++ {
+ r.must(r.s.AddTaste(r.ctx, paul, "", "Note "+itoa64(int64(i))+"."))
+ r.ackDispatches(s.ID)
+ if refused := r.authorize(l, s, ""); refused != "withdrawn" {
+ t.Fatalf("stale start %d: %q", i, refused)
+ }
+ s = r.stepNow(s.ID)
+ }
+ if k := r.load(task); k.DesignRuns != 1 || s.Placement == wire.PlacementDesignLimit || !r.attemptSent(s) {
+ t.Fatalf("after %d stale replacements: %d runs, %+v", wire.DesignRunLimit, k.DesignRuns, s)
+ }
+ r.ackDispatches(s.ID)
+ if refused := r.authorize(l, s, ""); refused != "" {
+ t.Fatalf("the fresh attempt: %q", refused)
+ }
+ // Held after its start, then a note: the launch check replaces it,
+ // and that unlaunched attempt spends no run either.
+ s = r.stepNow(s.ID)
+ r.must(r.s.AddTaste(r.ctx, paul, "", "Later."))
+ if refused := r.authorize(l, s, wire.LeasePurposeLaunch); refused != "withdrawn" {
+ t.Fatalf("stale launch: %q", refused)
+ }
+ if k := r.load(task); k.DesignRuns != 1 {
+ t.Fatalf("after a stale launch: %d runs", k.DesignRuns)
+ }
+ // A failover's advanced attempt (counted when the runner moved on)
+ // refused at its own start: its run is taken back too.
+ s = r.stepNow(s.ID)
+ r.ackDispatches(s.ID)
+ if refused := r.authorize(l, s, ""); refused != "" {
+ t.Fatalf("start %q", refused)
+ }
+ r.report(l, r.stepNow(s.ID), wire.StepReport{State: wire.StepRunning, Attempt: s.Attempt + 1})
+ adv := r.stepNow(s.ID)
+ if k := r.load(task); adv.Attempt != s.Attempt+1 || k.DesignRuns != 2 {
+ t.Fatalf("advance: attempt %d, %d runs", adv.Attempt, k.DesignRuns)
+ }
+ r.must(r.s.AddTaste(r.ctx, paul, "", "Even later."))
+ if refused := r.authorize(l, adv, ""); refused != "withdrawn" {
+ t.Fatalf("stale advanced start: %q", refused)
+ }
+ if k := r.load(task); k.DesignRuns != 2 {
+ t.Fatalf("after a stale advanced start: %d runs", k.DesignRuns)
+ }
+}