# Equipo: needs-you triage, thin v1

Status: 2026-11-11, revision 2.1 ("thin v1"), built. Revision 1 (3ab0e85)
drew NOT READY from Astra round 1 (§10); the coordinator cut the scope so
it converges: no new turn kind, no wire change, no split. Revision 2
drew READY AFTER FIXES from round 2; its seven findings are folded in
(§11). Paul then asked for a loop that carries tasks through to the end
(§2.5). Drafted by Claude
(Opus 5.5) on `needs-you-triage` from main 8d7f217. Builds on thin v1,
housekeeping (§§3-4: the ledger, the day budget, the principal), merge
authority (the gate, unchanged) and release slice 1 (hosted checks).

## 0. Why

Paul, on staging's six Needs you items: "I feel like a bunch of this stuff
doesn't actually need me." Ruled 2026-11-11: Needs you holds only
decisions only Paul can make; a step that stopped for a passing reason is
retried once on its own, within the retry budget; spend is first-class.

Staging, read from its replica at 20:37 UTC:

| Task | Needs you today | What the rows say | Thin v1 |
|---|---|---|---|
| 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) |
| 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) |
| Rename control | `fix_rounds` | round 2's hosted checks failed in named units | stays, with the failing units and a recommendation (§4) |
| Thinking indicators, Done to recheck | `retry` | round 1 Engineering stopped `runner_restarted`, never pushed | retried once on its own (§2.1) |
| 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) |

Item 6 asked because its checks predate hosted checks, not because of
the ships question (no project has a policy row yet; the ships card is
already its own project card). Items 2 and 6 still end at a merge card:
a hosted pass is asked about until amadan#136 lets hosted runs be
verified. The card says so (§4).

## 1. Shape

All on the instance; no wire field, frame or protocol change. One pure
function, `triage.Classify(Facts) Verdict` (`internal/equipo/triage`, no
store, clock or I/O), sorts the task's `NeedsYou` (as `progress.needsYou`
computes it today) into **act** (one of three actions) or **ask** (stays
in Needs you with a recommendation). The store runs it at the end of
`advance` (every step report, sync and merge refusal), after a sync
marks a step `interrupted` (a worker's sync never reaches `advanceAll`),
at start-up (§3), on the housekeeping tick for held rows and in the stall
sweep (§2.5), never under the principal.

**Never touched:** a task ended, cancelled or cancel-requested, folded,
or merging; a creator who is not a current member
and owner, has no primary runner (`PrimaryRunner` is empty when execution
is off), or paused their housekeeping. Classify checks the first four itself; the
store checks the rest in the transaction. A coordinator's merge hold
(`merge_hold`) stops only the merge-side actions (rebase and re-check):
a held task's passing stop is still retried, and its stuck step still
taken back (stopped-jobs audit, 2026-11-25: a hold had kept two
timed-out jobs from their retry).

## 2. The three actions

Each is a row in housekeeping's ledger (`chat_housekeeping`), detector
`triage_<action>`, subject the task, claimed and carried out in the
transaction that noticed it, under the housekeeping principal with one
new permission, `dispatch` (step dispatch for the principal's own person
only; `hkSpend` today refuses all dispatch). The principal still refuses
merges, merge cards, `merge_asked`, `merge_eligible`, `ready_sha`,
endings and settings. **Triage rows are consumed for good:** only a
`held` row is claimed again; `done`, `failed` and `refused` never act
again and keep their charges, so a failure cannot buy another try.

Every action revalidates its **source** inside the transaction: the
newest step, its attempt, state and reason, and the candidate, recorded
in the row's evidence when the row is first written and never replaced
(a held row is claimed later only if the task is still exactly there),
and the task still meets §1. A person's Retry
(new attempt), Cancel or hold, or any new step, makes the key stale and
it does nothing.

### 2.1 Retry a passing stop

- **When:** `NeedsYou` is `retry` or `review_blocked`; the newest step is
  Engineering, Review or Checks (a merge step never, checked in
  `Classify` itself), placed on the person's primary (a step on a
  worker, a Mac, stays with the person and the Mac checks gate, which
  makes it wait for the Mac's sandbox; an unknown runner counts as a
  worker); it failed with termination proven; its reason is
  `runner_restarted`, `interrupted` (the runner no longer held it at
  sync), `superseded` (lease lost), `step_timeout` or `checks_timeout`;
  and no automatic retry of this step was made before (any attempt).
