plan: refresh agent-start-demo-3 against merged Plan 2
Refresh code anchors and account for merged moved-page, retirement, serving-control and counter interfaces. Reuse the flags-based SQLite starter and document the existing account-cap exemption. Keep the design, constraints, review focus, task split, test names and claim protocols intact. Record each refresh in the plan. Document-only change; no implementation, Go tests or push.
1 file changed,
+44
−29
docs/superpowers/plans/2026-11-04-agent-start-demo-3-claim.md+44 −29
CI passed — run details
Intent
Attributed to this commit: 12.1 g CO₂e (1,145,162 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on agent-start-demo-3, 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/plans/2026-11-04-agent-start-demo-3-claim.md b/docs/superpowers/plans/2026-11-04-agent-start-demo-3-claim.md| index e7c0595b0..bb8081eb1 100644 |
| --- a/docs/superpowers/plans/2026-11-04-agent-start-demo-3-claim.md |
| +++ b/docs/superpowers/plans/2026-11-04-agent-start-demo-3-claim.md |
| @@ -38,30 +38,32 @@ |
| ## Existing interfaces and boundaries |
| -Read against main checkout `2914921ceabd4218b0363a9780f8e4db890aab4c`. These are existing-code anchors; interfaces introduced below are proposals. Plan 2 has not landed in this checkout. Do not review against its unmerged implementation; Task 6 supplies the minimum hook here. |
| +Refreshed against merged base `e129f535`, including Plan 2 (`f86e9792`) and the six Plan 1 follow-ups (`b40c2c1f`). These are current-tree anchors; interfaces introduced below remain proposals unless identified as merged. Plan 2 supplies the inert `demoMovedPage` hook; Task 6 still supplies authenticated notices and the route-independent entry needed after source purge. Read both `docs/superpowers/notes/agent-start-demo-1-rulings.md` and `docs/superpowers/notes/agent-start-demo-2-rulings.md` as settled dependencies. |
| | Existing mechanism | Evidence and consequence | |
| |---|---| |
| | Plan 1 extension points | `docs/superpowers/plans/2026-11-02-agent-start-demo-1-anonymous-apps.md:88`: token lookup, lifecycle lock, reserved fragment link and local-only SQLite. R13 and R19 replace the original plan's root-policy assumptions; R19b prohibits host reuse (`docs/superpowers/notes/agent-start-demo-1-rulings.md:37`, `:56`, `:27`). R15 (`:21`) permits a self-inflicted init-marker case; claim export never treats that marker as proof of a database. | |
| -| Token and lifecycle | `internal/console/demo_store.go:292`, `:323`, `:364`: strict 32-byte token decode, constant-time comparison, live anonymous predicate and app mutex. `:58` has a SQL CHECK permitting only anonymous/retiring/retired. Keep those states; put transfer phases in a separate table. | |
| -| Existing claim response | `internal/console/apidemo.go:259`, `:439`: `/demo/claim` is a 503 stub and create returns `claimAvailable:false`. Extend these without changing publish/status field names. | |
| -| Email discovery | `internal/console/emailsignin.go:90`, `:104`, `:124`, `:132`; `internal/console/server.go:3789`, `:3854`: canonical address, public Keymail discovery, mail readiness, async send and flow serialization. Discovery is not a membership lookup. | |
| +| Token and lifecycle | `internal/console/demo_store.go:311`, `:342`, `:386`: strict 32-byte token decode, constant-time comparison, live anonymous predicate and app mutex. `:63` has a SQL CHECK permitting only anonymous/retiring/retired. Keep those states; put transfer phases in a separate table. | |
| +| Existing claim response | `internal/console/apidemo.go:260`, `:448`: `/demo/claim` is a 503 stub and create returns `claimAvailable:false`. Extend these without changing publish/status field names. | |
| +| Email discovery | `internal/console/emailsignin.go:90`, `:104`, `:124`, `:132`; `internal/console/server.go:3792`, `:3857`: canonical address, public Keymail discovery, mail readiness, async send and flow serialization. Discovery is not a membership lookup. | |
| | Proof and limits | `internal/console/emailsignin_store.go:29`, `:101`, `:133`, `:156`, `:299`: purpose-bound challenges, held unsent challenge, destructive successful take, process-key code MAC. `internal/console/emailsignin_limits.go:18`, `:230`, `:313`: shared send/guess budgets. | |
| -| Identity and browser login | `internal/console/emailsignin.go:258` resolves a sign-in method, opens a session and calls current-account landing; `internal/console/server.go:3087` uses MRU before minting. Agent proof must reuse identity resolution without calling this session/landing wrapper. Keymail OAuth starts at `internal/console/server.go:3889`; `safeNext` is `internal/console/emailsignin.go:240`. | |
| -| Account authorization | `internal/console/store.go:1375` lists memberships. `internal/console/apicli.go:228`, `:381` admits a person through membership for ordinary create; ordinary members as well as owners can create. `internal/console/server.go:3145` mints an account; it does not itself enforce the free-account cap. | |
| -| Plans and locks | `internal/console/plancaps.go:106`, `:167`, `:230`, `:277`, `:310`: running things count apps plus instance records, free-account check, account/person locking. `internal/console/apicli.go:505` holds the account lock through count and create. A claim creates two counted things, not one. | |
| -| Fresh permanent app | `internal/console/server.go:5417` `claimAppWith` refuses demo placement, adopts only when permitted, and uses zero expiry for permanent apps. Use `ownerClaim=false`. `internal/console/regionclaim.go:105` resolves normal region; `internal/console/apiinstances.go:1806` inherits it. `internal/console/apex.go:31` derives `<app>.<sqid>.<AppsDomain>`. | |
| +| Identity and browser login | `internal/console/emailsignin.go:258` resolves a sign-in method, opens a session and calls current-account landing; `internal/console/server.go:3090` uses MRU before minting. Agent proof must reuse identity resolution without calling this session/landing wrapper. Keymail OAuth starts at `internal/console/server.go:3892`; `safeNext` is `internal/console/emailsignin.go:240`. | |
| +| Account authorization | `internal/console/store.go:1375` lists memberships. `internal/console/apicli.go:228`, `:381` admits a person through membership for ordinary create; ordinary members as well as owners can create. `internal/console/server.go:3148` mints an account; it does not itself enforce the free-account cap. | |
| +| Plans and locks | `internal/console/plancaps.go:106`, `:171`, `:234`, `:281`, `:314`: running things count apps plus instance records, free-account check (including the merged `opsOwner` exemption), account/person locking. `internal/console/apicli.go:505` holds the account lock through count and create. A claim creates two counted things, not one. | |
| +| Fresh permanent app | `internal/console/server.go:5420` `claimAppWith` refuses demo placement, adopts only when permitted, and uses zero expiry for permanent apps. Use `ownerClaim=false`. `internal/console/regionclaim.go:105` resolves normal region; `internal/console/apiinstances.go:1806` inherits it. `internal/console/apex.go:31` derives `<app>.<sqid>.<AppsDomain>`. | |
| | Artifact publication | `internal/console/demo_publish.go:38`, `:131`, `:140`: demo version, `release.ShipSpooled`, signed promotion. `:228` checks exact-host readiness. Copy and verify the selected artifact into the destination namespace; do not repoint the demo manifest or rebuild source. | |
| -| Assigned source and transport | `internal/console/demo_publish.go:193` records FleetBox; `internal/console/apidemobox.go:93`, `:191` authenticate workers and replay work. `internal/demobuild/job.go:139`, `:160` define readiness and stream envelopes; `internal/host/demo_jobs.go:335` reconnects. | |
| +| Assigned source and transport | `internal/console/demo_publish.go:193` records FleetBox; `internal/console/apidemobox.go:97`, `:202` authenticate workers and replay work. `internal/demobuild/job.go:139`, `:162` define readiness and stream envelopes, now including `WorkerReady.ServingProbe`/`ServingAck` and `StreamMessage.Serving`. `internal/host/demo_jobs.go:344` reconnects; `internal/host/demo_serving.go:72` adds serving probes/acks to the existing heartbeat. Task 3 adds claim fields alongside these. | |
| | Local data and stop | `internal/activator/demo_durability.go:36`, `:110` retain the lease without replication and refuse lost established data. `internal/activator/maintenance.go:105` provides owner-bound `FenceAndStopAs`; `internal/activator/activator.go:6044` provides `Quiesced`; `internal/activator/maintenance.go:244` lifts only its own fence. In-memory fences alone do not survive restart. | |
| | Root start and retirement | `internal/instancectl/demo_policy.go:20` already refuses starts on held demo rows under `lockDemo`; `internal/instancectl/demo_cleanup.go:77` validates binding and proves stop before deletion. `internal/host/demo_cleanup.go:20` verifies a receipt and current object before acting. Reuse that trust split, not a new root reader of tenant SQLite. | |
| | Offline move does not fit | `internal/host/movesoffline.go:92`, `:387`, `:822` supply hold/fence precedents. `internal/host/movesoffline_seal.go:307` seals a replica-based move of the same instance. This claim changes account and host and has no replica; do not invoke the move state machine. | |
| | Seeds partly fit | `internal/console/apiinstanceseed.go:257` restores from a replica and `:563` refuses demo sources. `internal/provision/seedswap.go:74` requires an existing address route for import. Neither public door can perform this claim. Reuse snapshot keys (`internal/seeds/seeds.go:121`), bounded scratch (`internal/console/seedscratch.go:86`), create-only snapshot upload (`internal/console/apiinstanceimport.go:659`), first-wake restore (`internal/activator/seedplace.go:99`) and first replica confirmation (`:531`). | |
| | Seed restrictions and gate | `internal/console/seedfloor.go:35`, `internal/console/apiinstanceseed.go:114`, `internal/console/apiinstanceimport.go:131`: seed capability floor, normal hosted placement and data residency. `internal/edge/importgate.go:12`, `:34` gates before cache/wake and strips `Carlos-Import-Verify`. A fresh claim seed needs its own kind, not a fake legacy route or replica TXID. | |
| | Safe database primitives | `internal/instancefs/instancefs_linux.go:84`, `:138` open beneath a directory without following symlinks. `internal/lease/check.go:44`, `:202` integrity-check and checkpoint SQLite. Use these on a private copied DB/WAL, never run SQLite as root on source data. | |
| -| Retirement is currently time-only | `internal/console/demo_expiry.go:76`, `:92`, `:125`, `:174`, `:241`: early calls are no-ops; retirement fences jobs and token, trashes, waits for cleanup acknowledgment, purges, preserves host tombstones. Extract a reasoned retirement entry point; do not falsify expiry to trigger it. | |
| -| Routing and cheap refresh | `internal/edge/demo.go:18`, `:27`, `:81` validate exact demo hosts independently of routes. `internal/edge/edge.go:1890` is the request entry. `internal/release/changeindex.go:50` enumerates indexed scopes; `internal/host/changeindex.go:55`, `:180` share a watch and distinguish control scopes. `internal/console/demo_jobs.go:371`, `:447` own recovery/backstop work. | |
| -| Binary flags | `internal/activator/backend_exec.go:2530`, `:2733` pass `--socket` and `--db`. The 2026-11-04 commissioning facts override older fixture descriptions using environment variables. | |
| +| Retirement already accepts operator takedown | `internal/console/demo_expiry.go:83` keeps the expiry-only wrapper; `:104` is `retireDemoLocked(..., reason string)` accepting `expired` and `operator`. `:167`, `:223`, `:290` fence jobs/token, trash, wait for cleanup acknowledgment, purge and preserve host tombstones. `internal/demobuild/retirement.go:13`, `:26` already sign/validate optional `Reason`; only `operator` currently permits early retirement. Task 5 adds committed-claim retirement to these existing functions without changing original expiry. | |
| +| Box-local counters and serving | `internal/host/demo_traffic.go:25`, `:102`, `:207` provide `openDemoTraffic`, `Initialize` and `Purge`; counters are separate from app SQLite and survive updates/restarts. `internal/host/demo_serving.go:108` initializes only when `ServingDemo.Initialize` permits it, otherwise requires the existing assignment (`internal/demo/traffic.go:39`). `internal/host/demo_cleanup.go:68` already stops traffic, purges the app and counter, then acknowledges. Tasks 3/5 preserve totals through freeze/abort and reuse this retirement path; no counter transfer or reset. | |
| +| Moved-page hook | `internal/edge/demo.go:207` defines inert `demoMovedPage`; `internal/edge/demo_traffic.go:142` calls it only for a resident route after serving permission, before later retirement/quota handling. `internal/edge/demo.go:104` currently refuses missing/expired routes before this hook can run. Task 6 must add signed notice storage/rendering and a route-independent lookup at the demo-domain entry. | |
| +| Routing and cheap refresh | `internal/edge/demo.go:134`, `:143`, `:197` validate exact demo hosts independently of routes. `internal/edge/edge.go:1900` enters `handleDemoRequest` before ordinary routing; `internal/edge/demo_traffic.go:128` already bypasses shared cache, local-asset shortcuts and upgrades for live demo traffic. `internal/release/changeindex.go:50` enumerates indexed scopes; `internal/host/changeindex.go:55`, `:180` share a watch and distinguish control scopes. `internal/console/demo_jobs.go:376`, `:452` own recovery/backstop work. | |
| +| Binary flags | `internal/activator/backend_exec.go:2530`, `:2733` pass `--socket` and `--db`. The merged starter at `internal/console/testdata/demo/main.go:16` now parses those flags; Task 8 reuses that contract. `internal/demobuild/testdata/starter/main.go:5` remains an empty validation fixture, not the runnable SQLite starter. | |
| ## Decisions and protocol |
| @@ -120,7 +122,7 @@ Deadline expiry before commit initiates abort; source expiry still wins. Deadlin |
| **Files:** |
| - Create: `internal/console/demo_claim_auth.go`, `internal/console/demo_claim_store.go`. |
| -- Modify: `internal/console/emailsignin_store.go:101`, `internal/console/emailsignin.go:317`, `internal/console/apidemo.go:259`, `internal/console/demo_store.go:51`, `internal/console/server.go:3854`. |
| +- Modify: `internal/console/emailsignin_store.go:101`, `internal/console/emailsignin.go:317`, `internal/console/apidemo.go:260`, `internal/console/demo_store.go:51`, `internal/console/server.go:3857`. |
| - Test: `internal/console/demo_claim_auth_test.go`, `internal/console/demo_claim_store_test.go`. |
| **Interfaces:** |
| @@ -150,7 +152,7 @@ TestDemoClaimCodeRestart: oldCode => refused; freshResend => works; plaintextCod |
| **Files:** |
| - Create: `internal/console/demo_claim_target.go`. |
| -- Modify: `internal/console/demo_claim_store.go` (Task 1), `internal/console/store.go:1865`, `internal/console/plancaps.go:106`, `internal/console/server.go:5417`, `internal/console/apicli.go:228`, `internal/console/apiinstances.go:1806`. |
| +- Modify: `internal/console/demo_claim_store.go` (Task 1), `internal/console/store.go:1865`, `internal/console/plancaps.go:106`, `internal/console/server.go:5420`, `internal/console/apicli.go:228`, `internal/console/apiinstances.go:1806`. |
| - Test: `internal/console/demo_claim_target_test.go`, `internal/console/demo_claim_caps_test.go`. |
| **Interfaces:** |
| @@ -178,16 +180,16 @@ TestDemoClaimTargetIsolation: ordinaryShip/promote/delete/seed/run/serviceToken |
| **Files:** |
| - Create: `internal/democlaim/work.go`, `internal/democlaim/snapshot.go`, `internal/host/demo_claim.go`, `internal/instancectl/demo_claim.go`, `internal/host/units/carlos-demo-snapshot@.service`. |
| -- Modify: `main.go:20` (private worker dispatch), `internal/host/bootstrap.go` (embedded unit installation), `internal/demobuild/job.go:139`, `:160`, `internal/console/apidemobox.go:191`, `internal/host/demo_jobs.go:335`, `internal/host/agent.go:988`, `internal/instancectl/demo_policy.go:20`, `internal/instancectl/server.go:474`, `internal/provision/provision.go:125`, `internal/provision/reconcile.go:118`. |
| +- Modify: `main.go:37` (private worker dispatch), `internal/host/bootstrap.go` (embedded unit installation), `internal/demobuild/job.go:139`, `:162`, `internal/console/apidemobox.go:202`, `internal/host/demo_jobs.go:344`, `internal/host/demo_serving.go:72`, `internal/host/agent.go:1010`, `internal/instancectl/demo_policy.go:20`, `internal/instancectl/server.go:474`, `internal/provision/provision.go:125`, `internal/provision/reconcile.go:118`. |
| - Test: `internal/democlaim/work_test.go`, `internal/democlaim/snapshot_test.go`, `internal/host/demo_claim_test.go`, `internal/instancectl/demo_claim_test.go`. |
| **Interfaces:** |
| - Produces: `democlaim.Work {ID string; Demo demo.Descriptor; Account, App, Fleet, Box string; Generation uint64; Action string; Deadline time.Time}`; Action is exactly `freeze`, `export` or `abort`. Sign/verify with Ed25519 and separator `carlos demo claim work v1\n`: `SignWork(priv ed25519.PrivateKey, w Work) ([]byte,error)` and `VerifyWork(pub ed25519.PublicKey, wire []byte, now time.Time) (Work,error)`. Freeze/export deadlines cannot exceed demo expiry; an abort gets a fresh 30-second delivery deadline even after expiry, but may never resume an expired demo. |
| - Produces: `(*demoWorker).claimDemo(ctx context.Context, wire []byte) error`; `(*instancectl.Client).FreezeDemo(ctx context.Context, d demo.Descriptor, operationID string) error` over `POST /demo-freeze` on the existing control socket. |
| - Produces: `democlaim.ExportSQLite(ctx context.Context, dbDir, dbBase, scratchDir string) (Snapshot,error)`; `Snapshot {Path, SHA256 string; Bytes int64}`. All paths are derived locally, never wire parameters; Path never leaves the box. |
| -- Produces: `(*instancectl.Client).SnapshotDemo(ctx context.Context, d demo.Descriptor, operationID string, db io.Reader, dbBytes int64, wal io.Reader, walBytes int64) (io.ReadCloser,error)` on `POST /demo-snapshot`; fixed multipart fields carry bytes and lengths, never filenames. The response streams the checked snapshot. `democlaim.RunSnapshotWorker(ctx context.Context) error` handles private `__demo-snapshot` dispatch, like `__registry-child` at `main.go:36`, outside the public command switch. |
| +- Produces: `(*instancectl.Client).SnapshotDemo(ctx context.Context, d demo.Descriptor, operationID string, db io.Reader, dbBytes int64, wal io.Reader, walBytes int64) (io.ReadCloser,error)` on `POST /demo-snapshot`; fixed multipart fields carry bytes and lengths, never filenames. The response streams the checked snapshot. `democlaim.RunSnapshotWorker(ctx context.Context) error` handles private `__demo-snapshot` dispatch, like `__registry-child` at `main.go:37`, outside the public command switch. |
| - Adds optional `provision.Record.DemoClaim *democlaim.Hold`, with `ID string; Generation uint64`; this is a console-owned source hold, not ownership-transfer authority. Ordinary writers preserve it and cannot set or clear it. A hold carries no auto-resume time. |
| -- Adds `StreamMessage.Claim []byte` and `WorkerReady.ClaimCapability string`, value `anonymous-demo-claim-v1`; old workers remain valid for builds but cannot receive claim work. |
| +- Adds `StreamMessage.Claim []byte` and `WorkerReady.ClaimCapability string`, value `anonymous-demo-claim-v1`; old workers remain valid for builds but cannot receive claim work. Preserve the merged `StreamMessage.Serving`, `WorkerReady.ServingProbe`/`ServingAck`, and `ServingDemo.Initialize` fields. Extend `demoHeartbeat` and the `WorkerReady.Valid`/`EmptyBuild` handling without conflating claim capability with build readiness or serving acknowledgment. |
| - [ ] **Step 1: Write failing tests.** |
| @@ -201,7 +203,7 @@ TestDemoClaimExportBounded: oneExportPerBox; helperMemory<=256MiB; scratch<=768M |
| - [ ] **Step 2: Run** `go test ./internal/democlaim ./internal/host ./internal/instancectl -run 'TestDemoClaim(Work|Snapshot|Freeze|Export)' -count=1`; expect FAIL. |
| - [ ] **Step 3: Implement the source protocol.** Verify signed work in the agent, then confirm its current operation through an authenticated console pickup before executing, so a signed stale abort/freeze cannot win after commit. Install the persistent source hold before fencing; restore holds before serving or reconciling on startup, including newly minted routes. Use `FenceAndStopAs` with owner `demo-claim/<operationID>` and matching generation; root's fixed freeze verb reuses the stop/cgroup proof from purge without deleting files. The freeze verb receives identity only; neither root door reads the source DB or accepts a path, argv or mount instruction. Root start gates must retain the hold for every covered binary generation. A false `Quiesced` or unknown cgroup state prevents export. |
| - The agent opens only the derived DB and optional WAL through no-follow descriptors after stop proof; reject multiple hardlinks and changing inode/size. Stream them into the fixed snapshot door. Root rechecks the exact held demo/operation, accepts only bounded bytes, and writes fixed names under root-created `/var/lib/carlos-demo-snapshots/<operationID>/`; it never opens an agent-supplied source path. SHM is transient and is recreated in this private scratch. The unit runs the shipped binary's private worker as a dynamic UID with only that scratch writable, no network/credentials/sibling data, `MemoryMax=268435456`, `MemorySwapMax=0`, `CPUQuota=50%`, `TasksMax=32`, `RuntimeMaxSec=120`, `TimeoutStopSec=5`, and `KillMode=control-group`. Reserve/enforce the 768 MiB disk budget before accepting input. The helper checkpoints the private copy with `lease.TruncateWAL`, runs `lease.CheckDBContext`, and hashes its completed DB. Serialize it with the builder slot; kill/reap before returning or cleaning scratch, including restart recovery. Upload its response by streaming to the console, never granting the demo box destination-account store permissions. An abort can lift only this operation's hold after the console proves destination rollback; retirement replaces the hold through the existing retirement path. |
| + The agent opens only the derived DB and optional WAL through no-follow descriptors after stop proof; reject multiple hardlinks and changing inode/size. Stream them into the fixed snapshot door. Root rechecks the exact held demo/operation, accepts only bounded bytes, and writes fixed names under root-created `/var/lib/carlos-demo-snapshots/<operationID>/`; it never opens an agent-supplied source path. SHM is transient and is recreated in this private scratch. The unit runs the shipped binary's private worker as a dynamic UID with only that scratch writable, no network/credentials/sibling data, `MemoryMax=268435456`, `MemorySwapMax=0`, `CPUQuota=50%`, `TasksMax=32`, `RuntimeMaxSec=120`, `TimeoutStopSec=5`, and `KillMode=control-group`. Reserve/enforce the 768 MiB disk budget before accepting input. The helper checkpoints the private copy with `lease.TruncateWAL`, runs `lease.CheckDBContext`, and hashes its completed DB. Serialize it with the builder slot; kill/reap before returning or cleaning scratch, including restart recovery. Upload its response by streaming to the console, never granting the demo box destination-account store permissions. An abort can lift only this operation's hold after the console proves destination rollback; retirement replaces the hold through the existing retirement path. Plan 2's `demoServingAllowed` already refuses held routes (`internal/host/demo_serving.go:221`). Preserve its shared dispatch/write gate and cancel active responses during freeze, retaining the box-local counters for abort/resume. `fenceDemoServing` (`:238`) and `demoTrafficStore.Fence` (`internal/host/demo_traffic.go:249`) permanently retire a lifetime, so they are not the reversible claim-freeze operation. |
| - [ ] **Step 4: Rerun Step 2**, plus existing demo durability/cleanup tests. Run the actual cgroup/no-follow witness only using prebuilt binaries in the explicitly approved dev scope; a skip is not proof. |
| - [ ] **Step 5: Commit** with subject `feat: freeze demo data for a bounded claim export`. |
| @@ -239,12 +241,12 @@ TestDemoClaimSeedCommit: committed => ordinaryReplicationAndWake; oldReaders => |
| **Files:** |
| - Create: `internal/console/demo_claim_transfer.go`. |
| -- Modify: `internal/console/demo_claim_store.go`, `internal/console/demo_jobs.go:371`, `:447`, `internal/console/demo_expiry.go:76`, `internal/console/demo_publish.go:43`, `internal/console/demo_store.go:329`, `internal/console/apidemobox.go`, `cmd/console/main.go:710`. |
| +- Modify: `internal/console/demo_claim_store.go`, `internal/console/demo_jobs.go:376`, `:452`, `internal/console/demo_expiry.go:104`, `internal/demobuild/retirement.go:26`, `internal/console/demo_publish.go:43`, `internal/console/demo_store.go:348`, `internal/console/apidemobox.go`, `cmd/console/main.go:710`. |
| - Test: `internal/console/demo_claim_transfer_test.go`, `internal/console/demo_claim_recovery_test.go`. |
| **Interfaces:** |
| - Produces: `(*Server).advanceDemoClaim(ctx context.Context, operationID string) error`, `(*Server).ReconcileDemoClaims(ctx context.Context, restart bool) error`, `(*Server).abortDemoClaim(ctx context.Context, operationID, reasonCode string) error`. |
| -- Produces: `(*Server).retireDemoLocked(ctx context.Context, d DemoRow, now time.Time, reason demoRetireReason) error`; reasons `demoRetireExpired` and `demoRetireClaimed`. Existing `expireDemoLocked` remains a wrapper. Claimed retirement requires the durable commit row; expiry retains its original time check. |
| +- Extends the merged `(*Server).retireDemoLocked(ctx context.Context, d DemoRow, now time.Time, reason string) error`; retain `expired` and `operator`, and add `claimed` only with the durable commit row. `expireDemoLocked` is already the expiry-checking wrapper. Extend the existing signed `demobuild.Retirement.Reason` validator for committed claims; retain omitted/`expired` wire compatibility and operator takedown. No new `demoRetireReason` type or second retirement implementation is needed. |
| - Produces: authenticated `POST /api/box/demo-claims/{operationID}/pickup`, `/snapshot`, `/ack`; use `demoBoxAuth` plus exact assigned box, claim phase, generation and lifetime. Snapshot metadata is digest and byte count; body is raw SQLite, not a path or archive. Duplicate identical snapshot is idempotent; changed bytes are refused. |
| - [ ] **Step 1: Write failing tests.** |
| @@ -260,7 +262,7 @@ TestDemoClaimRequestCost: idle/repeatedStatus/unchangedTick => zeroAdditionalSto |
| - [ ] **Step 2: Run** `go test ./internal/console -run 'TestDemoClaim(Transfer|CommitRecovery|ExpiryRace|Retirement|RequestCost)' -count=1`; expect FAIL. |
| - [ ] **Step 3: Implement the phase table and bounded recovery.** Pin the last settled live generation and channel artifact under the source lock; refuse any queued/building/starting/settling update. Extend enqueue and every publication boundary with the operation guard, not just the HTTP handler. Copy the manifest with only account/app namespace changes and stream/hash-check the same linux-arm64 artifact through `ShipSpooled`; use normal default pipeline and signed promotion. Write the destination record before its seed object, upload create-only and compare matching duplicates after ambiguous writes. Reserve scratch before accepting bytes, check digest/size/integrity, then publish the seed and verify exact HTTPS host without following redirects. Require 2xx, the pinned `X-Carlos-Version`, and seed `placed` before commitment. |
| - Commitment rechecks identity, cap reservation, source hold acknowledgment, lifetime and deadline under the ordered locks. At this point use `checkRunningThings(ctx, acct, 0)` because the reservation already counts; do not count the app and instance twice. Atomically record the irreversible decision, clear the claim token hash, invalidate other flows and enqueue all completion work. Seed opening follows that decision. A durable outbox retries opening, moved publication and Plan 1 retirement; status stays `claiming` until these finish. Extend the existing job runner/startup/backstop to drain SQL work and react to stream acknowledgments; status reads SQL only. The source's original expiry remains intact, but the reasoned retirement entry point permits an early committed claim. Preserve signed receipt validation, stop-before-delete, data-initialization-marker cleanup, acknowledgment and ceiling release. Do not let the expiry loop purge an uncommitted source before aborting its destination; once expired, it can never be resumed. |
| + Commitment rechecks identity, cap reservation, source hold acknowledgment, lifetime and deadline under the ordered locks. At this point use `checkRunningThings(ctx, acct, 0)` because the reservation already counts; do not count the app and instance twice. Atomically record the irreversible decision, clear the claim token hash, invalidate other flows and enqueue all completion work. Seed opening follows that decision. A durable outbox retries opening, moved publication and Plan 1 retirement; status stays `claiming` until these finish. Extend the existing job runner/startup/backstop to drain SQL work and react to stream acknowledgments; status reads SQL only. The source's original expiry remains intact; extend the merged `retireDemoLocked` and `Retirement.valid` to permit an early committed claim. Reuse the existing SQL serving-revision fence, signed receipt validation and `demoWorker.retireDemo` cleanup: stop traffic, stop-before-delete, purge local counters, acknowledge local purge, clear the data-initialization marker, acknowledge completion and release the ceiling. Preserve operator takedown and its retry behavior. Do not let the expiry loop purge an uncommitted source before aborting its destination; once expired, it can never be resumed. |
| Before commitment, abort closes all destination traffic first, CASes only this seed to aborted, and waits for normal seed/instance cleanup proof before releasing source. Retain uncertain cleanup and report it through status; console unavailability is not permission for either box to reopen. After commitment, errors are recovery work, never rollback. Keep unfinished work running when admission is switched off. |
| - [ ] **Step 4: Rerun Step 2**, including existing demo publication/expiry/settlement regressions. Inject failures before and after every irreversible boundary; expect PASS without a second claim or data loss. |
| @@ -272,12 +274,12 @@ TestDemoClaimRequestCost: idle/repeatedStatus/unchangedTick => zeroAdditionalSto |
| **Files:** |
| - Create: `internal/democlaim/moved.go`, `internal/console/demo_claim_moved.go`, `internal/host/demo_moved.go`, `internal/edge/demo_moved.go`. |
| -- Modify: `internal/release/changeindex.go:50`, `internal/host/changeindex.go:180`, `internal/edge/demo.go:18`, `internal/edge/edge.go:1890`, `internal/registry/registry.go`. |
| +- Modify: `internal/release/changeindex.go:50`, `internal/host/changeindex.go:180`, `internal/edge/demo.go:104`, `:207`, `internal/edge/demo_traffic.go:142`, `internal/edge/edge.go:1900`, `internal/registry/registry.go`. |
| - Test: `internal/democlaim/moved_test.go`, `internal/host/demo_moved_test.go`, `internal/edge/demo_moved_test.go`. |
| **Interfaces:** |
| - Produces: `democlaim.Moved {DemoID, Host, TargetHost string; ExpiresAt int64}` and `SignMoved(priv ed25519.PrivateKey, rows []Moved) ([]byte,error)`, `VerifyMoved(pub ed25519.PublicKey, wire []byte) ([]Moved,error)`; separator `carlos demo moved v1\n`. |
| -- Produces: `(*Server).publishDemoMoved(ctx context.Context) error`, `(*Edge).serveDemoMoved(w http.ResponseWriter, r *http.Request, host string) bool`. |
| +- Produces: `(*Server).publishDemoMoved(ctx context.Context) error`, `(*Edge).serveDemoMoved(w http.ResponseWriter, r *http.Request, host string) bool`. The latter supplies the signed-notice lookup/rendering behind the already-merged `(*Edge).demoMovedPage(w http.ResponseWriter, r *http.Request, host string) bool`; replace its inert body rather than add a second lifecycle hook. |
| - Console publishes `control/demo-moved.json`, a complete signed snapshot capped at 1 MiB/10,000 entries, after a committed destination is open. SQL source is independent of `apps` and source purge. Registry stores the verified snapshot separately from live routes; Edge revalidates signed bytes on load. |
| - [ ] **Step 1: Write failing tests.** |
| @@ -289,9 +291,9 @@ TestDemoMovedDelivery: changedScope => oneSnapshotRead; unchangedTicks => zeroRe |
| ``` |
| - [ ] **Step 2: Run** `go test ./internal/democlaim ./internal/host ./internal/edge -run 'TestDemoMoved' -count=1`; expect FAIL. |
| -- [ ] **Step 3: Implement the minimal Plan 2 hook.** Register one control scope on the existing watch. Load at startup and on its changed generation in the existing pass, not in a new ticker; require the shared watch for activation. Preserve a verified mapping across refresh failure only until its signed expiry. Extend the existing demo stream with the same signed snapshot if a serving demo-fleet edge needs it; it never polls the bucket. Require exact one-label demo hosts and derive TargetHost from the committed target account/app, under configured AppsDomain, with no scheme/path/port supplied by users. Reject overflow before claim commitment by reserving notice capacity. Keep notices monotonic for a never-reused host. |
| +- [ ] **Step 3: Complete the merged Plan 2 hook and notice delivery.** Register one control scope on the existing watch. Load at startup and on its changed generation in the existing pass, not in a new ticker; require the shared watch for activation. Preserve a verified mapping across refresh failure only until its signed expiry. Extend the existing demo stream with the same signed snapshot if a serving demo-fleet edge needs it; it never polls the bucket. Require exact one-label demo hosts and derive TargetHost from the committed target account/app, under configured AppsDomain, with no scheme/path/port supplied by users. Reject overflow before claim commitment by reserving notice capacity. Keep notices monotonic for a never-reused host. |
| - At the demo-domain entry, before lookup, cache, caps, upgrade or activation, serve a small escaped HTML page for GET and headers-only HEAD; other methods receive 410 and no forwarding. Use 200 for the page, `Cache-Control: no-store`, `Referrer-Policy: no-referrer`, `X-Content-Type-Options: nosniff`, and restrictive CSP with no scripts/forms/external resources. Link to `https://` plus TargetHost only; no automatic redirect, cookie or claim link. Plan 2 can call this hook before its generic demo states when it lands. Purging the source must never delete this independent notice or the permanent name tombstone. |
| + Plan 2 already calls `demoMovedPage` from `serveDemoTraffic` after live-route and serving checks. That call cannot cover a purged source or a held route. Add the signed notice check to `handleDemoRequest` at the demo-domain entry before live-route lookup/refusal, cache, caps, upgrade or activation, and serve a small escaped HTML page for GET and headers-only HEAD; other methods receive 410 and no forwarding. Use 200 for the page, `Cache-Control: no-store`, `Referrer-Policy: no-referrer`, `X-Content-Type-Options: nosniff`, and restrictive CSP with no scripts/forms/external resources. Link to `https://` plus TargetHost only; no automatic redirect, cookie or claim link. Use the existing `demoMovedPage` hook for this check and retain Plan 2's ordinary demo handling when it returns false. The moved notice must not depend on the retired source's serving-control membership or local counter row. Purging the source must never delete this independent notice or the permanent name tombstone. |
| - [ ] **Step 4: Rerun Step 2**, plus existing `TestDemo` edge tests and change-index request-count tests; expect PASS. |
| - [ ] **Step 5: Commit** with subject `feat: show moved notices for claimed demo hosts`. |
| @@ -301,7 +303,7 @@ TestDemoMovedDelivery: changedScope => oneSnapshotRead; unchangedTicks => zeroRe |
| **Files:** |
| - Create: `internal/console/demo_claim_page.go`, `internal/console/templates/demo_claim.html`, `internal/console/static/demo_claim.js`. |
| -- Modify: `internal/console/apidemo.go:269`, `internal/console/emailsignin.go:258`, `internal/console/server.go:3889`, Task 1 purpose-link dispatch and flow storage. |
| +- Modify: `internal/console/apidemo.go:272`, `internal/console/emailsignin.go:258`, `internal/console/server.go:3892`, Task 1 purpose-link dispatch and flow storage. |
| - Test: `internal/console/demo_claim_page_test.go`, `internal/console/demo_claim_browser_test.go`. |
| **Interfaces:** |
| @@ -331,7 +333,7 @@ TestDemoClaimBrowserRecovery: returnFromOAuth => sameIntent; pageReload => statu |
| **Files:** |
| - Create: `internal/console/demo_claim_e2e_test.go`, `internal/host/demo_claim_dev_linux_test.go`. |
| -- Modify: `internal/demo/config.go:22`, `cmd/console/main.go:478`, `internal/console/apidemo.go:439`, `README.md` anonymous-demo operator section; Task 7 page copy and claim API documentation alongside that section. |
| +- Modify: `internal/demo/config.go:22`, `cmd/console/main.go:478`, `internal/console/apidemo.go:448`, `README.md` anonymous-demo operator section; Task 7 page copy and claim API documentation alongside that section. |
| - Generate during implementation: `internal/provision/testdata/plan14-root-reads-agent-start-demo-3.tsv`, census chain entry and `docs/superpowers/notes/census-proposal-agent-start-demo-3.md` with proposal tooling and independent dispositions. |
| **Interfaces:** |
| @@ -349,7 +351,7 @@ TestDemoClaimOffCompatibility: switchUnset => noNewBehaviorOrStorePolls; switche |
| ``` |
| - [ ] **Step 2: Run** `go test ./internal/console ./internal/host -run 'TestDemoClaim(EmailToPermanent|FailureKeepsDemo|DevAcceptance|OffCompatibility)' -count=1`; demonstrate the integration witness fails with the coordinator disconnected. A gated dev skip is outstanding evidence. |
| -- [ ] **Step 3: Finish activation wiring and approved copy.** Run the copy review table through the repository's copy workflow before putting strings in product files. Update operator/API documentation and `claimAvailable`; no CLI verb is added. Build test binaries on the workstation and exercise the real dev boxes through APIs with those binaries. Use the existing demo wildcard and housekeeper certificate path, console drop-in and normal destination placement. Record account selection, plan refusal, WAL contents, artifact digest, destination first replica, old URL notice, expiry and interrupted-copy recovery. Dev switches on when the implementation lands; provisioning/DNS/IAM changes, if discovered necessary, need a concrete scoped approval before execution. This plan does not grant it. |
| +- [ ] **Step 3: Finish activation wiring and approved copy.** Run the copy review table through the repository's copy workflow before putting strings in product files. Reuse the merged `--socket`/`--db` SQLite starter at `internal/console/testdata/demo/main.go:15` for the claim integration witness. Update operator/API documentation and `claimAvailable`; no CLI verb is added. Build test binaries on the workstation and exercise the real dev boxes through APIs with those binaries. Use the existing demo wildcard and housekeeper certificate path, console drop-in and normal destination placement. Record account selection, plan refusal, WAL contents, artifact digest, destination first replica, old URL notice, expiry and interrupted-copy recovery. Dev switches on when the implementation lands; provisioning/DNS/IAM changes, if discovered necessary, need a concrete scoped approval before execution. This plan does not grant it. |
| - [ ] **Step 4: Run the final implementation gate once.** Targeted tests first, then repository-required `go build ./...`, `go vet ./...`, `go test ./... -count=1`, whole-tree gofmt check and prescribed cross-build/CI gate. Use the default Go cache; no compilation on demo boxes. Run `make census-card`, write unit claims, then `make census-propose NAME=agent-start-demo-3 CLAIMS=<claims-file>`; independently review every unit/envelope against amadan main and record verdict on #280. Whole-branch review follows the budget below. These commands belong to the future implementation session; none is required for authoring this document. |
| - [ ] **Step 5: Commit** with subject `test: prove email claims preserve demo apps and data`. Describe, push and squash-land the implementation branch through amadan after tip CI is green; inspect main CI afterward. Stop at this one visible merge. |
| @@ -378,10 +380,23 @@ This is a string inventory, not approved wording. All new human-facing strings b |
| Independent plan review rounds in this authoring session: **0**. No agents were spawned. Plan 1's controller rulings and review history remain settled dependencies; this is a new Plan 3 change, not a reopening of Plan 1. Use `docs/superpowers/reviews/REVIEW-BRIEF-TEMPLATE.md` for implementation briefs, carrying the round history and each finding's invariant. Tasks 1 through 7 require independent review for their marked risks; Task 8 receives the whole-branch review. For a Codex author, use Opus or Fable for other-family census and authority review. |
| -Stop at the first round with no P1. Apply that round's P2 fixes without a new general review, retaining census and checks of newly changed security/root/termination/production-storage behavior. Record P3s as follow-ups. Maximum three rounds; a fourth needs Paul's decision. Two consecutive rounds in one fault family trigger the stop-and-choose rule. No review against unmerged Plan 2. The implementation session owns this one plan and ends at its merge; carry the three-day/three-compaction and 24-hour reporting limits from AGENTS.md. |
| +Stop at the first round with no P1. Apply that round's P2 fixes without a new general review, retaining census and checks of newly changed security/root/termination/production-storage behavior. Record P3s as follow-ups. Maximum three rounds; a fourth needs Paul's decision. Two consecutive rounds in one fault family trigger the stop-and-choose rule. Plan 2 is now a merged dependency at `f86e9792`; do not reopen its settled review or rulings. The implementation session owns this one plan and ends at its merge; carry the three-day/three-compaction and 24-hour reporting limits from AGENTS.md. |
| Self-review: design §4.5 maps to Tasks 1/7 (email and Keymail), 2 (account choice/authorization/caps), 3/4/5 (same artifact and quiesced local SQLite into a normal permanent app), 5 (single-use token and retirement), 6 (moved page), and 8 (visible dev activation). The no-credential decision avoids granting an agent service roles, account scope or credential recovery; Task 1's continuation dies as a mutation capability when the one operation is reserved. The five Review Focus cases have named owning tests. Shared operation/flow/seed identities and signatures match across tasks. No production function bodies or full test suite were run or written during planning. The supported-placement boundary is explicit: ordinary placement is checked first, existing seed restrictions are retained, and an unsupported result refuses before stopping the demo. |
| ## Open questions |
| None for Paul. Builder choices above are marked “my call”; copy approval and any scoped infrastructure rollout approval are execution gates, not unresolved product decisions. |
| + |
| +## Refresh against merged Plan 2 (2026-11-05) |
| + |
| +- The baseline and review note said Plan 2 had not landed at `2914921c`. Base `e129f535` includes `f86e9792` and `b40c2c1f`, with the hook at `internal/edge/demo.go:207`; the plan now names those merged dependencies and both rulings files. |
| +- The console table and Modify lists used old anchors. Current anchors are `internal/console/demo_store.go:311`, `:342`, `:348`, `:386` (formerly 292, 323, 329, 364), `internal/console/apidemo.go:260`, `:272`, `:448` (259, 269, 439), and `internal/console/demo_jobs.go:376`, `:452` (371, 447). The plan now uses those locations and points directly to the state CHECK at `internal/console/demo_store.go:63` instead of the table start at 58. |
| +- The identity/account references used pre-merge line numbers. Current anchors are `internal/console/server.go:3090`, `:3148`, `:3792`, `:3857`, `:3892`, `:5420` (formerly 3087, 3145, 3789, 3854, 3889, 5417), and `internal/console/plancaps.go:171`, `:234`, `:281`, `:314` (167, 230, 277, 310). The table and affected Modify lists now point there; unchanged anchors were checked and retained. |
| +- The transport/routing references used old anchors. Current anchors are `internal/console/apidemobox.go:97`, `:202` (formerly 93, 191), `internal/demobuild/job.go:162` (160), `internal/host/demo_jobs.go:344` (335), `internal/host/agent.go:1010` (988), `internal/edge/demo.go:134`, `:143`, `:197` (18, 27, 81), and `internal/edge/edge.go:1900` (1890). The plan now uses these locations and pins private dispatch to `main.go:37` instead of the blank line at 20 or command extraction at 36. |
| +- Task 6 said it would supply a hook for a future Plan 2. `demoMovedPage` already exists at `internal/edge/demo.go:207`, called from `internal/edge/demo_traffic.go:142` after live-route/serving checks; `serveDemoTraffic` at `:128` already bypasses ordinary caches and shortcuts. Task 6 now completes that hook with signed notices and adds the route-independent check at `internal/edge/demo.go:104` needed after source purge, preserving the planned page protocol. |
| +- Task 5 proposed extracting time-only retirement into a new typed-reason function. `internal/console/demo_expiry.go:83` already wraps `retireDemoLocked` at `:104`, accepting `expired`/`operator`; `internal/demobuild/retirement.go:13`, `:26` already carry and validate signed reasons. Task 5 now extends those functions for committed `claimed` retirement while retaining operator and legacy expiry behavior. Retirement anchors now use `internal/console/demo_expiry.go:167`, `:223`, `:290` instead of 125, 174, 241. |
| +- The plan described source freeze and purge without Plan 2's local counters. `internal/host/demo_traffic.go:102`, `:207` initialize/purge them; `internal/host/demo_serving.go:108` applies `ServingDemo.Initialize`, and `internal/host/demo_cleanup.go:68` already stops traffic, purges counters and acknowledges. Tasks 3/5 now preserve counters through freeze/abort and reuse cleanup. Task 3 distinguishes reversible holds from the permanent fences at `internal/host/demo_serving.go:238` and `internal/host/demo_traffic.go:249`. |
| +- Task 3 proposed claim fields against the older stream. `internal/demobuild/job.go:139`, `:162` now contain serving probes/acks and control messages, with `EmptyBuild` at `:183`; `internal/host/demo_serving.go:72` builds the heartbeat. Task 3 now adds claim fields alongside these, preserving serving initialization/acknowledgment and build-readiness behavior, and names the heartbeat file in its Modify list. |
| +- The binary-flags row relied on commissioning facts overriding older fixtures. The merged SQLite starter parses `--socket`/`--db` at `internal/console/testdata/demo/main.go:16`, matching unchanged launcher arguments at `internal/activator/backend_exec.go:2530`, `:2733`. The row and Task 8 now name that reusable fixture and distinguish the empty validation fixture at `internal/demobuild/testdata/starter/main.go:5`. |
| +- The plan named the normal free-account check without its newly merged exemption. `internal/console/plancaps.go:171` now exempts `opsOwner`; the existing-interface table records that behavior while Task 2 continues to use the normal helper without adding a claim-specific allowance. |