carlos / platform Public

cli: carlos instances create --restore (#658)

--restore sends "restore": true to the create door merged in 3933abe;
it refuses with --from, --kind, --addr or --role before any request, and
prints "restore accepted" only when the console confirms. Ordinary
creates send the same bytes as before. Census: root envelope re-pinned,
approved by Astra (#280).

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

Squashed from instance-restore-658-cli into main.
claude agent, operated by paul@keymail.dev 663b76bf6cc032ef4433737b2bc1b68775a66c70 parent 3933abe
8 files changed, +198 −7
  • apimode.go +10 −4
  • canary.go +1 −1
  • docs/superpowers/notes/census-proposal-instance-restore-658-cli.md +11 −0
  • docs/superpowers/notes/instance-restore-658-cli-copy.json +23 −0
  • instances_cli.go +15 −2
  • instances_restore_test.go +134 −0
  • internal/provision/testdata/plan14-root-reads-chain.tsv +1 −0
  • internal/provision/testdata/plan14-root-reads-instance-restore-658-cli.tsv +3 −0

CI failed — run details

diff --git a/apimode.go b/apimode.go
index fd8d23e88..15b8e0e09 100644
--- a/apimode.go
+++ b/apimode.go
@@ -3363,6 +3363,9 @@ func (s *apiSession) instancesEnable(ctx context.Context, a apiAcct, app string,
// rather than imported because this client renders records, never writes
// them, and the fields it renders are the contract worth pinning.
type apiInstanceRecord struct {
+ // Restore is true when the create door accepted the request as a restore
+ // (#658); false from an older console that ignored the field.
+ Restore bool `json:"restore"`
Host string `json:"host"`
Slug string `json:"slug"`
Pool string `json:"pool"`
@@ -3603,13 +3606,15 @@ func (rq *instanceReplicaReq) set() []string {
// probe nil means unprobed — the same "absent, not zero" contract the wire
// carries for every optional field on this door.
func (s *apiSession) instanceCreate(ctx context.Context, a apiAcct, app, host, region, channel, kind, environment string, addrs []string, probe *instanceProbeReq, replicas *instanceReplicaReq, messages ...string) (apiInstanceRecord, error) {
- return s.instanceCreateScoped(ctx, a, app, host, region, channel, kind, environment, "", addrs, probe, replicas, messages...)
+ return s.instanceCreateScoped(ctx, a, app, host, region, channel, kind, environment, "", addrs, probe, replicas, false, messages...)
}
// instanceCreateScoped is instanceCreate with the person's explicit scope
// for binding into an environment a team scope owns (`--scope`,
-// team-scoped credentials §3); "" for every other create.
-func (s *apiSession) instanceCreateScoped(ctx context.Context, a apiAcct, app, host, region, channel, kind, environment, scope string, addrs []string, probe *instanceProbeReq, replicas *instanceReplicaReq, messages ...string) (apiInstanceRecord, error) {
+// team-scoped credentials §3); "" for every other create. restore asks the
+// console to bring back a deleted instance on host (#658) and is omitted from
+// the body when false.
+func (s *apiSession) instanceCreateScoped(ctx context.Context, a apiAcct, app, host, region, channel, kind, environment, scope string, addrs []string, probe *instanceProbeReq, replicas *instanceReplicaReq, restore bool, messages ...string) (apiInstanceRecord, error) {
message := firstMutationMessage(messages)
in := struct {
Host string `json:"host"`
@@ -3623,7 +3628,8 @@ func (s *apiSession) instanceCreateScoped(ctx context.Context, a apiAcct, app, h
Role string `json:"role,omitempty"`
Replicas []string `json:"replicas,omitempty"`
Message string `json:"message,omitempty"`
- }{host, region, channel, kind, environment, scope, addrs, probe, replicas.role(), replicas.set(), message}
+ Restore bool `json:"restore,omitempty"`
+ }{host, region, channel, kind, environment, scope, addrs, probe, replicas.role(), replicas.set(), message, restore}
status, body, err := s.postJSON(ctx, apiPath(a, app, "/instances"), in)
if err != nil {
return apiInstanceRecord{}, err
diff --git a/canary.go b/canary.go
index 1c260628c..d9eb21290 100644
--- a/canary.go
+++ b/canary.go
@@ -589,7 +589,7 @@ func runCanaryDeploy(args []string) {
case canaryPlanTaken:
log.Fatalf("canary: %s", canaryHostTaken(host, canaryHostChannel(pre, recs, host)))
case canaryPlanCreate:
- rec, cerr := sess.instanceCreateScoped(ctx, acct, app2, host, strings.TrimSpace(*regionFlag), channel, recKind, env, strings.TrimSpace(*scopeFlag), nil, nil, nil)
+ rec, cerr := sess.instanceCreateScoped(ctx, acct, app2, host, strings.TrimSpace(*regionFlag), channel, recKind, env, strings.TrimSpace(*scopeFlag), nil, nil, nil, false)
if cerr != nil {
log.Fatalf("canary: create %s: %v", host, cerr)
}
diff --git a/docs/superpowers/notes/census-proposal-instance-restore-658-cli.md b/docs/superpowers/notes/census-proposal-instance-restore-658-cli.md
new file mode 100644
index 000000000..004c8836a
--- /dev/null
+++ b/docs/superpowers/notes/census-proposal-instance-restore-658-cli.md
@@ -0,0 +1,11 @@
+# Census approval: instance-restore-658-cli
+
+Ruling `census-ruling-instance-restore-658-cli`. The independent reviewer approves or rejects every change below, 0 with a new disposition; nothing goes to the census owner (Paul, #280, 2026-10-26).
+
+Envelopes re-pinned: `.`.
+
+Review: a model from the other family than the author reads the branch's diff against main on the amadan.net remote (`origin` or `amadan`, whichever points at amadan.net) and gives a verdict for every unit and every re-pinned envelope above. For a unit, compare the change with its recorded disposition and basis below; for an envelope, read every changed function in the package and what it reaches. Reject if the change lets root open, run, query or follow anything it did not before from a path or input a tenant, an app or a box agent can create, write or name; if it weakens a check, refusal, validation, argument or environment the basis relies on; or if the diff cannot settle either. Otherwise approve. Record each verdict on #280 with the tip. A rejected unit goes back to the author to correct; nothing escalates to the census owner.
+
+Seal: `b970bb28c5a633d2572a1da549030e9258cfdabb6322ddffdd0ebf41b56c464c` → `b970bb28c5a633d2572a1da549030e9258cfdabb6322ddffdd0ebf41b56c464c`.
+
+Overlay: `internal/provision/testdata/plan14-root-reads-instance-restore-658-cli.tsv`, appended to `internal/provision/testdata/plan14-root-reads-chain.tsv`.
diff --git a/docs/superpowers/notes/instance-restore-658-cli-copy.json b/docs/superpowers/notes/instance-restore-658-cli-copy.json
new file mode 100644
index 000000000..565b39daa
--- /dev/null
+++ b/docs/superpowers/notes/instance-restore-658-cli-copy.json
@@ -0,0 +1,23 @@
+{
+ "approved_by": "Paul",
+ "approved_on": "2026-11-08",
+ "review": "quvrxpwioc7x3stkg5zt3xyxre",
+ "strings": [
+ {
+ "id": "cli.restore.flag",
+ "text": "bring back a deleted instance on this host with the data it kept: the same app's plain instance, created and deleted after restore was available"
+ },
+ {
+ "id": "cli.restore.done",
+ "text": "restore accepted"
+ },
+ {
+ "id": "cli.restore.wakes",
+ "text": "it wakes with whatever data it kept when it was deleted"
+ },
+ {
+ "id": "cli.restore.plainonly",
+ "text": "a restore is a plain instance. Drop --from, --kind, --addr and --role."
+ }
+ ]
+}
\ No newline at end of file
diff --git a/instances_cli.go b/instances_cli.go
index 730ab193b..510a2dbf1 100644
--- a/instances_cli.go
+++ b/instances_cli.go
@@ -327,6 +327,7 @@ func runInstancesCreate(args []string) {
from := fs.String("from", "", "copy this instance's database into the new one. The source must be an instance of the same app, in this console's region")
at := fs.Int64("at", 0, "with --from, the transaction id to copy at (default: the latest)")
replicas := fs.String("replicas", "", "comma-separated placement codes the account's replicas live in (the HOME record's opt-in; e.g. ie,uk) — this instance's own replica must be --role replica with --region")
+ restore := fs.Bool("restore", false, "bring back a deleted instance on this host with the data it kept: the same app's plain instance, created and deleted after restore was available")
fs.Usage = flagUsage(fs, instancesRecordsUsage)
fs.Parse(args)
if *host == "" {
@@ -336,6 +337,9 @@ func runInstancesCreate(args []string) {
fs.Visit(func(f *flag.Flag) { set[f.Name] = true })
addrs := parseAddrList(*addr, set["addr"])
probe := parseProbeFlags(*healthPath, *healthStatus, set["health-path"], set["health-status"])
+ if *restore && (*from != "" || *kind != "" || set["addr"] || *role != "") {
+ log.Fatalf("instances create: %s", "a restore is a plain instance. Drop --from, --kind, --addr and --role.")
+ }
if set["at"] && (*at <= 0 || *from == "") {
log.Fatalf("instances create: %s", "at must be a transaction id, a whole number above 0")
}
@@ -360,11 +364,17 @@ func runInstancesCreate(args []string) {
rec, err := sess.instanceCreateScoped(context.Background(), acct, app2,
strings.TrimSpace(*host), strings.TrimSpace(*region), strings.TrimSpace(*channel),
strings.TrimSpace(*kind), strings.TrimSpace(*environment), strings.TrimSpace(*scope), addrs, probe,
- replicaReqFromFlags(*role, *replicas, set["region"]), message)
+ replicaReqFromFlags(*role, *replicas, set["region"]), *restore, message)
if err != nil {
log.Fatalf("instances create: %v", err)
}
- fmt.Fprintf(stdout, "%s %s\n", colorFor(stdout).ok("created instance"),
+ // Only the answer's own word says a restore was accepted: an older
+ // console ignores the field and made an ordinary instance.
+ accepted := "created instance"
+ if *restore && rec.Restore {
+ accepted = "restore accepted"
+ }
+ fmt.Fprintf(stdout, "%s %s\n", colorFor(stdout).ok(accepted),
instanceCreatedLine(rec, environmentSuffix(rec.Environment)))
if rec.PrivateStoreBucket != "" {
mutedf(stdout, " private storage: bucket %s\n", rec.PrivateStoreBucket)
@@ -372,6 +382,9 @@ func runInstancesCreate(args []string) {
if line := instanceRuntimeLine(rec); line != "" {
mutedf(stdout, " %s", line)
}
+ if *restore && rec.Restore {
+ mutedf(stdout, " it wakes with whatever data it kept when it was deleted\n")
+ }
mutedf(stdout, " the host comes live on the next reconcile pass on its box")
}
diff --git a/instances_restore_test.go b/instances_restore_test.go
new file mode 100644
index 000000000..e43834def
--- /dev/null
+++ b/instances_restore_test.go
@@ -0,0 +1,134 @@
+package main
+
+import (
+ "io"
+ "net/http"
+ "net/http/httptest"
+ "strings"
+ "sync"
+ "testing"
+)
+
+// restoreConsole is a console whose create door records every body it is
+// sent and answers 201 with the given JSON.
+type restoreConsole struct {
+ mu sync.Mutex
+ bodies []string
+ answer string
+}
+
+func (c *restoreConsole) serve(t *testing.T) *httptest.Server {
+ t.Helper()
+ ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ b, _ := io.ReadAll(r.Body)
+ c.mu.Lock()
+ defer c.mu.Unlock()
+ if r.Method == http.MethodPost && r.URL.Path == "/api/cli/apps/bab/jam/instances" {
+ c.bodies = append(c.bodies, string(b))
+ w.Header().Set("Content-Type", "application/json")
+ w.WriteHeader(http.StatusCreated)
+ io.WriteString(w, c.answer)
+ return
+ }
+ c.bodies = append(c.bodies, "UNEXPECTED "+r.Method+" "+r.URL.Path)
+ http.NotFound(w, r)
+ }))
+ t.Cleanup(ts.Close)
+ return ts
+}
+
+func runInstancesCreateBin(t *testing.T, ts *httptest.Server, args ...string) (string, error) {
+ t.Helper()
+ bin := buildCarlos(t)
+ full := append([]string{"instances", "create", "--app", "jam", "--account", "bab", "--host", "acme.jam.bab.oncarlos.com"}, args...)
+ return runCarlosEnv(t, bin, full, "CARLOS_SERVICE_TOKEN=tok", "CARLOS_CONSOLE="+ts.URL)
+}
+
+const restoreAnswerOn = `{"host":"acme.jam.bab.oncarlos.com","slug":"acme","pool":"p","region":"ie","channel":"stable","restore":true}`
+const restoreAnswerOff = `{"host":"acme.jam.bab.oncarlos.com","slug":"acme","pool":"p","region":"ie","channel":"stable"}`
+
+func TestInstancesCreateRestoreSendsTheFlagOnlyWhenGiven(t *testing.T) {
+ c := &restoreConsole{answer: restoreAnswerOn}
+ ts := c.serve(t)
+ if out, err := runInstancesCreateBin(t, ts, "--restore"); err != nil {
+ t.Fatalf("create --restore: %v\n%s", err, out)
+ }
+ if len(c.bodies) != 1 || !strings.Contains(c.bodies[0], `"restore":true`) {
+ t.Fatalf("bodies = %q, want one carrying \"restore\":true", c.bodies)
+ }
+ c.bodies = nil
+ c.answer = restoreAnswerOff
+ if out, err := runInstancesCreateBin(t, ts); err != nil {
+ t.Fatalf("plain create: %v\n%s", err, out)
+ }
+ if len(c.bodies) != 1 || strings.Contains(c.bodies[0], "restore") {
+ t.Fatalf("bodies = %q, want one with no restore key", c.bodies)
+ }
+}
+
+func TestInstancesCreateRestorePrintsWhatTheAnswerSays(t *testing.T) {
+ c := &restoreConsole{answer: restoreAnswerOn}
+ ts := c.serve(t)
+ out, err := runInstancesCreateBin(t, ts, "--restore")
+ if err != nil {
+ t.Fatalf("create --restore: %v\n%s", err, out)
+ }
+ wakes := " it wakes with whatever data it kept when it was deleted"
+ live := "the host comes live on the next reconcile pass on its box"
+ if !strings.Contains(out, "restore accepted ") || strings.Contains(out, "created instance") {
+ t.Errorf("output lacks the restore line or still says created:\n%s", out)
+ }
+ i, j := strings.Index(out, wakes), strings.Index(out, live)
+ if i < 0 || j < 0 || i > j {
+ t.Errorf("want the wakes line before the reconcile line:\n%s", out)
+ }
+
+ // An older console ignores the field: the answer has no restore, and
+ // the CLI must not claim one.
+ c.answer = restoreAnswerOff
+ out, err = runInstancesCreateBin(t, ts, "--restore")
+ if err != nil {
+ t.Fatalf("create --restore, old console: %v\n%s", err, out)
+ }
+ if !strings.Contains(out, "created instance ") || strings.Contains(out, "restore accepted") || strings.Contains(out, "it wakes with") {
+ t.Errorf("an answer without restore must read as an ordinary create:\n%s", out)
+ }
+
+ c.answer = restoreAnswerOff
+ out, err = runInstancesCreateBin(t, ts)
+ if err != nil || !strings.Contains(out, "created instance ") || strings.Contains(out, "restore accepted") {
+ t.Errorf("plain create: %v\n%s", err, out)
+ }
+}
+
+func TestInstancesCreateRestoreRefusesTheOtherShapes(t *testing.T) {
+ const want = "instances create: a restore is a plain instance. Drop --from, --kind, --addr and --role."
+ for _, extra := range [][]string{
+ {"--from", "other.jam.bab.oncarlos.com"},
+ {"--kind", "service"},
+ {"--addr", "10.0.0.1:8090"},
+ {"--role", "replica"},
+ {"--from", "other.jam.bab.oncarlos.com", "--kind", "service"},
+ {"--from", "other.jam.bab.oncarlos.com", "--addr", "10.0.0.1:8090"},
+ {"--from", "other.jam.bab.oncarlos.com", "--role", "replica"},
+ } {
+ c := &restoreConsole{answer: restoreAnswerOn}
+ ts := c.serve(t)
+ out, err := runInstancesCreateBin(t, ts, append([]string{"--restore"}, extra...)...)
+ if err == nil || !strings.Contains(out, want) {
+ t.Errorf("--restore %v: err %v, output\n%s\nwant %q", extra, err, out, want)
+ }
+ if len(c.bodies) != 0 {
+ t.Errorf("--restore %v sent requests: %q", extra, c.bodies)
+ }
+ }
+}
+
+func TestInstancesCreateHelpListsRestore(t *testing.T) {
+ bin := buildCarlos(t)
+ out, _ := runCarlosEnv(t, bin, []string{"instances", "create", "-h"})
+ want := "bring back a deleted instance on this host with the data it kept: the same app's plain instance, created and deleted after restore was available"
+ if !strings.Contains(out, "-restore") || !strings.Contains(out, want) {
+ t.Errorf("instances create -h lacks the restore flag or its help:\n%s", out)
+ }
+}
diff --git a/internal/provision/testdata/plan14-root-reads-chain.tsv b/internal/provision/testdata/plan14-root-reads-chain.tsv
index d4b97253a..78806e37c 100644
--- a/internal/provision/testdata/plan14-root-reads-chain.tsv
+++ b/internal/provision/testdata/plan14-root-reads-chain.tsv
@@ -127,3 +127,4 @@ plan14-root-reads-agent-login-link.tsv e820ef22ac677cd49aa9ca3f70d6bca9dea061bce
plan14-root-reads-fix-activator-backoff-flake.tsv feba66806ddfcbdfaf369d72413bb18e75162263b6f82f117fccf1b75497986a
plan14-root-reads-region-ha-dr5.tsv f19eb78c1da1475cbf8e11a3d6c394d828aa1c8f88ae24469fe8d473581b934b
plan14-root-reads-instance-syscall-filter.tsv b970bb28c5a633d2572a1da549030e9258cfdabb6322ddffdd0ebf41b56c464c
+plan14-root-reads-instance-restore-658-cli.tsv b970bb28c5a633d2572a1da549030e9258cfdabb6322ddffdd0ebf41b56c464c
diff --git a/internal/provision/testdata/plan14-root-reads-instance-restore-658-cli.tsv b/internal/provision/testdata/plan14-root-reads-instance-restore-658-cli.tsv
new file mode 100644
index 000000000..fedd24313
--- /dev/null
+++ b/internal/provision/testdata/plan14-root-reads-instance-restore-658-cli.tsv
@@ -0,0 +1,3 @@
+# Census overlay instance-restore-658-cli, written by census-propose (#369). census-ruling-instance-restore-658-cli, approved on #280 before the merge; the approval card is docs/superpowers/notes/census-proposal-instance-restore-658-cli.md.
+# 0 body, 0 sites, 1 envelope: each changed unit re-frozen at its existing disposition with its claim appended.
+@coverage . 252bc86734e0d7f6178193e237d9e4233f71ba29484fc9d896b6817f94c69f14