Skip to content

fix(roadmap): keep the last valid stage plan on a revision schema error #6357

Closed

Description

@dan-petty

Problem

A stage revision run that breaks the reply schema ends the item, also when an earlier reply of the same attempt was a valid plan.

This item does not widen #6319. #6319 changes the schema. This item changes what the stage does after any schema failure of a revision.

Expected

  • When a revision run breaks the schema after its output retry, the stage keeps the last schema-valid reply. It sends the violations back to the planner as a gate return, and that return counts against roadmap.stage.gate_returns. The item does not end on the first schema failure of a revision.
  • A first reply that breaks the schema has no earlier plan. It keeps today's behavior, or it gets its own measure (for example a second output retry). The design names the choice.
  • Test first: a fake planner gives a valid first reply, then a revision that breaks the schema twice, then a valid reply. The item stages, and the gate return count is 1 higher. A second test: when gate_returns is used up, the schema failure ends the item with the class parser as today.

Related: #6319, #6214.

Dependencies

Alternatives check of 2026-11-19: none.
Tool: none found.
Reason: Searches for a structured-output retry or schema-error handling library returned only generic documentation pages, no open tool. The need is stage-internal control flow: keep the last valid StageProposal and turn the violations into a gate return.

Lacks:

  • No library keeps the last schema-valid plan across a failed revision
  • No library maps schema violations onto the gate return budget
  • No library decides the first-reply case with no earlier plan

Proposed design

Problem statement

A stage revision run that breaks the reply schema ends the item and loses the last schema-valid plan. The stage must keep that plan, send the schema violations back as a gate return, and count the return against roadmap.stage.gate_returns. A first reply with no earlier plan keeps the current one-retry behavior.

Acceptance criteria

Requirement: Revision schema failure keeps the last valid plan

When a revision reply fails the reply schema after its output retry, the stage SHALL keep the last schema-valid plan and send the schema violations to the planner as one gate return.

Scenario: A revision schema failure returns the last valid plan

  • WHEN A fake planner gives a valid first reply, a revision that fails the schema twice, and then a valid reply
  • THEN The stage stages the item, and the gate return count is one higher than before the revision

Requirement: An exhausted gate return ends with the parser class

When a revision schema failure uses the last roadmap.stage.gate_returns return, the stage MUST end the item with the failure class parser.

Scenario: The last gate return leaves the parser class

  • WHEN A fake planner gives a valid first reply and revisions that fail the schema until roadmap.stage.gate_returns is used up
  • THEN The stage ends the item with the failure class parser and opens no pull request

Requirement: A first reply with no plan keeps one output retry

A first plan reply that fails the reply schema MUST keep the single output retry and then end the item with the class parser when no valid plan exists.

Scenario: A first reply with no earlier plan ends as parser

  • WHEN A fake planner returns a schema-invalid first reply twice and no valid plan
  • THEN The stage ends the item with the failure class parser and makes no gate return

Requirement: The gate return names the schema violations

The gate return after a revision schema failure SHALL include the schema violations of the failed revision.

Scenario: The planner sees the revision schema violations

  • WHEN A fake planner returns a revision with the violation dependences (extra_forbidden)
  • THEN The next planner request contains dependences (extra_forbidden)

Existing Tool Considered

The alternatives check of 2026-11-19 records verdict none and names no tool. The alternatives block in the issue body gives its searches and lacks. No open, maintained tool or library covers the stage's internal schema-retry policy. The project builds the change in its own code. The proposal catches StructuredOutputValidationError at the revision call, keeps the last valid StageProposal, and sends the violations as one gate return. The estimated cost is about 30,000 tokens to build, keep and fix, and one working day.