- **Key** `retry:<step>:<attempt>`. **Costs** one retry (day limit 3,
  housekeeping's).
- **Does** the ordinary Retry of that step (`retryStep`, factored out of
  `RetryTask`), which refuses merge steps under the principal.

### 2.2 Rebase a conflicting candidate

- **When:** `NeedsYou` is `merge_conflict` (the newest step is a merge
  that failed `merge_conflict` with termination after the task's one
  rebase round), and no automatic rebase was made for this candidate.
- **Key** `rebase:<task>:<candidate>`. **Costs** one automatic round (day limit
  3, new `Limits.Rounds`); at most two per task.
- **Does** an Engineering rebase step exactly as `mergeFailed` makes the
  first. Checks, Review and the gate follow as for any candidate.

### 2.3 Re-check stale checks on a hosted-CI project

- **When:** `NeedsYou` is `merge`; the judged checks of the candidate are
  a Checks step that ended `cannot_run` with `needs_network` or
  `needs_macos`, with no hosted binding, **before** the project's first
  hosted verdict (the earliest `finished_at` of a step in the project
  with `checks_sandbox = hosted`); no merge step for the candidate. No
  hosted verdict in the project means not a hosted-CI project: nothing.
- **Key** `recheck:<task>:<candidate>`. **Costs** nothing (once per SHA).
- **Does** a Checks step on the exact candidate with `recheck_by =
  hosted`, stage back to In review, placed as any checks step; on the
  primary the dispatch carries slice 1's hosted offer. The offer is not a
  promise (the runner declines it for a macOS change, hosted CI off, or a
  read error, and a Mac may take the step), so the task line says only
  that the checks run again. Whatever comes back is judged as any checks
  result; a `cannot_run` again stays at the card, once per SHA. `merge_asked` is
  never cleared (the principal refuses it), so an asked SHA stays asked:
  the result refreshes the card's words as a Mac re-run does
  (`refreshAfterRecheck`), and a pass is still asked about (hosted is
  outside the sandbox). A failure takes the fix round as any failure.

### 2.4 Budget and spend

Per person per day in the ledger housekeeping sums (`hkUsed`): retries
3, automatic rounds 3 (new column pair `reserved_rounds`,
`charged_rounds`); a recheck is free. A row reserves its unit when
claimed and is charged it at once (the dispatch is the action). Whenever
usage for the step attempt it started arrives (at the end, or late), the
row's token record is recomputed from that attempt's usage rows, counted as `rowSpend` counts them (Claude's
cache reads and writes included; an attempt with no complete figure is
recorded as incomplete, never zero). Steps are bounded by count, not by
tokens: the token figures are the record, not a gate, and `hkUsed` leaves
triage rows' tokens out of every budget sum.

Day limit reached: the row is `held` (reason `budget`); the task stays in
Needs you with the recommendation (§4); the next tick or sync claims it
again if its source is still current.

### 2.5 The stall sweep

Paul: "Does it need a loop or something to kick it to make sure it
actually carries through tasks to completion?" Inside housekeeping's
existing minute (no new polling of runners), `SweepStalled` looks at open
tasks with no change for 30 minutes:

- **Stopped, with something for its person:** triage again (§§2.1-2.3),
  for whatever a missed trigger left.
- **An attempt running 90 minutes** (a step's own limit is 20, hosted
  checks wait at most 60) **or placed and not started for 30**, on a
  runner that is online and is the person's primary: taken back with the existing `withdraw` (a
  started attempt is cancelled and the next is placed once its end is
  proven; one never started is placed again at once). Once per step
  (`unstick:<step>`), one retry of the day's budget, said as "ran out of
  time". An offline runner's attempts stay the offline rule's and the
  next sync's.
- **Its newest step done 30 minutes ago, nothing scheduled and nothing
  to decide:** `advance` once (`kick:<step>:<attempt>`), free; a kick
  that moves nothing is recorded as expired, so it is not tried every
  minute.

Never a merge step, a task Ready to merge or merging, cancelled or
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
that would make a task Ready or merge it is refused there (the next sync
moves it).

## 3. Re-triage on deploy

At start-up, after housekeeping's claim recovery, `Retriage` runs once
over every open task with a non-empty `NeedsYou`, one transaction per
task. The keys make it idempotent: a second start, a sync or the tick
finds them and does nothing.

## 4. What the person sees

`wire.Task` (person API only) gains `triage {kind, reason, since, said,
failed[], recommend, why}`, omitempty.

