Repository navigation
Description
Problem Description
The stop reason of an implement step holds the body of a pydantic-ai UnexpectedModelBehavior, which is text of the model. _stop_reason in src/devops_cli/roadmap/implement_step.py builds its message from str(stopped). For UnexpectedModelBehavior, pydantic-ai's __str__ returns <message>, body:\n<body> when the error has a body. The reason goes to the stop comment and to the table of the command.
Reproduction Steps
- Run an implement step whose model call raises
UnexpectedModelBehavior(message, body="<reply text>"). - Read
StepOutcome.reason.
Expected vs Actual Behavior
Expected: the reason holds the class and the first line of message, masked and cut, and no body.
Actual: the reason holds body too, masked for secrets and cut to 500 characters, but still model text.
run_error_message in src/devops_cli/roadmap/agent_run.py (added by #2562) reads AgentRunError.message, keeps its first line, masks and cuts it. _stop_reason can use it.
Environment Diagnostics
pydantic-ai 2.59.0, devops-cli on main after 7c931b94.
Logs, Traces, or Terminal Output
Source of the installed package: UnexpectedModelBehavior.__str__ in pydantic_ai/exceptions.py.
Pre-Submission Checklist
- I have verified that no sensitive credentials, private keys, or internal tokens are contained in this issue report.
- I have checked existing issues and pull requests to ensure this is not a duplicate.
Proposed design
Problem statement
The stop reason of an implement step includes the body of a pydantic-ai UnexpectedModelBehavior exception. The _stop_reason function uses str(stopped), which for that exception returns the message plus the model reply text. The reason goes to the stop comment and the command table, so model text leaks into the record. The reason should hold only the class name and the first line of the exception message, masked and cut, with no body.
Acceptance criteria
Requirement: No body in stop reason
The stop reason of a step stopped by UnexpectedModelBehavior SHALL NOT contain the exception body.
Scenario: UnexpectedModelBehavior with a body
- WHEN A step is stopped by UnexpectedModelBehavior(message='schema error', body='model reply text here')
- THEN StepOutcome.reason contains 'schema error' and does not contain 'model reply text here'
Requirement: Message is masked and cut
The stop reason SHALL contain the exception class name and the first line of its message, masked for secrets and cut to the configured limit.
Scenario: Message with a secret
- WHEN A step is stopped by UnexpectedModelBehavior with a message that contains a secret token
- THEN StepOutcome.reason contains the class name and the masked first line of the message, and the secret token is not present
Requirement: UsageLimitExceeded unchanged
The stop reason for a step stopped by UsageLimitExceeded SHALL keep the same format as before the change.
Scenario: UsageLimitExceeded stop
- WHEN A step is stopped by UsageLimitExceeded
- THEN StepOutcome.reason contains the class name and the masked message, with no body text
Existing Tool Considered
No alternatives check has run. The need is covered by pydantic-ai itself: UnexpectedModelBehavior.message holds the message without the body. The project builds its own _stop_reason in src/devops_cli/roadmap/implement_step.py. The fix is one line: read .message instead of str(). The written cost is one line change plus one test case, roughly 200 tokens to build and keep.
Key questions
- What attribute of UnexpectedModelBehavior holds the message without the body?: The .message attribute. pydantic-ai's UnexpectedModelBehavior has .message and .body as separate fields. Its str joins them, but .message alone excludes the body. [sources: src/devops_cli/roadmap/implement_step.py:563, openspec/changes/archive/2026-10-30-2758-implement-stop-cause/design.md]
- Should _stop_reason read .message directly or use a helper from agent_run.py?: Read .message directly in _stop_reason with a getattr fallback to str() for safety. The body references run_error_message in agent_run.py, but that function is not present in the current code. A direct attribute read is simpler and avoids a cross-module dependency for a one-line fix. (best practice) [sources: src/devops_cli/roadmap/implement_step.py:563, src/devops_cli/roadmap/agent_run.py]
- Chosen: Read .message directly in _stop_reason. One-line change, no new import, no cross-module coupling. Both UsageLimitExceeded and UnexpectedModelBehavior expose .message.
- Rejected: Call a shared helper in agent_run.py. The body suggests run_error_message, but that function is not in the current code. Adding it would be a larger change than the fix needs.
- Does UsageLimitExceeded also expose a .message attribute?: Yes. Both pydantic-ai exceptions inherit from a base that sets .message. Using .message for both keeps the code uniform. [sources: src/devops_cli/roadmap/implement_step.py:606]
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.Model text leaks into a visible stop comment, but the step still completes and no data is lost.Users see raw model text in the stop reason, which is noisy and may contain sensitive content.The candidate names run_error_message as a ready-made helper, so the change is a small edit to _stop_reason.Both target the stop reason for UnexpectedModelBehavior in implement_step.py, but #2758 added the message while the candidate removes the body from it.devops-cli-service commentedon Oct 30, 2026
Status set to Ready at d264e6e (see proposed design in issue body).
fix(roadmap): name the repo and cause in refine warnings (#2784)
dan-petty commentedon Oct 30, 2026
Done by #2562 (PR 2784).
_stop_reasoninimplement_step.pynow readsstopped.messageand cuts it with the sharedbounded_text. It no longer callsstr(stopped), which addedbody, the text of the model. The shared helper keeps the first line, hides quoted parts and stops at:,;or=, and a test with a body that holds a token covers the implement step.