oficina / equipo Public

CONN1-PROGRESS and the slice 1 staging witness scenario

conn1_witness (staging only, EQUIPO_STAGING_CONN_WITNESS): the person's
messages, each answered by whichever connection the runner chooses,
recorded with the connection, attempt and switched line.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev 518646994117279508bc84698baf27e20811d17e parent 9595590
3 files changed, +307 −0
  • docs/superpowers/plans/CONN1-PROGRESS.md +252 −0
  • internal/headless/connections_test.go +54 −0
  • internal/headless/scenarios_test.go +1 −0
diff --git a/docs/superpowers/plans/CONN1-PROGRESS.md b/docs/superpowers/plans/CONN1-PROGRESS.md
new file mode 100644
index 00000000..dc383546
--- /dev/null
+++ b/docs/superpowers/plans/CONN1-PROGRESS.md
@@ -0,0 +1,252 @@
+# Connections slice 1 progress: several accounts, Codex, in-app sign-in
+
+Branch `thin-v1-conn1` from `thin-v1-slice4c` (2d1edaf), with
+`design-connections` merged (28f8455, then the revised spec eaf2f38) and
+the slice 4c fixes (aaf04aa). Spec:
+`docs/superpowers/specs/2026-11-08-equipo-connections.md` rev 2b, §8
+slice 1 (gates 1a to 1d), with Astra's round-1 findings
+(`~/.cache/tmp/equipo/connrev-final.md`) and Paul's rulings: Claude on
+a remote runner finishes signing in on the runner (no paste through
+Equipo, no token importer); Pi with OpenCode in reserve is a later
+slice. Conventions as in `SLICE1-PROGRESS.md` to `SLICE4C-PROGRESS.md`.
+
+## Done
+
+1. Contracts (`internal/wire/connections.go`, `frames.go`, fixtures):
+ `Connection`, `ConnectionList`, `Connect`; frames `connect`,
+ `cancel_connect`, `disconnect` (instance to runner, durable),
+ `connection` and `usage` (runner to instance, durable);
+ `hello.connections` and `sync.connections` replace `accounts`;
+ `Reply.usage`, `StepReport.usage`, `AnswerReport.usage` are usage
+ rows; `Reply.switched`, `Step.switched`, `Message.switched`,
+ `Turn.connection`, `Snapshot.connections`; turn state `waiting`
+ (nonterminal; `wire.InFlight`); reasons `no_connection`, `limited`,
+ `connection_removed`; `ToolResult.replayed`; `wire.WriteTools`.
+ Guard: no connection type, frame or fixture has a secret-shaped field
+ (`TestConnectionTypesCarryNoSecrets`, `...FixturesCarryNoSecrets`).
+
+2. Gate 1a, usage (`internal/runner/connect/usage.go`): one row per
+ attempt and model with outcome (`replied | failed | cancelled |
+ superseded`), `complete`, and nullable figures. Claude: the result's
+ `modelUsage` per model (reasoning null). Codex: `CodexTally` takes the
+ attempt's last `total` less the total seen before it began (the first
+ total after `thread/resume` is the baseline), drops other threads'
+ notices, so several notices and a resent one count once. Rows of
+ attempts that did not reply go in a `usage` frame. The instance keys
+ rows `(turn, step, attempt, connection, model)` (`chat_usage`,
+ migration 0049), so a resent frame is a no-op; raw rows kept 90 days.
+ `fakecodex` (`internal/fakecodex`) reproduces the pinned app-server:
+ initialize, account/read (refresh, revoked), config/read echoing the
+ `-c` session flags, device-code sign-in, rate limits with and without
+ windows, thread start and resume with a rollout, turns with deltas,
+ items, several cumulative usage notices and the resume replay, MCP
+ approvals by elicitation, `usageLimitExceeded`, interrupt.
+
+3. Gate 1b, protocol and auth. Connections from the app
+ (`internal/runner/thin/connector.go`, `connect/login.go`):
+ - Codex by device code: the pinned app-server in a new dedicated home
+ asks for a code (`account/login/start {chatgptDeviceCode}`); the card
+ shows OpenAI's page and code; `account/login/completed` then
+ `account/read` and `account/rateLimits/read`; healthy with email,
+ plan and windows. Refused (device login not enabled):
+ `provider_refused`. The same account twice: `already_connected`.
+ - Claude at the runner's machine (`same_machine`): the unmodified
+ `claude auth login --claudeai` on a pty, with BROWSER set to a
+ recorder in scratch, so the runner learns the loopback authorize URL
+ the CLI would open (checked: Anthropic's host, redirect to
+ localhost); the person's browser on that machine finishes it; nothing
+ is written to the CLI. Verified against the real 2.1.312 binary
+ that BROWSER receives the loopback URL (`redirect_uri=http://
+ localhost:<port>/callback`), while the printed URL is the paste flow.
+ - Claude elsewhere: the "Finish signing in on <runner>" card with
+ `equipo-runner login claude` and "I am at this machine"; the runner
+ watches the bindings and turns the card healthy when the terminal
+ login finishes.
+ - Cancel: recorded before the attempt saves, so it wins; a cancel that
+ arrives after a success signs that connection out on the runner.
+ - Sign out: `DELETE /api/v1/connections/{id}`, durable `disconnect`,
+ the provider's own logout, binding dropped
+ (`setup.RemoveAccountBinding`), home deleted, `signed_out` reported.
+ - Health: `Conns` (`thin/conns.go`) keeps state per connection in
+ thin.db: refreshed on first use and hourly with the CLI under the
+ source lock (Claude and Codex: thin v1's Codex refresh debt), limits
+ the providers reported, cool-off 15 min doubling to an hour when no
+ reset is reported. Only `healthy` connections are chosen.
+ - Failure kinds: Claude `rate_limit_event {rejected}` is quota (reset
+ only when reported), `api_retry {error: rate_limit}` running out is
+ quota without a reset, an assistant error `authentication_failed`,
+ `oauth_org_not_allowed`, `account_on_hold` or `billing_error` is auth
+ (sign_in_again, never limited); Codex `usageLimitExceeded` is quota,
+ `unauthorized` auth, anything else transient (no move).
+ - Instance (`chat/connections.go`): records from hello and sync (only
+ the runner's own person's), attempts, the API (`GET/POST
+ /api/v1/connections`, `GET /connections/{id}`, `POST
+ /connections/{id}/cancel`, `DELETE /connections/{id}`), events,
+ attempts expiring after 15 minutes with no progress.
+
+4. Gate 1c, failover and continuity:
+ - `connect.Choose` is the one choice: capable, healthy (or limited
+ with its reset passed), not avoided; the current binding kept while
+ eligible (across a restart too: the connection that answered last);
+ else the most reported headroom, unknown after any figure; reasons
+ `only_option | headroom | failover`. It replaces `pickReviewer` and
+ the coordinator's first-binding choice.
+ - Coordinator (`thin/failover.go`): a quota or auth failure, then the
+ old attempt's exit proven by the containment, then durably in one
+ transaction: the attempt's usage, `turn{waiting, limited |
+ sign_in_again}`, the run's attempt advanced and `turn{running, n+1}`;
+ the new session on the next connection is fresh (notebook, house
+ rule, tail) and told what the turn already did. No eligible
+ connection: `turn{waiting, no_connection}`, the card, and the turn
+ goes on its own when one returns. A reply from another connection
+ than the last carries the switched line. Returning to a connection
+ starts afresh rather than resuming a session that missed turns.
+ - Exactly-once writes: every write tool is recorded in thin.db before
+ and after it runs (`thin/effects.go`); a later attempt's repeat is
+ answered from the record, and a write whose answer the runner never
+ saw is reconciled under its earlier call id, which the instance
+ replays. Behind that, the instance answers a write an earlier attempt
+ of the turn made (same tool, canonical arguments) with its stored
+ result, `replayed: true`.
+ - Engineering and Review: a quota or auth failure, termination proof,
+ then the attempt runs again on another connection from a fresh tree
+ (Engineering) or the same tree (Review); the step shows "Engineering,
+ attempt 1: done (Claude was limited)". No eligible connection: the
+ step waits deferred in the queue and goes on when one returns.
+ - Ask stays pinned to the step's own kept session and connection; a
+ limited or signed-out connection fails it `account_unavailable`.
+ - Codex coordinator (`thin/codex.go`): the pinned 0.165.0 app-server in
+ the converse containment (bubblewrap, egress relay to the provider,
+ credential home denied to tools, runtime copy), validated as the
+ certified launcher does (`codex.ValidateThinPolicy`, initialize at
+ /home/runner, account, config/read against the policy, thread
+ policy), tools through the MCP proxy after an elicitation approval
+ correlated with the started tool call (anything else refused),
+ rollout kept for resume. `codex.PolicyInputs` now renders `converse`
+ (the coordinator surface: no shell, no patch, no search, MCP limited
+ to the conversation's own tools) and `answer` (read-only git tools);
+ `inspect` already passed; the deny profile is unchanged
+ (`TestThinActionPolicies`).
+
+5. Gate 1d, UI: the Connections page under the conversation (header
+ plug icon, and linked from Settings): each connection with its state
+ in words ("Limited until Tue 10:00 UTC", "Limited, no reset time
+ reported", "Needs signing in again", "Signed out"), Add Codex, Add
+ Claude, the device-code card, the sign-in link, the finish-on-runner
+ card, Cancel; scriptless (the page reloads every 3 s while connecting).
+ The chat: the switched line under a reply, the no_connection card with
+ Add a connection, no "Send your message again". Reset times are shown
+ in UTC until a person's zone is known.
+
+## Tests
+
+- Unit: `connect` (choice table, cool-off, Claude and Codex limits,
+ failure classes, usage over the recorded probe and the resume case,
+ Claude rows); `codex` thin policies; wire guards.
+- Contract (`internal/thintest/connections_contract_test.go`): hello and
+ attempts, duplicates, late frames, cancel, sign-out, the held turn and
+ the switch, usage rows; writes replayed across attempts.
+- Headless (`TestHeadlessConnections`, fake CLIs in real bubblewrap):
+ U1/U2 usage rows (replied, failed before a failover, cancelled); C1
+ Claude to Claude failover; C2 Codex coordinator with tools, a task,
+ usage and a cold resume; C3 device code (also refused, already
+ connected) then failover to Codex; C4 Claude at the machine (loopback
+ callback) and by the terminal card; A5 cancel and sign-out; A6/A7 no
+ reset and auth; F2 a limit straight after five writes; C5 Engineering
+ and Review moving connection; C6/F5/F7 waiting, cancel while waiting,
+ answered once Codex is added.
+- Browser (`-tags browser`): A1, A4, F1, F7.
+- Mutations, each observed failing a test: a secret-shaped field on a
+ connection frame (guard); both write guards removed (F2: two question
+ cards); the runner ledger removed (F2: record_task reached the instance
+ twice); the instance replay removed (contract: a second task); the
+ stickiness rule removed (choice table); the Codex baseline removed
+ (tally: the resumed turn counted the old total); failover without a
+ proven exit (C1: failed `limited`); the switched line dropped on settle
+ (browser F1, a real bug the test found); `enabled_tools` back to the old
+ coordinator tools (thin policy test).
+
+## Decisions
+
+- In-app sign-in runs the provider's CLI unconfined in the new home, as
+ `equipo-runner login` and the account refresh already do (not in the
+ converse namespace the spec sketches); egress for the login is the
+ CLI's own.
+- The coordinator and steps hold a turn or step on the runner rather
+ than ending it; "messages sent while it waits join the waiting turn"
+ is not built: a later message queues as its own turn behind it.
+- The runner's own durable ledger gives the new attempt its summary of
+ done effects; there is no `tool_calls{turn}` request to the instance.
+- Stickiness survives a restart through the last connection that
+ answered; returning to a connection starts a fresh session (the spec
+ says resume with a fresh notebook injection: fresh is simpler and the
+ notebook and tail carry the context).
+- Staging: in-app connections live in the staging root's own
+ `accounts/` and survive a restage (`scripts/staging-thin.py`); the
+ suite person runs on the owner's in-app Codex account the way it runs
+ on claude-a.
+
+## Staging
+
+Not restaged (the controller sequences restages). Steps once it is:
+1. Paul enables device code login for Codex in ChatGPT's security
+ settings, opens the staging Connections page, taps Add Codex, and
+ enters the code at OpenAI's page.
+2. `scripts/staging-thin.py runner` again so the suite runner gets the
+ owner's in-app Codex binding.
+3. `EQUIPO_STAGING_CONN_WITNESS` (messages separated by `---`) with
+ `scripts/staging-thin.py suite conn1_witness`: with claude-a still
+ limited the first turn meets the real limit and moves to Codex.
+
+## Live runs (budget: 6 coordinator turns, paul@tito.io homes only)
+
+Used: none.
+
+## Open issues
+
+- Version skew at deploy, as before: an old runner refuses the new
+ frames; install runners right after the instance.
+- Preferences (spec F8, "switch back to the preferred connection") are
+ slice 3; without them stickiness keeps the session where it moved.
+- A step waiting for a connection shows as queued, without the
+ no_connection reason on the task yet.
+- The ask card does not yet show the reset time of its limited
+ connection.
+- Reset times render in UTC.
+- Codex `account/updated` to signed out is not read as an auth failure
+ during a turn (the hourly refresh catches it).
+
+## Copy for review
+
+Accepted for now with the existing marker in `copy.go`:
+- `chat.connections.title` "Connections", `.empty` "Nothing is
+ connected yet.", `.add_codex` "Add Codex", `.add_claude` "Add Claude",
+ `.connecting` "Connecting %s", `.device` "Go to %s and enter %s",
+ `.sign_in_claude` "Sign in to Claude", `.finish_on` "Finish signing in
+ on %s", `.finish_how` "Claude sign-in finishes on the machine that
+ runs your runner. In a terminal there, run:", `.same_machine` "I am at
+ this machine", `.cancel` "Cancel", `.healthy` "Healthy", `.limited`
+ "Limited, no reset time reported", `.limited_until` "Limited until
+ %s", `.signed_out` "Signed out", `.sign_in_again` "Needs signing in
+ again", `.error` "Not working", `.offline` "Your runner is offline.
+ Start it to add a connection."
+- `chat.connections.reason.timed_out` "The sign-in was not finished in
+ time.", `.cancelled` "Cancelled.", `.provider_refused` "The provider
+ did not complete the sign-in.", `.runner_offline` "Your runner went
+ offline during the sign-in.", `.identity_mismatch` "The sign-in did not
+ match an account.", `.already_connected` "That account is already
+ connected."
+- `chat.switched` "Switched to %s", `chat.switched_reset` "Switched to
+ %s; %s resets %s", `chat.no_connection` "Nothing can answer right now.
+ %s", `.resets` "%s resets %s", `.limited` "%s is limited",
+ `.signed_out` "%s is signed out", `.none` "Nothing is connected.",
+ `.add` "Add a connection"
+- `work.reason.limited` "its model account reached its limit",
+ `work.reason.no_connection` "nothing connected can run it",
+ `work.switched` "%s was limited"
+- Changed: `chat.failed` "The coordinator could not answer this message."
+ (was "... Send your message again to retry.")
+
+## Blockers
+
+None.
diff --git a/internal/headless/connections_test.go b/internal/headless/connections_test.go
index 95a3ec2f..70ff79b7 100644
--- a/internal/headless/connections_test.go
+++ b/internal/headless/connections_test.go
@@ -643,3 +643,57 @@ func connQuotaAfterWrites(t *testing.T, env *Env, inst *thintest.Instance, r *lo
t.Fatalf("record_task reached the instance %d times", effects)
}
}
+
+// scenarioConnWitness is Connections slice 1's live witness (staging
+// only): the person's messages in EQUIPO_STAGING_CONN_WITNESS, separated
+// by a line "---", each answered by whichever connection the runner
+// chooses. It records, per turn, the connection that answered, the
+// attempt, the switched line and the time to the reply.
+func scenarioConnWitness(t *testing.T, env *Env) {
+ text := os.Getenv("EQUIPO_STAGING_CONN_WITNESS")
+ if !env.Live || text == "" {
+ t.Skip("staging only, with EQUIPO_STAGING_CONN_WITNESS")
+ }
+ s := open(t, env)
+ s.keep()
+ s.wait(t, "runner online", time.Minute, func(c *thintest.Conversation) bool { return c.Runner.Online })
+ conns, err := env.Client.Connections(s.ctx)
+ if err != nil {
+ t.Fatal(err)
+ }
+ var held []map[string]any
+ for _, c := range conns.Items {
+ h := map[string]any{"local_id": c.LocalID, "provider": c.Provider, "state": c.State, "plan": c.Plan}
+ if c.Headroom != nil {
+ h["resets_at"], h["utilization"] = c.Headroom.ResetsAt, c.Headroom.Utilization
+ }
+ held = append(held, h)
+ }
+ var turns []map[string]any
+ for _, msg := range strings.Split(text, "\n---\n") {
+ start := time.Now()
+ sent := s.send(t, strings.TrimSpace(msg))
+ turn := s.waitTurn(t, sent.Turn.ID, wire.TurnReplied, wire.TurnFailed, wire.TurnCancelled)
+ row := map[string]any{"turn": turn.ID, "state": turn.State, "reason": turn.Reason, "attempt": turn.Attempt, "connection": turn.Connection, "seconds": time.Since(start).Seconds()}
+ s.conv.Locked(func(c *thintest.Conversation) {
+ for _, m := range c.Replies() {
+ if m.TurnID == turn.ID {
+ row["reply"], row["switched"] = clipText(m.Text, 300), m.Switched
+ }
+ }
+ })
+ t.Logf("turn %+v", row)
+ turns = append(turns, row)
+ if turn.State != wire.TurnReplied {
+ break
+ }
+ }
+ Witness[t.Name()] = map[string]any{"connections": held, "turns": turns}
+}
+
+func clipText(s string, n int) string {
+ if len(s) <= n {
+ return s
+ }
+ return s[:n] + "…"
+}
diff --git a/internal/headless/scenarios_test.go b/internal/headless/scenarios_test.go
index 6779a3d1..f0adff21 100644
--- a/internal/headless/scenarios_test.go
+++ b/internal/headless/scenarios_test.go
@@ -462,6 +462,7 @@ var scenarios = []struct {
{"4c_rebase", scenarioRebase},
{"4c_duplicate", scenarioDuplicate},
{"4c_witness", scenarioMergeWitness},
+ {"conn1_witness", scenarioConnWitness},
}
// TestHeadless runs every scenario against a fresh local instance and