carlos / platform Public

console: offline doors refuse a different move id (Task 3)

Stage, start, seal, flip, open, finish and abort take an optional "id"
in their body. Another move's id answers 409 with MV-O35 ("the record
carries a different offline move"), an id with no move in flight MV-O24,
and nothing is written. No id, or the move's own id, is answered as
before (plan 2026-11-15-offline-move-run, Task 3).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 775fed4e96922862e615a2bf3c1b95b8059ba6c4 parent 21ab789
2 files changed, +161 −3
  • internal/console/apiinstancemove_offline.go +41 −3
  • internal/console/apiinstancemove_offline_test.go +120 −0
diff --git a/internal/console/apiinstancemove_offline.go b/internal/console/apiinstancemove_offline.go
index fc2a82c57..02b93a7ed 100644
--- a/internal/console/apiinstancemove_offline.go
+++ b/internal/console/apiinstancemove_offline.go
@@ -41,7 +41,9 @@ import (
// Every door is moveOperatorGate (the byte-identical 404 for anyone but an
// operator's own CLI token), then MV-O20 when this console runs host claims
// or Phase 1 moves, then its own checks, then exactly one SetRecordMove
-// transition and a serial bump, and answers 202 with the status view.
+// transition and a serial bump, and answers 202 with the status view. A
+// door that acts on a move takes the id of the move its caller expects as an
+// optional "id" member of its body, and refuses any other (offlineMoveIs).
//
// The doors decide from evidence the console reads and never from what the
// operator says: the record, the edges files, the boxes' status reports and
@@ -119,6 +121,38 @@ func (s *Server) offlineInFlight(w http.ResponseWriter, d offlineDoor) (*provisi
return d.rec.Move, true
}
+// offlineMoveIs refuses a request that expects a move the record does not
+// carry (plan 2026-11-15-offline-move-run, Task 3): MV-O24 when it carries
+// no offline move, MV-O35 when it carries another. An empty id expects
+// nothing, and the door goes on as it did before ids.
+func (s *Server) offlineMoveIs(w http.ResponseWriter, d offlineDoor, id string) bool {
+ if id == "" {
+ return true
+ }
+ mv, ok := s.offlineInFlight(w, d)
+ if !ok {
+ return false
+ }
+ if mv.ID != id {
+ jsonError(w, http.StatusConflict, "the record carries a different offline move")
+ return false
+ }
+ return true
+}
+
+// offlineExpects reads the id of the move a verb's caller expects, when it
+// sends one, and refuses it as offlineMoveIs does. A request with no body,
+// or none with an id in it, is answered as before.
+func (s *Server) offlineExpects(w http.ResponseWriter, r *http.Request, d offlineDoor) bool {
+ var req struct {
+ ID string `json:"id"`
+ }
+ if !readJSONAllowEmpty(w, r, &req) {
+ return false
+ }
+ return s.offlineMoveIs(w, d, req.ID)
+}
+
// offlineStateRefusal is MV-O25.
func offlineStateRefusal(state, host string) *offlineRefusal {
return &offlineRefusal{status: http.StatusConflict, msg: fmt.Sprintf("this move is %s. run carlos move offline status --host %s to see what it waits for", state, host)}
@@ -576,10 +610,14 @@ func (s *Server) offlineBeginChecks(w http.ResponseWriter, r *http.Request, d of
}
var req struct {
Region string `json:"region"`
+ ID string `json:"id"`
}
if !readJSON(w, r, &req) {
return "", offlineFleet{}, false
}
+ if !s.offlineMoveIs(w, d, req.ID) {
+ return "", offlineFleet{}, false
+ }
region := strings.TrimSpace(req.Region)
to := s.homeRegionIn(region)
if region == "" || !provision.ValidRegion(to) {
@@ -1273,7 +1311,7 @@ func (s *Server) offlineVerbDoor(verb string) http.HandlerFunc {
return
}
mv, ok := s.offlineInFlight(w, d)
- if !ok {
+ if !ok || !s.offlineExpects(w, r, d) {
return
}
if offlineVerbOf(mv.State) != verb {
@@ -1302,7 +1340,7 @@ func (s *Server) handleAPIInstanceOfflineAbort(w http.ResponseWriter, r *http.Re
return
}
mv, ok := s.offlineInFlight(w, d)
- if !ok {
+ if !ok || !s.offlineExpects(w, r, d) {
return
}
switch mv.State {
diff --git a/internal/console/apiinstancemove_offline_test.go b/internal/console/apiinstancemove_offline_test.go
index 6f8d15261..64da11a4c 100644
--- a/internal/console/apiinstancemove_offline_test.go
+++ b/internal/console/apiinstancemove_offline_test.go
@@ -2,6 +2,7 @@ package console
import (
"context"
+ "crypto/rand"
"crypto/sha256"
"encoding/hex"
"encoding/json"
@@ -1591,3 +1592,122 @@ func TestOfflineStartKeepsTheLockWhenTheRecordWriteFails(t *testing.T) {
})
}
}
+
+// otherMoveID is a move id no record in these worlds carries.
+func otherMoveID(t *testing.T) string {
+ t.Helper()
+ id, err := moves.NewMoveID(rand.Reader)
+ if err != nil {
+ t.Fatal(err)
+ }
+ return id
+}
+
+// withID is a door's JSON body: its own members and, when id is not empty,
+// the move id the caller expects.
+func withID(members, id string) string {
+ if id != "" {
+ if members != "" {
+ members += ","
+ }
+ members += `"id":"` + id + `"`
+ }
+ return "{" + members + "}"
+}
+
+// Every door that acts on a move takes the id of the move its caller expects
+// (plan 2026-11-15-offline-move-run, Task 3). Another move's id is refused
+// with the record's own sentence (MV-O35) and nothing written: not the
+// record, its record_seq, the serial or the lock. The move's own id is the
+// request with no id.
+func TestOfflineDoorsRefuseAnotherMovesID(t *testing.T) {
+ for _, tc := range []struct {
+ name, path, members string
+ setup func(w *offlineWorld)
+ want string // the state the move's own id leaves
+ }{
+ {"stage again", "/stage", `"region":"uk"`, func(w *offlineWorld) { w.stage() }, provision.OfflineStaging},
+ {"start a staged move", "", `"region":"uk"`, func(w *offlineWorld) { w.stage() }, provision.OfflineStopping},
+ {"seal", "/seal", "", func(w *offlineWorld) {
+ w.start()
+ w.stopped(nil, "ie-box")
+ }, provision.OfflineSealing},
+ {"flip", "/flip", "", func(w *offlineWorld) {
+ w.start()
+ w.stopped(nil, "ie-box")
+ w.ok("/seal", "", provision.OfflineSealing)
+ w.sealed("ie-box")
+ w.sealerFresh("ie-box")
+ w.stopped(nil, "ie-box")
+ }, provision.OfflineLanding},
+ {"open", "/open", "", func(w *offlineWorld) { w.toLanded() }, provision.OfflineOpen},
+ {"finish", "/finish", "", func(w *offlineWorld) {
+ w.start()
+ w.ok("/abort", "", provision.OfflineReverting)
+ w.report(moves.OfflineRoleSource, "ie-box", moves.OfflinePhaseReverted, nil)
+ }, "none"},
+ {"abort", "/abort", "", func(w *offlineWorld) { w.start() }, provision.OfflineReverting},
+ } {
+ t.Run(tc.name, func(t *testing.T) {
+ w := newOfflineWorld(t, oneEach...)
+ tc.setup(w)
+ seq := w.record().RecordSeq
+ w.refused(http.MethodPost, tc.path, withID(tc.members, otherMoveID(t)), http.StatusConflict, "the record carries a different offline move")
+ if got := w.record().RecordSeq; got != seq {
+ t.Fatalf("record_seq %d after a refused id, want %d", got, seq)
+ }
+ w.ok(tc.path, withID(tc.members, w.id), tc.want)
+ })
+ }
+}
+
+// An id on a record with no offline move expects a move that is not there:
+// MV-O24, as the verbs answer it with no id, and nothing written. The stage
+// and start doors, which begin a move when none is in flight, begin none.
+func TestOfflineDoorsRefuseAnIDWithNoMove(t *testing.T) {
+ w := newOfflineWorld(t, oneEach...)
+ id := otherMoveID(t)
+ for _, rt := range offlineRoutes {
+ if rt.method != http.MethodPost {
+ continue
+ }
+ w.refused(rt.method, rt.path, withID(strings.Trim(rt.body, "{}"), id), http.StatusConflict, offlineHost+" has no offline move in flight")
+ }
+ if rec := w.record(); rec.Move != nil {
+ t.Fatalf("a refused id began a move: %+v", rec.Move)
+ }
+}
+
+// The move's own id, and no id at all, are answered with the same bytes:
+// refusals in the state each door does not act on, and the abort that finds
+// the move already reverting. Nothing is written by any of them.
+func TestOfflineDoorsTheMovesOwnIDIsNoID(t *testing.T) {
+ w := newOfflineWorld(t, oneEach...)
+ w.start()
+ same := func(path, members string) {
+ t.Helper()
+ before := bucketState(t, w.fx.rel)
+ bodies := []string{withID(members, ""), withID(members, w.id)}
+ if members == "" {
+ bodies = append(bodies, "") // the verbs have never needed a body
+ }
+ code0, out0 := w.req(http.MethodPost, path, bodies[0])
+ for _, body := range bodies[1:] {
+ if code, out := w.req(http.MethodPost, path, body); code != code0 || out != out0 {
+ t.Fatalf("POST %s %q = %d %s\nwant %d %s", path, body, code, out, code0, out0)
+ }
+ }
+ if after := bucketState(t, w.fx.rel); fmt.Sprint(after) != fmt.Sprint(before) {
+ t.Fatalf("POST %s changed the bucket", path)
+ }
+ }
+ // offline-stopping with no box report yet: every door but abort refuses.
+ same("/stage", `"region":"uk"`)
+ same("", `"region":"uk"`)
+ for _, verb := range []string{"/seal", "/flip", "/open", "/finish"} {
+ same(verb, "")
+ }
+ // Already reverting: abort answers the view and writes nothing.
+ w.ok("/abort", "", provision.OfflineReverting)
+ same("/abort", "")
+}