spec: thin v1 round-3 fixes (rotation, atomicity, Codex events, turn cancel)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 file changed,
+65
−40
docs/superpowers/specs/2026-11-06-equipo-thin-v1.md+65 −40
CI passed — run details
Intent
diff --git a/docs/superpowers/specs/2026-11-06-equipo-thin-v1.md b/docs/superpowers/specs/2026-11-06-equipo-thin-v1.md| index af5aa342..25e103f4 100644 |
| --- a/docs/superpowers/specs/2026-11-06-equipo-thin-v1.md |
| +++ b/docs/superpowers/specs/2026-11-06-equipo-thin-v1.md |
| @@ -39,8 +39,12 @@ runner-advertised allowlist, DELETE = Remove); `messages` (GET |
| different body → 409); `turns/{id}` (`queued | running | replied | failed | |
| cancelled`, with `reason`); `tasks` and `tasks/{id}` (steps with `candidate_sha`, |
| log tails, branch), `PUT tasks/{id}/plan` (edits unstarted steps, guarded by |
| -`revision`), `tasks/{id}/cancel`, `tasks/{id}/retry` (refused until the runner |
| -has confirmed namespace termination), `steps/{id}/log`; `cards/{id}/answer` |
| +`revision`), `tasks/{id}/cancel` and `POST turns/{id}/cancel` (both return `202 {attempt}` |
| +and end in a `turn{state: cancelled}` or `step{state: cancelled, attempt}` |
| +event once the runner reports termination for that attempt, or `409` if the |
| +turn or step is already terminal), `tasks/{id}/retry` (refused until the |
| +runner has confirmed termination of the current attempt; returns the new |
| +attempt id), `steps/{id}/log`; `cards/{id}/answer` |
| (`{choice, revision}`; stale revision or already answered → 409 with the |
| current card); `needs-you`; `runners`; `accounts`; `snapshot` (everything a |
| client shows, plus `cursor`, in one transaction). |
| @@ -89,14 +93,17 @@ token separately. |
| **Credentials.** Self-heal's rules stand: a runtime credential copy lives 25 |
| minutes (`accounts.go:192`), never writes back, and cannot reach refresh |
| -hosts. So a process lives at most one copy: the runner records the copy's |
| -expiry, and when a turn would start inside the last five minutes, or the |
| -copy has expired while idle, it ends the process cleanly between turns, |
| -refreshes in the source home under the lock, stages a new copy and resumes. |
| -Mid-turn the copy is good for the rest of the turn by construction (turns |
| -are capped at 20 minutes). The source lock is held only for refresh and |
| -staging, not for the attempt: copies cannot refresh, so maintenance cannot |
| -race them. Specialists on the same account each get their own copy from the |
| +hosts. So a process lives at most one copy, and **a turn starts only if the |
| +copy's remaining validity covers the maximum turn duration plus a margin**: |
| +with a 20 minute turn cap and a 2 minute margin, only in the copy's first 3 |
| +minutes; otherwise the runner ends the process cleanly between turns, |
| +refreshes in the source home under the lock, stages a new copy and resumes |
| +before sending the frame. Practically that means a rotation before most |
| +turns, which the session home makes cheap (the cold path in scenario 1). If |
| +the provider's copy lifetime turns out shorter than the cap plus margin, the |
| +cap drops to fit; a turn never runs on a copy that can expire under it. The |
| +source lock is held only for refresh and staging, not for the attempt: |
| +copies cannot refresh, so maintenance cannot race them. Specialists on the same account each get their own copy from the |
| same source under the same short lock. If refresh reports a different |
| identity, the account is marked `sign_in_again`, its sessions are not |
| resumed on it, and the coordinator continues on another healthy account in |
| @@ -118,7 +125,9 @@ stays with the forge checks in §5), `propose_plan` as a consent step. |
| **Second message rule.** If the person's turn is `running`, the new message is |
| `queued`; when the turn ends, all queued messages go to the coordinator as |
| one frame and produce one reply. A running turn is never interrupted by a |
| -new message; cancel is explicit. |
| +new message; cancel is explicit (`POST turns/{id}/cancel`, §1): the runner |
| +interrupts the coordinator process for that attempt, the draft is discarded, |
| +and the turn ends `cancelled`; queued messages then start a fresh turn. |
| Setup by the agent: the heartbeat already carries every repository key in |
| the runner's forge credential file; any of them is a valid `add_project`, and |
| @@ -148,12 +157,16 @@ judged; a new candidate invalidates both. The last step is the person: the |
| card becomes "Ready to merge: branch, SHA, CI, verdict, open on Amadan". |
| **Codex path, separately.** Codex is JSON-RPC over the app-server's stdio: |
| -`initialize`, `account/read` (refresh in the source home only), |
| -`config/read`, `thread/start` or `thread/resume`, `turn/start`; `item/started` |
| -and `item/completed` notifications carry deltas; requests that need a response |
| -(approval requests) are answered deny by policy or relayed as `ask_person`; |
| -the turn ends on `turn/completed`; cancel is `turn/interrupt` and any tool |
| -call in flight is recorded `interrupted`, never completed. A thread stays |
| +`initialize` then the `initialized` notification, `account/read` (refresh in |
| +the source home only), `config/read`, `thread/start` or `thread/resume`, |
| +`turn/start`. Streamed text is `item/agentMessage/delta`, command output is |
| +`item/commandExecution/outputDelta`, items are bracketed by `item/started` |
| +and `item/completed` (all names as in `internal/runner/provider/codex`). |
| +Server requests that need a response (`item/commandExecution/requestApproval`, |
| +`item/fileChange/requestApproval`, `item/permissions/requestApproval`, |
| +`item/tool/requestUserInput`) are answered deny by policy or relayed as |
| +`ask_person`; the turn ends on `turn/completed`; cancel is `turn/interrupt` |
| +and any item in flight is recorded `interrupted`, never completed. A thread stays |
| with the account that started it; an account change starts a new thread with |
| a summary. Codex native refresh is fake-tested only so far: staging must |
| show one real refresh before slice 5 marks a Codex account healthy. |
| @@ -178,8 +191,8 @@ credential, enrolment unchanged. JSON lines, every frame with an `id`: |
| - instance → runner: `message{person, session, turn_id, text}`, |
| `answer{person, turn_id, card_id, choice}`, `dispatch{task, project, repo, |
| - branch, base_sha, steps}`, `cancel{task, step}`, `tool_result{call_id, |
| - body}`, `drain{retry_after}`. |
| + branch, base_sha, steps, attempt}`, `cancel{turn_id | task, step, |
| + attempt}`, `tool_result{call_id, body}`, `drain{retry_after}`. |
| - runner → instance: `hello{generation, repos, accounts[{id, provider, |
| email, healthy, headroom}], versions}` then every 30 s; `sync{sessions, |
| runs[{task, step, state, candidate_sha, attempt}]}` on every connect; |
| @@ -188,22 +201,34 @@ credential, enrolment unchanged. JSON lines, every frame with an `id`: |
| candidate_sha, attempt, termination}`; `needs_you{kind, action}`; `ack{id}`. |
| **Delivery.** Both ends keep a small table: the instance's `commands` and the |
| -runner's `outbox` (id, kind, payload, sent, acked). A frame is acked only |
| -after the receiver has persisted it; unacked frames are resent on reconnect; |
| -receivers dedup by id. Tool call ids are the provider's tool-use id plus |
| -turn, so a repeated `tool_call` returns the stored result. A `dispatch` lost |
| -after `start_task` is resent and ignored if the run exists; a push cut off |
| -mid-way is settled by forge's reconcile on the next `sync`, and the |
| -instance accepts only forward step transitions. |
| +runner's `outbox` (id, kind, payload, sent, acked). Producing is atomic with |
| +the state it describes: `start_task` writes the task, its steps, the |
| +`dispatch` command and the `task` event in one transaction, and a message |
| +POST writes the row, the `message` command and the event together. Consuming |
| +is atomic too: the receiver records the frame id and applies its effect (the |
| +runner inserts the `runs` row, the instance updates the step) in one |
| +transaction, and acks only after that commit; unacked frames are resent on |
| +reconnect and a seen id is a no-op. Tool call ids are the provider's |
| +tool-use id plus turn, so a repeated `tool_call` returns the stored result. |
| +A push cut off mid-way is settled by forge's reconcile on the next `sync`, |
| +and the instance accepts only forward step transitions. |
| **One owner.** The instance keeps `runner_sessions` (runner, generation, |
| -connected). A new connection from the same credential bumps the generation |
| -and closes the old socket; frames with a stale generation are rejected. A |
| -person's coordinator session and tasks live on one runner (the owner's |
| -`primary`), so two runners cannot touch one branch; the runner's `runs` |
| -table has a unique index on `(task, state='running')`. Retry is refused |
| -until the step's `termination` proof (namespace exit observed by pidfd, as |
| -`containment` does today) has arrived. |
| +connected). A new connection from the same credential bumps the generation, |
| +closes the old socket and rejects stale frames, but that alone does not stop |
| +an older runner process that is still executing. So the generation is an |
| +**execution lease**: the runner writes the generation it was granted in |
| +`hello` to its state file, checks it against the instance at every step |
| +start and immediately before every publish (a `sync` round trip; forge |
| +refuses without a fresh confirmation), and on seeing a newer generation |
| +kills its namespaces, marks its runs `superseded` and exits for systemd to |
| +restart it clean. A person's coordinator session and tasks live on one |
| +runner (the owner's `primary`), so two runners cannot touch one branch; the |
| +runner's `runs` table has a unique index on `(task, state='running')`. Every |
| +run has an `attempt` id; `cancel` frames and `step` reports carry it, so a |
| +delayed cancel for attempt 1 is ignored once attempt 2 exists. Retry is |
| +refused until the step's `termination` proof (namespace exit observed by |
| +pidfd, as `containment` does today) has arrived for the current attempt. |
| **Instance restarts.** Each instance process has a generation. On SIGTERM it |
| sends `drain` to connected runners, finishes in-flight writes and exits; |
| @@ -337,10 +362,10 @@ context, labelled, checking the exact candidate SHA; **the coordinator adds |
| projects itself** with an "Added · Remove" card, limited to the person's |
| runner-advertised allowlist, and adding never broadens publishing authority. |
| -Risks: a long-lived session may bloat or wedge (copy cycling restarts it at |
| -least every 25 minutes; a new session each day since Equipo tables hold the |
| -state); the edge may cut idle connections (pings, cursor resume, scenario 8 |
| -before `--swap hold` goes); v1 "done" is weaker than frozen evidence (labelled |
| -as branch, CI and verdict on one SHA, and Paul merges); headroom is best |
| -effort; Codex refresh is unproven live until slice 5; deleting verified guards |
| -looks like waste (they stay in history, §5 names what is kept and ported). |
| +Risks: a long-lived session may bloat or wedge (copy rotation restarts it |
| +often; a new session each day, since Equipo tables hold the state); the edge |
| +may cut idle connections (pings, cursor resume, scenario 8 before `--swap |
| +hold` goes); v1 "done" is weaker than frozen evidence (labelled as branch, CI |
| +and verdict on one SHA; Paul merges); headroom is best effort; Codex refresh |
| +is unproven live until slice 5; deleted guards stay in history and §5 names |
| +what is kept. |