carlos / platform Public

release, provision: stamped record reads (version id from the same GET)

release.GetStamped returns an object's body with its ObjectStamp: the
ETag, and from S3 the version id and last-modified time the same
GetObject response carries (no extra request); stores without them give
the ETag alone. provision.GetRecordStamped and GetSidecarRecordStamped
are GetRecord and GetSidecarRecord with that stamp, refusing what they
refuse. Read paths only; no writer changes.

Needed because the deployment bucket's ETag is the body's MD5 (SSE-S3):
two writes of the same bytes share it, and only the version id tells
them apart.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev a29c22523419b3ace71150e9701f8d3d2fe55501 parent 0cfd5ad
5 files changed, +285 −0
  • internal/provision/record_stamped.go +45 −0
  • internal/provision/record_stamped_test.go +64 −0
  • internal/provision/sidecar.go +6 −0
  • internal/release/stamped.go +75 −0
  • internal/release/stamped_test.go +95 −0

Intent

Human

<task-notification> <task-id>bwq300esn</task-id> <tool-use-id>toolu_01JsXay3MPqt3fDqUCc3Airj</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/ab362fc0-f177-4a7f-a92e-4a29ea210aad/tasks/bwq300esn.output</output-file> <status>completed</status> <summary>Background command "Fable review of the 1b plan" completed (exit code 0)</summary> </task-notification>

Human

<task-notification> <task-id>b2fuqpv6v</task-id> <tool-use-id>toolu_01MR6A9o5izvnNwkVEHc1idG</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/ab362fc0-f177-4a7f-a92e-4a29ea210aad/tasks/b2fuqpv6v.output</output-file> <status>completed</status> <summary>Background command "Astra plan reviews for 1b and 2b" completed (exit code 0)</summary> </task-notification>

Human

<task-notification> <task-id>a498d950348c587ef</task-id> <tool-use-id>toolu_01DEnnFHKeDKi2SW8WLppnc7</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/ab362fc0-f177-4a7f-a92e-4a29ea210aad/tasks/a498d950348c587ef.output</output-file> <status>completed</status> <summary>Agent "Write slice 2b plan (test line + operator view)" 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>Rev 2 still has 9 tasks. I declined none of the 7 findings.</result> <usage><subagent_tokens>291644</subagent_tokens><tool_uses>11</tool_uses><duration_ms>139065</duration_ms></usage> </task-notification>

