Skip to content

Deepen Recovery so each layer adds its facts and Recovery owns the rules for its lines #867

Closed

Description

@JacobStephens2

What to build

A Failed run's Recovery lines (Stopped at, Progress, Preserved, Retained work, Before retrying, Recovery, and the Launch directory, Continuing and Retry lines) come from facts that four modules add one after another: the Delivery, the Spec run, the Run's start, and the Run's end with its Base fix. Today each of them writes Recovery's public fields directly. The rules that decide what the lines say live with those writers:

  • a Continuation counts as preserved remotely even when the Delivery pushed nothing;
  • the Spec review counts as complete only past the Ticket and Spec review stages, and only when every Ticket was accounted for;
  • the Spec run assigns child Runs' retained work, and the Run's end extends it;
  • the Delivery patches the worktree path in after fail has returned.

Deepen Recovery so it owns those rules behind a small interface. Each layer adds the fact it knows, and Recovery decides how that fact changes the lines. Its fields become private. Nothing a user sees changes: the terminal, Activity log, Command record and Run notification show the same lines in the same order for every Failed run.

Acceptance criteria

  • Recovery's fields are private. Every layer that adds to a Failed run's Recovery does so through Recovery's own methods (see Decisions); no module outside Recovery assigns or extends a Recovery field.
  • The Continuation rule (nothing preserved, but the Issue branch is already on origin, means preserved remotely) is decided inside Recovery, given the Continuation context and whether the branch was already on origin.
  • The Spec review completion rule is decided inside Recovery, from its own stage and whether every Ticket was accounted for. The Spec run no longer reads Recovery's stage to work it out.
  • Retained work from child Runs and from a Run's Base fix accumulates in the order it was added. No layer replaces work another layer added.
  • The Delivery records its worktree path when it builds the Recovery, not by patching the Failed run it has already returned.
  • New unit tests in Recovery's own module exercise each rule through lines() alone:
    • a Continuation with nothing pushed reads preserved remotely, with the Continuing line;
    • a fresh Run with nothing pushed reads no work preserved, with the Retry line;
    • the final review reads complete only past the Spec review with every Ticket accounted for;
    • retained work added by two layers produces both Retained work lines in order, plus the Before retrying line;
    • local preservation names the recorded worktree, or the Launch directory when none is recorded.
  • The existing Failed run, Spec run, Run notification, status and Delivery tests pass with no change to their expected output. The one Run ending test that builds a Recovery by hand builds it through the new methods.
  • GLOSSARY.md gains a Recovery entry: the lines a Failed run ends with, saying where it stopped, what work was preserved and where, and the command that continues or retries it; built only from factory-owned facts, never agent output. The Failed run entry links to it.
  • The domain-to-code index in docs/code-navigation.md gains a Recovery row that names its module and the module's unit tests.

Blocked by

None (can start immediately)

Decisions

  • Deepen Recovery itself, not FailedRun. FailedRun stays a plain record of how a Run ended. Its recovery is still an optional boxed Recovery, so a failure that happens before any worktree exists still has none. Why: the friction is the rules for the Recovery lines, and those rules are about Recovery's facts. Moving them onto FailedRun would only move the field-poking up one level.

  • The interface is "add a fact", not "set a field". Recovery keeps its constructor from a Stage and a Preservation, and gains these methods (the names are suggestions; what each does is the decision):

    • record the worktree that holds retained work;
    • add Ticket progress (landed, total) together with whether every Ticket was accounted for, with Recovery working out the final-review flag;
    • add the Continuation context together with whether the Issue branch was already on origin, with Recovery applying the "preserved remotely" upgrade;
    • add retained child work, which only ever extends;
    • read the stage.

    The methods take &mut self, so layers above the Delivery can add to the Recovery that a FailedRun already carries. Why: each layer knows exactly one fact. Precedence and derived values then sit in one place, where lines() can test them.

  • Ticket progress no longer carries a caller-filled reviewed flag. The Ticket board reports only landed and total, and Recovery stores the reviewed flag it derives. Why: today the Spec run builds the progress, then overwrites reviewed from Recovery's stage. That flag belongs to Recovery's rule, not to the board.

  • Retained child work only accumulates. The Spec run's assignment becomes an add. Why: today the order works only because the Delivery starts with empty retained work. An add is correct whatever the order.

  • The Delivery's fail is given the worktree path. It records the path as it builds the Recovery, instead of the Delivery patching it in afterwards. Why: the Recovery then leaves the Delivery complete for the facts the Delivery owns.

  • The Spec run's fallback stays in the Spec run. When a Spec review delivery fails with no Recovery, the Spec run builds one at Spec review with remote preservation. Why: only the Spec run knows that default. It now builds it with the constructor.

  • The Ticket-phase Recovery still records no worktree. Why: the Ticket phase never reports local preservation, and the path matters only for that line. Adding one would change behaviour, and this is a refactor with no change in behaviour.

  • The line protocol does not change. The prefixes, the order of the lines, local_work and is_line stay as they are. Why: child Run accounting and the readers of Activity logs and Command records depend on them.

  • No ADR. Why: the change is easy to reverse and involves no real trade-off.

Testing decisions

  • Recovery's interface is the test surface. The new unit tests build a Recovery through the new methods and assert on lines() only. Why: today the rules are tested only end to end, through Spec run and Run notification fakes. Recovery's module has no tests of its own.
  • The existing end-to-end tests stay unchanged as the guard that nothing changed in behaviour.

Architecture review

Strength: Strong · Dependencies: in-process

Files: src/recovery.rs, src/failed_run.rs, src/delivery.rs, src/spec_run.rs, src/spec_run/ticket_board.rs, src/run.rs, src/run_ending.rs

Before

flowchart LR
  D[Delivery] -.sets worktree after fail.-> R[Recovery fields]
  S[Spec run] -.reads stage, sets tickets, assigns child work.-> R
  RS[Run start] -.upgrades preservation, sets continuation.-> R
  RE[Run end] -.extends child work.-> R
  R --> L[Recovery lines]
  classDef leak stroke:#dc2626,stroke-width:2px;
  class D,S,RS,RE leak
Loading

After

flowchart LR
  D[Delivery] --> Rec
  S[Spec run] --> Rec
  RS[Run start] --> Rec
  RE[Run end] --> Rec
  subgraph Rec[Recovery]
    direction LR
    facts[added facts] --> rules[precedence rules] --> L[Recovery lines]
  end
  classDef deep stroke-width:3px;
  class Rec deep
Loading

Problem: Recovery is shallow: four modules write its public fields, and the rules that decide its lines are spread across them.

Solution: Make Recovery's fields private behind "add a fact" methods, so the preservation, review-completion and retained-work rules live in Recovery and are tested through lines().

Wins

  • Locality: Recovery rules in one module
  • Tests hit one interface: lines()
  • Assign-versus-extend ordering hazard removed
  • Spec run stops reading Recovery's stage

Activity

  1. added
    needs-triage
    ready-for-agent
    architect-plan
    in-progress
    and removed
    needs-triage
    ready-for-agent
    on Oct 20, 2026
  2. removed
    in-progress
    on Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    architect-plan

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions