| 1 | # Copy specialist and failed-check routing |
| 2 | |
| 3 | Status: revised for Fable's code review of `099e42ba` and the controller's |
| 4 | v1 generic-mode decision, 2026-11-13. Paul's rulings R1–R4 remain in force. |
| 5 | Main `dc62df5` was merged into this branch as `b24a13f6`; it still uses protocol |
| 6 | 20 and migration 0080. This implementation retains protocol 21 and migration |
| 7 | 0081. The implementation and review fixes await human review and release. |
| 8 | |
| 9 | Engineering → Copy when delegated and needed → Checks → Review → the existing |
| 10 | merge gate. Copy grants no merge or deployment authority. This tooling change |
| 11 | is merged outside Equipo by the human controller, so it does not encounter |
| 12 | its own pending-copy gate. |
| 13 | |
| 14 | ## Delegation and wording |
| 15 | |
| 16 | An owner enables **Copy can accept on my behalf** per project in Settings. |
| 17 | The default is off. Store the authenticated delegating owner and a revision; |
| 18 | no migration, repository comment, notebook or deployment enables it. Paul |
| 19 | must enable it for oficina/equipo after release. Without delegation Copy does |
| 20 | not run, including proposal and learning calls. Current roster, owner role, |
| 21 | delegation revision, task revision and attempt are rechecked within each |
| 22 | write transaction, at dispatch and before publication. Revocation prevents |
| 23 | queued and already-running attempts from publishing. |
| 24 | |
| 25 | House rules come from repository guidance at the trusted base. Equipo's |
| 26 | AGENTS.md requires plain words, no em dashes and no exclamation marks. Other |
| 27 | repositories retain their own rules. Exact owner wording and placeholders |
| 28 | are preserved. When wording is uncertain, Copy accepts its best version and |
| 29 | adds a flag to the task. Ambiguous meaning produces a question and blocks |
| 30 | acceptance until answered. A wording flag does not block Checks or Review. |
| 31 | |
| 32 | ## Detection and contract |
| 33 | |
| 34 | Compare each Engineering candidate with the last accepted candidate for the |
| 35 | task, or its original base. Detect value changes regardless of acceptance |
| 36 | markers. A marker without a matching server-side Copy record for the key, |
| 37 | text hash, input candidate and current delegation is pending. Engineering |
| 38 | cannot mint those records. Record skipped detection too. Rebase and later |
| 39 | edits invalidate affected acceptance. |
| 40 | |
| 41 | The optional `.equipo/copy.json` version 1 contract declares app paths, |
| 42 | exclusions, extraction, application, acceptance, regeneration and classifier |
| 43 | commands as argument arrays. Resolve validated repository-relative paths; |
| 44 | never assemble shell text from logs. Both the contract and the executable |
| 45 | scripts are pinned to the trusted base while reading candidate files. |
| 46 | Candidate changes cannot broaden their permissions. Commands have bounded |
| 47 | input/output, a timeout, and the existing runner containment. No credential, |
| 48 | general network access or unsandboxed fallback is available to Copy. |
| 49 | |
| 50 | Extraction returns `version`, and `strings`: key, path, byte start/end of the |
| 51 | literal contents, old text, new text, context and placeholder constraints. |
| 52 | For Equipo it includes constants and runtime diagnostics in copy.go. The |
| 53 | changed set is determined from values and locations, never markers. |
| 54 | Contract Copy is one structured model call, without a worktree session: |
| 55 | `{"version":1,"strings":[{"key":"...","text":"...","action":"accept|question","flag":"..."}]}`. |
| 56 | The runner rejects duplicate/unknown keys, missing reviews, invalid actions, |
| 57 | placeholder changes and oversized output. It applies final text through the |
| 58 | base-pinned script. Tests change only by exact old-to-new string-literal |
| 59 | replacement, not substring replacement or assertion edits. Only the runner |
| 60 | invokes acceptance, after the pass, for the intersection of extracted changed |
| 61 | keys and reviewed accepted keys, backed by the server-side record. The model |
| 62 | cannot invoke acceptance or edit bookkeeping. Validate the entire final diff |
| 63 | before brokered commit and publication against the expected branch head. |
| 64 | |
| 65 | Without a contract, only delegated projects are inspected. V1 generic mode is |
| 66 | flag-only. The runner reads only diffed files in the supported Go, JS, TS, |
| 67 | JSX, TSX, JSON and HTML/template formats, excluding vendor, generated files, |
| 68 | comments, tests and docs. Unsupported file types are skipped. The deterministic |
| 69 | quoted-literal heuristic supplies possible wording, which can include technical |
| 70 | strings. Copy returns suggestions on the task card. It cannot edit or publish |
| 71 | files, update tests or bookkeeping, or establish acceptance records in this mode. |
| 72 | A generic extraction error skips that file's suggestions and does not fail the step. Empty detections |
| 73 | skip the model. Generic suggestions use the same empty model workspace and |
| 74 | structured review format as contract reviews. |
| 75 | |
| 76 | A Copy commit becomes `progress.candidate`, rather than using |
| 77 | `eng.CandidateSHA` after Copy. Old Checks and Review no longer count. No-edit |
| 78 | acceptance remains bound to the existing candidate. Track all editing model |
| 79 | families for Review independence, preserving Engineering's identity. |
| 80 | |
| 81 | ## Bookkeeping and release |
| 82 | |
| 83 | `python3 scripts/copy-status.py pending|accept|regenerate|verify` computes real |
| 84 | text hashes and synchronises copy.go markers and the consolidated Plan 3 |
| 85 | inventory. Application uses exact literal values in source and tests. Validate |
| 86 | all keys and hashes before writes; use a recoverable journal for multi-file |
| 87 | replacement. A repeat is a no-op. Preserve unrelated and historical rows. |
| 88 | Acceptance requires the runner's reviewed record; pending never creates one. |
| 89 | Release refuses pending text, stale hashes and missing inventory entries. |
| 90 | Historical human acceptances remain valid for their unchanged text. |
| 91 | |
| 92 | This implementation's UI strings receive the controller-authorised delegated |
| 93 | pass and the exact marker `COPY ACCEPTED BY DELEGATION (Astra, 2026-11-13)` in |
| 94 | copy.go and the Plan 3 inventory. Runtime Copy uses its actual reviewer and |
| 95 | bound record, never impersonates this historical pass. Rewrite AGENTS.md's |
| 96 | copy section for the pending → reviewed → runner acceptance sequence. README |
| 97 | prose is unchanged. General reference-allow reconciliation is deferred. The scoped |
| 98 | `python3 scripts/reference-allow.py` command takes explicit path, line numbers |
| 99 | and owner reason as bounded JSON, computes exact hashes, and preserves all |
| 100 | unrelated entries. Recovery accepts those inputs from the authenticated owner. |
| 101 | |
| 102 | ## Failure classification and repair rounds |
| 103 | |
| 104 | The runner fetches the full logs of failed units from the exact SHA and CI run |
| 105 | observed by Checks, up to the adapter's 2 MiB JSON input limit. Sharded steps use |
| 106 | their failed shards' logs, never aggregate logs containing successful retries. |
| 107 | A hosted 60-line display tail is not evidence truncation. Local evidence reaching |
| 108 | 200 lines or 32 KiB is conservatively incomplete. A package-level FAIL without |
| 109 | an associated named test is classified as other. Set incomplete only when |
| 110 | units or evidence were actually cut, or the run changed or could not be read. |
| 111 | The adapter accounts for each failed unit separately, including the reference |
| 112 | scan command and its matching test. Unclassified evidence remains other. |
| 113 | |
| 114 | Hosted evidence consists of at most 20 `HostedResult.Failed` unit names and |
| 115 | the final 60 log lines. A base-pinned classifier command receives |
| 116 | `{"version":1,"units":["..."],"log":"...","truncated":true|false}`. |
| 117 | It returns `{"version":1,"complete":true|false,"failures":[{"unit":"...","test":"...","code":"...","subject":"...","category":"copy|bookkeeping|other"}]}`. |
| 118 | Every failed unit must be represented. Unknown units or diagnostics become |
| 119 | `other`; malformed output, missing units, truncated evidence or failed |
| 120 | classification produces an incomplete signature. A bounded deterministic |
| 121 | recheck may supply complete evidence; a log never authorises a command. |
| 122 | The generic runner has no Equipo-specific test names. Equipo's script |
| 123 | recognises only explicit copy/inventory failures; broad test-lane failures |
| 124 | cannot be declared copy-only without complete diagnostic evidence. |
| 125 | |
| 126 | Persist version, completeness, adapter identity, normalised sorted failure |
| 127 | set, hash, source step/attempt and candidate. Stable identities include gate, |
| 128 | test/subtest, diagnostic code and subject, excluding time, temporary roots, |
| 129 | commit IDs and line drift. Before the second automatic repair, stop only if |
| 130 | both signatures are complete, adapter-classified and equal. Unknown never |
| 131 | equals unknown, including two empty sets. Review-driven changes-requested |
| 132 | rounds retain the normal cap. Partial overlap does not cause early stop. |
| 133 | |
| 134 | Persist `RepairRound` on the task, shared across Engineering, Copy and |
| 135 | bookkeeping, initialised from recorded Engineering rounds. A normal Copy pass |
| 136 | following Engineering is part of that round. Restart or switching roles never |
| 137 | resets it. Two automatic repairs remain the normal cap. A complete copy-only |
| 138 | failure schedules Copy; accepted wording with missing bookkeeping schedules |
| 139 | scripts without a model. Complete bookkeeping-only failures use only declared |
| 140 | commands with established inputs. Mixed/other failures go to Engineering. |
| 141 | Judgement, repeated failures and exhausted limits use the existing task-linked |
| 142 | coordinator path with evidence, attempts, candidates and a recommendation. |
| 143 | |
| 144 | Normal mechanical repairs consume the existing daily automatic allowance of |
| 145 | three as well as the task cap. Preserve housekeeping source snapshots, |
| 146 | consumed keys and transaction guards, including cancelled, held, folded, |
| 147 | ended or merging tasks, removed owners and paused automation. A transient |
| 148 | Copy stop gets the existing single retry only after proven termination. Terminal |
| 149 | Copy failures and pre-launch budget holds expose Continue without Copy to the |
| 150 | task creator. That authenticated decision is bound to the current candidate; |
| 151 | it resumes Checks/Review without granting string acceptance. Disabling delegation |
| 152 | withdraws queued Copy and releases waiting tasks. Started work is cancelled and |
| 153 | must prove termination before the next step. Stale delegation at reconnect is |
| 154 | a withdrawal, never a runner connection error. A repeated-failure round action |
| 155 | requires the newest step to be done, so a second tap cannot queue another round. |
| 156 | |
| 157 | ## Learning and limits |
| 158 | |
| 159 | Only the delegating owner's own authenticated edits made in Equipo teach |
| 160 | Copy. Imported copy-review results are submitted by that same authenticated |
| 161 | owner through a bounded JSON import: `version:1`, stable `source_id`, and |
| 162 | `strings` containing key, original text, final text and optional reason. |
| 163 | Validate the before/after association to that owner's Copy record and dedupe |
| 164 | by owner, repository and source ID. The same import also accepts approved |
| 165 | copy-review result.json files with id/original/text/edited/done/rerolled entries. |
| 166 | Only completed human edits are imported; model rerolls and unchanged strings |
| 167 | are excluded, and legacy entries over the 400-byte example limit are skipped |
| 168 | without rejecting the other edits. The imported Before is the reviewed original, so historical |
| 169 | results do not require a server-side Copy record that did not yet exist. A |
| 170 | stable content identity deduplicates each result. Reject imports and edit events from other |
| 171 | owners or members; never trust an owner ID in the payload. No forge-diff, |
| 172 | commit-author or notebook inference supplies teaching evidence. |
| 173 | |
| 174 | Store exact before/after examples and reasons in an owner/repository Copy |
| 175 | feedback ledger, separate from coordinator and Assistant notes. V1 derives |
| 176 | its notebook directly from those verified examples and makes no inferred |
| 177 | rules or compaction model calls. Notes cannot grant authority. The notebook |
| 178 | view is bounded at 40 entries, 400 bytes each and 6 KiB, within the existing |
| 179 | 12 KiB notebook ceiling. Lookup errors deny dispatch; they never become an |
| 180 | empty notebook. Notebook inspect/clear UI is deferred. |
| 181 | |
| 182 | Before including learned examples, check housekeeping’s existing |
| 183 | 37,500-token reservation against its shared four-turn/150,000-token daily |
| 184 | budget. When turns or tokens are spent, or housekeeping is paused, leave new examples |
| 185 | pending and keep reading the already learned notebook. Promotion is recorded |
| 186 | once on each source event, scoped to its owner and repository. V1 reads verified edits directly, so it charges no learning |
| 187 | model tokens or turns. An explicit owner correction on the current task is |
| 188 | an instruction and applies even while notebook learning is deferred. |
| 189 | Copy reviews use cheap/standard models, with a hard standard ceiling for both |
| 190 | subscription and metered connections. No fallback above the ceiling. Default |
| 191 | structured-call limits are 32,768 tokens and five minutes per pass, and 98,304 |
| 192 | per task across attempts. Before model admission, include only AGENTS.md's Copy |
| 193 | section and estimate the complete request, tool schema and response. The |
| 194 | conservative estimate counts one token per byte, 4,096 tokens for provider |
| 195 | framing, and comparable reply text plus 160 bytes per key. The checked baseline fixture |
| 196 | contains 56 actual app strings: 12,028 prompt bytes and a 28,554-token estimate. |
| 197 | The pass limit leaves 4,214 tokens above that estimate; the task limit allows |
| 198 | three full-pass allowances. Larger string sets are split into structured calls |
| 199 | that each fit the per-pass estimate. The complete batch must fit the remaining |
| 200 | task allowance before launch, and measured spend is checked before each next |
| 201 | call. Reviewed wording is applied only after the entire review is complete. A batch that |
| 202 | cannot fit stops with the token-allowance reason and Continue without Copy. These are estimates, not a promise about the model's exact tokenization. |
| 203 | |
| 204 | Measured accounting matches the Usage page's `rowSpend` in |
| 205 | `internal/equipo/chat/connections.go`: Claude adds separate cache reads and writes |
| 206 | to input/output; other providers include cache reads in input already. Unknown |
| 207 | usage is charged as a full pass, allowing the remaining task budget to be used. |
| 208 | A complete valid review is retained even on overrun or missing usage. Actual |
| 209 | overruns remain charged. Script-only bookkeeping has no model spend. |
| 210 | |
| 211 | ## Protocol, migration and rollout |
| 212 | |
| 213 | ProtocolCopy is 21; app migration 0081 is additive and registered in Models |
| 214 | and Schema. The runner uses idempotent additive schema statements, with no numbered |
| 215 | migration sequence. Its new `copy_attempts` table preserves per-attempt |
| 216 | usage and the structured result across restart and downgrade. Wire data binds comparison, review hashes, delegation revision, |
| 217 | budget remainder and failure evidence to runner/task/step/attempt. Old peers |
| 218 | never receive Copy disguised as Engineering and cannot silently lose required |
| 219 | acceptance data. Review dispatch drops AvoidFamilies below protocol 21. Hold Copy steps until both peers support Copy, including |
| 220 | after reconnect. Existing undelegated work continues on old peers. |
| 221 | |
| 222 | No migration grants delegation or acceptance. Preserve existing repair counts |
| 223 | and unknown signatures. Copy runs on the task’s existing primary runner, |
| 224 | with the project’s delegating owner recorded separately; this preserves |
| 225 | branch-publication ownership in teams with several owners. Deploy scripts and guards, then compatible runners |
| 226 | and instance, then Paul enables the project setting in Settings. For downgrade, |
| 227 | turn delegation off first and settle affected tasks as cancelled or merged. |
| 228 | Then stop runners and run the previous version with additive columns/tables |
| 229 | retained. Older instances do not enforce Copy, so do not downgrade the instance |
| 230 | with pending Copy work. Never drop review, feedback, recovery or budget history. |
| 231 | |
| 232 | ## Owner-triggered recovery |
| 233 | |
| 234 | After the versioned release, Paul enables delegation and explicitly requests |
| 235 | one recovery action per exact task ID and current candidate. This one-off is |
| 236 | exempt from the daily automatic-round allowance. The same recovery key may retry a failed, terminated attempt, but cannot duplicate an active or successful attempt. It can run after the normal |
| 237 | task cap. Persist a durable recovery key and preserve old round/spend history. |
| 238 | Re-fetch current heads and checks; only complete copy/bookkeeping-only failures |
| 239 | qualify. Unknown or truncated results remain held for judgement. For retained |
| 240 | references the owner supplies exact paths, line numbers and reasons in the |
| 241 | recovery form. No model or log supplies reference approval. Rebase legacy branches onto the reviewed tooling revision, resolving |
| 242 | copy.go bookkeeping conflicts by extracting final literal values and |
| 243 | regenerating markers/inventory with the pinned scripts. A conflict in product |
| 244 | meaning asks the owner. Never run candidate-supplied recovery scripts. |
| 245 | |
| 246 | | Task prefix (resolve to exact ID before acting) | Recovery | |
| 247 | | --- | --- | |
| 248 | | tk25j65kpelv, tkizl6frmnij, tknitqeua7yy | Reconfirm copy-only evidence, review strings, regenerate records, then fresh Checks and Review | |
| 249 | | tk3j4tcivyrx | Reconfirm bookkeeping-only evidence and exact retained references; scoped repair, then fresh Checks and Review | |
| 250 | | tkplvk6zce6q | Real conversation 500 still needs Engineering | |
| 251 | | tkataquuxfrw | Real headless failures still need Engineering | |
| 252 | |
| 253 | These are supplied observations, not fresh diagnoses. Never operate by prefix |
| 254 | or recover mixed failures automatically. Merge remains the existing human |
| 255 | policy. This branch is pushed and reviewed, never merged by its implementer. |
| 256 | |
| 257 | ## Verification |
| 258 | |
| 259 | Tests first, each observed failing before implementation. Mutate and restore |
| 260 | guards for forged acceptance, out-of-scope edits, unknown-equals-unknown, |
| 261 | non-owner learning and disabled delegation. Target browser checks at the |
| 262 | setting and flagged-wording task card. Cover structured output, placeholders, |
| 263 | trusted-base commands, recovery idempotence, shared rounds, candidate changes, |
| 264 | model ceilings, interrupted bookkeeping, protocol mixed versions and additive |
| 265 | migration/downgrade. Only targeted Go and browser tests run locally; hosted CI |
| 266 | runs the rest. Run budget, dead-reference, lanes and copy-release checks. |
| 267 | Record exact commands, failures, restored passes, CI SHA and recovery steps in |
| 268 | `../report2.md` and poll hosted CI to completion after pushing. |
| 269 | |