diff --git a/internal/provision/record_stamped.go b/internal/provision/record_stamped.go
new file mode 100644
index 000000000..6450c9760
--- /dev/null
+++ b/internal/provision/record_stamped.go
@@ -0,0 +1,45 @@
+package provision
+
+import (
+ "context"
+ "fmt"
+ "os"
+
+ "github.com/carlosframework/platform/internal/release"
+)
+
+// GetRecordStamped is GetRecord with the record's stamp from the same read
+// (release.GetStamped: the ETag, and on a versioned bucket the version id
+// and last-modified time). A reader that brackets its work between two
+// reads of a record compares the stamps: a write between them shows even
+// when it left the bytes as they were, such as a legacy move there and
+// back (member backups 2a, the restore drill's bracket). It refuses what
+// GetRecord refuses: a body disagreeing with its path, a retired record.
+func GetRecordStamped(ctx context.Context, s release.Store, acct, app, host string) (*Record, release.ObjectStamp, error) {
+ raw, st, err := release.GetStamped(ctx, s, RecordKey(acct, app, host))
+ if err != nil {
+ return nil, release.ObjectStamp{}, err
+ }
+ rec, err := decodeRecordAt(raw, acct, app, host)
+ if err != nil {
+ return nil, release.ObjectStamp{}, err
+ }
+ if rec.Retired {
+ return nil, release.ObjectStamp{}, fmt.Errorf("provision: record %s/%s/%s: retired: %w", acct, app, host, os.ErrNotExist)
+ }
+ return rec, st, nil
+}
+
+// GetSidecarRecordStamped is GetSidecarRecord with the record's stamp from
+// the same read, as GetRecordStamped.
+func GetSidecarRecordStamped(ctx context.Context, s release.Store, acct, app, name string) (*SidecarRecord, release.ObjectStamp, error) {
+ raw, st, err := release.GetStamped(ctx, s, SidecarRecordKey(acct, app, name))
+ if err != nil {
+ return nil, release.ObjectStamp{}, err
+ }
+ rec, err := decodeSidecarAt(raw, acct, app, name)
+ if err != nil {
+ return nil, release.ObjectStamp{}, err
+ }
+ return rec, st, nil
+}
diff --git a/internal/provision/record_stamped_test.go b/internal/provision/record_stamped_test.go
new file mode 100644
index 000000000..8f7d7312b
--- /dev/null
+++ b/internal/provision/record_stamped_test.go
@@ -0,0 +1,64 @@
+package provision
+
+import (
+ "context"
+ "encoding/json"
+ "errors"
+ "os"
+ "testing"
+ "time"
+
+ "github.com/carlosframework/platform/internal/release"
+)
+
+// The stamped reads return what GetRecord and GetSidecarRecord return,
+// with the record's stamp from the same read (release.GetStamped), and
+// refuse what they refuse.
+func TestRecordStampedReads(t *testing.T) {
+ ctx := context.Background()
+ s := release.NewDirStore(t.TempDir())
+ created := time.Date(2026, 9, 1, 0, 0, 0, 0, time.UTC)
+ put := func(key string, v any) string {
+ t.Helper()
+ body, err := json.Marshal(v)
+ if err != nil {
+ t.Fatal(err)
+ }
+ etag, err := s.Put(ctx, key, body, "")
+ if err != nil {
+ t.Fatal(err)
+ }
+ return etag
+ }
+
+ etag := put(RecordKey("bab", "shop", "a.example.com"), Record{Account: "bab", App: "shop", Host: "a.example.com", Region: "uk", CreatedAt: created})
+ rec, st, err := GetRecordStamped(ctx, s, "bab", "shop", "a.example.com")
+ want, _ := GetRecord(ctx, s, "bab", "shop", "a.example.com")
+ if err != nil || rec == nil || rec.Host != want.Host || rec.Region != want.Region || st.ETag != etag {
+ t.Fatalf("GetRecordStamped = %+v, %+v, %v; want GetRecord's record with ETag %q", rec, st, err, etag)
+ }
+ put(RecordKey("bab", "shop", "liar.example.com"), Record{Account: "bab", App: "shop", Host: "other.example.com"})
+ if _, _, err := GetRecordStamped(ctx, s, "bab", "shop", "liar.example.com"); !errors.Is(err, ErrRecordCorrupt) {
+ t.Fatalf("a record disagreeing with its path = %v, want ErrRecordCorrupt", err)
+ }
+ put(RecordKey("bab", "shop", "gone.example.com"), Record{Account: "bab", App: "shop", Host: "gone.example.com", Retired: true})
+ if _, _, err := GetRecordStamped(ctx, s, "bab", "shop", "gone.example.com"); !errors.Is(err, os.ErrNotExist) {
+ t.Fatalf("a retired record = %v, want os.ErrNotExist", err)
+ }
+ if _, _, err := GetRecordStamped(ctx, s, "bab", "shop", "none.example.com"); !errors.Is(err, os.ErrNotExist) {
+ t.Fatalf("no record = %v, want os.ErrNotExist", err)
+ }
+
+ setag := put(SidecarRecordKey("bab", "shop", "worker"), SidecarRecord{Account: "bab", App: "shop", Name: "worker", Host: "worker.example", Region: "uk"})
+ sc, sst, err := GetSidecarRecordStamped(ctx, s, "bab", "shop", "worker")
+ if err != nil || sc == nil || sc.Host != "worker.example" || sst.ETag != setag {
+ t.Fatalf("GetSidecarRecordStamped = %+v, %+v, %v; want the record with ETag %q", sc, sst, err, setag)
+ }
+ put(SidecarRecordKey("bab", "shop", "liar"), SidecarRecord{Account: "bab", App: "shop", Name: "other"})
+ if _, _, err := GetSidecarRecordStamped(ctx, s, "bab", "shop", "liar"); err == nil {
+ t.Fatal("a sidecar record disagreeing with its path was accepted")
+ }
+ if _, _, err := GetSidecarRecordStamped(ctx, s, "bab", "shop", "none"); !errors.Is(err, os.ErrNotExist) {
+ t.Fatalf("no sidecar record = %v, want os.ErrNotExist", err)
+ }
+}
diff --git a/internal/provision/sidecar.go b/internal/provision/sidecar.go
index adb794683..5d12d53bb 100644
--- a/internal/provision/sidecar.go
+++ b/internal/provision/sidecar.go
@@ -346,6 +346,12 @@ func GetSidecarRecord(ctx context.Context, s release.Store, acct, app, name stri
if err != nil {
return nil, err
}
+ return decodeSidecarAt(raw, acct, app, name)
+}
+
+// decodeSidecarAt decodes a sidecar record read from acct/app/name's key,
+// refusing one whose body names another path.
+func decodeSidecarAt(raw []byte, acct, app, name string) (*SidecarRecord, error) {
var rec SidecarRecord
if err := json.Unmarshal(raw, &rec); err != nil {
return nil, fmt.Errorf("provision: sidecar record %s/%s/%s: %w", acct, app, name, err)
diff --git a/internal/release/stamped.go b/internal/release/stamped.go
new file mode 100644
index 000000000..1e19fbd89
--- /dev/null
+++ b/internal/release/stamped.go
@@ -0,0 +1,75 @@
+package release
+
+import (
+ "context"
+ "fmt"
+ "io"
+ "os"
+ "time"
+
+ "github.com/aws/aws-sdk-go-v2/aws"
+ awss3 "github.com/aws/aws-sdk-go-v2/service/s3"
+)
+
+// ObjectStamp is what identifies one write of an object, as a read saw it.
+// ETag is a content hash on the stores in use (S3 SSE-S3: the body's MD5;
+// DirStore: its sha256), so two writes of the same bytes share it.
+// VersionID (a versioned bucket's id for this write, "" where the store
+// has none) and LastModified (S3's, to the second; zero where the store
+// gives none) tell them apart. A reader that must know whether anything
+// wrote the object between two reads compares stamps, not bodies.
+type ObjectStamp struct {
+ ETag string
+ VersionID string
+ LastModified time.Time
+}
+
+// Same reports whether two stamps name the same write.
+func (a ObjectStamp) Same(b ObjectStamp) bool {
+ return a.ETag == b.ETag && a.VersionID == b.VersionID && a.LastModified.Equal(b.LastModified)
+}
+
+// StampedGetter is the optional half of Store whose read also returns the
+// object's stamp, from the same request. Type-asserted like PageLister;
+// GetStamped falls back to Get where it is missing.
+type StampedGetter interface {
+ GetStamped(ctx context.Context, key string) ([]byte, ObjectStamp, error)
+}
+
+var _ StampedGetter = (*S3Store)(nil)
+
+// GetStamped reads key from s with its stamp: the store's own stamped
+// read when it has one, else Get's body and ETag. A missing key is
+// os.ErrNotExist, as Get reports it.
+func GetStamped(ctx context.Context, s Store, key string) ([]byte, ObjectStamp, error) {
+ if sg, ok := s.(StampedGetter); ok {
+ return sg.GetStamped(ctx, key)
+ }
+ body, etag, err := s.Get(ctx, key)
+ if err != nil {
+ return nil, ObjectStamp{}, err
+ }
+ return body, ObjectStamp{ETag: etag}, nil
+}
+
+// GetStamped is Get with the version id and last-modified time the same
+// GetObject response carries: no extra request.
+func (s *S3Store) GetStamped(ctx context.Context, key string) ([]byte, ObjectStamp, error) {
+ out, err := s.Client.GetObject(ctx, &awss3.GetObjectInput{Bucket: &s.Bucket, Key: &key})
+ if err != nil {
+ if s3NotFound(err) {
+ return nil, ObjectStamp{}, fmt.Errorf("s3store: %s: %w", key, os.ErrNotExist)
+ }
+ return nil, ObjectStamp{}, err
+ }
+ defer out.Body.Close()
+ b, err := io.ReadAll(out.Body)
+ if err != nil {
+ return nil, ObjectStamp{}, err
+ }
+ st := ObjectStamp{ETag: aws.ToString(out.ETag), VersionID: aws.ToString(out.VersionId)}
+ if out.LastModified != nil {
+ st.LastModified = out.LastModified.UTC()
+ }
+ return b, st, nil
+}
diff --git a/internal/release/stamped_test.go b/internal/release/stamped_test.go
new file mode 100644
index 000000000..7924174b1
--- /dev/null
+++ b/internal/release/stamped_test.go
@@ -0,0 +1,95 @@
+package release
+
+import (
+ "context"
+ "errors"
+ "net/http"
+ "net/http/httptest"
+ "os"
+ "sync/atomic"
+ "testing"
+ "time"
+
+ "github.com/aws/aws-sdk-go-v2/aws"
+ "github.com/aws/aws-sdk-go-v2/credentials"
+ awss3 "github.com/aws/aws-sdk-go-v2/service/s3"
+)
+
+// GetStamped reads the body and what identifies this write of the object
+// from one GetObject: the ETag, the version id and the last-modified
+// time. On a versioned SSE-S3 bucket two writes of the same bytes share
+// an ETag (the body's MD5) and differ in version id and time, which is
+// what a reader bracketing its own work needs to see (member backups 2a,
+// Astra's review of R1b).
+func TestS3GetStampedCarriesTheVersion(t *testing.T) {
+ t.Parallel()
+ const etag = `"same-bytes-md5"`
+ versions := []string{"v1", "v2"}
+ times := []string{"Thu, 12 Nov 2026 03:00:00 GMT", "Thu, 12 Nov 2026 03:04:00 GMT"}
+ var reqs atomic.Int32
+ srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ n := int(reqs.Add(1)) - 1
+ if r.URL.Path == "/b/gone" {
+ w.WriteHeader(http.StatusNotFound)
+ _, _ = w.Write([]byte(`<Error><Code>NoSuchKey</Code></Error>`))
+ return
+ }
+ w.Header().Set("ETag", etag)
+ w.Header().Set("x-amz-version-id", versions[n%2])
+ w.Header().Set("Last-Modified", times[n%2])
+ _, _ = w.Write([]byte("body"))
+ }))
+ defer srv.Close()
+ client := awss3.New(awss3.Options{
+ Region: "us-east-1",
+ Credentials: credentials.NewStaticCredentialsProvider("k", "s", ""),
+ BaseEndpoint: aws.String(srv.URL),
+ UsePathStyle: true,
+ Retryer: aws.NopRetryer{},
+ })
+ s := &S3Store{Client: client, Bucket: "b"}
+ ctx := context.Background()
+
+ body, first, err := GetStamped(ctx, s, "k")
+ if err != nil || string(body) != "body" {
+ t.Fatalf("first read: %q, %v", body, err)
+ }
+ _, second, err := GetStamped(ctx, s, "k")
+ if err != nil {
+ t.Fatal(err)
+ }
+ if n := reqs.Load(); n != 2 {
+ t.Fatalf("%d requests for two reads, want one each", n)
+ }
+ if first.ETag != etag || first.VersionID != "v1" || !first.LastModified.Equal(time.Date(2026, 11, 12, 3, 0, 0, 0, time.UTC)) {
+ t.Fatalf("first stamp %+v", first)
+ }
+ if first.Same(second) || second.VersionID != "v2" || second.ETag != first.ETag {
+ t.Fatalf("two writes of the same bytes: stamps %+v and %+v must differ, by version and time only", first, second)
+ }
+ if !first.Same(first) {
+ t.Fatal("a stamp is not the same as itself")
+ }
+ if _, _, err := GetStamped(ctx, s, "gone"); !errors.Is(err, os.ErrNotExist) {
+ t.Fatalf("a missing key = %v, want os.ErrNotExist", err)
+ }
+}
+
+// A store with no versions (DirStore) stamps a read with its ETag alone,
+// from its ordinary Get.
+func TestGetStampedFallsBackToTheETag(t *testing.T) {
+ t.Parallel()
+ ctx := context.Background()
+ d := NewDirStore(t.TempDir())
+ if _, err := d.Put(ctx, "a.json", []byte("one"), ""); err != nil {
+ t.Fatal(err)
+ }
+ body, st, err := GetStamped(ctx, d, "a.json")
+ _, etag, _ := d.Get(ctx, "a.json")
+ if err != nil || string(body) != "one" || st != (ObjectStamp{ETag: etag}) {
+ t.Fatalf("GetStamped = %q, %+v, %v; want the body and ETag %q only", body, st, err, etag)
+ }
+ if _, _, err := GetStamped(ctx, d, "absent.json"); !errors.Is(err, os.ErrNotExist) {
+ t.Fatalf("a missing key = %v, want os.ErrNotExist", err)
+ }
+}