carlos / platform Public

backups: name --instance when the list is refused; fix comments

Final fix wave for member backups slice 1 (#898).

- An operate credential reads the backups door but not the instance list,
  so `carlos instances backups` without --instance met the list's role
  403. instanceList now types a 403 as apiInstancesRefused (as a 404 is
  apiInstancesMissing), and the verb prints the approved line
  backups.cli.needinstance instead, asking the door nothing. The list
  route is not widened. Covered against a real console.Server.
- The line joins internal/backupswords, the copy record and the pin.
- routedecls.go and apibackups.go comments say `carlos instances backups`.
- Census: backupsShow and var routeDecls re-digested in the record-write
  inventory; root-read overlay re-proposed (envelopes . and
  internal/backupswords), claims updated. Seal unchanged.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev d28afa8fdcefb4a531db3fc8fdddec0e1508d77e parent 791acdc
11 files changed, +165 −15
  • apimode.go +10 −1
  • approved_member_backups_copy_test.go +3 −2
  • docs/superpowers/notes/census-claims-member-backups-1.txt +4 −1
  • docs/superpowers/plans/member-backups-slice1-copy.json +2 −1
  • instances_backups.go +7 −0
  • instances_backups_e2e_test.go +121 −0
  • internal/backupswords/words.go +4 −0
  • internal/console/apibackups.go +1 −1
  • internal/console/routedecls.go +3 −3
  • internal/provision/member_backups_1_census_test.go +8 −4
  • internal/provision/testdata/plan14-root-reads-member-backups-1.tsv +2 −2

Intent

Human

<task-notification> <task-id>b5dtte2yn</task-id> <tool-use-id>toolu_01KyEp76JoyX6cnZBm48zDrm</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/ab362fc0-f177-4a7f-a92e-4a29ea210aad/tasks/b5dtte2yn.output</output-file> <status>completed</status> <summary>Background command "Astra final whole-branch review of slice 1" completed (exit code 0)</summary> </task-notification>

Human

<task-notification> <task-id>a19e9c74fb235bc01</task-id> <tool-use-id>toolu_01UVq12hgFjWZqZ94vtSVxhS</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/ab362fc0-f177-4a7f-a92e-4a29ea210aad/tasks/a19e9c74fb235bc01.output</output-file> <status>completed</status> <summary>Agent "Implement slice 2a Task 9 (census)" finished</summary> <note>A task-notification fires each time this agent stops with no live background children of its own. The user can send it another message and resume it, so the same task-id may notify more than once.</note> <result>Status: DONE. Both concerns are fixed, the census is re-proposed with every unit claimed, and it still needs the reviewer's approval on #280. Commits on member-backups-2a (not pushed): - 8a79cf14: makes the ticker test deterministic. - 7eb8d64f: crashed writes are cleaned up, and the census accepts their leftovers meanwhile. - 7df59219: census re-proposed (seal a51642d7). 1. **Ticker test:** it failed 5 times in 200. The fault was in the test: the tick it sent last could still be in progress when the host was released, and could then rightly publish the new verdict. The publish loop now signals each time it has finished handling a tick (a no-op in production). The test waits for that signal before checking and before releasing the host, and the assertions are unchanged. 50 of 50 runs pass, 500 of 500 pass, and -race is clean. 2. **Crash leftovers:** - **Cleanup:** every write first removes this process's own staging directories in `&lt;data&gt;/monitor`, and the agent does the same once at start. Only the writer's exact shape, older than 10 minutes, is removed, so a write in progress in the other process is left alone. - **Census:** both census walks now accept a staging directory directly in `&lt;data&gt;/monitor` that is empty or holds one regular `data` file. Look-alikes, symlinks and stages anywhere else are still refused. - **Test:** the new test shows a fresh leftover passing the census, look-alikes refused, and the next write removing the stale leftover. Tests: safefile, boxself, hostbox, the host census and migration tests, metrics, ops and both provision census tests pass. vet and gofmt are clean, and the linux, darwin and windows builds pass. Concern: the census now covers two more root-run packages, safefile and hostbox. The new root behaviour is narrow: listing names inside a staging directory under `&lt;data&gt;/monitor` without following symlinks. The report flags it for the reviewer. Proposal: `docs/superpowers/notes/census-proposal-member-backups-2a.md` Report: /home/paulca/amadan.net/carlos/platform/.claude/worktrees/member-backups-2a/.superpowers/sdd/2026-11-11-member-backups-slice2a/task-9-report.md</result> <usage><subagent_tokens>291866</subagent_tokens><tool_uses>140</tool_uses><duration_ms>2639311</duration_ms></usage> </task-notification>

diff --git a/apimode.go b/apimode.go
index 00fa4dabf..369f17df6 100644
--- a/apimode.go
+++ b/apimode.go
@@ -3913,6 +3913,12 @@ func (s *apiSession) instanceSetRateLimit(ctx context.Context, a apiAcct, app, h
// non-empty recs slice from the same response proves it isn't really zero.
type apiInstancesMissing struct{ error }
+// apiInstancesRefused is instanceList's 403: the console won't list this
+// app's instances to this credential (a role the list route's gate does
+// not admit). Its text is the console's own; a verb that can say what to
+// do instead recognises it with errors.As.
+type apiInstancesRefused struct{ error }
+
func (s *apiSession) instanceList(ctx context.Context, a apiAcct, app, match, health string) ([]apiInstanceRecord, bool, int, error) {
tail := "/instances"
v := url.Values{}
@@ -3931,8 +3937,11 @@ func (s *apiSession) instanceList(ctx context.Context, a apiAcct, app, match, he
}
if status != http.StatusOK {
err := apiErrorFromBody(status, body)
- if status == http.StatusNotFound {
+ switch status {
+ case http.StatusNotFound:
err = &apiInstancesMissing{err}
+ case http.StatusForbidden:
+ err = &apiInstancesRefused{err}
}
return nil, false, 0, err
}
diff --git a/approved_member_backups_copy_test.go b/approved_member_backups_copy_test.go
index c56582c44..7516c6337 100644
--- a/approved_member_backups_copy_test.go
+++ b/approved_member_backups_copy_test.go
@@ -11,7 +11,8 @@ import (
// memberBackupsCopyRecordPath is the member backups slice 1 copy record
// (#898): the 33 strings Paul approved unedited in the copy review of
// 2026-11-11, for the Backups section on the instance page, its Download
-// button (slice 1b) and `carlos instances backups` (Task 5).
+// button (slice 1b) and `carlos instances backups` (Task 5), and the 34th,
+// backups.cli.needinstance, approved unedited in a later review that day.
const memberBackupsCopyRecordPath = "docs/superpowers/plans/member-backups-slice1-copy.json"
// memberBackupsCopyIDs is the record's applied inventory, pinned as a
@@ -29,7 +30,7 @@ var memberBackupsCopyIDs = []string{
"backups.why.demo", "backups.why.pooled", "backups.why.fleet",
"backups.why.otherregion", "backups.why.nothingyet",
"backups.cli.summary", "backups.cli.latest", "backups.cli.at",
- "backups.cli.heading",
+ "backups.cli.heading", "backups.cli.needinstance",
}
// memberBackupsPendingIDs are approved entries no file holds yet, each
diff --git a/docs/superpowers/notes/census-claims-member-backups-1.txt b/docs/superpowers/notes/census-claims-member-backups-1.txt
index 103d1a8d1..814101819 100644
--- a/docs/superpowers/notes/census-claims-member-backups-1.txt
+++ b/docs/superpowers/notes/census-claims-member-backups-1.txt
@@ -15,9 +15,12 @@
# internal/dbdoor/restore.go:restoreAt, recorder.LTXFiles the inline boundary and start rules replaced by historyBoundary and isHistoryStart, the same results; restoreAt is reached through Restore, RestoreTo and RestoreAsOf (the CLI's db pull and query over the console's door client, the console's seed path); the changed lines only build the BeforeHistoryError of an --at restore; no read added
#
# internal/backupswords (new package, envelope pinned):
-# internal/backupswords/words.go, display.go approved copy constants and Show, Date, AtExample: pure functions over an Input struct and a time (stdlib fmt, strings, time only); no file, env, network or registry access. Imported by the CLI command below and the console
+# internal/backupswords/words.go, display.go approved copy constants (final fix wave: one more, CLINeedInstance) and Show, Date, AtExample: pure functions over an Input struct and a time (stdlib fmt, strings, time only); no file, env, network or registry access. Imported by the CLI command below and the console
#
# . (root package, envelope re-pinned):
# cli.go:instancesCommand one more child, raw("backups", cust, runInstancesBackups); a subcommand registration for a signed-in user, no read
# instances_backups.go (new): runInstancesBackups, instancesBackups, backupsShow, printBackups, backupsJSON `carlos instances backups`: parses flags, signs in through the existing CLI session, resolves the instance (resolveDBInstance, as db pull does), GETs the console's /instances/{host}/backups door and prints the JSON or the backupswords layout; a user's CLI, never run by the agent or a root pass; no local file read beyond the CLI's existing session config
# db.go:dbFlags the --instance flag's help string moved into the constant dbInstanceUsage, shared with instances backups; same text, same flag
+# apimode.go:apiInstancesRefused (new), apiSession.instanceList (final fix wave) instanceList's non-200 error is wrapped as apiInstancesRefused on a 403, as it already was as apiInstancesMissing on a 404; the same text, the same GET, nothing more read; callers that don't look for the type see the error they saw before
+# instances_backups.go:backupsShow (final fix wave) when listing the instances is refused (apiInstancesRefused) it prints the approved backups.cli.needinstance line on stderr and exits 1 instead of the console's role refusal; no request added
+# internal/console/routedecls.go:var routeDecls, internal/console/apibackups.go (final fix wave) comment only: `carlos instances backups`, not `carlos backups`
diff --git a/docs/superpowers/plans/member-backups-slice1-copy.json b/docs/superpowers/plans/member-backups-slice1-copy.json
index 9b7180de4..5c55fb9bd 100644
--- a/docs/superpowers/plans/member-backups-slice1-copy.json
+++ b/docs/superpowers/plans/member-backups-slice1-copy.json
@@ -35,6 +35,7 @@
{"id": "backups.cli.summary", "file": "internal/console/instancecopy.go", "text": "Use the command line"},
{"id": "backups.cli.latest", "file": "internal/backupswords/words.go", "text": "The latest copy:"},
{"id": "backups.cli.at", "file": "internal/backupswords/words.go", "text": "As it was at a given time:"},
- {"id": "backups.cli.heading", "file": "instances_backups.go", "text": "Backups for {host}"}
+ {"id": "backups.cli.heading", "file": "instances_backups.go", "text": "Backups for {host}"},
+ {"id": "backups.cli.needinstance", "file": "internal/backupswords/words.go", "text": "This credential can't list the app's instances. Name one with --instance.", "note": "Approved unedited by Paul on 2026-11-11 in copy review 3wp2xlbugsnsdwbc5mur3rlo2q."}
]
}
diff --git a/instances_backups.go b/instances_backups.go
index dcfdabe15..d9e1e8c0a 100644
--- a/instances_backups.go
+++ b/instances_backups.go
@@ -86,6 +86,13 @@ func backupsShow(ctx context.Context, sess *apiSession, acct apiAcct, app, insta
return 1
}
host, err := resolveDBInstance(ctx, sess, acct, app, instance)
+ var refused *apiInstancesRefused
+ if errors.As(err, &refused) {
+ // The door admits credentials the instance list doesn't (operate):
+ // such a credential has to name the instance itself.
+ fmt.Fprintln(stderr, backupswords.CLINeedInstance)
+ return 1
+ }
if err != nil {
return fail(err)
}
diff --git a/instances_backups_e2e_test.go b/instances_backups_e2e_test.go
new file mode 100644
index 000000000..5213d7c57
--- /dev/null
+++ b/instances_backups_e2e_test.go
@@ -0,0 +1,121 @@
+// `carlos instances backups` against a REAL console.Server, through its
+// route gates: the backups door admits an operate credential, but the
+// instance list it would pick the only instance from does not.
+package main
+
+import (
+ "bytes"
+ "context"
+ "encoding/json"
+ "net/http"
+ "net/http/httptest"
+ "path/filepath"
+ "strings"
+ "testing"
+ "time"
+
+ "github.com/carlosframework/platform/internal/backupswords"
+ "github.com/carlosframework/platform/internal/console"
+ "github.com/carlosframework/platform/internal/provision"
+ "github.com/carlosframework/platform/internal/release"
+ "github.com/carlosframework/platform/internal/svcrole"
+)
+
+// An operate credential: with --instance the door answers it; without,
+// listing the instances is refused by the list route's role gate, and the
+// verb says the approved line and asks the door nothing. A deploy
+// credential, which may list, still picks the app's only instance.
+func TestInstancesBackupsOperateNeedsInstance(t *testing.T) {
+ useTempCredentials(t)
+ clearDeploymentEnv(t)
+ tmp := t.TempDir()
+ const host = "acme.go.tito.io"
+
+ relStore := release.NewDirStore(filepath.Join(tmp, "store"))
+ seed, pubB64, err := release.GenerateKey()
+ if err != nil {
+ t.Fatal(err)
+ }
+ priv, err := release.ParseSigningKey(seed, "e2e")
+ if err != nil {
+ t.Fatal(err)
+ }
+ pub, err := release.ParsePublicKey(pubB64, "e2e")
+ if err != nil {
+ t.Fatal(err)
+ }
+ cst, err := console.Open(filepath.Join(tmp, "console.db"))
+ if err != nil {
+ t.Fatal(err)
+ }
+ t.Cleanup(func() { cst.Close() })
+ var srv *console.Server
+ var paths []string
+ ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ paths = append(paths, r.URL.Path)
+ srv.ServeHTTP(w, r)
+ }))
+ t.Cleanup(ts.Close)
+ srv, err = console.NewServer(console.Config{
+ Origin: ts.URL,
+ Keymail: "http://keymail.invalid",
+ Registry: filepath.Join(tmp, "registry.db"),
+ Releases: relStore,
+ ReleasePub: pub,
+ Key: priv,
+ AppScheme: "http",
+ }, cst)
+ if err != nil {
+ t.Fatal(err)
+ }
+ const addr = "paul@keymail.dev"
+ if err := cst.AddMember(console.OpsAccountID, addr, console.RoleOwner, time.Now()); err != nil {
+ t.Fatal(err)
+ }
+ if _, err := cst.CreateAppIn(console.OpsAccountID, "titogo", addr, time.Now()); err != nil {
+ t.Fatal(err)
+ }
+ yes := true
+ rec, _ := json.Marshal(provision.Record{Host: host, App: "titogo", Account: release.OpsAccount, Hibernate: &yes})
+ if _, err := relStore.Put(context.Background(), provision.RecordKey(release.OpsAccount, "titogo", host), rec, ""); err != nil {
+ t.Fatal(err)
+ }
+ operate, err := cst.NewServicePrincipal(console.OpsAccountID, "ops-bot", "titogo", svcrole.Operate, addr, time.Now())
+ if err != nil {
+ t.Fatal(err)
+ }
+ deploy, err := cst.NewServicePrincipalScoped(console.OpsAccountID, "pipeline", "titogo", svcrole.Deploy, []string{"edge"}, nil, addr, time.Now())
+ if err != nil {
+ t.Fatal(err)
+ }
+ base := []string{"--console", ts.URL, "--account", release.OpsAccount, "--app", "titogo"}
+ door := "/api/cli/apps/" + release.OpsAccount + "/titogo/instances/" + host + "/backups"
+ run := func(token string, args ...string) (int, string, string) {
+ t.Helper()
+ t.Setenv("CARLOS_SERVICE_TOKEN", token)
+ paths = nil
+ var out, errb bytes.Buffer
+ code := instancesBackups(context.Background(), append(append([]string(nil), base...), args...), &out, &errb)
+ return code, out.String(), errb.String()
+ }
+
+ code, out, errOut := run(operate, "--instance", host)
+ if code != 0 || !strings.HasPrefix(out, "Backups for "+host+"\n") {
+ t.Fatalf("operate --instance: exit %d\n%s%s", code, out, errOut)
+ }
+
+ code, out, errOut = run(operate)
+ if code != 1 || out != "" || errOut != backupswords.CLINeedInstance+"\n" {
+ t.Fatalf("operate, no --instance: exit %d stdout %q stderr %q, want 1 and the approved line", code, out, errOut)
+ }
+ for _, p := range paths {
+ if p == door {
+ t.Fatalf("operate, no --instance: asked the door anyway: %v", paths)
+ }
+ }
+
+ code, out, errOut = run(deploy)
+ if code != 0 || !strings.HasPrefix(out, "Backups for "+host+"\n") || paths[len(paths)-1] != door {
+ t.Fatalf("deploy, no --instance: exit %d paths %v\n%s%s", code, paths, out, errOut)
+ }
+}
diff --git a/internal/backupswords/words.go b/internal/backupswords/words.go
index 69cd3b689..05c8d55b7 100644
--- a/internal/backupswords/words.go
+++ b/internal/backupswords/words.go
@@ -39,4 +39,8 @@ const (
CLILatest = "The latest copy:"
CLIAt = "As it was at a given time:"
+
+ // CLINeedInstance is `carlos instances backups` without --instance,
+ // for a credential the console won't list the app's instances to.
+ CLINeedInstance = "This credential can't list the app's instances. Name one with --instance."
)
diff --git a/internal/console/apibackups.go b/internal/console/apibackups.go
index 305e2ac42..5f7f5c6f7 100644
--- a/internal/console/apibackups.go
+++ b/internal/console/apibackups.go
@@ -1,5 +1,5 @@
// The backups door (member backups spec 2026-11-11 §1): what the console
-// knows about one instance's copy, for `carlos backups`.
+// knows about one instance's copy, for `carlos instances backups`.
package console
diff --git a/internal/console/routedecls.go b/internal/console/routedecls.go
index 46741eed1..cdbfbb33a 100644
--- a/internal/console/routedecls.go
+++ b/internal/console/routedecls.go
@@ -689,9 +689,9 @@ var routeDecls = []routeDecl{
// cannot list instances, so `carlos deploy` never reaches this with one.
{Pattern: "POST /api/cli/apps/{account}/{app}/instances/{host}/gate-pass", Kind: kindCLI, Allow: svcrole.Allow(svcrole.Instance, svcrole.Deploy), Handler: (*Server).handleAPIInstanceGatePass},
// The backups door (member backups spec 2026-11-11 §1, #898): what the
- // console knows about one instance's copy, for `carlos backups`. Read
- // only, and no data: a member, and the deploy and operate credentials a
- // pipeline or an operator holds (admin by Allow).
+ // console knows about one instance's copy, for `carlos instances
+ // backups`. Read only, and no data: a member, and the deploy and operate
+ // credentials a pipeline or an operator holds (admin by Allow).
{Pattern: "GET /api/cli/apps/{account}/{app}/instances/{host}/backups", Kind: kindCLI, Allow: svcrole.Allow(svcrole.Deploy, svcrole.Operate), Handler: (*Server).handleAPIInstanceBackups},
// The residence-move doors (issue #331): requested by the tenant's
// ROUTER with the app-held instance token (titogo's residence design —
diff --git a/internal/provision/member_backups_1_census_test.go b/internal/provision/member_backups_1_census_test.go
index cde1bf15c..443ce0221 100644
--- a/internal/provision/member_backups_1_census_test.go
+++ b/internal/provision/member_backups_1_census_test.go
@@ -21,13 +21,17 @@ package provision
// GET /api/cli/apps/{account}/{app}/instances/{host}/backups (Deploy and
// Operate allowed, handleAPIInstanceBackups, read only). A declaration,
// no record path. key-site / lit:instances,lit:sidecars, as before.
+// The final fix wave changed only its comment (`carlos instances
+// backups`, not `carlos backups`).
//
// New unit:
// - backupsShow (instances_backups.go, Task 5): the CLI side of
// `carlos instances backups`; resolves the instance (resolveDBInstance)
// and GETs the console's "/instances/{host}/backups" door, then prints
-// or passes the JSON through. The literal is a console API path, not a
-// record key; it writes nothing. key-site / lit:instances, as the other
+// or passes the JSON through. When the console refuses to list the
+// instances (403, typed apiInstancesRefused) it prints the approved
+// backups.cli.needinstance line instead. The literal is a console API
+// path, not a record key; it writes nothing. key-site / lit:instances, as the other
// CLI instance verbs (apiSession.instanceGatePass, runInstances).
func memberBackups1WriteCensusInventory() []censusEntry {
entries := append([]censusEntry(nil), linkedDeploymentsSlice1WriteCensusInventory()...)
@@ -35,7 +39,7 @@ func memberBackups1WriteCensusInventory() []censusEntry {
{"cli.go", "instancesCommand", "key-site", "lit:instances", "853d812fe20ca0549e84f11ea2e4e48f11c44fc0eee58e83bae185c3efa8649f"},
{"internal/console/instancepage.go", "Server.handleAppInstance", "key-site", "lit:instances", "aee1f045b7b79923b409d05f0372a3fb70e7b14268e710edf7894dab9d9df40e"},
{"internal/console/linkedpolicy.go", "var linkedPolicies", "key-site", "lit:instances,lit:sidecars", "e2d2ea5dc6e800302890d1870bfdabd3841b0b2ef4391da0c91bb46a44d8037d"},
- {"internal/console/routedecls.go", "var routeDecls", "key-site", "lit:instances,lit:sidecars", "1623af4688d9888e1bb0045908d039f6ce49b35d7064d9fab72150e307ef3e47"},
+ {"internal/console/routedecls.go", "var routeDecls", "key-site", "lit:instances,lit:sidecars", "a28cf9a5d207e88f985a1f32ae8c44e268de3f96ec574c6df5bad73b501b06b4"},
}
for _, r := range repins {
found := false
@@ -51,5 +55,5 @@ func memberBackups1WriteCensusInventory() []censusEntry {
panic("member-backups-1 census: re-pin of an unlisted unit " + r.File + ":" + r.Unit)
}
}
- return append(entries, censusEntry{"instances_backups.go", "backupsShow", "key-site", "lit:instances", "518a32e4eb95c5b6067a9d6ef3175ab4ee00a1c56bf67a25a80356d123566d30"})
+ return append(entries, censusEntry{"instances_backups.go", "backupsShow", "key-site", "lit:instances", "14241237b853826b92f9a87cea3b195d6da690e88948769251d0e6cd8fcf3784"})
}
diff --git a/internal/provision/testdata/plan14-root-reads-member-backups-1.tsv b/internal/provision/testdata/plan14-root-reads-member-backups-1.tsv
index 5d53bf5cf..309c93371 100644
--- a/internal/provision/testdata/plan14-root-reads-member-backups-1.tsv
+++ b/internal/provision/testdata/plan14-root-reads-member-backups-1.tsv
@@ -1,5 +1,5 @@
# Census overlay member-backups-1, written by census-propose (#369). census-ruling-member-backups-1, approved on #280 before the merge; the approval card is docs/superpowers/notes/census-proposal-member-backups-1.md.
# 0 body, 0 sites, 3 envelope: each changed unit re-frozen at its existing disposition with its claim appended.
-@coverage . 12be7c42194ccb37819376f6827959aebfbecd4f96cd9a1740c74623942097e5
-@coverage internal/backupswords b2e10a74facfd0f6841e9220748a7e35dacacb8f30bb8590e3834fd574c87e2f
+@coverage . bcd382ba3d90f69d44510c36b7699ccd9ff4da71764671bd1394feabc36faee6
+@coverage internal/backupswords a3fb7ae1f63a94f443a8788dc193b8efedf69fd29dbc895c3e596e48a78da22d
@coverage internal/dbdoor a8b3e7af6fb851ad71e678252a55f9f05444135c6bff93ef59ea5733ef94593d