| index 6cd0aa30..f5981d15 100644 |
| --- a/docs/superpowers/specs/2026-11-11-equipo-release-s1-hosted-checks.md |
| +++ b/docs/superpowers/specs/2026-11-11-equipo-release-s1-hosted-checks.md |
| @@ -1,157 +1,195 @@ |
| # Release slice 1: hosted checks |
| |
| -Status: 2026-11-11, revision 1, for Astra review. Drafted by Claude (Opus |
| -5.5) on `release-s1-hosted-checks` from main 577e24c. Slice 1 of |
| -`2026-11-11-equipo-release.md` (§2.7), approved by Paul as D2. Not |
| -implemented. |
| +Status: 2026-11-11, revision 2. Drafted by Claude (Opus 5.5) on |
| +`release-s1-hosted-checks` from main 577e24c. This is slice 1 of |
| +`2026-11-11-equipo-release.md` (§2.7), approved by Paul as D2. |
| +- Revision 1 (1d7b90d) drew READY AFTER FIXES from Astra, in one round. |
| + The findings are in `CODEX-FINDINGS-RELEASE-S1-HOSTED-CHECKS.md` |
| + beside this spec. |
| +- Revision 2 folds all six findings in, marked **(astra N)**. Where it |
| + could, it cut scope instead of adding machinery. |
| |
| ## 0. Why, and the finish line |
| |
| A checks step on the primary runs the repository's gate offline in |
| -bubblewrap. Equipo's own gate is written for hosted CI (it pulls an image, |
| -Chromium and tools, and govulncheck needs vuln.go.dev). So on |
| -oficina/equipo every checks step ends `cannot_run needs_network`, and the |
| -merge gate asks "checks couldn't run" for a change that hosted CI has |
| -already judged on the exact commit. |
| - |
| -Finish line: for a repository with hosted CI on, the checks step reports |
| -hosted CI's own verdict on the exact candidate SHA, bound to the |
| -repository, the branch, the SHA and the run's report time. The rename task |
| -(`tkataquuxfrw`) on Retry ends `failed` with hosted CI's failing steps, not |
| -`needs_network` or `runner_restarted`. |
| +bubblewrap. Equipo's own gate is written for hosted CI: it pulls an |
| +image, Chromium and tools, and govulncheck needs vuln.go.dev. So on |
| +oficina/equipo every checks step ends `cannot_run needs_network`, even |
| +though hosted CI has already judged the exact commit. |
| + |
| +**Finish line:** |
| +- For a repository with hosted CI on, the checks step reports hosted CI's |
| + own verdict on the exact candidate SHA. The verdict is bound to the |
| + repository, the branch, the SHA and the run's report time. |
| +- A runner restart while the step waits no longer ends it |
| + `runner_restarted`. |
| +- The rename task (`tkataquuxfrw`) on Retry ends `failed`, with hosted |
| + CI's failing steps in its fix round. |
| |
| ## 1. Rules |
| |
| 1. **No new credential, no new grant.** The primary reads the hub's bearer |
| - API with the agent credential it already holds for the repository |
| - (`forge.FileCredentials.Credential`), as `fileForge.Merge` does. Workers |
| - hold no forge credential and never use hosted checks. |
| + API with the agent credential it already holds for the repository, as |
| + `fileForge.Merge` does. Redirects are refused, and reads are capped. |
| + Workers hold no forge credential and never take this path. |
| 2. **Who decides.** The instance offers hosted checks on every checks |
| - dispatch to the primary (`DispatchCommand.HostedChecks`). The runner |
| - takes it only when the hub says hosted CI is on for the repository |
| - (`GET /api/v1/repos/{ns}/{repo}/ci/hosted`, `on`). Anything else, a |
| - read error included, is today's local gate, unchanged. |
| -3. **macOS changes stay as they are.** A change that needs macOS |
| - (`needsMacOS`) keeps today's path (`needs_macos`, the Mac re-run). |
| - Hosted CI runs on Linux machines. |
| -4. **Exact SHA.** The hub's status API reports a branch's tip |
| - (`GET .../ci/status?branch=<task branch>`). A verdict counts only when |
| - the tip is the candidate. Any other tip, an unknown state, `queued` or |
| - `running` means wait. |
| -5. **Wait, with a timeout.** Poll every 20 s with `logs=none`, for at most |
| - 60 minutes from the step's start. Then `cannot_run`, `checks_timeout` |
| - (an existing reason that always asks). Cancel and withdrawal stop it as |
| - today. |
| -6. **Verdicts.** |
| - |
| -| Hub state on the candidate | Checks | Gate | Exit | Reason | |
| -|---|---|---|---|---| |
| -| `success` | `passed` | `hosted CI` | 0 | | |
| -| `failure` | `failed` | `hosted CI` | 1 | | |
| -| `skipped` (no CI script) | `none` | | | | |
| -| `lost`, `stale` | `cannot_run` | | | `checks_unavailable` | |
| -| timeout | `cannot_run` | | | `checks_timeout` | |
| - |
| - On `failure` the runner makes one more read with `logs=failed`. The |
| - output is the failing step and shard names first, then the hub's |
| - summary, then the failing logs' tail, bounded by `wire.MaxChecksOutput`. |
| -7. **Binding.** A hosted verdict carries `StepReport.Hosted`: repository, |
| - branch, SHA, hub state, the run's report time (`updated_at`; the hub |
| - exposes no run id) and the failing unit names. The instance counts a |
| - report with gate `hosted CI` only when all of these hold: |
| - - it comes from the primary; |
| - - the step is a checks step; |
| - - `Hosted` is present; |
| + dispatch to the primary (`DispatchCommand.HostedChecks`). |
| + - The runner takes the offer only when `GET .../ci/hosted` answers |
| + `on` and the change does not need macOS (`needsMacOS`). |
| + - Anything else, a read error included, means today's local gate, |
| + unchanged. |
| + - Once taken, the attempt's phase becomes `hosted`, which is |
| + persisted. |
| +3. **Polling is deferred, not held (astra 5).** |
| + - Each run of the attempt confirms the lease, makes one status read |
| + (`GET .../ci/status?branch=<task branch>&logs=none`, 30 s request |
| + timeout), and returns `stepDeferred` when there is no verdict yet, |
| + as a merge waiting for CI does. The queue moves on meanwhile. |
| + - The deadline is 60 minutes from the first deferral |
| + (`deferred_since`, persisted), so neither a restart nor a reconnect |
| + resets it. |
| + - Cancel and withdrawal end it at the next run, through the lease. |
| + - Restart recovery runs a `hosted`-phase checks attempt again, as it |
| + does a merge, instead of failing it `runner_restarted`. |
| + - A read error counts as no verdict yet. At the deadline the step |
| + ends `cannot_run checks_timeout`. |
| +4. **One snapshot (astra 2).** A verdict comes only from a response whose |
| + `ns`, `repo` and `branch` equal the request and whose `sha` is the |
| + candidate. |
| + - On `failure`, one `logs=failed` read adds the logs only if its sha, |
| + state and `updated_at` equal the first response's. Otherwise the |
| + report carries the first snapshot's names and summary without logs. |
| + - Another tip, `queued`, `running` and `unknown` all mean no verdict |
| + yet. |
| +5. **Verdicts.** |
| + |
| +| Hub state on the candidate | Checks | Gate | Exit | Reason | `Hosted` | |
| +|---|---|---|---|---|---| |
| +| `success` | `passed` | `hosted CI` | 0 | | yes | |
| +| `failure` | `failed` | `hosted CI` | 1 | | yes | |
| +| `skipped` (no CI script) | `none` | | | | yes | |
| +| `lost`, `stale` | `cannot_run` | | | `checks_unavailable` | yes | |
| +| deadline | `cannot_run` | | | `checks_timeout` | no | |
| + |
| + The output lists the failing unit names first, then the hub's summary, |
| + then the failing logs' tail. It is bounded by `wire.MaxChecksOutput`. |
| +6. **Binding, bounded (astra 2, 6).** `StepReport.Hosted` holds `repo`, |
| + `branch`, `sha`, `state`, `reported_at` (the hub's `updated_at`; the |
| + hub exposes no run id) and `failed` (at most 20 names of 120 bytes, |
| + which the runner truncates). The instance counts a report that carries |
| + `Hosted`, or names gate `hosted CI`, only when all of these hold: |
| + - it comes from the primary, on a connection at protocol 5; |
| + - the step is checks, and `Hosted` is present; |
| - the repository is the project's own; |
| - the branch is the task's; |
| - the SHA is the step's candidate; |
| - - the state agrees with the outcome (`success` with `passed` and exit |
| - 0, `failure` with `failed` and a non-zero exit). |
| + - `reported_at` is greater than 0; |
| + - `failed` is within its bounds; |
| + - the state maps to the outcome as in rule 5. |
| |
| Anything else is ignored, as a judgement on another SHA is today. The |
| - instance stores the binding (`chat_steps.hosted_ci`, JSON) and records |
| + instance stores the binding in `chat_steps.hosted_ci` (JSON) and sets |
| `checks_sandbox = hosted`. |
| -8. **Fix round.** For a hosted failure, the fix round's feedback names the |
| - failing steps from the stored binding, then gives the output's tail: |
| - "The repository's hosted CI failed on 4d28994 in: step compile; step |
| - check shard 5. The end of their output: ...". |
| -9. **Merge authority.** A hosted `passed` or `failed` is checks that ran: |
| - `OutsideSandbox` stays false, because it is not `none`. With hosted |
| - CI, "checks couldn't run" remains only for `lost`, `stale` and the |
| - timeout, and `mergegate` does not change. The hub's own merge already |
| - refuses a commit whose CI is not green (`ci_not_green`). |
| +7. **Merge authority: checks that ran, not yet sandboxed (astra 1).** A |
| + hosted `passed` or `failed` is a real result: Review gets it, a |
| + failure starts the fix round, and "checks couldn't run" is no longer |
| + the reason. |
| + - **Why not sandboxed:** the hub's status API does not say where a |
| + verdict was produced. `on` is the desired setting, and a verdict |
| + from an ordinary runner survives enabling hosted CI. The hub's own |
| + merge gate on CI is off by default. |
| + - **So:** `checksOutsideSandbox` counts `hosted` as outside the |
| + sandbox. A hosted pass is asked about ("its checks ran outside the |
| + sandbox", existing copy) and never merged on its own. `mergegate` |
| + does not change. |
| + - **Later:** once the hub reports execution provenance and a run id |
| + (an amadan request, §5), hosted can count as sandboxed in its own |
| + change. |
| +8. **Fix round.** For a hosted failure, the feedback first names the |
| + failing units from the stored binding, for example "The repository's |
| + hosted CI failed on 4d28994 in: compile; check shard 5 of 23", then |
| + gives the output's tail. |
| |
| ## 2. Wire and versions |
| |
| -Protocol 5, `wire.ProtocolHostedChecks`, becomes `ProtocolCurrent`. Its |
| -two optional, `omitempty` fields: |
| -- `DispatchCommand.hosted_checks`; |
| -- `StepReport.hosted` (`{repo, branch, sha, state, reported_at, |
| - failed[]}`). |
| - |
| -`wire.Encode` gains `downgradeHostedChecks`, which clears both for any peer |
| -below 5, chained before the others. Frames are decoded with `Strict`, so |
| -without the downgrade an old peer would refuse the frame. |
| +- **Protocol 5,** `wire.ProtocolHostedChecks`, becomes |
| + `ProtocolCurrent`. It adds `DispatchCommand.hosted_checks` and |
| + `StepReport.hosted`, both `omitempty`. |
| +- **Downgrade, `downgradeHostedChecks` (astra 3):** |
| + - It drops the offer for any peer below 5. |
| + - It turns a hosted-derived report into `cannot_run |
| + checks_unavailable`, with no gate, no exit code and no `hosted`. A |
| + stripped report never keeps a `passed` an old instance would accept |
| + unbound. |
| + - It runs first, and the later steps keep the accumulated flag. |
| |
| | Combination | Behaviour | |
| |---|---| |
| -| new instance, runner at 4 | `hosted_checks` is never sent; local gate as today | |
| -| old instance, new runner | spoken 4: no flag, so local gate; `hosted` never sent | |
| -| new runner, its state holding a hosted dispatch, then rolled back to an old runner | the old runner reads its step bodies with `json.Unmarshal`, not `Strict`, so the unknown field is ignored and the local gate runs | |
| - |
| -The tests cover both directions at the wire, plus a contract with a |
| -protocol 4 runner rig. |
| +| new instance, runner at 4 | no offer, so the local gate as today | |
| +| old instance, new runner | spoken 4, so no offer. A hosted report still in flight from before reaches the old instance as `cannot_run` | |
| +| new runner rolled back to an old binary (astra 4) | not transparent. The old binary fails held checks `runner_restarted`, and an unacknowledged report with `hosted` in the outbox would be refused by a protocol 4 instance's strict decoder. Rule: roll a runner back below protocol 5 only after it has delivered its outbox, as for every earlier bump that added report fields (merge facts' `change`). The release plan's runner-state proof (§2.6 item 4) will test it | |
| |
| ## 3. Changes |
| |
| -- `wire`: `ProtocolHostedChecks`, the two fields, `GateHosted`, |
| - `SandboxHosted`, the downgrade. |
| -- `runner/forge`: `HubCIHosted` and `HubCIStatus`. Both send the bearer, |
| - escape the path, follow no redirects, cap the read (64 KiB and 4 MiB) |
| - and decode only the fields used. |
| -- `runner/thin`: an optional `HostedCI` interface on the Engineer, met by |
| - `fileForge`, and `hostedChecks` beside `checks`. The poll interval and |
| - timeout are variables, for the tests. |
| -- `equipo/chat`: |
| - - dispatch sets the flag for a checks step on the primary; |
| +- **`wire`:** `ProtocolHostedChecks`, the two fields, `HostedResult` |
| + with its bounds, `GateHosted`, `SandboxHosted`, and the semantic |
| + downgrade. |
| +- **`runner/forge`:** `HubCIHosted` and `HubCIStatus`. They send the |
| + bearer, escape the path, refuse redirects, cap the read (64 KiB and |
| + 4 MiB), and check the answer's identity. |
| +- **`runner/thin`:** |
| + - an optional `HostedCI` interface, met by `fileForge`; |
| + - `hostedChecks`, which runs in deferred steps; |
| + - `phaseHosted`, and its case in restart recovery. |
| +- **`equipo/chat`:** |
| + - dispatch sets the flag for checks on the primary; |
| - `stepReport` validates and stores the binding; |
| + - `checksOutsideSandbox` counts `hosted`; |
| - `feedback` names the failing units. |
| -- Migration `0062_thin_hosted_checks.sql`: `ALTER TABLE chat_steps ADD |
| - COLUMN hosted_ci text`. Additive; registered in the models; the |
| - snapshot is updated. |
| -- Budgets: `internal/runner/thin` and `internal/equipo/chat` sizes, with |
| - reasons. |
| -- No new UI copy. The checks line already shows the gate name. |
| +- **Migration** `0062_thin_hosted_checks.sql`: `chat_steps.hosted_ci` |
| + text. It is additive, and the model and snapshot are updated. |
| +- **Budgets:** the sizes for `internal/runner/thin`, |
| + `internal/equipo/chat` and the touched test packages, with reasons. |
| +- **No new UI copy.** |
| |
| ## 4. Tests, failing first |
| |
| -- **wire:** `Encode` clears both fields below 5 and keeps them at 5, in |
| - both directions. |
| -- **forge:** status and hosted reads against an `httptest` hub: the |
| - bearer, the path, the caps, a redirect refused, and an unreadable body |
| - as an error. |
| +- **wire:** below 5, `Encode` drops the offer, and turns a hosted |
| + `passed` into `cannot_run`. The result decodes strictly at protocols 4, |
| + 3, 2 and 1. At 5 it passes through unchanged. |
| +- **forge:** |
| + - the bearer and the path; |
| + - an answer for another branch, ns or repo is refused; |
| + - a malformed sha; |
| + - caps; |
| + - a redirect is refused and not followed; |
| + - a refusal, a bad repository, another logs mode, and a bearer with a |
| + newline. |
| - **thin**, with a fake `HostedCI`: |
| - - pending, then `success`, gives `passed` with its binding; |
| - - `failure` gives `failed`, with the names first and the logs; |
| - - another tip until the timeout gives `checks_timeout`; |
| - - `skipped` gives `none`; `lost` gives `checks_unavailable`; |
| - - hosted off, a read error, or the flag absent gives the local gate; |
| - - a macOS change gives the local path; |
| - - cancel gives `cancelled`. |
| + - pending defers, and unrelated work runs meanwhile; |
| + - a pass and a failure, each from one snapshot; a failure whose |
| + enrichment moved keeps no logs; |
| + - `skipped`, `lost`, and the deadline, measured from `deferred_since`; |
| + - hosted off, a read error on `hosted`, or no offer gives the local |
| + gate, as does a macOS change; |
| + - after a restart the step runs again, without `runner_restarted`; |
| + - cancel ends it; |
| + - the names are bounded. |
| - **thintest contracts:** |
| - - a hosted pass on the candidate leads to review, and then Ready with |
| - merge eligibility; |
| - - a hosted failure starts a fix round whose feedback names the units; |
| - - reports with the wrong repository, branch, SHA, state, sender or |
| - binding are ignored; |
| - - a protocol 4 runner gets no `hosted_checks`. |
| -- **Mutations:** each guard in rule 7, the SHA check in rule 4, the |
| - timeout, and the downgrade is broken once, and its test is seen to fail. |
| - |
| -## 5. Out of scope |
| - |
| -- A per-commit status read. The hub reports tips only; an amadan request |
| - for status by SHA, with a run id, is a follow-up. |
| -- Hosted checks for Mac workers. |
| -- Retrying a step that ended `runner_restarted`. Retry stays a person's |
| + - a hosted pass leads to review and approval, and the merge then asks |
| + with the sandbox reason and does not act; |
| + - a hosted failure starts a fix round that names the units; |
| + - every binding rule is checked on its own, and the report is ignored; |
| + - a protocol 4 rig gets no offer. |
| +- **Mutations:** every rule 6 guard, the identity check in rule 4, the |
| + deadline, the downgrade and the sandbox rule is broken once, and its |
| + test is seen to fail. |
| + |
| +## 5. Out of scope, and follow-ups |
| + |
| +- An amadan request: a status read by commit, with the run id and |
| + execution provenance (hosted or runner). It unlocks automatic merges |
| + on hosted passes. |
| +- Hosted checks on Mac workers. |
| +- Retrying steps already ended `runner_restarted`. Retry stays a person's |
| tap. |