Skip to content

Spec: Fix run #1784

Closed
4 of 4 issues completed
Closed

Description

@JacobStephens2

Problem Statement

When a pull request waiting in Ready for review in the Inbox develops a Merge conflict with its Base branch or has CI red, or when the Base branch itself goes red on origin, the Day shift currently has no way to ask the factory to simply heal the branch or pull request:

  • Re-running a Ticket run on the originating Issue URL re-runs the entire Process from the opening implementation and code-review sessions, requires an issue (which standalone or Review run pull requests lack), and cannot be triggered across all waiting pull requests as a Pass.
  • A Review run reviews the diff on the Standards and Spec axes and never merges the Base branch in or resolves merge conflicts.
  • A Pickup run only opens an unready CI red on <base> stub issue when the Base branch stays red, waiting for a human to write a task before any agent can touch it, while a Base fix only runs inside another active Ticket run that hits an Inherited failure and always forces a silent Self-merge with no Run notification.
  • From the Console, a Ready for review row showing CI red or Merge conflict offers no one-click command to copy and run a repair.

Solution

Introduce Fix run (thirdshift fix), a new Command with its own Built-in process (fix-run) that repairs either a specific open pull request or, when started with no pull request as a Pass, monitors and repairs a red Base branch and open pull requests with merge conflicts or failing CI:

  1. Targeted pull request Fix run (thirdshift fix <PR URL or number>): Checks out the pull request's head branch in a Worktree, reserves the pull request with in-progress, writes the trusted pull request and linked closing-issue context for Repair sessions, skips any opening implementation or review session, and takes the pull request straight through the Repair loop against its Base branch (merging the Base branch in, resolving merge conflicts via conflict Repairs, pushing, watching CI, fixing failing checks via CI-fix Repairs, and optionally starting a Base fix on Inherited failures).
  2. Unattended Pass mode (thirdshift fix [base <branch>] [--author <login>]):
    • Respects the repository's Command limit on the machine (UpToTheLimit).
    • When --author is not given, first checks the Base branch's latest push CI on origin. On a failed first attempt with failed jobs, requests one re-run of the failed jobs and skips the pass while the re-run runs. If the Base branch remains red and no fix pull request already exists for that Base branch tip commit, branches fix-<base>-<short-sha> off the Base branch in a Worktree, runs a CI-fix session with the failing check details, opens a pull request titled Fix CI on <base>: <check>[, <check>…] targeting the Base branch, and takes it through Delivery.
    • When the Base branch is green (or when --author <login> scopes the pass to pull requests), selects the lowest-numbered open, non-draft, same-repository pull request targeting the Base branch by a Trusted account (or --author) that is not in-progress and has a Merge conflict or CI red, and takes it through the Repair loop.
  3. Configurable Self-merge and Run notification: Follows the standard merge / no-merge flags and merge.always User config setting, plus email / email-unless-merged / no-email and email.always / email.unless_merged, so the operator or cron schedule can choose whether a Fix run automatically performs a Self-merge once green or leaves the pull request ready for review and emails a Run notification.
  4. Failure handling and repeat-Pass prevention: When a Fix run fails or is interrupted, it salvages uncommitted work as thirdshift: failed fix run (<reason>), pushes, converts the pull request back to a draft (unless it is already mergeable and green and only a requested Self-merge was refused), and prints a Recovery command (thirdshift fix <PR URL>). Because the unattended Pass only selects non-draft pull requests and deduplicates Base branch fixes by tip commit SHA, failed attempts are never retried in an infinite loop, while a targeted thirdshift fix <PR URL or number> accepts draft pull requests and marks them ready once green.
  5. Inbox hand-off and Console Copy fix command: In the Console, every Ready for review row with CI red or Merge conflict displays thirdshift fix <PR URL> with a Copy fix command button (both on the row and in Command details). Starting a later Command on the same pull request URL takes over an earlier row waiting in Ready for review or Needs you (taken up by a later Command started at <time>), just as a later Command on the same issue does.

