specs: connections rev 2a, slice 1 after Astra round 1
Slice 1 first, for the builder on thin-v1-conn1. Coordinator failover now runs in order: termination proof, a nonterminal waiting turn state, durable attempt advancement, reconciliation of recorded tool effects (replayed results by turn, name and canonical args), then the new session. Failure kinds quota, auth and transient are separated; Claude and Codex fields treated as optional, no window inferred; Codex failure is turn/completed with status failed. Telemetry is harness-side only; the CONNECT relay reads no headers. The setup-token importer is removed. Usage recording aggregates Codex notices per attempt with a resume baseline, records failed and cancelled attempts, nullable fields, completeness, price version and overage. Slice 1 is split into gates 1a to 1d with the crash, ack-loss, cancel, stale-report, post-tool-quota, unavailable-account and pinned-ask scenarios.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
1 file changed,
+220
−133
docs/superpowers/specs/2026-11-08-equipo-connections.md+220 −133
CI cancelled — superseded by a newer push — run details
diff --git a/docs/superpowers/specs/2026-11-08-equipo-connections.md b/docs/superpowers/specs/2026-11-08-equipo-connections.md| index d18e5ef3..6fa971f6 100644 |
| --- a/docs/superpowers/specs/2026-11-08-equipo-connections.md |
| +++ b/docs/superpowers/specs/2026-11-08-equipo-connections.md |
| @@ -92,10 +92,11 @@ it is for API-key connections only). |
| resetsAt, utilization}` (the Agent SDK's `SDKRateLimitEvent`), derived |
| from the `anthropic-ratelimit-unified-*` response headers; retries show |
| as `system/api_retry` with `error: "rate_limit"` and `retry_delay_ms`. |
| -`utilization` is a single number; per-window (five-hour versus weekly) |
| -figures are requested in issues #50518 and #91857 but not documented, so |
| -Equipo shows the one figure the CLI gives and names the window only when |
| -the reset time makes it obvious. Each `result` message carries `usage` |
| +Both `resetsAt` and `utilization` are optional, and `utilization` is a |
| +single number; per-window (five-hour versus weekly) figures are |
| +requested in issues #50518 and #91857 but not documented, so Equipo |
| +shows the one figure the CLI gives, never names a window, and copes with |
| +either field missing. Each `result` message carries `usage` |
| (`input_tokens`, `output_tokens`, `cache_creation_input_tokens`, |
| `cache_read_input_tokens`), `modelUsage` per model (`inputTokens`, |
| `outputTokens`, `cacheReadInputTokens`, `cacheCreationInputTokens`, |
| @@ -136,7 +137,11 @@ a route for Equipo. |
| **Headless and tools.** The path thin v1 §3 already designed: |
| `initialize`, `thread/start` or `thread/resume`, `turn/start`, |
| `item/agentMessage/delta`, the four approval requests answered deny or |
| -relayed as `ask_person`, `turn/interrupt`. Codex remains an MCP client |
| +relayed as `ask_person`, `turn/interrupt`; a turn ends on |
| +`turn/completed` whose `status` is `completed`, `failed` or |
| +`interrupted` (there is no separate `turn/failed`; the decoder in |
| +`provider/codex/events.go` already switches on these). Codex remains an |
| +MCP client |
| (`codex mcp`; `codex mcp-server` was removed in favour of the app-server, |
| which is not an MCP server). Custom providers in `config.toml` take |
| `base_url`, `env_key`, `http_headers` and `wire_api`, and **`responses` |
| @@ -471,19 +476,18 @@ person's browser is relative to the runner: |
| or in a terminal there run `equipo-runner login claude` and paste |
| the code where the CLI asks. The paste goes into the CLI, on the |
| runner, never into Equipo. |
| -3. **Last resort, `setup-token`.** A person who runs |
| - `claude setup-token` on any machine gets a one-year token. Equipo |
| - does not accept it in the app (holding it on the instance even in |
| - transit is storing a session token). The runner's terminal command |
| - `equipo-runner login claude --token` can read it from the terminal |
| - into the account's home as `CLAUDE_CODE_OAUTH_TOKEN` for that home's |
| - launches; it is marked `kind: subscription, method: token`, shown |
| - with its expiry, and excluded from `--bare` launches. Documented, |
| - not promoted. |
| +3. **No token importer.** `claude setup-token` prints a one-year token; |
| + a person could type it into a terminal on the runner, but Equipo's |
| + command reading it would be Equipo handling a subscription token, |
| + which is the intermediation the terms forbid. There is no `--token` |
| + path. Claude is signed in only directly to the unmodified binary: |
| + loopback on the runner's machine, or finish signing in on the |
| + runner. A Claude **API key** connection (§2.4) is the way to use |
| + Claude without a browser on that machine. |
| **Adding a second Claude account in the app** is therefore: tap Add, |
| choose Claude, and either finish on the runner's machine (no paste) or |
| -be told plainly that this one needs a terminal there. On Linux every |
| +be told plainly to finish signing in on the runner. On Linux every |
| Claude account gets its own home and the copy cycle of thin v1 §2 |
| applies unchanged; the Mac's Keychain question (Mac spec §3.4, probe P3) |
| decides whether a Mac runner can hold more than one Claude account. |
| @@ -536,7 +540,7 @@ sources in §1: |
| | Codex (API key) | Sealed key | No | n/a | Runner home | |
| | Claude (subscription), browser on runner's machine | CLI's own loopback OAuth, app shows the link | No | Runner, by the CLI | Runner home (`.credentials.json`, or Keychain on a Mac) | |
| | Claude (subscription), runner remote | Terminal at the runner: `equipo-runner login claude` | Yes, into the CLI, never into Equipo | Runner, by the CLI | Runner home | |
| -| Claude (`setup-token`) | Terminal at the runner, `--token` | Yes, into the terminal | n/a | Runner home, one year | |
| +| Claude (`setup-token`) | Not offered: Equipo would be handling the token | n/a | n/a | n/a | |
| | Claude (API key) | Sealed key | No | n/a | Runner home | |
| | OpenRouter | PKCE: app opens `openrouter.ai/auth?callback_url=…&code_challenge=…`; the callback lands on Equipo's web app or the native app's link; the app seals `code` plus `code_verifier` to the runner, which POSTs `/api/v1/auth/keys` and keeps the returned key | No | Runner | Runner home | |
| | Local or other endpoint | Sealed key or none, test call | No | n/a | Runner home | |
| @@ -559,109 +563,169 @@ same-machine case recognisable and the remote case honest. |
| **Health** is what the runner can prove: a `healthy` connection has a |
| valid credential (the CLI refresh under the source lock for Claude, |
| -`account/read` for Codex, a `/v1/models` call for an endpoint) checked on |
| -start, hourly, and before any turn that needs a fresh copy, as today. |
| -`sign_in_again` is set when refresh fails or reports a different |
| -identity (thin v1 §2). **Limited** is new: a connection whose provider |
| -said no to the last request on quota, with `resets_at` when the provider |
| -gave one. Sources: Claude `rate_limit_event {status: rejected, |
| -resetsAt}` and `api_retry {error: rate_limit}`; Codex |
| -`account/rateLimits/updated` with a window at `usedPercent` 100 or |
| -`rateLimitReachedType` set, and `turn/failed` on quota; endpoints and |
| -OpenRouter an HTTP 429, with `Retry-After` or the provider's reset |
| -header when present and otherwise a fifteen-minute cool-off that doubles |
| -to an hour. Headroom is whatever the provider reports and nothing else: |
| -Claude's single `utilization` and `resetsAt`, Codex's two windows, an |
| -endpoint's nothing (shown as "unknown"). A connection leaves `limited` |
| -when `resets_at` passes or a probe succeeds; the runner probes with the |
| -cheapest request the harness has, never a model turn, at most once per |
| -fifteen minutes. **Sign out** is `DELETE /connections/{id}`: the runner |
| -runs the harness's own logout (`claude auth logout`, `account/logout`, |
| -or nothing for a key), deletes the home, ends sessions on that |
| -connection (their rows stay, marked `connection_removed`), and reports |
| +`account/read` for Codex, the harness's cheapest request for an |
| +endpoint) checked on start, hourly, and before any turn that needs a |
| +fresh copy, as today. `connecting` is not healthy and is never chosen. |
| +`sign_in_again` is set on an `auth` failure (§3) or when refresh reports |
| +a different identity (thin v1 §2). **Limited** is set on a `quota` |
| +failure, with `resets_at` when the provider reported one. **All |
| +telemetry comes from the harness side**: Claude's stream-json |
| +(`rate_limit_event`, `api_retry`, `result`), the Codex app-server's |
| +notifications (`account/rateLimits/updated`, `thread/tokenUsage/updated`, |
| +`turn/completed`), and in slice 2 Pi's JSONL events. The egress relay |
| +is a CONNECT tunnel (`egress/proxy.go`: one bounded CONNECT, port 443, |
| +public addresses only) and cannot see upstream headers, so no design |
| +here reads `Retry-After` or `x-ratelimit-*` off the wire; a metered |
| +endpoint's limit is whatever its harness reports, and where the harness |
| +reports nothing the connection becomes `limited` on the harness's |
| +error event with no reset time and a cool-off of fifteen minutes, |
| +doubling to an hour. Headroom is whatever the provider reports and |
| +nothing more: Claude's optional `utilization` and `resetsAt` (one |
| +figure, never labelled "weekly" or "session" because the SDK does not |
| +say which window it describes), Codex's `primary` and `secondary` |
| +windows when present, an endpoint's nothing ("unknown"). The Codex |
| +decoder today validates and discards rate notices (`rate_notice_test`); |
| +keeping them as state is slice 1 work. A connection leaves `limited` |
| +when `resets_at` passes or a probe succeeds; the probe is the harness's |
| +cheapest request, never a model turn, at most once per fifteen minutes. |
| +**Sign out** is `DELETE /connections/{id}`: the runner runs the |
| +harness's own logout (`claude auth logout`, `account/logout`, or |
| +nothing for a key), deletes the home, ends sessions on that connection |
| +(their rows stay, marked `connection_removed`), and reports |
| `signed_out`; the instance keeps the row thirty days for Usage history |
| and then deletes it. |
| + |
| ## 3. Selection and failover |
| -**The choice.** For each run the runner picks a connection from the |
| -person's own connections on the runner that holds the session or task, |
| -in this order: capable of the role (the matrix in §5); not `limited`, |
| -`sign_in_again`, `error` or `signed_out`; the role's preference if the |
| -person set one (§3, last paragraph); then the router's class (§4); then |
| -the most headroom, where a subscription's headroom is the provider's |
| -reported figure, a metered connection's is "unlimited at a price", and a |
| -local endpoint's is "unlimited and free" but slow and small. Ties go to |
| -the connection that ran this session or task last, so sessions do not |
| -hop for nothing. The function stays small and pure: inputs are the |
| -connection list, the role, the class, the preference and the current |
| -binding; the output is one connection id and a reason code. It is unit-tested with a table and it is the only place that chooses: it |
| -replaces `pickReviewer` in `internal/runner/thin/judge.go` and the |
| -coordinator's binding choice, and it returns a `runner.AccountBinding` |
| -as they do. |
| - |
| -**Coordinator failover mid-conversation.** A turn fails on quota |
| -(§2.7's signals) or on a provider error the retry policy gives up on. |
| -The runner marks the connection `limited` with `resets_at`, picks again, |
| -and if a connection remains it starts a **new session** there (thin v1 |
| -§2: a fresh process, the notebook, the house rule, the 50-message tail |
| -and a short summary of the current turn written by the runner from the |
| -tail, not by a model), replays the turn's frame, and the person sees the |
| -reply arrive with one quiet line under it: "Switched to Codex; Claude's |
| -weekly limit resets Mon 10:00" (`chat.switched`, with `resets_at` |
| -rendered in the person's zone, or "Switched to Codex" when there is no |
| -reset time). The old `sessions` row stays for resume when its |
| -connection is healthy again; whether the coordinator moves back is the |
| -same choice function at the next turn start, so a preferred connection |
| -returns on its own once it has headroom, with a line only when the |
| -switch happens. The draft deltas of the failed attempt are discarded as |
| -on cancel; the turn's `attempt` increments; the SSE client sees |
| -`turn{state: running, attempt: 2}` then deltas, never a failure. |
| - |
| -**Engineering mid-step.** A step whose harness dies on quota is a |
| -failed attempt, as any crash is today: the runner waits for the |
| -termination proof (pidfd exit of the namespace, thin v1 §4), commits |
| -nothing (the worktree is discarded; an attempt's partial work is not a |
| -candidate), picks another connection avoiding the one that failed |
| -(`avoid_account` already exists on review dispatch and becomes a list |
| -on every dispatch), and starts attempt n+1 on it with the same brief. |
| -The step row records both attempts and their connections; the task |
| -card shows "Engineering on Codex (Claude was limited)". If no |
| -connection can run Engineering the step waits in `queued` with reason |
| -`no_connection` and the task shows what to add; it resumes without a |
| -retry when a connection becomes healthy. |
| - |
| -**Review across families.** Thin v1 §3's rule stands and gets its |
| -third option: Review runs on another family if a healthy, capable |
| -connection exists (`other_family`), else another connection of the same |
| -family with fresh context (`same_family`), else a fresh session on |
| -Engineering's connection (`same_account`). The label is recorded on the |
| -step and shown, as today. With Codex and an endpoint in the mix, |
| -`other_family` becomes the common case. |
| - |
| -**Ask the implementer** stays bound to the step's own session and |
| -connection (slice 4b); if that connection is `limited` the question |
| -fails `account_unavailable` with the reset time in the card, because a |
| -different model reading the transcript is not the implementer. |
| - |
| -**"No connection can answer."** When the choice function returns |
| -nothing for the coordinator, the turn ends `failed` with the new reason |
| -`no_connection` and the chat shows a card instead of `chat.failed`: |
| -"Nothing can answer right now. Claude resets Mon 10:00; Codex is signed |
| -out." with one action, **Add a connection**, and the message stays |
| -queued to be sent when a connection returns (the person can delete it). |
| -The old line "Send your message again to retry" is removed; retrying |
| -was never the person's job. `wire.Reasons` gains `no_connection`; |
| -`Task.NeedsYou` gains `no_connection`. |
| +**The choice.** For each run the runner picks a **connection and model |
| +pair** from the person's own connections on the runner that holds the |
| +session or task. Eligible pairs are those whose matrix cell (§5) says |
| +yes for the role and whose connection is `healthy` (not `connecting`, |
| +`limited`, `sign_in_again`, `error` or `signed_out`). Among eligible |
| +pairs the order is: the current binding, if the session or step already |
| +has one and it is eligible (stickiness is a rule, not a tie-breaker: |
| +a session leaves its connection only on failure or an explicit |
| +override); then the tier floor the router set (§4); then the person's |
| +preference for the role (§3, last paragraph); then headroom, where a |
| +subscription's headroom is the provider's reported figure, a metered |
| +connection with no report is "unknown" and ranks below any connection |
| +with a reported figure, and a local endpoint is "unknown" too, chosen |
| +by tier and preference rather than by a claim of being unlimited. The |
| +function is small and pure: inputs are the connection list with their |
| +models and matrix cells, the role, the tier floor, the preference and |
| +the current binding; the output is one `(connection, model)` and a |
| +reason code. It replaces `pickReviewer` in `internal/runner/thin/judge.go` |
| +and the coordinator's binding choice, returns a `runner.AccountBinding` |
| +as they do, and is unit-tested with a table. |
| + |
| +**Failure kinds.** The runner classifies every provider failure before |
| +it decides anything: `quota` (Claude `rate_limit_event {status: |
| +rejected}` or `api_retry {error: rate_limit}` exhausting its retries; |
| +Codex `account/rateLimits/updated` with a window at `usedPercent` 100 |
| +or `rateLimitReachedType` set, or `turn/completed {status: failed}` |
| +whose error the decoder recognises as a usage limit); `auth` |
| +(`authentication_failed`, `oauth_org_not_allowed`, `account_on_hold`, |
| +`billing_error`; Codex `account/updated` to signed out or a 401 class |
| +error): the connection becomes `sign_in_again`; `transient` |
| +(`overloaded`, `server_error`, no response): retried on the same |
| +connection by the existing retry policy, never a failover. Only |
| +`quota` makes a connection `limited`; only `quota` and `auth` trigger |
| +failover. Fields are optional everywhere: `resetsAt` and `utilization` |
| +may be absent, Codex windows may be absent; a `limited` connection |
| +without a reset time shows "Limited, no reset time reported" and is |
| +re-probed on the §2.7 schedule. |
| + |
| +**Coordinator failover, with exactly-once effects.** Today a tool call |
| +id is `turn/attempt/useID` (`thin/bridge.go`), so simply replaying the |
| +turn on a new attempt would execute `start_task`, `add_project` or |
| +`ask_person` again under new ids. Failover therefore runs in this |
| +order, each step durable before the next: |
| + |
| +1. The failed attempt is **terminated**: the runner kills the |
| + namespace and waits for the pidfd exit proof (thin v1 §4), as it |
| + does for cancel. No new attempt exists until then. |
| +2. The turn enters a new nonterminal state **`waiting`** |
| + (`turn{state: waiting, reason: limited | sign_in_again}`), added to |
| + the turn state machine beside `queued` and `running`; `wire.Terminal` |
| + stays false for it, so `chat/runner.go` keeps accepting reports. The |
| + draft deltas are discarded as on cancel. If no eligible pair exists |
| + the turn stays `waiting` and the chat shows the card in the last |
| + paragraph; queued messages join the waiting turn. |
| +3. The runner chooses a new pair and **advances the attempt** in its |
| + `runs` row and in a `turn{state: running, attempt: n+1}` report, |
| + which the instance accepts only as a forward transition from |
| + `waiting` for that turn. |
| +4. Before the new process gets the frame, the runner **reconciles tool |
| + effects**: it asks the instance for the recorded tool calls of the |
| + turn (`tool_calls{turn}` request, answered from the stored results |
| + the instance already keeps by call id, thin v1 §4) and builds the |
| + new attempt's frame as the person's messages plus a short, |
| + runner-written summary that lists each completed tool call and its |
| + recorded result ("You already added oficina/sample; task tk_… is |
| + started; the person was asked X and answered Y"). The coordinator |
| + is told, in the house rule for a resumed attempt, that these effects |
| + exist and are not to be repeated. On the instance side, a |
| + `tool_call` whose name and arguments match a recorded call of the |
| + same turn is answered with the stored result rather than executed; |
| + the match key is `(turn, name, canonical args)`, and the stored |
| + result is returned with `replayed: true` so the runner can log it. |
| + This closes the gap for a model that repeats a write regardless. |
| +5. The frame goes to the new session, seeded from the notebook, the |
| + house rule and the tail as thin v1 §2, and the reply arrives with one |
| + quiet line under it: "Switched to Codex; Claude resets Mon 10:00" |
| + (`chat.switched`), or "Switched to Codex" when no reset time was |
| + reported. Returning to a preferred connection happens at the next |
| + turn start when it is eligible again, with the line only when the |
| + switch happens, and the old session is resumed with a fresh notebook |
| + and tail injection (thin v1 §2's daily reset rule covers staleness). |
| + |
| +A cancel during `waiting` ends the turn `cancelled` and voids the |
| +pending frame; a cancel that arrives after step 3 targets attempt n+1 |
| +and ignores stale reports for attempt n (`chat/runner.go` already drops |
| +reports for `Attempt < r.Attempt`). |
| + |
| +**Engineering mid-step.** A step whose harness fails on `quota` or |
| +`auth` is a failed attempt as any crash is: termination proof first, |
| +nothing committed (the worktree is discarded; partial work is not a |
| +candidate), then a new attempt on another eligible pair avoiding the |
| +connections that failed (`avoid_connections[]` on dispatch replaces |
| +`avoid_account`), same brief. The step records both attempts and their |
| +pairs; the card shows "Engineering on Codex (Claude was limited)". |
| +With no eligible pair the step waits in `queued` with reason |
| +`no_connection` and resumes on its own when a connection returns. |
| + |
| +**Review across families.** Thin v1 §3's rule stands, with the family |
| +read from the pair actually chosen, not from the connection: an |
| +endpoint that serves several model families is `other_family` only |
| +when the chosen model's family differs from Engineering's. `other_family` |
| +first, then `same_family` with fresh context, then `same_account`; the |
| +label is recorded on the step. |
| + |
| +**Ask the implementer** keeps its exact binding: the kept session on |
| +the connection and model that ran the step (slice 4b). It never moves; |
| +if that connection is not `healthy` the question fails |
| +`account_unavailable` with the reset time in the card. |
| + |
| +**"Nothing can answer."** When no eligible pair exists for the |
| +coordinator the turn is `waiting` with reason `no_connection`, and the |
| +chat shows a card in place of `chat.failed`: "Nothing can answer right |
| +now. Claude resets Mon 10:00; Codex is signed out." with one action, |
| +**Add a connection**. The message is not lost and is not resent by the |
| +person; when a connection becomes eligible the runner advances the |
| +attempt and the reply arrives. The person may cancel the turn. |
| +`wire.Reasons` gains `limited` and `no_connection`; `Task.NeedsYou` |
| +gains `no_connection`; the old "Send your message again to retry" line |
| +goes. |
| **The preference.** Settings gains one quiet row per role, "Coordinator |
| prefers", "Engineering prefers", "Review prefers", each a picker over |
| -the person's connections plus "Automatic" (the default). A preference is |
| -the first tie-breaker after capability and health, never a requirement: |
| -a preferred connection that is limited is skipped with the switched |
| -line, and a preference for a connection the role cannot use (the matrix) |
| -is refused in the picker. `PUT /api/v1/preferences {role, connection_id |
| -| null, revision}`. Per task, the task page offers "Run on …" before the |
| -first step starts and "Retry on …" at a failed step. |
| +the person's connections and, for endpoints, a model, plus "Automatic" |
| +(the default). It sits after the tier floor in the order above, so a |
| +preference cannot put a `strong` job on a `cheap` model, and it never |
| +overrides health. `PUT /api/v1/preferences {role, connection_id, |
| +model | null, revision}`. Per task, the task page offers "Run on …" |
| +before the first step starts and "Retry on …" at a failed step; a |
| +per-task choice is a tier override as well, recorded as such. |
| ## 4. Routing: who does what |
| @@ -814,22 +878,40 @@ estimate where there is one. *Routing*: the sum lines from §4 for the |
| period ("3 tasks moved to Codex while Claude was limited", "12 small |
| fixes ran on the local model", "2 escalations after review"). |
| -**Recording, from day one.** The runner already receives per-turn and |
| -per-step usage from each harness: Claude's `result.usage` and |
| -`result.modelUsage` (with `costUSD` as a cross-check, never shown), |
| -Codex's `thread/tokenUsage/updated` (the `last` breakdown per turn, |
| -`total` as the check), and the endpoint harness's equivalent (OpenAI |
| -`usage` on the final chunk with `stream_options.include_usage`, or the |
| -harness's own usage event, §1.4). It writes one `usage` row per turn or |
| -step attempt: person, connection, harness, model, role, project, task, |
| -step, turn, input, cached input, cache write, output, reasoning output, |
| -estimated cost in micro-dollars (null for subscriptions and free |
| -endpoints), recorded at, and sends it in the existing `reply` and |
| -`step` frames as a `usage` object, which already exists on `reply` as |
| -`wire.Usage` ("without cost data", today) and gains the same fields. The instance stores it as a |
| -`usage` table and serves sums; raw rows are kept 90 days, daily sums |
| -indefinitely. Slice 1 records every field it can and shows nothing |
| -new; the page comes later and finds the data waiting. |
| +**Recording, from day one.** The runner writes one `usage` row per |
| +**attempt** of a turn, step or question, whether it replied, failed, |
| +was cancelled or is still waiting for a reconnect: person, connection, |
| +model, harness, role, project, task, step, turn, attempt, outcome |
| +(`replied | failed | cancelled | superseded`), input, cached input, |
| +cache write, output, reasoning output (each nullable: a harness that |
| +did not report a figure leaves null, never zero), `complete` (true |
| +only when the harness's final usage message for that attempt was |
| +seen), estimated cost in micro-dollars with `price_version` (the id of |
| +the price-table revision used; null for a subscription within plan and |
| +for a local endpoint), and recorded at. Per harness: Claude's `result` |
| +message gives `usage` and `modelUsage` once per attempt, and |
| +`modelUsage` is kept per model (one row per model when a turn used |
| +several); Codex sends several `thread/tokenUsage/updated` notices within |
| +one turn and across a resume, so the runner keeps the first `total` seen |
| +after `thread/resume` as the attempt's baseline, takes the attempt's |
| +figure as the last `total` minus that baseline, uses `last` only as a |
| +consistency check, and drops a notice whose `turnId` or `threadId` |
| +does not match the attempt (the local fixtures in `provider/codex/testdata` |
| +already show multiple notices per turn); Pi's `message_end.usage` |
| +(slice 2) is summed over the attempt's messages. Rows travel in the |
| +existing `reply`, `step` and `answer` frames as a `usage` array (the |
| +present `wire.Usage` "without cost data" becomes this shape), and a |
| +`usage` frame of its own carries rows for attempts that produced no |
| +reply. The instance stores them as a `usage` table keyed by |
| +`(turn or step or question, attempt, model)`, so a resent frame is a |
| +no-op; raw rows are kept 90 days, daily sums indefinitely. A |
| +subscription is not free past its plan: Claude's `rate_limit_info` |
| +carries `overageStatus` and `isUsingOverage`, and Codex's |
| +`rateLimitReachedType` and `credits` say when paid credits are being |
| +consumed; a row recorded under overage carries `overage: true` and is |
| +counted in Spend at the connection's typed overage price, labelled as |
| +such. Slice 1 records every field it can and shows nothing new; the |
| +page comes later and finds the data waiting. |
| **Resources.** `GET /api/v1/usage?period=day|week|month&by=connection| |
| role|project|task` returns `UsageReport {period, from, to, rows[{key, |
| @@ -919,16 +1001,21 @@ then UI, then deploy, as thin v1 §8. Sizes are agent days. |
| | Slice | Content | Tests | Size | |
| |---|---|---|---| |
| -| 1 Several accounts, Codex coordinator, in-app Codex and second Claude | `Connection` rows and homes, `connect` and `connection` frames, the Codex device-code flow, the Claude same-machine flow and the honest remote card, `hello.connections` and `seal_key`; the choice function over several connections with health and headroom; coordinator failover with the switched line and the new session seeded from the notebook; Engineering retry on another connection after termination; `no_connection` card; `fakecodex` with device-code login, `account/rateLimits`, `thread/tokenUsage/updated` and `turn/failed` on quota; **usage recording** from Claude `result` and Codex `tokenUsage` into the `usage` table and frames, no page; `routing` rows with reason `headroom`, `failover`, `only_option` only (no classes yet) | Headless: C1 two Claude accounts, first hits a fake weekly limit mid-turn, reply arrives from the second with the switched line, no duplicate; C2 Codex coordinator end to end (hello, tools, a task); C3 in-app Codex device code against `fakecodex`, card shows code, turns healthy; C4 add a second Claude in the same-machine case against `fakeclaude` (loopback callback simulated), and the remote case shows the terminal card; C5 Engineering step fails on quota, termination proof, retried on Codex, card shows both; C6 nothing available, `no_connection` card, message queued, connection returns, reply arrives; C7 guard: no secret-shaped field anywhere, `sealed` never in a report. Staging witness: one real Codex device-code sign-in in the app, one real Codex refresh (thin v1's debt), one real Claude limit observed or injected by a `rate_limit_event` replay, three coordinator turns across the switch | 4 days | |
| +| 1a Fake Codex and usage recording | `fakecodex` reproducing the pinned app-server protocol from recordings: `initialize`, `thread/start` and `thread/resume`, `turn/start`, items, `turn/completed` with `status: completed | failed | interrupted`, `account/login/start {chatgptDeviceCode}` and `account/login/completed`, `account/read`, `account/rateLimits/read` and `/updated` with and without windows, several `thread/tokenUsage/updated` per turn; the `usage` table, rows and frames of §6 for Claude and Codex, including failed and cancelled attempts; Codex rate notices kept as state rather than discarded | Unit: usage aggregation over the recorded fixtures (baseline after resume, dedup of a resent frame, nullable fields, `complete` false when the final notice is missing); property test that sums over random rows match by every grouping. Headless: U1 a Claude turn and a Codex turn each produce one row with `complete: true`; U2 a cancelled turn produces a row with `outcome: cancelled` | 1 day | |
| +| 1b Protocol and auth | `Connection` rows and homes, `connect`, `connection`, `disconnect` frames, `hello.connections`, `sync.connections`; Codex device code in the app; Claude same-machine loopback and the finish-on-runner card; health, `limited`, `sign_in_again` and the failure classifier of §3; Claude and Codex only, over the existing egress relay, no endpoints and no sealed keys | Headless: A1 device code against `fakecodex`, card shows the code, connection turns `healthy` with plan and windows; A2 device code refused (not enabled), `provider_refused`; A3 Claude same-machine against `fakeclaude` with a simulated loopback callback, `healthy` with the observed email; A4 remote case shows the finish-on-runner card and nothing else; A5 cancel during `connecting` defeats a late success (the runner's late `healthy` report for a cancelled attempt is dropped and the home deleted); A6 `rate_limit_event {rejected}` with and without `resetsAt` marks `limited` correctly; A7 an `auth` failure marks `sign_in_again`, never `limited`; A8 guard: no secret-shaped field in any frame, fixture or report | 1 day | |
| +| 1c Failover and continuity | The choice function over pairs with stickiness; the `waiting` turn state; termination before failover; durable attempt advancement; tool-effect reconciliation (`tool_calls{turn}` request, replayed results by `(turn, name, canonical args)`, the resumed-attempt house rule); the switched line; Engineering retry on another pair after termination; `no_connection` waiting card; pinned ask | Headless: F1 two Claude accounts, the first hits a fake limit mid-turn, reply from the second with the switched line, no duplicate message; F2 quota failure immediately after each write tool in turn (`add_project`, `record_task`, `start_task`, `ask_person`, `set_project_home`), the new attempt's summary names the effect, and a repeated call is answered `replayed: true` with no second project, task or card; F3 runner crash between termination and attempt advancement, restart recovers the turn in `waiting` and advances once; F4 ack loss on the `turn{running, attempt: 2}` report, resend is a no-op; F5 cancel during `waiting` ends `cancelled`, cancel after advancement targets attempt 2 and a stale attempt-1 report is dropped; F6 Engineering step fails on quota, termination proof, attempt 2 on Codex, card shows both; F7 nothing eligible, `waiting` with `no_connection`, the card, then a connection returns and the reply arrives without the person resending; F8 the preferred connection returns, the next turn switches back with the line and resumes the old session with a fresh notebook injection; F9 ask on a step whose connection is `limited` fails `account_unavailable` and never moves. Staging witness: one real Codex device-code sign-in in the app, one real Codex refresh (thin v1's debt), one real Claude limit observed or injected by a `rate_limit_event` replay against the real CLI, three coordinator turns across the switch, one of them straight after `start_task` | 1.5 days | |
| +| 1d UI | Connections list and Add in Settings, the connecting card, the switched line, the waiting card, the finish-on-runner card; no Usage page | Browser suite on A1, A4, F1, F7 | 0.5 day | |
| | 2 Local models and metered endpoints through Pi | Pi probes P1 to P4 (RPC session across 100 fake turns; `extension_ui_request` relay for a blocked tool; MCP pinning; `abort` termination), `fakepi`, Pi containment profile in `policy.go`, endpoint connections with the test call and `local` hosts, sealed API keys (`seal_key`, sealed box in the web app and the Go client), OpenRouter PKCE on the web app, TensorX and Mistral API as endpoints with their price tables and 429 parsing, Pi usage into `usage`, tiers from the static map (no classes yet: an endpoint is chosen by preference or when nothing else is healthy) | Headless: P1 to P4 as tests; E1 add an Ollama endpoint, model list shown, a Review step runs on it with `other_family`; E2 sealed key round trip, instance database contains no plaintext (grep the SQLite file), replay to another runner fails to open; E3 TensorX 429 with `retry-after` marks `limited` with the right time; E4 OpenRouter PKCE callback to the web app, exchange on the runner against a fake. Staging: a real Ollama on docs-t1 or Tito Studio running one Review step and one small Engineering step; one real TensorX test call | 4 days (OpenCode fallback adds 2) | |
| | 3 Routing and Usage page | `size`, `risk`, `kind` on `record_task` and `start_task`; the class-to-tier table; cheap-first escalation; routing lines on the task card; preferences per role and per task override; the Usage page with availability, spend, token tabs and routing lines; soft ceiling, 80% line and Pause (thin v1 slice 6's item, moved here); the sidebar dot; Mistral Vibe CLI as an Engineering and Review harness (`fakevibe`), subscription connection by the CLI's browser sign-in in the same-machine case and `MISTRAL_API_KEY` sealed otherwise | Headless: R1 a small, low-risk fix lands on the local model, fails checks, escalates to `standard` on another family, passes; R2 a high-risk task goes `strong` straight away; R3 preference set, switched line only on failover; R4 Usage sums equal the `usage` rows for each grouping and period (property test over random rows); R5 ceiling crossed, dot appears, Pause stops new metered steps and never the coordinator; V1 Vibe Engineering step with a fake. Staging: three routed tasks on the mix, page checked against the rows | 4 days | |
| | 4 Native apps and polish | Fixtures published, sealed box in Swift and Kotlin, `same_machine` detection on the Mac app, Connections and Usage screens | Contract fixtures replayed by the apps' own tests | app teams | |
| | 5 Command Code | BYOK `--local-only` Engineering and Review rows, `fakecmd`, containment profile with its network switches | One headless Engineering step, one Review step | 1.5 days | |
| -Slice 1 is the one that unblocks Paul: with two Claude accounts or one |
| -Claude and one Codex connected, the coordinator keeps answering through |
| -a weekly limit, and both can be added from the app (Codex entirely; |
| -Claude at the machine or by the terminal card). |
| +Slice 1 (gates 1a to 1d, four days) is the one that unblocks Paul: |
| +with two Claude accounts or one Claude and one Codex connected, the |
| +coordinator keeps answering through a limit, and both can be added from |
| +the app (Codex entirely; Claude at the machine, or finished on the |
| +runner). Each gate is green in CI before the next starts, and 1c's |
| +staging witness runs before 1d. |
| ## 9. Decisions for Paul |