| 1 | # Runner start: heartbeat report encoding |
| 2 | |
| 3 | The runner exits because its first heartbeat contains account reports encoded |
| 4 | with Go field names (`LocalID`, `Routing`, `AccountID`). The heartbeat handler |
| 5 | uses the strict protocol decoder, which requires `local_id`, `routing` and |
| 6 | `account_id`. The exact failing check is `runnerproto.DecodeLimit` on |
| 7 | `q.Reports` in `Handler.runnerConnections`, before `ReportConnections` runs. |
| 8 | The instance returns HTTP 422 with `form.invalid`; the client unwraps that |
| 9 | refusal as `provider.ErrContract` and previously discarded its location. |
| 10 | |
| 11 | This is a code defect, not a local configuration error. No edit to |
| 12 | `runner.env`, bindings, installed releases or the service was made. The |
| 13 | existing `runner.env.before-enable-execution` backup remains in place. |
| 14 | No credential files or account homes were inspected by investigation commands. |
| 15 | The explicitly authorized foreground runner uses its own normal credential and |
| 16 | account discovery paths. No account login or model task was requested. |
| 17 | |
| 18 | ## Reproduction and change |
| 19 | |
| 20 | The service was inactive before and after the investigation. The initial |
| 21 | literal empty-environment run exited 1 with `runner.policy at EQUIPO_CODEX_PATH`: |
| 22 | without `HOME`, the protected home paths are relative. Systemd supplies `HOME` |
| 23 | to the actual user service. Adding only that standard variable reproduced the |
| 24 | journal's `runner.contract at -`, exit 1: |
| 25 | |
| 26 | ```sh |
| 27 | timeout --signal=TERM --kill-after=5s 40s env -i HOME=/home/paulca \ |
| 28 | /bin/bash --noprofile --norc -c ' |
| 29 | set -a |
| 30 | . /home/paulca/.local/share/equipo-runner/runner.env |
| 31 | set +a |
| 32 | exec /home/paulca/.local/share/equipo-runner/releases/9f616f3/equipo-runner run |
| 33 | ' |
| 34 | ``` |
| 35 | |
| 36 | A disposable Go overlay added safe stage/status diagnostics. With the same |
| 37 | environment, it returned `runner.contract at http.heartbeat.status_422.form.invalid`. |
| 38 | No request body, response prose, token or account-home content was logged. |
| 39 | |
| 40 | `HTTPInstance.Heartbeat` now uses `runnerproto.Marshal` for its nested reports. |
| 41 | The outer protocol encoder preserves `json.RawMessage`, so it cannot repair |
| 42 | ordinary JSON inside that field. Persisted report JSON remains unchanged. |
| 43 | HTTP contract failures now identify status, envelope decoding, version or |
| 44 | result decoding. Refusals retain their typed status/reason and `errors.Is` / |
| 45 | `errors.As` behavior. Unknown remote reasons become the existing fixed |
| 46 | `form.invalid` code. The original failure now prints: |
| 47 | |
| 48 | ```text |
| 49 | Runner error runner.contract at http.response.status_422.form.invalid. |
| 50 | ``` |
| 51 | |
| 52 | No app copy was added or changed. The existing diagnostic format is reused; |
| 53 | new diagnostic locations are protocol check identifiers. No copy-review server |
| 54 | was started, as instructed. |
| 55 | |
| 56 | ## Verification |
| 57 | |
| 58 | The new tests ran in the runner package before implementation: |
| 59 | |
| 60 | ```sh |
| 61 | CGO_ENABLED=0 go test ./internal/runner \ |
| 62 | -run '^TestRunnerHeartbeatWireReports$|^TestRunnerHTTPContractDiagnostics$' -count=1 |
| 63 | ``` |
| 64 | |
| 65 | Exit 1: the two-account heartbeat failed against the real protocol HTTP handler, |
| 66 | and all six diagnostic cases failed. The heartbeat test also covers empty and |
| 67 | nil account lists. The diagnostic test checks safe refusal codes, redirect |
| 68 | rejection, invalid JSON, wrong protocol version and invalid result shape. |
| 69 | |
| 70 | After implementation, this targeted command passed. The new tests now live in |
| 71 | `internal/runner/transporttest`, using the public client against loopback HTTP |
| 72 | servers and the real heartbeat handler: |
| 73 | |
| 74 | ```sh |
| 75 | CGO_ENABLED=0 go test ./internal/runner/transporttest ./internal/runner ./internal/equipotest \ |
| 76 | -run '^TestRunnerHeartbeatWireReports$|^TestRunnerHTTPContractDiagnostics$|^TestRunnerHTTPClient|^TestDirectBugRuntimeRenewHeartbeat$|^TestDirectClaimRevalidates$|^TestRunnerHeartbeatAndValidatedReceipt$|^TestRunnerAppCSRF$' \ |
| 77 | -count=1 |
| 78 | ``` |
| 79 | |
| 80 | Seven independent mutations used disposable overlays in |
| 81 | `/home/paulca/.cache/tmp/equipo-runner-start`. For each name below: |
| 82 | |
| 83 | ```sh |
| 84 | CGO_ENABLED=0 go test -overlay=/home/paulca/.cache/tmp/equipo-runner-start/NAME.json \ |
| 85 | ./internal/runner/transporttest \ |
| 86 | -run '^TestRunnerHeartbeatWireReports$|^TestRunnerHTTPContractDiagnostics$' -count=1 |
| 87 | ``` |
| 88 | |
| 89 | | NAME | Deliberately broken behavior | Result | |
| 90 | | --- | --- | --- | |
| 91 | | wire | Restore ordinary JSON for reports | Exit 1, two-account heartbeat rejected | |
| 92 | | refusal | Remove refusal location | Exit 1, refusal diagnostic assertions | |
| 93 | | status | Remove unexpected-status location | Exit 1, redirect diagnostic assertion | |
| 94 | | envelope | Remove envelope location | Exit 1, malformed-envelope assertion | |
| 95 | | version | Remove version location | Exit 1, wrong-version assertion | |
| 96 | | result | Remove result location | Exit 1, wrong-result assertion | |
| 97 | | redaction | Use the raw remote error code | Exit 1, untrusted reason exposed | |
| 98 | |
| 99 | The unchanged working sources passed the targeted command again after the |
| 100 | mutations. No mutation was applied to the working source files. |
| 101 | |
| 102 | A second temporary overlay only printed successful heartbeat/report counts |
| 103 | and poll/assignment counts. Built with `CGO_ENABLED=0 go build -overlay=...` |
| 104 | and run with the same environment under a 35-second timeout, it recorded: |
| 105 | |
| 106 | ```text |
| 107 | probe: heartbeat accepted, reports=2 |
| 108 | probe: poll accepted, assignments=0 |
| 109 | probe: heartbeat accepted, reports=2 |
| 110 | ``` |
| 111 | |
| 112 | SIGTERM stopped the foreground process at the deadline; `timeout` returned 124. |
| 113 | Two `runner.poll_retry` lines appeared as cancellation interrupted polling. |
| 114 | The runner reached the job loop and reported both configured accounts. This |
| 115 | proves report acceptance, not that both accounts passed provider preflight. |
| 116 | No authenticated browser session was used to inspect the app. |
| 117 | |
| 118 | One full `make -k ci` completed with exit 2. Its only failing target was |
| 119 | `budget`: the initial test file took `internal/runner` from 8798 to 8902 test |
| 120 | lines against its existing 8800 ceiling. The tests were moved into |
| 121 | `internal/runner/transporttest`, using the public client and loopback HTTP |
| 122 | servers. `make budget` then passed with all 40 directories within budget. |
| 123 | No budget was raised. The final tests and all seven mutations passed in their |
| 124 | new package. There was no second full CI run; the original full gate remains |
| 125 | recorded as failed, with its size failure corrected by the focused rerun. |
| 126 | |
| 127 | The full test step ran 30 packages, none cached, with zero failures. Build, |
| 128 | vet, formatting, staticcheck, govulncheck, gitleaks, reference inventory, |
| 129 | adapter checks, namespace checks, migrations and performance all passed. |
| 130 | Cold boot median was 250 ms against the 500 ms limit. After moving the tests, |
| 131 | `make budget vet staticcheck fmt-check runner-dead-references` passed again. |
| 132 | |
| 133 | Local timing overruns were advisory; these timings would fail under CI timing |
| 134 | enforcement. No time allowance was changed: |
| 135 | |
| 136 | | Package | Measured seconds | Budget seconds | |
| 137 | | --- | ---: | ---: | |
| 138 | | directlive | 518.394 | 360 | |
| 139 | | equipotest | 336.270 | 300 | |
| 140 | | runner | 539.301 | 330 | |
| 141 | | runner/forge | 15.751 | 15 | |
| 142 | | runner/provider | 23.431 | 15 | |
| 143 | | runner/provider/claude | 51.572 | 45 | |
| 144 | | runner/provider/codex | 43.410 | 35 | |
| 145 | |
| 146 | ## Controller: install the reviewed runner, then restart |
| 147 | |
| 148 | Restarting the installed `9f616f3` runner alone will repeat the failure. After |
| 149 | review and human merge, use a clean checkout of the chosen version on docs-t1. |
| 150 | Build a versioned runner release with the existing certified executable paths: |
| 151 | |
| 152 | ```bash |
| 153 | set -euo pipefail |
| 154 | umask 077 |
| 155 | set -a |
| 156 | . "$HOME/.local/share/equipo-runner/runner.env" |
| 157 | set +a |
| 158 | make release-runner |
| 159 | EQUIPO_START_VERSION=$(git rev-parse --short HEAD) |
| 160 | EQUIPO_START_ROOT="$HOME/.local/share/equipo-runner" |
| 161 | EQUIPO_START_RELEASE="$EQUIPO_START_ROOT/releases/$EQUIPO_START_VERSION" |
| 162 | EQUIPO_START_SOURCE="$PWD/releases/equipo-runner-linux-amd64-$EQUIPO_START_VERSION" |
| 163 | mkdir "$EQUIPO_START_RELEASE" |
| 164 | install -m 700 "$EQUIPO_START_SOURCE/equipo-runner" "$EQUIPO_START_RELEASE/" |
| 165 | install -m 700 "$EQUIPO_START_SOURCE/equipo-tool-proxy" "$EQUIPO_START_RELEASE/" |
| 166 | install -m 600 "$EQUIPO_START_SOURCE/install-manifest.json" "$EQUIPO_START_RELEASE/" |
| 167 | "$EQUIPO_START_RELEASE/equipo-runner" verify-install-manifest \ |
| 168 | "$EQUIPO_START_RELEASE/install-manifest.json" >/dev/null |
| 169 | export EQUIPO_START_ROOT EQUIPO_START_RELEASE EQUIPO_START_VERSION |
| 170 | python3 - <<'PY' |
| 171 | import os, pathlib |
| 172 | root = pathlib.Path(os.environ['EQUIPO_START_ROOT']) |
| 173 | service = root / 'equipo-runner.service' |
| 174 | old = service.read_bytes() |
| 175 | before = b'ExecStart=' + bytes(str(root / 'releases/9f616f3/equipo-runner'), 'utf-8') + b' run' |
| 176 | after = b'ExecStart=' + bytes(os.environ['EQUIPO_START_RELEASE'] + '/equipo-runner', 'utf-8') + b' run' |
| 177 | assert old.count(before) == 1, 'Service changed; reconcile its current release first' |
| 178 | backup = root / ('equipo-runner.service.before-' + os.environ['EQUIPO_START_VERSION']) |
| 179 | with backup.open('xb') as f: |
| 180 | f.write(old) |
| 181 | service.write_bytes(old.replace(before, after)) |
| 182 | service.chmod(0o600) |
| 183 | PY |
| 184 | systemctl --user daemon-reload |
| 185 | systemctl --user restart equipo-runner.service |
| 186 | systemctl --user is-active equipo-runner.service |
| 187 | systemctl --user status equipo-runner.service --no-pager |
| 188 | journalctl --user -u equipo-runner.service --since '2 minutes ago' --no-pager |
| 189 | ``` |
| 190 | |
| 191 | The existing tool-proxy path can stay in `runner.env`: that binary is unchanged |
| 192 | and the release gate verifies its certified hash. The new runner uses |
| 193 | `os.Executable()`, so the old `EQUIPO_RUNNER_EXECUTABLE` value is ignored and |
| 194 | needs no edit. No re-enrolment is needed. These are controller commands; this |
| 195 | session did not install a release, start the unit, merge or deploy. |
| 196 | |
| 197 | Sign in at |
| 198 | [https://equipo.bds.oncarlos.com/connections](https://equipo.bds.oncarlos.com/connections). |
| 199 | Refresh after startup and confirm cards for `claude-a` and `claude-b`, both |
| 200 | showing Claude `2.1.312`. Neither should show the preflight-unavailable or |
| 201 | sign-in-again message when ready. Connection availability expires after 90 |
| 202 | seconds without a report, so refresh again after that interval with the unit |
| 203 | still active to confirm continuing heartbeats. The enrolled-machine page at |
| 204 | [https://equipo.bds.oncarlos.com/runners/enrol](https://equipo.bds.oncarlos.com/runners/enrol) |
| 205 | should list `docs-t1`, but that page has no online badge and enrolment alone |
| 206 | does not prove liveness. Use the active unit plus fresh, available connection |
| 207 | cards. If a card remains unavailable, report its state before requesting work; |
| 208 | accepted heartbeat reports can correctly describe an unavailable account. |
| 209 | |
| 210 | Task scratch, temporary overlay binaries and logs were removed. The foreground |
| 211 | runner and all task test servers exited; the systemd unit remains inactive. |
| 212 | The change is committed on `runner-start` for push to `origin/runner-start`. |
| 213 | Human review, versioned installation and restart remain with the controller. |
| 214 | |