Skip to content

feat(roadmap): fix mechanical stage gate problems with no model call #4853

Closed

Description

@dan-petty

Problem or Motivation

Some gate problems have one right edit that needs no model. The dependencies gate names the other open plan item whose files overlap: about 10 refusals in 7 days, 3 of 3 sampled were deterministic, and the model did not fix them in its one return. The module-test gate names a module whose known test is not in the reads; a criterion text or a registry task can be missing. Each one spends a return of about 0.31M prompt tokens or fails the item.

Proposed Solution & Architectural Design

Before a return, apply the mechanical findings (#4846 codes) as a rewrite in the style of plan_rewrite.py: add the named item to the dependencies, add the known test of the module to the reads, copy the criterion text, add the registry task. Gate the rewritten plan again; a rewrite costs no return. The refused file names each edit. Citation re-anchoring stays with #4479.

Target Subsystem

SDLC, Git & PR Governance (roadmap stage gates).

Existing Tool Considered

The rewrite pattern of plan_rewrite.py; no model call. Cost to build: about 0.6M tokens, half a day.

Acceptance Criteria

  • On the saved refused records, every dependencies and registry finding, and each module-test finding that names an existing test, passes with no model request.
  • A test: no rewrite changes text outside its finding.
  • devops_cli_roadmap_fix_checks_total{site="stage.gate",path="mechanical"} counts each rewrite.

Dependencies

#4846.

Source: #4843

Alternatives check of 2026-11-14: none.
Tool: none found.

Proposed design

Problem statement

Some stage gate refusals have one right edit. The dependencies gate names the item to add, the module and perimeter test gates name the test to add, and a criterion or registry finding names the text or declared path to add. The job sends these refusals to the model, and each return costs about 0.31M prompt tokens or fails the item. This change applies these edits as a rewrite of the plan reply with no model call and gates the plan again. Citation re-anchoring stays with #4479.

Acceptance criteria

Requirement: Mechanical edits before the model

The stage job SHALL apply every mechanical finding of a refused reply before it sends the remaining findings of that reply to the model.

Scenario: One mechanical and one model finding

  • WHEN A refused reply holds a dependencies finding and a finding that needs the model
  • THEN The dependencies edit is applied, the gate runs again, and the model receives only the findings that remain.

Requirement: Dependencies rewrite

The stage gate SHALL add the item that a dependencies finding names to the plan's dependencies before it calls the model.

Scenario: Dependencies finding on a saved record

  • WHEN A saved refused record holds a dependencies finding that names one open item
  • THEN The rewritten plan lists that item under Dependencies and the gate passes with no model request.

Requirement: Perimeter test in the manifest group

The rewrite SHALL add the named perimeter test path to the Changes: line of the group that changes the manifest.

Scenario: Missing perimeter test

  • WHEN A refused record holds stage_problem_missing_perimeter_test for a test file that exists
  • THEN The Changes: line of that group names the test path and the gate passes with no model request.

Requirement: Module test in the reads

The rewrite SHALL add the known test of a module to the reads of the plan when a module-test finding names it.

Scenario: Missing module test

  • WHEN A refused record holds stage_problem_missing_module_test for a test file that exists
  • THEN The reads list that test path and the gate passes with no model request.

Requirement: Criterion text copy

The rewrite SHALL copy the criterion text that a finding names into the plan.

Scenario: Missing criterion text

  • WHEN A refused record holds a finding for a criterion with no text
  • THEN The plan holds the criterion text and the gate passes with no model request.

Requirement: Registry task add

The rewrite SHALL add the registry task that a finding names to the plan.

Scenario: Missing registry task

  • WHEN A refused record holds a finding for a registry task that the plan lacks
  • THEN The plan lists the registry task and the gate passes with no model request.

Requirement: Rewrite pass bound

The stage job SHALL run at most two rewrite passes on one refused reply before it calls the model.

Scenario: A rewrite exposes a second finding

  • WHEN The first rewrite pass leaves a mechanical finding that its edit exposed
  • THEN The second pass applies that edit and the gate runs again, and no third pass runs.

Requirement: No edit outside the finding

A rewrite MUST change no text outside the lines that its finding names.

Scenario: Diff of one rewrite

  • WHEN The rewrite applies one finding to a saved plan
  • THEN The diff touches only the line or lines of that finding.

Requirement: Skip a finding with no target

The rewrite MUST leave the plan unchanged when the named test, item or task is absent from the repository.

Scenario: Module test that does not exist

  • WHEN A module-test finding names a test file that the repository does not hold
  • THEN The plan text is unchanged and the gate returns the finding to the model.

Requirement: Rewrite metric and log

The rewrite SHALL write one log line for each applied edit and increment devops_cli_roadmap_fix_checks_total with site="stage.gate" and path="mechanical".

Scenario: One applied rewrite

  • WHEN The gate applies one mechanical rewrite
  • THEN The counter increases by one and the log holds one line that names the code and the edited path.

Requirement: Idempotent rewrite

A second rewrite of an already rewritten plan SHALL make no change.

Scenario: Second pass on the rewritten plan

  • WHEN The rewrite runs again on its own output
  • THEN The plan text is identical and the counter does not increase.

Existing Tool Considered

No open, maintained tool covers the need. The alternatives check of 2026-11-14 found no open, maintained tool that reads the stage gate codes, adds a named item to the plan's dependencies, adds a test to the Changes: line or to the reads, copies criterion text, adds a registry task, or re-runs the gate. The work belongs in the project's code. The body gives the written cost: about 0.6M tokens and half a day to build, keep and fix it.

Key questions

  • Which finding codes does the mechanical rewrite handle?: The three codes that stage_findings.py already classes as mechanical (stage_problem_dependencies, stage_problem_missing_module_test, stage_problem_missing_perimeter_test), plus stage_problem_criterion and stage_problem_registry, whose messages name the exact text or declared path to add. The change adds the last two codes to _MECHANICAL and sets their class in stage_finding_classes.json to mechanical. (best practice) [sources: src/devops_cli/roadmap/stage/stage_findings.py:88, src/devops_cli/lang/en/messages.py:4953, src/devops_cli/lang/en/messages.py:5096, src/devops_cli/roadmap/stage/stage_finding_classes.json:100, docs/adr/0005-review-findings-come-from-tools-not-models.md]
    • Rejected: The codes that _MECHANICAL lists today. It leaves out the criterion and registry findings that the body names and whose messages give the one edit.
    • Chosen: The body's codes plus the perimeter test code. It covers the criterion, registry, dependencies and module-test findings, and the perimeter test that was 36 of 104 gate codes in 3 days.
    • Rejected: Every gate code. A code such as plan_defect has no one right edit, so the model must read it.
  • Where in the stage step does the rewrite run?: In _returned, after _settle returns a _Refused and before _ask_plan sends the reply to the model. The rewrite edits the StageProposal, _settle judges it again, and only the findings that remain go back to the model. (best practice) [sources: src/devops_cli/roadmap/stage/stage.py:1707, src/devops_cli/roadmap/stage/stage.py:1710, src/devops_cli/roadmap/stage/stage.py:1749, docs/adr/0021-the-roadmap-service-is-a-webhook-router-cluster-pods-run-the-roadmap-jobs-and-valkey-holds-their-shared-state.md]
    • Chosen: In the stage step, before the model call. It uses the gate result that the step already holds and spends no return.
    • Rejected: As instructions in the model prompt. It spends the return that this change removes.
    • Rejected: As a separate job. It adds a pod and a round trip for work that takes no model call.
  • What does the job do when the gate reports a mechanical finding and a model finding together?: It applies the mechanical edits, gates the rewritten proposal again, and sends only the findings that remain to the model. (best practice) [sources: src/devops_cli/roadmap/stage/stage.py:1710, src/devops_cli/roadmap/stage/stage.py:1749, src/devops_cli/roadmap/stage/stage_findings.py:88]
    • Chosen: Apply the mechanical edits, then re-gate. The model then reads a shorter list and spends less on the same return.
    • Rejected: Send all findings to the model. It spends a return on edits that need no model.
    • Rejected: Skip the mechanical edits when a model finding is present. The mechanical finding stays and the gate refuses the plan again.
  • How many rewrite passes run before the model gets the plan?: Two passes at most. One pass applies every mechanical finding. A second pass handles a finding that the first edit exposes. Then the gate result goes to the model. (best practice) [sources: src/devops_cli/roadmap/stage/stage.py:1707, src/devops_cli/roadmap/stage/stage.py:1729, src/devops_cli/roadmap/stage/stage.py:1746]
    • Rejected: One pass. A dependencies edit can expose a second finding, which then spends a return.
    • Chosen: Two passes. It covers a finding that the first edit exposes and cannot loop.
    • Rejected: Repeat until no finding remains. A defect in the rewrite can loop with no bound.
  • What does the rewrite do when the named test or task is absent?: It leaves the plan unchanged for that finding and lets the gate return the finding to the model. (best practice) [sources: src/devops_cli/roadmap/stage/stage_paths.py:638, src/devops_cli/roadmap/stage/stage_paths.py:457, src/devops_cli/roadmap/stage/stage.py:1749]
    • Rejected: Write a stub test. The plan would name a test that no one wrote.
    • Chosen: Skip the finding. The plan keeps its text and the model reads the finding as before.
    • Rejected: Fail the item. The item can still pass when the model fixes the plan.
  • Which metric counts a mechanical rewrite?: The body's devops_cli_roadmap_fix_checks_total with site="stage.gate" and path="mechanical". No counter of that name exists in instruments.py today, so the change adds it as a new counter and increments it once for each applied rewrite. (best practice) [sources: src/devops_cli/telemetry/instruments.py:642, src/devops_cli/telemetry/instruments.py:652, src/devops_cli/roadmap/stage/stage.py:1778]
    • Chosen: Add the body's counter as a new instrument. The body's acceptance criterion names it, and no counter of that name exists, so it is one new series.
    • Rejected: Reuse devops_cli_roadmap_stage_gate_problems. That histogram counts findings in a reply, not the rewrites that remove them.
    • Rejected: Add a new stage-named counter. It would contradict the metric that the body's acceptance criterion names.

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

#4846

Activity

  1. added
    source/agent
    on Nov 11, 2026
  2. added
    type/feature
    scope/roadmap
    status/new
    value/medium
    effort/low
    on Nov 11, 2026
  3. dan-petty commented on Nov 11, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.

    • Type: type/feature. The feat prefix of the title gives the type.
    • Scope: scope/roadmap. The (roadmap) scope of the title gives the scope.
    • Priority: P2-Medium. Saves roughly 3M tokens per week and prevents item failures, but no data loss or security risk.
    • Value: Medium. Prevents about 10 failed or costly model returns per week.
    • Effort: Low. Body states about half a day of work.
    • Related: fix(roadmap): a refused repair revision goes back to the planner once #4348, which asks for a different change. Both reduce wasted model returns on stage gate refusals, but #4348 retries the model while the candidate fixes the plan mechanically before the model is called.
  4. added
    priority/p2-medium
    on Nov 11, 2026
  5. removed
    priority/p2-medium
    on Nov 11, 2026
  6. devops-cli-service commented on Nov 11, 2026

    @devops-cli-service
    Contributor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.

    • Type: type/feature. The feat prefix of the title gives the type.
    • Scope: scope/roadmap. The (roadmap) scope of the title gives the scope.
    • Priority: P2-Medium. The change saves model tokens and prevents item failures, but it is not critical.
    • Value: Medium. It prevents repeated gate failures and saves about 0.31M prompt tokens for each refusal.
    • Effort: Low. The author estimates about half a day and 0.6M tokens to build and test the rewrite.
    • Related: feat(roadmap): keep the stage gate problems as a list with a code #4846, which asks for a different change. Both items concern stage gate findings. #4846 records each finding with a code. The candidate rewrites the plan from those codes.
  7. dan-petty commented on Nov 13, 2026

    @dan-petty
    OwnerAuthor

    New evidence of 2026-11-13 (review of failing jobs). The perimeter-test finding is now the largest single class of stage gate codes, so this item has a larger effect than its body states.

    • Loki, 3 days to 2026-11-13 16:00Z: stage_problem_missing_perimeter_test 36 and stage_problem_missing_module_test 1 of 104 logged gate codes, in 4 or more items. One reply got 22 findings of this class.
    • 207 stage reply refused lines over 40 items, with a median of 39 tool calls for each reply.
    • Stage results in the same days: staged 5, failed 10 (plan_defect 7).
    • stage_findings.py (lines 84-94) already classes both codes as mechanical. The job still sends them to the model as text (messages.py, near lines 4832-4836; stage_paths.py, near lines 457-470).

    Scope point: add stage_problem_missing_perimeter_test to the rewrite list in the body. The rewrite adds the named test path to the Changes: line of the group that changes the manifest, logs the edit, and runs the gate again, with no model call. Each such rewrite saves one plan round of about 38 tool calls.

    Measure: stage_problem_missing_perimeter_test findings that go back to the model go to 0, refusal rounds per stage item go down, and the stage success ratio goes up (7 days after the release).

  8. devops-cli-service commented on Nov 14, 2026

    @devops-cli-service
    Contributor

    Alternatives check: none

    Reason: Eight web searches for an open, maintained tool that turns stage-gate finding codes into deterministic plan edits returned only unrelated documentation pages, no matching project or library. The needed mapping — add the overlapping item to the dependencies, add the module/perimeter test to the reads, copy the criterion text, add the registry task, re-gate, and count the rewrite — is specific to this repository's plan format and its own plan_rewrite.py, so no external tool covers it and the work belongs in the project's code.

    Tool: none found

    Lacks:

    • No tool reads the repository's stage gate finding codes (dependencies, missing module/perimeter test, missing criterion text, missing registry task)
    • No tool knows the roadmap plan format well enough to add a named item to Changes:/dependencies or a test path to the reads
    • No tool copies criterion text or adds a registry task from a finding
    • No tool re-runs the project's gate on the rewritten plan or increments devops_cli_roadmap_fix_checks_total
    • The rewrite must preserve text outside the finding, which a generic codemod cannot guarantee for this format

    Searches run:

    • deterministic rewrite tool applies lint findings fixes to document without an LLM, results: 5
    • open source tool automatic plan repair missing dependency entries from validation errors, results: 5
    • libcst codemod framework automated code modification Python, results: 5
    • comby structural search and rewrite tool for custom file formats, results: 5
    • OpenRewrite automated refactoring recipes deterministic fix, results: 5
    • tool that fixes task list plan file by adding missing test files to a reads list, results: 5
    • comby github structural matching and rewriting, results: 5
    • python library rewrite sections of markdown plan file programmatically, results: 5
    • ast-grep structural search and replace command line tool, results: 5
    • "codemod" tool for automated codebase migrations open source, results: 5

    Checked on 2026-11-14. A person decides what this means for the item. The check changes no label and closes no issue.

  9. removed
    status/new
    on Nov 15, 2026
  10. 1 remaining item

  11. devops-cli-service commented on Nov 15, 2026

    @devops-cli-service
    Contributor

    Status set to Ready at ca62d6a (see proposed design in issue body).

  12. added
    owner/agent
    on Nov 15, 2026
  13. added
    status/in-progress
    and removed
    status/ready
    on Nov 15, 2026
  14. added
    status/in-review
    and removed
    status/in-progress
    on Nov 16, 2026
  15. removed
    status/in-review
    owner/agent
    on Nov 16, 2026
  16. devops-cli-service commented on Nov 16, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-16 03:02 UTC

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

    effort/lowpriority/p2-mediumscope/roadmapsource/agenttype/featurevalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions