carlos / platform Public

region labels: carlos db names the label, and both regions of a move when the console sends them (plan 2 task 7)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev f013393434fe065203f2267ffe25760262118e3d parent c847300
7 files changed, +198 −89
  • approved_db_forward_copy_test.go +3 −3
  • db.go +1 −1
  • dbforward.go +81 −41
  • dbforward_e2e_test.go +28 −8
  • dbforward_test.go +24 −24
  • docs/superpowers/plans/2026-10-22-db-region-forward-copy.md +20 −12
  • region_labels_test.go +41 −0

CI failed — run details

diff --git a/approved_db_forward_copy_test.go b/approved_db_forward_copy_test.go
index 9eebffc01..cd3b6070d 100644
--- a/approved_db_forward_copy_test.go
+++ b/approved_db_forward_copy_test.go
@@ -26,7 +26,7 @@ var dbForwardCopyIDPattern = regexp.MustCompile(`^DBF-[0-9]+$`)
// dbForwardCopyIDs is the record's inventory, pinned: DBF-1 to DBF-20,
// DBF-23 and DBF-24 (plan 3's pull rows among them), then DBF-21, DBF-22,
-// DBF-30, DBF-31 and DBF-32.
+// DBF-30, DBF-31, DBF-32 and DBF-33 (region labels RC-32).
var dbForwardCopyIDs = func() []string {
ids := make([]string, 0, 27)
for i := 1; i <= 24; i++ {
@@ -35,7 +35,7 @@ var dbForwardCopyIDs = func() []string {
}
ids = append(ids, "DBF-"+strconv.Itoa(i))
}
- return append(ids, "DBF-21", "DBF-22", "DBF-30", "DBF-31", "DBF-32")
+ return append(ids, "DBF-21", "DBF-22", "DBF-30", "DBF-31", "DBF-32", "DBF-33")
}()
// dbForwardCopyBuilt is every id whose text the code or docs carry. The task
@@ -43,7 +43,7 @@ var dbForwardCopyIDs = func() []string {
// approved the row.
var dbForwardCopyBuilt = []string{
"DBF-1", "DBF-2", "DBF-14", "DBF-9", "DBF-10", "DBF-21", "DBF-22", // the console
- "DBF-3", "DBF-4", "DBF-5", "DBF-6", "DBF-7", "DBF-8", "DBF-11", "DBF-12", "DBF-13", "DBF-15", "DBF-16", "DBF-32", // the CLI
+ "DBF-3", "DBF-4", "DBF-5", "DBF-6", "DBF-7", "DBF-8", "DBF-11", "DBF-12", "DBF-13", "DBF-15", "DBF-16", "DBF-32", "DBF-33", // the CLI
"DBF-19", "DBF-20", // the console's pull audit details (plan 3)
"DBF-17", "DBF-18", "DBF-24", // the CLI's pull sentences (plan 3)
"DBF-23", "DBF-31", // docs/site/cli.md (DBF-23 replaced DBF-30 there)
diff --git a/db.go b/db.go
index bf697ae3d..d5bf60b21 100644
--- a/db.go
+++ b/db.go
@@ -288,7 +288,7 @@ func dbPull(ctx context.Context, t dbTarget, out string) error {
// forward spec §6), when the console forwards pulls there.
if !slices.Contains(fwd.door.Forward.Ops, dbreads.OpPull) {
// A console that forwards queries and not pulls (plan 2's): DBF-8.
- return fmt.Errorf(dbfNoPull, t.host, fwd.door.Forward.Region)
+ return fmt.Errorf(dbfNoPull, t.host, fwdPlace(*fwd.door.Forward))
}
r, err = dbPullForward(ctx, t, *fwd.door.Forward)
}
diff --git a/dbforward.go b/dbforward.go
index 5bf8af68a..fad144d2a 100644
--- a/dbforward.go
+++ b/dbforward.go
@@ -39,28 +39,62 @@ import (
// The forwarded read's CLI sentences (copy record DBF-3 to DBF-8, DBF-11 to
// DBF-13, DBF-15, DBF-16, DBF-32), approved by Luna on 2026-10-23.
const (
- dbfNotPicked = "no server in region %s started the read within 60 seconds. try again in a few minutes." // DBF-3
- dbfTooLarge = "the database for %s is %s once restored. carlos db can query at most %s in region %s." // DBF-4
- dbfNoRoom = "the server in region %s does not have room to restore %s's database right now. try again later." // DBF-5
- dbfOutputCap = "the result was cut off at 64 MB. narrow the query with WHERE or LIMIT and run it again." // DBF-6
- dbfTimeout = "the query ran for 5 minutes and was stopped. narrow it and run it again." // DBF-7
- dbfNoPull = "%s keeps its data in region %s. carlos db pull cannot fetch a copy from there yet. carlos db query can read it." // DBF-8
- dbfReading = "reading a copy of %s's database in region %s." // DBF-11
- dbfUnfinished = "the read of %s's database in region %s did not finish, so nothing was printed. try again." // DBF-12
- dbfUnchecked = "the answer from region %s was invalid, so carlos db printed nothing. try again." // DBF-13
- dbfChanged = "%s changed while the read was waiting. try again." // DBF-15
- dbfMovingCLI = "%s is moving between regions. read its database once the move has finished." // DBF-16
- dbfNotUTF8 = "this query cannot be sent to region %s, because it contains invalid UTF-8 or the replacement character U+FFFD. fix the query and run it again." // DBF-32
+ dbfNotPicked = "no server in %s started the read within 60 seconds. try again in a few minutes." // DBF-3
+ dbfTooLarge = "the database for %s is %s once restored. carlos db can query at most %s in %s." // DBF-4
+ dbfNoRoom = "the server in %s does not have room to restore %s's database right now. try again later." // DBF-5
+ dbfOutputCap = "the result was cut off at 64 MB. narrow the query with WHERE or LIMIT and run it again." // DBF-6
+ dbfTimeout = "the query ran for 5 minutes and was stopped. narrow it and run it again." // DBF-7
+ dbfNoPull = "%s keeps its data in %s. carlos db pull cannot fetch a copy from there yet. carlos db query can read it." // DBF-8
+ dbfReading = "reading a copy of %s's database in %s." // DBF-11
+ dbfUnfinished = "the read of %s's database in %s did not finish, so nothing was printed. try again." // DBF-12
+ dbfUnchecked = "the answer from %s was invalid, so carlos db printed nothing. try again." // DBF-13
+ dbfChanged = "%s changed while the read was waiting. try again." // DBF-15
+ dbfMovingCLI = "%s is moving between regions. read its database once the move has finished." // DBF-16
+ dbfNotUTF8 = "this query cannot be sent to %s, because it contains invalid UTF-8 or the replacement character U+FFFD. fix the query and run it again." // DBF-32
+ // dbfMovingBetween is DBF-16 when the console's refusal named both
+ // regions (region labels RC-32).
+ dbfMovingBetween = "%s is moving from %s to %s. read its database once the move has finished." // DBF-33
)
// The forwarded pull's CLI sentences (copy record DBF-17, DBF-18, DBF-24),
// approved by Luna on 2026-10-23.
const (
- dbfPullTooLarge = "the database for %s has %s of files to fetch. carlos db pull can fetch at most %s from region %s." // DBF-17
- dbfFetching = "fetching a copy of %s's database from region %s." // DBF-18
- dbfPullNoRoom = "the server in region %s does not have room to prepare a copy of %s's database right now. try again later." // DBF-24
+ dbfPullTooLarge = "the database for %s has %s of files to fetch. carlos db pull can fetch at most %s from %s." // DBF-17
+ dbfFetching = "fetching a copy of %s's database from %s." // DBF-18
+ dbfPullNoRoom = "the server in %s does not have room to prepare a copy of %s's database right now. try again later." // DBF-24
)
+// fwdPlace is where a forwarded read's data is, as its sentences name it
+// (region labels §5 row 27): the console's label, else "region <code>", the
+// words every sentence carried before, so an older console's lines are
+// byte-identical. A label that is only the code (a labels console that has
+// not read its name map yet, spec §3.2) is no place either: "in region uk"
+// still reads as it always did, never "in uk".
+func fwdPlace(f dbdoor.Forward) string {
+ if p := cleanPlace(f.RegionName); p != "" && p != f.Region {
+ return p
+ }
+ return "region " + f.Region
+}
+
+// dbMovingLine is RC-32: the console's moving refusal (DBF-10) named both
+// of the move's regions, so the CLI says them. Anything less, or anything
+// not fit to print, is false and the console's own sentence is printed.
+func dbMovingLine(host string, body []byte) (string, bool) {
+ var b struct {
+ FromName string `json:"from_name"`
+ ToName string `json:"to_name"`
+ }
+ if json.Unmarshal(body, &b) != nil {
+ return "", false
+ }
+ from, to := cleanPlace(b.FromName), cleanPlace(b.ToName)
+ if from == "" || to == "" {
+ return "", false
+ }
+ return fmt.Sprintf(dbfMovingBetween, host, from, to), true
+}
+
// errDBForward is the db door's forward marker, handed back by dbRestore so
// a verb can switch to the forwarded read.
type errDBForward struct {
@@ -82,7 +116,7 @@ func dbQueryForward(ctx context.Context, t dbTarget, sqlText string, fwd dbdoor.
// same reason (plan review finding 36). First, so no other check can
// read the bytes differently.
if !utf8.ValidString(sqlText) || strings.ContainsRune(sqlText, utf8.RuneError) {
- return fmt.Errorf(dbfNotUTF8, fwd.Region)
+ return fmt.Errorf(dbfNotUTF8, fwdPlace(fwd))
}
if err := checkQuerySQL(sqlText); err != nil {
return err
@@ -107,19 +141,22 @@ func dbQueryForward(ctx context.Context, t dbTarget, sqlText string, fwd dbdoor.
if errors.Is(ctx.Err(), context.Canceled) {
return errors.New("stopped")
}
- return fmt.Errorf(dbfUnfinished, t.host, fwd.Region)
+ return fmt.Errorf(dbfUnfinished, t.host, fwdPlace(fwd))
}
defer res.Body.Close()
if res.StatusCode != http.StatusOK {
raw, _ := io.ReadAll(io.LimitReader(res.Body, 64<<10))
+ if line, ok := dbMovingLine(t.host, raw); ok && res.StatusCode == http.StatusConflict {
+ return errors.New(line)
+ }
return apiErrorFromBody(res.StatusCode, raw)
}
sink := &memSink{}
- id, result, err := readDBForward(ctx, res.Body, key, t.host, fwd.Region, dbfReading, os.Stderr, sink, newDBFChunkBound(dbreads.MaxOutputBytes, dbreads.ChunkBytes))
+ id, result, err := readDBForward(ctx, res.Body, key, t.host, fwdPlace(fwd), dbfReading, os.Stderr, sink, newDBFChunkBound(dbreads.MaxOutputBytes, dbreads.ChunkBytes))
if err != nil {
return err
}
- ans, err := openDBForward(id, key, sink, *result, t.host, fwd.Region)
+ ans, err := openDBForward(id, key, sink, *result, t.host, fwdPlace(fwd))
if err != nil {
return err
}
@@ -208,8 +245,8 @@ func (f *fileSink) drop(i int) { os.Remove(filepath.Join(f.dir, strconv.Itoa(i+1
// says the reading sentence once admitted, keeps every chunk in sequence in
// sink (each one checked against bound before the sink keeps anything, plan
// review finding 37), and returns the read's id and its result unopened.
-func readDBForward(ctx context.Context, body io.Reader, key *ecdh.PrivateKey, host, region, reading string, status io.Writer, sink dbChunkSink, bound *dbfChunkBound) (string, *dbreads.Result, error) {
- unchecked := fmt.Errorf(dbfUnchecked, region)
+func readDBForward(ctx context.Context, body io.Reader, key *ecdh.PrivateKey, host, place, reading string, status io.Writer, sink dbChunkSink, bound *dbfChunkBound) (string, *dbreads.Result, error) {
+ unchecked := fmt.Errorf(dbfUnchecked, place)
sc := bufio.NewScanner(body)
sc.Buffer(make([]byte, 64<<10), dbreads.MaxLineBytes)
var id, ended string
@@ -224,7 +261,7 @@ func readDBForward(ctx context.Context, body io.Reader, key *ecdh.PrivateKey, ho
return "", nil, unchecked
}
id = l.Admitted
- fmt.Fprintln(status, fmt.Sprintf(reading, host, region))
+ fmt.Fprintln(status, fmt.Sprintf(reading, host, place))
case l.Chunk != 0:
if id == "" || l.Chunk != int64(sink.count())+1 || !bound.admit(l.Data) {
return "", nil, unchecked
@@ -245,16 +282,16 @@ func readDBForward(ctx context.Context, body io.Reader, key *ecdh.PrivateKey, ho
return "", nil, errors.New("stopped")
}
if ended == dbreads.EndedNotPicked {
- return "", nil, fmt.Errorf(dbfNotPicked, region)
+ return "", nil, fmt.Errorf(dbfNotPicked, place)
}
- return "", nil, fmt.Errorf(dbfUnfinished, host, region)
+ return "", nil, fmt.Errorf(dbfUnfinished, host, place)
}
// openDBForward opens a result: a done one's every chunk and its summary,
// checked against each other before anything is returned; any other state
// mapped to its sentence (spec §5.6, §10).
-func openDBForward(id string, key *ecdh.PrivateKey, sink dbChunkSink, res dbreads.Result, host, region string) (dbForwardAnswer, error) {
- unchecked := fmt.Errorf(dbfUnchecked, region)
+func openDBForward(id string, key *ecdh.PrivateKey, sink dbChunkSink, res dbreads.Result, host, place string) (dbForwardAnswer, error) {
+ unchecked := fmt.Errorf(dbfUnchecked, place)
if res.Valid() != nil {
return dbForwardAnswer{}, unchecked
}
@@ -303,16 +340,16 @@ func openDBForward(id string, key *ecdh.PrivateKey, sink dbChunkSink, res dbread
case dbreads.CodeChangedTwice:
return dbForwardAnswer{}, dbRestoreError(host, os.ErrNotExist)
case dbreads.CodeTooLarge:
- return dbForwardAnswer{}, fmt.Errorf(dbfTooLarge, host, humanBytes(&s.Restored), humanBytes(&s.Cap), region)
+ return dbForwardAnswer{}, fmt.Errorf(dbfTooLarge, host, humanBytes(&s.Restored), humanBytes(&s.Cap), place)
case dbreads.CodeNoRoom:
- return dbForwardAnswer{}, fmt.Errorf(dbfNoRoom, region, host)
+ return dbForwardAnswer{}, fmt.Errorf(dbfNoRoom, place, host)
case dbreads.CodeSQLError:
return dbForwardAnswer{}, errors.New(s.Error)
case dbreads.CodeTimeout:
return dbForwardAnswer{}, errors.New(dbfTimeout)
}
}
- return dbForwardAnswer{}, fmt.Errorf(dbfUnfinished, host, region)
+ return dbForwardAnswer{}, fmt.Errorf(dbfUnfinished, host, place)
}
// openDBPull opens a pull's result (spec §6, phase 2): a done one's chunks,
@@ -320,8 +357,8 @@ func openDBForward(id string, key *ecdh.PrivateKey, sink dbChunkSink, res dbread
// against the summary's count and hash and split by its file list into a
// litestream file replica under dir, which today's restore and check turn
// into the copy. Any other state maps to its sentence.
-func openDBPull(ctx context.Context, id string, key *ecdh.PrivateKey, sink dbChunkSink, res dbreads.Result, host, region, dir string) (*dbdoor.Restored, error) {
- unchecked := fmt.Errorf(dbfUnchecked, region)
+func openDBPull(ctx context.Context, id string, key *ecdh.PrivateKey, sink dbChunkSink, res dbreads.Result, host, place, dir string) (*dbdoor.Restored, error) {
+ unchecked := fmt.Errorf(dbfUnchecked, place)
if res.Valid() != nil {
return nil, unchecked
}
@@ -332,11 +369,11 @@ func openDBPull(ctx context.Context, id string, key *ecdh.PrivateKey, sink dbChu
if res.State != dbreads.StateDone {
switch res.Code {
case dbreads.CodeTooLarge:
- return nil, fmt.Errorf(dbfPullTooLarge, host, humanBytes(&s.Restored), humanBytes(&s.Cap), region)
+ return nil, fmt.Errorf(dbfPullTooLarge, host, humanBytes(&s.Restored), humanBytes(&s.Cap), place)
case dbreads.CodeNoRoom:
- return nil, fmt.Errorf(dbfPullNoRoom, region, host)
+ return nil, fmt.Errorf(dbfPullNoRoom, place, host)
}
- _, err := openDBForward(id, key, sink, res, host, region)
+ _, err := openDBForward(id, key, sink, res, host, place)
return nil, err
}
// A done pull is the whole answer: no output cap applies to one.
@@ -358,7 +395,7 @@ func openDBPull(ctx context.Context, id string, key *ecdh.PrivateKey, sink dbChu
// Ctrl-C and the read's deadline stop the rebuild too (Astra round
// 1 on plan 3, finding 2); RestoreLocal's reads check ctx after it.
if err := ctx.Err(); err != nil {
- return nil, dbPullStopped(err, host, region)
+ return nil, dbPullStopped(err, host, place)
}
sealed, err := sink.chunk(i)
if err != nil {
@@ -419,7 +456,7 @@ func openDBPull(ctx context.Context, id string, key *ecdh.PrivateKey, sink dbChu
db := filepath.Join(dir, "replica.db")
if err := dbdoor.RestoreLocal(ctx, lsfile.NewReplicaClient(root), db, s.TXID); err != nil {
if cerr := ctx.Err(); cerr != nil {
- return nil, dbPullStopped(cerr, host, region)
+ return nil, dbPullStopped(cerr, host, place)
}
return nil, dbRestoreError(host, err)
}
@@ -429,11 +466,11 @@ func openDBPull(ctx context.Context, id string, key *ecdh.PrivateKey, sink dbChu
// dbPullStopped is a pull that ended on its context: "stopped" for Ctrl-C,
// DBF-12 for the read's own deadline.
-func dbPullStopped(err error, host, region string) error {
+func dbPullStopped(err error, host, place string) error {
if errors.Is(err, context.Canceled) {
return errors.New("stopped")
}
- return fmt.Errorf(dbfUnfinished, host, region)
+ return fmt.Errorf(dbfUnfinished, host, place)
}
// checkPullManifest is the summary's file list checked whole before any
@@ -499,11 +536,14 @@ func dbPullForward(ctx context.Context, t dbTarget, fwd dbdoor.Forward) (*dbdoor
if errors.Is(ctx.Err(), context.Canceled) {
return nil, errors.New("stopped")
}
- return nil, fmt.Errorf(dbfUnfinished, t.host, fwd.Region)
+ return nil, fmt.Errorf(dbfUnfinished, t.host, fwdPlace(fwd))
}
defer res.Body.Close()
if res.StatusCode != http.StatusOK {
raw, _ := io.ReadAll(io.LimitReader(res.Body, 64<<10))
+ if line, ok := dbMovingLine(t.host, raw); ok && res.StatusCode == http.StatusConflict {
+ return nil, errors.New(line)
+ }
return nil, apiErrorFromBody(res.StatusCode, raw)
}
dir, err := os.MkdirTemp("", "carlos-db-")
@@ -523,11 +563,11 @@ func dbPullForward(ctx context.Context, t dbTarget, fwd dbdoor.Forward) (*dbdoor
}
}()
sink := &fileSink{dir: filepath.Join(dir, "sealed")}
- id, result, err := readDBForward(ctx, res.Body, key, t.host, fwd.Region, dbfFetching, os.Stderr, sink, newDBFChunkBound(dbreads.MaxPullBytes, dbreads.PullChunkBytes))
+ id, result, err := readDBForward(ctx, res.Body, key, t.host, fwdPlace(fwd), dbfFetching, os.Stderr, sink, newDBFChunkBound(dbreads.MaxPullBytes, dbreads.PullChunkBytes))
if err != nil {
return nil, err
}
- r, err := openDBPull(ctx, id, key, sink, *result, t.host, fwd.Region, dir)
+ r, err := openDBPull(ctx, id, key, sink, *result, t.host, fwdPlace(fwd), dir)
if err != nil {
return nil, err
}
diff --git a/dbforward_e2e_test.go b/dbforward_e2e_test.go
index f509cbddd..db33871cc 100644
--- a/dbforward_e2e_test.go
+++ b/dbforward_e2e_test.go
@@ -62,6 +62,9 @@ type dbfE2EOptions struct {
worker dbreads.WorkerOptions
// noBox leaves the uk box out; the test scripts its own.
noBox bool
+ // labels: the uk box publishes its AWS region and the console reads its
+ // region name map (region labels spec §3.2).
+ labels bool
}
type dbfE2E struct {
@@ -133,9 +136,16 @@ func newDBFE2E(t *testing.T, o dbfE2EOptions) *dbfE2E {
t.Fatal(err)
}
}
- edges, _ := json.Marshal(map[string]any{"v": 1, "box": "uk-1", "eip": "203.0.113.10", "placement": "uk",
- "capabilities": []string{dbreads.Capability}, "hosts": map[string]any{}})
+ edgesMap := map[string]any{"v": 1, "box": "uk-1", "eip": "203.0.113.10", "placement": "uk",
+ "capabilities": []string{dbreads.Capability}, "hosts": map[string]any{}}
+ if o.labels {
+ edgesMap["region"] = "eu-west-2"
+ }
+ edges, _ := json.Marshal(edgesMap)
e.store.Put(context.Background(), "control/edges/uk-1.json", edges, "")
+ if o.labels && !srv.LoadRegionNames(context.Background()) {
+ t.Fatal("the console did not read its region names")
+ }
status, _ := json.Marshal(map[string]any{"generated_at": time.Now().UTC(), "label": "uk-1"})
e.store.Put(context.Background(), "status/boxes/uk-1.json", status, "")
token, expiresAt := e2eDeviceLogin(t, direct.URL, cst, addr, "e2e@laptop")
@@ -487,7 +497,7 @@ func checkProgressAtTheCLI(t *testing.T, e *dbfE2E, tap *dbfTap, atLeast time.Du
var reading time.Time
sc := bufio.NewScanner(pipe)
for sc.Scan() {
- if reading.IsZero() && strings.Contains(sc.Text(), fmt.Sprintf(dbfReading, dbfE2EFar, "uk")) {
+ if reading.IsZero() && strings.Contains(sc.Text(), fmt.Sprintf(dbfReading, dbfE2EFar, "region uk")) {
reading = time.Now()
}
stderr = append(stderr, sc.Text())
@@ -541,7 +551,7 @@ func TestDBForwardParityThroughTheCLI(t *testing.T) {
if here != far || here == "" {
t.Fatalf("at %q: in region %q, forwarded %q", at, here, far)
}
- if !strings.Contains(farErr, fmt.Sprintf(dbfReading, dbfE2EFar, "uk")) {
+ if !strings.Contains(farErr, fmt.Sprintf(dbfReading, dbfE2EFar, "region uk")) {
t.Fatalf("no DBF-11 on stderr: %s", farErr)
}
if at != "" && strings.Contains(far, "later") {
@@ -694,7 +704,7 @@ func TestDBForwardPrintsNothingForABadAnswer(t *testing.T) {
func TestDBForwardRefusesSQLThatIsNotUTF8(t *testing.T) {
e := newDBFE2E(t, dbfE2EOptions{forward: true, noBox: true})
out, stderr, err := e.run(t, "db", "query", "--account", "ops", "--app", "shop", "--instance", dbfE2EFar, "--sql", "SELECT 'caf\xe9'")
- if err == nil || out != "" || !strings.Contains(stderr, fmt.Sprintf(dbfNotUTF8, "uk")) {
+ if err == nil || out != "" || !strings.Contains(stderr, fmt.Sprintf(dbfNotUTF8, "region uk")) {
t.Fatalf("%q %q %v", out, stderr, err)
}
if keys, _ := e.store.List(context.Background(), dbreads.Prefix); len(keys) != 0 {
@@ -822,7 +832,7 @@ func TestDBForwardPullParityThroughTheCLI(t *testing.T) {
if here == "" || strings.ReplaceAll(strings.ReplaceAll(far, dbfE2EFar, dbfE2EHere), farOut, hereOut) != here {
t.Fatalf("at %q: in region %q, forwarded %q", at, here, far)
}
- if !strings.Contains(farErr, fmt.Sprintf(dbfFetching, dbfE2EFar, "uk")) {
+ if !strings.Contains(farErr, fmt.Sprintf(dbfFetching, dbfE2EFar, "region uk")) {
t.Fatalf("no DBF-18: %s", farErr)
}
db, _ := sql.Open("sqlite", "file:"+farOut+"?mode=ro")
@@ -872,7 +882,7 @@ func TestDBForwardPullSavesNothingForABadAnswer(t *testing.T) {
defer stop()
out := filepath.Join(t.TempDir(), "far.db")
_, stderr, err := e.run(t, "db", "pull", "--account", "ops", "--app", "shop", "--instance", dbfE2EFar, "--out", out)
- if err == nil || !strings.Contains(stderr, fmt.Sprintf(dbfUnchecked, "uk")) {
+ if err == nil || !strings.Contains(stderr, fmt.Sprintf(dbfUnchecked, "region uk")) {
t.Fatalf("%q %v", stderr, err)
}
if _, err := os.Stat(out); !os.IsNotExist(err) {
@@ -960,10 +970,20 @@ func TestDBForwardPullOnAQueryOnlyConsole(t *testing.T) {
e := newDBFE2E(t, dbfE2EOptions{forward: true, noBox: true, serve: queryOnly})
out := filepath.Join(t.TempDir(), "far.db")
_, stderr, err := e.run(t, "db", "pull", "--account", "ops", "--app", "shop", "--instance", dbfE2EFar, "--out", out)
- if err == nil || !strings.Contains(stderr, fmt.Sprintf(dbfNoPull, dbfE2EFar, "uk")) {
+ if err == nil || !strings.Contains(stderr, fmt.Sprintf(dbfNoPull, dbfE2EFar, "region uk")) {
t.Fatalf("%q %v", stderr, err)
}
if _, err := os.Stat(out); !os.IsNotExist(err) {
t.Fatalf("something was saved at --out: %v", err)
}
}
+
+// TestDBForwardSaysTheLabel (spec §5 rows 27): the marker's region_name
+// reaches the CLI's sentence through the real console.
+func TestDBForwardSaysTheLabel(t *testing.T) {
+ e := newDBFE2E(t, dbfE2EOptions{forward: true, noBox: true, labels: true})
+ out, stderr, err := e.run(t, "db", "query", "--account", "ops", "--app", "shop", "--instance", dbfE2EFar, "--sql", "SELECT 'caf\xe9'")
+ if err == nil || out != "" || !strings.Contains(stderr, fmt.Sprintf(dbfNotUTF8, "London (uk)")) {
+ t.Fatalf("%q %q %v", out, stderr, err)
+ }
+}
diff --git a/dbforward_test.go b/dbforward_test.go
index 74dd9c2b6..84fbfeebe 100644
--- a/dbforward_test.go
+++ b/dbforward_test.go
@@ -74,11 +74,11 @@ func readFwd(t *testing.T, s *stream, key *ecdh.PrivateKey) (dbForwardAnswer, st
t.Helper()
var status bytes.Buffer
sink := &memSink{}
- id, res, err := readDBForward(context.Background(), &s.buf, key, "shop.example.com", "uk", dbfReading, &status, sink, newDBFChunkBound(dbreads.MaxOutputBytes, dbreads.ChunkBytes))
+ id, res, err := readDBForward(context.Background(), &s.buf, key, "shop.example.com", "region uk", dbfReading, &status, sink, newDBFChunkBound(dbreads.MaxOutputBytes, dbreads.ChunkBytes))
if err != nil {
return dbForwardAnswer{}, status.String(), err
}
- ans, err := openDBForward(id, key, sink, *res, "shop.example.com", "uk")
+ ans, err := openDBForward(id, key, sink, *res, "shop.example.com", "region uk")
return ans, status.String(), err
}
@@ -93,7 +93,7 @@ func TestForwardedQueryPrintsOnlyACheckedAnswer(t *testing.T) {
if err != nil || string(ans.rows) != "n\n30\n" || ans.summary.TXID != 7 {
t.Fatalf("%q %v", ans.rows, err)
}
- if status != fmt.Sprintf(dbfReading, "shop.example.com", "uk")+"\n" {
+ if status != fmt.Sprintf(dbfReading, "shop.example.com", "region uk")+"\n" {
t.Fatalf("status %q", status)
}
}
@@ -102,7 +102,7 @@ func TestForwardedQueryPrintsOnlyACheckedAnswer(t *testing.T) {
// does not add up each print nothing.
func TestForwardedQueryRefusesAnAnswerThatDoesNotCheckOut(t *testing.T) {
t.Parallel()
- unchecked := fmt.Sprintf(dbfUnchecked, "uk")
+ unchecked := fmt.Sprintf(dbfUnchecked, "region uk")
for name, build := range map[string]func(s *stream){
"the last chunk dropped": func(s *stream) {
s.chunk(1, false, []byte("n\n"))
@@ -137,7 +137,7 @@ func TestForwardedQueryEndsWithoutAResult(t *testing.T) {
key, _ := dbreads.NewReplyKey()
s := newStream(t, key)
s.chunk(1, false, []byte("n\n"))
- if _, _, err := readFwd(t, s, key); err == nil || err.Error() != fmt.Sprintf(dbfUnfinished, "shop.example.com", "uk") {
+ if _, _, err := readFwd(t, s, key); err == nil || err.Error() != fmt.Sprintf(dbfUnfinished, "shop.example.com", "region uk") {
t.Fatalf("no result: %v", err)
}
key2, _ := dbreads.NewReplyKey()
@@ -145,7 +145,7 @@ func TestForwardedQueryEndsWithoutAResult(t *testing.T) {
s2.line(dbreads.Line{Admitted: fwdID})
s2.line(dbreads.Line{Wait: dbreads.WaitPickup})
s2.line(dbreads.Line{Ended: dbreads.EndedNotPicked})
- if _, _, err := readFwd(t, s2, key2); err == nil || err.Error() != fmt.Sprintf(dbfNotPicked, "uk") {
+ if _, _, err := readFwd(t, s2, key2); err == nil || err.Error() != fmt.Sprintf(dbfNotPicked, "region uk") {
t.Fatalf("not picked: %v", err)
}
}
@@ -154,13 +154,13 @@ func TestForwardedQueryMapsEveryCode(t *testing.T) {
t.Parallel()
host := "shop.example.com"
for code, want := range map[string]string{
- dbreads.CodeTooLarge: fmt.Sprintf(dbfTooLarge, host, "3.0GB", "2.0GB", "uk"),
- dbreads.CodeNoRoom: fmt.Sprintf(dbfNoRoom, "uk", host),
+ dbreads.CodeTooLarge: fmt.Sprintf(dbfTooLarge, host, "3.0GB", "2.0GB", "region uk"),
+ dbreads.CodeNoRoom: fmt.Sprintf(dbfNoRoom, "region uk", host),
dbreads.CodeTimeout: dbfTimeout,
dbreads.CodeSQLError: "no such table: nope",
dbreads.CodeNothingReplicated: dbRestoreError(host, dbdoorErrNothing()).Error(),
dbreads.CodeChangedTwice: dbRestoreError(host, errVanished()).Error(),
- dbreads.CodeInterrupted: fmt.Sprintf(dbfUnfinished, host, "uk"),
+ dbreads.CodeInterrupted: fmt.Sprintf(dbfUnfinished, host, "region uk"),
} {
key, _ := dbreads.NewReplyKey()
s := newStream(t, key)
@@ -219,7 +219,7 @@ func TestForwardedQueryCtrlCPrintsNothing(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
cancel()
var status bytes.Buffer
- _, _, err := readDBForward(ctx, &cutReader{r: &s.buf}, key, "shop.example.com", "uk", dbfReading, &status, &memSink{}, newDBFChunkBound(dbreads.MaxOutputBytes, dbreads.ChunkBytes))
+ _, _, err := readDBForward(ctx, &cutReader{r: &s.buf}, key, "shop.example.com", "region uk", dbfReading, &status, &memSink{}, newDBFChunkBound(dbreads.MaxOutputBytes, dbreads.ChunkBytes))
if err == nil || err.Error() != "stopped" {
t.Fatalf("%v", err)
}
@@ -235,7 +235,7 @@ func TestForwardedQueryCtrlCPrintsNothing(t *testing.T) {
func TestForwardedQueryBoundsChunkCountAndSize(t *testing.T) {
t.Parallel()
key, _ := dbreads.NewReplyKey()
- unchecked := fmt.Sprintf(dbfUnchecked, "uk")
+ unchecked := fmt.Sprintf(dbfUnchecked, "region uk")
many := newDBFChunkBound(dbreads.MaxOutputBytes, dbreads.ChunkBytes).maxChunks + 1
for name, write := range map[string]func(s *stream){
"a chunk shorter than its seal": func(s *stream) {
@@ -257,9 +257,9 @@ func TestForwardedQueryBoundsChunkCountAndSize(t *testing.T) {
write(s)
var status bytes.Buffer
sink := &memSink{}
- id, res, err := readDBForward(context.Background(), &s.buf, key, "shop.example.com", "uk", dbfReading, &status, sink, newDBFChunkBound(dbreads.MaxOutputBytes, dbreads.ChunkBytes))
+ id, res, err := readDBForward(context.Background(), &s.buf, key, "shop.example.com", "region uk", dbfReading, &status, sink, newDBFChunkBound(dbreads.MaxOutputBytes, dbreads.ChunkBytes))
if err == nil {
- _, err = openDBForward(id, key, sink, *res, "shop.example.com", "uk")
+ _, err = openDBForward(id, key, sink, *res, "shop.example.com", "region uk")
}
if err == nil || err.Error() != unchecked {
t.Errorf("%s: %v", name, err)
@@ -281,7 +281,7 @@ func TestForwardedQueryRefusesSQLThatIsNotUTF8(t *testing.T) {
app: "shop", host: "shop.example.com"}
for _, q := range []string{"SELECT '\xff'", "SELECT '�'"} {
err := dbQueryForward(context.Background(), target, q, dbdoor.Forward{Region: "uk", Ops: []string{dbreads.OpQuery}})
- if err == nil || err.Error() != fmt.Sprintf(dbfNotUTF8, "uk") {
+ if err == nil || err.Error() != fmt.Sprintf(dbfNotUTF8, "region uk") {
t.Errorf("%q: %v", q, err)
}
}
@@ -359,11 +359,11 @@ func readPull(t *testing.T, st *stream, key *ecdh.PrivateKey) (*dbdoor.Restored,
func readPullIn(t *testing.T, st *stream, key *ecdh.PrivateKey, dir string) (*dbdoor.Restored, error) {
t.Helper()
sink := &fileSink{dir: filepath.Join(dir, "sealed")}
- id, res, err := readDBForward(context.Background(), &st.buf, key, "shop.example.com", "uk", dbfFetching, io.Discard, sink, newDBFChunkBound(dbreads.MaxPullBytes, dbreads.PullChunkBytes))
+ id, res, err := readDBForward(context.Background(), &st.buf, key, "shop.example.com", "region uk", dbfFetching, io.Discard, sink, newDBFChunkBound(dbreads.MaxPullBytes, dbreads.PullChunkBytes))
if err != nil {
return nil, err
}
- return openDBPull(context.Background(), id, key, sink, *res, "shop.example.com", "uk", dir)
+ return openDBPull(context.Background(), id, key, sink, *res, "shop.example.com", "region uk", dir)
}
func TestForwardedPullRestoresTheFiles(t *testing.T) {
@@ -435,7 +435,7 @@ func TestForwardedPullRefusesFilesThatDoNotAddUp(t *testing.T) {
t.Errorf("%s: panic %v", name, p)
}
}()
- if _, err := readPullIn(t, pullStream(t, key, dir, mutate), key, out); err == nil || err.Error() != fmt.Sprintf(dbfUnchecked, "uk") {
+ if _, err := readPullIn(t, pullStream(t, key, dir, mutate), key, out); err == nil || err.Error() != fmt.Sprintf(dbfUnchecked, "region uk") {
t.Errorf("%s: %v", name, err)
}
}()
@@ -455,8 +455,8 @@ func TestForwardedPullEndings(t *testing.T) {
want string
}{
"too large": {dbreads.CodeTooLarge, dbreads.Summary{Restored: 3 << 30, Cap: 2 << 30},
- fmt.Sprintf(dbfPullTooLarge, "shop.example.com", humanBytes(ptr(int64(3<<30))), humanBytes(ptr(int64(2<<30))), "uk")},
- "no room": {dbreads.CodeNoRoom, dbreads.Summary{}, fmt.Sprintf(dbfPullNoRoom, "uk", "shop.example.com")},
+ fmt.Sprintf(dbfPullTooLarge, "shop.example.com", humanBytes(ptr(int64(3<<30))), humanBytes(ptr(int64(2<<30))), "region uk")},
+ "no room": {dbreads.CodeNoRoom, dbreads.Summary{}, fmt.Sprintf(dbfPullNoRoom, "region uk", "shop.example.com")},
"nothing replicated": {dbreads.CodeNothingReplicated, dbreads.Summary{}, dbRestoreError("shop.example.com", dbdoor.ErrNothingReplicated).Error()},
} {
key, _ := dbreads.NewReplyKey()
@@ -496,10 +496,10 @@ func TestForwardedPullSpoolsNoMalformedOrExcessChunk(t *testing.T) {
want := write(s)
dir := filepath.Join(t.TempDir(), "sealed")
sink := &fileSink{dir: dir}
- _, _, err := readDBForward(context.Background(), &s.buf, key, "shop.example.com", "uk", dbfFetching, io.Discard, sink,
+ _, _, err := readDBForward(context.Background(), &s.buf, key, "shop.example.com", "region uk", dbfFetching, io.Discard, sink,
&dbfChunkBound{maxBytes: dbreads.MaxPullBytes, maxChunks: 10})
files, _ := os.ReadDir(dir)
- if err == nil || err.Error() != fmt.Sprintf(dbfUnchecked, "uk") || len(files) != want {
+ if err == nil || err.Error() != fmt.Sprintf(dbfUnchecked, "region uk") || len(files) != want {
t.Errorf("%s: %v, %d spool files, want %d", name, err, len(files), want)
}
}
@@ -640,7 +640,7 @@ func TestForwardedPullRefusesARelabelledSnapshot(t *testing.T) {
key, _ := dbreads.NewReplyKey()
out := t.TempDir()
r, err := readPullIn(t, pullStreamOf(t, key, b, s), key, out)
- if err == nil || err.Error() != fmt.Sprintf(dbfUnchecked, "uk") {
+ if err == nil || err.Error() != fmt.Sprintf(dbfUnchecked, "region uk") {
t.Fatalf("a relabelled snapshot gave %+v, %v", r, err)
}
if _, err := os.Stat(filepath.Join(out, "replica.db")); !os.IsNotExist(err) {
@@ -660,13 +660,13 @@ func TestForwardedPullStopsWhenCancelledAfterTheDownload(t *testing.T) {
st := pullStreamN(t, key, dir, 4, nil)
out := t.TempDir()
sink := &fileSink{dir: filepath.Join(out, "sealed")}
- id, res, err := readDBForward(context.Background(), &st.buf, key, "shop.example.com", "uk", dbfFetching, io.Discard, sink, newDBFChunkBound(dbreads.MaxPullBytes, dbreads.PullChunkBytes))
+ id, res, err := readDBForward(context.Background(), &st.buf, key, "shop.example.com", "region uk", dbfFetching, io.Discard, sink, newDBFChunkBound(dbreads.MaxPullBytes, dbreads.PullChunkBytes))
if err != nil {
t.Fatal(err)
}
ctx, cancel := context.WithCancel(context.Background())
cancel()
- if _, err := openDBPull(ctx, id, key, sink, *res, "shop.example.com", "uk", out); err == nil || err.Error() != "stopped" {
+ if _, err := openDBPull(ctx, id, key, sink, *res, "shop.example.com", "region uk", out); err == nil || err.Error() != "stopped" {
t.Fatalf("a cancelled pull answered %v", err)
}
for _, gone := range []string{"replica", "replica.db"} {
diff --git a/docs/superpowers/plans/2026-10-22-db-region-forward-copy.md b/docs/superpowers/plans/2026-10-22-db-region-forward-copy.md
index a4a1db96c..7e8b1c6c6 100644
--- a/docs/superpowers/plans/2026-10-22-db-region-forward-copy.md
+++ b/docs/superpowers/plans/2026-10-22-db-region-forward-copy.md
@@ -30,7 +30,14 @@ The rules:
Placeholders: `<host>` the instance's hostname; `<region>` a placement code
such as uk; `<size>` and `<cap>` byte sizes as the CLI prints them; `<n>` a
count of bytes; `<sha>` the first 16 hex digits of a SHA-256; `<time>` an
-RFC 3339 time.
+RFC 3339 time; `<place>` the region as the console labels it, such as
+London (uk), or `region <code>` from an older console (region labels,
+2026-10-26).
+
+Region labels (2026-10-26): the CLI rows DBF-3, 4, 5, 8, 11, 12, 13, 17, 18,
+24 and 32 took `<place>` where they had `region <region>` (region labels copy
+rows RC-21 to RC-31, in that order), and DBF-33 is new (RC-32), all approved
+by Luna under Paul's delegation (`LUNA-COPY-REVIEW-REGION-LABELS-2.md`).
## Console (plan 2)
@@ -48,18 +55,19 @@ RFC 3339 time.
| id | file | text | status |
|---|---|---|---|
-| DBF-3 | dbforward.go | no server in region <region> started the read within 60 seconds. try again in a few minutes. | approved |
-| DBF-4 | dbforward.go | the database for <host> is <size> once restored. carlos db can query at most <cap> in region <region>. | approved |
-| DBF-5 | dbforward.go | the server in region <region> does not have room to restore <host>'s database right now. try again later. | approved |
+| DBF-3 | dbforward.go | no server in <place> started the read within 60 seconds. try again in a few minutes. | approved |
+| DBF-4 | dbforward.go | the database for <host> is <size> once restored. carlos db can query at most <cap> in <place>. | approved |
+| DBF-5 | dbforward.go | the server in <place> does not have room to restore <host>'s database right now. try again later. | approved |
| DBF-6 | dbforward.go | the result was cut off at 64 MB. narrow the query with WHERE or LIMIT and run it again. | approved |
| DBF-7 | dbforward.go | the query ran for 5 minutes and was stopped. narrow it and run it again. | approved |
-| DBF-8 | dbforward.go | <host> keeps its data in region <region>. carlos db pull cannot fetch a copy from there yet. carlos db query can read it. | approved |
-| DBF-11 | dbforward.go | reading a copy of <host>'s database in region <region>. | approved |
-| DBF-12 | dbforward.go | the read of <host>'s database in region <region> did not finish, so nothing was printed. try again. | approved |
-| DBF-13 | dbforward.go | the answer from region <region> was invalid, so carlos db printed nothing. try again. | approved |
+| DBF-8 | dbforward.go | <host> keeps its data in <place>. carlos db pull cannot fetch a copy from there yet. carlos db query can read it. | approved |
+| DBF-11 | dbforward.go | reading a copy of <host>'s database in <place>. | approved |
+| DBF-12 | dbforward.go | the read of <host>'s database in <place> did not finish, so nothing was printed. try again. | approved |
+| DBF-13 | dbforward.go | the answer from <place> was invalid, so carlos db printed nothing. try again. | approved |
| DBF-15 | dbforward.go | <host> changed while the read was waiting. try again. | approved |
| DBF-16 | dbforward.go | <host> is moving between regions. read its database once the move has finished. | approved |
-| DBF-32 | dbforward.go | this query cannot be sent to region <region>, because it contains invalid UTF-8 or the replacement character U+FFFD. fix the query and run it again. | approved |
+| DBF-32 | dbforward.go | this query cannot be sent to <place>, because it contains invalid UTF-8 or the replacement character U+FFFD. fix the query and run it again. | approved |
+| DBF-33 | dbforward.go | <host> is moving from <place> to <place>. read its database once the move has finished. | approved |
## Pull (plan 3)
@@ -68,12 +76,12 @@ DBF-23 replaces DBF-30 on the CLI page; DBF-30 stays here, approved, and leaves
| id | file | text | status |
|---|---|---|---|
-| DBF-17 | dbforward.go | the database for <host> has <size> of files to fetch. carlos db pull can fetch at most <cap> from region <region>. | approved |
-| DBF-18 | dbforward.go | fetching a copy of <host>'s database from region <region>. | approved |
+| DBF-17 | dbforward.go | the database for <host> has <size> of files to fetch. carlos db pull can fetch at most <cap> from <place>. | approved |
+| DBF-18 | dbforward.go | fetching a copy of <host>'s database from <place>. | approved |
| DBF-19 | internal/console/apidbforward.go | forwarded a database pull to region <region> (cli) | approved |
| DBF-20 | internal/console/apidbforward.go | forwarded a database pull to region <region>, as of <time> (cli) | approved |
| DBF-23 | docs/site/cli.md | If the app has more than one instance, name one with `--instance`. Only instances that sleep have a database copy. An instance on your own fleet or in a pool cannot be read this way, and the command says which.\n\nWhen an instance keeps its data in a different region from the console's, `carlos db query` runs in that region. A server there restores the copy, runs your query and sends back only the rows. `carlos db pull` fetches the copy's files from there and restores them on your machine. Both are encrypted for your terminal on the way, so nothing in between can read them, and nothing is printed or saved until all of it has arrived and been checked. In that region, a query's copy can be at most 2 GB once restored, the query runs for at most 5 minutes, and the rows can total at most 64 MB. A pull can fetch at most 2 GB. | approved |
-| DBF-24 | dbforward.go | the server in region <region> does not have room to prepare a copy of <host>'s database right now. try again later. | approved |
+| DBF-24 | dbforward.go | the server in <place> does not have room to prepare a copy of <host>'s database right now. try again later. | approved |
## Docs
diff --git a/region_labels_test.go b/region_labels_test.go
index 24674b67d..04d261c33 100644
--- a/region_labels_test.go
+++ b/region_labels_test.go
@@ -7,6 +7,8 @@ import (
"strings"
"testing"
"time"
+
+ "github.com/carlosframework/platform/internal/dbdoor"
)
func TestCleanPlaceRefusesWhatATerminalWouldObey(t *testing.T) {
@@ -152,3 +154,42 @@ func TestDeployWatchLinesSayWhere(t *testing.T) {
t.Fatalf("hostPlaces = %v", p)
}
}
+
+func TestDBSentencesNameTheLabel(t *testing.T) {
+ labelled := dbdoor.Forward{Region: "uk", RegionName: "London (uk)"}
+ older := dbdoor.Forward{Region: "uk"}
+ hostile := dbdoor.Forward{Region: "uk", RegionName: "London\x1b[0m"}
+ unread := dbdoor.Forward{Region: "uk", RegionName: "uk"} // a labels console before its first edges read
+ if fwdPlace(labelled) != "London (uk)" || fwdPlace(older) != "region uk" || fwdPlace(hostile) != "region uk" || fwdPlace(unread) != "region uk" {
+ t.Fatal("fwdPlace")
+ }
+ for _, c := range []struct{ got, want string }{
+ {fmt.Sprintf(dbfNotPicked, fwdPlace(labelled)), "no server in London (uk) started the read within 60 seconds. try again in a few minutes."},
+ {fmt.Sprintf(dbfReading, "a.shop.example.com", fwdPlace(labelled)), "reading a copy of a.shop.example.com's database in London (uk)."},
+ {fmt.Sprintf(dbfNoPull, "a.shop.example.com", fwdPlace(labelled)), "a.shop.example.com keeps its data in London (uk). carlos db pull cannot fetch a copy from there yet. carlos db query can read it."},
+ // An older console: today's bytes.
+ {fmt.Sprintf(dbfNotPicked, fwdPlace(older)), "no server in region uk started the read within 60 seconds. try again in a few minutes."},
+ {fmt.Sprintf(dbfUnchecked, fwdPlace(older)), "the answer from region uk was invalid, so carlos db printed nothing. try again."},
+ } {
+ if c.got != c.want {
+ t.Errorf("%q, want %q", c.got, c.want)
+ }
+ }
+}
+
+func TestDBMovingLine(t *testing.T) {
+ line, ok := dbMovingLine("a.shop.example.com", []byte(`{"error":"a.shop.example.com is moving between regions. read its database once the move has finished.","from_name":"London (uk)","to_name":"Dublin (ie)"}`))
+ if !ok || line != "a.shop.example.com is moving from London (uk) to Dublin (ie). read its database once the move has finished." {
+ t.Fatalf("%q %v", line, ok)
+ }
+ for _, body := range []string{
+ `{"error":"a.shop.example.com is moving between regions. read its database once the move has finished."}`, // an older console: DBF-10 as sent
+ `{"error":"x","from_name":"London (uk)"}`, // one side only
+ `{"error":"x","from_name":"\u001b[2J","to_name":"Dublin (ie)"}`, // not fit to print
+ `not json`,
+ } {
+ if _, ok := dbMovingLine("a.shop.example.com", []byte(body)); ok {
+ t.Errorf("RC-32 from %s", body)
+ }
+ }
+}