carlos / platform Public

fix: check the storage declaration without an extra S3 read

Move storage-declaration reads from ship preflight to failed immutable manifest publication. Successful ships keep the existing request budget, while conflicting declarations cannot replace the served manifest.

Assert the storage conflict sentinel and exact console refusal text, cover both declaration directions through memory and spooled shipping, and refresh the release census envelope.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by claude agent, operated by paul@keymail.dev e2f2e9e31e5dea84575e08fb4b50e5bb09896ee5 parent 5855faa
6 files changed, +56 −22
  • internal/console/stateless_ship_test.go +2 −2
  • internal/provision/testdata/plan14-root-reads-stateless-replicas-1.tsv +1 −1
  • internal/release/release.go +1 −4
  • internal/release/rootfs_ship.go +1 −4
  • internal/release/stateless.go +6 −9
  • internal/release/stateless_test.go +45 −2

CI passed — run details

Intent

Human

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

Attributed to this commit: 2.75 g CO₂e (329,430 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.

diff --git a/internal/console/stateless_ship_test.go b/internal/console/stateless_ship_test.go
index cf1ce0756..02f4e2f4f 100644
--- a/internal/console/stateless_ship_test.go
+++ b/internal/console/stateless_ship_test.go
@@ -27,7 +27,7 @@ func TestStatelessShipRootfs(t *testing.T) {
}
delete(fields, "stateless")
parts[0] = metaOf(t, fields)
- if status, out := postShip(t, f.url("shop"), f.token, parts); status != http.StatusConflict {
+ if status, out := postShip(t, f.url("shop"), f.token, parts); status != http.StatusConflict || out["error"] != release.ErrStorageDeclarationConflict.Error() {
t.Fatalf("storage change: %d %v", status, out)
}
f.assertScratchEmpty(t)
@@ -62,7 +62,7 @@ func TestStatelessShipBinaryAndStatic(t *testing.T) {
}
delete(fields, "stateless")
parts[0] = metaOf(t, fields)
- if status, out = postShip(t, f.url("shop"), f.token, parts); status != http.StatusConflict {
+ if status, out = postShip(t, f.url("shop"), f.token, parts); status != http.StatusConflict || out["error"] != release.ErrStorageDeclarationConflict.Error() {
t.Fatalf("storage change: %d %v", status, out)
}
})
diff --git a/internal/provision/testdata/plan14-root-reads-stateless-replicas-1.tsv b/internal/provision/testdata/plan14-root-reads-stateless-replicas-1.tsv
index 79323c1c0..0da56c30f 100644
--- a/internal/provision/testdata/plan14-root-reads-stateless-replicas-1.tsv
+++ b/internal/provision/testdata/plan14-root-reads-stateless-replicas-1.tsv
@@ -9,5 +9,5 @@ ship_check.go rootfsCheck.runArgs legacy accepted-legacy accepted-legacy;rev3=ce
internal/replicas/coordinator.go ChangeCoordinator legacy accepted-legacy accepted-legacy;rev3=census-ruling-stateless-replicas-1;basis=Generate a fresh 128-bit coordinator term using crypto/rand.Read; no file path or process input added. file:Read@472 e50ce5a352b3022a1ee6375fbfee315a5d2fcaeb4f4a25f4e33a5a10e3000a67
@coverage . d8abf32baa39f05d1e9d4e9b8a24e7113c58f42f8735e7a62e217eb39e7a4bf7
@coverage internal/provision 0de8deb0811673f6c9223d0cca375435326dc8bb1fa077afd6a305d61c0f0acb
-@coverage internal/release 4f591204ea68e1c2f3c686ea07ace804bd91bbab7f6ca9942ff6ea6d88ff07d8
+@coverage internal/release 261fde7e6e53d2b4d944df966be3f00208d4d7153aed2d19148cbfd403af9d52
@coverage internal/replicas 53b94eb040154539a0a977498b4b8bc1d53d82f67c1c6233667a0b823dd30d8a
diff --git a/internal/release/release.go b/internal/release/release.go
index 8c9de4459..c69d1b38e 100644
--- a/internal/release/release.go
+++ b/internal/release/release.go
@@ -774,9 +774,6 @@ func claimRawShip(ctx context.Context, s Store, acct string, m Manifest, files m
if err := validateManifest(&m); err != nil {
return fmt.Errorf("ship: %w", err)
}
- if err := checkStorageDeclaration(ctx, s, acct, &m); err != nil {
- return err
- }
// The kind is checked, and for the app's first ship fixed, before the
// first artifact byte, so a ship that loses the first-kind race writes
// nothing (rootfs_ship.go).
@@ -792,7 +789,7 @@ func claimRawShip(ctx context.Context, s Store, acct string, m Manifest, files m
if err != nil {
return err
}
- if err := putImmutable(ctx, s, ManifestKey(acct, m.App, m.Version), raw); err != nil {
+ if err := putImmutableManifest(ctx, s, acct, &m, raw); err != nil {
return fmt.Errorf("ship: manifest: %w", err)
}
return nil
diff --git a/internal/release/rootfs_ship.go b/internal/release/rootfs_ship.go
index 592b26812..f2e7d5f46 100644
--- a/internal/release/rootfs_ship.go
+++ b/internal/release/rootfs_ship.go
@@ -403,9 +403,6 @@ func claimRawShipSpooled(ctx context.Context, s Store, acct string, m Manifest,
if err := validateManifest(&m); err != nil {
return fmt.Errorf("ship: %w", err)
}
- if err := checkStorageDeclaration(ctx, s, acct, &m); err != nil {
- return err
- }
if err := establishShipKind(ctx, s, acct, &m); err != nil {
return err
}
@@ -418,7 +415,7 @@ func claimRawShipSpooled(ctx context.Context, s Store, acct string, m Manifest,
if err != nil {
return err
}
- if err := putImmutable(ctx, s, ManifestKey(acct, m.App, m.Version), raw); err != nil {
+ if err := putImmutableManifest(ctx, s, acct, &m, raw); err != nil {
return fmt.Errorf("ship: manifest: %w", err)
}
return nil
diff --git a/internal/release/stateless.go b/internal/release/stateless.go
index 6ee0264cb..d17e8959b 100644
--- a/internal/release/stateless.go
+++ b/internal/release/stateless.go
@@ -5,7 +5,6 @@ import (
"crypto/sha256"
"encoding/hex"
"errors"
- "os"
"strings"
)
@@ -20,18 +19,16 @@ func ValidateStateless(m *Manifest) error {
return nil
}
-func checkStorageDeclaration(ctx context.Context, s Store, acct string, m *Manifest) error {
- old, _, err := GetManifestRaw(ctx, s, acct, m.App, m.Version)
- if errors.Is(err, os.ErrNotExist) {
+func putImmutableManifest(ctx context.Context, s Store, acct string, m *Manifest, raw []byte) error {
+ err := putImmutable(ctx, s, ManifestKey(acct, m.App, m.Version), raw)
+ if err == nil {
return nil
}
- if err != nil {
- return err
- }
- if old.Stateless != m.Stateless {
+ old, _, readErr := GetManifestRaw(ctx, s, acct, m.App, m.Version)
+ if readErr == nil && old.Stateless != m.Stateless {
return ErrStorageDeclarationConflict
}
- return nil
+ return err
}
// CanonicalManifestDigest hashes the exact validated canonical manifest bytes.
diff --git a/internal/release/stateless_test.go b/internal/release/stateless_test.go
index b890ab64c..2e9596627 100644
--- a/internal/release/stateless_test.go
+++ b/internal/release/stateless_test.go
@@ -6,7 +6,10 @@ import (
"crypto/sha256"
"encoding/hex"
"encoding/json"
+ "errors"
+ "fmt"
"os"
+ "path/filepath"
"strings"
"testing"
)
@@ -89,8 +92,8 @@ func TestStatelessManifestCompatibility(t *testing.T) {
t.Fatalf("rollback: %v %v", rolled, err)
}
m.Stateless = false
- if err := Ship(ctx, s, "bab", m, files); err == nil {
- t.Fatal("storage declaration changed under immutable version")
+ if err := Ship(ctx, s, "bab", m, files); !errors.Is(err, ErrStorageDeclarationConflict) {
+ t.Fatalf("storage declaration conflict: %v", err)
}
}
func TestStatelessFloorsArePinned(t *testing.T) {
@@ -156,3 +159,43 @@ func TestStatelessRootfsCompatibility(t *testing.T) {
}
}
}
+
+func TestStatelessShipConflictKeepsManifest(t *testing.T) {
+ for _, spooled := range []bool{false, true} {
+ for _, stateless := range []bool{false, true} {
+ t.Run(fmt.Sprintf("spooled=%t/stateless=%t", spooled, stateless), func(t *testing.T) {
+ ctx := context.Background()
+ s := NewDirStore(t.TempDir())
+ m := rootfsManifest()
+ m.Stateless = stateless
+ m.Artifacts = map[string]Artifact{RootfsArtifactKey: {File: RootfsArtifactFile}}
+ body := []byte("image")
+ path := filepath.Join(t.TempDir(), RootfsArtifactFile)
+ if err := os.WriteFile(path, body, 0600); err != nil {
+ t.Fatal(err)
+ }
+ ship := func() error {
+ if spooled {
+ return ShipSpooled(ctx, s, "bab", *m, map[string]string{RootfsArtifactKey: path})
+ }
+ return Ship(ctx, s, "bab", *m, map[string][]byte{RootfsArtifactKey: body})
+ }
+ if err := ship(); err != nil {
+ t.Fatal(err)
+ }
+ _, before, err := GetManifestRaw(ctx, s, "bab", m.App, m.Version)
+ if err != nil {
+ t.Fatal(err)
+ }
+ m.Stateless = !stateless
+ if err := ship(); !errors.Is(err, ErrStorageDeclarationConflict) {
+ t.Fatalf("storage declaration conflict: %v", err)
+ }
+ got, after, err := GetManifestRaw(ctx, s, "bab", m.App, m.Version)
+ if err != nil || got.Stateless != stateless || !bytes.Equal(before, after) {
+ t.Fatalf("conflict changed served manifest: %v %v", got, err)
+ }
+ })
+ }
+ }
+}