Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions docs/commands/roadmap.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
schema: spec-driven
created: 2026-11-16
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Design

## Decisions
- Expose `run_fix_checks` in `src/devops_cli/roadmap/steps/fix_checks.py`.
- Register `fix-checks` subcommand in `src/devops_cli/commands/roadmap_step.py`.
- Classify failures using `classify_failure` and `FailureEvidence`.
- Tier 1 handlers:
- Lint: run `ruff check --fix` and `ruff format` on changed files.
- Docs: run `devops docs generate`.
- Lock: run `uv lock`.
If the check passes afterwards locally, commit and push with `--force-with-lease`.
- Tier 2 handlers:
- If log does not name a file in `repair_scope`, stop with 0 model calls.
- If log names a file in `repair_scope`, run `run_fix_step`.
- Enforce caps:
- Soft cap: 3 rounds (from settings).
- One more round allowed if error count decreased (`current_errors < prev_errors`).
- Hard cap: 5 rounds.
- Head limit: at most 3 distinct heads per pull request.
- Record keys:
- `fix_checks.key`: `<head>:<check>`
- `fix_checks.rounds`: round count
- `fix_checks.errors`: error count
- `fix_checks.result`: outcome string

## Rejected alternatives
- Running a model call on every lint or lock error: rejected because standard formatters and lock tools fix these deterministically at 0 token cost.
- Unlimited repair rounds: rejected to avoid infinite repair loops on unresolvable CI checks.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Proposal: #5023

