| 1 | # Self-healing coordinator |
| 2 | |
| 3 | Implemented on `self-heal`, from the dispatched brief commit `cac8b11` |
| 4 | (main base `80c15d0`). Commit only; no push, merge or deployment. |
| 5 | New runtime copy is individually marked `COPY REVIEW PENDING` in |
| 6 | `internal/equipo/copy.go` and listed in the existing copy inventory. |
| 7 | No copy-review server was started. README prose is unchanged. |
| 8 | |
| 9 | ## Changes |
| 10 | |
| 11 | The runner runs the pinned official CLI in the dedicated source home while |
| 12 | holding the existing directory lock, before staging any runtime login. |
| 13 | Claude 2.1.312 uses `auth status --json`; its startup performs and awaits |
| 14 | native refresh. Codex 0.165.0 uses app-server `account/read` with |
| 15 | `refreshToken:true`, after initialization. Neither path starts a model turn. |
| 16 | Equipo consumes account metadata only and does not extract refresh tokens. |
| 17 | The executable digests are checked before maintenance. |
| 18 | |
| 19 | Saved-account setup and generic discovery also probe the locked source home. |
| 20 | An unconfined native CLI probe rejects a staged binding. This closes the setup |
| 21 | path as well as the dispatch path. |
| 22 | |
| 23 | The source lock stays held throughout the attempt, so maintenance cannot |
| 24 | run alongside a turn. Runtime copies expire after 25 minutes, which covers |
| 25 | the existing 20-minute coordinator attempt limit. A production lease cannot |
| 26 | commit runtime credentials back to its source. Runtime network policy still |
| 27 | excludes the refresh hosts; Claude refresh uses platform.claude.com and Codex |
| 28 | uses auth.openai.com. Owner mode uses the same isolation and needs no new |
| 29 | certification. Certified mode continues to enforce its policy hashes. |
| 30 | |
| 31 | Temporary maintenance failures remain retryable. A native missing-login result |
| 32 | or a recognized terminal refresh rejection produces `account.sign_in_again`. |
| 33 | That connection gets one conversation note containing its exact command, |
| 34 | including the dedicated-home environment, pinned executable and directory lock. |
| 35 | Repeated polls do not repeat that note. No credentials are included in reports. |
| 36 | |
| 37 | Coordinator settings now show the current connection and the automatic-selection |
| 38 | reason. The binding picker and its Save/Reset controls are gone; the obsolete |
| 39 | binding form action is rejected. Recovery reset actions remain available for |
| 40 | uncertain work. On each new message and poll, selection prefers a currently |
| 41 | healthy report, then fewer active tasks, then the latest report. Only the |
| 42 | person's own enrolled runners qualify. An admitted attempt with pending |
| 43 | containment cannot be moved or cancelled by automatic selection. |
| 44 | |
| 45 | Projects without an explicit budget inherit the team ceiling. Job creation, |
| 46 | plan admission, reservation headroom, usage reads and bug preparation agree |
| 47 | on this rule. Explicit project caps and aggregate team caps still apply. |
| 48 | Temporary connection and admission waits stay in the thinking bubble, name |
| 49 | the connection and retry on polling. Missing bindings are retried when a |
| 50 | runner becomes available. Routine fallback no longer adds system notes. |
| 51 | |
| 52 | `equipo_status` accepts no caller-supplied scope. The normal claim, handle and |
| 53 | current-roster checks apply before it returns the person's runners and |
| 54 | connections, team budgets, coordinator usage and permitted projects. It excludes |
| 55 | credentials, home paths, machine keys and other people's connections. Stale |
| 56 | heartbeats are reported as unavailable. A deleted selected connection still |
| 57 | renders a waiting conversation; database failures remain errors. |
| 58 | |
| 59 | ## Verification |
| 60 | |
| 61 | Behavioral failures observed before implementation: |
| 62 | |
| 63 | - `CGO_ENABLED=0 go test ./internal/equipo/team -run TestSelfHeal -count=1`: |
| 64 | failed with `job needs configured project`; passed after inheritance. |
| 65 | - `CGO_ENABLED=0 go test ./internal/runner/provider -run TestSourceRefresh -count=1`: |
| 66 | failed because staging retained the old login and failed refresh still staged. |
| 67 | - `CGO_ENABLED=0 go test ./internal/coordinator -run TestEquipoStatusSchema -count=1`: |
| 68 | rejected the new read-only tool before implementation. |
| 69 | - `CGO_ENABLED=0 go test ./internal/plan3test -run TestSelfHeal -count=1`: |
| 70 | failed for the missing live wait bubble and the remaining picker. |
| 71 | - `CGO_ENABLED=0 go test ./internal/runner/provider -run TestSourceRefreshLease -count=1`: |
| 72 | admitted an expired staged lease before the lifetime guard. |
| 73 | - `CGO_ENABLED=0 go test ./internal/runner/provider -run TestRefreshRevocationCodes -count=1`: |
| 74 | failed to distinguish terminal refresh rejections before classification. |
| 75 | - `CGO_ENABLED=0 go test ./internal/runner/provider -run TestRefreshUsesOfficialCLIWithoutTurn -count=1`: |
| 76 | the added staged-home case failed because an unconfined CLI accepted the copy. |
| 77 | - `CGO_ENABLED=0 go test ./internal/ownermodetest -run TestSelfHealRemovedConnection -count=1`: |
| 78 | returned a not-found error for the waiting conversation before correction. |
| 79 | |
| 80 | Each mutation below was applied alone, tested with `CGO_ENABLED=0 go test` |
| 81 | and `-count=1`, and restored immediately. All eleven tests failed at their |
| 82 | behavior assertion, not at compilation: |
| 83 | |
| 84 | | Broken guard | Package and test | |
| 85 | | --- | --- | |
| 86 | | Skip source refresh | `./internal/runner/provider -run ^TestSourceRefreshBeforeStageUnderLock$` | |
| 87 | | Remove source flock | Same test | |
| 88 | | Ignore changed identity | `./internal/runner/provider -run ^TestSourceRefreshFailureDoesNotStage$` | |
| 89 | | Ignore staged lifetime | `./internal/runner/provider -run ^TestSourceRefreshLeaseExpiresAndCannotWriteBack$` | |
| 90 | | Permit runtime writeback | Same test | |
| 91 | | Send Codex refreshToken:false | `./internal/runner/provider -run ^TestRefreshUsesOfficialCLIWithoutTurn$` | |
| 92 | | Repeat sign-in note | `./internal/plan3test -run ^TestSelfHealRevokedLoginNotifiedOnce$` (subsequently moved to `./internal/ownermodetest`) | |
| 93 | | Prefer the busier connection | `./internal/plan3test -run ^TestSelfHealBusyConnectionFailsOver$` | |
| 94 | | Permit active-turn fallback | `./internal/plan3test -run ^TestSelfHealFailoverDoesNotMoveActiveTurn$`; caught cancellation of the active job | |
| 95 | | Remove the status runner-person filter | `./internal/ownermodetest -run ^TestSelfHealStatusIsScopedAndRevocationApplies$`; caught another person's runner label | |
| 96 | | Treat a stale heartbeat as available | `./internal/ownermodetest -run ^TestSelfHealStatusDoesNotCallStaleReportsAvailable$` | |
| 97 | |
| 98 | Restored targeted tests cover source refresh and CLI failures, picker removal, |
| 99 | status scope and roster revocation, one-time login notices, busy failover, |
| 100 | active-attempt fencing, inherited budgets and project-card-to-work admission. |
| 101 | Existing tests were updated where they required the removed picker, repeated |
| 102 | setup notes, or rejection of an unset project budget. Their authority, |
| 103 | transaction rollback and accounting assertions remain. |
| 104 | |
| 105 | ## Live proof |
| 106 | |
| 107 | Only the authorized paul@tito.io `claude-a` home was used. With the production |
| 108 | runner briefly stopped and the source directory exclusively locked, pinned |
| 109 | Claude `auth status --json` exited 0, reported the expected identity, and |
| 110 | changed the credential file's modification time. The proof inspected metadata |
| 111 | only; it did not read, print or copy credential contents. The runner was |
| 112 | restarted immediately. The brief reported this login as expired. The proof used |
| 113 | it unchanged; no credential was edited to manufacture an expiry. Codex refresh |
| 114 | is covered by fake CLI tests; |
| 115 | no live Codex account was used. |
| 116 | |
| 117 | `CGO_ENABLED=0 make e2e-live` passed twice, in 91.8 seconds and 95.6 seconds. |
| 118 | Its fake CLI prerequisites passed too. The final browser run confirmed no |
| 119 | coordinator picker, proposed a project, clicked Set up, then received a second |
| 120 | admitted coordinator reply with `Projects:null` still in the budget record. |
| 121 | The coordinator called `equipo_status` successfully. Each passing run used two |
| 122 | coordinator turns. No specialist model work ran. |
| 123 | |
| 124 | Other live harness attempts consumed five coordinator turns. One stopped on |
| 125 | a browser-helper error. Two encountered the setup card being replaced by a |
| 126 | late live update. One two-turn run created the project but its subsequent |
| 127 | reply became contained and uncertain. That run did not silently redispatch. |
| 128 | The final test waits for containment, opens the settled conversation, and |
| 129 | explicitly requires the reply through `post_message`. Metadata-only failure |
| 130 | diagnostics are now included in the harness. Total live coordinator turns: |
| 131 | nine, below the authorized twenty. The production runner was left active. |
| 132 | |
| 133 | ## Final gates and handoff |
| 134 | |
| 135 | The first `CGO_ENABLED=0 make -k ci` completed all lanes. It failed the |
| 136 | reference inventory, size gate and tests that still expected the previous |
| 137 | setup notes, picker and coordinator inventory. It also caught an onboarding |
| 138 | probe error regression and a synthetic-policy test that now crossed the new |
| 139 | executable verification boundary. Targeted checks pass after correction. |
| 140 | The synthetic test now enters the shared policy builder with its synthetic |
| 141 | lease; production still verifies executable digests before source maintenance. |
| 142 | The two changed coordinator inventory hashes remain explicitly uncertified. |
| 143 | |
| 144 | Build, vet, staticcheck, govulncheck, gitleaks, adapter checks, namespace checks, |
| 145 | migration checks and performance passed in that first full run. Local timing |
| 146 | notes reflect shared-machine load; no budget ceilings were raised. The size |
| 147 | gate passes after moving diagnostics and test helpers to their feature packages. |
| 148 | The reference inventory contains three new exact entries, including the |
| 149 | controller's authorization in the original brief. |
| 150 | |
| 151 | Both permitted full reruns passed every gate with exit 0. Exactly three full |
| 152 | `CGO_ENABLED=0 make -k ci` runs were made. The final run tested 41 packages, |
| 153 | with zero failures, then passed adapter, namespace, migration and performance |
| 154 | checks. Cold boot had a 167 ms median against the 500 ms limit. All screen |
| 155 | performance checks passed. |
| 156 | |
| 157 | The final local run reported timing advisories: runner 371.68 s against 330 s, |
| 158 | discovery tests 10.662 s against 10 s, provider 22.654 s against 15 s, Claude |
| 159 | 49.786 s against 45 s, and Codex 41.921 s against 35 s. These are advisory |
| 160 | locally but become failures when CI or AMADAN_CI is set. No ceilings were raised. |
| 161 | The last two status mutations were made after the full gate, restored byte for |
| 162 | byte, and followed by passing targeted status and refresh tests. |
| 163 | |
| 164 | Scratch logs and disposable test environments are removed. No review server |
| 165 | or test process remains. The pre-existing production runner is active, as |
| 166 | required. The controller can review and push this local commit; pending copy |
| 167 | still needs its release review. Nothing was pushed, merged or deployed. |
| 168 | |