carlos / platform Public

moves: offlinerun.Decide exits 5 on a refused first stage

From the Task 0 rehearsal: when the first stage POST gets a non-2xx
answer and the follow-up status read shows no move, the run ends with
exit 5 and the console's refusal sentence as the reason. Nothing is
bound, nothing to abort, no retry.

The caller hands the refusal in with Memory.Refused(sentence); the
next Decide consumes it. A POST lost on the network is not a refusal
and still ends as stage-not-written, exit 4. A refused POST whose
follow-up read shows the move after all is decided by the view.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 21ab789c3667af67d97b329b4238b3065a035dfd parent 1b42836
2 files changed, +54 −0
  • internal/moves/offlinerun/decide.go +24 −0
  • internal/moves/offlinerun/decide_test.go +30 −0

CI passed — run details

diff --git a/internal/moves/offlinerun/decide.go b/internal/moves/offlinerun/decide.go
index 94a03a180..27897ffa4 100644
--- a/internal/moves/offlinerun/decide.go
+++ b/internal/moves/offlinerun/decide.go
@@ -52,6 +52,7 @@ const (
ExitDone = 0 // the move finished, or stopped at open by --no-finish
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
)
// Reasons are short codes for the log line and for tests. They are not
@@ -223,6 +224,11 @@ type Memory struct {
opened bool // open (or finishing) was read
probeOK bool // the probe answered 2xx
+
+ // refused: the last POST got a non-2xx answer from the console, which
+ // said refusal. Set by Refused, consumed by the next Decide.
+ refused bool
+ refusal string
}
// NewMemory is a fresh run's memory. resume is --resume's move id, bound
@@ -240,6 +246,18 @@ func (m Memory) Probed(ok bool) Memory {
return m
}
+// Refused records that the POST just made got a non-2xx answer from the
+// console, with the console's sentence (may be empty). Call it before the
+// follow-up status read's Decide; a POST lost on the network is not a
+// refusal and does not call it. Decide consumes it on its next call: when
+// that view shows no move and nothing is bound after our first stage, the
+// run ends with ExitRefused and the sentence as Reason. Otherwise the view
+// decides, as for any POST that was not a clean 2xx.
+func (m Memory) Refused(sentence string) Memory {
+ m.refused, m.refusal = true, sentence
+ return m
+}
+
// Abort asks for an abort (the first Ctrl-C). Before open it is sticky:
// Decide posts abort until the view is reverting or open. After open it is
// ignored; nothing aborts an opened move.
@@ -330,10 +348,16 @@ func (m Memory) observe(v View, now time.Duration) Memory {
// - after open nothing aborts; a probe with no 2xx stops with exit 4;
// - a wait with no change for NudgeAfter nudges, then every NudgeEvery.
func Decide(v View, p Policy, m Memory, now time.Duration) (Action, Memory) {
+ refused, refusal := m.refused, m.refusal
+ m.refused, m.refusal = false, ""
m = m.observe(v, now)
if v.State == StateNone {
switch {
+ case m.id == "" && m.stagePosts > 0 && refused:
+ // The console refused our stage and no move exists: nothing
+ // is bound and nothing to abort. Its sentence is the reason.
+ return Done{Exit: ExitRefused, Reason: refusal}, m
case m.id == "" && m.stagePosts > 0:
// The view after our stage POST is authoritative: nothing was
// written (refused, or lost before the console committed it).
diff --git a/internal/moves/offlinerun/decide_test.go b/internal/moves/offlinerun/decide_test.go
index 0d84bc06b..3dbc275f9 100644
--- a/internal/moves/offlinerun/decide_test.go
+++ b/internal/moves/offlinerun/decide_test.go
@@ -99,6 +99,12 @@ func TestDecideTable(t *testing.T) {
{"no move, last is ours and aborted: exit 3", bound(StateReverting, 0), none(&Outcome{ID: tID, Outcome: OutcomeAborted}), at(1), Done{Exit: ExitAborted, Reason: ReasonAborted}},
{"no move, last is another's: stop", bound(StateFinishing, 0), none(&Outcome{ID: tOther, Outcome: OutcomeDone}), at(1), Done{Exit: ExitStopped, Reason: ReasonMoveGone}},
{"a move on the host, nothing bound, no --resume: stop", NewMemory(""), staging(5, true, 0), 0, Done{Exit: ExitStopped, Reason: ReasonHostHasMove}},
+ {"first stage refused, no move: exit 5 with the console's sentence", func() Memory {
+ m := NewMemory("")
+ m.stagePosts = 1
+ return m.Refused("another move is in flight. try again shortly")
+ }(), none(nil), at(2), Done{Exit: ExitRefused, Reason: "another move is in flight. try again shortly"}},
+ {"first stage refused with an old move's outcome: exit 5", func() Memory { m := NewMemory(""); m.stagePosts = 1; return m.Refused("refused") }(), none(&Outcome{ID: tOther, Outcome: OutcomeDone}), at(2), Done{Exit: ExitRefused, Reason: "refused"}},
{"our stage wrote nothing: stop", func() Memory { m := NewMemory(""); m.stagePosts = 1; return m }(), none(nil), at(2), Done{Exit: ExitStopped, Reason: ReasonStageNotWritten}},
{"a state this glue does not know: stop", bound(StateStaging, 0), tv("offline-somethingnew"), at(1), Done{Exit: ExitStopped, Reason: ReasonUnexpectedState}},
}
@@ -377,3 +383,27 @@ func TestDecideNamesMatchProvision(t *testing.T) {
}
}
}
+
+// TestDecideStageRefused: a refused first stage ends the run with exit 5
+// and the console's sentence, with no retry; the refusal is consumed by
+// the next Decide, so it never colours a later tick.
+func TestDecideStageRefused(t *testing.T) {
+ p := DefaultPolicy()
+ m := play(t, p, NewMemory(""), []step{{0, none(nil), Post{Verb: VerbStage}}})
+ got, _ := Decide(none(nil), p, m.Refused("the instance is not in a region"), at(2))
+ if want := (Done{Exit: ExitRefused, Reason: "the instance is not in a region"}); got != Action(want) {
+ t.Fatalf("Decide = %#v, want %#v", got, want)
+ }
+ // A refused POST whose follow-up read shows the move after all (a
+ // committed write answered with an error): the view wins, no exit 5.
+ m2 := play(t, p, NewMemory(""), []step{{0, none(nil), Post{Verb: VerbStage}}})
+ got, m2 = Decide(staging(5, false, 0), p, m2.Refused("timeout"), at(2))
+ if got != Action(Wait{}) {
+ t.Fatalf("Decide = %#v, want Wait", got)
+ }
+ // The refusal was consumed: a later none reads as the move gone.
+ got, _ = Decide(none(nil), p, m2, at(4))
+ if want := (Done{Exit: ExitStopped, Reason: ReasonMoveGone}); got != Action(want) {
+ t.Fatalf("Decide = %#v, want %#v", got, want)
+ }
+}