Repository navigation
Description
Problem Description
A model call that fails during a step of devops roadmap implement raises the client error out of _run_agent. run_step then resets the checkout. The stop comment holds no diff of the discarded work. This is worst in the extra turn for the ticks: every check has passed, only the ticks are missing, and a person cannot see the work.
Reproduction Steps
- Run a step whose first turn passes all checks and leaves a task unticked.
- Let the model call of the extra turn fail with a
ModelAPIError. - Read the stop comment of the item.
Expected vs Actual Behavior
Expected: the stop comment holds the masked diff of the discarded work, as it does for a stop with a reason (#2721).
Actual: the comment names the class of the error and holds no diff.
Environment Diagnostics
src/devops_cli/roadmap/implement_step.py: _run_agent re-raises the error, _attempt calls _discarded_diff only on the path of a reason. src/devops_cli/roadmap/implement_run.py: _implement_item catches the error and stops the item without a diff.
Logs, Traces, or Terminal Output
No test covers a ModelAPIError on the second turn. A fix needs a partial result (requests, tokens, last message) from the failed turn, so _attempt can build a stopped outcome. AICredentialsError must still stop the whole run.
Proposed design
Problem statement
When a model call fails with a ModelAPIError during an implement step, the error propagates out of _run_agent. The step resets the checkout. The stop comment holds no diff of the discarded work. This is worst in the tick turn: every check has passed, only the ticks are missing, and a person cannot see the work. The fix makes _run_agent return a stopped _Run with the partial result. Then _attempt builds a stopped outcome with the diff.
Acceptance criteria
Requirement: Stop with diff on model error
When a non-credentials ModelAPIError occurs in a step, the step SHALL stop with a reason and a masked diff of the discarded work.
Scenario: First turn model call fails
- WHEN _run_agent catches a ModelAPIError that is not an AICredentialsError
- THEN _attempt returns a StepOutcome with status STOPPED, a non-empty reason, and a non-empty diff
Requirement: Credentials error propagates
When an AICredentialsError occurs, it SHALL propagate to stop the whole run.
Scenario: Model call fails with 401
- WHEN _run_agent catches a ModelAPIError that maps to AICredentialsError
- THEN _run_agent raises AICredentialsError and it propagates out of run_step
Requirement: Partial result in outcome
The outcome of a stopped step SHALL include the requests, tokens, and last message from the failed turn.
Scenario: Model call fails after one request
- WHEN _run_agent catches a ModelAPIError after one model reply
- THEN The StepOutcome has requests >= 1 and a non-empty last_message
Requirement: Tick turn failure gets diff
When the tick turn model call fails with a non-credentials ModelAPIError, the step SHALL stop with a diff.
Scenario: First turn passes, tick turn model call fails
- WHEN _tick_turn calls _turn and the model call raises a non-credentials ModelAPIError
- THEN The StepOutcome has status STOPPED, a non-empty reason, and a non-empty diff
Existing Tool Considered
No check has run. No external tool or library covers this need. This is a bug fix in the project's own error handling in _run_agent (src/devops_cli/roadmap/implement_step.py). The cost is a change to one exception handler: replace the raise with a return of a stopped _Run, and add an isinstance check for AICredentialsError. The change is about 5 lines of code plus one import.
Key questions
- How should _run_agent handle a non-credentials ModelAPIError?: Treat it like UsageLimitExceeded or UnexpectedModelBehavior: set the reason from the error, capture the last message, and return a _Run with the partial spend data. Do not raise. (best practice) [sources: src/devops_cli/roadmap/implement_step.py:588, src/devops_cli/roadmap/implement_step.py:580]
- Rejected: Raise the error (current behavior). Rejected: the stop comment has no diff of the discarded work.
- Rejected: Return a stopped _Run. Chosen: _attempt already builds a stopped outcome with the diff when _Run.reason is set.
- How does model_call_error distinguish AICredentialsError from other ModelAPIErrors?: model_call_error maps a ModelHTTPError with status 401 or 403 to AICredentialsError. Any other ModelAPIError maps to AIClientError. [sources: src/devops_cli/roadmap/agent_run.py:29, openspec/changes/archive/2026-10-28-2398-refine-investigates-questions/design.md:36]
- Does _attempt need changes?: No. _attempt already handles a _Run with a reason by building a stopped outcome with the diff via _discarded_diff. (best practice) [sources: src/devops_cli/roadmap/implement_step.py:918, src/devops_cli/roadmap/implement_step.py:944]
- Rejected: Change _attempt to catch the error. Rejected: the error is handled by returning a _Run with a reason.
- Rejected: Leave _attempt unchanged. Chosen: it already builds the correct stopped outcome with the diff.
- Does _implement_item need changes?: No. Once _run_agent returns a stopped _Run, the normal stop path in _groups handles it: outcome.status is STOPPED, and _stopped_by creates a _StopError with the diff. (best practice) [sources: src/devops_cli/roadmap/implement_run.py:566]
- Rejected: Change _implement_item to catch the error and add the diff. Rejected: the normal stop path already includes the diff.
- Rejected: Leave _implement_item unchanged. Chosen: the fix is in _run_agent, and the stop path already carries the diff.
Fit
Fits in one pull request.
Suspected block
None.
Dependencies
None.
Activity
dan-petty commentedon Oct 30, 2026
Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.
fixprefix of the title gives the type.(roadmap)scope of the title gives the scope.Work is silently lost on a specific failure path, but it is an edge case and not a security or availability blocker.Preserves already-completed work so a person can inspect it, preventing rework and confusion.Requires threading a partial result through _attempt, building a stopped outcome, and guarding AICredentialsError separately.Both preserve the diff in the stop comment, but #2721 handles a stop with a reason (task unticked) while the candidate handles a ModelAPIError on an extra turn.devops-cli-service commentedon Oct 30, 2026
Status set to Ready at 46fd02d (see proposed design in issue body).
chore(main): release 0.22.5 (#2788)