design: group roll verb rev 2, Astra round 1 fixes
The claim is narrowed (no forced release, owner token and machine, divergence carried group-wide, absence from a listing); environment isolation for credentials and endpoints; plugin gets the profile and endpoint; registry parity artifacts per slice; retirement migrates the fault harness imports first.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2 files changed,
+160
−78
docs/superpowers/plans/2026-11-09-group-roll-verb.md+29 −25docs/superpowers/specs/2026-11-09-group-roll-verb-design.md+131 −53
CI cancelled — superseded by a newer push — run details
Intent
Human
<task-notification> <task-id>b2hfj8yp3</task-id> <tool-use-id>toolu_014oz9T3mqdR281JMCC3e8d4</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/669506ff-23ec-45f1-9035-1d29593f2c37/tasks/b2hfj8yp3.output</output-file> <status>completed</status> <summary>Background command "Wait for Astra review to finish" completed (exit code 0)</summary> </task-notification>
diff --git a/docs/superpowers/plans/2026-11-09-group-roll-verb.md b/docs/superpowers/plans/2026-11-09-group-roll-verb.md| index 03d8ced32..6058103bc 100644 |
| --- a/docs/superpowers/plans/2026-11-09-group-roll-verb.md |
| +++ b/docs/superpowers/plans/2026-11-09-group-roll-verb.md |
| @@ -8,7 +8,7 @@ |
| **Tech Stack:** Go, aws-sdk-go-v2 (autoscaling, ec2, ssm, new: elasticloadbalancingv2), `internal/release` (`Store`, `GetSystemPointer`), `golang.org/x/sys/unix` for the pseudo-terminal, MinIO for integration tests. |
| -**Spec:** `docs/superpowers/specs/2026-11-09-group-roll-verb-design.md` (rev 1). Read it and the script before any task; the script at the merge of `held-floor-sha-map` is the parity target. |
| +**Spec:** `docs/superpowers/specs/2026-11-09-group-roll-verb-design.md` (rev 2). Plan rev 2 applies Astra round 1 (`~/.cache/group-roll-go/ASTRA-R1.md`). Read it and the script before any task; the script at the merge of `held-floor-sha-map` is the parity target. |
| ## Global Constraints |
| @@ -20,6 +20,7 @@ |
| - Operator copy is the script's `TEXT` table ported verbatim into `internal/grouproll/text.go`; no new user-facing string is invented outside that table, and Task 13's copy review is the only place strings change. |
| - Local tests: changed packages only, with `-run`; full suite once before the branch review (memory: local verification budget). Scratch under `$TMPDIR`. |
| - Commit subjects under 80 characters. One amadan task per plan task on the branch, advanced as each closes. |
| +- Command registry: every task that adds a `clireg` leaf adds its rows to `parity/parity.tsv` (status `cli-only`, audience operator) and runs `make parity-doc` in the same commit, so `TestCLIProjection` and `internal/parity` stay green; the leaf's usage text is in the copy review of Task 13 before any release. |
| - Census: every task that adds files to the root binary's closure appends its units to the branch's census proposal (`make census-propose`); Task 14 gets the reviewer's verdict. |
| ## Review Focus |
| @@ -39,11 +40,11 @@ |
| - Test: `internal/grouproll/config_test.go`, `journal_test.go`, `state_test.go` |
| **Interfaces:** |
| -- Produces: `type Config struct{...}` with the script's keys (JSON tags identical) and `func LoadConfig(path string) (Config, error)`; `type Journal`, `func (j *Journal) Add(kind string, fields map[string]any) (Row, error)`, `func (j *Journal) Last(kind string, match map[string]any) (Row, bool)`; `type State`, `func OpenState(c Config, readonly bool) (*State, error)`, `func (s *State) Lock() (unlock func(), err error)`, `func (s *State) Create(header Header) (*Journal, error)`, `func (s *State) Load(tx string, readonly bool) (*Journal, error)`, `func (s *State) ActiveID() (string, error)`, `func (s *State) Finish() error`; `type Refusal struct{Key string; Args map[string]string}` and `func Text(key string, args ...string) string`. |
| +- Produces: `type Config struct{...}` with the script's keys (JSON tags identical; `state_dir` is parsed and validated but not used, spec V4) and `func LoadConfig(path string) (Config, error)`; `type Journal`, `func (j *Journal) Add(kind string, fields map[string]any) (Row, error)`, `func (j *Journal) Last(kind string, match map[string]any) (Row, bool)`; `type State`, `func OpenState(c Config, readonly bool) (*State, error)`, `func (s *State) Lock() (unlock func(), err error)`, `func (s *State) Create(header Header) (*Journal, error)`, `func (s *State) Load(tx string, readonly bool) (*Journal, error)`, `func (s *State) ActiveID() (string, error)`, `func (s *State) Finish() error`, `func (s *State) OwnerToken(tx string) (string, error)` (creates `<tx>.owner`, 0600, 128 random bits, on `Create`), `func MachineID() (string, error)`; `func DefaultStateDir() string` (`$XDG_STATE_HOME/carlos/group`, else `~/.local/state/carlos/group`); `type Refusal struct{Key string; Args map[string]string}` and `func Text(key string, args ...string) string`. |
| -- [ ] **Step 1: Write failing tests.** `TestConfigMatchesScriptValidation`: a table of every accept/refuse case in `scripts/region_group_roll_test.py` and `region_group_held_test.py` config tests plus the `held-floor-sha-map` keys; each refusal is `config_invalid`. `TestJournalFormat2Golden`: two fixed rows encode to the bytes in `testdata/journal-format2.golden` (header has `"format":2`, times are integer milliseconds). `TestJournalRefusesDamage`: truncated last line, duplicate key, `NaN`, a bad `previous`, a bad `hash`, `seq` gap, over 64 MiB → `record`. `TestStateRefusesUnsafe`: state dir 0755, owned by another uid, a symlinked ancestor, a group-writable ancestor → `unsafe_state`. `TestStateRefusesScriptActive`: a script `active.json` naming a journal without `"format":2` → `journal_kind` (V4). `TestLockRefusesSecondWriter`: a second `Lock()` in another process → `busy`. |
| +- [ ] **Step 1: Write failing tests.** `TestConfigMatchesScriptValidation`: a table of every accept/refuse case in `scripts/region_group_roll_test.py` and `region_group_held_test.py` config tests plus the `held-floor-sha-map` keys; each refusal is `config_invalid`. `TestJournalFormat2Golden`: two fixed rows encode to the bytes in `testdata/journal-format2.golden` (header has `"format":2`, times are integer milliseconds). `TestJournalRefusesDamage`: truncated last line, duplicate key, `NaN`, a bad `previous`, a bad `hash`, `seq` gap, over 64 MiB → `record`. `TestStateRefusesUnsafe`: state dir 0755, owned by another uid, a symlinked ancestor, a group-writable ancestor → `unsafe_state`. `TestStateIgnoresScriptFiles`: a directory holding a script `active.json` and `<tx>.jsonl` is invisible to `ActiveID`, and `Load` of a `.v2.jsonl` whose header lacks `"format":2` → `record` (V4). `TestMachineID`: Linux reads `/etc/machine-id` (injected path); empty or unreadable → refusal. `TestLockRefusesSecondWriter`: a second `Lock()` in another process → `busy`. |
| - [ ] **Step 2: Run** `go test ./internal/grouproll -run 'TestConfig|TestJournal|TestState|TestLock'` — FAIL (undefined). |
| -- [ ] **Step 3: Implement.** Canonical encoding in one function `encodeRow(map[string]any) []byte`: keys sorted, no spaces, integers only (refuse floats), HTML escaping off. Group directory `hex(sha256(group_arn))[:32]`, files `<tx>.jsonl`, `active.json`, `group.lock` (`flock(LOCK_EX|LOCK_NB)`), `provider-observation.json`, `provider-divergence.json`, plan logs `plan-<hex>.log`. File checks as `private_file` with the owner = euid (V1). Port `TEXT` verbatim. |
| +- [ ] **Step 3: Implement.** Canonical encoding in one function `encodeRow(map[string]any) []byte`: keys sorted, no spaces, integers only (refuse floats), HTML escaping off. Group directory `hex(sha256(group_arn))[:32]` under `DefaultStateDir()` or `--state-dir`, files `<tx>.v2.jsonl`, `active-v2.json`, `<tx>.owner`, `group.lock` (`flock(LOCK_EX|LOCK_NB)`), `provider-observation.json`, `provider-divergence.json`, plan logs `plan-<hex>.log`. File checks as `private_file` with the owner = euid (V1). Port `TEXT` verbatim. |
| - [ ] **Step 4: Run** the same command — PASS. |
| - [ ] **Step 5: Commit** `grouproll: config, journal format 2 and the group lock`. |
| @@ -55,7 +56,7 @@ |
| - Test: `internal/grouproll/box_test.go` |
| **Interfaces:** |
| -- Produces: `func RemoteCommand(verb string, a BoxArgs, nonce string) (string, error)`; `type BoxStatus` (fields of `group_maintenance_verbs.go:245-301`, unknown fields kept in `Raw map[string]any`); `func ParseFramed(text, nonce, verb string) (BoxResult, error)` covering `drain_output` (exit 124 → `Uncertain{Timeout:true}`), `edge_stop_output`, the `drain-cancel` exit-1 detail, and the 8192-byte JSON decode; `type Box interface { Run(ctx, iid string, verb string, a BoxArgs) (BoxResult, error) }`. |
| +- Produces: `func RemoteCommand(verb string, a BoxArgs, nonce string) (string, error)`; `type BoxStatus` (fields of `group_maintenance_verbs.go:245-301`, unknown fields kept in `Raw map[string]any`); `func ParseFramed(text, nonce, verb string) (BoxResult, error)` covering `drain_output` (exit 124 → `Uncertain{Timeout:true}`), `edge_stop_output`, the `drain-cancel` exit-1 detail, and the 8192-byte JSON decode; `type Box interface { Run(ctx context.Context, iid, verb string, a BoxArgs, onSession func(id string)) (BoxResult, error); CancelSession(ctx context.Context, id string) error }` (the engine journals `session-opened` from `onSession` and calls `CancelSession` after an uncertain timeout, as `Operator.call` does at `:1180-1202`). |
| - [ ] **Step 1: Failing tests.** `TestRemoteCommandGolden`: every golden case matches byte for byte. `TestRemoteCommandMatchesDocumentPattern`: each output matches the regex in `infra/modules/region-group-operator-document/tool-pattern.txt`. `TestParseFramed`: two frames → `remote`; END code `124` on drain → uncertain; over-cap body → `remote`; the drain report is the last `{"v":1,...}` line. |
| - [ ] **Step 2: Run** `go test ./internal/grouproll -run 'TestRemoteCommand|TestParseFramed'` — FAIL. |
| @@ -72,12 +73,12 @@ |
| **Interfaces:** |
| - Consumes: Task 1 `Config`, `Refusal`. |
| -- Produces in core `internal/grouproll/provider.go`: `type Phase string` (`Serving, Parking, Parked, Returning, ReturnHeld, Leaving, Absent, Unknown`); `type GroupView struct{Name, ARN, Deployment, Region string; Minimum, Desired, Maximum int; Members map[string]Member; Template map[string]any; TargetGroups []string}` with `Member{Phase Phase; Raw string; Healthy bool}`; `type Activity struct{ID, Kind, Status string; Time int64}`; `type Group interface { Describe(ctx) (GroupView, error); Targets(ctx, arn string) (map[string]string, error); Hook(ctx) (Hook, error); Online(ctx, iid string) (bool, error); Activities(ctx, iid string) ([]Activity, error); Instance(ctx, iid string) (InstanceState, error); TemplateRelease(ctx, tpl map[string]any) (string, error); SetMinimum(ctx, n int) (WriteResult, error); RaiseDesired(ctx, n int) (WriteResult, error); Park(ctx, iid string) (WriteResult, error); Unpark(ctx, iid string) (WriteResult, error); Terminate(ctx, iid string) (WriteResult, error) }`. `WriteResult{Activity string; Uncertain bool; Response any}`. |
| +- Produces in core `internal/grouproll/provider.go`: `type Phase string` (`Serving, Parking, Parked, Returning, ReturnHeld, Leaving, Absent, Unknown`); `type GroupView struct{Name, ARN, Deployment, Region string; Minimum, Desired, Maximum int; Members map[string]Member; Template map[string]any; TargetGroups []string}` with `Member{Phase Phase; Raw string; Healthy bool}`; `type Activity struct{ID, Kind, Status string; Time int64}`; `type Group interface { Describe(ctx) (GroupView, error); Targets(ctx, arn string) (map[string]string, error); Hook(ctx) (Hook, error); Online(ctx, iid string) (bool, error); Activities(ctx, iid string) ([]Activity, error); Membership(ctx, iid string) (row MemberRow, found bool, err error); Instance(ctx, iid string) (InstanceState, error); TemplateRelease(ctx, tpl map[string]any) (string, error); SetMinimum(ctx, n int) (WriteResult, error); RaiseDesired(ctx, n int) (WriteResult, error); Park(ctx, iid string) (WriteResult, error); Unpark(ctx, iid string) (WriteResult, error); Terminate(ctx, iid string) (WriteResult, error) }`. `Membership` is the member's own Auto Scaling row (group name, template, raw state, phase, health), which the probe reconciles against `Describe`; `Instance` is EC2 existence for `close-lost`. `WriteResult{Activity string; Uncertain bool; Response any}`. |
| - Produces in adapter: `func New(ctx, c grouproll.Config) (*Adapter, error)`; `func MapPhase(state string) grouproll.Phase`. |
| -- [ ] **Step 1: Failing tests.** `TestMapPhaseTotal`: every state in the spec §5.2 table maps as listed; `"Warmed:Pending"` → `Unknown`. `TestCredentialsIgnoreAmbient`: with `AWS_ACCESS_KEY_ID`, `AWS_PROFILE=other`, `AWS_ENDPOINT_URL=http://evil` set and a shared config file naming the config's profile, the resolved credentials are the profile's and the endpoint is AWS's; IMDS disabled. `TestExpiredSSOIsAPIRefusal` (Review Focus 4). `TestWriteShapes` (SDK middleware capture, no network): `Park` sends `ShouldDecrementDesiredCapacity=true` for exactly that iid; `Terminate` sends `ShouldDecrementDesiredCapacity=false` and refuses (`h4`) unless a fresh describe shows the member `Standby` and `desired == minimum`; `RaiseDesired` refuses unless `desired <= n <= maximum`; no method can lower desired. `TestActivitiesKinds`: "Moving EC2 instance out of Standby", "to Standby", "into Standby", "Terminating EC2 instance" classified as the script; a description naming another iid is ignored. `TestTemplateRelease`: gzip and plain user data; zero or two `CARLOS_RELEASE=` lines → `api`. `TestTargetsDuplicatePort`: two registrations with different states → `unknown`. `TestInstanceNotFound`: an empty filtered response → `not-found`; a CLI error is never absence. |
| +- [ ] **Step 1: Failing tests.** `TestMapPhaseTotal`: every state in the spec §5.2 table maps as listed; `"Warmed:Pending"` → `Unknown`. `TestIsolatedEnvironment` (runs the adapter constructor in a subprocess): with `AWS_ACCESS_KEY_ID`, `AWS_PROFILE=other`, `AWS_DEFAULT_PROFILE=other`, `AWS_ENDPOINT_URL=http://127.0.0.1:1`, `AWS_ENDPOINT_URL_AUTO_SCALING=…`, `AWS_CONTAINER_CREDENTIALS_FULL_URI=…` set, and a shared config whose profile has `endpoint_url = http://127.0.0.1:1`, the resolved credentials are the profile's static keys, every client's resolved endpoint is the AWS regional one, and `os.Environ()` afterwards holds only the allow-list plus `AWS_IGNORE_CONFIGURED_ENDPOINT_URLS=true`, `AWS_EC2_METADATA_DISABLED=true`, `AWS_PROFILE=<profile>`. `TestRefusedCredentialSources`: profiles with `credential_source = Environment`, `Ec2InstanceMetadata`, `EcsContainer` → refused before any call. `TestExpiredSSOIsAPIRefusal` (Review Focus 4). `TestWriteShapes` (SDK middleware capture, no network): `Park` sends `ShouldDecrementDesiredCapacity=true` for exactly that iid; `Terminate` sends `ShouldDecrementDesiredCapacity=false` and refuses (`h4`) unless a fresh describe shows the member `Standby` and `desired == minimum`; `RaiseDesired` refuses unless `desired <= n <= maximum`; no method can lower desired. `TestActivitiesKinds`: "Moving EC2 instance out of Standby", "to Standby", "into Standby", "Terminating EC2 instance" classified as the script; a description naming another iid is ignored. `TestTemplateRelease`: gzip and plain user data; zero or two `CARLOS_RELEASE=` lines → `api`. `TestTargetsDuplicatePort`: two registrations with different states → `unknown`. `TestInstanceNotFound`: an empty filtered response → `not-found`; a CLI error is never absence. |
| - [ ] **Step 2: Run** `go test ./internal/grouprollaws -run .` — FAIL. |
| -- [ ] **Step 3: Implement** with `awsconfig.LoadDefaultConfig` given `WithSharedConfigProfile(c.Profile)`, an explicit credentials provider resolved from that profile, `WithRegion(c.Region)`, IMDS disabled, `RetryMaxAttempts=1`, 2 s connect and read timeouts. Never read `AWS_ENDPOINT_URL*`. |
| +- [ ] **Step 3: Implement** `func IsolateEnvironment(profile string) error` (called by the CLI leaf before anything else: `os.Clearenv`, then the spec §4 allow-list and the three fixed values), then `awsconfig.LoadDefaultConfig` with `WithSharedConfigProfile(c.Profile)`, `WithRegion(c.Region)`, IMDS disabled, `RetryMaxAttempts=1`, 2 s connect and read timeouts; read the profile's `credential_source` with `awsconfig.LoadSharedConfigProfile` first and refuse the three sources. |
| - [ ] **Step 4: Run** — PASS. |
| - [ ] **Step 5: Commit** `grouprollaws: Auto Scaling, ELB and EC2 calls behind the Group interface`. |
| @@ -89,11 +90,11 @@ |
| **Interfaces:** |
| - Consumes: Task 2 `RemoteCommand`, `ParseFramed`, `Box`. |
| -- Produces: `func (a *Adapter) Run(ctx, iid, verb string, args grouproll.BoxArgs) (grouproll.BoxResult, error)` implementing `grouproll.Box`; `SessionObserver func(sessionID string)` set by the engine before each call; `func (a *Adapter) TerminateSession(ctx, id string) error`. |
| +- Produces: `func (a *Adapter) Run(ctx, iid, verb string, args grouproll.BoxArgs) (grouproll.BoxResult, error)` implementing `grouproll.Box`; `func (a *Adapter) CancelSession(ctx, id string) error` (`ssm:TerminateSession`). |
| -- [ ] **Step 1: Failing tests** using a fake plugin binary built in `TestMain` and put first on `PATH`: `TestSessionReadsFrame`; `TestSessionBoundKillsGroup` (the fake ignores SIGTERM and forks a child; at the bound both are gone, error is uncertain-timeout, the session id seen was reported to the observer); `TestSessionOutputCap` (4 MiB + 1 → `remote`); `TestPluginMissing` (Review Focus 5: `PATH` without it → `remote` refusal naming the plugin); `TestSessionStartArgs` (the StartSession request carries the config's `document`, the target iid and `{"command":[<RemoteCommand>]}`). |
| -- [ ] **Step 2: Run** `go test ./internal/grouprollaws -run TestSession -run TestPlugin` — FAIL. |
| -- [ ] **Step 3: Implement.** Call `ssm.StartSession`, then exec `session-manager-plugin '<response json>' <region> StartSession '' '<request json>' https://ssm.<region>.amazonaws.com` on a fresh pty (`Setsid`), stdin the pty slave left open and silent, read the master until frame or bound; at the bound `kill(-pgid, SIGKILL)` then reap. |
| +- [ ] **Step 1: Failing tests** using a fake plugin binary built in `TestMain` and put first on `PATH`: `TestSessionReadsFrame`; `TestSessionBoundKillsGroup` (the fake ignores SIGTERM and forks a child; at the bound both are gone, error is uncertain-timeout, the session id seen was reported to the observer); `TestSessionOutputCap` (4 MiB + 1 → `remote`); `TestPluginMissing` (Review Focus 5: `PATH` without it → `remote` refusal naming the plugin); `TestSessionStartArgs` (the StartSession request carries the config's `document`, the target iid and `{"command":[<RemoteCommand>]}`). `TestPluginArgs`: the fake plugin records argv and env; argv is `<response json> <region> StartSession <config profile> <request json> <resolved ssm endpoint>` and the endpoint equals the SDK's resolution for the region (an `aws-cn` region gives the `.amazonaws.com.cn` host); env holds no ambient keys. |
| +- [ ] **Step 2: Run** `go test ./internal/grouprollaws -run 'TestSession|TestPlugin'` — FAIL. |
| +- [ ] **Step 3: Implement.** Call `ssm.StartSession`, then exec `session-manager-plugin '<response json>' <region> StartSession <c.Profile> '<request json>' <endpoint from the ssm client's resolver>` with the isolated environment, on a fresh pty (`Setsid`), stdin the pty slave left open and silent, read the master until frame or bound; at the bound `kill(-pgid, SIGKILL)` then reap. |
| - [ ] **Step 4: Run** — PASS; also `GOOS=darwin GOARCH=arm64 go build ./... && GOOS=windows GOARCH=amd64 go build ./...`. |
| - [ ] **Step 5: Commit** `grouprollaws: run framed box verbs through Session Manager`. |
| @@ -101,7 +102,7 @@ |
| **Files:** |
| - Create: `internal/grouproll/engine.go` (the `Operator` equivalent: `call`, `snapshot`, `identity`, `readiness`, `preflight`), `plan.go`, `status.go` |
| -- Create: `system_group.go`; Modify: `system_roles.go:122-130` (add the new leaves to `systemGroupCommand()`) |
| +- Create: `system_group.go`; Modify: `system_roles.go:122-130` (add the new leaves to `systemGroupCommand()`), `parity/parity.tsv` (rows for `system group plan` and `system group status`), regenerated `parity/cli.tsv` and `docs/parity.md` (`make parity-doc`) |
| - Test: `internal/grouproll/fake_test.go` (the Go port of the script's `Fake`), `plan_test.go`, `system_group_test.go` |
| **Interfaces:** |
| @@ -109,10 +110,10 @@ |
| - Produces: `type Engine struct{...}`; `func NewEngine(c Config, g Group, b Box, s *State, clock func() time.Time, sleep func(time.Duration), out io.Writer, attendedBy string) *Engine`; `func (e *Engine) Plan(ctx, iid, sha string) (ok bool, err error)`; `func SavedStatus(j *Journal) map[string]any`; `func runSystemGroup(verb string, args []string) int`; the fake `newFake(t, n int) *fake` that later tasks extend. |
| - [ ] **Step 1: Failing tests.** Port every `test_plan*`, `test_status*`, `test_stale_and_racing_readiness`, `test_publication_lag_and_two_second_margin`, `test_readiness_clock_starts_at_first_response_*`, `test_live_*` parsing test. Add `TestSkewedClockRefuses` (Review Focus 1: box `started_at` 3 minutes ahead of the local clock → `admission`). `TestCLIRefusesRootBoxWindows`: euid 0 → `root` text adapted per Task 13; `/etc/carlos/host.env` present (injected path) → refused; positional args → usage error; missing `--config` → usage error; no console session is ever opened (the console client constructor is a nil func in the test and must not be called). |
| -- [ ] **Step 2: Run** `go test ./internal/grouproll ./ -run 'TestPlan|TestStatus|TestReadiness|TestSkewed|TestCLIRefuses'` — FAIL. |
| +- [ ] **Step 2: Run** `go test ./internal/grouproll ./ -run 'TestPlan|TestStatus|TestReadiness|TestSkewed|TestCLIRefuses|TestCLIProjection' && go test ./internal/parity` — FAIL. |
| - [ ] **Step 3: Implement** the script's `snapshot`, `identity`, `readiness`, `preflight`, `plan`, `saved_status` and `main`'s argument rules. |
| - [ ] **Step 4: Run** — PASS. Cross-compile check. |
| -- [ ] **Step 5: Commit** `carlos system group: plan and status`. |
| +- [ ] **Step 5: Commit** `carlos system group: plan and status` (with the parity rows and regenerated files). |
| - [ ] **Step 6: Merge A.** Whole-change review for Tasks 1-5 (one Astra pass: Task 3 touches termination), census card, CI green, merge under the standing rule for inert operator verbs. Then, read-only and only with Paul's dev go: `carlos system group plan --config <dev ie config> --member <iid> --to-sha256 <current sha>` from an operator machine; it must print the same refusals as the script's `plan` on the same group. |
| ### Task 6: The deciders and golden fixtures |
| @@ -135,6 +136,7 @@ |
| **Files:** |
| - Create: `internal/grouproll/roll.go` (roll, resume, rollback, return, abandon, close-lost, prepare, mutation, verify, alert, divergence), `sim_test.go`, `mutation_test.go` |
| +- Modify: `system_group.go`, `parity/parity.tsv` + `make parity-doc` (leaves `roll`, `resume`, `rollback`, `return`, `abandon`, `close-lost`) |
| - Test: `internal/grouproll/roll_test.go` |
| **Interfaces:** |
| @@ -167,6 +169,7 @@ Starts only after `held-floor-sha-map` merges (stopping rule 4). |
| **Files:** |
| - Create: `internal/grouproll/depart.go` (start, depart, drain, pre-action, lock sweep, edge stop, stop-and-terminate, watch, summary, cancel-drain, `check_remove`) |
| +- Modify: `system_group.go`, `parity/parity.tsv` + `make parity-doc` (leaves `replace`, `remove`, `cancel-drain`) |
| - Test: `internal/grouproll/depart_test.go`; extend `sim_test.go`, `mutation_test.go` |
| **Interfaces:** |
| @@ -182,7 +185,7 @@ Starts only after `held-floor-sha-map` merges (stopping rule 4). |
| ### Task 10: The probe |
| **Files:** |
| -- Create: `internal/grouproll/probe.go`; Test: `internal/grouproll/probe_test.go` |
| +- Create: `internal/grouproll/probe.go`; Modify: `system_group.go`, `parity/parity.tsv` + `make parity-doc` (leaf `probe`); Test: `internal/grouproll/probe_test.go` |
| **Interfaces:** |
| - Produces: `func (e *Engine) Probe(ctx, iid string) error`, `func (e *Engine) ProbeResume(ctx, tx string) error`; journal kind `probe`. |
| @@ -190,29 +193,30 @@ Starts only after `held-floor-sha-map` merges (stopping rule 4). |
| - [ ] **Step 1: Failing tests:** port all `region_group_probe_test.py` tests (status-only sessions, `read_only` refusal for any other verb, the member's own instance row overriding membership, `unchanged`). |
| - [ ] **Step 2: Run** `go test ./internal/grouproll -run TestProbe` — FAIL. **Step 3: Implement** as a wrapper over `Group` and `Box` that refuses writes outside the probe's set. **Step 4: Run** — PASS. **Step 5: Commit** `grouproll: the Standby observation probe`. |
| -### Task 11: The claim and its policy statement |
| +### Task 11: The claim, its policy statement and the script's interlock |
| **Files:** |
| -- Create: `internal/grouproll/claim.go`; Modify: `internal/grouproll/state.go` (take before `Create`, release after `Finish`), `system_group.go` (`claim-release`) |
| +- Create: `internal/grouproll/claim.go`; Modify: `internal/grouproll/state.go` (take before `Create`, ownership check at every writing verb's entry, release after `Finish`), `internal/grouproll/roll.go` (divergence written to the claim before the local file) |
| - Modify: `infra/modules/region-host/group_operator.tf` (statement `GroupMaintenanceClaim`), `infra/modules/region-host/tests/group_operator.tftest.hcl` |
| +- Modify: `scripts/region-group-roll.py` (read the claim before `State.create`; refuse `busy` or `blocked`), `scripts/region_group_held_test.py` (its tests) |
| - Test: `internal/grouproll/claim_test.go`, `claim_minio_test.go` |
| **Interfaces:** |
| -- Produces: `func TakeClaim(ctx, st release.Store, c Config, tx, attendedBy, machine string) (etag string, err error)`, `func ReleaseClaim(ctx, st release.Store, c Config, etag, outcome string) error`, `func ForceReleaseAtRest(ctx, e *Engine, tx string) error`; key `control/group-maintenance/<hex(sha256(group_arn))[:32]>.json`. |
| +- Produces: `func ClaimKey(groupARN string) string` (`control/group-maintenance/<hex(sha256(group_arn))[:32]>.json`); `type Claim struct{...}` (spec §8 body); `func ReadClaim(ctx, st release.Store, c Config) (Claim, etag string, present bool, err error)` (presence from `List` of the exact key, never from a failed `Get`); `func TakeClaim(ctx, st release.Store, c Config, tx, owner, attendedBy, machine string) (etag string, err error)`; `func CheckOwnership(ctx, st release.Store, c Config, tx, owner, machine string) (etag string, err error)`; `func MarkDivergence(ctx, st release.Store, c Config, etag string, d Divergence) (string, error)`; `func ReleaseClaim(ctx, st release.Store, c Config, etag, outcome string) error`. |
| -- [ ] **Step 1: Failing tests.** `TestClaimRace` (Review Focus 3: two goroutines take on an absent key; exactly one wins, the loser refuses `busy` and has written no journal). `TestClaimLifecycle`: absent → open → closed → open again with `If-Match`. `TestClaimLostRelease`: release PUT fails; the next verb on the same machine closes it first. `TestClaimForeignOpen` refuses with holder, machine and time. `TestForceReleaseAtRest`: refused when any member is not `Serving`, unhealthy, has a permit or a fence, or `min/desired/max` differ; allowed otherwise, and the forced row names the operator. `TestClaimNeverDeletes` (the fake store fails on any Delete). The MinIO variant runs under `CARLOS_MINIO_TEST=1`. The tftest asserts the exact statement: `s3:GetObject` and `s3:PutObject` on exactly `arn:<partition>:s3:::<deployment bucket>/control/group-maintenance/<hex(sha256(group_arn))[:32]>.json` (computed in tofu with `sha256()` and `substr()`), no wildcard, and nothing else in the statement. |
| -- [ ] **Step 2: Run** `go test ./internal/grouproll -run TestClaim -run TestForceRelease` — FAIL. |
| -- [ ] **Step 3: Implement** with `release.Store.Put(ctx, key, body, ifMatch)` (`""` = create-only) and `ErrCASConflict` → `busy`. |
| +- [ ] **Step 1: Failing tests.** `TestClaimRace` (Review Focus 3: two goroutines take an absent key; exactly one wins; the loser refuses `busy` and has written no journal). `TestClaimLifecycle`: absent → open (create-only PUT) → closed → open again with `If-Match`. `TestClaimAbsenceIsAListing`: a store whose `Get` of the missing key returns AccessDenied and whose `List` lacks it → absent; a `List` error → `api`, never absent. `TestClaimOwnership`: `resume` with a copied journal and owner file on another machine id → refused; with the right machine but another owner token → refused; a claim rewritten under a running verb → its next claim write is `busy` and nothing further is sent to the provider. `TestClaimDivergenceGroupWide`: machine A records a return hook, then `close-lost`; the claim is `closed` with `divergence` set; machine B's `roll` and `plan` refuse `blocked`. `TestClaimLostRelease`: release PUT fails; the next verb on the same machine with the same owner closes it first. `TestClaimNotStarted`: journal creation fails after the take → claim closed with `not-started`. `TestClaimNeverDeletes` (the fake store fails on any Delete). The MinIO variant runs under `CARLOS_MINIO_TEST=1`. Python: `test_script_refuses_open_claim` and `test_script_refuses_diverged_claim` in `region_group_held_test.py`, with the fake's list and get. The tftest asserts the statement: `s3:GetObject` and `s3:PutObject` on exactly `arn:<partition>:s3:::<deployment bucket>/<ClaimKey>` (computed in tofu with `sha256()` and `substr()`), and `s3:ListBucket` on the bucket with `StringEquals s3:prefix` equal to that key; no wildcard. |
| +- [ ] **Step 2: Run** `go test ./internal/grouproll -run 'TestClaim'` and `python3 -m unittest scripts/region_group_held_test.py -k claim` — FAIL. |
| +- [ ] **Step 3: Implement** with `release.Store.Put(ctx, key, body, ifMatch)` (`""` = create-only) and `ErrCASConflict` → `busy`; presence with `List(prefix=key)`. |
| - [ ] **Step 4: Run** — PASS; `tofu test` in `infra/modules/region-host` with OpenTofu 1.13.9 if available, else say so in the commit body. |
| - [ ] **Step 5: Commit** `grouproll: a claim in the deployment bucket serializes machines`. |
| ### Task 12: The parity ledger, the boundary and integration |
| **Files:** |
| -- Create: `internal/grouproll/testdata/parity-ledger.tsv`, `internal/grouproll/parity_test.go`, `internal/grouproll/integration_minio_test.go` |
| +- Create: `internal/grouproll/testdata/parity-ledger.tsv`, `internal/grouproll/testdata/python-tests.txt` (the `def test_` names of the three Python files, generated once and committed; frozen at the port's merge), `internal/grouproll/parity_test.go`, `internal/grouproll/integration_minio_test.go` |
| - Modify: `region_ha_boundary_test.go` (core files listed), `internal/provision/region_group_guards_test.go` (run `region_group_document_test.py` also against the Go builder through a small `go run` shim) |
| -- [ ] **Step 1: Failing tests.** `TestParityLedgerComplete`: parse `def test_` names from the three Python files; every name has a ledger row; every Go test a row names exists in the package (`go test -list`). `TestCoreHasNoAWS` is the existing boundary test with the new files. `TestEndToEndNoAWSEnvironment`: with every `AWS_*` unset, `plan`, `roll`, `replace` and `remove` run to completion against the fake `Group` and `Box` and MinIO (edges files, locks, pointers, claim). |
| +- [ ] **Step 1: Failing tests.** `TestParityLedgerComplete`: every name in `python-tests.txt` has a ledger row (while the Python files exist, a second check fails if they hold a name the list lacks); every Go test a row names exists in the package (`go test -list`). `TestCoreHasNoAWS` is the existing boundary test with the new files. `TestEndToEndNoAWSEnvironment`: with every `AWS_*` unset, `plan`, `roll`, `replace` and `remove` run to completion against the fake `Group` and `Box` and MinIO (edges files, locks, pointers, claim). |
| - [ ] **Step 2: Run** `go test ./internal/grouproll -run 'TestParity|TestEndToEnd' && go test . -run TestRegionHACoreImportsNoAWS` — FAIL until the ledger is filled. |
| - [ ] **Step 3: Fill the ledger**; each "does not apply" row carries a reason tied to a V-row of spec §7. |
| - [ ] **Step 4: Run** — PASS. **Commit** `grouproll: parity ledger, boundary and MinIO end to end`. |
| @@ -234,4 +238,4 @@ Starts only after `held-floor-sha-map` merges (stopping rule 4). |
| 1. A release; apply the operator policy (claim statement) on dev, then flagship. |
| 2. Dev parity witnesses (spec §11 step 4): W1, W2, W4 (with the refused remove), one probe, one `cancel-drain` after a forced drain failure, from an operator machine other than the operator host. Compare journals and summaries with the script's runs. |
| -3. Retirement branch: delete `scripts/region-group-roll.py`, `scripts/region-group-probe.py`, `region_group_roll_test.py`, `region_group_held_test.py`, `region_group_probe_test.py`; point the document test at the Go builder only; update the runbook. |
| +3. Retirement branch, first commit: move the text, `remote_command` framing and session transport that `scripts/region_group_frames.py` (`:9-12`) and `scripts/region-group-fault/client.py` (`:14-15`, `:33-44`) import from the script into `region_group_frames.py`; run `region_group_fault_test.py` with the script moved aside. Then: delete `scripts/region-group-roll.py`, `scripts/region-group-probe.py`, `region_group_roll_test.py`, `region_group_held_test.py`, `region_group_probe_test.py`; point the document test at the Go builder only; update `TestRegionGroupHeldPythonGuards` and every CI entry naming the deleted files; update the runbook. |
diff --git a/docs/superpowers/specs/2026-11-09-group-roll-verb-design.md b/docs/superpowers/specs/2026-11-09-group-roll-verb-design.md| index 8fc1aa06c..0cb3bca66 100644 |
| --- a/docs/superpowers/specs/2026-11-09-group-roll-verb-design.md |
| +++ b/docs/superpowers/specs/2026-11-09-group-roll-verb-design.md |
| @@ -1,4 +1,4 @@ |
| -# `carlos system group`: the roll tool as a carlos verb (design, rev 1, 2026-11-09) |
| +# `carlos system group`: the roll tool as a carlos verb (design, rev 2, 2026-11-09) |
| **Asked by:** Paul, 2026-11-09, via agent manager 8a3d302: a spec for porting |
| `scripts/region-group-roll.py` into the `carlos` binary. |
| @@ -9,6 +9,15 @@ found twice is cut or turned into an invariant, not fixed a third time. |
| Line citations are to `origin/main` at `eed714da` unless they name a branch. |
| +**Rev 2 (Astra round 1, `~/.cache/group-roll-go/ASTRA-R1.md`, 4 spec P1).** The |
| +claim drew three P1s from one cause, a shared object with too many jobs and an |
| +escape hatch. It is now narrower: no forced release, ownership bound to a token |
| +and the machine, divergence carried in the claim, absence read from a listing |
| +(§8). Credentials now isolate the environment rather than trust SDK options (§4). |
| +The plugin gets the profile and resolved endpoint (§5.3). Retirement migrates the |
| +fault harness's imports first (§11). Journals use separate file names (V3, V4). |
| +§6 states the recovery rules it left implicit. |
| + |
| ## 1. Why |
| The roll tool is the only way to roll, replace, resize or scale in a group |
| @@ -35,7 +44,7 @@ document tests; the roll, probe and fault suites run in no CI job. |
| | # | Decision | Section | |
| |---|---|---| |
| -| D1 | Verb shape: `carlos system group <verb>`, one leaf per Python subcommand, plus `probe` and `claim-release`. | §3 | |
| +| D1 | Verb shape: `carlos system group <verb>`, one leaf per Python subcommand, plus `probe`. | §3 | |
| | D2 | Where it runs: any operator machine (Linux or macOS), never as root, never on a carlos box, never through the console. | §4 | |
| | D3 | What it needs: an AWS profile with the existing operator policy (plus two statements), and the Session Manager plugin. No root, no python, no AWS CLI, no cryptography package. | §4 | |
| | D4 | A provider-neutral engine (`internal/grouproll`) with an AWS adapter (`internal/grouprollaws`). | §5 | |
| @@ -66,7 +75,6 @@ carlos system group abandon --config F --transaction T |
| carlos system group close-lost --config F --transaction T |
| carlos system group cancel-drain --config F --member I --transaction T |
| carlos system group probe --config F --member I | resume --transaction T (the probe's verbs) |
| -carlos system group claim-release --config F --transaction T [--at-rest] |
| ``` |
| Every verb takes `--attended-by NAME` as the script does (required when stdin is |
| @@ -122,14 +130,22 @@ with a `_other.go` sibling, per the cross-compile gate. |
| **What it needs on the machine:** |
| 1. **An AWS profile** named in the config's `profile` key, carrying the operator |
| policy output `group_operator_policy_json` (`infra/modules/region-host/group_operator.tf`) |
| - plus the two statements in §8 and §9. The verb builds its credentials from that |
| - named shared profile only: ambient `AWS_ACCESS_KEY_ID`/`AWS_SECRET_ACCESS_KEY`/ |
| - `AWS_SESSION_TOKEN`, `AWS_PROFILE`, `AWS_DEFAULT_PROFILE` and every |
| - `AWS_ENDPOINT_URL*` are ignored, and the instance metadata service is disabled |
| - (the script's `invoke`, `:786-797`, does the same to the CLI). |
| - `AWS_CONFIG_FILE`, `AWS_SHARED_CREDENTIALS_FILE` and `AWS_CA_BUNDLE` are honoured, |
| - as today. SSO and `credential_process` profiles work, since the verb never runs |
| - as root. |
| + plus the claim statement in §8 and `held-floor-sha-map`'s `ReadReleasePointers` |
| + (§9). SDK options alone do not isolate it: `LoadDefaultConfig` still reads |
| + `AWS_ENDPOINT_URL*` and a profile's `endpoint_url`, and a profile with |
| + `credential_source = Environment` reads ambient keys. So the verb isolates the |
| + process instead. At entry, before any goroutine starts, it rebuilds its |
| + environment from an allow-list: `HOME`, `PATH`, `TMPDIR`, `TERM`, `LANG`, `LC_*`, |
| + `USER`, `AWS_CONFIG_FILE`, `AWS_SHARED_CREDENTIALS_FILE`, `AWS_CA_BUNDLE`; it then |
| + sets `AWS_IGNORE_CONFIGURED_ENDPOINT_URLS=true` (honoured by the SDK, |
| + `config/env_config.go:75`, and by the plugin's SDK), `AWS_EC2_METADATA_DISABLED=true` |
| + and `AWS_PROFILE` to the config's profile. Everything else, including ambient |
| + keys, `AWS_DEFAULT_PROFILE`, container and web-identity variables and endpoint |
| + overrides, is gone for the SDK and for the plugin it starts. A profile whose |
| + `credential_source` is `Environment`, `Ec2InstanceMetadata` or `EcsContainer` is |
| + refused up front. SSO and `credential_process` profiles work, since the verb |
| + never runs as root. This matches what the script does to the CLI (`invoke`, |
| + `:786-797`) and closes the profile-file endpoint the script left open. |
| 2. **The Session Manager plugin** (`session-manager-plugin`) on `PATH`. This is the |
| one external program, and it belongs to the AWS adapter. §5.3 says why it |
| stays. |
| @@ -152,9 +168,11 @@ with a `_other.go` sibling, per the cross-compile gate. |
| | The box-verb protocol: the framed remote command and parsing its output | Running one framed remote command on one member (Session Manager) | |
| | All operator text | The release the pinned launch template boots (user data `CARLOS_RELEASE`) | |
| -The engine talks to two interfaces, `Group` (the left column of provider calls, |
| -in provider-neutral terms) and `Box` (run one box verb on one member, return its |
| -framed output). Object-store reads (edges files, locks, release pointers, the |
| +The engine talks to two interfaces, `Group` (the right column's provider calls, |
| +in provider-neutral terms; membership of one member, as the probe reads it, is a |
| +separate call from whether an instance still exists) and `Box` (run one box verb |
| +on one member and return its framed output, reporting each session id to the |
| +engine as it opens so it is journaled, and cancel a session by id after a cut). Object-store reads (edges files, locks, release pointers, the |
| claim) are core and go through `release.Store`, so MinIO works as it does |
| everywhere else. |
| @@ -183,7 +201,11 @@ The journal records the raw provider state beside the phase, for operators. |
| The adapter calls `ssm:StartSession` itself through the SDK with the approved |
| document and the framed command, then runs `session-manager-plugin` with the |
| -returned session (the same invocation the AWS CLI makes), on a pseudo-terminal, |
| +returned session, the request, the region, the config's profile and the SSM |
| +endpoint the SDK resolved for that region and partition: the same arguments the |
| +AWS CLI passes (`awscli/customizations/sessionmanager.py`), so the plugin's own |
| +calls (reconnect, `TerminateSession`) run as the same caller, which the policy's |
| +`OwnSessions` condition on `aws:userid` requires. It runs on a pseudo-terminal, |
| reading output until the frame or the bound. It keeps the script's behaviour |
| (`session_output`, `:733-784`): a 4 MiB output cap, session-id capture for |
| `TerminateSession` after a cut, the plugin's process group killed at the bound, |
| @@ -220,7 +242,7 @@ the fake provider with no AWS configuration in the environment. |
| The Go verb does what the script does, decision for decision. In particular: |
| - **One serialized transaction per group.** The group directory is keyed by |
| - `sha256(group_arn)[:32]` (`:627`); one `active.json` names the open transaction; |
| + `sha256(group_arn)[:32]` (`:627`); one `active-v2.json` names the open transaction; |
| a non-blocking exclusive lock guards every writing verb (`State.lock`, `:642-654`); |
| `status` stays lock-free and read-only. The claim (§8) adds cross-host |
| serialization on top; it replaces nothing. |
| @@ -260,6 +282,21 @@ The Go verb does what the script does, decision for decision. In particular: |
| 120 s, cancel 300 s, `TERMINATE_RETRIES` 2, settle 120 s, pending 600 s, the 5 s |
| freshness window on `ExitStandby`, the 60 s readiness age, the 2 s publication |
| margin, `EDGES_MAX_AGE` 15 min and `EDGES_SKEW` 60 s. |
| +- **Recovery and closure rules, unchanged.** `abandon` closes only a |
| + transaction whose journal holds no group write intent and no `permit`, |
| + `revoke`, `apply`, `rollback`, `drain`, `edge-stop` or `fence-clear` session |
| + intent and no `exit-intent`, even an unsent one (`:1392-1407`). `close-lost` |
| + closes only when a fresh group read lacks the member and EC2 shows it |
| + `terminated` or not found, never on a read error (`:1410-1431`). A return after |
| + a failed drain closes the transaction with outcome `drain-failed`, prints the |
| + `cancel-drain` instruction and exits 1, leaving the member fenced and draining |
| + (`:1849-1858`). Terminate recovery decides from the activity the attempt's |
| + response named, else from an activity started no earlier than 5 s before the |
| + latest intent that no earlier attempt owns, with at most two resends per |
| + invocation (`:377-420`, `:2184-2196`). `rollback` needs this transaction's |
| + consumed `apply` in Standby and no `exit-intent` or `drain-failed` |
| + (`:1700-1735`). A cut session is terminated by id before the next box call, |
| + and the next box operation is a status read (`:1197-1202`, `:1558-1563`). |
| - **The same remote commands.** The framed command string for every box verb is |
| byte-identical to `AWS.remote_command` (`:824-867`), because the session |
| document's `allowedPattern` (`infra/modules/region-group-operator-document/tool-pattern.txt`) |
| @@ -288,11 +325,12 @@ build to it. |
| |---|---|---|---| |
| | V1 | euid 0 required; root-owned state with root-owned ancestors | euid 0 refused; state owned by the invoking user, 0700, ancestors not group- or world-writable and owned by root or that user | §4 | |
| | V2 | Serialization only among users of one host's state directory | The same local lock plus a claim object in the deployment bucket | §8 | |
| -| V3 | Journal rows hashed over Python's `json.dumps(sort_keys=True, separators=(",", ":"))`; times are Python floats | Journal format 2: a `"format": 2` header field, times as integer milliseconds, keys sorted, Go's canonical encoding defined in one function and pinned by golden bytes | Byte-identical float and escape formatting across languages is a trap; neither tool has to read the other's journals (§11) | |
| -| V4 | Refuses to adopt nothing: it cannot read a Go journal | Refuses any journal without `"format": 2` naming the script, and refuses to start while a script `active.json` exists in the same configured `state_dir` | §11 overlap | |
| +| V3 | Journal rows hashed over Python's `json.dumps(sort_keys=True, separators=(",", ":"))`; times are Python floats | Journal format 2: a `"format": 2` header field, times as integer milliseconds, keys sorted, Go's canonical encoding defined in one function and pinned by golden bytes | Byte-identical float and escape formatting across languages is a trap; neither tool reads the other's journals | |
| +| V4 | State in the config's `state_dir` (root-owned): `<tx>.jsonl`, `active.json` | State in the invoking user's `$XDG_STATE_HOME/carlos/group` (default `~/.local/state/carlos/group`, or `--state-dir`); the config's `state_dir` is ignored. Files are `<tx>.v2.jsonl` and `active-v2.json`, and the reader refuses a journal whose header lacks `"format": 2` | The two tools can never share a directory (root versus user ownership) or a file name, so neither can misread the other; the claim and the script patch (§8) interlock them across tools | |
| | V5 | SHA mapping verified with `python3-cryptography` (`held-floor-sha-map`) | `release.GetSystemPointer` (`internal/release/systempointer.go:259`), the code boxes use | §9 | |
| | V6 | Refuses nothing about where it runs, beyond root | Refuses on a carlos box and on Windows | §4 | |
| | V7 | `region-group-probe.py` is a separate script | `carlos system group probe` | Same engine; probe rules unchanged (read-only status sessions, the member's own `DescribeAutoScalingInstances` row overrides group membership) | |
| +| V8 | `provider-divergence.json` blocks only the host it is on | The block is also in the claim, so every machine sees it (§8) | Group-wide interlock across machines | |
| Not deviations, recorded so nobody "fixes" them in the port: the drain-rerun |
| backoff and the TakeHost `wake_timeout` follow-ups from the held build stay |
| @@ -305,36 +343,65 @@ not written by `probe`. |
| The script serializes operators only if they all use one state directory on one |
| host. A verb that runs on any operator machine needs a shared fact. The core |
| -already assumes an object store with conditional writes, so: |
| +already assumes an object store with conditional writes, so the claim is one |
| +object per group. It carries two things the script keeps in local files: which |
| +transaction is open, and whether provider divergence blocks the group. |
| -- **Key:** `control/group-maintenance/<sha256(group_arn)[:32]>.json` in the |
| +- **Key:** `control/group-maintenance/<hex(sha256(group_arn))[:32]>.json` in the |
| deployment bucket (the config's `bucket`). No box reads or writes it. |
| -- **Body:** `{v:1, group_arn, state: "open"|"closed", transaction, attended_by, |
| - machine, opened_at, closed_at, outcome}`. |
| -- **Take** (before `create` writes the journal's first row): GET the key. Absent: |
| - PUT with `If-None-Match: *`. `closed`: PUT with `If-Match` on its ETag. `open` |
| - with this transaction and a local journal for it: already ours. Anything else |
| - refuses with who holds it, from which machine, since when. A lost race |
| - (`release.ErrCASConflict`) refuses as busy. |
| -- **Release:** when the transaction finishes (`State.finish`), PUT `closed` with the |
| - outcome, `If-Match` on the ETag the take returned. The local finish comes first. |
| - A release that fails leaves the claim `open`; the next verb on this machine for |
| - this group sees its own finished transaction and closes it before anything else. |
| +- **Body:** `{v:1, group_arn, state: "open"|"closed", transaction, owner, |
| + attended_by, machine, opened_at, closed_at, outcome, divergence}`. |
| + `owner` is a random 128-bit token made when the transaction is created and kept |
| + only in the machine's state directory, beside the journal, in a 0600 file named |
| + for the transaction; `machine` is the machine's identity (`/etc/machine-id` on |
| + Linux, `IOPlatformUUID` on macOS). `divergence` is `null` or |
| + `{transaction, phase, reason, at}`. |
| +- **Absence is a listing answer.** As the lock sweep already does (`:1009-1012`), |
| + the verb lists the exact key (`s3:ListBucket` with `s3:prefix` equal to the key) |
| + and treats the object as absent only when the listing lacks it. A failed GET is |
| + never absence; an AccessDenied is `api`. |
| +- **Take** (before the journal's first row): create-only PUT |
| + (`If-None-Match: *`) of an `open` claim. On a conflict, GET it: `closed` with |
| + `divergence: null` is taken with `If-Match` on its ETag; `closed` with a |
| + divergence refuses `blocked`; `open` refuses `busy`, naming the transaction, |
| + who, which machine and since when. A lost race (`release.ErrCASConflict`) is |
| + `busy`. Only after the PUT succeeds is the journal created; if journal creation |
| + fails, the claim is closed again with outcome `not-started`. |
| +- **Ownership on every writing verb.** `resume`, `return`, `rollback`, `abandon`, |
| + `close-lost` and `cancel-drain` first GET the claim and go on only when it is |
| + `open` for this transaction, its `owner` equals the token in this state |
| + directory, and its `machine` equals this machine. A journal copied to another |
| + machine therefore cannot act. Every claim write after the take uses `If-Match` |
| + on the ETag this verb last read, so a claim that changed under a running verb |
| + stops it at its next claim write (`busy`). There is no forced release: a claim |
| + whose machine is lost blocks the group, fail closed, and recovery is the |
| + controller's documented procedure (a hand edit of the object after proving the |
| + member set at rest), not a verb. |
| +- **Divergence is group-wide.** Wherever the script writes |
| + `provider-divergence.json` (`:1468`, `:1755`), the verb first writes the claim |
| + with `divergence` set (still `open`), then the local file. The close PUT |
| + carries `divergence` forward, and nothing the verb does clears it, `close-lost` |
| + included (`:1430-1431` keeps the flag; the claim keeps it too). The controller |
| + clears it by hand after resolving the provider contract, as it removes the file |
| + today. `plan` and every take refuse while it is set. |
| +- **Release:** when the transaction finishes (`State.finish`), the local finish |
| + comes first, then a PUT of `closed` with the outcome, `If-Match` on the ETag. A |
| + release that fails leaves the claim `open`; the next verb on the same machine, |
| + with the same owner token, finds its finished journal and closes the claim |
| + before anything else. |
| - **No delete.** The store's IAM denies `s3:DeleteObject` in places |
| (`lease-deleteobject-outage`); the claim is only ever overwritten. |
| -- **Lost machine.** A claim whose machine is gone blocks the group, fail closed. |
| - `claim-release --transaction T --at-rest` closes it from another machine only when |
| - a fresh describe shows the group at rest: `min = desired = max = N`, every member |
| - `Serving`, healthy in both target groups, and every member's box status showing |
| - no permit and no fence. The release row records who forced it. Without |
| - `--at-rest`, `claim-release` closes only a claim whose transaction this machine's |
| - journal has finished. |
| -- **`plan` and `status` take no claim.** `plan` reads the claim and reports it as a |
| - refusal when it is open. |
| +- **`plan` and `status` take no claim.** `plan` lists and reads it and reports an |
| + open claim or a divergence as a refusal. `status` reads only the local journal. |
| +- **The script during the overlap** (§11) reads the claim, read-only, before |
| + creating a journal, and refuses when it is open or diverged: a small patch to |
| + the script, with its own test, in the plan's claim task. |
| - **IAM:** one new operator policy statement, `GroupMaintenanceClaim`: |
| - `s3:GetObject` and `s3:PutObject` on exactly that key. Census: an infra change on |
| + `s3:GetObject` and `s3:PutObject` on exactly that key, and `s3:ListBucket` on the |
| + deployment bucket with `s3:prefix` equal to that key. Census: an infra change on |
| a card. |
| -- **Request budget:** two GETs and two PUTs per transaction, none on a timer. |
| +- **Request budget:** per transaction, one LIST and one or two GETs and PUTs at the |
| + take, one GET per later writing verb, one PUT at close; none on a timer. |
| ## 9. The floor from signed release records (D7) |
| @@ -441,14 +508,21 @@ operations, the decrement flags and the group name on every write. |
| `cancel-drain` after a forced drain failure. Their journals and drain summaries |
| are compared with the script's W1, W2 and W4 runs: the same phases in the same |
| order, the same provider writes, the same summary fields. |
| -5. **Overlap rule.** Until step 6 a card names one tool per group per window. Each tool |
| - fails closed on the other's state: the script refuses a format-2 journal named in |
| - `active.json` (it fails its hash check, "record"), and the Go verb refuses a script |
| - `active.json` (V4). The claim covers only the Go verb, so the card rule matters. |
| -6. **Retire the script.** One branch deletes `region-group-roll.py`, |
| - `region-group-probe.py` and their tests, moves the document test to the Go builder, |
| - repoints `TestRegionGroupHeldPythonGuards`, and updates the runbook to the verb. The |
| - golden fixtures stay in Go testdata. |
| +5. **Overlap rule.** Until step 6 a card names one tool per group per window. The |
| + tools never share state (V4). The patched script refuses while the claim is open or |
| + diverged (§8), but it does not take the claim, so a Go take can still race a script |
| + transaction already past that check: the card rule covers that window. A divergence |
| + the script records stays in its local file only; the card sends it to the controller. |
| +6. **Retire the script.** First, in its own commit, move what the kept tools import from |
| + it: `scripts/region_group_frames.py` (`:9-12`) and `scripts/region-group-fault/client.py` |
| + (`:14-15`, `:33-44`) use its text, `remote_command` framing and session transport; those |
| + pieces move into `region_group_frames.py`, and the fault tests run with the script |
| + absent. Then one branch deletes `region-group-roll.py`, `region-group-probe.py` and their |
| + tests, points the document test at the Go builder, updates |
| + `TestRegionGroupHeldPythonGuards` and every other CI entry that names them, and updates |
| + the runbook. The parity ledger's Python test inventory is a committed list |
| + (`testdata/python-tests.txt`), frozen at the port's merge, so the ledger test needs no |
| + Python file. The golden fixtures stay in Go testdata. |
| ## 12. W6, the fixed-edge restart gap (D10) |
| @@ -464,8 +538,12 @@ member is parked and deregistered before its edge stops. |
| ## 13. Open questions for Paul |
| 1. **The claim (§8).** Recommended: build it, since the verb runs anywhere. The cut: keep |
| - "one operator host per deployment" as a card rule, unenforced, as today. |
| -2. **Parity witnesses (§11 step 4).** Recommended: W1, W2 and W4 only, not all of W1-W5, |
| + "one operator host per deployment" as a card rule, unenforced, as today, and keep the |
| + divergence block local as the script does. |
| +2. **A lost operator machine** leaves its claim open and the group blocked until the |
| + controller edits the object by hand. Recommended: accept; a forced-release verb is what |
| + round 1 found unsafe. |
| +3. **Parity witnesses (§11 step 4).** Recommended: W1, W2 and W4 only, not all of W1-W5, |
| because the script's runs already prove the box side. |
| -3. **Windows.** Recommended: refuse. Supporting it needs a ConPTY transport for one AWS |
| +4. **Windows.** Recommended: refuse. Supporting it needs a ConPTY transport for one AWS |
| plugin. |