carlos / platform Public

console: file seeds on a region, through the import door

A create whose import object says "kind":"file" begins a file seed:
reserving, kind file, the sha256 and length the upload must match, and
no Replaces or VerifyHash. The import's PUT takes it, puts the snapshot
at seeds.SnapshotKey in the data bucket and publishes it ready. A length
or sha256 mismatch aborts the seed at once with FS-17 through the record
CAS. Readiness asks for the file protocol in the floor and on every box,
with no one-box rule, at begin and at the upload (R1-3).
seedStorageRefusal is the one storage check for begin and upload (R2-2);
the import's refusal is unchanged. The sweep aborts a stuck reservation
and the finish deletes a file seed's region replica, as --from's.

Fleet records stay refused with seedPlacementRefusal's sentence.
Record-write census: fleet_seeded_create_1 (abortFileSeed new, seven
re-pins including Task 4's two). FS-41 to FS-43 added to the copy table,
pending.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 5e1927bfdc33116467bc62e61fca40c6a7f88b09 parent 479913f
13 files changed, +928 −46
  • docs/superpowers/plans/2026-11-20-fleet-seeded-create.md +3 −0
  • internal/console/apiinstanceimport.go +78 −34
  • internal/console/apiinstances.go +2 −2
  • internal/console/demo_claim_gate_causes_test.go +2 −2
  • internal/console/demo_claim_seed.go +1 −1
  • internal/console/seedfile.go +293 −0
  • internal/console/seedfile_copy.go +31 −0
  • internal/console/seedfile_test.go +429 −0
  • internal/console/seedfinish.go +3 −1
  • internal/console/seedfloor.go +11 −3
  • internal/console/seedsweep.go +3 −2
  • internal/provision/fleet_seeded_create_1_census_test.go +71 −0
  • internal/provision/plan9_b8_census_test.go +1 −1

CI failed — run details

diff --git a/docs/superpowers/plans/2026-11-20-fleet-seeded-create.md b/docs/superpowers/plans/2026-11-20-fleet-seeded-create.md
index f464c5b0f..cfe4f5f47 100644
--- a/docs/superpowers/plans/2026-11-20-fleet-seeded-create.md
+++ b/docs/superpowers/plans/2026-11-20-fleet-seeded-create.md
@@ -846,6 +846,9 @@ House rules applied: no em dashes; curly apostrophes; placeholders in their orde
| FS-37 | (FS-34's location, `held` staging) moves/%s/ | new | approved (Paul, 2026-11-20) (Decision D12) |
| FS-38 | (FS-34's location, `held` both: FS-36, then FS-37) %s and %s | new | approved (Paul, 2026-11-20) (Decision D12) |
| FS-35 | %s can’t be deleted permanently until its fleet box has cleaned up %s. | %s can’t be purged yet: %s still hold their hostnames until their fleet box has cleaned up. | approved (Paul, 2026-11-20) (the Trash page's "Delete now", and the trash sweep's log) |
+| FS-41 | kind must be file, or left out for an import | new | pending (Task 5) (an import object whose kind is neither absent nor `file`; 400, as the sibling shape sentences SD-N48 and the sha256 rule; only a hand-written API call reaches it) |
+| FS-42 | began seeding %s from a file (%s, %d bytes) | new | pending (Task 5) (the begin's `instance-seed` activity row: host, first 12 of the sha256, length; as the import's "began an import of …") |
+| FS-43 | uploaded the seed file for %s | new | pending (Task 5) (the upload's `seed-file-uploaded` activity row; as the import's "uploaded the snapshot for %s") |
| — | the upload is not a database that passes an integrity check, so it was not kept. (and the other upload sentences) | same | approved (Paul, 2026-11-20); reused (SD-N52, SD-N61, SD-N67) |
| — | %s places its instances in a pool or on a fleet, so it cannot take a seeded instance. | same | approved (Paul, 2026-11-20); reused, unchanged, for `--from` and import |
| — | (region begin refusals) SD-N2 to SD-N8 and SD-N38 | same | approved (Paul, 2026-11-20); reused |
diff --git a/internal/console/apiinstanceimport.go b/internal/console/apiinstanceimport.go
index 325b29e20..5f92f45c8 100644
--- a/internal/console/apiinstanceimport.go
+++ b/internal/console/apiinstanceimport.go
@@ -38,6 +38,11 @@ type seedImportReq struct {
SHA256 string `json:"sha256"`
Bytes int64 `json:"bytes"`
Replaces string `json:"replaces"`
+ // Kind is "" for an import and seeds.KindFile for a file seed (fleet
+ // seeded create, Decision D2): the begin rides this object so that an
+ // old console, which drops the field, refuses the body on its missing
+ // replaces before writing anything.
+ Kind string `json:"kind,omitempty"`
}
// importFailed is the import door's retry sentence (SD-N67).
@@ -71,14 +76,10 @@ func seedOneDoorRefusal(from, imp bool) *doorRefusal {
// limit, the hash's spelling, and replaces as host:port with a port in
// 1 to 65535.
func importShapeRefusal(imp seedImportReq) *doorRefusal {
- switch {
- case imp.Bytes <= 0:
- return &doorRefusal{Status: http.StatusBadRequest, Msg: importSizeRule}
- case imp.Bytes > seedMaxBytes:
- return &doorRefusal{Status: http.StatusRequestEntityTooLarge, Msg: importSizeRule}
- case !sha256Hex.MatchString(imp.SHA256):
- return &doorRefusal{Status: http.StatusBadRequest, Msg: "sha256 must be 64 lowercase hex characters"}
- case !validReplaces(imp.Replaces):
+ if ref := seedSizeHashRefusal(imp); ref != nil {
+ return ref
+ }
+ if !validReplaces(imp.Replaces) {
return &doorRefusal{Status: http.StatusBadRequest, Msg: "replaces must name the address the import takes over, as host:port"}
}
return nil
@@ -97,7 +98,19 @@ func validReplaces(addr string) bool {
// until the door is done, so that a begin which fails after writing its
// record has rolled that record back and finished it (freeing the host)
// before the refusal reaches the caller (preflight M2).
+//
+// A body whose kind is "file" is a file seed's begin (seedfile.go), and
+// any other kind is refused before anything is written.
func (s *Server) createImport(w http.ResponseWriter, r *http.Request, c seedCreate, imp seedImportReq) {
+ switch imp.Kind {
+ case "":
+ case seeds.KindFile:
+ s.createFileSeed(w, r, c, imp)
+ return
+ default:
+ jsonError(w, http.StatusBadRequest, fileSeedKindCopy)
+ return
+ }
held := &heldResponse{header: w.Header()}
s.beginImport(held, r, c, imp)
held.flush(w, importFailed)
@@ -119,8 +132,7 @@ func (s *Server) beginImport(w http.ResponseWriter, r *http.Request, c seedCreat
if s.refuseHAImport(w, &c.rec) {
return
}
- if s.cfg.SeedData == nil || s.cfg.HibernateBucket == "" {
- ref := seedNoDataRefusal()
+ if ref := s.seedStorageRefusal(seeds.KindImport, c.rec.Region); ref != nil {
jsonError(w, ref.Status, ref.Msg)
return
}
@@ -301,8 +313,9 @@ const importUploadReadDeadline = 60 * time.Minute
// importGate is every import call's gate: the instance gate (cliRoute has
// already applied the instance role), the claim console's refusal, the
// host, the record, that the record is an import (SD-N59), and that it is
-// the import the caller names (SD-N60).
-func (s *Server) importGate(w http.ResponseWriter, r *http.Request) (principal string, acct *Account, app, host string, rec *provision.Record, ok bool) {
+// the import the caller names (SD-N60). upload is the PUT's: it alone
+// also takes a file seed, which has no stopped, commit or abort.
+func (s *Server) importGate(w http.ResponseWriter, r *http.Request, upload bool) (principal string, acct *Account, app, host string, rec *provision.Record, ok bool) {
principal, acct, app, ok = s.instanceGate(w, r)
if !ok {
return "", nil, "", "", nil, false
@@ -338,7 +351,7 @@ func (s *Server) importGate(w http.ResponseWriter, r *http.Request) (principal s
jsonError(w, ref.Status, ref.Msg)
return "", nil, "", "", nil, false
}
- if !rec.Seed.Import() {
+ if !rec.Seed.Import() && !(upload && seedTakesUpload(rec.Seed)) {
ref := notAnImportRefusal(host)
jsonError(w, ref.Status, ref.Msg)
return "", nil, "", "", nil, false
@@ -368,6 +381,7 @@ type importUpload struct {
acct *Account
app, host, by string
id string
+ kind string // the seed's: seeds.KindImport or seeds.KindFile
dir, spool string
release func()
// unit is the request's admitted unit, handed over before the
@@ -387,13 +401,13 @@ type importUpload struct {
// for a 30-minute check and a 4 GiB put. The caller follows the record
// until it is uploaded, or aborted with the reason in Seed.Reason.
func (s *Server) handleAPIImportUpload(w http.ResponseWriter, r *http.Request) {
- principal, acct, app, host, rec, ok := s.importGate(w, r)
+ principal, acct, app, host, rec, ok := s.importGate(w, r, true)
if !ok {
return
}
ctx := r.Context()
seed := rec.Seed
- if s.refuseHAImport(w, rec) {
+ if s.refuseHASeed(w, rec, seed.Kind) {
return
}
if ref := staleUploadRefusal(host, rec, seed.ID); ref != nil {
@@ -407,13 +421,12 @@ func (s *Server) handleAPIImportUpload(w http.ResponseWriter, r *http.Request) {
jsonError(w, http.StatusBadGateway, importFailed)
return
}
- if s.cfg.SeedData == nil || s.cfg.HibernateBucket == "" {
- ref := seedNoDataRefusal()
+ if ref := s.seedStorageRefusal(seed.Kind, rec.Region); ref != nil {
jsonError(w, ref.Status, ref.Msg)
return
}
checks, cancel := context.WithTimeout(ctx, instanceStoreTimeout)
- ref := s.seedRegionReady(checks, rec.Region, true)
+ ref := s.seedUploadReady(checks, rec)
cancel()
if ref != nil {
jsonError(w, ref.Status, ref.Msg)
@@ -463,14 +476,14 @@ func (s *Server) handleAPIImportUpload(w http.ResponseWriter, r *http.Request) {
}
}()
spool := filepath.Join(dir, host+".db")
- if !s.spoolImport(w, r, spool, seed) {
+ if !s.spoolImport(w, r, spool, seed, acct.Sqid, app) {
return
}
writeJSON(w, http.StatusAccepted, map[string]string{"state": "checking"})
handedOver = true
s.seedCopies.Add(1)
go s.runImportUpload(&importUpload{ctx: context.WithoutCancel(ctx), acct: acct, app: app, host: host, by: principal,
- id: seed.ID, dir: dir, spool: spool, release: releaseScratch, unit: detachUnit(ctx)})
+ id: seed.ID, kind: seed.Kind, dir: dir, spool: spool, release: releaseScratch, unit: detachUnit(ctx)})
}
// readImportRecord reads host's record under instanceStoreTimeout.
@@ -481,10 +494,20 @@ func (s *Server) readImportRecord(ctx context.Context, sqid, app, host string) (
return rec, err
}
-// awaitingUpload reports whether rec's seed is the import id, still
-// waiting for its upload.
+// awaitingUpload reports whether rec's seed is seed id, still waiting for
+// its upload: an import awaiting-upload, or a file seed still reserving.
func awaitingUpload(rec *provision.Record, id string) bool {
- return rec.Seed.Import() && rec.Seed.ID == id && rec.Seed.State == seeds.StateAwaitingUpload
+ seed := rec.Seed
+ if seed == nil || seed.ID != id {
+ return false
+ }
+ switch seed.Kind {
+ case seeds.KindImport:
+ return seed.State == seeds.StateAwaitingUpload
+ case seeds.KindFile:
+ return seed.State == seeds.StateReserving
+ }
+ return false
}
// notAnImportRefusal is SD-N59.
@@ -499,7 +522,7 @@ func staleUploadRefusal(host string, rec *provision.Record, id string) *doorRefu
switch {
case awaitingUpload(rec, id):
return nil
- case !rec.Seed.Import():
+ case !seedTakesUpload(rec.Seed):
return notAnImportRefusal(host)
}
return &doorRefusal{Status: http.StatusConflict, Msg: fmt.Sprintf("%s is %s. It takes an upload only while it waits for one.", host, rec.Seed.State)}
@@ -508,8 +531,10 @@ func staleUploadRefusal(host string, rec *provision.Record, id string) *doorRefu
// spoolImport reads the body into spool, never more than the declared
// length and one byte, hashing as it writes, and reports whether it
// matches begin's length and sha256. It has answered w when it reports
-// false.
-func (s *Server) spoolImport(w http.ResponseWriter, r *http.Request, spool string, seed *provision.SeedSource) bool {
+// false. A file seed whose upload does not match is aborted before the
+// answer (Paul, 2026-11-20): an import waits for the right file, a file
+// seed does not.
+func (s *Server) spoolImport(w http.ResponseWriter, r *http.Request, spool string, seed *provision.SeedSource, sqid, app string) bool {
host := r.PathValue("host")
// The server's ReadTimeout would cut a large body; this read gets an
// hour. Go drops the deadline once the body has been read.
@@ -542,6 +567,11 @@ func (s *Server) spoolImport(w http.ResponseWriter, r *http.Request, spool strin
jsonError(w, http.StatusBadGateway, importFailed)
return false
case tooLong != nil || n != seed.Bytes || hex.EncodeToString(h.Sum(nil)) != seed.SHA256:
+ if seed.Kind == seeds.KindFile {
+ s.abortFileSeed(r.Context(), sqid, app, host, seed.ID, fileSeedMismatchCopy, "mismatched upload")
+ jsonError(w, http.StatusUnprocessableEntity, fileSeedMismatchCopy)
+ return false
+ }
jsonError(w, http.StatusUnprocessableEntity, "the upload does not match the length and sha256 this import began with, so it was not kept.")
return false
}
@@ -553,9 +583,10 @@ func (s *Server) spoolImport(w http.ResponseWriter, r *http.Request, spool strin
// the request, which has been answered. A failure moves the record to
// aborted with the sentence the door would have answered in Seed.Reason
// (SD-N52, SD-N61 or SD-N67), but only while the record still waits for
-// this upload (SeedAbortUploadBecause): an import that has moved on, by
-// another upload, an abort or a delete, is never touched, and neither is
-// a snapshot already at its key (fix round 1). On every exit it removes
+// this upload (SeedAbortUploadBecause, or SeedAbortFileUploadBecause for a
+// file seed, whose upload lands as ready rather than uploaded): an import
+// that has moved on, by another upload, an abort or a delete, is never
+// touched, and neither is a snapshot already at its key (fix round 1). On every exit it removes
// the spool's directory and then releases the reservation, as runFrom
// does.
//
@@ -570,10 +601,16 @@ func (s *Server) runImportUpload(j *importUpload) {
defer j.release()
ctx := j.ctx
sqid, app, host := j.acct.Sqid, j.app, j.host
+ // A file seed has --from's states: its abort is only while it is
+ // reserving, and its upload publishes it ready (seedfile.go).
+ abortStep, landed := provision.SeedAbortUploadBecause, provision.SeedUploaded
+ if j.kind == seeds.KindFile {
+ abortStep, landed = provision.SeedAbortFileUploadBecause, provision.SeedPublishFile
+ }
abort := func(reason, why string) {
bg, cancel := context.WithTimeout(ctx, instanceStoreTimeout)
defer cancel()
- _, err := provision.SetRecordSeed(bg, s.cfg.Releases, sqid, app, host, provision.SeedAbortUploadBecause(j.id, reason))
+ _, err := provision.SetRecordSeed(bg, s.cfg.Releases, sqid, app, host, abortStep(j.id, reason))
switch {
case errors.Is(err, provision.ErrSeedConflict), errors.Is(err, os.ErrNotExist):
log.Printf("console: import %s: seed %s moved on before its upload's %s was recorded; not aborted: %v", host, j.id, why, err)
@@ -639,7 +676,7 @@ func (s *Server) runImportUpload(j *importUpload) {
}
pctx, pcancel := context.WithTimeout(ctx, instanceStoreTimeout)
defer pcancel()
- _, err = provision.SetRecordSeed(pctx, s.cfg.Releases, sqid, app, host, provision.SeedUploaded(j.id))
+ _, err = provision.SetRecordSeed(pctx, s.cfg.Releases, sqid, app, host, landed(j.id))
switch {
case errors.Is(err, provision.ErrSeedConflict), errors.Is(err, os.ErrNotExist):
log.Printf("console: import %s: seed %s moved on before it was marked uploaded; not aborted: %v", host, j.id, err)
@@ -649,6 +686,13 @@ func (s *Server) runImportUpload(j *importUpload) {
abort(importFailed, "the record write")
return
}
+ if j.kind == seeds.KindFile {
+ s.auditActivity(j.acct, app, j.by, Activity{Action: "seed-file-uploaded", TargetType: "instance", Target: host,
+ Detail: fmt.Sprintf(fileSeedUploadedAudit, host)})
+ // Ready is the box's cue to place it: tell the boxes now.
+ s.bumpSerial(pctx)
+ return
+ }
s.auditActivity(j.acct, app, j.by, Activity{Action: "import-uploaded", TargetType: "instance", Target: host,
Detail: fmt.Sprintf("uploaded the snapshot for %s", host)})
}
@@ -716,7 +760,7 @@ func (s *Server) importTransitionFailure(w http.ResponseWriter, app, host string
// races an abort, a delete or a second stopped changes nothing but its own
// answer; the check below only picks the sentence.
func (s *Server) handleAPIImportStopped(w http.ResponseWriter, r *http.Request) {
- principal, acct, app, host, rec, ok := s.importGate(w, r)
+ principal, acct, app, host, rec, ok := s.importGate(w, r, false)
if !ok {
return
}
@@ -764,7 +808,7 @@ func (s *Server) handleAPIImportStopped(w http.ResponseWriter, r *http.Request)
// edge checks on the app's own requests (spec §5.5), and this door never
// sees it. Committed already answers 200, so a retried commit is safe.
func (s *Server) handleAPIImportCommit(w http.ResponseWriter, r *http.Request) {
- principal, acct, app, host, rec, ok := s.importGate(w, r)
+ principal, acct, app, host, rec, ok := s.importGate(w, r, false)
if !ok {
return
}
@@ -877,7 +921,7 @@ func (s *Server) readDeletedRecord(ctx context.Context, sqid, app, host string)
// is left to the next abort or the sweep. An abort that loses its race
// re-reads once and answers by what won.
func (s *Server) handleAPIImportAbort(w http.ResponseWriter, r *http.Request) {
- principal, acct, app, host, rec, ok := s.importGate(w, r)
+ principal, acct, app, host, rec, ok := s.importGate(w, r, false)
if !ok {
return
}
diff --git a/internal/console/apiinstances.go b/internal/console/apiinstances.go
index 9558740c6..3fd04c32b 100644
--- a/internal/console/apiinstances.go
+++ b/internal/console/apiinstances.go
@@ -2520,11 +2520,11 @@ func (s *Server) handleAPIInstanceCreate(w http.ResponseWriter, r *http.Request)
}
if seeded && s.haRegion(region) {
c := seedCreate{rec: rec, placed: placed, m: m, app: app}
- if ref := seedPlacementRefusal(c); ref != nil {
+ if ref := seedDoorPlacementRefusal(c, req.Import); ref != nil {
jsonError(w, ref.Status, ref.Msg)
return
}
- if req.Import != nil && s.refuseHAImport(w, &rec) {
+ if req.Import != nil && s.refuseHASeed(w, &rec, req.Import.Kind) {
return
}
}
diff --git a/internal/console/demo_claim_gate_causes_test.go b/internal/console/demo_claim_gate_causes_test.go
index 44e85bdb0..9b99fa950 100644
--- a/internal/console/demo_claim_gate_causes_test.go
+++ b/internal/console/demo_claim_gate_causes_test.go
@@ -99,7 +99,7 @@ func TestDemoClaimReadinessSeedRefusalCauses(t *testing.T) {
s, _, _ := claimTestServer(t)
claimActivationFixture(t, s)
tc.change(t, s)
- if s.seedRegionReadyForEdges(t.Context(), s.cfg.Region, false, demoClaimEdge) == nil {
+ if s.seedRegionReadyForEdges(t.Context(), s.cfg.Region, false, 0, demoClaimEdge) == nil {
t.Fatal("fixture did not reach an existing seed refusal")
}
var output bytes.Buffer
@@ -198,7 +198,7 @@ func TestDemoClaimSeedCauseChecksPreserveAcceptance(t *testing.T) {
t.Fatal(err)
}
}
- if ref := s.seedRegionReadyForEdges(t.Context(), s.cfg.Region, false, demoClaimEdge); ref != nil {
+ if ref := s.seedRegionReadyForEdges(t.Context(), s.cfg.Region, false, 0, demoClaimEdge); ref != nil {
t.Fatalf("existing refusal: %+v", ref)
}
if gates := s.demoClaimSeedGates(t.Context(), s.cfg.Region); len(gates) != 0 {
diff --git a/internal/console/demo_claim_seed.go b/internal/console/demo_claim_seed.go
index a4261e4db..aca779344 100644
--- a/internal/console/demo_claim_seed.go
+++ b/internal/console/demo_claim_seed.go
@@ -47,7 +47,7 @@ func (s *Server) demoClaimSeedGates(ctx context.Context, region string) demoClai
if s.cfg.Releases == nil {
return gates
}
- gates.check("seed-region", s.seedRegionReadyForEdges(ctx, region, false, demoClaimEdge) == nil)
+ gates.check("seed-region", s.seedRegionReadyForEdges(ctx, region, false, 0, demoClaimEdge) == nil)
floor, err := seeds.ReadFloor(ctx, s.cfg.Releases)
gates.check("seed-floor", err == nil && floor != nil && floor.Min >= seeds.DemoClaimProtocol)
if floor != nil {
diff --git a/internal/console/seedfile.go b/internal/console/seedfile.go
new file mode 100644
index 000000000..84217002f
--- /dev/null
+++ b/internal/console/seedfile.go
@@ -0,0 +1,293 @@
+// File seeds (#1139, fleet seeded create design §3): `carlos instances
+// create --seed-file <db>` starts a new instance from an uploaded SQLite
+// file. It rides the import door's two calls: begin is the create door
+// with "import":{"kind":"file",...} in its body, and the upload is the
+// import's streamed PUT. The seed has --from's states (reserving, ready,
+// placed; aborted, rolled-back), not the import's swap, so a region file
+// seed is --from-shaped everywhere except how its bytes arrive.
+//
+// This file holds the file seed's begin, its readiness rule and the
+// helpers the import door calls when it meets a file seed. Fleet records
+// are refused here until slice 3 of the plan.
+
+package console
+
+import (
+ "context"
+ "errors"
+ "fmt"
+ "log"
+ "net/http"
+ "os"
+ "time"
+
+ "github.com/carlosframework/platform/internal/provision"
+ "github.com/carlosframework/platform/internal/regionlabel"
+ "github.com/carlosframework/platform/internal/release"
+ "github.com/carlosframework/platform/internal/seeds"
+)
+
+// createFileSeed is the file seed's begin, held like the import's so that
+// every refusal reaches the caller after anything the door wrote has been
+// put on its way out.
+func (s *Server) createFileSeed(w http.ResponseWriter, r *http.Request, c seedCreate, imp seedImportReq) {
+ held := &heldResponse{header: w.Header()}
+ s.beginFileSeed(held, r, c, imp)
+ held.flush(w, importFailed)
+}
+
+// beginFileSeed runs after the create door's own checks, seedOneDoorRefusal
+// and seedCommonRefusal among them. It refuses a pool (FS-20), a fleet
+// (seedPlacementRefusal's sentence, until slice 3) and an HA region
+// (FS-16); a region record must be in this console's region (FS-15), as
+// the import's must, because the snapshot goes to this console's data
+// bucket. Then seedFileReady, the size and sha256, and private storage as
+// the import does. The record is written reserving, kind file, with the
+// sha256 and length the upload must match and no Replaces or VerifyHash,
+// before any byte of the snapshot is stored (design §3.2). It answers 201
+// with the record view.
+//
+// A failure after the record is written aborts the seed with the refusal
+// as its reason, as --from's copy does. The box's rollback and the
+// console's finish then free the hostname; nothing here deletes the record,
+// because a box may already have minted a row for it.
+func (s *Server) beginFileSeed(w http.ResponseWriter, r *http.Request, c seedCreate, imp seedImportReq) {
+ ctx := r.Context()
+ acct, app, host := c.acct, c.app, c.rec.Host
+ if ref := fileSeedPlacementRefusal(c); ref != nil {
+ jsonError(w, ref.Status, ref.Msg)
+ return
+ }
+ if s.refuseHASeed(w, &c.rec, seeds.KindFile) {
+ return
+ }
+ if ref := s.seedStorageRefusal(seeds.KindFile, c.rec.Region); ref != nil {
+ jsonError(w, ref.Status, ref.Msg)
+ return
+ }
+ if c.rec.Region != s.cfg.Region {
+ jsonError(w, http.StatusConflict, fmt.Sprintf(fileSeedRegionCopy, s.dbRegionName(s.cfg.Region), host))
+ return
+ }
+ checks, cancel := context.WithTimeout(ctx, instanceStoreTimeout)
+ defer cancel()
+ if ref := s.seedFileReady(checks, c.rec.Region); ref != nil {
+ jsonError(w, ref.Status, ref.Msg)
+ return
+ }
+ // Replaces is the import's; a file seed swaps nothing, so it is not
+ // read, and nothing of it is kept.
+ if ref := seedSizeHashRefusal(imp); ref != nil {
+ jsonError(w, ref.Status, ref.Msg)
+ return
+ }
+ id, err := seeds.NewID()
+ if err != nil {
+ log.Printf("console: seed file %s: seed id: %v", host, err)
+ jsonError(w, http.StatusBadGateway, importFailed)
+ return
+ }
+ if c.m.PrivateStorage {
+ // The store gates that write nothing, before the record (ruling
+ // R3): their refusals leave nothing holding the host.
+ if _, ok := s.instanceStorePreflight(ctx, w, acct, app); !ok {
+ return
+ }
+ storeCtx, storeCancel := context.WithTimeout(ctx, instanceStoreTimeout)
+ ref := s.seedStoreRefusal(storeCtx, c, id, importFailed)
+ storeCancel()
+ if ref != nil {
+ jsonError(w, ref.Status, ref.Msg)
+ return
+ }
+ }
+
+ rec := c.rec
+ rec.Seed = &provision.SeedSource{ID: id, Kind: seeds.KindFile, SHA256: imp.SHA256, Bytes: imp.Bytes,
+ State: seeds.StateReserving, By: c.principal, At: time.Now().UTC()}
+ if err := provision.EnsureAssetGen(&rec); err != nil {
+ log.Printf("console: seed file %s: asset generation: %v", host, err)
+ jsonError(w, http.StatusBadGateway, importFailed)
+ return
+ }
+ // Not the request's cancellation: a client leaving now must not turn a
+ // write that landed into an error.
+ writeCtx, writeCancel := context.WithTimeout(context.WithoutCancel(ctx), instanceStoreTimeout)
+ err = s.createSeedRecord(writeCtx, c, rec)
+ writeCancel()
+ if err != nil {
+ // A pending lifetime create's record, once recovery writes it, is a
+ // reserving file seed, which the seeds sweep abandons.
+ if ref, ok := lifetimeCreateRefusal(host, err, msgLifetimeUploadPending); ok {
+ log.Printf("console: seed file %s: write the record: %v", host, err)
+ writeDoorRefusalJSON(w, r, ref)
+ return
+ }
+ if errors.Is(err, release.ErrCASConflict) {
+ jsonError(w, http.StatusConflict, "instance "+host+" already exists")
+ return
+ }
+ // The write may have landed all the same: abort it by its seed id,
+ // which touches nothing if it did not.
+ log.Printf("console: seed file %s: write the record: %v", host, err)
+ s.abortFileSeed(ctx, acct.Sqid, app, host, id, importFailed, "a failed record write")
+ jsonError(w, http.StatusBadGateway, importFailed)
+ return
+ }
+
+ // From here every failure aborts the seed before the answer goes out.
+ privateBucket := ""
+ if c.m.PrivateStorage {
+ // The refusal is held on its own, so that its sentence can be the
+ // seed's reason too.
+ inner := &heldResponse{header: w.Header()}
+ storeRec, ok, err := s.instanceStoreProvisionFor(ctx, inner, acct, app, rec.Environment, c.principal, id)
+ if !ok {
+ switch {
+ case errors.Is(err, errSeedStoreTaken):
+ ref := seedStoreTakenRefusal(rec.Environment, app, storeRec)
+ jsonError(inner, ref.Status, ref.Msg)
+ case errors.Is(err, errSeedEnvironmentUnread):
+ jsonError(inner, http.StatusBadGateway, importFailed)
+ }
+ s.abortFileSeed(ctx, acct.Sqid, app, host, id, inner.message(importFailed), "store provisioning")
+ inner.flush(w, importFailed)
+ return
+ }
+ privateBucket = storeBucketName(storeRec)
+ }
+ // The create door's re-check after its write (apiinstances.go): an app
+ // created under the host's label since the door asked owns its apex.
+ if c.siblingLabel != "" {
+ if live, trashed, err := s.store.AppNameState(acct.ID, c.siblingLabel); err == nil && (live || trashed) {
+ reason := seedSiblingApexReason(host, c.siblingLabel)
+ s.abortFileSeed(ctx, acct.Sqid, app, host, id, reason, "a sibling app took the label")
+ jsonError(w, http.StatusConflict, reason)
+ return
+ }
+ }
+
+ s.auditActivity(acct, app, c.principal, Activity{
+ Action: "instance-seed", TargetType: "instance", Target: host, Message: c.message,
+ Detail: fmt.Sprintf(fileSeedBeganAudit, host, imp.SHA256[:12], imp.Bytes),
+ })
+ viewCtx, viewCancel := context.WithTimeout(context.WithoutCancel(ctx), instanceStoreTimeout)
+ defer viewCancel()
+ out := s.publicRecordView(ctx, rec)
+ out.PrivateStoreBucket = privateBucket
+ out.RegionFrom = c.regionFrom
+ out.RegionName = s.placeOf(rec.Region, s.candsOrHome(viewCtx)) // never fleet-placed: refused above
+ // The region's label (region labels §4), as every create answer has.
+ out.RegionLabel = regionlabel.ForRecord(rec, s.regionHome(), s.regionNames()).Text
+ writeJSON(w, http.StatusCreated, out)
+}
+
+// fileSeedPlacementRefusal is a file seed's placement rule. A pool has its
+// own sentence (FS-20), since file seeds will reach a fleet but not a pool.
+// A fleet keeps seedPlacementRefusal's sentence until slice 3 admits it.
+func fileSeedPlacementRefusal(c seedCreate) *doorRefusal {
+ if c.rec.Demo != nil || c.placed != "" {
+ return seedPlacementRefusal(c)
+ }
+ if c.m.Pool != "" {
+ return &doorRefusal{Status: http.StatusConflict, Msg: fmt.Sprintf(fileSeedPoolCopy, c.app)}
+ }
+ return nil
+}
+
+// seedDoorPlacementRefusal is the create door's early placement check for
+// a seeded create in an HA region: imp is the body's import object, nil
+// for --from.
+func seedDoorPlacementRefusal(c seedCreate, imp *seedImportReq) *doorRefusal {
+ if imp != nil && imp.Kind == seeds.KindFile {
+ return fileSeedPlacementRefusal(c)
+ }
+ return seedPlacementRefusal(c)
+}
+
+// refuseHASeed is refuseHAImport for either seed the import door begins:
+// a file seed's sentence is FS-16, an import's stays RHA-P1a-C2.
+func (s *Server) refuseHASeed(w http.ResponseWriter, rec *provision.Record, kind string) bool {
+ if kind != seeds.KindFile {
+ return s.refuseHAImport(w, rec)
+ }
+ if rec.HA || s.haRegion(rec.Region) {
+ jsonError(w, http.StatusConflict, fmt.Sprintf(fileSeedHACopy, s.offlineName(rec.Region)))
+ return true
+ }
+ return false
+}
+
+// seedStorageRefusal is the one answer to "can this console store this
+// seed's snapshot" (plan R2-2), asked by begin and by the upload alike so
+// the two never disagree. placement is the record's Region column. An
+// import and a region file seed need this console's data bucket and the
+// hibernation bucket its replicas live in; the refusal is the import's,
+// byte for byte (seedNoDataRefusal). Slice 3 adds the fleet file seed's
+// branch here, which needs the deployment bucket instead.
+func (s *Server) seedStorageRefusal(kind, placement string) *doorRefusal {
+ if s.cfg.SeedData == nil || s.cfg.HibernateBucket == "" {
+ return seedNoDataRefusal()
+ }
+ return nil
+}
+
+// seedFileReady is seedRegionReady with the file protocol: the published
+// floor's Min must be at least seeds.FileSeedProtocol (FS-25), and every
+// box in the region must report at least max(FileSeedProtocol, floor.Min).
+// There is no one-box rule: a region file seed is --from-shaped, placed by
+// whichever box wakes it, with no swap and no journal (plan R1-3).
+func (s *Server) seedFileReady(ctx context.Context, region string) *doorRefusal {
+ return s.seedRegionReadyForEdges(ctx, region, false, seeds.FileSeedProtocol, nil)
+}
+
+// seedUploadReady is the upload's readiness re-check, by the seed's kind:
+// an import keeps its one-box rule, a file seed asks seedFileReady.
+func (s *Server) seedUploadReady(ctx context.Context, rec *provision.Record) *doorRefusal {
+ if rec.Seed != nil && rec.Seed.Kind == seeds.KindFile {
+ return s.seedFileReady(ctx, rec.Region)
+ }
+ return s.seedRegionReady(ctx, rec.Region, true)
+}
+
+// seedTakesUpload reports a seed the import door's PUT is for: an import,
+// or a file seed.
+func seedTakesUpload(seed *provision.SeedSource) bool {
+ return seed.Import() || (seed != nil && seed.Kind == seeds.KindFile)
+}
+
+// seedSizeHashRefusal is the size and hash half of importShapeRefusal: the
+// whole of a file seed's shape.
+func seedSizeHashRefusal(imp seedImportReq) *doorRefusal {
+ switch {
+ case imp.Bytes <= 0:
+ return &doorRefusal{Status: http.StatusBadRequest, Msg: importSizeRule}
+ case imp.Bytes > seedMaxBytes:
+ return &doorRefusal{Status: http.StatusRequestEntityTooLarge, Msg: importSizeRule}
+ case !sha256Hex.MatchString(imp.SHA256):
+ return &doorRefusal{Status: http.StatusBadRequest, Msg: "sha256 must be 64 lowercase hex characters"}
+ }
+ return nil
+}
+
+// abortFileSeed moves file seed id to aborted with reason, but only while
+// it is still reserving (provision.SeedAbortFileUploadBecause): a seed
+// that has moved on, by its upload landing, the sweep, or a delete, is
+// never touched. The record CAS is the guard; the import door takes no
+// record lock. A write that lands bumps the serial, so the box rolls back
+// its part and the console's finish frees the hostname. A failure is
+// logged, never answered: the caller's answer does not change.
+func (s *Server) abortFileSeed(ctx context.Context, sqid, app, host, id, reason, why string) {
+ actx, cancel := context.WithTimeout(context.WithoutCancel(ctx), instanceStoreTimeout)
+ defer cancel()
+ _, err := provision.SetRecordSeed(actx, s.cfg.Releases, sqid, app, host, provision.SeedAbortFileUploadBecause(id, reason))
+ switch {
+ case errors.Is(err, provision.ErrSeedConflict), errors.Is(err, os.ErrNotExist):
+ log.Printf("console: seed file %s: seed %s moved on before its %s was recorded; not aborted: %v", host, id, why, err)
+ return
+ case err != nil:
+ log.Printf("console: seed file %s: abort seed %s after %s: %v", host, id, why, err)
+ return
+ }
+ s.bumpSerial(actx)
+}
diff --git a/internal/console/seedfile_copy.go b/internal/console/seedfile_copy.go
new file mode 100644
index 000000000..f9d310ff3
--- /dev/null
+++ b/internal/console/seedfile_copy.go
@@ -0,0 +1,31 @@
+package console
+
+// The console's copy for file seeds (#1139), verbatim from the copy table
+// of docs/superpowers/plans/2026-11-20-fleet-seeded-create.md. Every row
+// there is approved (Paul, 2026-11-20) except those marked pending here,
+// which this task added and the copy review has not seen yet. %s fill in
+// the order the table names.
+const (
+ // FS-15: a region record outside this console's region; %s is the
+ // console's region, then the host. In place of the import's SD-N118.
+ fileSeedRegionCopy = "a seeded instance runs in this console’s region, %s. To run %s elsewhere, create it here and then run carlos move."
+ // FS-16: in place of haImportSentence for a file seed; %s is the region.
+ fileSeedHACopy = "%s has high availability turned on. seeded instances are not available there yet"
+ // FS-17: in place of SD-N51 for a file seed; the door aborts the seed
+ // as it answers.
+ fileSeedMismatchCopy = "the upload does not match the file this create began with, so it was not kept."
+ // FS-20: %s is the app.
+ fileSeedPoolCopy = "%s places its instances in a pool, so it cannot take a seeded instance."
+ // FS-25: capital T, as its sibling SD-N3.
+ fileSeedFloorCopy = "This deployment’s seeds floor does not allow seed files yet. An operator publishes it again with carlos system seeds-floor publish."
+
+ // FS-41 (pending): an import object whose kind is neither absent nor
+ // "file". Only a hand-written API call reaches it; the CLI sends one or
+ // the other.
+ fileSeedKindCopy = "kind must be file, or left out for an import"
+ // FS-42 (pending): the begin's audit row; %s is the host, then the
+ // first 12 characters of the sha256, then %d the length.
+ fileSeedBeganAudit = "began seeding %s from a file (%s, %d bytes)"
+ // FS-43 (pending): the upload's audit row; %s is the host.
+ fileSeedUploadedAudit = "uploaded the seed file for %s"
+)
diff --git a/internal/console/seedfile_test.go b/internal/console/seedfile_test.go
new file mode 100644
index 000000000..60c5f273d
--- /dev/null
+++ b/internal/console/seedfile_test.go
@@ -0,0 +1,429 @@
+package console
+
+import (
+ "bytes"
+ "context"
+ "encoding/json"
+ "errors"
+ "fmt"
+ "net/http"
+ "os"
+ "strings"
+ "testing"
+ "time"
+
+ "github.com/carlosframework/platform/internal/provision"
+ "github.com/carlosframework/platform/internal/release"
+ "github.com/carlosframework/platform/internal/seeds"
+)
+
+// File seeds on a region (#1139 Task 5): the import door's begin and
+// upload, with "kind":"file" in the create body's import object.
+
+const fileHost = "push.shop.example.com"
+
+// newFileSeedFixture is the import fixture with the seeds floor and the
+// region's box at the file seed protocol.
+func newFileSeedFixture(t *testing.T) fromFixture {
+ t.Helper()
+ f := newImportFixture(t)
+ publishFileFloor(t, f.fx.rel)
+ seedReadyBox(t, f.fx, "kass-1", "", seeds.FileSeedProtocol, "v0.27.0", "v0.27.0", "nested", false)
+ return f
+}
+
+func publishFileFloor(t *testing.T, st release.Store) {
+ t.Helper()
+ if err := seeds.PublishFloor(context.Background(), st, seeds.Floor{Min: seeds.FileSeedProtocol, MinRelease: "v0.27.0"}); err != nil {
+ t.Fatal(err)
+ }
+}
+
+func fileSeedBody(host, sha string, n int64) string {
+ body, _ := json.Marshal(map[string]any{"host": host, "import": map[string]any{"kind": "file", "sha256": sha, "bytes": n}})
+ return string(body)
+}
+
+// beginFile begins a file seed of host for body, requires its 201 with a
+// reserving file record, and returns the record.
+func (f fromFixture) beginFile(t *testing.T, host string, body []byte) *provision.Record {
+ t.Helper()
+ code, out := f.create(t, fileSeedBody(host, sha256Of(body), int64(len(body))))
+ if code != http.StatusCreated {
+ t.Fatalf("begin = %d %v", code, out)
+ }
+ rec, err := f.record(t, host)
+ if err != nil || rec.Seed == nil {
+ t.Fatalf("record after begin = %+v, %v", rec, err)
+ }
+ return rec
+}
+
+func requireFileState(t *testing.T, rec *provision.Record, id, state, reason string) {
+ t.Helper()
+ if rec.Seed == nil || rec.Seed.ID != id || rec.Seed.Kind != seeds.KindFile || rec.Seed.State != state || rec.Seed.Reason != reason {
+ t.Fatalf("record %s seed = %+v; want file %s %s with reason %q", rec.Host, rec.Seed, id, state, reason)
+ }
+}
+
+func TestFileSeedBeginRegionWritesReservingRecord(t *testing.T) {
+ f := newFileSeedFixture(t)
+ body, sha := sqliteBytes(t)
+ code, out := f.create(t, fileSeedBody(fileHost, sha, int64(len(body))))
+ if code != http.StatusCreated {
+ t.Fatalf("begin = %d %v", code, out)
+ }
+ if _, ok := out["verify_token"]; ok {
+ t.Fatalf("a file seed's begin answered a verify token: %v", out)
+ }
+ rec, err := f.record(t, fileHost)
+ if err != nil {
+ t.Fatal(err)
+ }
+ s := rec.Seed
+ if s == nil || s.Kind != seeds.KindFile || s.State != seeds.StateReserving || !seeds.ValidID(s.ID) ||
+ s.SHA256 != sha || s.Bytes != int64(len(body)) || s.Replaces != "" || s.VerifyHash != "" ||
+ s.By != "alice@keymail.dev" || s.At.IsZero() || s.Reason != "" {
+ t.Fatalf("record seed = %+v", s)
+ }
+ seed, _ := out["seed"].(map[string]any)
+ if out["host"] != fileHost || seed == nil || seed["id"] != s.ID || seed["state"] != seeds.StateReserving || seed["kind"] != seeds.KindFile {
+ t.Fatalf("201 body = %v", out)
+ }
+ f.requireNothingUploaded(t)
+ f.requireClean(t)
+}
+
+func TestFileSeedUploadRegionPutsSnapshotAndPublishes(t *testing.T) {
+ f := newFileSeedFixture(t)
+ body, _ := sqliteBytes(t)
+ begun := f.beginFile(t, fileHost, body)
+ rec := f.uploaded(t, fileHost, body)
+ requireFileState(t, rec, begun.Seed.ID, seeds.StateReady, "")
+ got, _, err := f.data.Get(context.Background(), seeds.SnapshotKey(fileHost, begun.Seed.ID))
+ if err != nil || !bytes.Equal(got, body) {
+ t.Fatalf("snapshot = %d bytes, %v; want the upload", len(got), err)
+ }
+ if keys, _ := f.data.List(context.Background(), seeds.Prefix); len(keys) != 1 {
+ t.Fatalf("seeds/ = %v; want the one snapshot", keys)
+ }
+ f.requireClean(t)
+ // Ready is the end of the door's part: a second upload is refused.
+ if code, out := uploadImport(t, f, fileHost, body); code != http.StatusConflict ||
+ str(t, out, "error") != "push.shop.example.com is ready. It takes an upload only while it waits for one." {
+ t.Fatalf("second upload = %d %v", code, out)
+ }
+}
+
+// R1-3: a region file seed is --from-shaped, so the import's one-box rule
+// is not its rule, at begin or at the upload's re-check.
+func TestFileSeedRegionTwoBoxesBeginThroughUpload(t *testing.T) {
+ f := newFileSeedFixture(t)
+ seedReadyBox(t, f.fx, "kass-2", "", seeds.FileSeedProtocol, "v0.27.0", "v0.27.0", "nested", false)
+ body, _ := sqliteBytes(t)
+ begun := f.beginFile(t, fileHost, body)
+ requireFileState(t, f.uploaded(t, fileHost, body), begun.Seed.ID, seeds.StateReady, "")
+ // An import in the same region still refuses the second box.
+ code, out := beginImport(t, f, importHost, importSHA, 10)
+ if code != http.StatusConflict || str(t, out, "error") != "the home region has more than one box. An import needs a region with one box for now." {
+ t.Fatalf("import begin = %d %v", code, out)
+ }
+}
+
+// A length or sha256 mismatch aborts a file seed at once with FS-17 (Paul,
+// 2026-11-20); an import's keeps SD-N51 and stays waiting.
+func TestFileSeedUploadMismatchAborts(t *testing.T) {
+ for _, row := range []struct {
+ name string
+ mk func(*testing.T) fromFixture
+ }{
+ {"region", newFileSeedFixture},
+ } {
+ t.Run(row.name, func(t *testing.T) {
+ f := row.mk(t)
+ body, _ := sqliteBytes(t)
+ begun := f.beginFile(t, fileHost, body)
+ short := body[:len(body)-1]
+ if code, out := uploadImport(t, f, fileHost, short); code != http.StatusUnprocessableEntity || str(t, out, "error") != fileSeedMismatchCopy {
+ t.Fatalf("mismatched upload = %d %v, want 422 FS-17", code, out)
+ }
+ rec, err := f.record(t, fileHost)
+ if err != nil {
+ t.Fatal(err)
+ }
+ requireFileState(t, rec, begun.Seed.ID, seeds.StateAborted, fileSeedMismatchCopy)
+ f.requireNothingUploaded(t)
+ f.requireClean(t)
+ // The right file now is refused: the seed has gone.
+ if code, out := uploadImport(t, f, fileHost, body); code != http.StatusConflict ||
+ str(t, out, "error") != "push.shop.example.com is aborted. It takes an upload only while it waits for one." {
+ t.Fatalf("upload after the abort = %d %v", code, out)
+ }
+ })
+ }
+ t.Run("import keeps waiting", func(t *testing.T) {
+ f := newImportFixture(t)
+ body, _ := sqliteBytes(t)
+ begun := f.begun(t, importHost, body)
+ if code, out := uploadImport(t, f, importHost, body[:len(body)-1]); code != http.StatusUnprocessableEntity || str(t, out, "error") != importMismatch {
+ t.Fatalf("import mismatch = %d %v", code, out)
+ }
+ rec, _ := f.record(t, importHost)
+ requireImportState(t, rec, begun.Seed.ID, seeds.StateAwaitingUpload, "")
+ })
+}
+
+func TestFileSeedUploadBadDatabaseAborts(t *testing.T) {
+ f := newFileSeedFixture(t)
+ junk := bytes.Repeat([]byte("j"), 100)
+ begun := f.beginFile(t, fileHost, junk)
+ requireFileState(t, f.uploaded(t, fileHost, junk), begun.Seed.ID, seeds.StateAborted, importNotADB)
+ f.requireNothingUploaded(t)
+ f.requireClean(t)
+}
+
+func TestFileSeedRefusesPool(t *testing.T) {
+ f := newFileSeedFixture(t)
+ m := fromManifest(false)
+ m.Pool = "shared"
+ enableInstances(t, f.fx, fromApp, m)
+ code, out := f.create(t, fileSeedBody(fileHost, importSHA, 10))
+ if code != http.StatusConflict || str(t, out, "error") != "shop places its instances in a pool, so it cannot take a seeded instance." {
+ t.Fatalf("= %d %v", code, out)
+ }
+ f.requireNoRecord(t, fileHost)
+}
+
+// fleetSeedCreate posts body for shop on a fleet-placed world and requires
+// the --from and import placement refusal, with nothing written.
+func fleetSeedCreate(t *testing.T, body string) {
+ t.Helper()
+ fx, token, reg := d1World(t, "code-fs-fleet", "pi-1")
+ putFleetRecord(t, fx, "shop", "a.example.com", nil)
+ code, _, raw := rawReq(t, http.MethodPost, instancesURL(fx, fx.sqid, "shop"), token, body)
+ if code != http.StatusConflict || errorOf(t, raw) != "shop places its instances in a pool or on a fleet, so it cannot take a seeded instance." {
+ t.Fatalf("seeded create = %d %s; want 409 with the seed placement refusal", code, raw)
+ }
+ noShopRecord(t, fx, "b.example.com")
+ if boxRow(t, reg, "pi-1").LabelledAt != 0 {
+ t.Fatal("a seeded create marked a box")
+ }
+}
+
+func TestFileSeedRefusesFleetUntilSlice3(t *testing.T) {
+ fleetSeedCreate(t, fileSeedBody("b.example.com", importSHA, 10))
+}
+
+func TestFromOnFleetStillRefuses(t *testing.T) {
+ fleetSeedCreate(t, `{"host":"b.example.com","from":{"host":"a.example.com"}}`)
+}
+
+func TestFileSeedRefusesAnotherRegion(t *testing.T) {
+ f := newFileSeedFixture(t)
+ seedReadyBox(t, f.fx, "far-1", "us", seeds.FileSeedProtocol, "v0.27.0", "v0.27.0", "nested", false)
+ code, out := f.create(t, `{"host":"push.shop.example.com","region":"us","import":{"kind":"file","sha256":"`+importSHA+`","bytes":10}}`)
+ if code != http.StatusConflict || str(t, out, "error") != "a seeded instance runs in this console’s region, the home region. To run push.shop.example.com elsewhere, create it here and then run carlos move." {
+ t.Fatalf("= %d %v", code, out)
+ }
+ f.requireNoRecord(t, fileHost)
+}
+
+func TestFileSeedRefusesHARegion(t *testing.T) {
+ f := newFileSeedFixture(t)
+ f.fx.srv.cfg.HomeRegion = "ie"
+ f.fx.srv.cfg.HARegions = []string{"ie"}
+ code, out := f.create(t, fileSeedBody(fileHost, importSHA, 10))
+ if code != http.StatusConflict || str(t, out, "error") != "ie has high availability turned on. seeded instances are not available there yet" {
+ t.Fatalf("= %d %v", code, out)
+ }
+ f.requireNoRecord(t, fileHost)
+}
+
+func TestFileSeedBeginShapeAndKind(t *testing.T) {
+ f := newFileSeedFixture(t)
+ for _, c := range []struct {
+ body string
+ code int
+ want string
+ }{
+ {fileSeedBody(fileHost, importSHA, 0), http.StatusBadRequest, importSizeRule},
+ {fileSeedBody(fileHost, importSHA, 4294967297), http.StatusRequestEntityTooLarge, importSizeRule},
+ {fileSeedBody(fileHost, "ABC", 10), http.StatusBadRequest, "sha256 must be 64 lowercase hex characters"},
+ {`{"host":"push.shop.example.com","import":{"kind":"zip","sha256":"` + importSHA + `","bytes":10,"replaces":"127.0.0.1:1"}}`, http.StatusBadRequest, fileSeedKindCopy},
+ } {
+ if code, out := f.create(t, c.body); code != c.code || str(t, out, "error") != c.want {
+ t.Errorf("%s = %d %v, want %d %q", c.body, code, out, c.code, c.want)
+ }
+ f.requireNoRecord(t, fileHost)
+ }
+}
+
+// R2-2's one storage prerequisite: begin and upload ask the same question
+// and give the import's refusal.
+func TestFileSeedNeedsADataBucket(t *testing.T) {
+ const noData = "this console has no data bucket set up, so it cannot create a seeded instance."
+ f := newFileSeedFixture(t)
+ body, _ := sqliteBytes(t)
+ f.beginFile(t, fileHost, body)
+ data := f.fx.srv.cfg.SeedData
+ f.fx.srv.cfg.SeedData = nil
+ if code, out := uploadImport(t, f, fileHost, body); code != http.StatusServiceUnavailable || str(t, out, "error") != noData {
+ t.Fatalf("upload = %d %v", code, out)
+ }
+ code, out := f.create(t, fileSeedBody("other.shop.example.com", importSHA, 10))
+ if code != http.StatusServiceUnavailable || str(t, out, "error") != noData {
+ t.Fatalf("begin = %d %v", code, out)
+ }
+ f.requireNoRecord(t, "other.shop.example.com")
+ f.fx.srv.cfg.SeedData = data
+ f.fx.srv.cfg.HibernateBucket = ""
+ if code, out := f.create(t, fileSeedBody("other.shop.example.com", importSHA, 10)); code != http.StatusServiceUnavailable || str(t, out, "error") != noData {
+ t.Fatalf("begin without a bucket = %d %v", code, out)
+ }
+}
+
+func TestFileSeedReadyRefusesFloorBelowFileProtocol(t *testing.T) {
+ fx := newConsoleFixture(t)
+ ctx := context.Background()
+ publishSeedsFloorFx(t, fx, "v0.27.0")
+ seedReadyBox(t, fx, "kass-1", "", seeds.FileSeedProtocol, "v0.27.0", "v0.27.0", "nested", false)
+ ref := fx.srv.seedFileReady(ctx, "")
+ if ref == nil || ref.Status != http.StatusConflict || ref.Msg != "This deployment’s seeds floor does not allow seed files yet. An operator publishes it again with carlos system seeds-floor publish." {
+ t.Fatalf("a floor at protocol %d: %+v", seeds.RequiredProtocol, ref)
+ }
+ publishFileFloor(t, fx.rel)
+ if ref := fx.srv.seedFileReady(ctx, ""); ref != nil {
+ t.Fatalf("a floor at the file protocol: %+v", ref)
+ }
+}
+
+func TestFileSeedReadyNamesBoxBelowFileProtocol(t *testing.T) {
+ fx := newConsoleFixture(t)
+ publishFileFloor(t, fx.rel)
+ seedReadyBox(t, fx, "kass-1", "", seeds.FileSeedProtocol, "v0.27.0", "v0.27.0", "nested", false)
+ seedReadyBox(t, fx, "kass-2", "", seeds.FileSeedProtocol-1, "v0.27.0", "v0.27.0", "nested", false)
+ ref := fx.srv.seedFileReady(context.Background(), "")
+ if ref == nil || ref.Status != http.StatusConflict ||
+ ref.Msg != "kass-2 in the home region are below the seeds floor. Roll the platform there, then publish the seeds floor again." {
+ t.Fatalf("a box below the file protocol: %+v", ref)
+ }
+}
+
+// The doors that were there before keep protocol 1.
+func TestSeedRegionReadyUnchangedForImport(t *testing.T) {
+ fx := newConsoleFixture(t)
+ ctx := context.Background()
+ publishSeedsFloorFx(t, fx, "v0.27.0")
+ seedReadyBox(t, fx, "kass-1", "", seeds.RequiredProtocol, "v0.27.0", "v0.27.0", "nested", false)
+ if ref := fx.srv.seedRegionReady(ctx, "", true); ref != nil {
+ t.Fatalf("an import at protocol %d: %+v", seeds.RequiredProtocol, ref)
+ }
+ if ref := fx.srv.seedRegionReady(ctx, "", false); ref != nil {
+ t.Fatalf("a --from at protocol %d: %+v", seeds.RequiredProtocol, ref)
+ }
+ if ref := fx.srv.seedFileReady(ctx, ""); ref == nil {
+ t.Fatal("a file seed admitted below its protocol")
+ }
+}
+
+// Stopped, commit and abort are an import's: a file seed gets SD-N59 there
+// and its record is unchanged.
+func TestImportGateRefusesFileOutsideUpload(t *testing.T) {
+ f := newFileSeedFixture(t)
+ body, _ := sqliteBytes(t)
+ begun := f.beginFile(t, fileHost, body)
+ for _, verb := range []string{"stopped", "commit", "abort"} {
+ if code, out := postImport(t, f, fileHost, verb); code != http.StatusConflict || str(t, out, "error") != "push.shop.example.com is not an import." {
+ t.Errorf("%s = %d %v, want 409 SD-N59", verb, code, out)
+ }
+ }
+ rec, _ := f.record(t, fileHost)
+ requireFileState(t, rec, begun.Seed.ID, seeds.StateReserving, "")
+}
+
+func TestOldConsoleShapeRefusesFileBegin(t *testing.T) {
+ ref := importShapeRefusal(seedImportReq{Kind: seeds.KindFile, SHA256: importSHA, Bytes: 10})
+ if ref == nil || ref.Status != http.StatusBadRequest || ref.Msg != "replaces must name the address the import takes over, as host:port" {
+ t.Fatalf("an old console's shape check of a file begin = %+v", ref)
+ }
+}
+
+func TestSeedsPassAbortsStuckFileReservation(t *testing.T) {
+ f := newSweepFixture(t)
+ now := time.Now()
+ live := f.seeded(t, "live.shop.example.com", seeds.KindFile, seeds.StateReserving, now.Add(-10*time.Minute))
+ stuck := f.seeded(t, "stuck.shop.example.com", seeds.KindFile, seeds.StateReserving, now.Add(-2*time.Hour))
+ ready := f.seeded(t, "ready.shop.example.com", seeds.KindFile, seeds.StateReady, now.Add(-2*time.Hour))
+ liveKey := f.snapshot(t, "live.shop.example.com", live, 10*time.Minute)
+ stuckKey := f.snapshot(t, "stuck.shop.example.com", stuck, 90*time.Minute)
+ readyKey := f.snapshot(t, "ready.shop.example.com", ready, 90*time.Minute)
+ f.pass(now)
+ if got := f.state(t, "live.shop.example.com"); got != seeds.StateReserving || !f.snapshotExists(t, liveKey) {
+ t.Fatalf("a live file reservation = %s", got)
+ }
+ if got := f.state(t, "stuck.shop.example.com"); got != seeds.StateAborted || f.snapshotExists(t, stuckKey) {
+ t.Fatalf("a stuck file reservation = %s, snapshot kept %v", got, f.snapshotExists(t, stuckKey))
+ }
+ if got := f.state(t, "ready.shop.example.com"); got != seeds.StateReady || !f.snapshotExists(t, readyKey) {
+ t.Fatalf("a ready file seed = %s", got)
+ }
+}
+
+func TestFinishFileSeedDeletesRegionReplica(t *testing.T) {
+ f := finishFixture(t)
+ id := newSeedID(t)
+ f.seedRecord(t, fromHost, "canary", id, seeds.KindFile, seeds.StateRolledBack)
+ ctx := context.Background()
+ if _, err := f.data.Put(ctx, seeds.SnapshotKey(fromHost, id), []byte("snapshot"), ""); err != nil {
+ t.Fatal(err)
+ }
+ f.putReplicaKeys(t, fromHost, 3)
+ if err := f.fx.srv.finishSeed(ctx, "bab", fromApp, fromHost, id); err != nil {
+ t.Fatal(err)
+ }
+ if _, _, err := f.data.Get(ctx, seeds.SnapshotKey(fromHost, id)); !errors.Is(err, os.ErrNotExist) {
+ t.Fatalf("snapshot after the finish: %v; want it gone", err)
+ }
+ if keys := replicaKeys(t, f, fromHost); len(keys) != 0 {
+ t.Fatalf("replica after the finish: %v", keys)
+ }
+ f.requireRecordGone(t, fromHost)
+}
+
+// The audit rows a file seed leaves: one at begin, one at the upload.
+func TestFileSeedAuditRows(t *testing.T) {
+ f := newFileSeedFixture(t)
+ body, sha := sqliteBytes(t)
+ f.beginFile(t, fileHost, body)
+ f.uploaded(t, fileHost, body)
+ events, err := f.fx.st.Events(OpsAccountID, fromApp, 50)
+ if err != nil {
+ t.Fatal(err)
+ }
+ var rows []string
+ for _, e := range events {
+ if strings.HasPrefix(e.Action, "instance-seed") || e.Action == "seed-file-uploaded" {
+ rows = append(rows, e.Action+" | "+e.Detail)
+ }
+ }
+ want := []string{
+ fmt.Sprintf("instance-seed | began seeding %s from a file (%s, %d bytes)", fileHost, sha[:12], len(body)),
+ "seed-file-uploaded | uploaded the seed file for " + fileHost,
+ }
+ if len(rows) != 2 || !containsAll(rows, want) {
+ t.Fatalf("audit rows = %q, want %q", rows, want)
+ }
+}
+
+func containsAll(have, want []string) bool {
+ for _, w := range want {
+ found := false
+ for _, h := range have {
+ found = found || h == w
+ }
+ if !found {
+ return false
+ }
+ }
+ return true
+}
diff --git a/internal/console/seedfinish.go b/internal/console/seedfinish.go
index 7daf34f2f..24378a9d4 100644
--- a/internal/console/seedfinish.go
+++ b/internal/console/seedfinish.go
@@ -121,7 +121,9 @@ func (s *Server) finishSeedOnce(ctx context.Context, sqid, app, host, seedID str
if err := s.cfg.SeedData.Delete(ctx, seeds.SnapshotKey(host, seedID)); err != nil && !errors.Is(err, os.ErrNotExist) {
return fmt.Errorf("delete the snapshot of seed %s of %s: %w", seedID, host, err)
}
- if rec.Seed.Kind == seeds.KindReplica || rec.Seed.DemoClaim() {
+ // A file seed places as a --from seed does, so its rollback may leave a
+ // replica too.
+ if rec.Seed.Kind == seeds.KindReplica || rec.Seed.Kind == seeds.KindFile || rec.Seed.DemoClaim() {
var gone bool
if etag, gone, err = s.deleteSeedReplica(ctx, rec, etag); err != nil {
return err
diff --git a/internal/console/seedfloor.go b/internal/console/seedfloor.go
index a43197322..75ffab549 100644
--- a/internal/console/seedfloor.go
+++ b/internal/console/seedfloor.go
@@ -33,12 +33,17 @@ import (
// box whose own local floor is unreadable publishes "" for its floor, and
// must never be read as ready.
func (s *Server) seedRegionReady(ctx context.Context, region string, oneBox bool) *doorRefusal {
- return s.seedRegionReadyForEdges(ctx, region, oneBox, nil)
+ return s.seedRegionReadyForEdges(ctx, region, oneBox, 0, nil)
}
// Demo claims only use shared-pool edges. Other seed operations pass nil and
// retain the region-wide checks, including layout and host-claim readiness.
-func (s *Server) seedRegionReadyForEdges(ctx context.Context, region string, oneBox bool, include func(edgesFilePlacementView) bool) *doorRefusal {
+//
+// protocol is the seeds protocol the door needs above the doors that came
+// first (0 for those, which keep seeds.RequiredProtocol): the published
+// floor's Min must reach it, else the floor predates the door (FS-25, the
+// file door's, seedFileReady), and every box must report at least it.
+func (s *Server) seedRegionReadyForEdges(ctx context.Context, region string, oneBox bool, protocol int, include func(edgesFilePlacementView) bool) *doorRefusal {
region = s.homeRegionIn(region)
if s.cfg.HostClaim {
return seedClaimConsoleRefusal()
@@ -59,7 +64,10 @@ func (s *Server) seedRegionReadyForEdges(ctx context.Context, region string, one
if floor == nil {
return &doorRefusal{Status: http.StatusConflict, Msg: "This deployment has no seeds floor yet. An operator publishes it with carlos system seeds-floor publish."}
}
- minProtocol := max(seeds.RequiredProtocol, floor.Min)
+ if floor.Min < protocol {
+ return &doorRefusal{Status: http.StatusConflict, Msg: fileSeedFloorCopy}
+ }
+ minProtocol := max(seeds.RequiredProtocol, floor.Min, protocol)
name := s.homeRegionOut(region)
if name == "" {
name = "the home region"
diff --git a/internal/console/seedsweep.go b/internal/console/seedsweep.go
index da91b89c4..6646d46aa 100644
--- a/internal/console/seedsweep.go
+++ b/internal/console/seedsweep.go
@@ -86,7 +86,8 @@ func (s *Server) seedsIteration(ctx context.Context) {
})
}
-// seedStale reports a seed stuck where no box moves it: a --from seed
+// seedStale reports a seed stuck where no box moves it: a --from seed, or a
+// file seed waiting for its upload (fleet seeded create design §3.3),
// reserving for over seedReserveTTL, or an import waiting for its upload or
// its stop for over seedImportTTL. Both times are a console's: At is
// stamped by the console whose door reserved or began the seed, now is the
@@ -101,7 +102,7 @@ func seedStale(seed *provision.SeedSource, now time.Time) bool {
return false
case seed == nil:
return false
- case seed.Kind == seeds.KindReplica && seed.State == seeds.StateReserving:
+ case (seed.Kind == seeds.KindReplica || seed.Kind == seeds.KindFile) && seed.State == seeds.StateReserving:
return now.Sub(seed.At) > seedReserveTTL
case seed.Import() && (seed.State == seeds.StateAwaitingUpload || seed.State == seeds.StateUploaded):
return now.Sub(seed.At) > seedImportTTL
diff --git a/internal/provision/fleet_seeded_create_1_census_test.go b/internal/provision/fleet_seeded_create_1_census_test.go
new file mode 100644
index 000000000..aae8b1cd6
--- /dev/null
+++ b/internal/provision/fleet_seeded_create_1_census_test.go
@@ -0,0 +1,71 @@
+package provision
+
+// fleetSeededCreate1WriteCensusInventory is the record-write census for
+// slice 1 of seeded instances on a customer fleet (#1139, branch
+// fleet-seeded-create-1: file seeds on a region), layered on
+// platformAccounts1WriteCensusInventory (main's newest at branch time).
+// Reviewed by the branch author against the source. No class or site kind
+// changes; one unit is new.
+//
+// New:
+// - Server.abortFileSeed (internal/console/seedfile.go): moves a file
+// seed to aborted with a reason through the record CAS
+// (provision.SetRecordSeed with SeedAbortFileUploadBecause), which acts
+// only while that seed id is still reserving; then bumps the serial.
+// It is the file seed begin's abort after a write (a failed record
+// write, store provisioning, a sibling's apex) and the upload's
+// length/sha256 mismatch abort in spoolImport (Paul, 2026-11-20).
+// record-writer / key:SetRecordSeed, as runImportUpload's own abort.
+// beginFileSeed itself writes through createSeedRecord, and spoolImport
+// through abortFileSeed, so neither has a site of its own.
+//
+// Re-pinned:
+// - Server.runImportUpload (console): dispatches on the seed's kind. A
+// file seed aborts with SeedAbortFileUploadBecause and lands with
+// SeedPublishFile (reserving to ready), then bumps the serial; an
+// import keeps SeedAbortUploadBecause and SeedUploaded. The same
+// SetRecordSeed writes, the same put to the data bucket at
+// seeds.SnapshotKey.
+// - Server.handleAPIImportStopped, Server.handleAPIImportCommit,
+// Server.handleAPIImportAbort (console): importGate takes upload=false,
+// so a file seed is refused there (SD-N59) as before; their writes are
+// unchanged.
+// - Server.finishSeedOnce (console): a file seed's finish deletes the
+// region replica as a --from seed's does (KindFile beside
+// KindReplica); deleteSeedReplica's own rail is unchanged. A read of
+// the record key, as before.
+// - Reconcile (provision): Task 4's abortRetiresRow(rec) in place of the
+// inline replica check, so an aborted file seed's row is retired
+// before its rollback, as --from's. The key site is unchanged.
+// - finishAbortedSeed (provision): Task 4, a file seed's purge of its
+// marked local snapshot runs as --from's; the same SetRecordSeed to
+// rolled-back.
+func fleetSeededCreate1WriteCensusInventory() []censusEntry {
+ entries := append([]censusEntry(nil), platformAccounts1WriteCensusInventory()...)
+ repins := []censusEntry{
+ {"internal/console/apiinstanceimport.go", "Server.handleAPIImportAbort", "record-writer", "key:SetRecordSeed", "149b2356c0e65cd2c348873d9892b07b48e8dace9eecc6d8e43ebc862da6e5a9"},
+ {"internal/console/apiinstanceimport.go", "Server.handleAPIImportCommit", "record-writer", "key:SetRecordSeed", "7d2c05814ee90e4981a09edd80378f852355d1ee3b247f2e192c51d694208131"},
+ {"internal/console/apiinstanceimport.go", "Server.handleAPIImportStopped", "record-writer", "key:SetRecordSeed", "31e821dd3111fdba5dc09c33338deb7944ab44f06d8ba4cd5a3ed11430397fc0"},
+ {"internal/console/apiinstanceimport.go", "Server.runImportUpload", "record-writer", "key:SetRecordSeed", "c84fc2edd41a2b5265ee990b4f0f9fdbe8cbb8de6e392957770c7ab341e94b27"},
+ {"internal/console/seedfinish.go", "Server.finishSeedOnce", "key-site", "key:RecordKey", "597f1f6dbbd8a8d72a6e34d29671e03252eab4e81fb9cf1e9f1ced62fb338920"},
+ {"internal/provision/reconcile.go", "Reconcile", "key-site", "key:RecordKey", "684e5d0a0c9bd33c9b99c8b1bf7f10180df09344ee6884ebb67313affe25dace"},
+ {"internal/provision/seedreconcile.go", "finishAbortedSeed", "record-writer", "key:SetRecordSeed", "0fc8fcbd23d702ad1374f2343707fbfbbae0760a1dfe674e4c83ddcdae1b07bf"},
+ }
+ for _, r := range repins {
+ found := false
+ for i, e := range entries {
+ if e.File == r.File && e.Unit == r.Unit {
+ if e.Class != r.Class || e.Kinds != r.Kinds {
+ panic("fleet-seeded-create-1 census: classification changed for " + r.File + ":" + r.Unit)
+ }
+ entries[i], found = r, true
+ }
+ }
+ if !found {
+ panic("fleet-seeded-create-1 census: re-pin of an unlisted unit " + r.File + ":" + r.Unit)
+ }
+ }
+ return append(entries,
+ censusEntry{"internal/console/seedfile.go", "Server.abortFileSeed", "record-writer", "key:SetRecordSeed", "9098c1c4ca105896f2ac3275d7ab0044527b95be69ca15de41179a3b340c542e"},
+ )
+}
diff --git a/internal/provision/plan9_b8_census_test.go b/internal/provision/plan9_b8_census_test.go
index dd40caf67..ee18e9ba4 100644
--- a/internal/provision/plan9_b8_census_test.go
+++ b/internal/provision/plan9_b8_census_test.go
@@ -366,7 +366,7 @@ func TestPlan9B8RecordWriteCensus(t *testing.T) {
if len(got) < 100 {
t.Fatalf("census found only %d units under %s; the walk is broken", len(got), root)
}
- inventory := platformAccounts1WriteCensusInventory()
+ inventory := fleetSeededCreate1WriteCensusInventory()
problems := append(censusDiff(inventory, got), censusPolicy(inventory)...)
if len(problems) > 0 {
t.Fatalf("record-write census rejected %d site(s); update the explicit inventory only after reviewing the source:\n %s", len(problems), strings.Join(problems, "\n "))