- **Acting:** while a triage step runs (`retrying`, `rebasing`,
  `rechecking`), `NeedsYou` is already empty (the step is queued or
  running) and the task line says so (§7's acting lines). Each action is a quiet action row on
  the Housekeeping view; no conversation card, no Undo (a dispatched step
  may already run; the task's Cancel is the reversal).
- **Asking:** every other `NeedsYou` stays, as a plain question with a
  deterministic recommendation from what is recorded: Review's newest
  finding (or summary) in one line, hosted CI's failing step names, and
  why Equipo did not act (a passing stop already retried, today's budget
  used, two rebases used). Recommendations: `round` for `fix_rounds`,
  `retry` for a stopped step, `rebase` for a conflict. Actions:
  - **Ask the coordinator:** the existing link to the conversation with
    the task named in the composer (`?about=`); Paul sends it, an
    ordinary turn.
  - **Try another round:** new `POST /api/v1/tasks/{id}/round` (and the
    page form). The creator, an owner, `NeedsYou` `fix_rounds` or
    `merge_conflict`: one Engineering round on the candidate with the
    last feedback (a rebase round for a conflict). Person-initiated, so
    never budgeted.
  - **Cancel**, as today.
- **Hosted merge card:** when the gate asks only because hosted checks
  are outside the sandbox, its reason reads "Hosted checks passed. Equipo
  can merge these on its own once hosted runs can be verified".

## 5. Data

Migration 0065 (additive; 0064 is taken by mac-checks-wait-sandbox): `chat_housekeeping.reserved_rounds`,
`charged_rounds`. Nothing else: `recheck_by` exists, keys and sources
live on the ledger row (`subject_id`, `finding_key`, `attempt` =
`step:<id>:<attempt>` of the step the action started).

## 6. Tests, failing first

Contracts in `internal/thintest`, each seen failing before the code:

- `TestTriageRetriesPassingStop` (items 4, 5): `runner_restarted` before a
  push is retried once, with the action row and the acting line; the
  same step stopping again stays in Needs you with `retry` recommended.
- `TestTriageNeverRetriesMerge`: a merge step failed `interrupted`: no
  retry, by `Classify` and by `retryStep` under the principal.
- `TestTriageRebasesConflict` (item 2): a conflict after the first rebase
  starts one more rebase round for that candidate; the gate then asks.
- `TestTriageRechecksStaleChecks` (item 6): `needs_network` before the
  project's first hosted verdict, at Ready to merge with a card: checks
  run again on the same SHA with the hosted offer; the SHA stays asked; a
  hosted pass refreshes the card with the hosted reason; nothing merges.
  Not before any hosted verdict: nothing.
- `TestTriageAsksWithRecommendation` (items 1, 3): `fix_rounds` stays in
  Needs you with the failing units, Review's last word and `round`; Try
  another round starts round 3 with the feedback.
- `TestTriageStale`: a person's Retry, Cancel or hold before a held row
  is claimed again: it does nothing.
- `TestTriageBudget`: the fourth retry of a day is held with the
  recommendation; the next day claims it; a failed row never acts again.
- `TestTriageRetriageIdempotent`: `Retriage` twice and a sync act once.
- `TestTriageCancelledUntouched`: cancelled, cancel-requested,
  paused: nothing changes.
- `TestTriageHeldStillRetries`: a held task's `step_timeout` is retried
  once; the hold stays.
- `TestTriageStaleRebase`: a rebase held for the budget, then the
  person's merge Retry on the same SHA conflicting again: never acts.
- `TestTriageSweepsStalled`: running past its time, queued and never
  started, stopped with nothing scheduled, done with its next step lost;
  never a merge; a held task's stuck step is taken back.

Unit: the `Classify` table. Headless scenario 4 now expects the
automatic retry; Mac M4 and the sandbox-wait contract keep the person's
Retry (worker steps). Every guard (the reason list, the specialist list
and the merge exclusion, termination, once per step, staleness, the
hosted-project rule, budget, consumed rows, the principal's `dispatch`
scope, never-touched) is broken once and its test watched failing.

## 7. Copy

New strings in `copy.go`, through a delegated Astra copy pass (verdicts
applied verbatim): the acting lines ("Equipo is trying the step again
because %s.", "Engineering is fixing conflicting changes.", "Equipo is
running the checks again."), the recommendations ("Equipo recommends
another round." and two more), why it waits ("Equipo already tried this
once on its own.", "Equipo has used all its automatic tries for
today."), "Review's latest finding: %s", "Hosted checks failed: %s.",
"Ask the coordinator", "Try another round", the hosted merge reason ("its
hosted checks passed, but I need to verify those runs before I can merge
it on my own") and the Housekeeping view names of the three action
detectors. The stall sweep's kick has no name of its own (nothing it does
shows as a receipt).

## 8. Moved to v2

The coordinator hand-off turn kind (most of round 1's findings: turn
keys, requeue, budgets, older protocols, follow-ups), splitting a task,
retrying stops that are not passing, Undo for dispatched steps, hosted
passes merging on their own (amadan#136).

## 9. Round 1 and where it went

1. Merge authority through a hand-off retry: no hand-off; `retryStep`
   refuses merge steps under the principal and `Classify` never picks
   them (§2.1).
2. Bound to the source: every key names its step and attempt or
   candidate, revalidated in the transaction (§2).
3. Yield and requeue: no turns (§8).
4. Follow-up keys: no follow-ups (§8).
5. Consumed rows: only `held` is reclaimable, charges kept (§2).
6. Token remainder: no model turns; steps are bounded by count (§2.4).
7. Token totals: `rowSpend`, cache included, incomplete never zero (§2.4).
8. Split: cut (§8).
9. Protocol: no wire change (§1).
10. Retry eligibility and Needs you: passing stops only, and a spent
    budget stays in Needs you with the recommendation (coordinator's
    rulings, §§2.1, 2.4, 4).

## 11. Astra round 2 (revision 2): READY AFTER FIXES

1. Execution authority: `triageMay` requires a primary runner, which is
   empty when execution is off or the creator is not an active owner.
2. Source fence: keys carry the task; the source snapshot lives in the
   row's evidence and is never replaced (`TestTriageStaleRebase`).
3. Tokens as a gate: triage rows' tokens are left out of `hkUsed`;
   `triageFits` checks retries and rounds only; rounds are in every cost
   operation and the query.
4. Late usage: the record is recomputed in `recordUsage` whenever usage
   for the attempt arrives.
5. Worker syncs: `syncSteps` triages a step it marks `interrupted`.
6. The hosted offer: neutral acting text; fallbacks stay at the card
   (§2.3).
7. The rebase chain: two automatic rebases after the merge's own, keyed
   per candidate, tested across a re-triage (`TestTriageRebasesConflict`).

## 10. Astra round 1 (revision 1): NOT READY

`gpt-6-astra`, effort high, read-only, against revision 1 and main
4e51bcd. Findings as given, shortened; revision 2 must answer each.

1. **Critical, §3.** `resolve_task` retry can reach `RetryTask`'s merge
   path, which calls `authorizeMerge` as the person and records
   `decided_by: person`. §2 excludes merge steps; §3 does not, and the
   hand-off runs outside the principal. Fix: refuse merge steps in
   `resolve_task`; no coordinator action ever carries a person's merge
   authority.
2. **Important, §§1-3.** Hand-offs and questions are not bound to the
   situation that raised them: a person's Retry, Cancel or a hold in the
   meantime does not invalidate them. Fix: bind to the source step,
   attempt and candidate; revalidate at dispatch, resolution and answer.
3. **Important, §§2-3.** A yielded hand-off re-queued through
   `kindEnded`/`queueKind` loses its task and ledger link and can
   replenish the budget; and §3's fallback restores the old Needs you
   even after `resolve_task` committed a round or question. Fix: persist
   the resolution apart from the reply; continue a yielded hand-off under
   the same row and reservation; never restore after a committed effect.
4. **Important, §§2-4.** The answer follow-up has no usable key (the
   `ask` changes no step, so it collides with `handoff:<task>:<step>:
   <attempt>`) and no clear bound against the two-hand-off cap. Fix: a
   dedicated answer path, a card-keyed follow-up, at most one question
   and one follow-up per episode, and say exactly which limit the
   person's tap is exempt from.
5. **Important, §§2, 3, 6.** `reclaimable` re-opens `failed` rows once
   and `vetoed` rows after 30 days, and `hkRun` clears earlier charges.
   Fix: failed and undone triage keys are consumed for good; charges are
   kept; dispatched failures count toward the lifetime caps.
6. **Important, §4.** A 37,500-token reservation does not stop a turn
   spending more: nothing carries a remaining allowance to the runner
   across attempts (housekeeping §4's `max_tokens`). Fix: carry and
   enforce the remainder; charge overruns without a fresh allowance.
7. **Important, §4.** "Input plus output" undercounts Claude, whose cache
   reads and writes `rowSpend` counts separately; rows can be partial or
   null. Fix: provider-aware totals across attempts, at least the
   reservation for incomplete usage, later reports reconciled once.
8. **Important, §§2-4.** Split does not fit the caps (three parts against
   two rounds), and new tasks get fresh caps, so splitting replenishes
   them; no lineage is stored. Fix: a shared allowance for the original
   work, child lineage, all parts reserved at once, durable keys for
   `round` and `split`.
9. **Important, §7.** A hand-off queued behind a person's turn can be
   dispatched after the runner reconnects below 7; `send` drops it on
   `ErrProtocol` and the turn blocks the queue. Fix: check the protocol
   at dispatch and retire the turn in the same transaction; say what a
   new runner holding a hand-off does with an old instance.
10. **Important, §§1, 3-5.** Non-transient failures skip the first retry
    Paul ruled for every stopped step, and spent budgets or an unsettled
    hand-off leave raw `retry` or `fix_rounds` in Needs you, which a
    recommendation does not turn into a decision only Paul can make.
    Fix: reconcile retry eligibility with the ruling, keep operational
    waiting out of Needs you, and escalate only with a concrete question.
    (The brief asked for "a plain Needs you question with a
    recommendation" when a budget runs out, so the second half needs a
    ruling.)
