carlos / platform Public

fix: keep stateful wakes unchanged around the stateless branch

Restore stateful acquire/restore before identity selection and publication,
keep config admission inside Acquire, and retain legacy fallback-error
classification. Retry deployment-store opens and preserve DemandHold for
stateful builds whose canonical manifest cannot be read.

Use existing reconcile observations for stateless release preparation, then
read the instance record once at the backend final exec gate. Check current
placement, lifetime and released deploy after preparation and pending writes.
Keep both hold and overlap launches subject to that fresh check.

Add regression witnesses for every round-1 finding, refresh the cumulative
census proposal, and inventory the context-key references. Targeted Task 3,
121 stateful/exec-gate regressions, canonical/rollout/index checks and root
and record-write censuses pass. Darwin, Windows and Linux arm64 builds pass.
Independent follow-up and census review remain with the controller.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by claude agent, operated by paul@keymail.dev 9fe9b0dc3a298f6a660606356886dcbac4345675 parent 37f894e
19 files changed, +967 −215
  • docs/superpowers/notes/census-proposal-stateless-replicas-1.md +19 −15
  • internal/activator/activator.go +103 −80
  • internal/activator/genbackend.go +11 −3
  • internal/activator/stateless.go +95 −32
  • internal/activator/stateless_fix1_test.go +383 −0
  • internal/activator/stateless_test.go +29 −8
  • internal/activator/swap.go +1 −0
  • internal/activator/swaphold.go +6 −1
  • internal/activator/wakeplan.go +14 −6
  • internal/host/agent.go +40 −7
  • internal/host/rollout.go +2 −2
  • internal/host/stateless_runtime_test.go +84 −0
  • internal/provision/lifetimeindex.go +37 −3
  • internal/provision/stateless_replicas_census_test.go +11 −0
  • internal/provision/testdata/plan14-root-reads-chain.tsv +1 −1
  • internal/provision/testdata/plan14-root-reads-stateless-replicas-1.tsv +37 −29
  • internal/release/runtime_selection.go +29 −27
  • internal/release/runtime_selection_test.go +19 −1
  • internal/rollout/stateless_selection_test.go +46 −0

CI failed — run details

Intent

Human

<task-notification> <task-id>bq2voktuu</task-id> <tool-use-id>toolu_01PbudkiTAP5D4VjMdkcGh7M</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/412bbef6-9468-4e8d-b9fe-5343bad21de8/tasks/bq2voktuu.output</output-file> <status>completed</status> <summary>Background command "Wait for 3b" completed (exit code 0)</summary> </task-notification>

Human

