roll tool: return a failed drain's member only on proof no move runs
Branch review r2, Astra B2.1/B2.2 (the r1 uncertain-drain family; cut per stopping rule 2). After a failed drain the tool exits Standby only when the agent's status is known and shows no running move of this transaction: unknown or malformed status keeps the member in Standby, the transaction open, and cancel-drain then return. A remote exit 124 (the verb's timeout) is now Uncertain, so the session reruns and joins the move instead of failing the drain. B2.3: the §25.10 example counts two sweeps per replacement. Tests: unknown status with a running move (stays in Standby; cancel and return); a framed 124 through the real parser, rerun joins.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
docs/superpowers/specs/2026-10-26-region-ha-without-claims-design.md+2 −2scripts/region-group-roll.py+16 −9scripts/region_group_held_test.py+57 −2
CI failed — run details
Intent
<task-notification> <task-id>binxfl06e</task-id> <tool-use-id>toolu_0193PxG5hh5iry5SPcQfS7Zo</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/a99cbe46-f458-4f72-8b8a-294aae9cdf21/tasks/binxfl06e.output</output-file> <status>completed</status> <summary>Background command "Astra branch review round 2" completed (exit code 0)</summary> </task-notification>
Attributed to this commit: 14.1 g CO₂e (1,495,777 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on region-ha-held-build, never backward from it. A turn that produced more than one commit books all of its tokens to the last one, and a concurrent session on this branch can add to the same figure. Some of it was priced using the shared default rate, because no model-specific factor row exists yet for at least one model involved. The Carbon view has the repo total, which is never derived from this attribution.
diff --git a/docs/superpowers/specs/2026-10-26-region-ha-without-claims-design.md b/docs/superpowers/specs/2026-10-26-region-ha-without-claims-design.md| index ed1c77e34..550e974cc 100644 |
| --- a/docs/superpowers/specs/2026-10-26-region-ha-without-claims-design.md |
| +++ b/docs/superpowers/specs/2026-10-26-region-ha-without-claims-design.md |
| @@ -1155,7 +1155,7 @@ The roll tool gains `replace` and `remove` transactions beside `roll`. All three |
| 1. Preflight: the roll's shape checks (`scripts/region-group-roll.py:917-942`) and the floor (§25.9). |
| 2. Lower minimum by one, then `EnterStandby` of A with decrement, then verify A is deregistered from both target groups, as the roll does today (H4). |
| -3. `drain` (§25.4). A session that drops is run again, up to three sessions in all; a rerun joins the move step the agent reports running or done for the transaction. A failed drain stops the transaction: the tool exits Standby and restores the shape, and A stays draining until `drain --cancel`. If A's agent still runs that move step, the tool does not exit Standby: it stops, the operator runs `cancel-drain`, then `return` (build ruling, 2026-11-09). |
| +3. `drain` (§25.4). A session that drops is run again, up to three sessions in all; a rerun joins the move step the agent reports running or done for the transaction. A failed drain stops the transaction: the tool exits Standby and restores the shape, and A stays draining until `drain --cancel`. If A's agent still runs that move step, or its status cannot say, the tool does not exit Standby: it stops, the operator runs `cancel-drain`, then `return` (build ruling, 2026-11-09). |
| 4. Re-read every lock in the region's data bucket that names A. Each must be a marker or have another owner. Read A's drain report again and check its incarnation (H5). |
| 5. The action: |
| - **roll:** `apply`, which restarts the edge with nothing awake, then ExitStandby and restore minimum, as today. The restarted agent is not draining. Its markers name it, but the hosts are held elsewhere; |
| @@ -1212,7 +1212,7 @@ A drain is only safe when every box that may send A a request understands the ne |
| - two acknowledgement rounds, each costing one fold read per live box (one LIST plus one GET per edges file, as at any fold). A failed fold read is retried at the 5 s cadence, so the worst case is 24 fold reads per box per round. The change-index fold that the publication triggers anyway is separate; |
| - the tool's lock check (the sweep): one delimited LIST of the lock prefix (one page per 1,000 hosts), then for each host under it, HA or not, one exact-key LIST and one GET when its `lock.json` exists. A replace or remove sweeps twice, before the action check and again after the edge stops; a resumed or retried stop sweeps again. Per transaction only, never on a timer. |
| - **Per host moved:** the marker PUT, as at any sleep, plus the successor's acquire (1 GET + 1 PUT) and restore, which the host's next wake would have cost anyway. |
| -- **Example:** replacing all 4 members of a region with 200 awake hosts, some moved twice, costs about 300 markers and acquires, 8 edges mutations, 8 acknowledgement rounds over 6 boxes, and 4 lock sweeps of 500 hosts. That is about $0.01 in S3 requests, plus the restore GETs. |
| +- **Example:** replacing all 4 members of a region with 200 awake hosts, some moved twice, costs about 300 markers and acquires, 8 edges mutations, 8 acknowledgement rounds over 6 boxes, and 8 lock sweeps (two per replacement) of 500 hosts, each about one LIST and one GET per host. That is about $0.03 in S3 requests, plus retries and the restore GETs. |
| **Simulation (§21.1).** It adds: |
| - Standby and drains; |
diff --git a/scripts/region-group-roll.py b/scripts/region-group-roll.py| index b4a8e12ab..00b4b52ae 100755 |
| --- a/scripts/region-group-roll.py |
| +++ b/scripts/region-group-roll.py |
| @@ -191,7 +191,7 @@ TEXT = { |
| "drain_cancel": "The member stays fenced and draining. To end it, run: region-group-roll.py cancel-drain --member {iid} --transaction {transaction}", |
| "drain_reason": "drain: {reason}", |
| "drain_report": "The drain printed no valid report for this transaction", |
| - "drain_moving": "The member's agent still runs this transaction's drain. The member stays in Standby. Run: region-group-roll.py cancel-drain --member {iid} --transaction {transaction}, then: region-group-roll.py return --transaction {transaction}", |
| + "drain_moving": "The member's agent still runs this transaction's drain, or did not say whether it does. The member stays in Standby. Run: region-group-roll.py cancel-drain --member {iid} --transaction {transaction}, then: region-group-roll.py return --transaction {transaction}", |
| "fence_missing": "The start fence of this transaction is not in place", |
| "drain_void": "The agent does not report a finished drain of this transaction", |
| "incarnation": "The agent's incarnation changed after the drain", |
| @@ -1101,7 +1101,11 @@ class AWS: |
| @staticmethod |
| def drain_output(body, code): |
| # The verb prints its report as one JSON line, and exits 0 only when |
| - # the report's result is ok. A refusal prints no report. |
| + # the report's result is ok. A refusal prints no report. 124 is the |
| + # remote timeout's: the verb was killed, the agent's drain goes on, |
| + # so the outcome is unknown and a rerun joins it (Astra r2 B2.2). |
| + if code == "124": |
| + raise Uncertain(TEXT["remote"], timeout=True) |
| require(code in ("0", "1") and len(body.encode()) <= 1024 * 1024, "remote") |
| report = None |
| for line in body.splitlines(): |
| @@ -1812,17 +1816,20 @@ class Operator: |
| observed["describe_error" if action == "describe" else "operation_error"] = True |
| def refuse_while_moving(self, status): |
| - """Never ExitStandby a failed drain's member whose agent still runs |
| - that drain's move step: it would finish InService, publish ha_drained |
| - and refuse its traffic. The operator cancels the drain, then resumes |
| - the return (branch review r1, Fable B1.2 c). A move that ended, ok or |
| - not, returns fenced and draining as before (section 25.4 failures).""" |
| + """Never ExitStandby a failed drain's member unless its agent shows |
| + that no move step of this drain runs: a running move would finish |
| + InService, publish ha_drained and refuse its traffic. Unknown or |
| + malformed drain status proves nothing, so it refuses too (Fable r1 |
| + B1.2 c; Astra r2 B2.1). The operator cancels the drain, then resumes |
| + the return. A move known to have ended, ok or not, returns fenced |
| + and draining as before (section 25.4 failures).""" |
| h = self.header |
| if not self.unchanged() or self.j.last("exit-intent"): |
| return |
| d = status.get("drain") if isinstance(status.get("drain"), dict) else {} |
| - if not (d.get("transaction") == h["transaction"] and d.get("step") == "move" and |
| - d.get("result") == "running"): |
| + running = d.get("transaction") == h["transaction"] and d.get("step") == "move" and \ |
| + d.get("result") == "running" |
| + if d.get("state") == "known" and not running: |
| return |
| self.event("return-refused-moving", drain=d) |
| message = TEXT["drain_moving"].format(iid=h["iid"], transaction=h["transaction"]) |
diff --git a/scripts/region_group_held_test.py b/scripts/region_group_held_test.py| index 7d9335a10..689ca744f 100644 |
| --- a/scripts/region_group_held_test.py |
| +++ b/scripts/region_group_held_test.py |
| @@ -134,6 +134,14 @@ class HeldFake(base.Fake): |
| assert self.desired == self.minimum == self.maximum - 1 |
| if self.drain_mode == "uncertain": |
| raise roll.Uncertain("drain") |
| + if self.drain_mode == "remote-timeout" and not getattr(self, "drain_calls", 0): |
| + # The first session's remote bound kills the verb (framed exit |
| + # 124, through the real parser); the agent's move goes on. |
| + self.drain_calls = 1 |
| + self.fence = a["transaction"] |
| + self.drain_state = dict(state="known", incarnation=self.incarnation, transaction=a["transaction"], |
| + step="move", result="running", error=None) |
| + return roll.AWS.drain_output("", "124") |
| self.drain_calls = getattr(self, "drain_calls", 0) + 1 |
| if self.drain_mode in ("drop-once", "drop-running", "drop-done"): |
| # The session drops; the agent's move step goes on. |
| @@ -144,7 +152,7 @@ class HeldFake(base.Fake): |
| step="move", result=result, error=None) |
| if self.drain_mode != "drop-once" or self.drain_calls == 1: |
| raise roll.Uncertain("drain") |
| - tx, ok = a["transaction"], self.drain_mode in ("ok", "drop-once") |
| + tx, ok = a["transaction"], self.drain_mode in ("ok", "drop-once", "remote-timeout") |
| assert self.fence in (None, tx) |
| self.fence = tx |
| self.drain_state = dict(state="known", incarnation=self.incarnation, transaction=tx, step="move", |
| @@ -537,6 +545,50 @@ class ReplaceTests(HeldBase): |
| self.assertIsNone(self.fake.fence) |
| self.assertIsNone(self.store.active_id()) |
| + def test_remote_timeout_reruns_and_joins(self): |
| + # Astra r2 B2.2: the remote bound's exit 124 is not a failed drain. |
| + self.fake.drain_mode = "remote-timeout" |
| + self.depart() |
| + self.assertEqual(self.fake.states[IID], "Terminated") |
| + self.assertEqual(self.fake.drain_calls, 2) |
| + with self.journal() as journal: |
| + self.assertEqual(journal.last("drain-uncertain")["attempt"], 1) |
| + self.assertIsNone(journal.last("drain-failed")) |
| + |
| + def test_unknown_drain_status_never_returns_the_member(self): |
| + # Astra r2 B2.1: every session drops while the move runs, and status |
| + # cannot reach the agent: unknown is not proof the move ended. |
| + self.fake.drain_mode = "drop-running" |
| + status = self.fake.session |
| + |
| + def unknown(a): |
| + r = status(a) |
| + if a["verb"] == "status" and a["iid"] == IID: |
| + r = dict(r, drain=dict(state="unknown", incarnation=None, transaction=None, step=None, |
| + result=None, error="context deadline exceeded")) |
| + return r |
| + self.fake.session = unknown |
| + with self.assertRaises(roll.DrainMoving): |
| + self.depart() |
| + self.assertEqual(self.fake.states[IID], "Standby") |
| + self.assertNotIn("exit", self.verbs()) |
| + self.assertEqual(self.store.active_id(), "t6-held") |
| + with self.journal() as journal: |
| + self.assertEqual(journal.last("return-refused-moving")["drain"]["state"], "unknown") |
| + # cancel-drain is admitted on the stopped transaction; then return. |
| + self.fake.session = status |
| + with self.store.lock(): |
| + op = self.engine() |
| + try: |
| + op.cancel_drain(IID, "t6-held") |
| + finally: |
| + op.j.close() |
| + with self.assertRaises(roll.Refusal) as caught: |
| + self.resume() |
| + self.assertEqual(str(caught.exception), roll.TEXT["drain_failed"]) |
| + self.assertEqual(self.fake.states[IID], "InService") |
| + self.assertIsNone(self.store.active_id()) |
| + |
| def test_dropped_sessions_after_a_finished_move_return_fenced(self): |
| # The move finished but no session brought its report back: the |
| # member returns fenced and draining, as after any failed drain. |
| @@ -1324,9 +1376,12 @@ class RemoteCommandTests(unittest.TestCase): |
| self.assertEqual(roll.AWS.drain_output(failed, "1")["report"]["result"], "failed") |
| self.assertEqual(roll.AWS.drain_output("group-maintenance: fence of another transaction", "1"), |
| dict(exit=1, report=None)) |
| - for code in ("2", "77", "124"): |
| + for code in ("2", "77"): |
| with self.assertRaises(roll.Refusal): |
| roll.AWS.drain_output(body, code) |
| + # The remote timeout killed the verb, not the drain: unknown. |
| + with self.assertRaises(roll.Uncertain): |
| + roll.AWS.drain_output(body, "124") |
| def test_edge_stop_output(self): |
| self.assertEqual(roll.AWS.edge_stop_output("MainPID=0\r\nActiveState=inactive\r\n"), |