User Stories

  1. As a Day shift operator looking at a Ready for review row in the Console with Merge conflict or CI red, I want a Copy fix command button on the row and in Command details that copies thirdshift fix <PR URL>, so that I can start a repair immediately without typing the pull request URL by hand.
  2. As a Day shift operator, I want to run thirdshift fix <PR URL> or thirdshift fix <PR number> from the Launch directory, so that thirdshift checks out that pull request's head branch in a Worktree and takes it straight through the Repair loop against its Base branch without re-running implementation or code review.
  3. As a Day shift operator, I want a targeted thirdshift fix <PR URL or number> to work on an open pull request by a Trusted account even when it has no linked closing issue, so that hand-opened pull requests and Review run pull requests can be repaired the same way as Ticket run and Spec run pull requests.
  4. As a Day shift operator, I want conflict Repairs and CI-fix Repairs in a Fix run to receive the pull request's title, body, any linked closing issues, and Trusted account comments from the pull request and its closing issues, so that the agent resolves conflicts and test failures in alignment with the Spec and review discussion.
  5. As a Day shift operator, I want every Fix run on a pull request to reserve the pull request on origin and label it in-progress until the run ends, so that concurrent machines or passes never work on the same pull request at the same time.
  6. As a Day shift operator, I want a failed or interrupted Fix run to commit uncommitted work as thirdshift: failed fix run (<reason>), push, convert the pull request back to a draft (unless it is already mergeable and green and only Self-merge was refused), and print thirdshift fix <PR URL> as its Recovery, so that no work is lost and the pull request only claims to be ready when the factory stands behind it.
  7. As a Day shift operator retrying a failed Fix run, I want a targeted thirdshift fix <PR URL or number> to accept an open draft pull request and mark it ready for review once the Repair loop succeeds, so that the Recovery command works directly on the draft pull request left by the failure.
  8. As a Day shift operator, I want a Fix run on a pull request to support base-fix / no-base-fix and base.fix in the User config, so that when the pull request hits an Inherited failure on its Base branch, it can start or wait on a Base fix just like a Ticket run.
  9. As a Day shift operator scheduling unattended maintenance, I want thirdshift fix with no pull request argument (and optional base <branch> / --base <branch>) to run as a Pass that respects the repository's Command limit (UpToTheLimit) and skips cleanly with exit 0 and no Run notification when nothing needs fixing.
  10. As a Day shift operator scheduling thirdshift fix, I want the Pass (when --author is not given) to check the Base branch's latest push CI on origin first, re-running failed jobs once on a first failed attempt and skipping while the re-run runs, so that transient flakes on the Base branch heal without opening a pull request.
  11. As a Day shift operator scheduling thirdshift fix, I want the Pass to repair a persistently red Base branch by branching fix-<base>-<short-sha> off the Base branch in a Worktree, running a CI-fix session with the failing check details, opening a pull request titled Fix CI on <base>: <check>[, <check>…] targeting the Base branch, and taking it through Delivery (treating all red checks as its own to fix rather than Inherited failures), so that a broken default or release branch is repaired automatically.
  12. As a Day shift operator scheduling thirdshift fix, I want the Pass to skip opening another Base branch fix pull request if a fix-<base>-<short-sha> pull request already exists for that exact Base branch tip commit (whether open and ready, in-progress, or draft after a failed attempt), so that the schedule never opens duplicate pull requests or loops on an unfixable Base branch failure.
  13. As a Day shift operator scheduling thirdshift fix, I want a Base branch fix that merges to close any open CI red on <base> or base-fix issue for that branch, so that stale red-branch issues do not linger after the branch is green.
  14. As a Day shift operator scheduling thirdshift fix, when the Base branch is green (or when --author <login> is given), I want the Pass to select the lowest-numbered open, non-draft, same-repository pull request targeting the Base branch by a Trusted account (or --author) that is not in-progress and has a Merge conflict or CI red, and run a Fix run on it.
  15. As a Day shift operator, I want merge / no-merge on the command line and merge.always in the User config, together with email / email-unless-merged / no-email and email.always / email.unless_merged, to control whether a Fix run (for either a Base branch or a pull request) performs a Self-merge once green or leaves the pull request ready for review and emails a Run notification.
  16. As a Day shift operator viewing the Inbox in thirdshift status or the Console, when a Fix run (or any later Command) starts on a pull request that has an earlier row waiting in Ready for review or Needs you, I want the earlier row to leave that group with taken up by a later Command started at <time> and the Fix run's own row to represent the pull request in Ready for review (when ready) or Needs you (when failed).
  17. As a developer customizing factory workflows, I want fix-run to ship as a Built-in process (delivery followed by self-merge) that is listed by thirdshift processes and recorded in Command records, Command logs, and the Activity log.

