oficina / equipo Public

spec: release slice 1 rev 2 (Astra round 1 folded in)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by paul@keymail.dev 218246c0c411ffdc1c11c2c4d7c3ff4dd83ec5cb parent 1d7b90d
2 files changed, +188 −123
  • docs/superpowers/specs/2026-11-11-equipo-release-s1-hosted-checks.md +161 −123
  • docs/superpowers/specs/CODEX-FINDINGS-RELEASE-S1-HOSTED-CHECKS.md +27 −0
diff --git 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
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.
diff --git a/docs/superpowers/specs/CODEX-FINDINGS-RELEASE-S1-HOSTED-CHECKS.md b/docs/superpowers/specs/CODEX-FINDINGS-RELEASE-S1-HOSTED-CHECKS.md
new file mode 100644
index 00000000..c916629a
--- /dev/null
+++ b/docs/superpowers/specs/CODEX-FINDINGS-RELEASE-S1-HOSTED-CHECKS.md
@@ -0,0 +1,27 @@
+READY AFTER FIXES
+
+All findings are **Important**, ordered by impact. Hub citations refer to the locally inspected `origin/main`.
+
+1. **Hosted enablement does not prove that a verdict came from hosted execution.** Rule 2 checks only `on`, but that field is `DesiredOn` (Hub `internal/hub/hosted_optin.go:152`). Enabling hosted CI leaves existing verdicts intact (`internal/repod/store_ci_hosted.go:102`). The status endpoint returns the general commit verdict without execution provenance (`internal/hub/ci_status_api.go:215`). An earlier ordinary runner’s success can therefore become `SandboxHosted`, enabling automatic merge through [gate.go:225](/home/paulca/amadan.net/oficina/equipo-release-s1/internal/equipo/mergegate/gate.go:225). The claimed backup is also conditional: Hub `internal/repod/git_merge.go:443` bypasses the green check when disabled, and `internal/repod/store_merge.go:38` defaults it off.
+
+ **Fix:** Require trustworthy hosted-run provenance before granting sandboxed-check treatment; otherwise require confirmation. Add a contract covering an ordinary green result followed by hosted enablement, with the hub merge gate disabled.
+
+2. **The response-to-report binding and second-read consistency rules are incomplete.** Rules 4 and 7 require matching SHA and report metadata, but never explicitly require comparing the hub response’s namespace, repository and branch with the request before constructing that metadata. The hub supplies those fields (`internal/hub/ci_status_api.go:215`). Rule 6’s second `logs=failed` request resolves the branch tip again (`internal/hub/ci_status_api.go:191`), so a branch move or rerun can attach another result’s names and logs to the first failure. `reported_at` is carried but has no validation rule.
+
+ **Fix:** Validate response identity before constructing `Hosted`; define and validate the timestamp. Build verdict, binding, names and logs from one validated response snapshot. If enrichment fails or changes identity, retain only evidence from the original snapshot or continue polling. Test wrong-response identity, branch movement, same-SHA reruns and failed enrichment. Validate bindings for hosted `skipped`, `lost` and `stale` reports too, rather than conditioning validation solely on a nonempty gate.
+
+3. **Downgrading only the new fields can silently discard the authority evidence.** A v5 runner may already hold a hosted dispatch or completed report when it reconnects to a v4 instance. Clearing `hosted` preserves `passed`, exit zero and gate `hosted CI`. The old [judgement validator at tasks.go:1125](/home/paulca/amadan.net/oficina/equipo-release-s1/internal/equipo/chat/tasks.go:1125) accepts that result without binding validation. The compatibility table covers fresh dispatches only.
+
+ **Fix:** Specify a semantic downgrade for existing hosted results, such as `cannot_run/checks_unavailable`, rather than stripping their evidence alone. Test queued and completed v5 work reconnecting at v4, plus strict decoding at every supported lower protocol. Preserve the accumulated downgrade-change flag when modifying [runners.go:377](/home/paulca/amadan.net/oficina/equipo-release-s1/internal/wire/runners.go:377).
+
+4. **Runner state rollback is not transparent.** Although dispatch bodies use `json.Unmarshal`, startup recovery marks checks attempts `runner_restarted`; it does not execute the local gate ([step.go:380](/home/paulca/amadan.net/oficina/equipo-release-s1/internal/runner/thin/step.go:380)). Completed reports pose another problem: unacknowledged outbox bodies remain raw JSON ([state.go:194](/home/paulca/amadan.net/oficina/equipo-release-s1/internal/runner/thin/state.go:194)). An old runner sending to a v4 peer returns those frames unchanged from [Encode at runners.go:366](/home/paulca/amadan.net/oficina/equipo-release-s1/internal/wire/runners.go:366); the old receiver rejects `hosted` through [frames.go:174](/home/paulca/amadan.net/oficina/equipo-release-s1/internal/wire/frames.go:174).
+
+ **Fix:** Define a tested drain or conversion procedure before reusing v5 state with an old binary, or explicitly prohibit that rollback. Correct the recovery promise. Cover both persisted dispatches and unacknowledged hosted reports using the actual old reader.
+
+5. **An hour-long polling call would monopolize the runner’s step queue.** Engineering, review and specialist questions execute serially ([step.go:553](/home/paulca/amadan.net/oficina/equipo-release-s1/internal/runner/thin/step.go:553)). Existing CI merge waits deliberately defer and release that queue ([mergestep.go:106](/home/paulca/amadan.net/oficina/equipo-release-s1/internal/runner/thin/mergestep.go:106)).
+
+ **Fix:** Specify deferred hosted polling with a persistent start/deadline, bounded requests and cancellation-aware waits. Define status-read error behavior after opting into hosted checks. Add tests proving unrelated work proceeds, cancellation and withdrawal stop polling, and reconnects do not reset the timeout. Explicitly test the chosen restart behavior.
+
+6. **The new binding has no size budget.** Bounding `Output` does not bound `Hosted.failed[]`. A permitted 4 MiB response can produce a report exceeding the 256 KiB frame limit ([api.go:452](/home/paulca/amadan.net/oficina/equipo-release-s1/internal/wire/api.go:452)), causing repeated rejection of a durable report.
+
+ **Fix:** Bound failed-unit count, individual names and total serialized binding size before enqueueing and when accepting reports. Reserve frame space for existing fields. Test oversized names/lists and verify truncated feedback still identifies failures without breaking delivery.
\ No newline at end of file