specs: housekeeping rev 3 after Astra round 2
Claim recovery at restart and in the sweep (revalidate subject_revision, release to held, settle by sync, or expire subject_moved); vetoed keys reconciled with their single recurrence; deterministic claims act in one transaction. Budgets: retries reserve 100,000 tokens with execution caps, one remaining cap shared across attempts with a floor, reservations released only after termination and charging (unknown charged in full), stand-down tested on the selected connection with fresh headroom. Retry Undo stores the full RetryTask snapshot, attempts never go backwards (undone_attempt fencing), merge eligibility earned by policy while direct housekeeping writes are refused. Tests and slice gates updated.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
1 file changed,
+133
−56
docs/superpowers/specs/2026-11-08-equipo-housekeeping.md+133 −56
CI passed — run details
diff --git a/docs/superpowers/specs/2026-11-08-equipo-housekeeping.md b/docs/superpowers/specs/2026-11-08-equipo-housekeeping.md| index 5af6f2a0..bd59c4e4 100644 |
| --- a/docs/superpowers/specs/2026-11-08-equipo-housekeeping.md |
| +++ b/docs/superpowers/specs/2026-11-08-equipo-housekeeping.md |
| @@ -1,7 +1,7 @@ |
| # Equipo housekeeping: a tidying loop that stays under control |
| -Status: design for Paul's review, 2026-11-08, revision 2 after Astra's |
| -round 1 (NOT READY at cc6ca41). Drafted by Claude (Fable 5.1) on |
| +Status: design for Paul's review, 2026-11-08, revision 3 after Astra's |
| +rounds 1 and 2 (NOT READY at cc6ca41; READY AFTER FIXES at f94fad0). Drafted by Claude (Fable 5.1) on |
| `design-housekeeping` from `thin-v1-conn1` (7946111). Builds on thin v1 |
| (`2026-11-06-equipo-thin-v1.md`), Connections rev 3 |
| (`2026-11-08-equipo-connections.md`, §§3, 4, 6) and the progress logs |
| @@ -138,6 +138,33 @@ functions a person's Undo uses (`uncombine`, which restores the folded |
| task and its thread exactly and removes the fold from the destination) |
| and moves the ledger row to `undone`, a retained veto. |
| +**Automatic retry, its Undo and its fencing** (slice 2). The action is |
| +the ordinary `RetryTask` path under the principal, so it does what a |
| +person's Retry does: the step goes `queued`, `attempt` becomes n+1, and |
| +`reason`, `pushed`, `terminated`, `summary`, `headline`, `log_tail`, |
| +`activity`, `started_at`, `finished_at` are cleared; for Engineering |
| +without a republish `candidate_sha` and `from_attempt` are cleared too; |
| +the task's `stage` returns to `in_progress` and its `needs_you` is |
| +recomputed. The ledger row's `result` therefore stores the **complete |
| +snapshot** of every one of those fields, on the step and on the task, |
| +plus both revisions, before the call. Undo is offered only while the |
| +retried step is still `queued` on the instance and no `step{running, |
| +attempt: n+1}` report has been accepted. Undo writes, in one |
| +transaction: a durable `cancel_step` for attempt n+1; the snapshot's |
| +fields back onto the step and task; and `undone_attempt = n+1` on the |
| +step. **Attempts never go backwards**: the step keeps `attempt` n+1 and |
| +the snapshot's `state`, `reason` and Needs you, so a later report for |
| +attempt n+1 is accepted only if it is the termination (the instance |
| +already drops reports for attempts below the current one; this adds |
| +dropping non-terminal reports for an `undone_attempt`). A person's Retry |
| +after an Undo gives attempt n+2 as usual. If a `running` report for n+1 |
| +commits first, the Undo gets 409 with the current action and the person |
| +is pointed at the ordinary Cancel. Nothing about merge eligibility is |
| +special here: the retried task earns `merge_eligible`, `ready_sha` and |
| +its cards through the slice 4c policy as any task does; what housekeeping |
| +may never do is write those fields or a merge card directly, and the |
| +principal's store functions refuse those writes. |
| + |
| **Propose.** Creates a **suggestion** (§5), never a task, and writes to |
| no other resource. De-duplication against tasks records |
| `Suggestion.related_task` on the suggestion; it never appends to the |
| @@ -174,23 +201,41 @@ that will spend holds a **reservation** written in its `claimed` |
| transaction: the claim sums today's reserved and charged figures for the |
| person and refuses the claim (`held`, §4 ledger) if the new reservation |
| would exceed any limit, so two concurrent claims cannot both pass. A |
| -judgement turn reserves one turn and a per-turn token cap (40,000, |
| -passed to the runner as `max_tokens` on the frame and enforced by the |
| -harness's own limit; the attempt is cancelled at the cap). A retry |
| -reserves one retry and every attempt and step it causes: the retried |
| -step, and the checks, review and fix rounds that follow it, carry |
| -`caused_by: <action_id>` on dispatch, their usage rows carry it, and the |
| -sum is charged to the action as they complete. A failover attempt within |
| -a housekeeping turn is charged to the same reservation. When the charge |
| -is known the reservation is released and the row records `charged`. |
| - |
| -**Stand-down.** Housekeeping dispatches nothing that spends when: any |
| -limit is reached; no connection is `healthy` with a reported utilization |
| -below 0.8; or the best candidate's headroom is **unknown** (no figure |
| -from the provider means stand down, not proceed). Deterministic actions |
| -that spend nothing (combine, digest lines) carry on. The digest says |
| -"Housekeeping stood down: today's budget is used" or "... Claude is near |
| -its limit". |
| +judgement turn reserves one turn and 40,000 tokens. A retry reserves one |
| +retry and 100,000 tokens, covering the retried Engineering step and the |
| +review and checks that follow it, and an execution cap: the retried step |
| +runs under the ordinary `step_timeout`, at most the ordinary two fix |
| +rounds, and every step it causes carries `caused_by: <action_id>` on |
| +dispatch and on its usage rows. If today's remaining tokens are below a |
| +reservation, the claim is `held`. |
| + |
| +**One cap across attempts.** Every frame the reservation pays for |
| +carries `max_tokens` = reserved minus charged so far, so a failover or |
| +a second attempt inherits the remainder, never a fresh cap; below a |
| +floor of 5,000 the turn or step ends `failed` with reason `budget`, and |
| +the harness's own limit enforces the figure. Usage rows are charged to |
| +the action as each attempt's row arrives; when a step overruns its |
| +share, the overrun is charged and the day's remaining tokens shrink by |
| +it (person turns are never budgeted, so nothing of theirs is taken). |
| + |
| +**Release only after reconciling.** A reservation is released only when |
| +the attempt's termination proof has arrived **and** its usage has been |
| +charged: the row's figure when `complete: true`, the harness's partial |
| +figures when `complete: false`, and the **whole reservation** when no |
| +figure came at all (unknown is charged in full, never zero). Until then |
| +the row is `releasing` and still counts against the day. Yield, Pause |
| +and cancel all go through this path. |
| + |
| +**Stand-down.** Housekeeping dispatches nothing that spends when any |
| +limit is reached, and the headroom test applies to the **connection the |
| +choice function actually selected**, never to the fleet: the selected |
| +pair's headroom must be reported, checked within the last fifteen |
| +minutes (`checked_at`, re-probed if older by the §2.7 probe of |
| +Connections), and below 0.8 utilization; otherwise the claim is `held` |
| +and no other connection is tried in its place. Unknown headroom means |
| +stand down, not proceed. Deterministic actions that spend nothing |
| +(combine, digest lines) carry on. The digest says "Housekeeping stood |
| +down: today's budget is used" or "... Claude is near its limit". |
| **Tier at selection.** A housekeeping turn asks the choice function for |
| role `housekeeping` with a **tier ceiling** of `cheap`: pairs above the |
| @@ -202,8 +247,9 @@ slice 3 of this spec waits on it. |
| **Person turns pre-empt**, in three places. In the queue: `dispatchNext` |
| takes person turns first, then move-in and explore, then housekeeping. |
| On yield: a person's message cancels a running housekeeping turn as it |
| -does a move-in (`yielded`), its reservation is released, the finding |
| -returns to `held`. On steps: a retry dispatched by housekeeping is |
| +does a move-in (`yielded`), its reservation goes to `releasing` until |
| +termination and the charge are in, and the finding returns to `held`. |
| +On steps: a retry dispatched by housekeeping is |
| deferred behind any step a person started and never runs beside one; a |
| person's own Retry on the same task supersedes it, and the housekeeping |
| attempt is dropped as `superseded`. |
| @@ -225,19 +271,35 @@ memory, unique on `(team, detector, key)` for team subjects and |
| `(team, person, detector, key)` for personal ones, and every row moves |
| only forward: |
| -- `claimed`: inserted atomically with the reservation and the subject's |
| - revision; a key that already exists in any state other than `held` or |
| - `failed` makes the finding a no-op. |
| +- `claimed`: inserted with `claimed_at`, the reservation and the |
| + subject's `subject_revision`. A key that already exists is a no-op |
| + unless it is `held`, `failed` with no recovery yet, or `vetoed` past |
| + its window with a recurrence left (below). |
| +- A deterministic action that spends nothing claims and acts in **one |
| + transaction** (`claimed → done` never commits separately). A spending |
| + action commits `claimed` first, dispatches, and moves to `done` on the |
| + report. |
| - `claimed → done`: the action, its receipt and its event, in one |
| transaction. `claimed → refused`: the principal check failed. |
| - `claimed → failed`: the action errored; the sweep may retry a `failed` |
| - row once, then it stays. |
| + `claimed → failed`: the action errored; the sweep may re-claim a |
| + `failed` row once, then it stays. |
| +- **Recovery.** A row found in `claimed` at start-up, or older than ten |
| + minutes at any sweep, is revalidated: the subject is read and its |
| + revision compared with `subject_revision`. Unchanged and nothing |
| + dispatched (no attempt recorded): the claim is **released** to `held` |
| + and re-run as a fresh finding. Unchanged and dispatched: the row waits |
| + for the runner's `sync` to settle the attempt, as steps do, then |
| + advances to `done` or `failed`. Changed: `expired` with reason |
| + `subject_moved`, the reservation reconciled as in §4 and released. |
| + A row never silently stays `claimed`. |
| - `done → undone`: a retained veto; the key never acts again. |
| - `held`: capacity or budget was lacking, or the turn yielded; a held |
| row is claimed when the next sweep or event finds room. At most 20 |
| held rows per person; beyond that the oldest is dropped as `expired`. |
| -- `vetoed`: a dismissed suggestion's key, 30 days; after that the key |
| - may recur **once** (`recurrences` counter), then never. |
| +- `vetoed`: a dismissed suggestion's key. Within 30 days the key is a |
| + no-op. After 30 days, while `recurrences` is 0, the next finding |
| + re-claims the row and sets `recurrences` to 1; once it is 1 the key is |
| + a no-op for ever, whatever the window. |
| **Verdicts through the mutation ledger.** `housekeeping_verdict` is a |
| designated mutation (`MutationKinds` gains `verdict`), target the |
| @@ -255,8 +317,9 @@ the person's first message, whichever is first. The Housekeeping view |
| shows them at once. |
| **Pause.** One switch, `PUT /api/v1/housekeeping {paused}`. Paused: no |
| -detector runs, no sweep, nothing posted, reservations released; existing |
| -Undo stays. |
| +detector runs, no sweep, nothing posted; running housekeeping turns and |
| +retries are cancelled and their reservations reconciled and released |
| +through the path above; existing Undo stays. |
| **The digest.** Once a day when something happened, one instance-written |
| line: "Tidied 2 things, suggested 1. [Housekeeping]". |
| @@ -311,10 +374,12 @@ person** (ten team-wide); a sixth is `held`. |
| - `chat_housekeeping`: `id`, `team`, `person` (null for team subjects), |
| `detector`, `subject_kind`, `subject_id`, `subject_revision`, `key`, |
| `class`, `state` (`claimed`, `held`, `done`, `undone`, `refused`, |
| - `failed`, `vetoed`, `expired`), `reserved {turns, tokens, retries}`, |
| - `charged {turns, tokens, retries}`, `evidence`, `result` (enough to |
| - undo), `visible_at`, `undo_until`, `recurrences`, `at`, `undone_at`, |
| - `revision`; unique indexes as in §4. |
| + `failed`, `vetoed`, `expired`), `claimed_at`, `attempt` (the dispatch |
| + it made, null before), `reserved {turns, tokens, retries}`, `charged |
| + {turns, tokens, retries, complete}`, `releasing` (bool), `evidence`, |
| + `result` (the full undo snapshot of §3), `visible_at`, `undo_until`, |
| + `recurrences`, `expired_reason`, `at`, `undone_at`, `revision`; unique |
| + indexes as in §4. |
| - `chat_housekeeping_failures`: `person`, `detector`, `kind`, `at`. |
| - `chat_suggestions`: `id`, `team`, `audience_person`, `detector`, |
| `subject_kind`, `subject_id`, `project`, `key`, `title`, `text`, |
| @@ -324,7 +389,8 @@ person** (ten team-wide); a sixth is `held`. |
| - `chat_housekeeping_settings`: `person`, `paused`, `disabled` (JSON: |
| detector to reason and time), `last_digest_at`, `revision`. |
| - `chat_turns.kind` gains `housekeeping`; `chat_usage` gains `role` |
| - value `housekeeping` and `caused_by`; `chat_steps` gains `caused_by`. |
| + value `housekeeping` and `caused_by`; `chat_steps` gains `caused_by` |
| + and `undone_attempt`. |
| **Resources.** `GET /api/v1/housekeeping` returns `Housekeeping {paused, |
| budget {turns {reserved, charged, limit}, tokens {...}, retries {...}}, |
| @@ -370,27 +436,38 @@ another creator, a suggestion related to another's task, a retry on |
| another's step, and a detector running inside `advance` for a person |
| removed from the roster mid-turn: every one `refused`, nothing changed); |
| `TestHousekeepingReservation` (two claims racing the last turn: one |
| -`claimed`, one `held`; a retry's fix round charged to its action; a |
| -failover attempt charged once; the token cap cancels an attempt); |
| -`TestHousekeepingStandsDown` (unknown headroom, 0.8 utilization, only |
| -limited: nothing spends, combine still acts); `TestHousekeepingTier` (a |
| -`standard` pair alone: `held`; no tiers at all: no turn); |
| -`TestHousekeepingPreempts` (a person's message yields the turn and |
| -releases its reservation; a person's Retry supersedes the automatic |
| -one; a person step dispatched first); `TestHousekeepingUndoRoundTrips` |
| -(combine then Undo: both tasks and threads equal their prior fixture byte |
| -for byte, destination included, key `undone`, a second finding a no-op; |
| -retry Undo before the step starts restores the step's reason and |
| -Needs you; Undo racing the step start: exactly one wins, 409 for the |
| -other); `TestHousekeepingRetryChain` (one automatic retry per chain, |
| -termination proof required, a pushed step never retried, the second |
| -failure is Needs you `retry`, `merge_eligible`, `merge_asked` and an open |
| -merge card untouched by the retried task's later progress); |
| +`claimed`, one `held`; a retry reserves 100,000 and its fix round is |
| +charged to it; a failover attempt's `max_tokens` is the remainder, and |
| +the floor ends it `budget`; an attempt with no usage figure charges the |
| +whole reservation; a yield, a Pause and a cancel each keep the row |
| +`releasing` until termination and the charge, then release); |
| +`TestHousekeepingStandsDown` (the selected pair's headroom unknown, at |
| +0.8, or checked over fifteen minutes ago: `held`, no other connection |
| +tried; combine still acts); `TestHousekeepingTier` (a `standard` pair |
| +alone: `held`; no tiers at all: no turn); `TestHousekeepingPreempts` (a |
| +person's message yields the turn; a person's Retry supersedes the |
| +automatic one; a person step dispatched first); |
| +`TestHousekeepingUndoRoundTrips` (combine then Undo: both tasks and |
| +threads equal their prior fixture byte for byte, destination included, |
| +key `undone`, a second finding a no-op; retry then Undo: every field |
| +`RetryTask` cleared equals the snapshot on step and task, `attempt` stays |
| +n+1, `undone_attempt` set, a late `running` report for n+1 dropped and |
| +its termination accepted, a person's Retry then gives n+2; Undo racing |
| +the `running` report: exactly one commits, the other 409); |
| +`TestHousekeepingRetryChain` (one automatic retry per chain, termination |
| +proof required, a pushed step never retried, the second failure is |
| +Needs you `retry`; the retried task later earns `merge_eligible`, |
| +`ready_sha` and its merge card through the ordinary policy, while a |
| +housekeeping principal writing any of them directly is refused); |
| `TestHousekeepingNever` (the principal attempting delete, merge, a |
| `limited` connection, the eleventh action: refused at the store, a |
| -`refused` row); `TestHousekeepingLedger` (replayed event, restart |
| -between claim and action, held then claimed, veto then one recurrence |
| -then none, team-scoped key raised by two people once); |
| +`refused` row); `TestHousekeepingLedger` (replayed event; a crash after |
| +`claimed` with nothing dispatched: released to `held` at restart; a |
| +crash after dispatch: settled by `sync`; the subject moved meanwhile: |
| +`expired` with `subject_moved` and the reservation released; a |
| +deterministic action's claim and effect in one transaction; held then |
| +claimed; veto then one recurrence then none; team-scoped key raised by |
| +two people once); |
| `TestHousekeepingVerdicts` (a verdict with a forged finding id, a stale |
| `subject_revision`, a subject that moved: refused and counted; a replay |
| after failover `replayed: true`; a yielded turn leaves findings held); |
| @@ -414,8 +491,8 @@ and 390. |
| | Slice | Content | Gate | Size | |
| |---|---|---|---| |
| -| 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`, `UndoRoundTrips` (combine), `Never`, `AutoDisable`, `QuietHours`; H1 | 3 days | |
| -| 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`, `Preempts`, `RetryChain`, `UndoRoundTrips` (retry and the race), `Principal` (foreign owner), restart in `Ledger` and `AutoDisable` are green; H2 | 2.5 days | |
| +| 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 | |
| +| 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 | |
| | 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 | |
| | 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 | |