Implementation Decisions

  • CLI Surface and Argument Parsing:
    • thirdshift fix is a top-level Command.
    • Target argument: optional pull request URL or bare pull request number (thirdshift fix [<PR URL or number>]).
    • Pass-only flags: base <branch> / --base <branch> (naming the Base branch when no pull request is given; rejected with an argument error if combined with a pull request target, since a pull request defines its own Base branch) and --author <login> / author <login> (filtering open pull requests by author in Pass mode; rejected when combined with a pull request target).
    • Shared execution flags: merge / --merge, no-merge / --no-merge, base-fix / --base-fix, no-base-fix / --no-base-fix, harness <name>, model <name>, effort <level>, email [<address>], email-unless-merged [<address>], and no-email.
  • Built-in Process (fix-run):
    • Ships as a Built-in process with steps delivery followed by self-merge on the pull request's Worktree.
    • Recorded as a Fix run in Command records, Command logs, the Activity log, and Run notifications.
  • Pull Request Reservation and Worktree Acquisition:
    • Reuses the pull request reservation mechanism (refs/thirdshift/reservations/<pr-number> on origin plus the in-progress label on the pull request) for the duration of a pull request Fix run.
    • Refuses pull requests from outside the repository at origin, closed or merged pull requests, and pull requests authored by untrusted accounts.
    • A targeted thirdshift fix <PR URL or number> accepts both ready and draft open pull requests; the unattended Pass only selects non-draft open pull requests.
  • Repair Context Bundle:
    • Writes a worktree context file containing the pull request's title, body, any linked closing issues, and Trusted account comments on the pull request and its linked closing issues.
    • Conflict Repair, CI-fix Repair, and Foreign-commit review Repair Session prompts read this context file when the Delivery is running on a pull request without a standalone Issue branch issue file.
  • Delivery and Failure Salvage:
    • Pull request Fix runs enter Delivery's publication and Repair loop directly (merge Base branch → conflict Repair → push → mark ready → CI watch → CI-fix Repair → optional Base fix → optional Self-merge).
    • If the Fix run fails or is interrupted, uncommitted work is committed with thirdshift: failed fix run (<reason>) and pushed, the pull request is converted back to a draft unless it is already mergeable and green and only Self-merge was refused, and Recovery offers thirdshift fix <PR URL> (preserving the command's flags).
  • Base Branch Monitoring and Repair in Pass Mode:
    • When thirdshift fix runs as a Pass without --author, it checks the Base branch on origin before searching open pull requests.
    • Uses the cross-host Base branch CI reservation ref to inspect the latest push workflow run and check runs on the Base branch tip commit.
    • If the latest workflow run on the Base branch tip failed on attempt 1 with rerunnable failed jobs, it requests gh run rerun <id> --failed and finishes the pass as skipped so transient flakes do not spin up a session.
    • If checks on the Base branch tip remain red (attempt > 1, or non-rerunnable check failure) and no pull request from fix-<base>-<short-sha> already exists (open or draft) in the repository, the Fix run creates branch fix-<base>-<short-sha> from the Base branch tip in a Worktree, runs a CI-fix session with the failing check names and URLs, opens a pull request titled Fix CI on <base>: <check>[, <check>…] targeting <base>, and runs Delivery with Base fix inheritance disabled (every red check is its own to fix).
    • When that pull request merges via Self-merge, thirdshift closes any open CI red on <base> or base-fix issue covering <base>.
  • Inbox Hand-off and Console Copy fix command:
    • In Inbox reading, superseded_at matches both (repository, issue.number) and (repository, pull_request_url), so starting a Fix run (or Review run) on a pull request moves an earlier waiting row for that pull request out of Ready for review or Needs you with taken up by a later Command started at <time>.
    • In the Console and status presentation, a row in Ready for review whose pull_request is present and that has ci == Red or merge_conflict == true exposes fix_command (thirdshift fix <PR URL>), rendered in both the Inbox row template and the Command details (Peek) template as <code>thirdshift fix <PR URL></code> <button type="button" data-copy-cli="thirdshift fix <PR URL>">Copy fix command</button>.

Testing Decisions

  • Good tests verify observable external behavior: exit codes, stdout/stderr progress and Recovery lines, Git branch and commit state on origin, GitHub pull request readiness/draft state, labels, comments and merges via fake gh, Command records, Command logs, Activity log entries, Run notifications, and rendered Console HTML/DOM behavior.
  • Primary seam — CLI + Fake Boundary (Scenario::run):
    • Test targeted thirdshift fix <PR URL or number>, thirdshift fix Pass mode for pull requests, and thirdshift fix Pass mode for a red Base branch through the binary entry point against real Git repositories and fake gh, fake Harnesses, and fake Resend (following the patterns in tests/review_run.rs, tests/review_pass.rs, tests/base_fix.rs, and tests/status.rs).
  • Secondary seam — Console HTTP and Browser (tests/console.rs and console/):
    • Test Copy fix command rendering and clipboard interaction on Ready for review rows with CI red or Merge conflict and in Command details (Peek), and verify Inbox row hand-off when a Fix run starts on a waiting pull request.

Out of Scope

Further Notes

Sub-issues

Sub-issues

4 of 4 Issues completed
Loading 4 sub-issues

Activity

  1. added
    enhancement
    needs-triage
    on Nov 5, 2026
  2. changed the title [-]add thirdshift fix run if we don't already have it[/-] [+]Spec: Fix run[/+] on Nov 5, 2026
  3. added
    ready-for-agent
    in-progress
    and removed
    needs-triage
    ready-for-agent
    on Nov 5, 2026
  4. removed
    in-progress
    on Nov 6, 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

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions