carlos / platform Public

escrow: record absent shared files; a copy joins with them (#511)

Drill 1, ruling R21b: escrow completeness uses explicit absence.

A stateless host's coordinator now records, under its term, which trio
files are absent here: for each of instance.key and report.token with
no file, no published item and no marker, it stages a plaintext marker
"<item>.absent" ({"v":1}, never a secret) through the new
hostfiles.Publisher.StageSealedAbsent. Publishing the item later drops
its marker, and a published item always wins over a marker.

escrowComplete: the sealed env present, and every other sealed item
published or recorded absent. followerEscrowEnv and
prepareStatelessEscrow use it. A joining copy reads, restores and holds
to its local copy exactly the published items. A listed item that
cannot be read still refuses, which halts a join (SR-4-C83).

Older escrows: a manifest with no absence recorded stays incomplete,
as before, until its coordinator upgrades it at its next publish under
its term: the next launch or, with nothing changed on disk, the next
30 s escrow sweep. escrowChanged counts such a host as changed once per
process on the box holding the authority. Followers never write.

The publication guard admits StageSealedAbsent as it admits
StageSealed: its argument must be a classified SealedRel.

Witness: TestStatelessEscrowRecordsAbsence (never written joins with
complete secrets; written reach the joining copy, including one written
after the first publish; listed but unreadable refuses; an older escrow
is upgraded by the coordinator's sweep).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 78966b17070d957ca12ba98bbb3584d9b78d2e9b parent 66095ed
5 files changed, +281 −13
  • internal/activator/escrow.go +79 −2
  • internal/activator/escrow_authority.go +11 −9
  • internal/activator/replica_drill1_test.go +148 −0
  • internal/hostfiles/sealed.go +39 −0
  • internal/layout/pubclass/publication_guard_test.go +4 −2

Intent

Human

<task-notification> <task-id>a3447eef93b8e73dc</task-id> <tool-use-id>toolu_01GRuaPu6BwskfB2dEJmnRP2</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/72128d15-58b8-452f-9f7e-8e864e8854d2/tasks/a3447eef93b8e73dc.output</output-file> <status>completed</status> <summary>Agent "Fix drill-1 findings on Plan 4" 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>Status: DONE_WITH_CONCERNS. All four findings are fixed with witnesses, but R21's main root cause needs your ruling: a copy can never join an app that doesn't write instance.key and report.token itself. **Commits** (on stateless-replicas-4, not pushed): - ad96a35c: raising copies is a join on the same attempt, through the existing permit, proof and ACK path, and the running copy keeps serving (R18, F4) - 3fdfa552: a join whose new copy can't get the shared secrets now halts with a clear refusal (R21) - 340b4198: the release waits for the instance's config, and `instances retry` works at copies 1 (R20) - 736b8ce9: the copies door checks room for the app's size, and placement never removes a running copy (R19) - 6295f1bc: copy rows SR-4-C83 to C89, approved (controller; Luna house rules), and docs; 66095ed9: census stateless-replicas-4-drill1 (`make census-card` clean, record-write census green) **Tests:** 12 new witnesses pass; each fails without its fix, mostly with the drill's own message. The neighbouring targeted suites, the region HA guards and the three cross-compiles all pass. **Concerns:** - **R21 needs a decision.** Escrow counts as complete only with instance.key and report.token, files only the app itself writes; the drill's Go fixture never does. Every join of such an app now halts cleanly instead of waiting forever. Options: an absence marker, accept env.sealed alone, or have the fixture write both files. - **A box added after a deploy is done** still starts with no permit, and its escrow wait has no bound. I left this alone because changing it would change how returning boxes behave. - **The 6-minute gap with no permit on srdrill is unexplained:** both evidence journals are cut at 24 KB, before the fixture existed. - **Instances on older builds:** a copies-1 instance whose release passed before this build gives its serving box the first permit. For that one step it can't restart. - **Smaller:** the config wait has no upper bound. Blocked placement shows only in the console log. Each commit printed a `packed-refs.lock` warning from another process; all six landed, and I didn't touch the lock. Report: /home/paulca/amadan.net/carlos/platform/.claude/worktrees/stateless-replicas-4/.superpowers/sdd/2026-11-01-stateless-replicas-4-deploy-and-drill/task-drill1-report.md</result> <usage><subagent_tokens>583428</subagent_tokens><tool_uses>237</tool_uses><duration_ms>3750346</duration_ms></usage> </task-notification>

Human

Is that all running now?

diff --git a/internal/activator/escrow.go b/internal/activator/escrow.go
index b72162b15..8ae4dba01 100644
--- a/internal/activator/escrow.go
+++ b/internal/activator/escrow.go
@@ -186,6 +186,12 @@ type escrowState struct {
// offLogged: this process has said once that escrow is off for the
// host (escrowOff).
offLogged bool
+ // absence: a stateless host's escrow records, as of this process's
+ // last publish under authority, which trio files are absent here
+ // (escrowAbsentItem; #511 drill 1, R21b). Until it does, the sweep
+ // publishes the host even with no file changed, so an escrow an older
+ // build wrote is upgraded by its coordinator's next sweep or launch.
+ absence bool
}
// escrowBook is the backend's escrow state: one escrowState per host, the
@@ -708,6 +714,33 @@ type escrowRead struct {
plain []byte
stamp *statStamp // nil: none to keep (the launch's capture, a refusal, a stamp too recent)
stage bool
+ // absent: the file is not here (a trio file the app never wrote).
+ absent bool
+}
+
+// escrowAbsentItem is the platform item that records, for a stateless
+// host, that r's file was absent when its coordinator published (#511
+// drill 1, R21b): its plaintext is escrowAbsentBody, never a secret. An
+// escrow is complete for a joining copy when every trio item is either
+// published or recorded absent (escrowComplete). A published item wins
+// over its marker, and the coordinator removes the marker when it
+// publishes the item.
+func escrowAbsentItem(r pubclass.SealedRel) string { return hostfiles.SealedAbsentItem(r) }
+
+// escrowComplete reports whether m holds everything a joining copy needs:
+// the sealed env, and each other sealed item published or recorded
+// absent. A manifest from an older build, which records no absence, is
+// complete only with every item published, as before.
+func escrowComplete(m hostfiles.Manifest, lay pubclass.Layout, host string) bool {
+ for _, rel := range pubclass.SealedRels(lay, host) {
+ if _, ok := m.Platform[rel.Item()]; ok {
+ continue
+ }
+ if _, absent := m.Platform[escrowAbsentItem(rel)]; !absent || rel.Item() == hostfiles.SealedEnvItem {
+ return false
+ }
+ }
+ return true
}
func (b *ExecBackend) publishEscrowLocked(ctx context.Context, rt registry.Route, p instancePaths, lay pubclass.Layout, st *escrowState, env []byte) (escrowPublish, error) {
@@ -750,8 +783,9 @@ func (b *ExecBackend) publishEscrowLocked(ctx context.Context, rt registry.Route
refused = append(refused, fmt.Errorf("%s: %w", r.Rel(), err))
reads = append(reads, escrowRead{rel: r})
case unchanged || s.absent:
- // Absent stages nothing: absence never deletes an escrow.
- reads = append(reads, escrowRead{rel: r, stamp: stamp})
+ // Absent stages nothing: absence never deletes an escrow. A
+ // stateless host records it (escrowAbsentItem) below.
+ reads = append(reads, escrowRead{rel: r, stamp: stamp, absent: s.absent})
default:
reads = append(reads, escrowRead{rel: r, plain: body, stamp: stamp, stage: true})
}
@@ -760,6 +794,13 @@ func (b *ExecBackend) publishEscrowLocked(ctx context.Context, rt registry.Route
for _, r := range reads {
staging = staging || r.stage
}
+ // A stateless host's escrow says which trio files are absent (R21b):
+ // until this process has recorded it, the publish opens the escrow to
+ // check, and stages a marker for each absent file it lacks.
+ markAbsence := rt.Stateless
+ if markAbsence {
+ b.escrow.with(func() { staging = staging || !st.absence })
+ }
// keep records what was read: an item with a stamp is the publisher's
// as of that stamp; the launch's capture, or a refused item, leaves
// none, so the next sweep reads it.
@@ -795,6 +836,32 @@ func (b *ExecBackend) publishEscrowLocked(ctx context.Context, rt registry.Route
if err := b.stageEscrowReads(ctx, rt, p, pub, seal, reads); err != nil {
return out, err
}
+ decided := len(refused) == 0
+ if markAbsence {
+ m, err := baselineManifest(before)
+ if err != nil {
+ return out, fmt.Errorf("%w: %w", errEscrowUnreadable, err)
+ }
+ for _, r := range reads {
+ item := r.rel.Item()
+ if item == hostfiles.SealedEnvItem {
+ continue
+ }
+ marker := escrowAbsentItem(r.rel)
+ _, published := m.Platform[item]
+ _, marked := m.Platform[marker]
+ switch {
+ case r.absent && !published && !marked:
+ if err := pub.StageSealedAbsent(ctx, r.rel); err != nil {
+ return out, err
+ }
+ case r.stage && marked:
+ if err := pub.StagePlatformDelete(marker); err != nil {
+ return out, err
+ }
+ }
+ }
+ }
// Any raw secret an older box published under this prefix goes in the
// same commit (manifest only, no object deleted).
if err := pub.DropRawSecrets(rawSecretEntries); err != nil {
@@ -828,6 +895,9 @@ func (b *ExecBackend) publishEscrowLocked(ctx context.Context, rt registry.Route
out.base, out.exists = after, escrowedIn(after)
out.committed = before.ETag != after.ETag || before.Found != after.Found
keep()
+ if markAbsence && decided {
+ b.escrow.with(func() { st.absence = true })
+ }
if !out.committed {
// Nothing was written (the staged bytes were already escrowed), so
// nothing was learned about the bucket: a publisher opened from the
@@ -1435,6 +1505,13 @@ func (b *ExecBackend) escrowChanged(rt registry.Route, p instancePaths, lay pubc
if pub != nil && pub.Dirty() {
return true
}
+ // A stateless host whose escrow does not yet record its absent trio
+ // files, on the box that may publish it (R21b).
+ absence := true
+ b.escrow.with(func() { absence = st.absence })
+ if rt.Stateless && !absence && b.holdsEscrowAuthority(rt) {
+ return true
+ }
for _, r := range pubclass.SealedRels(lay, rt.Host) {
prev, ok := stamps[r.Item()]
if !ok {
diff --git a/internal/activator/escrow_authority.go b/internal/activator/escrow_authority.go
index 1e68af3a5..d7f911ba9 100644
--- a/internal/activator/escrow_authority.go
+++ b/internal/activator/escrow_authority.go
@@ -60,10 +60,15 @@ func (b *ExecBackend) followerEscrowEnv(ctx context.Context, rt registry.Route)
return refuse(err)
}
var reads []escrowRead
+ // Every member must be published and readable, even if it exists
+ // locally, or recorded absent by the coordinator (R21b): a copy joins
+ // with exactly what exists. A listed item that cannot be read refuses.
+ if !escrowComplete(m, lay, rt.Host) {
+ return refuse(ErrEscrowNotReady)
+ }
for _, rel := range pubclass.SealedRels(lay, rt.Host) {
- // Every member must be published and readable, even if it exists locally.
if _, ok := m.Platform[rel.Item()]; !ok {
- return refuse(ErrEscrowNotReady)
+ continue
}
if _, err := hostfiles.ReadSealed(ctx, b.FilesStore, b.filesPrefix(rt.Host), m, rel.Item(), nil, seal); err != nil {
return refuse(err)
@@ -77,6 +82,9 @@ func (b *ExecBackend) followerEscrowEnv(ctx context.Context, rt registry.Route)
return refuse(err)
}
for _, rel := range pubclass.SealedRels(lay, rt.Host) {
+ if _, ok := m.Platform[rel.Item()]; !ok {
+ continue // recorded absent: nothing to hold the local copy to
+ }
plain := c.own
if rel.Item() != hostfiles.SealedEnvItem {
plain, err = instancefs.ReadBeneathLimit(p.dataDir, filepath.FromSlash(rel.Rel()), haEnvReadLimit)
@@ -134,13 +142,7 @@ func (b *ExecBackend) prepareStatelessEscrow(ctx context.Context, rt registry.Ro
if err != nil {
return refuse(err)
}
- complete := found
- for _, rel := range pubclass.SealedRels(lay, rt.Host) {
- if _, ok := m.Platform[rel.Item()]; !ok {
- complete = false
- }
- }
- if complete {
+ if found && escrowComplete(m, lay, rt.Host) {
return nil
}
if b.Coordination == nil {
diff --git a/internal/activator/replica_drill1_test.go b/internal/activator/replica_drill1_test.go
index 77638f7d8..db78280aa 100644
--- a/internal/activator/replica_drill1_test.go
+++ b/internal/activator/replica_drill1_test.go
@@ -5,13 +5,16 @@ import (
"errors"
"fmt"
"os"
+ "path/filepath"
"slices"
"sync/atomic"
"testing"
"time"
+ "github.com/carlosframework/platform/internal/hostfiles"
"github.com/carlosframework/platform/internal/provision"
"github.com/carlosframework/platform/internal/registry"
+ "github.com/carlosframework/platform/internal/release"
"github.com/carlosframework/platform/internal/replicas"
)
@@ -235,3 +238,148 @@ func TestFirstWakeReleaseWaitsForConfig(t *testing.T) {
t.Fatalf("the release did not run once and pass: %+v, releases %d", d, len(r.b.releaseStarts()))
}
}
+
+// getFailingStore fails the read of one object key, and nothing else.
+type getFailingStore struct {
+ release.Store
+ key string
+}
+
+func (s *getFailingStore) Get(ctx context.Context, key string) ([]byte, string, error) {
+ if key == s.key {
+ return nil, "", errors.New("the object could not be read")
+ }
+ return s.Store.Get(ctx, key)
+}
+
+// TestStatelessEscrowRecordsAbsence (#511 drill 1, R21b): a stateless
+// host's coordinator records which trio files are absent (escrowAbsentItem),
+// so a joining copy gets exactly what exists.
+// - never written: the app never writes instance.key or report.token. The
+// escrow records both absent; the joining copy's launch preparation,
+// which refused in the drill, now has its complete secrets, and writes
+// nothing and publishes nothing.
+// - written: the app writes both, one of them after the first publish.
+// The coordinator's next sweep publishes it and drops its marker; the
+// joining copy gets both files.
+// - unreadable: an item the manifest lists cannot be read; the joining
+// copy refuses with the shared-secrets refusal, which halts its join
+// (TestReplicaJoinWithoutSecretsHalts).
+// - upgraded: an escrow an older build wrote, with no absence recorded,
+// is incomplete as before; the coordinator's next sweep records the
+// absence, and the joining copy then starts.
+func TestStatelessEscrowRecordsAbsence(t *testing.T) {
+ ctx := context.Background()
+ setup := func(t *testing.T) (b *ExecBackend, rt registry.Route, f *ExecBackend, frt registry.Route) {
+ t.Helper()
+ b, rt = escrowBackend(t, escrowHost)
+ f, frt = otherBox(t, b, rt)
+ frt.Stateless = true
+ if err := os.MkdirAll(f.pathsFor(frt).dataDir, 0o700); err != nil {
+ t.Fatal(err)
+ }
+ writeEnv(t, b, rt, envA)
+ return b, rt, f, frt
+ }
+ coordinate := func(t *testing.T, b *ExecBackend, rt *registry.Route) {
+ t.Helper()
+ rt.Stateless = true
+ statelessEscrowCoordinator(t, b, *rt)
+ }
+ manifest := func(t *testing.T, b *ExecBackend, rt registry.Route) hostfiles.Manifest {
+ t.Helper()
+ m, _, err := hostfiles.Load(ctx, b.FilesStore, b.filesPrefix(rt.Host))
+ if err != nil {
+ t.Fatal(err)
+ }
+ return m
+ }
+ join := func(t *testing.T, f *ExecBackend, frt registry.Route) (map[string]string, error) {
+ t.Helper()
+ count := &escrowCountingStore{Store: f.FilesStore}
+ f.FilesStore = count
+ defer func() { f.FilesStore = count.Store }()
+ env, err := statelessEscrowLaunch(f, frt)
+ if count.puts.Load() != 0 {
+ t.Fatal("the joining copy published")
+ }
+ return env, err
+ }
+ trio := func(t *testing.T, f *ExecBackend, frt registry.Route, name string) string {
+ t.Helper()
+ raw, err := os.ReadFile(filepath.Join(f.pathsFor(frt).dataDir, frt.Host, name))
+ if errors.Is(err, os.ErrNotExist) {
+ return ""
+ }
+ if err != nil {
+ t.Fatal(err)
+ }
+ return string(raw)
+ }
+ t.Run("never written", func(t *testing.T) {
+ b, rt, f, frt := setup(t)
+ coordinate(t, b, &rt)
+ mustPublish(t, b, rt)
+ m := manifest(t, b, rt)
+ for _, item := range []string{"instance.key.sealed.absent", "report.token.sealed.absent"} {
+ if _, ok := m.Platform[item]; !ok {
+ t.Fatalf("the escrow does not record %s: %v", item, m.Platform)
+ }
+ }
+ env, err := join(t, f, frt)
+ if err != nil || env["CARLOS_ADMIN_TOKEN"] != "tok-a" || env["CARLOS_INSTANCE_KEY"] != "key-a" {
+ t.Fatalf("the joining copy did not get the shared secrets: %v %v", env, err)
+ }
+ if trio(t, f, frt, "instance.key") != "" || trio(t, f, frt, "report.token") != "" {
+ t.Fatal("the joining copy was handed files the app never wrote")
+ }
+ })
+ t.Run("written", func(t *testing.T) {
+ b, rt, f, frt := setup(t)
+ coordinate(t, b, &rt)
+ writeFiles(t, b, rt, map[string]string{"report.token": "rt-secret"})
+ mustPublish(t, b, rt)
+ writeFiles(t, b, rt, map[string]string{"instance.key": "ik-secret"})
+ rep := b.EscrowSweep(ctx, []registry.Route{rt})
+ if rep.Published != 1 {
+ t.Fatalf("the sweep did not publish the new file: %+v", rep)
+ }
+ m := manifest(t, b, rt)
+ if _, marked := m.Platform["instance.key.sealed.absent"]; marked {
+ t.Fatal("the published file kept its absence marker")
+ }
+ if _, err := join(t, f, frt); err != nil {
+ t.Fatal(err)
+ }
+ if trio(t, f, frt, "instance.key") != "ik-secret" || trio(t, f, frt, "report.token") != "rt-secret" {
+ t.Fatal("the joining copy did not get the files the app wrote")
+ }
+ })
+ t.Run("unreadable", func(t *testing.T) {
+ b, rt, f, frt := setup(t)
+ coordinate(t, b, &rt)
+ writeFiles(t, b, rt, map[string]string{"instance.key": "ik-secret"})
+ mustPublish(t, b, rt)
+ f.FilesStore = &getFailingStore{Store: f.FilesStore, key: manifest(t, b, rt).Platform["instance.key.sealed"].Object}
+ if _, err := join(t, f, frt); !errors.Is(err, errStatelessSecretsWaiting) {
+ t.Fatalf("a listed item that cannot be read did not refuse: %v", err)
+ }
+ })
+ t.Run("upgraded", func(t *testing.T) {
+ b, rt, f, frt := setup(t)
+ mustPublish(t, b, rt) // an older build: no absence recorded
+ if _, err := join(t, f, frt); !errors.Is(err, errStatelessSecretsWaiting) {
+ t.Fatalf("an escrow with no absence recorded was taken as complete: %v", err)
+ }
+ coordinate(t, b, &rt)
+ if rep := b.EscrowSweep(ctx, []registry.Route{rt}); len(rep.Failing) != 0 {
+ t.Fatalf("sweep: %+v", rep)
+ }
+ if _, err := join(t, f, frt); err != nil {
+ t.Fatalf("the coordinator's sweep did not upgrade the escrow: %v", err)
+ }
+ if rep := b.EscrowSweep(ctx, []registry.Route{rt}); rep.Published != 0 {
+ t.Fatalf("an upgraded escrow was published again: %+v", rep)
+ }
+ })
+}
diff --git a/internal/hostfiles/sealed.go b/internal/hostfiles/sealed.go
index 8e05b378b..e4c24546d 100644
--- a/internal/hostfiles/sealed.go
+++ b/internal/hostfiles/sealed.go
@@ -163,6 +163,45 @@ func (p *Publisher) StageSealed(ctx context.Context, r pubclass.SealedRel, plain
return nil
}
+// AbsentSuffix names, after a sealed item, the platform item that records
+// that the item's file was absent when its publisher last looked (#511
+// drill 1, R21b): "instance.key.sealed.absent". Its object is the plaintext
+// absentBody, never a secret.
+const AbsentSuffix = ".absent"
+
+var absentBody = []byte(`{"v":1}`)
+
+// SealedAbsentItem is r's absence marker (AbsentSuffix).
+func SealedAbsentItem(r pubclass.SealedRel) string { return r.Item() + AbsentSuffix }
+
+// StageSealedAbsent records that r's file is absent: it stages r's absence
+// marker unless the manifest already holds it or holds r's item, which
+// wins over a marker. The env item is never recorded absent. A marker is
+// removed with StagePlatformDelete when its item is published.
+func (p *Publisher) StageSealedAbsent(ctx context.Context, r pubclass.SealedRel) error {
+ item := r.Item()
+ if item == "" || item == SealedEnvItem {
+ return fmt.Errorf("hostfiles: stage sealed absent: %q cannot be recorded absent", item)
+ }
+ p.mu.Lock()
+ defer p.mu.Unlock()
+ if p.stale != nil {
+ return p.stale
+ }
+ if _, ok := p.man.Platform[item]; ok {
+ return nil
+ }
+ if _, ok := p.man.Platform[item+AbsentSuffix]; ok {
+ return nil
+ }
+ e, err := p.put(ctx, absentBody, 0o600, false)
+ if err != nil {
+ return err
+ }
+ p.man.Platform[item+AbsentSuffix], p.dirty = e, true
+ return nil
+}
+
// SealedOpenError distinguishes a verified object's envelope that cannot
// open under the supplied key and binding from a failed storage read.
// Callers may persist a key conflict without making transient GET errors
diff --git a/internal/layout/pubclass/publication_guard_test.go b/internal/layout/pubclass/publication_guard_test.go
index 4a0280ab8..56d360514 100644
--- a/internal/layout/pubclass/publication_guard_test.go
+++ b/internal/layout/pubclass/publication_guard_test.go
@@ -918,9 +918,11 @@ func (g *publicationGuard) check(u *publicationUnit, c *ast.CallExpr, target pub
if len(args) < 2 || !publicationPlatformName(u.pkg.TypesInfo, args[1]) {
g.problem(u, c, "StagePlatform: name is not WakeItem or AdoptionItem")
}
- case "StageSealed":
+ case "StageSealed", "StageSealedAbsent":
+ // StageSealedAbsent (#511 drill 1, R21b) stages only a sealed
+ // item's plaintext absence marker, named by the same SealedRel.
if len(args) < 2 || !publicationNamed(u.pkg.TypesInfo.TypeOf(args[1]), publicationClassifier, "SealedRel") {
- g.problem(u, c, "StageSealed: argument is not SealedRel")
+ g.problem(u, c, target.kind+": argument is not SealedRel")
}
default:
skipIndex := 3