## Why
Fix rounds run only inside the runner Job, before the ready mark. When the Job ends, no job fixes the pull request. The classes test, lint, and types have the action REPAIR, but no job takes it. A plan draft with a failing check stays a draft (#3387). Each fix round uses a model, also for a lint or lock failure that a tool can fix. Closes #5023.

## What Changes
- Add `src/devops_cli/roadmap/steps/fix_checks.py` providing `run_fix_checks`.
- Add command `devops roadmap step fix-checks --pull N` in `src/devops_cli/commands/roadmap_step_fix_checks.py` and register it in `roadmap_step.py`.
- Classify failed check log with `classify_failure`.
- Tier 1 (deterministic, 0 model calls): run `ruff check --fix` and `ruff format` on changed paths for lint failures, `devops docs generate` for doc failures, or `uv lock` for lockfile failures.
- Tier 2 (model): run `run_fix_step`, only when the log names a path within the repair scope.
- Enforce bounds: bot pull requests only, stop on `owner/*` labels, skip if head moved, soft cap 3 rounds (extendable while error count falls), hard cap 5 rounds, at most 3 heads per pull request.
- Record keys `fix_checks.key` (`<head>:<check>`), `fix_checks.rounds`, `fix_checks.errors`, `fix_checks.result`.
- Update runner Job repair loop to record `fix_checks.*` keys.

## Capabilities
- Automate tier 1 fixes for lint, docs, and lockfile failures with 0 model requests.
- Automate tier 2 model fixes for failed checks within plan scope.
- Settle failed checks on both delivery drafts and stage plan drafts.

## Impact
- Reduces token usage by resolving deterministic check failures without model calls.
- Recovers stalled draft pull requests automatically.

## Feasibility
- Confirmed against existing implementations of `run_fix_step`, `failed_log`, `classify_failure`, and `repair_scope`.

## Existing Tool Considered
- ruff (`check --fix`, `format`), `devops docs generate`, and `uv lock` fix tier 1 failures with 0 model calls.
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# roadmap-fix-checks Specification

## Purpose
How the roadmap step `fix-checks` repairs failed checks on pull requests: bounds enforcement, tier 1 deterministic repair with zero model calls, tier 2 model repair, plan scope confinement, and runner Job integration.

## ADDED Requirements

### Requirement: The step admits only bot pull requests and enforces bounds
The step `fix-checks` SHALL judge only open bot pull requests. It SHALL stop on pull requests that have `owner/*` labels. When an expected head is given, the step SHALL skip when the remote head differs. It SHALL enforce a soft cap of 3 rounds (extendable while error count decreases), a hard cap of 5 rounds, and at most 3 distinct heads per pull request.

#### Scenario: A pull request with an owner label stops
- **WHEN** `fix-checks` runs on a pull request with an `owner/human` or `owner/agent` label
- **THEN** the step stops and makes no changes

#### Scenario: A moved head returns skipped
- **WHEN** the head of the pull request differs from the expected head
- **THEN** the step returns skipped

#### Scenario: Caps enforce round limits
- **WHEN** a pull request reaches 5 rounds or reaches the soft cap without error reduction
- **THEN** the step halts further attempts

#### Scenario: Head cap stops after 3 heads
- **WHEN** a pull request already has 3 distinct heads recorded and a new head arrives
- **THEN** the step halts further attempts

### Requirement: Tier 1 resolves deterministic check failures with zero model calls
When a check failure is classified as `lint`, the step SHALL run `ruff check --fix` and `ruff format` on the changed files. When a check failure is documentation-related, the step SHALL run `devops docs generate`. When a check failure is lockfile-related, the step SHALL run `uv lock`. The step SHALL run the check again locally, and when it passes, push the repair with zero model requests.

#### Scenario: Tier 1 fixes a lint failure with 0 model requests
- **WHEN** a pull request check fails on code formatting or lint errors
- **THEN** the step runs the lint fixers and pushes the repair with 0 model requests

#### Scenario: Tier 1 fixes a docs failure
- **WHEN** a pull request check fails because documentation is out of sync
- **THEN** the step regenerates the documentation and pushes the repair

#### Scenario: Tier 1 fixes a lockfile failure
- **WHEN** a pull request check fails because uv.lock is not updated
- **THEN** the step updates the lockfile and pushes the repair

### Requirement: Tier 2 repairs failures within plan scope using a model
When Tier 1 does not resolve the failure, the step SHALL inspect the failed log against the repair scope of the item. When the log names no path within the repair scope, the step SHALL stop with zero model calls. When the log names a path in scope, the step SHALL invoke `run_fix_step`.

#### Scenario: A log outside the plan scope stops with 0 model requests
- **WHEN** the failed check log names only paths outside the plan scope
- **THEN** the step stops with 0 model requests

#### Scenario: A log within plan scope runs a fix step
- **WHEN** the failed check log names a path within the plan scope
- **THEN** the step invokes `run_fix_step`

### Requirement: CI infrastructure failures post a comment and wait
When the failure is classified as `ci_infra`, the step SHALL post one comment explaining the infrastructure failure and return status `wait`.

#### Scenario: A CI infrastructure failure waits
- **WHEN** a check fails due to CI infrastructure issues
- **THEN** the step posts a comment, records result wait, and stops

### Requirement: The dry run makes zero requests
`devops roadmap step fix-checks --dry-run` SHALL make zero requests and mutate no state.

#### Scenario: Dry run
- **WHEN** `devops roadmap step fix-checks --pull 42 --dry-run` runs
- **THEN** the command exits 0 and makes zero requests
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Tasks

## 1. Fix checks step and CLI

Kind: behavior. Reads: `src/devops_cli/roadmap/implement/implement_run.py`, `src/devops_cli/roadmap/failure.py`, `src/devops_cli/roadmap/implement/implement_fix_scope.py`. Changes: `src/devops_cli/roadmap/steps/fix_checks.py` (new), `src/devops_cli/commands/roadmap_step_fix_checks.py` (new), `src/devops_cli/commands/roadmap_step.py`, `src/devops_cli/roadmap/stores/store.py`, `src/devops_cli/lang/en/help.py`, `src/devops_cli/roadmap/implement/implement_run.py`, `tests/commands/test_roadmap_step_fix_checks.py` (new), `tests/roadmap/steps/test_roadmap_step_fix_checks.py` (new).

- [x] 1.1 Write tests for fix-checks step and CLI command
- Verification: `$ uv run pytest tests/commands/test_roadmap_step_fix_checks.py tests/roadmap/steps/test_roadmap_step_fix_checks.py`
- [x] 1.2 Implement store record keys and CLI command for fix-checks
- Verification: `$ uv run pytest tests/commands/test_roadmap_step_fix_checks.py`
- [x] 1.3 Implement fix-checks step logic with tier 1 deterministic fixers, tier 2 model fallback, scope validation, and bounds
- Verification: `$ uv run pytest tests/roadmap/steps/test_roadmap_step_fix_checks.py`
- [x] 1.4 Wire record keys and repair loop in implement_run.py
- Verification: `$ uv run pytest tests/roadmap/implement/test_roadmap_implement_step_repair.py`
65 changes: 65 additions & 0 deletions openspec/specs/roadmap-fix-checks/spec.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# roadmap-fix-checks Specification

## Purpose
How the roadmap step `fix-checks` repairs failed checks on pull requests: bounds enforcement, tier 1 deterministic repair with zero model calls, tier 2 model repair, plan scope confinement, and runner Job integration.

## Requirements

### Requirement: The step admits only bot pull requests and enforces bounds
The step `fix-checks` SHALL judge only open bot pull requests. It SHALL stop on pull requests that have `owner/*` labels. When an expected head is given, the step SHALL skip when the remote head differs. It SHALL enforce a soft cap of 3 rounds (extendable while error count decreases), a hard cap of 5 rounds, and at most 3 distinct heads per pull request.

#### Scenario: A pull request with an owner label stops
- **WHEN** `fix-checks` runs on a pull request with an `owner/human` or `owner/agent` label
- **THEN** the step stops and makes no changes

#### Scenario: A moved head returns skipped
- **WHEN** the head of the pull request differs from the expected head
- **THEN** the step returns skipped

#### Scenario: Caps enforce round limits
- **WHEN** a pull request reaches 5 rounds or reaches the soft cap without error reduction
- **THEN** the step halts further attempts

#### Scenario: Head cap stops after 3 heads
- **WHEN** a pull request already has 3 distinct heads recorded and a new head arrives
- **THEN** the step halts further attempts

### Requirement: Tier 1 resolves deterministic check failures with zero model calls
When a check failure is classified as `lint`, the step SHALL run `ruff check --fix` and `ruff format` on the changed files. When a check failure is documentation-related, the step SHALL run `devops docs generate`. When a check failure is lockfile-related, the step SHALL run `uv lock`. The step SHALL run the check again locally, and when it passes, push the repair with zero model requests.

#### Scenario: Tier 1 fixes a lint failure with 0 model requests
- **WHEN** a pull request check fails on code formatting or lint errors
- **THEN** the step runs the lint fixers and pushes the repair with 0 model requests

#### Scenario: Tier 1 fixes a docs failure
- **WHEN** a pull request check fails because documentation is out of sync
- **THEN** the step regenerates the documentation and pushes the repair

#### Scenario: Tier 1 fixes a lockfile failure
- **WHEN** a pull request check fails because uv.lock is not updated
- **THEN** the step updates the lockfile and pushes the repair

### Requirement: Tier 2 repairs failures within plan scope using a model
When Tier 1 does not resolve the failure, the step SHALL inspect the failed log against the repair scope of the item. When the log names no path within the repair scope, the step SHALL stop with zero model calls. When the log names a path in scope, the step SHALL invoke `run_fix_step`.

#### Scenario: A log outside the plan scope stops with 0 model requests
- **WHEN** the failed check log names only paths outside the plan scope
- **THEN** the step stops with 0 model requests

#### Scenario: A log within plan scope runs a fix step
- **WHEN** the failed check log names a path within the plan scope
- **THEN** the step invokes `run_fix_step`

### Requirement: CI infrastructure failures post a comment and wait
When the failure is classified as `ci_infra`, the step SHALL post one comment explaining the infrastructure failure and return status `wait`.

#### Scenario: A CI infrastructure failure waits
- **WHEN** a check fails due to CI infrastructure issues
- **THEN** the step posts a comment, records result wait, and stops

### Requirement: The dry run makes zero requests
`devops roadmap step fix-checks --dry-run` SHALL make zero requests and mutate no state.

#### Scenario: Dry run
- **WHEN** `devops roadmap step fix-checks --pull 42 --dry-run` runs
- **THEN** the command exits 0 and makes zero requests
2 changes: 2 additions & 0 deletions src/devops_cli/commands/roadmap_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from __future__ import annotations

from devops_cli.commands.roadmap_step_fix_checks import fix_checks_cmd
from devops_cli.commands.roadmap_step_fix_conflict import fix_conflict_cmd
from devops_cli.commands.roadmap_step_fix_plan import fix_plan_cmd
from devops_cli.commands.roadmap_step_open import open_cmd
Expand All @@ -17,6 +18,7 @@
from devops_cli.lang import HELP

step_app = new_typer(help=HELP.roadmap.step_app, no_args_is_help=True)
step_app.command("fix-checks", help=HELP.roadmap.step_fix_checks)(fix_checks_cmd)
step_app.command("fix-conflict", help=HELP.roadmap.step_fix_conflict)(fix_conflict_cmd)
step_app.command("fix-plan", help=HELP.roadmap.step_fix_plan)(fix_plan_cmd)
step_app.command("open", help=HELP.roadmap.step_open)(open_cmd)
Expand Down
60 changes: 60 additions & 0 deletions src/devops_cli/commands/roadmap_step_fix_checks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
"""`devops roadmap step fix-checks`: repair a failed check on a pull request (#5023)."""

from __future__ import annotations

from pathlib import Path
from typing import Annotated

import typer

from devops_cli.core.repo import find_repo_root, get_repo_origin_name
from devops_cli.dry_run import dry_run_class, is_dry_run
from devops_cli.exceptions import DevOpsCLIError
from devops_cli.lang import HELP
from devops_cli.output import print_error, write_stdout


def _repository(repo: str | None) -> str:
"""`--repo`, or the origin of the checkout, which reads no network."""
target = repo or get_repo_origin_name(find_repo_root(Path.cwd()))
if not target or "/" not in target:
print_error("Cannot resolve the repository; pass --repo owner/name.")
raise typer.Exit(1)
return target


@dry_run_class("request-plan")
def fix_checks_cmd(
repo: Annotated[str | None, typer.Option("--repo", "-R", help=HELP.roadmap.repo)] = None,
pull: Annotated[
int | None, typer.Option("--pull", "-p", min=1, help=HELP.roadmap.step_fix_checks_pull)
] = None,
head: Annotated[
str | None, typer.Option("--head", help=HELP.roadmap.step_fix_checks_head)
] = None,
confirm: Annotated[
bool, typer.Option("--confirm", help=HELP.roadmap.step_fix_checks_confirm)
] = False,
dry_run: Annotated[
bool, typer.Option("--dry-run", help=HELP.roadmap.step_fix_checks_dry_run)
] = False,
) -> None:
"""Repair a failed check on a pull request (#5023)."""
if pull is None:
print_error("Pass --pull <number>.")
raise typer.Exit(1)
if dry_run or is_dry_run():
return

from devops_cli.roadmap.steps.fix_checks import run_fix_checks
from devops_cli.roadmap.stores.store import get_roadmap_store

target = _repository(repo)
store = get_roadmap_store(target)
try:
report = run_fix_checks(store, target, pull, head=head, confirm=confirm)
except DevOpsCLIError as exc:
print_error(f"Could not fix checks on PR #{pull}: {exc}", safe=True)
raise typer.Exit(1) from exc

write_stdout(report.to_json() + "\n")
5 changes: 5 additions & 0 deletions src/devops_cli/lang/en/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -1577,6 +1577,11 @@ class RoadmapCommandHelp:
step_ready_head: str = "Expected commit SHA of the pull request head."
step_ready_force: str = "Bypass draft readiness verification."
step_ready_dry_run: str = "Make no network request and mark nothing ready."
step_fix_checks: str = "Repair a failed check of an open pull request (#5023)."
step_fix_checks_pull: str = "Number of the pull request to repair."
step_fix_checks_head: str = "Expected commit SHA of the pull request head."
step_fix_checks_confirm: str = "Confirm and apply check repairs."
step_fix_checks_dry_run: str = "Make no network request and change nothing."
eval_app: str = (
"Score the roadmap jobs. grades reads the live result lines of each job in Loki. Each "
"other command runs a job's real code on committed cases with a chosen model. Each is on "
Expand Down
22 changes: 22 additions & 0 deletions src/devops_cli/roadmap/implement/implement_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,9 @@
from devops_cli.roadmap.status_sync import StatusFacts, write_status
from devops_cli.roadmap.step_files import TaskGroup, parse_task_groups, section_text
from devops_cli.roadmap.step_metrics import observe_implement
from devops_cli.roadmap.steps.fix_checks import count_errors
from devops_cli.roadmap.stores.store import (
FixChecksRecordKey,
ImplementRecordKey,
ImplementResult,
Item,
Expand Down Expand Up @@ -1851,8 +1853,19 @@ def _repair_after_push(self, pull: int, check: PRCheckItem, rounds: int) -> None
whose log names no path of the repair scope gets no fix step: the item stops with no model
request (#4028)."""
log = failed_log(self.repo, check)
head = self._head()
errors = count_errors(log)
scope = self._repair_scope()
if not scope.names(log):
self.store.set_marks(
self._fresh(),
{
FixChecksRecordKey.KEY: f"{head}:{check.name}",
FixChecksRecordKey.ROUNDS: str(rounds + 1),
FixChecksRecordKey.ERRORS: str(errors),
FixChecksRecordKey.RESULT: "stopped",
},
)
reason = MESSAGES.roadmap.implement_stop_check_outside_scope.format(
check=check.name, scope=scope.listing()
)
Expand All @@ -1867,6 +1880,15 @@ def _repair_after_push(self, pull: int, check: PRCheckItem, rounds: int) -> None
self._fix(check.name, log)
self._push()
self._comment(pull)
self.store.set_marks(
self._fresh(),
{
FixChecksRecordKey.KEY: f"{head}:{check.name}",
FixChecksRecordKey.ROUNDS: str(rounds + 1),
FixChecksRecordKey.ERRORS: str(errors),
FixChecksRecordKey.RESULT: "repaired",
},
)
self.step = MESSAGES.roadmap.implement_step_names["checks"]

def _repair_scope(self) -> RepairScope:
Expand Down
Loading