moves: offline run ends on a status refused for good, notes outages
Astra branch review round 1, finding 6 (P2). Once the move is under way, a status read the console refuses for good (401, 403, 404 or another 4xx but the rate limit's, or a console that moved) ends run with exit 1: the console's own sentence, then OR29 and the status command. Failures that may pass (no answer, 5xx, 429) are still ridden out silently, but after 2 minutes run says so once per outage (new OR71, pending) with the status command, and carries on.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
9 files changed,
+201
−5
approved_moves_copy_test.go+1 −1docs/drafts/offline-move-run/copy-review/strings-fix.json+8 −0docs/superpowers/plans/2026-10-06-moves-phase1-copy.md+1 −0internal/moves/offlinerun/decide.go+1 −0internal/moves/offlinerun/run.go+13 −0internal/moves/offlinerun/run_test.go+39 −0move_offline_run.go+61 −4move_offline_run_test.go+71 −0move_test.go+6 −0
Intent
diff --git a/approved_moves_copy_test.go b/approved_moves_copy_test.go| index 7a298d547..d73aa46ef 100644 |
| --- a/approved_moves_copy_test.go |
| +++ b/approved_moves_copy_test.go |
| @@ -129,7 +129,7 @@ var movesCopyIDs = []string{ |
| "OR60", "OR61", "OR62", "OR63", "OR65", "OR66", |
| // The fixes for Astra's branch review, round 1 (deck |
| // strings-fix.json beside strings.json; pending). |
| - "OR70", |
| + "OR70", "OR71", |
| } |
| // copyRow is one row of the record. The File cell is the file the sentence is |
diff --git a/docs/drafts/offline-move-run/copy-review/strings-fix.json b/docs/drafts/offline-move-run/copy-review/strings-fix.json| index 4a828410b..5aef60c51 100644 |
| --- a/docs/drafts/offline-move-run/copy-review/strings-fix.json |
| +++ b/docs/drafts/offline-move-run/copy-review/strings-fix.json |
| @@ -6,5 +6,13 @@ |
| "text": "Stopped. Nothing was sent.", |
| "context": "carlos move offline run, a Ctrl-C before run has sent anything: during its first status read, or while a rate limit holds up its first stage (no door took it). No move was staged. Exit 4. Astra branch review round 1, finding 2.", |
| "status": "pending" |
| + }, |
| + { |
| + "id": "OR71", |
| + "section": "run stops", |
| + "label": "No status for a while", |
| + "text": "No status from the console for %s. run keeps asking. To see where the move is, run:", |
| + "context": "carlos move offline run, once the move is under way: the status reads have failed in a way that may pass (no answer, a 5xx, the rate limit) for 2 minutes. Said once per outage; the next line is the status command (carlos move offline status --host <host>). %s is '2 min'. run sends nothing while it has no status, and goes on when the console answers. A refusal that will not pass (401, 403, 404) ends run instead, with exit 1: the console's own sentence, then OR29 and the status command. Astra branch review round 1, finding 6.", |
| + "status": "pending" |
| } |
| ] |
diff --git a/docs/superpowers/plans/2026-10-06-moves-phase1-copy.md b/docs/superpowers/plans/2026-10-06-moves-phase1-copy.md| index 9b1f0654a..b2ca9dbf6 100644 |
| --- a/docs/superpowers/plans/2026-10-06-moves-phase1-copy.md |
| +++ b/docs/superpowers/plans/2026-10-06-moves-phase1-copy.md |
| @@ -819,3 +819,4 @@ Sentences the fixes for Astra's whole-branch review of `offline-move-run` (round |
| | id | file | text | status | |
| |---|---|---|---| |
| | OR70 | move_offline_run.go | Stopped. Nothing was sent. | pending | |
| +| OR71 | move_offline_run.go | No status from the console for <duration>. run keeps asking. To see where the move is, run: | pending | |
diff --git a/internal/moves/offlinerun/decide.go b/internal/moves/offlinerun/decide.go| index 974b2b0f3..6584d8804 100644 |
| --- a/internal/moves/offlinerun/decide.go |
| +++ b/internal/moves/offlinerun/decide.go |
| @@ -50,6 +50,7 @@ const PhaseFailed = "failed" |
| // Exit codes Done carries, the CLI's own (move.go moveExit*). |
| const ( |
| ExitDone = 0 // the move finished, or stopped at open by --no-finish |
| + ExitError = 1 // the console refused the status read for good, mid-run |
| ExitAborted = 3 // the move was aborted and finished back where it was |
| ExitStopped = 4 // stopped; a human decides what comes next |
| ExitRefused = 5 // the console refused the first stage; nothing was written |
diff --git a/internal/moves/offlinerun/run.go b/internal/moves/offlinerun/run.go| index b0b400c67..c33de1891 100644 |
| --- a/internal/moves/offlinerun/run.go |
| +++ b/internal/moves/offlinerun/run.go |
| @@ -2,6 +2,7 @@ package offlinerun |
| import ( |
| "context" |
| + "errors" |
| "sync" |
| "time" |
| ) |
| @@ -17,6 +18,15 @@ const DefaultPoll = 2 * time.Second |
| // second before open, the first after it). The move itself goes on. |
| const ReasonStoppedWatching = "stopped-watching" |
| +// ErrStatusRefused is a status read the console refused for good: it will |
| +// not answer this run again (its token is no longer let in, or the console |
| +// does not know the host). Doors wrap it; Run ends the run with ExitError |
| +// and ReasonStatusRefused, since nothing can be decided without a view. |
| +var ErrStatusRefused = errors.New("the console refused the status read") |
| + |
| +// ReasonStatusRefused ends a run on ErrStatusRefused (exit 1). |
| +const ReasonStatusRefused = "status-refused" |
| + |
| // ReasonNothingSent ends a run stopped with Ctrl-C before it sent anything |
| // (exit 4): no move was staged. |
| const ReasonNothingSent = "nothing-sent" |
| @@ -285,6 +295,9 @@ func (r *Runner) Run(ctx context.Context, m Memory) (Done, Memory, error) { |
| switch { |
| case err != nil && !read: |
| return Done{}, m, err |
| + case errors.Is(err, ErrStatusRefused): |
| + // Later failures are ridden out; this one never ends. |
| + return Done{Exit: ExitError, Reason: ReasonStatusRefused}, m, nil |
| case err == nil: |
| read = true |
| } |
diff --git a/internal/moves/offlinerun/run_test.go b/internal/moves/offlinerun/run_test.go| index 470002d79..2f5489d46 100644 |
| --- a/internal/moves/offlinerun/run_test.go |
| +++ b/internal/moves/offlinerun/run_test.go |
| @@ -3,6 +3,7 @@ package offlinerun |
| import ( |
| "context" |
| "errors" |
| + "fmt" |
| "reflect" |
| "strings" |
| "testing" |
| @@ -407,3 +408,41 @@ func TestRunFirstStageUncertainNeverAdopts(t *testing.T) { |
| }) |
| } |
| } |
| + |
| +// TestRunStatusRefusedForGood (finding 6): a later status read the console |
| +// refuses for good (the Doors say ErrStatusRefused: a revoked token, a |
| +// console that no longer knows the host) ends the run with exit 1 and |
| +// nothing sent, rather than a silent wait for ever. Other failures are |
| +// still ridden out. |
| +func TestRunStatusRefusedForGood(t *testing.T) { |
| + d := &fakeDoors{views: []View{tv(StateSealing)}} |
| + gone := false |
| + r, _ := testRunner(&refusingDoors{fakeDoors: d, gone: &gone}, func() int { return 200 }) |
| + r.After = func(dd time.Duration) <-chan time.Time { |
| + gone = true |
| + c := make(chan time.Time, 1) |
| + c <- time.Time{} |
| + return c |
| + } |
| + done, _, err := r.Run(context.Background(), offline(StateSealing, 0)) |
| + if err != nil || done != (Done{Exit: ExitError, Reason: ReasonStatusRefused}) { |
| + t.Fatalf("done %#v, err %v", done, err) |
| + } |
| + if got := strings.Join(d.log, ","); got != "status,status" { |
| + t.Fatalf("calls %s", got) |
| + } |
| +} |
| + |
| +// refusingDoors answer every status read with ErrStatusRefused once gone. |
| +type refusingDoors struct { |
| + *fakeDoors |
| + gone *bool |
| +} |
| + |
| +func (r *refusingDoors) Status(ctx context.Context) (View, error) { |
| + v, err := r.fakeDoors.Status(ctx) |
| + if *r.gone { |
| + return View{}, fmt.Errorf("status: %w", ErrStatusRefused) |
| + } |
| + return v, err |
| +} |
diff --git a/move_offline_run.go b/move_offline_run.go| index 562cf85bc..1ecdb64d9 100644 |
| --- a/move_offline_run.go |
| +++ b/move_offline_run.go |
| @@ -157,11 +157,12 @@ func (m *mover) offlineRun(ctx context.Context, a moveArgs, d moveDeps) int { |
| ints := offlinerun.NewInterrupts() |
| w := &offlineRun{m: m, said: map[string]bool{}} |
| - doors := &runDoors{w: w, region: a.to, code: -1, ints: ints} |
| + doors := &runDoors{w: w, region: a.to, code: -1, ints: ints, downSince: -1} |
| start := now() |
| watch := &runWatcher{w: w, doors: doors, now: now, policy: policy, |
| resume: a.resume, bound: a.resume, url: "https://" + m.host + path} |
| watch.clock = func() time.Duration { return now().Sub(start) } |
| + doors.clock = watch.clock |
| r := &offlinerun.Runner{ |
| Doors: doors, |
| Probe: func(ctx context.Context) int { return probe(ctx, watch.url) }, |
| @@ -241,6 +242,45 @@ type runDoors struct { |
| code int // the exit code the first status read ended with, -1 for none |
| last offlineReply // the latest status view |
| reply moveReply // the latest POST's reply |
| + |
| + // A later status read's trouble (finding 6 of the branch review): gone |
| + // is the reply the console refused it with for good; downSince is when |
| + // the reads that may pass began failing (run's clock, -1 while they |
| + // answer), downSaid that the notice was said for this outage. |
| + clock func() time.Duration |
| + gone moveReply |
| + downSince time.Duration |
| + downSaid bool |
| +} |
| + |
| +// runStatusNotice is how long later status reads may fail before run says |
| +// so (once an outage). |
| +const runStatusNotice = 2 * time.Minute |
| + |
| +// refusedForGood says a later status read's reply will not change by |
| +// asking again: the console's token or member check says no (401, 403), |
| +// it does not know the host (404) or any other 4xx but the rate limit's, |
| +// or it has moved. Anything else (no answer, a 5xx, a 429) may pass. |
| +func refusedForGood(r moveReply) bool { |
| + if r.moved != "" { |
| + return true |
| + } |
| + return !r.failed && r.status >= 400 && r.status <= 499 && r.status != http.StatusTooManyRequests |
| +} |
| + |
| +// outage notes a later status read that may pass, and says the notice once |
| +// it has gone on for runStatusNotice. |
| +func (d *runDoors) outage() { |
| + now := d.clock() |
| + if d.downSince < 0 { |
| + d.downSince = now |
| + } |
| + if now-d.downSince >= runStatusNotice && !d.downSaid { |
| + d.downSaid = true |
| + out := d.w.m.out |
| + moveSay(out, fmt.Sprintf("No status from the console for %s. run keeps asking. To see where the move is, run:", runDuration(runStatusNotice))) |
| + sayRunCommand(out, "status", d.w.m.host) |
| + } |
| } |
| // wait is one interval between calls (the mover's, 10 s once limited), |
| @@ -322,11 +362,23 @@ func (d *runDoors) Status(ctx context.Context) (offlinerun.View, error) { |
| return offlinerun.View{}, errRunStatus |
| } |
| } else { |
| - // Later ones are ridden out by the loop, silently: the move is |
| - // under way and only a view decides anything. |
| - if r, _ = d.get(ctx); r.failed || r.moved != "" || r.status != http.StatusOK { |
| + // Later ones are ridden out by the loop: the move is under way |
| + // and only a view decides anything. One the console refuses for |
| + // good ends the run; the rest are silent, until they have gone on |
| + // long enough to say so once. |
| + var interrupted bool |
| + r, interrupted = d.get(ctx) |
| + switch { |
| + case interrupted: |
| + return offlinerun.View{}, errRunStatus |
| + case refusedForGood(r): |
| + d.gone = r |
| + return offlinerun.View{}, fmt.Errorf("%w: %d", offlinerun.ErrStatusRefused, r.status) |
| + case r.failed || r.status != http.StatusOK: |
| + d.outage() |
| return offlinerun.View{}, errRunStatus |
| } |
| + d.downSince, d.downSaid = -1, false |
| } |
| var full offlineView |
| var v offlinerun.View |
| @@ -684,6 +736,11 @@ func (rw *runWatcher) end(d offlinerun.Done) int { |
| rw.w.headline(r) |
| case offlinerun.ReasonStoppedWatching, offlinerun.ReasonNothingSent: |
| // said at the Ctrl-C |
| + case offlinerun.ReasonStatusRefused: |
| + // The console's own sentence for it, then where to look. |
| + rw.w.m.sayReply(rw.doors.gone) |
| + moveSay(rw.out(), "Stopped watching. The move is still running. To see where it is, run:") |
| + sayRunCommand(rw.out(), "status", host) |
| } |
| return d.Exit |
| } |
diff --git a/move_offline_run_test.go b/move_offline_run_test.go| index 42d7c0b9a..34d34c2ea 100644 |
| --- a/move_offline_run_test.go |
| +++ b/move_offline_run_test.go |
| @@ -50,6 +50,9 @@ type offlineSim struct { |
| onLimit func() |
| // onDrop runs as a reply is thrown away (drop). |
| onDrop func() |
| + // getFault, when set, may answer a status read itself (ok true) with |
| + // a code and a body, before the boxes tick. |
| + getFault func(s *offlineSim) (code int, body frame, ok bool) |
| } |
| const simEpoch = int64(1794724320) // 2026-11-15T06:32:00Z |
| @@ -945,3 +948,71 @@ func TestMoveOfflineRunLogStandsAlone(t *testing.T) { |
| t.Fatalf("doors %s", got) |
| } |
| } |
| + |
| +// TestMoveOfflineRunStatusRefusedForGood (finding 6): once the move is |
| +// under way, a status read the console refuses for good (a token it no |
| +// longer lets in, a host it does not know) ends the run with exit 1: the |
| +// console's own sentence, then OR29 and the status command. Nothing is |
| +// sent after it. |
| +func TestMoveOfflineRunStatusRefusedForGood(t *testing.T) { |
| + for _, c := range []struct { |
| + name string |
| + code int |
| + body frame |
| + say string |
| + }{ |
| + {"token revoked", http.StatusUnauthorized, frame{"error": "this token is no longer valid. run carlos auth login"}, "this token is no longer valid. run carlos auth login"}, |
| + {"not allowed", http.StatusForbidden, frame{"error": "operators only"}, "operators only"}, |
| + {"host unknown", http.StatusNotFound, frame{}, "Not found. Check --account and --app, and that you are a member of the instance's account."}, |
| + } { |
| + t.Run(c.name, func(t *testing.T) { |
| + sim := &offlineSim{holdIn: "offline-sealing", getFault: func(s *offlineSim) (int, frame, bool) { |
| + return c.code, c.body, s.state == "offline-sealing" |
| + }} |
| + f := &fakeOfflineConsole{sim: sim} |
| + code, out := runOfflineRun(t, f, runSeams{}, "--to", "uk") |
| + if code != 1 { |
| + t.Fatalf("exit %d:\n%s", code, out) |
| + } |
| + if got := doorsOf(f.postsSent()); got != "stage,start,seal" { |
| + t.Fatalf("doors %s:\n%s", got, out) |
| + } |
| + if !strings.HasSuffix(out, c.say+"\n"+ |
| + "Stopped watching. The move is still running. To see where it is, run:\n"+ |
| + " carlos move offline status --host acme.shop.example.com\n") { |
| + t.Fatalf("output:\n%s", out) |
| + } |
| + }) |
| + } |
| +} |
| + |
| +// TestMoveOfflineRunStatusOutageNotice (finding 6): failures that may pass |
| +// (no answer, a 5xx, a 429) are ridden out silently, but after 2 minutes |
| +// without a status run says so once, with the status command, and goes on. |
| +func TestMoveOfflineRunStatusOutageNotice(t *testing.T) { |
| + failures := 0 |
| + sim := &offlineSim{getFault: func(s *offlineSim) (int, frame, bool) { |
| + if s.state == "offline-stopping" && failures < 70 { |
| + failures++ |
| + if failures%2 == 0 { |
| + return http.StatusTooManyRequests, frame{"error": "too many requests"}, true |
| + } |
| + return http.StatusBadGateway, frame{"error": "could not read the instance"}, true |
| + } |
| + return 0, nil, false |
| + }} |
| + c := &fakeOfflineConsole{sim: sim} |
| + code, out := runOfflineRun(t, c, runSeams{}, "--to", "uk") |
| + if code != 0 { |
| + t.Fatalf("exit %d:\n%s", code, out) |
| + } |
| + notice := "No status from the console for 2 min. run keeps asking. To see where the move is, run:\n" + |
| + " carlos move offline status --host acme.shop.example.com\n" |
| + if strings.Count(out, notice) != 1 { |
| + t.Fatalf("want the notice once:\n%s", out) |
| + } |
| + wantLines(t, out, orMoved) |
| + if strings.Contains(out, "could not read the instance") { |
| + t.Fatalf("a passing failure was said:\n%s", out) |
| + } |
| +} |
diff --git a/move_test.go b/move_test.go| index 1bf3c89c9..0f3394026 100644 |
| --- a/move_test.go |
| +++ b/move_test.go |
| @@ -1154,6 +1154,12 @@ func (c *fakeOfflineConsole) ServeHTTP(w http.ResponseWriter, r *http.Request) { |
| write(http.StatusTooManyRequests, frame{"error": "too many requests"}) |
| return |
| } |
| + if c.sim.getFault != nil { |
| + if code, body, ok := c.sim.getFault(c.sim); ok { |
| + write(code, body) |
| + return |
| + } |
| + } |
| c.i++ |
| v := c.sim.get() |
| if c.sim.onGet != nil { |