Skip to content

Deepen Delivery's stage into one module that records both Recovery and the Command record #865

Closed

Description

@JacobStephens2

What to build

Give Delivery one module that owns its stage. Today each Delivery step records its stage twice, by hand:

  • once in the stage that a Failed run's recovery lines report as Stopped at:;
  • once in the Command record stage that thirdshift status and the Console show.

The mapping between the two vocabularies is written nowhere. It is spread over about a dozen adapter methods and one partial match in the Repair loop's adapter.

After this change, Delivery's steps and the Repair loop name each stage they enter through their Outside seam, and one exhaustive table maps it to both records. What users see does not change: every Stopped at: line and every Command record stage stays as it is today.

Acceptance criteria

  • A Delivery stage module owns a Delivery Stage enum with these variants: Implementation, Spec review, Security review, Push, Pull request readiness, Repair loop round, Repair session, CI watch, Base fix, Self-merge. It also owns the tracker that holds the current stage, which deliver reads when it fails.

  • One exhaustive match maps each variant to its recovery stage and, where there is one, its Command record stage. It reproduces today's pairs exactly:

    Delivery stage Stopped at: Command record stage
    Implementation Implementation none (the Session log names it)
    Spec review Spec review none (the Session log names it)
    Security review Security review Security review
    Push Push pull request
    Pull request readiness Pull request readiness pull request
    Repair loop round Repair none
    Repair session Repair Repair
    CI watch CI watching CI watch
    Base fix Base fix none
    Self-merge Self-merge Self-merge
  • Entering a stage is one call. It sets the tracker and, when the table names a Command record stage, records it. Recording the same Command record stage twice still collapses into one, as it does today.

  • Delivery's Outside gains a stage method. Route::steps calls it before the opening session, the Security review, the push and marking the pull request ready. The Repair loop's existing Outside::stage takes the Delivery Stage instead of the recovery stage. The loop calls it before:

    • each round (a Repair loop round);
    • each Repair session;
    • each push;
    • each CI watch and Check re-run;
    • the Base fix;
    • the Self-merge.
  • The real adapters, InWorktree and RunOutside, implement stage once each, by entering the tracker. None of their other methods sets a stage or calls the Command record's stage recording. RunOutside's partial match is gone, and so is take_to_goal's redundant stage set, since the loop's first round sets it.

  • The opening's stage comes from one fact on the opening: spec review or implementation. It replaces both the catch_up_from_origin test for the initial stage and the kind == "spec-review" string comparison.

  • After a Security hold, the failure path still reports Stopped at: Security review without adding a Command record stage. It does this through a tracker method for that one case, never by entering the stage again.

  • Inline tests cover:

    • the table, through the module's interface. Entering each stage leaves the expected recovery stage and records the expected Command record stage, or none. Use an in-memory recording adapter at the module's own seam, or the existing in-memory Command record test support, whichever the module's interface makes natural; no new global.
    • the Repair loop's Scripted double, which keeps the stages it is given in a list of their own, apart from its call log, so the existing call-sequence assertions stay unchanged. New tests assert the stage in force when a failure happens: a failed merge of the Base branch (Repair loop round), a failed CI watch (CI watch), a failed Repair session (Repair session) and a refused Self-merge (Self-merge).
    • Delivery's own Scripted double, which records stages the same way. New tests assert the stages of the opening session, the Security review, the push and readiness, plus the Security hold case.
  • Existing integration tests that check Stopped at: lines or Command record stages pass unchanged.

  • docs/code-navigation.md's Delivery row names the Delivery stage module.

  • cargo test passes, and cargo clippy and cargo fmt --check are clean.

Blocked by

None (can start immediately)

Decisions

  • Keep both vocabularies; own the mapping. The Stopped at: names and the Command record names are user-visible and already shown by thirdshift status, the Console and Failed run endings. Renaming either one is a separate decision, and this is a behaviour-preserving deepening.
  • Split "Repair" into a Repair loop round and a Repair session. Today one recovery stage, Repair, means two things: being in a round (merging the Base branch, Foreign commits) and running a Repair session. Only the session reaches the Command record, because the glossary's Repair is a session. Two variants make that difference explicit in the table rather than in which call sites happen to log.
  • The steps name the stages; the adapters stop. Stage order is a fact of Delivery's steps and the Repair loop, both of which already sit behind an Outside seam with a Scripted double. Announcing stages there puts stage order where it is tested, and the two doubles plus the real adapters make the seam real. Leaving the calls in the adapters would keep them out of every unit test.
  • Keep the stage recording idempotent and call it on every entry. The Command record already collapses a repeated stage name, so re-entering CI watch on every round records nothing new, exactly as today's repeated calls do.
  • The Session log's own stage route stays. logs::session sets the Command record stage from the session kind when a Session log starts. That route serves Architect runs, Security runs and Resumes outside Delivery. Replacing it belongs to a typed session kind, which is out of scope here. That is why Implementation and Spec review record no Command record stage in the table.
  • A Security hold overrides only the recovery stage. The hold is found after the pull request is ready. Entering Security review again would add a misleading Command record stage after the fact.
  • Leave Spec run's own recovery stages alone. Tickets, and the Spec run's Push before its Spec review, are set outside Delivery, and the recovery stage enum stays shared with them.
  • Stage recording for Pass kinds (Architecture review, Security audit and the rest) is out of scope. They are not Delivery and record one stage each.
  • No GLOSSARY.md or ADR change. Delivery stage is an implementation term, like Ticket board, and the change is easy to reverse.

Architecture review

Strength: Strong · Dependencies: in-process

Files: src/delivery.rs, src/delivery/repair_loop.rs, src/recovery.rs, src/logs.rs, src/logs/command_record.rs, docs/code-navigation.md

Before

flowchart LR
  Steps[Delivery steps] --> IW[InWorktree adapter]
  Loop[Repair loop] --> RO[RunOutside adapter]
  IW -.set + log by hand.-> Rec[Recovery stage]
  IW -.set + log by hand.-> CR[Command record stage]
  RO -.partial match.-> Rec
  RO -.partial match.-> CR
  classDef leak stroke:#dc2626,stroke-width:2px;
  class IW,RO leak
Loading

After

flowchart LR
  Steps[Delivery steps] -->|stage| DS
  Loop[Repair loop] -->|stage| DS
  subgraph DS[Delivery stage module]
    direction LR
    table[one table] --> Rec[Recovery stage]
    table --> CR[Command record stage]
  end
  classDef deep stroke-width:3px;
  class DS deep
Loading

Problem: every Delivery step records its stage twice, in two vocabularies, by hand across about a dozen adapter methods. Nothing tests the mapping, and the Repair loop's double ignores stages.

Solution: the Delivery stage module owns one stage enum and one table to both records, and the steps announce stages through their Outside seam.

Wins

  • Locality: one table, both vocabularies
  • Stage order tested through Outside
  • Adapters lose twenty stage lines
  • "Repair" ambiguity becomes two variants
  • Interface shrinks to one stage call

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