carlos / platform Public

cli: label reads flags after the host; a gateway status is C38

Round 1 of review on carlos instances label:
- flags are read on both sides of the positional host, so the order C01
  shows and C14 prints works (--app shop shop.example.com --box box-1);
- on a write, a 502 or 504 decides before a body-read error, so a cut-off
  gateway answer is C38, not the transport error;
- the --account-id help drops the capitals and the em dash.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 083e964381cabc8b089b18f50e8670c4d47fbd98 parent 7ad7675
2 files changed, +102 −16
  • instances_cli.go +30 −11
  • instances_cli_label_test.go +72 −5

CI failed — run details

Intent

Human

<task-notification> <task-id>ab2cf8140995c083d</task-id> <tool-use-id>toolu_01DrmCTyed78zgxjad6W6Cna</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/ac77363b-5830-422c-9f38-d7f2540dd398/tasks/ab2cf8140995c083d.output</output-file> <status>completed</status> <summary>Agent "Implement Task 5: carlos instances label" 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. The door now sends the coordinator and floor-box fields, and the CLI fills C24 and C29 from them. - **Commits:** - `b39eecf5 cli: carlos instances label` - `7ad76752 console, cli: label answer names the coordinator and the floor box` - **Tests:** CLI RED (`coordinated` and both floor cases failed), then GREEN. All passed: the brief's Step 4 command, `go test ./internal/parity`, the console `TestLabelDoor|...` run, and the darwin and windows builds. The door assertions went in with the fields, so they have no separate RED run. - **Concerns:** - When nothing is below the floor at the time the door looks (the view changed between reads), `floor_box` comes back empty. I don't think that happens in practice. - "the console" in C29 is a new phrase and needs to go in the copy deck. - UX items for T7: - C14's suggested command leaves out `--console` and `--account`. - The `no_evidence` refusal repeats a line already printed above it. - The refusal line carries the log timestamp, as every verb's does. - **Report:** /home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-fleet-record-labels/.superpowers/sdd/2026-11-14-fleet-record-labels/task-5-report.md (fix report appended)</result> <usage><subagent_tokens>173710</subagent_tokens><tool_uses>68</tool_uses><duration_ms>874494</duration_ms></usage> </task-notification>

Attributed to this commit: 16.8 g CO₂e (2,059,855 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on fleet-record-labels-m2, never backward from it. A turn that produced more than one commit books all of its tokens to the last one, and a concurrent session on this branch can add to the same figure. Some of it was priced using the shared default rate, because no model-specific factor row exists yet for at least one model involved. The Carbon view has the repo total, which is never derived from this attribution.

diff --git a/instances_cli.go b/instances_cli.go
index 741c573b9..15df87cca 100644
--- a/instances_cli.go
+++ b/instances_cli.go
@@ -1368,12 +1368,14 @@ func (s *apiSession) instanceLabel(ctx context.Context, acct apiAcct, app, host,
}{box, !write}
status, body, err := clone.postJSON(ctx, apiPath(acct, app, "/instances/"+url.PathEscape(host)+"/label"), in)
switch {
+ // A gateway status decides before any body-read error: its body may
+ // be cut off, and the write may have landed either way.
+ case write && (status == http.StatusBadGateway || status == http.StatusGatewayTimeout):
+ return nil, errLabelOutcomeUnknown
case err != nil && write && (status == http.StatusOK || status == 0 && !labelNotSent(err)):
return nil, errLabelOutcomeUnknown
case err != nil:
return nil, err
- case write && (status == http.StatusBadGateway || status == http.StatusGatewayTimeout):
- return nil, errLabelOutcomeUnknown
case status != http.StatusOK:
return nil, apiErrorFromBody(status, body)
}
@@ -1541,23 +1543,21 @@ func labelRefusal(host string, a *instanceLabelAnswer) string {
}
// runInstancesLabel is `carlos instances label <host>` (fleet record labels
-// spec §5). The host may come first or after the flags. Without --box it
-// is a dry run.
+// spec §5). The host may come before, between or after the flags, as C01
+// and C14 write it. Without --box it is a dry run.
func runInstancesLabel(args []string) {
- host, args := leadingArg(args)
fs := flag.NewFlagSet("instances label", flag.ExitOnError)
app := appFlag(fs, "app the instance belongs to")
box := fs.String("box", "", instancesLabelFlagBox)
dryRun := fs.Bool("dry-run", false, instancesLabelFlagDry)
consoleFlag := consoleOption(fs, "console to act through (default: the only logged-in one)")
acctRaw := fs.String("account", "", "account (sqid or name) the app belongs to (default: your only account, or the configured/chosen one)")
- acctIDRaw := fs.String("account-id", "", "account sqid, matched as a sqid ONLY — supersedes --account")
+ acctIDRaw := fs.String("account-id", "", "account sqid, matched as a sqid only. it supersedes --account")
fs.Usage = flagUsage(fs, instancesRecordsUsage)
- fs.Parse(args)
- if host == "" && fs.NArg() == 1 {
- host = strings.TrimSpace(fs.Arg(0))
- } else if fs.NArg() != 0 {
- host = ""
+ words := interleavedArgs(fs, args)
+ host := ""
+ if len(words) == 1 {
+ host = strings.TrimSpace(words[0])
}
if host == "" {
log.Fatalf("%s\nusage: %s", instancesLabelOneHost, instancesLabelUsageLine)
@@ -1571,3 +1571,22 @@ func runInstancesLabel(args []string) {
log.Fatal(err)
}
}
+
+// interleavedArgs parses fs over args, reading flags on both sides of each
+// positional word, and returns the positional words in order. After "--"
+// every word is positional.
+func interleavedArgs(fs *flag.FlagSet, args []string) []string {
+ var words []string
+ for {
+ fs.Parse(args)
+ rest := fs.Args()
+ if len(rest) == 0 {
+ return words
+ }
+ if consumed := len(args) - len(rest); consumed > 0 && args[consumed-1] == "--" {
+ return append(words, rest...)
+ }
+ words = append(words, rest[0])
+ args = rest[1:]
+ }
+}
diff --git a/instances_cli_label_test.go b/instances_cli_label_test.go
index 1ce666797..85d5ddfba 100644
--- a/instances_cli_label_test.go
+++ b/instances_cli_label_test.go
@@ -12,6 +12,7 @@ import (
"context"
"encoding/json"
"errors"
+ "fmt"
"io"
"net/http"
"net/http/httptest"
@@ -361,15 +362,80 @@ func TestInstancesLabelUnknownOutcome(t *testing.T) {
}
})
- t.Run("the door's 502", func(t *testing.T) {
- stub := newLabelStub(t, http.StatusBadGateway, `{"error":"`+labelC38+`"}`)
- out, ok := runLabelCLI(t, stub.ts.URL, "--app", "shop", "--account", "bab", "--box", "box-1", "shop.example.com")
- if ok || !strings.Contains(out, labelC38) {
- t.Fatalf("want C38 and a non-zero exit, got ok=%v:\n%s", ok, out)
+ // A gateway answer is classified by the CLI, not passed through: the
+ // stub's body says nothing of C38.
+ for _, code := range []int{http.StatusBadGateway, http.StatusGatewayTimeout} {
+ t.Run(fmt.Sprintf("a %d", code), func(t *testing.T) {
+ stub := newLabelStub(t, code, `{"error":"upstream went away"}`)
+ out, ok := runLabelCLI(t, stub.ts.URL, "--app", "shop", "--account", "bab", "--box", "box-1", "shop.example.com")
+ if ok || !strings.Contains(out, labelC38) || strings.Contains(out, "upstream went away") {
+ t.Fatalf("want C38 and a non-zero exit, got ok=%v:\n%s", ok, out)
+ }
+ })
+
+ // The status line arrives, then the body is cut off: the status
+ // still decides, so C38 rather than the read error.
+ t.Run(fmt.Sprintf("a %d with its body cut off", code), func(t *testing.T) {
+ sent := make(chan struct{}, 1)
+ ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ io.Copy(io.Discard, r.Body)
+ w.Header().Set("Content-Type", "application/json")
+ w.Header().Set("Content-Length", "100")
+ w.WriteHeader(code)
+ io.WriteString(w, `{"error":"upstr`)
+ w.(http.Flusher).Flush()
+ sent <- struct{}{}
+ <-r.Context().Done()
+ }))
+ t.Cleanup(ts.Close)
+ go func() {
+ <-sent
+ ts.CloseClientConnections()
+ }()
+ out, ok := runLabelCLI(t, ts.URL, "--app", "shop", "--account", "bab", "--box", "box-1", "shop.example.com")
+ if ok || !strings.Contains(out, labelC38) {
+ t.Fatalf("want C38 and a non-zero exit, got ok=%v:\n%s", ok, out)
+ }
+ })
+ }
+
+ t.Run("a dry run's 502 is the console's own text", func(t *testing.T) {
+ stub := newLabelStub(t, http.StatusBadGateway, `{"error":"could not read the instance and its fleet, so it was not tied. try again"}`)
+ out, ok := runLabelCLI(t, stub.ts.URL, "--app", "shop", "--account", "bab", "shop.example.com")
+ if ok || strings.Contains(out, labelC38) || !strings.Contains(out, "could not read the instance") {
+ t.Fatalf("want the console's text and a non-zero exit, got ok=%v:\n%s", ok, out)
}
})
}
+// The host may sit between flags, in the order C01 shows and C14 prints:
+// flags after it are still read.
+func TestInstancesLabelFlagsAfterTheHost(t *testing.T) {
+ for _, tc := range []struct {
+ args []string
+ answer map[string]any
+ dryRun bool
+ want string
+ }{
+ {[]string{"--app", "shop", "--account", "bab", "shop.example.com", "--box", "box-1"},
+ map[string]any{"applied": true, "label": "box-1"}, false, labelC17},
+ {[]string{"--app", "shop", "--account", "bab", "shop.example.com", "--box", "box-1", "--dry-run"},
+ nil, true, labelC16},
+ {[]string{"--app", "shop", "shop.example.com", "--dry-run", "--box", "box-1", "--account", "bab"},
+ nil, true, labelC16},
+ } {
+ stub := newLabelStub(t, http.StatusOK, labelAnswerJSON(t, tc.answer))
+ out, ok := runLabelCLI(t, stub.ts.URL, tc.args...)
+ if !ok || !strings.Contains(out, tc.want) {
+ t.Fatalf("%q: want %q and exit 0, got ok=%v:\n%s", tc.args, tc.want, ok, out)
+ }
+ path, body, _ := stub.last()
+ if path != "/api/cli/apps/bab/shop/instances/shop.example.com/label" || body["box"] != "box-1" || body["dry_run"] != tc.dryRun {
+ t.Fatalf("%q: request %s %v", tc.args, path, body)
+ }
+ }
+}
+
// The host is trimmed and lowercased before it reaches the path (plan
// review focus), as instances retry does.
func TestInstancesLabelNormalisesTheHost(t *testing.T) {
@@ -396,6 +462,7 @@ func TestInstancesLabelArgErrors(t *testing.T) {
{"--app", "shop", "--account", "bab", "shop.example.com", "other.example.com"},
{"shop.example.com", "--app", "shop", "--account", "bab", "other.example.com"},
{" ", "--app", "shop", "--account", "bab"},
+ {"--app", "shop", "shop.example.com", "--box", "box-1", "other.example.com"},
} {
out, ok := runLabelCLI(t, stub.ts.URL, args...)
if ok || !strings.Contains(out, "name one instance host") {