<task-notification> <task-id>adacffe8f2908227d</task-id> <tool-use-id>toolu_016JmibBiWXHnSnSmoSWejZf</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/412bbef6-9468-4e8d-b9fe-5343bad21de8/tasks/adacffe8f2908227d.output</output-file> <status>completed</status> <summary>Agent "Review Task 3b (spec + quality)" 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>### Spec Compliance - ✅ **Escrow authority applies only to stateless.** `holdsEscrowAuthority` (escrow_authority.go:16) uses `holdsLease` unchanged for stateful rows. Every one of the five former `holdsLease` call sites now goes through it. For stateful rows, the mint-guard wrapper, the restore error wrapping and the new branches in `escrowedLaunchEnv` all leave behaviour as it was. Conflict marker, bucket-knowledge (`known`), keyless and first-launch protections are untouched. - ✅ **A follower cannot mint or publish.** `followerEscrowEnv` never opens a publisher or the sweep. `restoreEscrowIfMissing` has no lease or publisher call (checked). The mint wrapper checks authority again on every call, so a once-cached verdict cannot outlive Lost. A cold start with no trio refuses with the waiting sentinel. A partial trio, a failed read or a divergent secret also refuses. Divergence reuses `escrowDivergence` and `escrowConflictFound`. - ✅ **Authority loss does not stop web or workers.** No new path connects Lost to termination. The `serving` subtest witnesses this. - ✅ **Bindings.** The OnWake and startup writers skip stateless rows (fleetbind.go:368, `residentBindingHosts`). The coordinator writes the existing `fleets/&lt;fleet&gt;/bindings/&lt;host&gt;.json` key through the existing GET/CAS. It needs exact-lifetime `Held(id)` and checks authority before each Put. The trigger is the existing `backstopFullDue` and fast-loop full pass, with no new loop. The only other writers are those two hooks. Renewals cause no request. There is no new listing: the write's own GET is the existing read, and it runs only on a state change. - ✅ **Litestream.** `FleetDBsWithSkipped` drops stateless paths, including unit trees that reach into them. `HibernatingHosts` (hibernate_verify.go:60) already excludes stateless rows from maintenance. I found no other vacuum/checkpoint/backup reader of `DBPath` outside the shelved claim path. - ✅ **SR-1-C06** is verbatim (stateless.go) and listed in the built inventory. - ⚠️ **The binding failure path breaks the "existing pass" contract** (see Important 1). ### Strengths - The mint guard checks live authority on every call, and the mutation run was aimed exactly at that. - The follower path requires every sealed member of the trio to be published before it trusts local files. - The binding writer checks authority immediately before both Put calls. - The publisher re-checks the record against the route (assignment time, account and box) before writing. - The litestream overlap guard (`inactive`) stops another unit's tree from claiming the stateless database again. - The tests use a real `DirStore`, real sealing and real preparation helpers. ### Issues **Important** 1. **A binding error aborts the whole reconcile pass** (internal/provision/reconcile.go:2105-2108). - What: `if err := cfg.StatelessBinding(...); err != nil { return err }`. Any binding failure ends `Reconcile` for every host on the box. That includes a transient bucket error, a CAS conflict lost twice, a denied Put, `replicas.ErrFenced` from losing authority between `Held` and Put, and an `Incarnation` error. The pass stops before mints, converges, `pr.applied` and the removal phase run for the remaining records. Every other per-host failure in this loop (`SetSeedSource`, `SetSeed`, …) logs and moves on. - Why: one stateless instance's binding object, which is not a record, can stall convergence for the whole box. Losing authority is a normal event, not an exceptional one. A persistent Put failure wedges the box on every pass. - Fix: log the error and continue. The publisher already leaves its cache unacknowledged on failure, so the next pass retries. Add a witness that a failing callback still converges a second record in the same pass. **Minor** 2. **The waiting sentinel covers too many errors** (escrow.go:1000-1004, escrow_authority.go:36-38, logsink.go:80). - What: every stateless restore or follower error, including an ALERT conflict or divergence, reaches the member as "waiting for the instance's shared secrets. existing copies keep serving". - Why: a permanent conflict that needs an operator reads to the member as a temporary wait. On a first copy, "existing copies keep serving" is also untrue. Operator logs still carry the ALERT. - Fix: wrap only the not-ready, absent and read-failed cases, and let conflict and divergence go through the normal rendering. 3. **The follower reads the same sealed items twice** (escrow_authority.go:63-71). - What: the first loop reads and discards every sealed item. `restoreEscrowIfMissing` then reads the missing ones again, and `envDivergence` reads the env a third time. A cold launch costs up to about 7 GETs where about 4 would do. - Why: this happens once per launch, so it stays inside the budget, but it is wasted work. - Fix: check manifest presence only, and let restore and divergence surface read failures. 4. **A follower restarted before its first publish can wait forever** (escrowedLaunchEnv follower branch; the cause is the acquisition seam in 3a/Task 2). - What: `PrepareStatelessRelease` returns early when the deploy is already `released`, before `Acquire`. Suppose the first publish failed (launch held) and then the agent restarted. The box now has no authority and no trio, so it waits for an initializer that never comes. That lasts until the next deploy, unless Task 2's tick acquires again. - Fix: the controller should confirm that some acquisition trigger exists for a box that holds the assignment but has no published trio. 5. **The import block in fleetbind.go is out of order** (fleetbind.go:9-16): `"time"` sits after the internal imports. gofmt accepts it, but stdlib and internal packages are mixed in one group. 6. **The publisher holds `p.mu` across network I/O** (fleetbind.go:484). This is harmless while reconcile is serialized; it is noted in case that changes. ### Census - `internal/activator/escrow_authority.go` holdsEscrowAuthority / followerEscrowEnv: **approve**. Reads stay beneath the data dir with a size limit (`ReadBeneathLimit`). Bucket reads go through the existing sealed or manifest path, keyed by a registry host. - `internal/activator/escrow.go` (mint guard, restore, launch env, sweep): **approve**. Only the authority predicate changed. No new path or input. - `internal/host/fleetbind.go` writeFleetBinding / statelessBindingPublisher.publish: **approve**. It writes the fixed binding key built from the configured fleet and the platform-validated record host, gated by authority. - `internal/provision/reconcile.go` Reconcile: **approve**. It is a callback on a record this pass already read. No new key or read. - `internal/ops/litestream.go` FleetDBsWithSkipped: **approve**. The change only removes paths from the replication set. It opens or follows nothing new. - `internal/host/agent.go` wiring: **approve**. - The record-write inventory notes (WriteFleetBinding moved into writeFleetBinding as a non-record writer) match the code. - Answer to the census question: no. No root read now opens, runs, queries or follows a path or input that a tenant, app or box agent can create or name. ### Assessment **Task quality:** Needs fixes **Reasoning:** The escrow and authority split is right. Stateful behaviour is unchanged, followers cannot mint or publish, and bindings and litestream meet the budget. But a stateless binding write failure, including a routine authority loss, aborts the box's entire reconcile pass (reconcile.go:2107). It must log and continue like the loop's other per-host failures.</result> <usage><subagent_tokens>101590</subagent_tokens><tool_uses>23</tool_uses><duration_ms>223750</duration_ms></usage> </task-notification>

Attributed to this commit: 9.06 g CO₂e (1,104,319 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on stateless-replicas-1-runtime, 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.

docs/superpowers/notes/census-proposal-stateless-replicas-1.md

Loading diff…

internal/activator/activator.go

Loading diff…

internal/activator/genbackend.go

Loading diff…

internal/activator/stateless.go

Loading diff…

internal/activator/stateless_fix1_test.go

Loading diff…

internal/activator/stateless_test.go

Loading diff…

internal/activator/swap.go

Loading diff…

internal/activator/swaphold.go

Loading diff…

internal/activator/wakeplan.go

Loading diff…

internal/host/agent.go

Loading diff…

internal/host/rollout.go

Loading diff…

internal/host/stateless_runtime_test.go

Loading diff…

internal/provision/lifetimeindex.go

Loading diff…

internal/provision/stateless_replicas_census_test.go

Loading diff…

internal/provision/testdata/plan14-root-reads-chain.tsv

Loading diff…

internal/provision/testdata/plan14-root-reads-stateless-replicas-1.tsv

Loading diff…

internal/release/runtime_selection.go

Loading diff…

internal/release/runtime_selection_test.go

Loading diff…

internal/rollout/stateless_selection_test.go

Loading diff…