member backups 2a: flagship readiness note (cost, safety, risks) (#898)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
docs/superpowers/notes/member-backups-2a-flagship-readiness.md+87 −0
CI failed — run details
Intent
<paseo-system version="1" kind="agent-message" source-agent-id="8a3d302a-eac7-407c-b61c-f5ccc66b5544" message-id="b518654f-1045-4fda-b075-adbd8ed4092f"> Agent manager 8a3d302: your go is verified. v0.34.48 (2a + referrer fix) goes to ALL of dev tonight via release agent 82664493, aiming for S48 before 02:50Z so the 03:00Z drill runs; it will tell you when. You run the morning check (your 4 points). Flagship after that, on my and Paul's word. Two questions for your check report, since 2a arms on every flagship box including the region HA group: (1) S3 requests and bytes per box per night at flagship scale (sleeping hosts per box on annie, iris, adi, barbara, the US members), against memory s3-requests-cost-money; (2) confirm the drill only reads replicas (never takes a lease, never writes into an instance's replica prefix) and is safe on an HA group member mid-move. </paseo-system>
<task-notification> <task-id>a260ed5c2c276dfff</task-id> <tool-use-id>toolu_01QqHwVSf2umCFwxMSQMdVrj</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/ab362fc0-f177-4a7f-a92e-4a29ea210aad/tasks/a260ed5c2c276dfff.output</output-file> <status>completed</status> <summary>Agent "Drill cost and safety analysis" finished</summary> <note>A task-notification fires each time this agent stops with no live background children of its own. The user can send it another message and resume it, so the same task-id may notify more than once.</note> <result>The note is written and not committed: /home/paulca/amadan.net/carlos/platform/.claude/worktrees/member-backups/docs/superpowers/notes/member-backups-2a-flagship-readiness.md. I used 18 read-only S3 requests and 8 CloudWatch calls. **Formula:** each drilled host costs 20 LIST + (F + 4) GET, where F is the number of LTX files in the restore chain (1 to 24 on four sampled hosts). The 20 LISTs come from PlanFrom listing all 10 levels and then the restore listing them again. Each box adds 1 GET per night, plus 2 GET + 2 PUT per publish, which includes the `control/changes.json` bump; that is 1 or 2 publishes tonight. | Box | Sleeping hosts | LIST/night | GET/night | Bytes/night | $/month | |---|---|---|---|---|---| | annie | 174 | 3,480 | ~1,745 | ~0.4–1 GB (the 412 MB tenant dominates) | ~$0.54 (≤$0.71) | | iris | 16 | 320 | ~165 | under 0.1 GB | ~$0.05 | | barbara | 3 | 60 | ~35 | tiny | ~$0.01 | | adi | 3 | 60 | ~35 | tiny | ~$0.01 | | each US group member | ~2 of 4 HA hosts | ~40 | ~25 | tiny | under $0.01 | The fleet comes to about $0.62 a month (at most ~$1.10), and LISTs are about 95% of it. Every box should finish well inside the 45-minute budget, so no host goes unreached tonight. The drill runs once a night, so it does not break the no-polling rule. But spec §9 prices restore traffic at GET rates, and no test counts the drill's S3 calls per host. **Top risks:** 1. **Landed but not yet woken:** after an offline move lands, the target box drills `instances/<host>/` before the first wake promotes the staged copy from `moves/<host>/`. The result is unverified (`nothing_replicated`). If the instance comes back to a box it left earlier, the drill **passes** on the old copy left there. The IE bucket already has 136 such orphan prefixes. A rarer race with the promotion could raise a false **failed** alert. 2. **Read-only by convention:** the restore is handed a full read-write litestream client. It is safe in v0.5.14, but nothing enforces it. Restoring through `VerifyClientAt` over the planner's cached listing would make it read-only by type and halve the LISTs. 3. **Annie disk:** annie publishes no headroom figure, so check its free disk before the roll; the 412 MB tenant restores to disk. 4. **Minor:** barbara's 03:00 UTC run falls at 14:00 Sydney time. **Safety:** the drill never takes or renews a lease, never writes `lock.json`, and never writes under `instances/` or `moves/`. A move, landing or recreated record during a restore makes the result `moving` or `record_changed` instead of a verdict.</result> <usage><subagent_tokens>185367</subagent_tokens><tool_uses>65</tool_uses><duration_ms>615210</duration_ms></usage> </task-notification>
diff --git a/docs/superpowers/notes/member-backups-2a-flagship-readiness.md b/docs/superpowers/notes/member-backups-2a-flagship-readiness.md| new file mode 100644 |
| index 000000000..1ec525995 |
| --- /dev/null |
| +++ b/docs/superpowers/notes/member-backups-2a-flagship-readiness.md |
| @@ -0,0 +1,87 @@ |
| +# Member backups slice 2a: flagship readiness (S3 cost and safety) |
| + |
| +2026-11-12. Read-only check of `carlos ops hibernate-verify` (178dcfe5) before it arms on every flagship box at the next roll. Code at design-member-backups (includes main). Flagship numbers come from the commands at the end (18 S3 requests). |
| + |
| +## Q1. Requests per run, from the code |
| + |
| +Per drilled host, clean path, one plan attempt: |
| + |
| +| Step | Where | Requests | |
| +|---|---|---| |
| +| Bracket open: record GET (instance or sidecar) | drillidentity.go:52-53, 94/108 | 1 GET (deployment bucket, eu-west-1) | |
| +| Plan: `CalcRestorePlan` lists L9 then L8..L0 | hibernate_verify.go:539-544, plan_from.go:156-160; litestream replica.go:1452,1487 | 10 LIST (one more per 1,000 files in a level) | |
| +| Plan: ranged header GET of the last planned file | plan.go:81 | 1 GET (100 B) | |
| +| Pinned restore: a fresh client re-runs `CalcRestorePlan` | check.go:23-28, 247-250; replica.go:622 | 10 LIST more | |
| +| Pinned restore: one GET per planned LTX file (F) | replica.go:633-643 | F GET | |
| +| Freshness: lock.json GET (clean restores only) | hibernate_verify.go:405-406, 555; lockstate.go:56 | 1 GET | |
| +| Bracket close: record GET | hibernate_verify.go:412 | 1 GET | |
| +| Local DB header read, integrity check, scratch | check.go:309-318, freshness.go:97-126 | free | |
| + |
| +**Per host: 20 LIST + (F + 4) GET.** A planned position compacted away doubles it once (hibernate_verify.go:473, at most 2 attempts). Never replicated: 10 LIST + 2 GET. Moving or no record at open: 1 GET and stop (hibernate_verify.go:375-383). Region is explicit (`data_bucket_region` is published by every box), so no GetBucketLocation. |
| + |
| +Per box per run: 1 GET `dbverify.Load` (ops.go:503) + P publishes. Each publish is GET + PUT of `control/verify/<ref>.json` (dbverify.go:382, 406) **plus** the change-index bump, GET + PUT of `control/changes.json` (store.go:992-995, changeindex.go:89-95, 154). P = 1 final + 1 per 10-minute tick that has something new (hibernate_verify.go:216-240), so 1 to 5 in a 45-minute run. A box with no sleeping hosts and no prior record: 1 GET. |
| + |
| +Bytes per host = the planned chain (`RestorePlan.LTXBytes`): latest L9 snapshot plus the files after it. Simulating the plan on four sampled IE replicas gave F = 1, 2, 4, 24 files and 0.02 to 1.6 MB each. The largest known hibernating tenant is 412 MB (unit comment, carlos-hibernate-verify.service). All drill traffic is same-region S3 to EC2 (free), except the bracket GETs from US/UK/AU boxes to the eu-west-1 deployment bucket (records are under 2 KB). |
| + |
| +## Q1. Per box on flagship tonight |
| + |
| +"Sleeping hosts" = the box's non-alias, non-wildcard `home` hosts in `control/edges/<ref>.json` that also have an `instances/<host>/` replica prefix in the box's regional data bucket. The edges file does not mark leased hosts. Homes with no replica are static, box-wide-litestream or never-replicated hosts; a leased one among them costs 10 LIST + 2 GET (the upper bound below). Prices (S3 Standard list prices): LIST/PUT per 1,000 = $0.005 (us-east-1, eu-west-1), $0.0053 (eu-west-2), $0.0055 (ap-southeast-2); GET per 1,000 = $0.0004 / $0.00042 / $0.00044. GET/host taken as F + 4 = 10. |
| + |
| +| Box (region) | Homes | Sleeping hosts | LIST/night | GET/night | PUT/night | Bytes/night | $/month | Upper bound $/month | |
| +|---|---|---|---|---|---|---|---|---| |
| +| annie (eu-west-1) | 282 | 174 | 3,480 | ~1,745 | 2-4 | ~0.4-1 GB (412 MB tenant dominates) | ~$0.54 | ~$0.71 (+108 homes) | |
| +| iris (eu-west-2) | 68 | 16 | 320 | ~165 | 2-4 | <0.1 GB (UK bucket 8.3 GB in all) | ~$0.05 | ~$0.14 | |
| +| barbara (ap-southeast-2) | 63 | 3 | 60 | ~35 | 2 | <0.2 MB (AU bucket 150 KB) | ~$0.01 | ~$0.11 | |
| +| adi (us-east-1, fixed) | 62 | 3 | 60 | ~35 | 2 | <2.5 MB (US bucket 2.5 MB) | ~$0.01 | ~$0.10 | |
| +| g-10b8... (us-east-1, group) | 4 (all HA) | ~2 assigned (HRW) | ~40 (<=80) | ~25 | 2 | <2.5 MB | <$0.01 | ~$0.01 (double drill) | |
| +| g-a921... (us-east-1, group) | 4 (all HA) | ~2 assigned (HRW) | ~40 (<=80) | ~25 | 2 | <2.5 MB | <$0.01 | ~$0.01 | |
| +| **Fleet** | | **~202** | **~4,000** | **~2,030** | **12-16** | **~0.5-1 GB** | **~$0.62** | **~$1.10** | |
| + |
| +LIST is about 95% of the cost: one LIST costs 12.5 GETs. Fleet-wide that is about 6,000 requests a night (about 250 an hour averaged), or about $0.003 per sleeping host per month. |
| + |
| +**Budget cap (45 min, ops.go:279).** Per host is about 22 sequential S3 calls (~0.5-1 s same-region), 2 cross-region record GETs (~0.05-0.6 s) and an integrity check (ms for small DBs, ~10-40 s for the 412 MB tenant). Annie's 174 hosts should finish in roughly 5-10 min, so **no host goes unreached tonight on any box** and P is 1-2. The cap starts to bind at roughly 1,500-2,500 hosts per box. After that, OldestFirst (hibernate_verify.go:645) rotates coverage over several nights. |
| + |
| +**Against the S3 rule (memory s3-requests-cost-money).** This is not polling: it runs once a night per box, and its only bucket write is per-box scoped (`control/verify/<ref>`), so it fits the change-index rule. It still costs per host per night whether or not anything changed: an unchanged sleeping replica is listed 20 times and fully re-downloaded every night. That is about 0.02% of the ~$3/app/month polling bill the rule was written for. Spec §9 states the verdict PUTs but prices restore traffic as "tens of requests" at GET prices, while 20 of them are LISTs at 12.5x. No test counts the drill's own S3 calls per host. Cheapest fix: restore through `lease.VerifyClientAt` (check.go:256) over the planner's cached `listing` (plan_from.go:77-114) instead of a fresh client. That gives 10 LIST/host, halves the fleet cost and makes the restore read-only by type (risk 2). |
| + |
| +## Q2. Safety, from the code |
| + |
| +**Reads only.** The drill acquires and renews no lease: there are no `lease.Acquire/Renew/Tombstone/Release/Mirror/Restore` calls in internal/ops. Its only lease touch is `LockState`, a single GetObject (lockstate.go:47-79). `VerifyReplicaAt` restores into the drill's scratch file with litestream's `Restore` (nil DB). In litestream v0.5.14 that path (replica.go:544-735) only calls `LTXFiles` and `OpenLTXFile`. The replica writers `uploadLTXFile` (replica.go:184-192) and `deleteBeforeTXID` (replica.go:289-312) are not reachable from it. The planner's client refuses writes by type (plan_from.go:142-148). Write sites, complete: |
| + |
| +| Write | Site | |
| +|---|---| |
| +| `control/verify/<ref>.json` (CAS PUT, 3 tries) | dbverify.go:406 via ops.go:652 (`PublishOver`) | |
| +| `control/changes.json` bump after that PUT | store.go:992-995 -> changeindex.go:192-206 | |
| +| `<data>/monitor/verify.json` (local alert copy) | ops.go:685-690 (`boxself.WriteFile`, boxself.go:280) | |
| +| Scratch: run dir and per-host dir under `%C/carlos-verify`, removed on return | ops.go:533-538, hibernate_verify.go:389-394, check.go:279-293 | |
| +| Crashed-run scratch older than 2 h removed (own prefix only, no symlinks) | ops.go:571-592 | |
| +| `<data>/monitor/verify-assign.json` (by the agent, not the drill) | verifyassign.go:104, boxself.go:202 | |
| + |
| +Nothing is written under any `instances/<host>/` prefix, to lock.json, or under `moves/`. The local freshness read is a 28-byte `os.Open` of the live DB's header (check.go:335-349). It takes no SQLite lock and happens only when this box provably holds the lease (hibernate_verify.go:554-561). |
| + |
| +**Mid-move instances (offline/residence moves).** `Move` is set from move-prepare to the cut's terminal flip (provision.go:86-89). Bracket open with `Move != nil` gives unverified/moving and no restore (hibernate_verify.go:381-382). A move that starts, lands (region changes) or recreates the record (new incarnation) during the restore is caught at close: moving, or record_changed, which discards the restore (drillidentity.go:79-88, hibernate_verify.go:412-421). The drill reads only `<prefix>/<host>/` and never `moves/<host>/...` staging (staging.go:6-9, backend_exec.go:4056). It holds no lock and no lease, so it cannot delay a cut, a seal or a lease handover. The worst case for the move is a few hundred extra GETs on the same prefix. The record then says moving or record_changed. On the source, the landing's `RemoveHost` (movespass.go:577) drops the host, and `PublishOver` respects that removal (ops.go:599-604, 652-657; dbverify.go:386-399). |
| + |
| +**HA group hosts.** Only the HRW winner over the host's serving boxes drills it (verifyassign.go:52-73, hibernate_verify.go:600-637). A stale (>15 min) or missing assignment means no_assignment and no requests. Double drills when two boxes' views differ are harmless: both only read, and each writes only its own record. A lease handover between members leaves the record unchanged, so the bracket does not fire. The restore still reads a committed position. If the new holder compacts away a planned file, the drill re-plans once and then records plan_moved (hibernate_verify.go:471-502). Freshness is judged only by the lease holder; a sleeping HA host's release marker reads unknown (hibernate_verify.go:549-560). |
| + |
| +## Risks, ranked |
| + |
| +1. **Landed but not yet woken.** The target box (route present, `Move` cleared) drills `instances/<host>/` before the first wake promotes `moves/<host>/` over it (backend_exec.go:1041-1051, 4092-4122; offline.go:54). The result is nothing_replicated (unverified). In a boomerang it is worse: **passed** on the left-behind older lineage, because the legacy cut does not delete the own prefix (backend_exec.go:1046-1047). IE already holds 136 replica prefixes with no home on any box. The verdict's `written_at` exposes the age, but `passed` is false assurance. A first wake racing a drill restore (exact mirror with deletes) mostly gives plan_moved. A mixed-lineage read could give restore_error, a false **failed** alert. That is rare: it needs an offline move plus a wake between 03:00 and 03:30. |
| +2. **Read-only is by convention for the restore.** `VerifyReplicaAt` hands litestream a full read-write `lss3.ReplicaClient` (check.go:23-41), and the unit runs with the box's normal store credentials. It is safe in v0.5.14 by reading the code, but a future litestream bump is not caught by type. The `VerifyClientAt` fix in Q1 closes this too. |
| +3. **The restore lists twice (20 LIST/host).** About 95% of cost. Levels 4-8 were empty on every sampled replica. Cheap to halve (Q1). |
| +4. **Annie disk and memory headroom.** Annie publishes no `headroom` (null in its edges file). The 412 MB tenant restores to `/var/cache/carlos-verify` (plus its `.tmp`) under MemoryMax=512M. Check annie's free disk before the roll (memory: box-version-staging-disk). |
| +5. **Timer wall-clock.** If box clocks are UTC, 03:00 UTC is 14:00 in Sydney, so barbara drills during the AU working day. Small at 3 hosts. |
| +6. **Change-index bump per publish.** About 6 boxes CAS `control/changes.json` 1-2 times each between 03:00 and 03:30. Negligible cost; contention is retried (changeindex.go:143-170). |
| + |
| +## Commands run (flagship, read-only, `--profile keymail`; 18 S3 requests + 8 CloudWatch calls) |
| + |
| +``` |
| +aws s3api list-objects-v2 --bucket carlos-flagship-271376211898 --prefix control/edges/ # 1 LIST |
| +aws s3api get-object --bucket carlos-flagship-271376211898 --key control/edges/<box>.json OUT # 6 GET (adi, annie, barbara, iris, g-10b8..., g-a921...) |
| +aws s3api list-objects-v2 --bucket carlos-data-us-271376211898 --delimiter / # 1 LIST |
| +aws s3api list-objects-v2 --bucket carlos-data-ie-271376211898 --delimiter / # 1 LIST |
| +aws s3api list-objects-v2 --bucket carlos-data-{us,ie,uk,au}-271376211898 --prefix instances/ --delimiter / # 4 LIST |
| +aws s3api list-objects-v2 --bucket carlos-data-ie-271376211898 --prefix instances/<sample>/ --max-items 3000-4000 # 4 LIST (4 sampled hosts, 1 page each) |
| +aws s3api get-bucket-location --bucket carlos-flagship-271376211898 # 1 (eu-west-1) |
| +aws cloudwatch get-metric-statistics --region <r> --namespace AWS/S3 --metric-name {BucketSizeBytes(StandardStorage),NumberOfObjects(AllStorageTypes)} --dimensions Name=BucketName,Value=carlos-data-<r>-271376211898 ... --period 86400 --statistics Average # 8 calls |
| +``` |
| + |
| +CloudWatch (2026-11-11): ie 623.8 GB / 773k objects (most outside `instances/`: `db/`, backups and other prefixes); uk 8.3 GB / 144k; us 2.5 MB / 3.5k; au 150 KB / 281. Replica prefixes under `instances/`: ie 322, uk 20, us 10, au 4. |