carlos / platform Public

moves: offline run binds the move its own stage made

The run took its move id from the first view after its stage, so a
second operator who aborted, finished and restaged in that window got
their move carried through by this run. An accepted stage reply now
binds the run to the id it names; a different move after it stops the
run (exit 4) with nothing sent. A lost stage reply still binds from the
next view. Found by Task 7's simulation.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 7569d6f9768b9768c65f9f3c1c2c752b7befac59 parent cbff4f1
4 files changed, +59 −1
  • internal/moves/offlinerun/run.go +9 −0
  • internal/moves/offlinerun/run_test.go +29 −0
  • move_offline_run.go +1 −1
  • move_offline_run_test.go +20 −0
diff --git a/internal/moves/offlinerun/run.go b/internal/moves/offlinerun/run.go
index c7ed5bd3f..4328bce5a 100644
--- a/internal/moves/offlinerun/run.go
+++ b/internal/moves/offlinerun/run.go
@@ -29,6 +29,9 @@ type Answer struct {
// Sentence is the console's own sentence for a refusal, when the
// Doors can carry it; "" otherwise.
Sentence string
+ // ID is the move the door's view names, for an accepted POST ("" when
+ // the Doors cannot read it). An accepted stage binds the run to it.
+ ID string
}
// Doors are the console's offline move doors, as this run reaches them.
@@ -108,6 +111,12 @@ func (r *Runner) Step(ctx context.Context, m Memory) (Memory, *Done, error) {
if !ans.Accepted && ans.Refused {
m = m.Refused(ans.Sentence)
}
+ if a.Verb == VerbStage && ans.Accepted && ans.ID != "" && m.id == "" {
+ // Bound to the move this stage made, not to whatever the next
+ // view shows: someone may have ended it and staged their own
+ // before that read.
+ m.id = ans.ID
+ }
if a.Verb == VerbOpen && (ans.Accepted || !ans.Refused) {
r.openSent = true
}
diff --git a/internal/moves/offlinerun/run_test.go b/internal/moves/offlinerun/run_test.go
index ad98ff512..60be43806 100644
--- a/internal/moves/offlinerun/run_test.go
+++ b/internal/moves/offlinerun/run_test.go
@@ -230,3 +230,32 @@ func TestRunProbeThenFinish(t *testing.T) {
t.Fatalf("calls %s", got)
}
}
+
+// TestRunBindsTheMoveItsStageMade: the stage door's accepted reply names
+// the move it made, and the run is bound to it from then on. A second
+// operator who aborts that move, finishes it and stages one of their own
+// before the run's next read leaves the run looking at another move: it
+// stops (exit 4) and sends nothing for it, rather than adopting it.
+func TestRunBindsTheMoveItsStageMade(t *testing.T) {
+ theirs := View{State: StateStaging, ID: tOther, StagedAt: 5}
+ d := &fakeDoors{
+ views: []View{none(nil), theirs},
+ answer: func(verb string) Answer {
+ return Answer{Accepted: true, ID: tID}
+ },
+ }
+ r, _ := testRunner(d, func() int { return 200 })
+ done, m, err := r.Run(context.Background(), NewMemory(""), nil)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if want := (Done{Exit: ExitStopped, Reason: ReasonOtherMove}); done != want {
+ t.Fatalf("done = %#v, want %#v", done, want)
+ }
+ if m.Bound() != tID {
+ t.Fatalf("bound to %q, want %q", m.Bound(), tID)
+ }
+ if want := []string{"status", "stage ", "status"}; !reflect.DeepEqual(d.log, want) {
+ t.Fatalf("calls %q, want %q", d.log, want)
+ }
+}
diff --git a/move_offline_run.go b/move_offline_run.go
index 51bf8d87f..bbf63250a 100644
--- a/move_offline_run.go
+++ b/move_offline_run.go
@@ -283,7 +283,7 @@ func (d *runDoors) answer(r moveReply) offlinerun.Answer {
if json.Unmarshal(r.body, &v) == nil {
d.w.learn(v)
}
- return offlinerun.Answer{Accepted: true}
+ return offlinerun.Answer{Accepted: true, ID: v.ID}
case r.refused, r.status >= 400 && r.status <= 499:
return offlinerun.Answer{Refused: true}
}
diff --git a/move_offline_run_test.go b/move_offline_run_test.go
index e72eb911d..fc0d7c809 100644
--- a/move_offline_run_test.go
+++ b/move_offline_run_test.go
@@ -694,3 +694,23 @@ func TestMoveOfflineStatusLeadsWithTheState(t *testing.T) {
}
}
}
+
+// TestMoveOfflineRunBindsTheMoveItsStageMade: the run is bound to the move
+// its stage's reply names, so a move someone else staged before the run's
+// next read is another move: exit 4, nothing sent for it.
+func TestMoveOfflineRunBindsTheMoveItsStageMade(t *testing.T) {
+ theirs := offView("offline-staging", frame{"id": "mv_theirs", "staged_at": 5})
+ c := &fakeOfflineConsole{
+ moveID: "mv_theirs", // the record's move, which the doors check ids against
+ gets: []frame{{"host": oHost, "state": "none"}, theirs},
+ posts: map[string][]offPost{"/stage": {{202, offView("offline-staging", frame{"staged_at": 4})}}},
+ }
+ code, out := runOfflineRun(t, c, runSeams{}, "--to", "uk")
+ if code != 4 {
+ t.Fatalf("exit %d:\n%s", code, out)
+ }
+ if got := doorsOf(c.postsSent()); got != "stage" {
+ t.Fatalf("doors %s:\n%s", got, out)
+ }
+ wantLines(t, out, "acme.shop.example.com now has a different move (mv_theirs). This run sent nothing for that move and stopped.")
+}