carlos / platform Public

edge: stream static-site artifacts to a verified temp file

The apt site (~2 GB) was read whole into memory on every promote,
peaking annie's edge at ~5 GB. The artifact now streams into a private,
already-unlinked temp file through sha256 and a size cap, is verified
before the tar parser sees a byte, and is extracted from the file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Squashed from static-stream-extract into main.
Paul Campbell pushed by claude agent, operated by paul@keymail.dev 74757d13d7c7c5c8be42d11f4f8d0877a18abded parent 1694108
9 files changed, +485 −18
  • docs/superpowers/notes/census-proposal-static-stream-extract.md +23 −0
  • internal/edge/static.go +58 −18
  • internal/edge/static_artifact_other.go +5 −0
  • internal/edge/static_artifact_unix.go +5 −0
  • internal/edge/static_stream_test.go +368 −0
  • internal/edge/static_test.go +8 −0
  • internal/provision/testdata/plan14-root-reads-chain.tsv +1 −0
  • internal/provision/testdata/plan14-root-reads-static-stream-extract.tsv +9 −0
  • internal/release/qualified.go +8 −0

CI failed — run details

diff --git a/docs/superpowers/notes/census-proposal-static-stream-extract.md b/docs/superpowers/notes/census-proposal-static-stream-extract.md
new file mode 100644
index 000000000..909af810a
--- /dev/null
+++ b/docs/superpowers/notes/census-proposal-static-stream-extract.md
@@ -0,0 +1,23 @@
+# Census approval: static-stream-extract
+
+Ruling `census-ruling-static-stream-extract`. The independent reviewer approves or rejects every change below, 1 with a new disposition; nothing goes to the census owner (Paul, #280, 2026-10-26).
+
+| unit | change | read sites | what changed |
+|---|---|---|---|
+| `internal/edge/static.go` `extractSiteTar` | body | unchanged (1) | Accepts io.Reader instead of []byte; gzip reads the verified temporary file supplied by ensureExtracted or the bytes.NewReader adapter in ExtractSite. The extraction paths, file opens, path validation and entry-type refusals are unchanged. No new read site or authority. |
+
+Envelopes re-pinned: `internal/edge`, `internal/release`.
+
+Review: a model from the other family than the author reads the branch's diff against main on the amadan.net remote (`origin` or `amadan`, whichever points at amadan.net) and gives a verdict for every unit and every re-pinned envelope above. For a unit, compare the change with its recorded disposition and basis below; for an envelope, read every changed function in the package and what it reaches. Reject if the change lets root open, run, query or follow anything it did not before from a path or input a tenant, an app or a box agent can create, write or name; if it weakens a check, refusal, validation, argument or environment the basis relies on; or if the diff cannot settle either. Otherwise approve. Record each verdict on #280 with the tip. A rejected unit goes back to the author to correct; nothing escalates to the census owner.
+
+Recorded dispositions, which each change must still satisfy:
+
+- `internal/edge/static.go` `extractSiteTar`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=J4;basis=root-input
+
+New dispositions, which census-propose wrote and the reviewer checks against the unit's reads and the diff:
+
+- reads `internal/edge/static.go:staticSite.ensureExtracted`: +file:CreateTemp; keeps legacy, task accepted-legacy
+
+Seal: `b0fc198c53bb0dacba33a54c3d8bf8fe5ac07d94b76a31b8a69e9411115ecd85` → `7fb932b118e67e23b33a374c6a4020b38976667c7ec4cfb855c0f8b598b1756b`.
+
+Overlay: `internal/provision/testdata/plan14-root-reads-static-stream-extract.tsv`, appended to `internal/provision/testdata/plan14-root-reads-chain.tsv`.
diff --git a/internal/edge/static.go b/internal/edge/static.go
index 7b8fe36fb..e0057e5d0 100644
--- a/internal/edge/static.go
+++ b/internal/edge/static.go
@@ -22,6 +22,7 @@ import (
"io"
"io/fs"
"log"
+ "math"
"mime"
"net/http"
"os"
@@ -408,37 +409,76 @@ func (s *staticSite) ensureExtracted(ctx context.Context, version, want string)
if art == nil {
return "", "", fmt.Errorf("release %s/%s has no %s artifact", s.app, version, siteArtifactFile)
}
- data, _, err := release.GetQualified(ctx, s.store, release.ArtifactKey(s.acct, s.app, version, art.File))
- if err != nil {
- return "", "", err
+ if art.Size < 0 || art.Size == math.MaxInt64 {
+ return "", "", fmt.Errorf("%s invalid size %d", siteArtifactFile, art.Size)
}
- sum := sha256.Sum256(data)
- if hex.EncodeToString(sum[:]) != art.SHA256 {
- return "", "", fmt.Errorf("%s sha256 mismatch (manifest %s, stored %s): refusing to extract",
- siteArtifactFile, art.SHA256, hex.EncodeToString(sum[:]))
+ started := time.Now()
+ key := release.ArtifactKey(s.acct, s.app, version, art.File)
+ body, _, err := release.OpenQualifiedStreaming(ctx, s.store, key)
+ if errors.Is(err, errors.ErrUnsupported) {
+ const getFallbackMax = 64 << 20
+ if art.Size > getFallbackMax {
+ return "", "", fmt.Errorf("%s size %d exceeds Get-only store limit %d", siteArtifactFile, art.Size, getFallbackMax)
+ }
+ body, _, err = release.OpenQualified(ctx, s.store, key)
}
- if int64(len(data)) != art.Size {
- return "", "", fmt.Errorf("%s size mismatch (manifest %d, stored %d)", siteArtifactFile, art.Size, len(data))
+ if err != nil {
+ return "", "", err
}
+ defer body.Close()
appDir := s.appDir()
if err := os.MkdirAll(appDir, 0o755); err != nil {
return "", "", err
}
+ artifact, err := os.CreateTemp(appDir, ".artifact-")
+ if err != nil {
+ return "", "", err
+ }
+ named := true
+ defer func() {
+ artifact.Close()
+ if named {
+ os.Remove(artifact.Name())
+ }
+ }()
+ if unlinkOpenStaticArtifact {
+ if err := os.Remove(artifact.Name()); err != nil {
+ return "", "", err
+ }
+ named = false
+ }
+ hash := sha256.New()
+ n, err := io.Copy(io.MultiWriter(artifact, hash), io.LimitReader(body, art.Size+1))
+ if err != nil {
+ return "", "", err
+ }
+ if n > art.Size {
+ return "", "", fmt.Errorf("%s size mismatch (manifest %d, stored more than %d)", siteArtifactFile, art.Size, art.Size)
+ }
+ if n < art.Size {
+ return "", "", fmt.Errorf("%s size mismatch (manifest %d, stored %d)", siteArtifactFile, art.Size, n)
+ }
+ if sum := hex.EncodeToString(hash.Sum(nil)); sum != art.SHA256 {
+ return "", "", fmt.Errorf("%s sha256 mismatch (manifest %s, stored %s): refusing to extract",
+ siteArtifactFile, art.SHA256, sum)
+ }
+ if _, err := artifact.Seek(0, io.SeekStart); err != nil {
+ return "", "", err
+ }
tmp, err := os.MkdirTemp(appDir, ".extract-")
if err != nil {
return "", "", err
}
- if err := extractSiteTar(data, tmp); err != nil {
- os.RemoveAll(tmp)
+ defer os.RemoveAll(tmp)
+ if err := extractSiteTar(artifact, tmp); err != nil {
return "", "", err
}
if err := os.Rename(tmp, dst); err != nil {
- os.RemoveAll(tmp)
- if _, serr := os.Stat(dst); serr == nil {
- return name, digest, nil // lost the staging race; the winner's tree is identical
+ if _, serr := os.Stat(dst); serr != nil {
+ return "", "", err
}
- return "", "", err
}
+ log.Printf("INFO edge: static site=%s/%s version=%s bytes=%d seconds=%.3f", s.acct, s.app, version, n, time.Since(started).Seconds())
return name, digest, nil
}
@@ -462,14 +502,14 @@ func (s *staticSite) pointCurrent(name string) error {
// ExtractSite is extractSiteTar for callers outside this package: the devbox
// registrar (localstatic.go) fills its local tree with it, under the same
// refusals.
-func ExtractSite(data []byte, dst string) error { return extractSiteTar(data, dst) }
+func ExtractSite(data []byte, dst string) error { return extractSiteTar(bytes.NewReader(data), dst) }
// extractSiteTar unpacks a verified site tar into dst, rejecting anything
// that would write outside it: absolute names, ".." traversal, and non-file
// entry types (a symlink in a site tar could alias the extraction outside
// the cache — PackDir never emits one, so none is ever legitimate).
-func extractSiteTar(data []byte, dst string) error {
- gz, err := gzip.NewReader(bytes.NewReader(data))
+func extractSiteTar(src io.Reader, dst string) error {
+ gz, err := gzip.NewReader(src)
if err != nil {
return fmt.Errorf("site tar: %v", err)
}
diff --git a/internal/edge/static_artifact_other.go b/internal/edge/static_artifact_other.go
new file mode 100644
index 000000000..34cc8d6e7
--- /dev/null
+++ b/internal/edge/static_artifact_other.go
@@ -0,0 +1,5 @@
+//go:build !linux && !darwin
+
+package edge
+
+const unlinkOpenStaticArtifact = false
diff --git a/internal/edge/static_artifact_unix.go b/internal/edge/static_artifact_unix.go
new file mode 100644
index 000000000..2dad8093b
--- /dev/null
+++ b/internal/edge/static_artifact_unix.go
@@ -0,0 +1,5 @@
+//go:build linux || darwin
+
+package edge
+
+const unlinkOpenStaticArtifact = true
diff --git a/internal/edge/static_stream_test.go b/internal/edge/static_stream_test.go
new file mode 100644
index 000000000..cb1d746e9
--- /dev/null
+++ b/internal/edge/static_stream_test.go
@@ -0,0 +1,368 @@
+package edge
+
+import (
+ "archive/tar"
+ "bytes"
+ "compress/gzip"
+ "context"
+ "crypto/sha256"
+ "encoding/hex"
+ "encoding/json"
+ "errors"
+ "fmt"
+ "io"
+ "math"
+ "os"
+ "path/filepath"
+ "runtime"
+ "strings"
+ "testing"
+
+ "github.com/carlosframework/platform/internal/release"
+)
+
+type staticStreamStore struct {
+ release.Store
+ artifact string
+ key string
+ gets int
+ opens int
+ read int64
+ closed bool
+ panicRead bool
+ readErr error
+ beforeRead func()
+}
+
+func (s *staticStreamStore) Get(ctx context.Context, key string) ([]byte, string, error) {
+ if key != s.key {
+ return s.Store.Get(ctx, key)
+ }
+ s.gets++
+ b, err := os.ReadFile(s.artifact)
+ return b, "artifact", err
+}
+
+func (s *staticStreamStore) Open(ctx context.Context, key string) (io.ReadCloser, string, error) {
+ if key != s.key {
+ return release.OpenObject(ctx, s.Store, key)
+ }
+ s.opens++
+ f, err := os.Open(s.artifact)
+ if err != nil {
+ return nil, "", err
+ }
+ return &staticStreamBody{File: f, store: s}, "artifact", nil
+}
+
+type staticStreamBody struct {
+ *os.File
+ store *staticStreamStore
+}
+
+func (b *staticStreamBody) Read(p []byte) (int, error) {
+ if b.store.beforeRead != nil {
+ b.store.beforeRead()
+ }
+ if b.store.panicRead {
+ panic("stream panic")
+ }
+ if b.store.readErr != nil {
+ return 0, b.store.readErr
+ }
+ n, err := b.File.Read(p)
+ b.store.read += int64(n)
+ return n, err
+}
+
+func (b *staticStreamBody) Close() error {
+ b.store.closed = true
+ return b.File.Close()
+}
+
+type staticZeroReader struct{}
+
+func (staticZeroReader) Read(p []byte) (int, error) { clear(p); return len(p), nil }
+
+func staticStreamFixture(t *testing.T, size int64) (*staticSite, *staticStreamStore, release.Manifest) {
+ t.Helper()
+ dir := t.TempDir()
+ file := filepath.Join(dir, "artifact")
+ f, err := os.Create(file)
+ if err != nil {
+ t.Fatal(err)
+ }
+ hash := sha256.New()
+ gz, err := gzip.NewWriterLevel(io.MultiWriter(f, hash), gzip.NoCompression)
+ if err != nil {
+ t.Fatal(err)
+ }
+ tw := tar.NewWriter(gz)
+ if err := tw.WriteHeader(&tar.Header{Name: "nested/file.bin", Mode: 0o644, Size: size}); err != nil {
+ t.Fatal(err)
+ }
+ if _, err := io.CopyN(tw, staticZeroReader{}, size); err != nil {
+ t.Fatal(err)
+ }
+ if err := tw.Close(); err != nil {
+ t.Fatal(err)
+ }
+ if err := gz.Close(); err != nil {
+ t.Fatal(err)
+ }
+ if err := f.Close(); err != nil {
+ t.Fatal(err)
+ }
+ info, err := os.Stat(file)
+ if err != nil {
+ t.Fatal(err)
+ }
+ s := &staticStreamStore{Store: release.NewDirStore(filepath.Join(dir, "store")), artifact: file, key: release.ArtifactKey(release.OpsAccount, "site", "v1", siteArtifactFile)}
+ m := release.Manifest{Schema: 1, App: "site", Version: "v1", Kind: "static", Artifacts: map[string]release.Artifact{siteArtifactFile: {File: siteArtifactFile, Size: info.Size(), SHA256: hex.EncodeToString(hash.Sum(nil))}}}
+ staticStreamManifest(t, s, m)
+ site := &staticSite{store: s, acct: release.OpsAccount, app: "site", cacheDir: filepath.Join(dir, "cache")}
+ return site, s, m
+}
+
+func staticStreamManifest(t *testing.T, s *staticStreamStore, m release.Manifest) {
+ t.Helper()
+ raw, err := json.Marshal(m)
+ if err != nil {
+ t.Fatal(err)
+ }
+ key := release.ManifestKey(release.OpsAccount, "site", "v1")
+ if err := s.Store.Delete(t.Context(), key); err != nil {
+ t.Fatal(err)
+ }
+ if _, err := s.Store.Put(t.Context(), key, raw, ""); err != nil {
+ t.Fatal(err)
+ }
+}
+
+func staticStreamNoDebris(t *testing.T, site *staticSite) {
+ t.Helper()
+ entries, err := os.ReadDir(site.appDir())
+ if err != nil && !errors.Is(err, os.ErrNotExist) {
+ t.Fatal(err)
+ }
+ if len(entries) != 0 {
+ t.Fatalf("stage left files: %v", entries)
+ }
+}
+
+func TestStaticStreamLargeArtifact(t *testing.T) {
+ const payload = 64 << 20
+ site, store, _ := staticStreamFixture(t, payload)
+ runtime.GC()
+ var before, after runtime.MemStats
+ runtime.ReadMemStats(&before)
+ name, _, err := site.ensureExtracted(t.Context(), "v1", "")
+ runtime.ReadMemStats(&after)
+ if err != nil {
+ t.Fatal(err)
+ }
+ allocated := after.TotalAlloc - before.TotalAlloc
+ t.Logf("stage allocated %d bytes for a %d-byte site", allocated, payload)
+ if store.gets != 0 || store.opens != 1 || !store.closed {
+ t.Errorf("gets=%d opens=%d closed=%v", store.gets, store.opens, store.closed)
+ }
+ if allocated >= 16<<20 {
+ t.Errorf("stage allocated %d bytes, want <16 MiB", allocated)
+ }
+ f, err := os.Open(filepath.Join(site.dir(name), "nested/file.bin"))
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer f.Close()
+ actual := sha256.New()
+ n, err := io.Copy(actual, f)
+ if err != nil {
+ t.Fatal(err)
+ }
+ expected := sha256.New()
+ io.CopyN(expected, staticZeroReader{}, payload)
+ if n != payload || !bytes.Equal(actual.Sum(nil), expected.Sum(nil)) {
+ t.Fatal("extracted content differs")
+ }
+ entries, err := os.ReadDir(site.appDir())
+ if err != nil || len(entries) != 1 || entries[0].Name() != name {
+ t.Fatalf("stage debris: %v, %v", entries, err)
+ }
+}
+
+func TestStaticStreamRefusals(t *testing.T) {
+ for _, tc := range []string{"hash", "overrun", "short", "negative", "overflow", "extract", "read", "panic"} {
+ t.Run(tc, func(t *testing.T) {
+ site, store, m := staticStreamFixture(t, 1024)
+ art := m.Artifacts[siteArtifactFile]
+ want := ""
+ switch tc {
+ case "hash":
+ art.SHA256 = strings.Repeat("0", 64)
+ want = "sha256 mismatch"
+ case "overrun":
+ art.Size = 16
+ want = "size mismatch (manifest 16, stored more than 16)"
+ case "short":
+ want = fmt.Sprintf("size mismatch (manifest %d, stored %d)", art.Size+1, art.Size)
+ art.Size++
+ case "negative":
+ art.Size = -1
+ case "overflow":
+ art.Size = math.MaxInt64
+ case "extract":
+ data := []byte("not a gzip file")
+ if err := os.WriteFile(store.artifact, data, 0o600); err != nil {
+ t.Fatal(err)
+ }
+ sum := sha256.Sum256(data)
+ art.Size = int64(len(data))
+ art.SHA256 = hex.EncodeToString(sum[:])
+ want = "site tar"
+ case "read":
+ store.readErr = errors.New("broken stream")
+ want = "broken stream"
+ case "panic":
+ store.panicRead = true
+ }
+ m.Artifacts[siteArtifactFile] = art
+ staticStreamManifest(t, store, m)
+ var stageErr error
+ var panicked any
+ func() {
+ defer func() { panicked = recover() }()
+ _, _, stageErr = site.ensureExtracted(t.Context(), "v1", "")
+ }()
+ if tc == "panic" {
+ if panicked == nil {
+ t.Error("expected panic")
+ }
+ } else if stageErr == nil || !strings.Contains(stageErr.Error(), want) {
+ t.Errorf("error=%v, want %q", stageErr, want)
+ }
+ if store.opens > 0 && !store.closed {
+ t.Error("stream not closed")
+ }
+ if tc == "overrun" && store.read > art.Size+1 {
+ t.Errorf("read %d bytes beyond limit %d", store.read, art.Size+1)
+ }
+ staticStreamNoDebris(t, site)
+ })
+ }
+}
+
+type staticGetFallback struct{ release.Store }
+
+func (s staticGetFallback) Open(ctx context.Context, key string) (io.ReadCloser, string, error) {
+ return release.OpenObject(ctx, s.Store, key)
+}
+
+func TestStaticStreamGetOnly(t *testing.T) {
+ for _, wrapped := range []bool{false, true} {
+ label := map[bool]string{false: "direct", true: "wrapped"}[wrapped]
+ for _, large := range []bool{false, true} {
+ t.Run(label+"/"+map[bool]string{false: "small", true: "above-ceiling"}[large], func(t *testing.T) {
+ site, store, m := staticStreamFixture(t, 1024)
+ site.store = struct{ release.Store }{store}
+ if wrapped {
+ site.store = staticGetFallback{site.store}
+ }
+ if large {
+ art := m.Artifacts[siteArtifactFile]
+ art.Size = (64 << 20) + 1
+ m.Artifacts[siteArtifactFile] = art
+ staticStreamManifest(t, store, m)
+ }
+ _, _, err := site.ensureExtracted(t.Context(), "v1", "")
+ if large {
+ if err == nil || store.gets != 0 {
+ t.Errorf("error=%v, Get calls=%d", err, store.gets)
+ }
+ staticStreamNoDebris(t, site)
+ } else if err != nil || store.gets != 1 {
+ t.Errorf("error=%v, Get calls=%d", err, store.gets)
+ }
+ })
+ }
+ }
+}
+
+func TestExtractSiteBytesCompatibility(t *testing.T) {
+ files := map[string]string{"index.html": "home", "nested/page.html": "page"}
+ data, err := PackDir(writeTree(t, files))
+ if err != nil {
+ t.Fatal(err)
+ }
+ dst := t.TempDir()
+ if err := ExtractSite(data, dst); err != nil {
+ t.Fatal(err)
+ }
+ for name, want := range files {
+ got, err := os.ReadFile(filepath.Join(dst, name))
+ if err != nil || string(got) != want {
+ t.Fatalf("%s: %q, %v", name, got, err)
+ }
+ }
+}
+
+func TestStaticStreamArtifactNameLifetime(t *testing.T) {
+ for _, fail := range []bool{false, true} {
+ t.Run(fmt.Sprintf("copy-error=%v", fail), func(t *testing.T) {
+ site, store, _ := staticStreamFixture(t, 128<<10)
+ checkNames := func() {
+ t.Helper()
+ entries, err := os.ReadDir(site.appDir())
+ if err != nil {
+ t.Fatal(err)
+ }
+ for _, entry := range entries {
+ if strings.HasPrefix(entry.Name(), ".artifact-") {
+ t.Errorf("artifact name still exists: %s", entry.Name())
+ }
+ }
+ }
+ reads := 0
+ copyErr := errors.New("forced mid-copy error")
+ store.beforeRead = func() {
+ reads++
+ if runtime.GOOS == "linux" || runtime.GOOS == "darwin" {
+ checkNames()
+ }
+ if fail && store.read > 0 {
+ store.readErr = copyErr
+ }
+ }
+ _, _, err := site.ensureExtracted(t.Context(), "v1", "")
+ if fail {
+ if !errors.Is(err, copyErr) || store.read == 0 {
+ t.Fatalf("read=%d err=%v", store.read, err)
+ }
+ staticStreamNoDebris(t, site)
+ } else if err != nil {
+ t.Fatal(err)
+ }
+ if reads < 2 || !store.closed {
+ t.Errorf("reads=%d closed=%v", reads, store.closed)
+ }
+ checkNames()
+ })
+ }
+}
+
+func TestStaticStreamMissingArtifactMigrationHint(t *testing.T) {
+ for _, getOnly := range []bool{false, true} {
+ t.Run(fmt.Sprintf("get-only=%v", getOnly), func(t *testing.T) {
+ site, store, _ := staticStreamFixture(t, 1024)
+ if getOnly {
+ site.store = struct{ release.Store }{store}
+ }
+ if err := os.Remove(store.artifact); err != nil {
+ t.Fatal(err)
+ }
+ _, _, err := site.ensureExtracted(t.Context(), "v1", "")
+ if !errors.Is(err, os.ErrNotExist) || !strings.Contains(err.Error(), "carlos accounts migrate --app site --from legacy --to bab") {
+ t.Fatalf("missing migration hint or not-found sentinel: %v", err)
+ }
+ })
+ }
+}
diff --git a/internal/edge/static_test.go b/internal/edge/static_test.go
index 05d0c4e28..4af384ff3 100644
--- a/internal/edge/static_test.go
+++ b/internal/edge/static_test.go
@@ -488,6 +488,11 @@ func (l *legacyTripwire) Get(ctx context.Context, key string) ([]byte, string, e
return l.Store.Get(ctx, key)
}
+func (l *legacyTripwire) Open(ctx context.Context, key string) (io.ReadCloser, string, error) {
+ l.trip("opened", key)
+ return release.OpenObject(ctx, l.Store, key)
+}
+
func (l *legacyTripwire) List(ctx context.Context, prefix string) ([]string, error) {
l.trip("listed", prefix)
return l.Store.List(ctx, prefix)
@@ -529,6 +534,9 @@ func TestStaticExtractNeverReadsALegacyArtifact(t *testing.T) {
}
s := &legacyTripwire{Store: dir, t: t, app: "site"}
+ if _, ok := any(s).(release.Opener); !ok {
+ t.Fatal("legacy tripwire does not guard streaming Open")
+ }
rt := registry.Route{Host: "site.example.com", Kind: "static", App: "site", Channel: "canary/x", Status: "ready"}
h := newStaticHandler(rt, s, pub, filepath.Join(t.TempDir(), "cache"))
h.(*staticSite).recheck = 0
diff --git a/internal/provision/testdata/plan14-root-reads-chain.tsv b/internal/provision/testdata/plan14-root-reads-chain.tsv
index 408b05739..cdf76193c 100644
--- a/internal/provision/testdata/plan14-root-reads-chain.tsv
+++ b/internal/provision/testdata/plan14-root-reads-chain.tsv
@@ -72,3 +72,4 @@ plan14-root-reads-region-ha-placement-survivor.tsv 09ad1d7267b9598c64e89ec0faa7b
plan14-root-reads-domains-buy-nosub.tsv 09ad1d7267b9598c64e89ec0faa7b18839c785c5c63905b398afe681cf9777c6
plan14-root-reads-wake-storm-cap.tsv b0fc198c53bb0dacba33a54c3d8bf8fe5ac07d94b76a31b8a69e9411115ecd85
plan14-root-reads-domains-check-country.tsv b0fc198c53bb0dacba33a54c3d8bf8fe5ac07d94b76a31b8a69e9411115ecd85
+plan14-root-reads-static-stream-extract.tsv 7fb932b118e67e23b33a374c6a4020b38976667c7ec4cfb855c0f8b598b1756b
diff --git a/internal/provision/testdata/plan14-root-reads-static-stream-extract.tsv b/internal/provision/testdata/plan14-root-reads-static-stream-extract.tsv
new file mode 100644
index 000000000..864fc2be1
--- /dev/null
+++ b/internal/provision/testdata/plan14-root-reads-static-stream-extract.tsv
@@ -0,0 +1,9 @@
+# Census overlay static-stream-extract, written by census-propose (#369). census-ruling-static-stream-extract, approved on #280 before the merge; the approval card is docs/superpowers/notes/census-proposal-static-stream-extract.md.
+# 1 body, 0 sites, 2 envelope: each changed unit re-frozen at its existing disposition with its claim appended.
+# 1 new dispositions: 1 reads re-frozen at their disposition with the claim, 0 new units frozen accepted-legacy, 0 quiet units retired while they read nothing, 0 other.
+@legacy 6ec53b85baeb153fff041965262373ce5bee8f9fae7c77a1543be9cf4dc44111 internal/edge/static.go extractSiteTar legacy accepted-legacy accepted-legacy;rev3=J4;basis=root-input;rev3=census-ruling-static-stream-extract;basis=Accepts io.Reader instead of []byte; gzip reads the verified temporary file supplied by ensureExtracted or the bytes.NewReader adapter in ExtractSite. The extraction paths, file opens, path validation and entry-type refusals are unchanged. No new read site or authority. file:OpenFile@776 825ce7522436a7da19e5dc967f3e86276fb5ecac0ae7e283b516e3182b94864f
+@legacy 1383b1549db9a213a9038ede7462d2b148e6a81763597564e37780fb8e25705a internal/edge/static.go staticSite.ensureExtracted legacy accepted-legacy accepted-legacy;rev3=J4;basis=root-input;rev3=census-ruling-static-stream-extract;basis=Streams the same account-qualified artifact into a private CreateTemp file under the existing site app directory; adds file:CreateTemp, then reads that same open file only after exact manifest size and SHA256 verification. Limits streaming reads to manifest size plus one and refuses Get fallback above a 64 MiB manifest size, including through wrappers. Keeps the existing mutex, manifest digest binding, cache destination and atomic rename; On linux or darwin immediately unlinks only the name ensureExtracted itself just created, then works solely through the open handle; refuses an unlink failure and retains close/remove cleanup until unlink succeeds. Other platforms keep deferred close/remove. Defers extraction cleanup and logs successful stages. OpenQualifiedStreaming restores the existing qualified-miss migration hint without adding reads or permitting Get fallback; size overruns report more than the manifest size. No deployment record writes or root authority change. file:CreateTemp@1570,file:Stat@2834,file:Stat@346 4e31d41b0079ad039904a021683d49c61397226d2c91ea7bf4eee955bcef73fc
+internal/edge/static.go extractSiteTar legacy accepted-legacy accepted-legacy;rev3=J4;basis=root-input;rev3=census-ruling-static-stream-extract;basis=Accepts io.Reader instead of []byte; gzip reads the verified temporary file supplied by ensureExtracted or the bytes.NewReader adapter in ExtractSite. The extraction paths, file opens, path validation and entry-type refusals are unchanged. No new read site or authority. file:OpenFile@776 825ce7522436a7da19e5dc967f3e86276fb5ecac0ae7e283b516e3182b94864f
+internal/edge/static.go staticSite.ensureExtracted legacy accepted-legacy accepted-legacy;rev3=J4;basis=root-input;rev3=census-ruling-static-stream-extract;basis=Streams the same account-qualified artifact into a private CreateTemp file under the existing site app directory; adds file:CreateTemp, then reads that same open file only after exact manifest size and SHA256 verification. Limits streaming reads to manifest size plus one and refuses Get fallback above a 64 MiB manifest size, including through wrappers. Keeps the existing mutex, manifest digest binding, cache destination and atomic rename; On linux or darwin immediately unlinks only the name ensureExtracted itself just created, then works solely through the open handle; refuses an unlink failure and retains close/remove cleanup until unlink succeeds. Other platforms keep deferred close/remove. Defers extraction cleanup and logs successful stages. OpenQualifiedStreaming restores the existing qualified-miss migration hint without adding reads or permitting Get fallback; size overruns report more than the manifest size. No deployment record writes or root authority change. file:CreateTemp@1570,file:Stat@2834,file:Stat@346 4e31d41b0079ad039904a021683d49c61397226d2c91ea7bf4eee955bcef73fc
+@coverage internal/edge e130c816c1c8d34812ca2aabf3302735881d9d8049a46fc275cd3744028a6d5d
+@coverage internal/release 2d80d868274dbb67d8e06eb132f7af2f1f07a44c42d0fcc22a3f4dc4adf27f81
diff --git a/internal/release/qualified.go b/internal/release/qualified.go
index 72f71f2ca..8ba437fbb 100644
--- a/internal/release/qualified.go
+++ b/internal/release/qualified.go
@@ -100,6 +100,14 @@ func OpenQualified(ctx context.Context, s Store, key string) (io.ReadCloser, str
return rc, etag, err
}
+func OpenQualifiedStreaming(ctx context.Context, s Store, key string) (io.ReadCloser, string, error) {
+ rc, etag, err := OpenObjectStreaming(ctx, s, key)
+ if err != nil && errors.Is(err, os.ErrNotExist) {
+ return nil, "", fmt.Errorf("%w%s", err, migrationHint(key))
+ }
+ return rc, etag, err
+}
+
// migrationHint turns a miss on an account-qualified APP key into the exact
// command that fixes it, for the one deployment shape that produces a
// surprising 404: upgraded from a pre-accounts binary, objects still at