Key questions

  • What should a first plan reply that breaks the schema do when no earlier plan exists?: Keep the current behavior: one output retry, then end the item with the class parser. Do not add a second output retry. (best practice) [sources: src/devops_cli/roadmap/stage/stage.py:991, src/devops_cli/roadmap/stage/stage_verify.py:83, openspec/specs/roadmap-stage/replies/spec.md:9, openspec/specs/roadmap-failure-taxonomy/spec.md:121]
    • Chosen: Keep one output retry and end as parser. The replies spec sets one retry, and no earlier plan exists to return.
    • Rejected: Add a second output retry. It hides schema defects and adds token cost without a plan to preserve.
    • Rejected: Treat it as a gate return with no plan. A gate return needs a plan to revise, and no plan exists.
  • How should a revision schema failure use the gate return budget?: Catch StructuredOutputValidationError from the revision call, keep the last StageProposal that _ask_plan returned, and send the violations as one gate return. Reuse roadmap.stage.gate_returns; add no new setting. (best practice) [sources: src/devops_cli/roadmap/stage/stage.py:1994, src/devops_cli/roadmap/stage/stage.py:2010, src/devops_cli/config/settings.py:1347, src/devops_cli/roadmap/stage/stage.py:1078, src/devops_cli/roadmap/stage/stage.py:1392]
    • Chosen: Reuse roadmap.stage.gate_returns. The setting already counts planner returns, and the issue requires the same count.
    • Rejected: Add a separate schema-return setting. It adds a second budget for the same planner loop and changes configuration.
    • Rejected: End the item at once. It loses the last valid plan, which is the defect.
  • Where does the stage keep the last schema-valid plan?: In the caller's proposal value. _ask_plan returns only a schema-valid StageProposal; a failed revision raises before it returns. Catch the error at the revision call and keep proposal. (best practice) [sources: src/devops_cli/roadmap/stage/stage.py:1994, src/devops_cli/roadmap/stage/stage.py:2010]
    • Chosen: Keep the caller's proposal value. It already holds the last reply that passed the schema, and a failed revision raises before it changes.
    • Rejected: Add a module-level cache. It adds shared state to a job that runs one item at a time and has no need for it.
    • Rejected: Reread the last plan from disk. It adds file I/O and a second source of truth for a value that the caller holds.
  • What ends the item when a revision schema failure has no gate return left?: The item ends with the failure class parser, because StructuredOutputValidationError maps to parser. [sources: openspec/specs/roadmap-failure-taxonomy/spec.md:121]
  • What text does the gate return carry after a revision schema failure?: It carries the schema violations of the failed revision, such as dependences (extra_forbidden), so the planner can correct the same reply. [sources: src/devops_cli/roadmap/stage/stage.py:2010, openspec/specs/roadmap-stage/replies/spec.md:9]

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    type/bug
    source/agent
    scope/roadmap
    status/new
    on Nov 19, 2026
  2. dan-petty commented on Nov 19, 2026

    @dan-petty
    OwnerAuthor
    • Priority: P1-High. The parser class caused 8 of 11 stage failures over 24 h, which is a high error rate on the stage service.
    • Related: fix(roadmap): A schema limit of the plan reply never fails a stage item #6319, which asks for a different change. Both address schema validation failures in the stage, but #6319 removes the schema constraints while this item keeps the last valid reply and sends violations as a gate return.
  3. added
    effort/medium
    value/high
    priority/p1-high
    on Nov 19, 2026
  4. devops-cli-service commented on Nov 19, 2026

    @devops-cli-service
    Contributor

    Waiting for the alternatives check to run. The next refine round looks at the item again after the check records a verdict.

  5. devops-cli-service commented on Nov 19, 2026

    @devops-cli-service
    Contributor

    The result in the alternatives block of the issue body changed. Before this check: no check. A person decides what the new result means for the item.

    Searches (6)

    Searches run:

    • LLM structured output validation retry library keep last valid response, results: 5
    • pydantic-ai output validator retry StructuredOutputValidationError handling, results: 5
    • guardrails-ai reask validation failure retry, results: 5
    • instructor python retry validation error structured outputs, results: 5
    • pydantic-ai retries output validators documentation, results: 5
    • json schema validation retry library python, results: 5

    Sources:

  6. added
    status/ready
    and removed
    status/new
    on Nov 19, 2026
  7. devops-cli-service commented on Nov 19, 2026

    @devops-cli-service
    Contributor

    Next step: the stage job writes the plan of the item. See the section Proposed design of the body.

  8. added
    owner/service
    and removed
    owner/service
    on Nov 19, 2026
  9. 19 remaining items

  10. added
    status/in-review
    and removed
    status/in-progress
    on Nov 20, 2026
  11. devops-cli-service commented on Nov 20, 2026

    @devops-cli-service
    Contributor

    Pull request #6484 is ready for review. The checks passed.

    Spend: 68 model requests, 5695051 input tokens, 19300 output tokens.

  12. dan-petty commented on Nov 20, 2026

    @dan-petty
    OwnerAuthor

    Frozen on 2026-11-20. The stage, implement and fix-checks jobs grade under 60%, so the owner rule asks for a re-architecture before more fixes inside the current design (tracker #6519). This item is incremental work on those jobs, so its Dependencies section now names #6521 first. Stage and implement leave this item while #6521 is open. When the experiments of #6519 decide, a person closes #6521 (this item can then continue) or closes this item as not planned.

  13. added
    owner/agent
    on Nov 20, 2026
  14. removed
    status/in-review
    owner/agent
    on Nov 20, 2026
  15. devops-cli-service commented on Nov 20, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-20 17:44 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/mediumpriority/p1-highscope/roadmapsource/agenttype/bugvalue/high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions