oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

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