| 1 | # Equipo: needs-you triage, thin v1 |
| 2 | |
| 3 | Status: 2026-11-11, revision 2.1 ("thin v1"), built. Revision 1 (3ab0e85) |
| 4 | drew NOT READY from Astra round 1 (§10); the coordinator cut the scope so |
| 5 | it converges: no new turn kind, no wire change, no split. Revision 2 |
| 6 | drew READY AFTER FIXES from round 2; its seven findings are folded in |
| 7 | (§11). Paul then asked for a loop that carries tasks through to the end |
| 8 | (§2.5). Drafted by Claude |
| 9 | (Opus 5.5) on `needs-you-triage` from main 8d7f217. Builds on thin v1, |
| 10 | housekeeping (§§3-4: the ledger, the day budget, the principal), merge |
| 11 | authority (the gate, unchanged) and release slice 1 (hosted checks). |
| 12 | |
| 13 | ## 0. Why |
| 14 | |
| 15 | Paul, on staging's six Needs you items: "I feel like a bunch of this stuff |
| 16 | doesn't actually need me." Ruled 2026-11-11: Needs you holds only |
| 17 | decisions only Paul can make; a step that stopped for a passing reason is |
| 18 | retried once on its own, within the retry budget; spend is first-class. |
| 19 | |
| 20 | Staging, read from its replica at 20:37 UTC: |
| 21 | |
| 22 | | Task | Needs you today | What the rows say | Thin v1 | |
| 23 | |---|---|---|---| |
| 24 | | Swipe from the edge | `fix_rounds` | round 2 approved, then a Mac re-run's checks failed outside the sandbox | stays, with Review's and the checks' last word and a recommendation (§4) | |
| 25 | | Centre the star | `merge_conflict` | the first rebase round passed hosted checks and Review; the merge conflicted again | Engineering rebases again (§2.2), then the gate asks (hosted) | |
| 26 | | Rename control | `fix_rounds` | round 2's hosted checks failed in named units | stays, with the failing units and a recommendation (§4) | |
| 27 | | Thinking indicators, Done to recheck | `retry` | round 1 Engineering stopped `runner_restarted`, never pushed | retried once on its own (§2.1) | |
| 28 | | Private repository storage | `merge` | approved; checks `needs_network` at 12:45, before hosted checks; its card has no merge audit row | hosted re-check on the same SHA (§2.3), then the gate asks (hosted) | |
| 29 | |
| 30 | Item 6 asked because its checks predate hosted checks, not because of |
| 31 | the ships question (no project has a policy row yet; the ships card is |
| 32 | already its own project card). Items 2 and 6 still end at a merge card: |
| 33 | a hosted pass is asked about until amadan#136 lets hosted runs be |
| 34 | verified. The card says so (§4). |
| 35 | |
| 36 | ## 1. Shape |
| 37 | |
| 38 | All on the instance; no wire field, frame or protocol change. One pure |
| 39 | function, `triage.Classify(Facts) Verdict` (`internal/equipo/triage`, no |
| 40 | store, clock or I/O), sorts the task's `NeedsYou` (as `progress.needsYou` |
| 41 | computes it today) into **act** (one of three actions) or **ask** (stays |
| 42 | in Needs you with a recommendation). The store runs it at the end of |
| 43 | `advance` (every step report, sync and merge refusal), after a sync |
| 44 | marks a step `interrupted` (a worker's sync never reaches `advanceAll`), |
| 45 | at start-up (§3), on the housekeeping tick for held rows and in the stall |
| 46 | sweep (§2.5), never under the principal. |
| 47 | |
| 48 | **Never touched:** a task ended, cancelled or cancel-requested, folded, |
| 49 | or merging; a creator who is not a current member |
| 50 | and owner, has no primary runner (`PrimaryRunner` is empty when execution |
| 51 | is off), or paused their housekeeping. Classify checks the first four itself; the |
| 52 | store checks the rest in the transaction. A coordinator's merge hold |
| 53 | (`merge_hold`) stops only the merge-side actions (rebase and re-check): |
| 54 | a held task's passing stop is still retried, and its stuck step still |
| 55 | taken back (stopped-jobs audit, 2026-11-25: a hold had kept two |
| 56 | timed-out jobs from their retry). |
| 57 | |
| 58 | ## 2. The three actions |
| 59 | |
| 60 | Each is a row in housekeeping's ledger (`chat_housekeeping`), detector |
| 61 | `triage_<action>`, subject the task, claimed and carried out in the |
| 62 | transaction that noticed it, under the housekeeping principal with one |
| 63 | new permission, `dispatch` (step dispatch for the principal's own person |
| 64 | only; `hkSpend` today refuses all dispatch). The principal still refuses |
| 65 | merges, merge cards, `merge_asked`, `merge_eligible`, `ready_sha`, |
| 66 | endings and settings. **Triage rows are consumed for good:** only a |
| 67 | `held` row is claimed again; `done`, `failed` and `refused` never act |
| 68 | again and keep their charges, so a failure cannot buy another try. |
| 69 | |
| 70 | Every action revalidates its **source** inside the transaction: the |
| 71 | newest step, its attempt, state and reason, and the candidate, recorded |
| 72 | in the row's evidence when the row is first written and never replaced |
| 73 | (a held row is claimed later only if the task is still exactly there), |
| 74 | and the task still meets §1. A person's Retry |
| 75 | (new attempt), Cancel or hold, or any new step, makes the key stale and |
| 76 | it does nothing. |
| 77 | |
| 78 | ### 2.1 Retry a passing stop |
| 79 | |
| 80 | - **When:** `NeedsYou` is `retry` or `review_blocked`; the newest step is |
| 81 | Engineering, Review or Checks (a merge step never, checked in |
| 82 | `Classify` itself), placed on the person's primary (a step on a |
| 83 | worker, a Mac, stays with the person and the Mac checks gate, which |
| 84 | makes it wait for the Mac's sandbox; an unknown runner counts as a |
| 85 | worker); it failed with termination proven; its reason is |
| 86 | `runner_restarted`, `interrupted` (the runner no longer held it at |
| 87 | sync), `superseded` (lease lost), `step_timeout` or `checks_timeout`; |
| 88 | and no automatic retry of this step was made before (any attempt). |
| 89 | - **Key** `retry:<step>:<attempt>`. **Costs** one retry (day limit 3, |
| 90 | housekeeping's). |
| 91 | - **Does** the ordinary Retry of that step (`retryStep`, factored out of |
| 92 | `RetryTask`), which refuses merge steps under the principal. |
| 93 | |
| 94 | ### 2.2 Rebase a conflicting candidate |
| 95 | |
| 96 | - **When:** `NeedsYou` is `merge_conflict` (the newest step is a merge |
| 97 | that failed `merge_conflict` with termination after the task's one |
| 98 | rebase round), and no automatic rebase was made for this candidate. |
| 99 | - **Key** `rebase:<task>:<candidate>`. **Costs** one automatic round (day limit |
| 100 | 3, new `Limits.Rounds`); at most two per task. |
| 101 | - **Does** an Engineering rebase step exactly as `mergeFailed` makes the |
| 102 | first. Checks, Review and the gate follow as for any candidate. |
| 103 | |
| 104 | ### 2.3 Re-check stale checks on a hosted-CI project |
| 105 | |
| 106 | - **When:** `NeedsYou` is `merge`; the judged checks of the candidate are |
| 107 | a Checks step that ended `cannot_run` with `needs_network` or |
| 108 | `needs_macos`, with no hosted binding, **before** the project's first |
| 109 | hosted verdict (the earliest `finished_at` of a step in the project |
| 110 | with `checks_sandbox = hosted`); no merge step for the candidate. No |
| 111 | hosted verdict in the project means not a hosted-CI project: nothing. |
| 112 | - **Key** `recheck:<task>:<candidate>`. **Costs** nothing (once per SHA). |
| 113 | - **Does** a Checks step on the exact candidate with `recheck_by = |
| 114 | hosted`, stage back to In review, placed as any checks step; on the |
| 115 | primary the dispatch carries slice 1's hosted offer. The offer is not a |
| 116 | promise (the runner declines it for a macOS change, hosted CI off, or a |
| 117 | read error, and a Mac may take the step), so the task line says only |
| 118 | that the checks run again. Whatever comes back is judged as any checks |
| 119 | result; a `cannot_run` again stays at the card, once per SHA. `merge_asked` is |
| 120 | never cleared (the principal refuses it), so an asked SHA stays asked: |
| 121 | the result refreshes the card's words as a Mac re-run does |
| 122 | (`refreshAfterRecheck`), and a pass is still asked about (hosted is |
| 123 | outside the sandbox). A failure takes the fix round as any failure. |
| 124 | |
| 125 | ### 2.4 Budget and spend |
| 126 | |
| 127 | Per person per day in the ledger housekeeping sums (`hkUsed`): retries |
| 128 | 3, automatic rounds 3 (new column pair `reserved_rounds`, |
| 129 | `charged_rounds`); a recheck is free. A row reserves its unit when |
| 130 | claimed and is charged it at once (the dispatch is the action). Whenever |
| 131 | usage for the step attempt it started arrives (at the end, or late), the |
| 132 | row's token record is recomputed from that attempt's usage rows, counted as `rowSpend` counts them (Claude's |
| 133 | cache reads and writes included; an attempt with no complete figure is |
| 134 | recorded as incomplete, never zero). Steps are bounded by count, not by |
| 135 | tokens: the token figures are the record, not a gate, and `hkUsed` leaves |
| 136 | triage rows' tokens out of every budget sum. |
| 137 | |
| 138 | Day limit reached: the row is `held` (reason `budget`); the task stays in |
| 139 | Needs you with the recommendation (§4); the next tick or sync claims it |
| 140 | again if its source is still current. |
| 141 | |
| 142 | ### 2.5 The stall sweep |
| 143 | |
| 144 | Paul: "Does it need a loop or something to kick it to make sure it |
| 145 | actually carries through tasks to completion?" Inside housekeeping's |
| 146 | existing minute (no new polling of runners), `SweepStalled` looks at open |
| 147 | tasks with no change for 30 minutes: |
| 148 | |
| 149 | - **Stopped, with something for its person:** triage again (§§2.1-2.3), |
| 150 | for whatever a missed trigger left. |
| 151 | - **An attempt running 90 minutes** (a step's own limit is 20, hosted |
| 152 | checks wait at most 60) **or placed and not started for 30**, on a |
| 153 | runner that is online and is the person's primary: taken back with the existing `withdraw` (a |
| 154 | started attempt is cancelled and the next is placed once its end is |
| 155 | proven; one never started is placed again at once). Once per step |
| 156 | (`unstick:<step>`), one retry of the day's budget, said as "ran out of |
| 157 | time". An offline runner's attempts stay the offline rule's and the |
| 158 | next sync's. |
| 159 | - **Its newest step done 30 minutes ago, nothing scheduled and nothing |
| 160 | to decide:** `advance` once (`kick:<step>:<attempt>`), free; a kick |
| 161 | that moves nothing is recorded as expired, so it is not tried every |
| 162 | minute. |
| 163 | |
| 164 | Never a merge step, a task Ready to merge or merging, cancelled or |
| 165 | paused (a merge hold does not stop the sweep: the sweep never merges). The take-back and the kick run under the principal, so a kick |
| 166 | that would make a task Ready or merge it is refused there (the next sync |
| 167 | moves it). |
| 168 | |
| 169 | ## 3. Re-triage on deploy |
| 170 | |
| 171 | At start-up, after housekeeping's claim recovery, `Retriage` runs once |
| 172 | over every open task with a non-empty `NeedsYou`, one transaction per |
| 173 | task. The keys make it idempotent: a second start, a sync or the tick |
| 174 | finds them and does nothing. |
| 175 | |
| 176 | ## 4. What the person sees |
| 177 | |
| 178 | `wire.Task` (person API only) gains `triage {kind, reason, since, said, |
| 179 | failed[], recommend, why}`, omitempty. |
| 180 | |
| 181 | - **Acting:** while a triage step runs (`retrying`, `rebasing`, |
| 182 | `rechecking`), `NeedsYou` is already empty (the step is queued or |
| 183 | running) and the task line says so (§7's acting lines). Each action is a quiet action row on |
| 184 | the Housekeeping view; no conversation card, no Undo (a dispatched step |
| 185 | may already run; the task's Cancel is the reversal). |
| 186 | - **Asking:** every other `NeedsYou` stays, as a plain question with a |
| 187 | deterministic recommendation from what is recorded: Review's newest |
| 188 | finding (or summary) in one line, hosted CI's failing step names, and |
| 189 | why Equipo did not act (a passing stop already retried, today's budget |
| 190 | used, two rebases used). Recommendations: `round` for `fix_rounds`, |
| 191 | `retry` for a stopped step, `rebase` for a conflict. Actions: |
| 192 | - **Ask the coordinator:** the existing link to the conversation with |
| 193 | the task named in the composer (`?about=`); Paul sends it, an |
| 194 | ordinary turn. |
| 195 | - **Try another round:** new `POST /api/v1/tasks/{id}/round` (and the |
| 196 | page form). The creator, an owner, `NeedsYou` `fix_rounds` or |
| 197 | `merge_conflict`: one Engineering round on the candidate with the |
| 198 | last feedback (a rebase round for a conflict). Person-initiated, so |
| 199 | never budgeted. |
| 200 | - **Cancel**, as today. |
| 201 | - **Hosted merge card:** when the gate asks only because hosted checks |
| 202 | are outside the sandbox, its reason reads "Hosted checks passed. Equipo |
| 203 | can merge these on its own once hosted runs can be verified". |
| 204 | |
| 205 | ## 5. Data |
| 206 | |
| 207 | Migration 0065 (additive; 0064 is taken by mac-checks-wait-sandbox): `chat_housekeeping.reserved_rounds`, |
| 208 | `charged_rounds`. Nothing else: `recheck_by` exists, keys and sources |
| 209 | live on the ledger row (`subject_id`, `finding_key`, `attempt` = |
| 210 | `step:<id>:<attempt>` of the step the action started). |
| 211 | |
| 212 | ## 6. Tests, failing first |
| 213 | |
| 214 | Contracts in `internal/thintest`, each seen failing before the code: |
| 215 | |
| 216 | - `TestTriageRetriesPassingStop` (items 4, 5): `runner_restarted` before a |
| 217 | push is retried once, with the action row and the acting line; the |
| 218 | same step stopping again stays in Needs you with `retry` recommended. |
| 219 | - `TestTriageNeverRetriesMerge`: a merge step failed `interrupted`: no |
| 220 | retry, by `Classify` and by `retryStep` under the principal. |
| 221 | - `TestTriageRebasesConflict` (item 2): a conflict after the first rebase |
| 222 | starts one more rebase round for that candidate; the gate then asks. |
| 223 | - `TestTriageRechecksStaleChecks` (item 6): `needs_network` before the |
| 224 | project's first hosted verdict, at Ready to merge with a card: checks |
| 225 | run again on the same SHA with the hosted offer; the SHA stays asked; a |
| 226 | hosted pass refreshes the card with the hosted reason; nothing merges. |
| 227 | Not before any hosted verdict: nothing. |
| 228 | - `TestTriageAsksWithRecommendation` (items 1, 3): `fix_rounds` stays in |
| 229 | Needs you with the failing units, Review's last word and `round`; Try |
| 230 | another round starts round 3 with the feedback. |
| 231 | - `TestTriageStale`: a person's Retry, Cancel or hold before a held row |
| 232 | is claimed again: it does nothing. |
| 233 | - `TestTriageBudget`: the fourth retry of a day is held with the |
| 234 | recommendation; the next day claims it; a failed row never acts again. |
| 235 | - `TestTriageRetriageIdempotent`: `Retriage` twice and a sync act once. |
| 236 | - `TestTriageCancelledUntouched`: cancelled, cancel-requested, |
| 237 | paused: nothing changes. |
| 238 | - `TestTriageHeldStillRetries`: a held task's `step_timeout` is retried |
| 239 | once; the hold stays. |
| 240 | - `TestTriageStaleRebase`: a rebase held for the budget, then the |
| 241 | person's merge Retry on the same SHA conflicting again: never acts. |
| 242 | - `TestTriageSweepsStalled`: running past its time, queued and never |
| 243 | started, stopped with nothing scheduled, done with its next step lost; |
| 244 | never a merge; a held task's stuck step is taken back. |
| 245 | |
| 246 | Unit: the `Classify` table. Headless scenario 4 now expects the |
| 247 | automatic retry; Mac M4 and the sandbox-wait contract keep the person's |
| 248 | Retry (worker steps). Every guard (the reason list, the specialist list |
| 249 | and the merge exclusion, termination, once per step, staleness, the |
| 250 | hosted-project rule, budget, consumed rows, the principal's `dispatch` |
| 251 | scope, never-touched) is broken once and its test watched failing. |
| 252 | |
| 253 | ## 7. Copy |
| 254 | |
| 255 | New strings in `copy.go`, through a delegated Astra copy pass (verdicts |
| 256 | applied verbatim): the acting lines ("Equipo is trying the step again |
| 257 | because %s.", "Engineering is fixing conflicting changes.", "Equipo is |
| 258 | running the checks again."), the recommendations ("Equipo recommends |
| 259 | another round." and two more), why it waits ("Equipo already tried this |
| 260 | once on its own.", "Equipo has used all its automatic tries for |
| 261 | today."), "Review's latest finding: %s", "Hosted checks failed: %s.", |
| 262 | "Ask the coordinator", "Try another round", the hosted merge reason ("its |
| 263 | hosted checks passed, but I need to verify those runs before I can merge |
| 264 | it on my own") and the Housekeeping view names of the three action |
| 265 | detectors. The stall sweep's kick has no name of its own (nothing it does |
| 266 | shows as a receipt). |
| 267 | |
| 268 | ## 8. Moved to v2 |
| 269 | |
| 270 | The coordinator hand-off turn kind (most of round 1's findings: turn |
| 271 | keys, requeue, budgets, older protocols, follow-ups), splitting a task, |
| 272 | retrying stops that are not passing, Undo for dispatched steps, hosted |
| 273 | passes merging on their own (amadan#136). |
| 274 | |
| 275 | ## 9. Round 1 and where it went |
| 276 | |
| 277 | 1. Merge authority through a hand-off retry: no hand-off; `retryStep` |
| 278 | refuses merge steps under the principal and `Classify` never picks |
| 279 | them (§2.1). |
| 280 | 2. Bound to the source: every key names its step and attempt or |
| 281 | candidate, revalidated in the transaction (§2). |
| 282 | 3. Yield and requeue: no turns (§8). |
| 283 | 4. Follow-up keys: no follow-ups (§8). |
| 284 | 5. Consumed rows: only `held` is reclaimable, charges kept (§2). |
| 285 | 6. Token remainder: no model turns; steps are bounded by count (§2.4). |
| 286 | 7. Token totals: `rowSpend`, cache included, incomplete never zero (§2.4). |
| 287 | 8. Split: cut (§8). |
| 288 | 9. Protocol: no wire change (§1). |
| 289 | 10. Retry eligibility and Needs you: passing stops only, and a spent |
| 290 | budget stays in Needs you with the recommendation (coordinator's |
| 291 | rulings, §§2.1, 2.4, 4). |
| 292 | |
| 293 | ## 11. Astra round 2 (revision 2): READY AFTER FIXES |
| 294 | |
| 295 | 1. Execution authority: `triageMay` requires a primary runner, which is |
| 296 | empty when execution is off or the creator is not an active owner. |
| 297 | 2. Source fence: keys carry the task; the source snapshot lives in the |
| 298 | row's evidence and is never replaced (`TestTriageStaleRebase`). |
| 299 | 3. Tokens as a gate: triage rows' tokens are left out of `hkUsed`; |
| 300 | `triageFits` checks retries and rounds only; rounds are in every cost |
| 301 | operation and the query. |
| 302 | 4. Late usage: the record is recomputed in `recordUsage` whenever usage |
| 303 | for the attempt arrives. |
| 304 | 5. Worker syncs: `syncSteps` triages a step it marks `interrupted`. |
| 305 | 6. The hosted offer: neutral acting text; fallbacks stay at the card |
| 306 | (§2.3). |
| 307 | 7. The rebase chain: two automatic rebases after the merge's own, keyed |
| 308 | per candidate, tested across a re-triage (`TestTriageRebasesConflict`). |
| 309 | |
| 310 | ## 10. Astra round 1 (revision 1): NOT READY |
| 311 | |
| 312 | `gpt-6-astra`, effort high, read-only, against revision 1 and main |
| 313 | 4e51bcd. Findings as given, shortened; revision 2 must answer each. |
| 314 | |
| 315 | 1. **Critical, §3.** `resolve_task` retry can reach `RetryTask`'s merge |
| 316 | path, which calls `authorizeMerge` as the person and records |
| 317 | `decided_by: person`. §2 excludes merge steps; §3 does not, and the |
| 318 | hand-off runs outside the principal. Fix: refuse merge steps in |
| 319 | `resolve_task`; no coordinator action ever carries a person's merge |
| 320 | authority. |
| 321 | 2. **Important, §§1-3.** Hand-offs and questions are not bound to the |
| 322 | situation that raised them: a person's Retry, Cancel or a hold in the |
| 323 | meantime does not invalidate them. Fix: bind to the source step, |
| 324 | attempt and candidate; revalidate at dispatch, resolution and answer. |
| 325 | 3. **Important, §§2-3.** A yielded hand-off re-queued through |
| 326 | `kindEnded`/`queueKind` loses its task and ledger link and can |
| 327 | replenish the budget; and §3's fallback restores the old Needs you |
| 328 | even after `resolve_task` committed a round or question. Fix: persist |
| 329 | the resolution apart from the reply; continue a yielded hand-off under |
| 330 | the same row and reservation; never restore after a committed effect. |
| 331 | 4. **Important, §§2-4.** The answer follow-up has no usable key (the |
| 332 | `ask` changes no step, so it collides with `handoff:<task>:<step>: |
| 333 | <attempt>`) and no clear bound against the two-hand-off cap. Fix: a |
| 334 | dedicated answer path, a card-keyed follow-up, at most one question |
| 335 | and one follow-up per episode, and say exactly which limit the |
| 336 | person's tap is exempt from. |
| 337 | 5. **Important, §§2, 3, 6.** `reclaimable` re-opens `failed` rows once |
| 338 | and `vetoed` rows after 30 days, and `hkRun` clears earlier charges. |
| 339 | Fix: failed and undone triage keys are consumed for good; charges are |
| 340 | kept; dispatched failures count toward the lifetime caps. |
| 341 | 6. **Important, §4.** A 37,500-token reservation does not stop a turn |
| 342 | spending more: nothing carries a remaining allowance to the runner |
| 343 | across attempts (housekeeping §4's `max_tokens`). Fix: carry and |
| 344 | enforce the remainder; charge overruns without a fresh allowance. |
| 345 | 7. **Important, §4.** "Input plus output" undercounts Claude, whose cache |
| 346 | reads and writes `rowSpend` counts separately; rows can be partial or |
| 347 | null. Fix: provider-aware totals across attempts, at least the |
| 348 | reservation for incomplete usage, later reports reconciled once. |
| 349 | 8. **Important, §§2-4.** Split does not fit the caps (three parts against |
| 350 | two rounds), and new tasks get fresh caps, so splitting replenishes |
| 351 | them; no lineage is stored. Fix: a shared allowance for the original |
| 352 | work, child lineage, all parts reserved at once, durable keys for |
| 353 | `round` and `split`. |
| 354 | 9. **Important, §7.** A hand-off queued behind a person's turn can be |
| 355 | dispatched after the runner reconnects below 7; `send` drops it on |
| 356 | `ErrProtocol` and the turn blocks the queue. Fix: check the protocol |
| 357 | at dispatch and retire the turn in the same transaction; say what a |
| 358 | new runner holding a hand-off does with an old instance. |
| 359 | 10. **Important, §§1, 3-5.** Non-transient failures skip the first retry |
| 360 | Paul ruled for every stopped step, and spent budgets or an unsettled |
| 361 | hand-off leave raw `retry` or `fix_rounds` in Needs you, which a |
| 362 | recommendation does not turn into a decision only Paul can make. |
| 363 | Fix: reconcile retry eligibility with the ruling, keep operational |
| 364 | waiting out of Needs you, and escalate only with a concrete question. |
| 365 | (The brief asked for "a plain Needs you question with a |
| 366 | recommendation" when a budget runs out, so the second half needs a |
| 367 | ruling.) |
| 368 | |