| 1 | # Equipo housekeeping: a tidying loop that stays under control |
| 2 | |
| 3 | Status: design for Paul's review, 2026-11-08, revision 3 after Astra's |
| 4 | rounds 1 and 2 (NOT READY at cc6ca41; READY AFTER FIXES at f94fad0). Drafted by Claude (Fable 5.1) on |
| 5 | `design-housekeeping` from `thin-v1-conn1` (7946111). Builds on thin v1 |
| 6 | (`2026-11-06-equipo-thin-v1.md`), Connections rev 3 |
| 7 | (`2026-11-08-equipo-connections.md`, §§3, 4, 6) and the progress logs |
| 8 | for slices 2b, 3, 4, 4c, CONN1 and UX1. Paul's rulings of 2026-11-08 |
| 9 | are folded in (§9). Not implemented. |
| 10 | |
| 11 | ## 0. Why, and the shape of the answer |
| 12 | |
| 13 | Paul, on the duplicate tasks the coordinator kept filing: "Can Equipo |
| 14 | itself tidy up the duplicates? This is where I guess we need to start |
| 15 | thinking about loops where it pro-actively tries to keep everything tidy |
| 16 | and to spot things to improve (whilst not going out of control)." And |
| 17 | later: the loop is the basis of continual improvement that Equipo should |
| 18 | suggest and manage "across the whole business / organisation / family". |
| 19 | |
| 20 | Equipo already has the pieces of a loop without the loop. Move-in and |
| 21 | explore turns run with no person message and only read and note tools. |
| 22 | The notebook holds what the coordinator has learned. The runner checks |
| 23 | reach every minute and watches merged branches. The merge policy is |
| 24 | deterministic and runs in `advance`. Duplicate detection is being built |
| 25 | on `thin-v1-ux1`: same-creator, high-similarity pairs are combined with |
| 26 | an Undo receipt (`Task.folded`, `CardCombined`, |
| 27 | `POST /tasks/{id}/uncombine`); weaker matches get a "Possible duplicate |
| 28 | of" link. The mutation ledger makes writes idempotent across attempts. |
| 29 | Usage records every attempt. |
| 30 | |
| 31 | Housekeeping is the rule that joins them: **deterministic detectors |
| 32 | notice things; a policy table says what each class of thing may become; |
| 33 | a reserved budget, a ledger with a state machine and one Pause switch |
| 34 | keep it bounded; everything it does leaves a receipt with Undo; and |
| 35 | anything that depends on a model's judgement becomes a suggestion, never |
| 36 | an action, until a person taps.** No setup: the loop is on from the |
| 37 | first message, with defaults, and the only control a person needs is |
| 38 | Pause. |
| 39 | |
| 40 | Two invariants hold everywhere below and are tested as such. **No |
| 41 | forbidden effect is reachable**: every write the loop makes goes through |
| 42 | the shared store functions under a server-derived housekeeping principal |
| 43 | that checks current membership and the owner of every affected resource |
| 44 | inside the transaction. **Model judgement is never an action**: a model |
| 45 | may shape the words of a suggestion and nothing else. |
| 46 | |
| 47 | ## 1. Scope: teams, subjects, who sees what |
| 48 | |
| 49 | Everything in this spec belongs to a **team**: the roster that shares a |
| 50 | conversation server today, which in time may be a business, an |
| 51 | organisation or a family. Within a team, every finding, action and |
| 52 | suggestion has a **subject**: `{kind, id}` where kind is `task`, |
| 53 | `project`, `connection`, `notebook_entry`, `person` (a person's own area) |
| 54 | or `team`. The subject decides authority and visibility by one rule: |
| 55 | **a subject owned by one person is that person's business; a subject |
| 56 | owned by the team is everyone's to see and the owner's to act on.** |
| 57 | |
| 58 | A task's subject owner is its creator ("only a task's creator acts on |
| 59 | it" stands, and it applies to the *destination* of a fold as well as the |
| 60 | source). A connection's owner is its person. A notebook entry's owner is |
| 61 | the coordinator's person. A project and the team itself are team |
| 62 | subjects. The loop runs **per person**: each person's coordinator keeps |
| 63 | that person's own subjects tidy, draws on that person's connections and |
| 64 | budget, and posts receipts into that person's conversation. Team |
| 65 | subjects produce suggestions visible to the whole roster and nothing |
| 66 | more until slice 4, which adds acting on team subjects by the owner. A |
| 67 | person sees a suggestion if its audience is them or the team; a person |
| 68 | may accept a suggestion if they could create the task it describes (any |
| 69 | member for team subjects, the owner for personal ones); dismissing is |
| 70 | per person for team suggestions and final for personal ones. |
| 71 | |
| 72 | **The housekeeping principal.** Every loop write runs as |
| 73 | `housekeeping{team, person, detector, finding_id}`, built by the |
| 74 | instance from the ledger row, never from a frame or a tool argument. It |
| 75 | is passed into the same store functions a person's request uses |
| 76 | (`foldTask`, `retryStep`, `recordSuggestion`), and those functions |
| 77 | check, inside the write transaction: the person is a current member; for |
| 78 | every task touched, including a fold's destination and any task a |
| 79 | suggestion is linked to, the creator is the principal's person; for a |
| 80 | notebook entry, its person; for a team subject, that the class permits |
| 81 | it (propose only before slice 4). A principal that fails any check gets |
| 82 | `housekeeping_forbidden`, the ledger row becomes `refused`, and nothing |
| 83 | else in the transaction survives. Handlers are not the only gate: the |
| 84 | detectors run inside `advance`, so the gate is in the store. |
| 85 | |
| 86 | ## 2. Detectors: a registry of small declared units |
| 87 | |
| 88 | A **detector** is a declared, data-driven unit in a registry |
| 89 | (`internal/equipo/housekeeping`), never free code in a handler. Each |
| 90 | declares: `id`; subject kind; `class` (§3); `triggers` (event types from |
| 91 | the stream, plus `sweep`); `judgement` (`none` or `model`); `rate` (at |
| 92 | most N findings per subject and per team per period); and `Detect`, a |
| 93 | pure function from a read-only view of the store to zero or more |
| 94 | **findings** `{detector, subject, subject_revision, key, evidence, |
| 95 | proposal}`. The key is the finding's identity (`duplicate:tkA:tkB`, |
| 96 | `retry:tkA:chain2`); the ledger (§4) decides whether it may act. |
| 97 | Evidence is structured fields the receipt and the page render, never |
| 98 | model prose. A detector with `judgement: model` may only have class |
| 99 | Propose: the registry refuses any other combination at start-up |
| 100 | (`TestRegistryModelMeansPropose`). Adding a detector is a registry entry |
| 101 | and a fixture; nothing else changes, which is what lets the non-code |
| 102 | detectors of §8 arrive later. |
| 103 | |
| 104 | | Detector | Fires on | Class | Judgement | |
| 105 | |---|---|---|---| |
| 106 | | `duplicate_same_creator` | `record_task` (or the sweep) where two of one creator's open tasks in the same project overlap at or above 0.75 with three shared title words, or 0.7 with five across title and brief (UX1's thresholds as shipped; kept by the controller 2026-11-08), both tasks owned by that creator and checked again in the transaction. The one furthest along is kept (stage, then not stopped, then the older); the other closes. Only a pending decision on the task that closes (an open card other than its task card) or a step at work on it blocks the combine; an open card on the task kept, a merge card included, does not, and stays open on it (coordinator's ruling 2026-11-11, on Paul's "combine automatically with Undo": staging's Woodstar pair keeps `tkf6dufnbzcg` at Ready to merge and closes the stopped `tks6kwzzdngr`) | Act and tell: combine, receipt with Undo (built on `thin-v1-ux1`) | none | |
| 107 | | `duplicate_possible` | overlap at or above 0.6 with two shared title words, or 0.5 with three across title and brief, or any such overlap across creators | Link only: "Possible duplicate of" on the new task, `Task.duplicate_of` as UX1 | none | |
| 108 | | `retry_transient` | a step that **never pushed a candidate** stopped with `runner_restarted`, `interrupted`, `provider_failed`, `clone_failed`, `candidate_unavailable`, `checks_timeout` or `no_runner`, termination proven, no earlier automatic retry in this failure chain | Act and tell: one retry per chain, Undo until the retried step starts (slice 2) | none | |
| 109 | | `ready_waiting` | a task at Ready to merge with an open card or no card for over 24 h | Digest mention only, never a new card | none | |
| 110 | | `branch_gone` | the merge watch finds the task branch deleted on the forge without a merge | Needs you `branch_moved`, as today; digest line | none | |
| 111 | | `stale_project` | no task, message or push in 60 days | Propose: "Archive <project>?" (team subject, slice 4) | none | |
| 112 | | `flaky_check` | the same gate fails then passes on the same SHA (a Retry of checks), twice in 30 days | Propose, with both tails as evidence | model, slice 3, to name the test | |
| 113 | | `findings_unaddressed` | Review findings on a merged task naming files the fix rounds never touched | Propose | model | |
| 114 | | `notebook_stale` | an entry whose `repo` source file changed since it was written, or an `own` entry older than 90 days | Propose: "This note may be out of date" with a one-tap Mark stale | model for "contradicted", words only | |
| 115 | | `repo_reach` | hello catalog gains or loses a repository | Digest line; a lost repository with open tasks: the existing access card | none | |
| 116 | | `connection_health` | `limited` with a reset over 48 h away, `sign_in_again`, a key expiring within 7 days | The existing Needs you once; digest line otherwise | none | |
| 117 | | `improvement_noticed` | a specialist calls `note_improvement{text, repo, path}` during a step | Propose: one suggestion per note | model, to merge near-identical notes | |
| 118 | |
| 119 | `notebook_stale` never hides an entry on its own; the tap does, as a |
| 120 | person's action with the ordinary Undo. Cross-creator duplicates are |
| 121 | links in every slice of this spec. Thresholds are constants beside the |
| 122 | detector and appear in its fixture; the similarity function is |
| 123 | `record_task`'s. |
| 124 | |
| 125 | ## 3. Action classes and the policy table |
| 126 | |
| 127 | Four classes, named in the registry, enforced in the store under the |
| 128 | principal of §1, never by detector code or a model. |
| 129 | |
| 130 | **Act and tell.** Deterministic only, within the person's own subjects, |
| 131 | no model spend, undoable for seven days or until a later change makes |
| 132 | the undo impossible (409 with the reason, as the home card's Undo). The |
| 133 | action, its receipt card and its `housekeeping` event are written in one |
| 134 | transaction with the ledger transition (§4); the card appears on the |
| 135 | Housekeeping view at once and in the conversation at its `visible_at` |
| 136 | (§4, quiet hours). Undo restores the prior state through the same store |
| 137 | functions a person's Undo uses (`uncombine`, which restores the folded |
| 138 | task and its thread exactly and removes the fold from the destination) |
| 139 | and moves the ledger row to `undone`, a retained veto. |
| 140 | |
| 141 | **Automatic retry, its Undo and its fencing** (slice 2). The action is |
| 142 | the ordinary `RetryTask` path under the principal, so it does what a |
| 143 | person's Retry does: the step goes `queued`, `attempt` becomes n+1, and |
| 144 | `reason`, `pushed`, `terminated`, `summary`, `headline`, `log_tail`, |
| 145 | `activity`, `started_at`, `finished_at` are cleared; for Engineering |
| 146 | without a republish `candidate_sha` and `from_attempt` are cleared too; |
| 147 | the task's `stage` returns to `in_progress` and its `needs_you` is |
| 148 | recomputed. The ledger row's `result` therefore stores the **complete |
| 149 | snapshot** of every one of those fields, on the step and on the task, |
| 150 | plus both revisions, before the call. Undo is offered only while the |
| 151 | retried step is still `queued` on the instance and no `step{running, |
| 152 | attempt: n+1}` report has been accepted. Undo writes, in one |
| 153 | transaction: a durable `cancel_step` for attempt n+1; the snapshot's |
| 154 | fields back onto the step and task; and `undone_attempt = n+1` on the |
| 155 | step. **Attempts never go backwards**: the step keeps `attempt` n+1 and |
| 156 | the snapshot's `state`, `reason` and Needs you, so a later report for |
| 157 | attempt n+1 is accepted only if it is the termination (the instance |
| 158 | already drops reports for attempts below the current one; this adds |
| 159 | dropping non-terminal reports for an `undone_attempt`). A person's Retry |
| 160 | after an Undo gives attempt n+2 as usual. If a `running` report for n+1 |
| 161 | commits first, the Undo gets 409 with the current action and the person |
| 162 | is pointed at the ordinary Cancel. Nothing about merge eligibility is |
| 163 | special here: the retried task earns `merge_eligible`, `ready_sha` and |
| 164 | its cards through the slice 4c policy as any task does; what housekeeping |
| 165 | may never do is write those fields or a merge card directly, and the |
| 166 | principal's store functions refuse those writes. |
| 167 | |
| 168 | **Propose.** Creates a **suggestion** (§5), never a task, and writes to |
| 169 | no other resource. De-duplication against tasks records |
| 170 | `Suggestion.related_task` on the suggestion; it never appends to the |
| 171 | task. Costs nothing unless `judgement: model`, in which case one |
| 172 | reserved housekeeping turn. |
| 173 | |
| 174 | **Ask once.** Shared, irreversible or costly; a Needs you card asked |
| 175 | once per key, answered by the subject's owner only. In this spec it is |
| 176 | used only by `stale_project` in slice 4. Automatic retries of pushed |
| 177 | work are not asked: the existing Needs you `retry` card already covers |
| 178 | them and is unchanged. |
| 179 | |
| 180 | **Never.** Delete tasks, projects, branches, notes or usage rows; merge, |
| 181 | or alter `merge_eligible`, `merge_asked`, an open merge card or the |
| 182 | checks-exception decision (combining another task into one with an open |
| 183 | merge card is allowed and leaves that card, its SHA and its answer |
| 184 | exactly as they were; closing a task that has a decision still open is |
| 185 | not); touch another person's task or notebook, |
| 186 | including as a fold's destination; create or start a task from a |
| 187 | suggestion without a tap; dispatch past the reservation or on a |
| 188 | connection that is `limited` or of unknown tier; post more than receipts |
| 189 | and one digest line a day; change a setting. Refused in the store, a |
| 190 | `refused` ledger row, shown on the view. |
| 191 | |
| 192 | | Class | Needs | Costs | Reversal | Tells the person | |
| 193 | |---|---|---|---|---| |
| 194 | | Act and tell | own subject, deterministic, reversible | 0, or one reserved step (retry) | Undo, 7 days (retry: until the step starts) | receipt card, digest | |
| 195 | | Propose | any subject | 0 or one reserved turn | dismiss | Suggestions lane, digest | |
| 196 | | Ask once | shared or irreversible, owner answers | 0 | the answer | one Needs you card | |
| 197 | | Never | | | | refused, on the view | |
| 198 | |
| 199 | ## 4. Control |
| 200 | |
| 201 | **Budget by reservation.** Per person per day (Paul's ruling): 4 |
| 202 | judgement turns, 150,000 tokens and 3 automatic retries. A ledger row |
| 203 | that will spend holds a **reservation** written in its `claimed` |
| 204 | transaction: the claim sums today's reserved and charged figures for the |
| 205 | person and refuses the claim (`held`, §4 ledger) if the new reservation |
| 206 | would exceed any limit, so two concurrent claims cannot both pass. A |
| 207 | judgement turn reserves one turn and its share of the day's tokens, |
| 208 | 150,000 / 4 = 37,500, so all four turns fit (Paul, 2026-11-08; the |
| 209 | token budget stays the binding total). A retry reserves one |
| 210 | retry and 100,000 tokens, covering the retried Engineering step and the |
| 211 | review and checks that follow it, and an execution cap: the retried step |
| 212 | runs under the ordinary `step_timeout`, at most the ordinary two fix |
| 213 | rounds, and every step it causes carries `caused_by: <action_id>` on |
| 214 | dispatch and on its usage rows. If today's remaining tokens are below a |
| 215 | reservation, the claim is `held`. |
| 216 | |
| 217 | **One cap across attempts.** Every frame the reservation pays for |
| 218 | carries `max_tokens` = reserved minus charged so far, so a failover or |
| 219 | a second attempt inherits the remainder, never a fresh cap; below a |
| 220 | floor of 5,000 the turn or step ends `failed` with reason `budget`, and |
| 221 | the harness's own limit enforces the figure. Usage rows are charged to |
| 222 | the action as each attempt's row arrives; when a step overruns its |
| 223 | share, the overrun is charged and the day's remaining tokens shrink by |
| 224 | it (person turns are never budgeted, so nothing of theirs is taken). |
| 225 | |
| 226 | **Release only after reconciling.** A reservation is released only when |
| 227 | the attempt's termination proof has arrived **and** its usage has been |
| 228 | charged: the row's figure when `complete: true`, the harness's partial |
| 229 | figures when `complete: false`, and the **whole reservation** when no |
| 230 | figure came at all (unknown is charged in full, never zero). Until then |
| 231 | the row is `releasing` and still counts against the day. Yield, Pause |
| 232 | and cancel all go through this path. |
| 233 | |
| 234 | **Stand-down.** Housekeeping dispatches nothing that spends when any |
| 235 | limit is reached, and the headroom test applies to the **connection the |
| 236 | choice function actually selected**, never to the fleet: the selected |
| 237 | pair's headroom must be reported, checked within the last fifteen |
| 238 | minutes (`checked_at`, re-probed if older by the §2.7 probe of |
| 239 | Connections), and below 0.8 utilization; otherwise the claim is `held` |
| 240 | and no other connection is tried in its place. Unknown headroom means |
| 241 | stand down, not proceed. Deterministic actions that spend nothing |
| 242 | (combine, digest lines) carry on. The digest says "Housekeeping stood |
| 243 | down: today's budget is used" or "... Claude is near its limit". |
| 244 | |
| 245 | **Tier at selection.** A housekeeping turn asks the choice function for |
| 246 | role `housekeeping` with a **tier ceiling** of `cheap`: pairs above the |
| 247 | ceiling are filtered out before stickiness or preference apply, and if |
| 248 | none remains the turn is `held`. Tiers come from Connections slice 3; |
| 249 | until that lands, no pair has a tier, so judgement turns do not run and |
| 250 | slice 3 of this spec waits on it. |
| 251 | |
| 252 | **Person turns pre-empt**, in three places. In the queue: `dispatchNext` |
| 253 | takes person turns first, then move-in and explore, then housekeeping. |
| 254 | On yield: a person's message cancels a running housekeeping turn as it |
| 255 | does a move-in (`yielded`), its reservation goes to `releasing` until |
| 256 | termination and the charge are in, and the finding returns to `held`. |
| 257 | On steps: a retry dispatched by housekeeping is |
| 258 | deferred behind any step a person started and never runs beside one; a |
| 259 | person's own Retry on the same task supersedes it, and the housekeeping |
| 260 | attempt is dropped as `superseded`. |
| 261 | |
| 262 | **Cadence.** Event-driven first: each detector lists its event types |
| 263 | and `advance` runs the registry for the affected subject inside the |
| 264 | transaction that wrote the event. Plus one **daily sweep** per person at |
| 265 | 03:00 in the person's zone (UTC until known) for the time-based |
| 266 | detectors; one pass, never a loop. |
| 267 | |
| 268 | **Rate limits** are in the registry: `retry_transient` one per failure |
| 269 | chain; `duplicate_same_creator` unbounded; `flaky_check` once per gate |
| 270 | per week; `improvement_noticed` five per task; and a ceiling of ten |
| 271 | actions and five new suggestions per person per day, after which |
| 272 | findings are held. |
| 273 | |
| 274 | **The ledger state machine.** `chat_housekeeping` (§6) is the loop's |
| 275 | memory, unique on `(team, detector, key)` for team subjects and |
| 276 | `(team, person, detector, key)` for personal ones, and every row moves |
| 277 | only forward: |
| 278 | |
| 279 | - `claimed`: inserted with `claimed_at`, the reservation and the |
| 280 | subject's `subject_revision`. A key that already exists is a no-op |
| 281 | unless it is `held`, `failed` with no recovery yet, or `vetoed` past |
| 282 | its window with a recurrence left (below). |
| 283 | - A deterministic action that spends nothing claims and acts in **one |
| 284 | transaction** (`claimed → done` never commits separately). A spending |
| 285 | action commits `claimed` first, dispatches, and moves to `done` on the |
| 286 | report. |
| 287 | - `claimed → done`: the action, its receipt and its event, in one |
| 288 | transaction. `claimed → refused`: the principal check failed. |
| 289 | `claimed → failed`: the action errored; the sweep may re-claim a |
| 290 | `failed` row once, then it stays. |
| 291 | - **Recovery.** A row found in `claimed` at start-up, or older than ten |
| 292 | minutes at any sweep, is revalidated: the subject is read and its |
| 293 | revision compared with `subject_revision`. Unchanged and nothing |
| 294 | dispatched (no attempt recorded): the claim is **released** to `held` |
| 295 | and re-run as a fresh finding. Unchanged and dispatched: the row waits |
| 296 | for the runner's `sync` to settle the attempt, as steps do, then |
| 297 | advances to `done` or `failed`. Changed: `expired` with reason |
| 298 | `subject_moved`, the reservation reconciled as in §4 and released. |
| 299 | A row never silently stays `claimed`. |
| 300 | - `done → undone`: a retained veto; the key never acts again. |
| 301 | - `held`: capacity or budget was lacking, or the turn yielded; a held |
| 302 | row is claimed when the next sweep or event finds room. At most 20 |
| 303 | held rows per person; beyond that the oldest is dropped as `expired`. |
| 304 | - `vetoed`: a dismissed suggestion's key. Within 30 days the key is a |
| 305 | no-op. After 30 days, while `recurrences` is 0, the next finding |
| 306 | re-claims the row and sets `recurrences` to 1; once it is 1 the key is |
| 307 | a no-op for ever, whatever the window. |
| 308 | |
| 309 | **Verdicts through the mutation ledger.** `housekeeping_verdict` is a |
| 310 | designated mutation (`MutationKinds` gains `verdict`), target the |
| 311 | finding id, idempotent per finding across the turn's attempts like any |
| 312 | kind. The instance accepts a verdict only if its `finding_id`, `subject` |
| 313 | and `subject_revision` match a finding it issued in that turn's frame |
| 314 | and the subject has not moved; anything else is refused, recorded as an |
| 315 | error for the detector, and the finding stays `held` for one more turn. |
| 316 | A yielded or failed turn leaves its findings `held`; a replayed verdict |
| 317 | after failover is answered from the ledger with `replayed: true`. |
| 318 | |
| 319 | **Quiet hours.** 22:00 to 08:00 in the person's zone: the loop may act |
| 320 | and claim, but every receipt and digest line gets `visible_at` 08:00 or |
| 321 | the person's first message, whichever is first. The Housekeeping view |
| 322 | shows them at once. |
| 323 | |
| 324 | **Pause.** One switch, `PUT /api/v1/housekeeping {paused}`. Paused: no |
| 325 | detector runs, no sweep, nothing posted; running housekeeping turns and |
| 326 | retries are cancelled and their reservations reconciled and released |
| 327 | through the path above; existing Undo stays. |
| 328 | |
| 329 | **The digest.** Once a day when something happened, one instance-written |
| 330 | line: "Tidied 2 things, suggested 1. [Housekeeping]". |
| 331 | |
| 332 | **The Housekeeping view** (`/housekeeping`, beside Notebook in the |
| 333 | header): Pause; today's three budgets as quiet meters, reserved and |
| 334 | charged; actions newest first with evidence and Undo while possible; |
| 335 | suggestions; refusals and errors; detectors with state, reason and the |
| 336 | re-enable switch. |
| 337 | |
| 338 | **Failure containment.** Failures are counted in |
| 339 | `chat_housekeeping_failures` written in its **own transaction after the |
| 340 | action's rollback**, so an error cannot erase its own record. A detector |
| 341 | is auto-disabled for a person when, within seven days, it accumulates |
| 342 | two of: an action undone, an action `failed`, a judgement turn `failed` |
| 343 | or refused for a forged verdict, or a retried step that failed again. It |
| 344 | says so once in the digest and the view offers the switch |
| 345 | (`PUT /housekeeping/detectors/{id} {enabled}`); re-enabling clears the |
| 346 | count. Nothing re-enables on its own. |
| 347 | |
| 348 | ## 5. Suggestions |
| 349 | |
| 350 | A suggestion is a row (§6) with a title, a short text, structured |
| 351 | evidence, a subject, an optional `related_task` and an audience. Paul's |
| 352 | ruling: it shows as a **folded "Suggestions (3)" group at the bottom of |
| 353 | the Tasks page**, collapsed by default, rows muted with no track, and in |
| 354 | full on the Housekeeping view. No sidebar count. |
| 355 | |
| 356 | Two quiet actions per row. **Make it a task** calls `record_task` as |
| 357 | the tapper, with the suggestion as brief and its project, through the |
| 358 | ordinary path including the duplicate check; the suggestion becomes |
| 359 | `accepted` with the task id. **Dismiss** marks it `dismissed` and vetoes |
| 360 | its key for 30 days. |
| 361 | |
| 362 | Suggestions **decay**: 14 days open becomes `expired`; expired and |
| 363 | dismissed rows are kept 30 days for the view, then deleted by the |
| 364 | retention sweep that trims usage rows. |
| 365 | |
| 366 | **De-duplication**, in order: by key against open and recent |
| 367 | suggestions (no-op); against open tasks in the same project by |
| 368 | `record_task`'s similarity, in which case the suggestion is still |
| 369 | created but `related_task` is set and the row reads "Related to [task]" |
| 370 | (the task is not written to); within a judgement turn, where the model |
| 371 | may merge near-identical `improvement_noticed` findings into one |
| 372 | verdict, binding every merged finding id. **At most five open per |
| 373 | person** (ten team-wide); a sixth is `held`. |
| 374 | |
| 375 | ## 6. Data model, API v1, wire, tests |
| 376 | |
| 377 | **Tables** (migration 0050): |
| 378 | |
| 379 | - `chat_housekeeping`: `id`, `team`, `person` (null for team subjects), |
| 380 | `detector`, `subject_kind`, `subject_id`, `subject_revision`, `key`, |
| 381 | `class`, `state` (`claimed`, `held`, `done`, `undone`, `refused`, |
| 382 | `failed`, `vetoed`, `expired`), `claimed_at`, `attempt` (the dispatch |
| 383 | it made, null before), `reserved {turns, tokens, retries}`, `charged |
| 384 | {turns, tokens, retries, complete}`, `releasing` (bool), `evidence`, |
| 385 | `result` (the full undo snapshot of §3), `visible_at`, `undo_until`, |
| 386 | `recurrences`, `expired_reason`, `at`, `undone_at`, `revision`; unique |
| 387 | indexes as in §4. |
| 388 | - `chat_housekeeping_failures`: `person`, `detector`, `kind`, `at`. |
| 389 | - `chat_suggestions`: `id`, `team`, `audience_person`, `detector`, |
| 390 | `subject_kind`, `subject_id`, `project`, `key`, `title`, `text`, |
| 391 | `evidence`, `related_task`, `state` (`open`, `held`, `accepted`, |
| 392 | `dismissed`, `expired`), `task_id`, `created_at`, `expires_at`, |
| 393 | `revision`; `chat_suggestion_dismissals (suggestion, person)`. |
| 394 | - `chat_housekeeping_settings`: `person`, `paused`, `disabled` (JSON: |
| 395 | detector to reason and time), `last_digest_at`, `revision`. |
| 396 | - `chat_turns.kind` gains `housekeeping`; `chat_usage` gains `role` |
| 397 | value `housekeeping` and `caused_by`; `chat_steps` gains `caused_by` |
| 398 | and `undone_attempt`. |
| 399 | |
| 400 | **Resources.** `GET /api/v1/housekeeping` returns `Housekeeping {paused, |
| 401 | budget {turns {reserved, charged, limit}, tokens {...}, retries {...}}, |
| 402 | detectors[{id, class, enabled, disabled_reason}], actions[], refusals[], |
| 403 | revision}`; `PUT /api/v1/housekeeping {paused, revision}`; |
| 404 | `PUT /api/v1/housekeeping/detectors/{id} {enabled, revision}`; |
| 405 | `GET /api/v1/housekeeping/actions?before=&limit=`; |
| 406 | `POST /api/v1/housekeeping/actions/{id}/undo` (409 with the current |
| 407 | action when no longer undoable); `GET /api/v1/suggestions`; |
| 408 | `POST /api/v1/suggestions/{id}/accept` returns `TaskAccepted`; |
| 409 | `POST /api/v1/suggestions/{id}/dismiss`. Events `housekeeping` and |
| 410 | `suggestion`. `Snapshot` gains `suggestions` and `housekeeping_summary |
| 411 | {open_suggestions, paused, disabled}`. `Card` gains kind `housekeeping` |
| 412 | with `action_id`, `visible_at` and `ChoiceUndo`; the combined card is |
| 413 | its first instance. `Step` and `Task` gain `caused_by`. |
| 414 | |
| 415 | **Wire.** Instance to runner: `message{kind: housekeeping, max_tokens, |
| 416 | findings[{id, subject, subject_revision, evidence}]}`; the proxy mounts |
| 417 | **only** `status`, `read_task`, `find`, `search_code`, `read_file`, |
| 418 | `read_notes` and `housekeeping_verdict` for this kind, and the runner's |
| 419 | launcher policy (`policy.go`, `TestConversePolicyCoversEveryTool`) |
| 420 | carries the same allowlist, so a frame or a model asking for anything |
| 421 | else is refused at both ends; 24 calls as explore. `dispatch` gains |
| 422 | `caused_by`, `not_before_person_steps: true`. Runner to instance: `step` |
| 423 | reports gain `noticed[{text, repo, path}]` from the pinned |
| 424 | `note_improvement` tool (five per step, 280 bytes each); the merge watch |
| 425 | reports `branch_gone{task, branch}`. Fixtures under |
| 426 | `internal/wire/wiretest/testdata`: `api/housekeeping.json`, |
| 427 | `api/housekeeping-paused.json`, `api/action-combined.json`, |
| 428 | `api/action-retry.json`, `api/action-undone.json`, |
| 429 | `api/action-refused.json`, `api/suggestions.json`, |
| 430 | `api/suggestion-related.json`, `api/event-housekeeping.json`, |
| 431 | `api/event-suggestion.json`, `api/card-housekeeping.json`, |
| 432 | `frames/message-housekeeping.json`, `frames/step-noticed.json`, |
| 433 | `frames/branch-gone.json`, `frames/dispatch-caused-by.json`. The |
| 434 | secret-shape guard covers the new types. |
| 435 | |
| 436 | **Tests.** Unit: a deterministic fixture per detector (store snapshot |
| 437 | in, exact findings out, threshold edges included), the rate table, and |
| 438 | `TestRegistryModelMeansPropose`. Contract, each with a mutation observed |
| 439 | failing: `TestHousekeepingPrincipal` (a fold whose destination belongs to |
| 440 | another creator, a suggestion related to another's task, a retry on |
| 441 | another's step, and a detector running inside `advance` for a person |
| 442 | removed from the roster mid-turn: every one `refused`, nothing changed); |
| 443 | `TestHousekeepingReservation` (two claims racing the last turn: one |
| 444 | `claimed`, one `held`; a retry reserves 100,000 and its fix round is |
| 445 | charged to it; a failover attempt's `max_tokens` is the remainder, and |
| 446 | the floor ends it `budget`; an attempt with no usage figure charges the |
| 447 | whole reservation; a yield, a Pause and a cancel each keep the row |
| 448 | `releasing` until termination and the charge, then release); |
| 449 | `TestHousekeepingStandsDown` (the selected pair's headroom unknown, at |
| 450 | 0.8, or checked over fifteen minutes ago: `held`, no other connection |
| 451 | tried; combine still acts); `TestHousekeepingTier` (a `standard` pair |
| 452 | alone: `held`; no tiers at all: no turn); `TestHousekeepingPreempts` (a |
| 453 | person's message yields the turn; a person's Retry supersedes the |
| 454 | automatic one; a person step dispatched first); |
| 455 | `TestHousekeepingUndoRoundTrips` (combine then Undo: both tasks and |
| 456 | threads equal their prior fixture byte for byte, destination included, |
| 457 | key `undone`, a second finding a no-op; retry then Undo: every field |
| 458 | `RetryTask` cleared equals the snapshot on step and task, `attempt` stays |
| 459 | n+1, `undone_attempt` set, a late `running` report for n+1 dropped and |
| 460 | its termination accepted, a person's Retry then gives n+2; Undo racing |
| 461 | the `running` report: exactly one commits, the other 409); |
| 462 | `TestHousekeepingRetryChain` (one automatic retry per chain, termination |
| 463 | proof required, a pushed step never retried, the second failure is |
| 464 | Needs you `retry`; the retried task later earns `merge_eligible`, |
| 465 | `ready_sha` and its merge card through the ordinary policy, while a |
| 466 | housekeeping principal writing any of them directly is refused); |
| 467 | `TestHousekeepingNever` (the principal attempting delete, merge, a |
| 468 | `limited` connection, the eleventh action: refused at the store, a |
| 469 | `refused` row); `TestHousekeepingLedger` (replayed event; a crash after |
| 470 | `claimed` with nothing dispatched: released to `held` at restart; a |
| 471 | crash after dispatch: settled by `sync`; the subject moved meanwhile: |
| 472 | `expired` with `subject_moved` and the reservation released; a |
| 473 | deterministic action's claim and effect in one transaction; held then |
| 474 | claimed; veto then one recurrence then none; team-scoped key raised by |
| 475 | two people once); |
| 476 | `TestHousekeepingVerdicts` (a verdict with a forged finding id, a stale |
| 477 | `subject_revision`, a subject that moved: refused and counted; a replay |
| 478 | after failover `replayed: true`; a yielded turn leaves findings held); |
| 479 | `TestHousekeepingHostile` (a repository file and a notebook entry |
| 480 | containing instructions to combine, cancel, merge or call other tools: |
| 481 | the turn's only effect is verdicts, and only on issued findings); |
| 482 | `TestHousekeepingAutoDisable` (two failures of mixed kinds within seven |
| 483 | days: disabled, one digest line, failure rows survive the action's |
| 484 | rollback, re-enable clears); `TestSuggestionsLane` (five open, sixth |
| 485 | held, accept through `record_task`, dismiss vetoes, related task |
| 486 | untouched, decay); `TestHousekeepingQuietHours` (an action at 02:00 |
| 487 | shows on the view at once and in the conversation at 08:00). Headless: |
| 488 | `H1` two similar tasks in one message, combined, Undo from the receipt |
| 489 | restores both; `H2` (slice 2) the runner killed before any push, |
| 490 | restarted, one automatic retry with a receipt, a second kill is Needs |
| 491 | you; `H3` (slice 3) a judgement turn with the fake CLI produces one |
| 492 | suggestion and charges one turn. Browser: the view and the lane at 1280 |
| 493 | and 390. |
| 494 | |
| 495 | ## 7. Slices |
| 496 | |
| 497 | | Slice | Content | Gate | Size | |
| 498 | |---|---|---|---| |
| 499 | | 1 The smallest useful loop | Registry; `chat_housekeeping` with the state machine and reservations; the housekeeping principal in the store functions; `duplicate_same_creator` as the first detector, its action the reversible combine from `thin-v1-ux1` (same creator, both tasks checked in the transaction, Undo restores both); `duplicate_possible` as links; Pause; quiet hours; the digest line; the Housekeeping view with Undo and refusals; `chat_housekeeping_failures` and auto-disable. No spend, no model turns, no suggestions | `thin-v1-ux1`'s combine merged first; `TestHousekeepingPrincipal`, `Ledger` (including claim recovery at restart and `subject_moved`), `UndoRoundTrips` (combine), `Never`, `AutoDisable`, `QuietHours`; H1 | 3 days | |
| 500 | | 2 Retries and suggestions | `retry_transient` (pre-push only, one per chain, Undo until the step starts, `caused_by` charging); `chat_suggestions`, the lane, accept and dismiss, decay, de-duplication by `related_task`, the cap; `ready_waiting`, `branch_gone`, `repo_reach`, `connection_health` digest lines; `flaky_check` without the model | Automatic retries ship only after `Reservation` (caps, remainder, unknown charged in full, releasing), `StandsDown` (selected pair), `Preempts`, `RetryChain`, `UndoRoundTrips` (snapshot, fencing and the race), `Principal` (foreign owner), the dispatched-claim recovery in `Ledger` and `AutoDisable` are green; H2 | 2.5 days | |
| 501 | | 3 Judgement | turn kind `housekeeping`, tier ceiling, `max_tokens`, the two-ended allowlist, `housekeeping_verdict` as a mutation kind, the sweep; `note_improvement` and `improvement_noticed`; `findings_unaddressed`; `notebook_stale` as a proposal; model naming for `flaky_check` | **Depends on Connections slice 3 (tiers)**; `Tier`, `Verdicts`, `Hostile`, `StandsDown`; H3 | 2 days | |
| 502 | | 4 Team scope | team suggestions with per-person dismissal, `stale_project` with its ask-once, the owner's team budget and team Pause, acting on team subjects by the owner | team-keyed `Ledger` cases | 1.5 days | |
| 503 | |
| 504 | Each slice lands headless first, then staging with the real CLI, then |
| 505 | UI, as thin v1 §8. Slice 1 is on by default with Pause as the exit; it |
| 506 | spends nothing and can only combine and undo. |
| 507 | |
| 508 | ## 8. Beyond code |
| 509 | |
| 510 | The same loop serves a business or a family when three things change |
| 511 | and nothing in §§3 to 5 does. **Subjects** widen: a person's area, a |
| 512 | shared responsibility, a recurring obligation, a decision. **Detectors** |
| 513 | are added to the registry over new facts: a recurring chore with no |
| 514 | completion since its period (`chore_overdue`, propose a reminder), a |
| 515 | notebook decision whose review date has passed (`decision_stale`, |
| 516 | propose revisiting it), a question with no owner after N days |
| 517 | (`unowned_followup`, ask once who takes it), spend drifting from its |
| 518 | usual level on a connected ledger (`spending_drift`, propose a look). |
| 519 | **Data sources** become connections of new kinds (a calendar, a shared |
| 520 | list, an accounts export, a mailbox) with the same consent model as |
| 521 | model connections: added by the person who owns them, readable by that |
| 522 | person's housekeeping, shared with the team only by an explicit grant, |
| 523 | never a secret on the instance. For a family the owner role matters |
| 524 | more than for a one-person team: the owner sets the team Pause and the |
| 525 | team budget, and personal subjects stay personal even from the owner. |
| 526 | Before any of it is built: a typed fact store the detectors read instead |
| 527 | of the chat tables, a consent record per source and per audience, and |
| 528 | copy a non-developer reads without flinching. None of that is designed |
| 529 | here. |
| 530 | |
| 531 | ## 9. Rulings and decisions |
| 532 | |
| 533 | Paul, 2026-11-08: **budget defaults** 4 judgement turns, 150,000 tokens |
| 534 | and 3 automatic retries per person per day, standing down at 80%; |
| 535 | **suggestions** as a folded group at the bottom of Tasks plus the |
| 536 | Housekeeping view, five open per person. Both are folded in above. |
| 537 | |
| 538 | Taken here, for review rather than decision: automatic retry acts only |
| 539 | on steps that never pushed and is otherwise the existing Needs you card; |
| 540 | cross-creator duplicates are links only in every slice; model judgement |
| 541 | produces suggestions only. No decision is open for Paul in this |
| 542 | revision. |
| 543 | |
| 544 | ## 10. Risks |
| 545 | |
| 546 | Headroom is best effort, so the stand-down rule is conservative by |
| 547 | design (unknown means stop), and on a week when Claude reports no figure |
| 548 | judgement turns simply do not run. A deterministic detector that is |
| 549 | wrong on real data acts before it is undone twice; the seven-day Undo, |
| 550 | the retained veto and auto-disable bound that. Slice 1 depends on the |
| 551 | combine landing on `thin-v1-ux1` first. Slice 3 depends on Connections |
| 552 | slice 3 for tiers and until then has nothing cheap to run on. The |
| 553 | judgement turn reads code and notes that may be hostile; its only effect |
| 554 | is a verdict bound to a server-issued finding, enforced at the proxy and |
| 555 | the launcher, and `TestHousekeepingHostile` is the regression guard. |
| 556 | |