Repository navigation
feat: extract runtime turn error handler #458
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
coding-agent/.opencode/prompts/tasks/local-daemon-pr35-turn-error-handler.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| Goal: | ||
| Extract local daemon turn error actions from `SessionManager.run_agent` into a | ||
| runtime lifecycle helper so error handling is owned by the runtime turn boundary, | ||
| not by the session manager loop body. | ||
|
|
||
| Scope: | ||
| - Add a `RuntimeTurnErrorHandler` helper under `coding_agent.runs.lifecycle`. | ||
| - Move fatal, cancelled, and generic turn error actions out of | ||
| `SessionManager.run_agent`. | ||
| - Preserve existing behavior for run finish status, observation state, runtime | ||
| close, wire error notification, and outer exception propagation. | ||
| - Update ADR-0058 follow-up notes. | ||
| - Add focused unit coverage for the new lifecycle helper. | ||
|
|
||
| Out of scope: | ||
| - Changing runtime store payloads or status names. | ||
| - Moving checkpoint restore, display projection, or final cleanup policy. | ||
| - Changing HTTP/CLI API behavior. | ||
| - Changing LocalDaemonExecutor execution semantics. | ||
|
|
||
| Context: | ||
| - ADRs: | ||
| - docs/adr/0058-local-daemon-control-plane-executor-architecture.md | ||
| - Relevant files: | ||
| - src/coding_agent/runs/lifecycle.py | ||
| - src/coding_agent/runs/__init__.py | ||
| - src/coding_agent/server/session_manager.py | ||
| - tests/coding_agent/test_run_lifecycle.py | ||
| - tests/ui/test_session_manager_runtime.py | ||
|
|
||
| Target tests: | ||
| - uv run pytest tests/coding_agent/test_run_lifecycle.py -v | ||
| - uv run pytest tests/ui/test_session_manager_runtime.py -k "run_agent_marks_agent_run_failed_when_turn_outcome_errors or run_agent_records_error_outcome_without_runtime_store or run_agent_reraises_fatal_tool_execution_error_without_sending_error_turn or run_agent_persists_agent_run_lifecycle_when_store_configured" -v | ||
| - uv run ruff check src/coding_agent/runs src/coding_agent/server/session_manager.py tests/coding_agent/test_run_lifecycle.py tests/ui/test_session_manager_runtime.py | ||
| - uv run ruff format --check src/coding_agent/runs/lifecycle.py src/coding_agent/runs/__init__.py src/coding_agent/server/session_manager.py tests/coding_agent/test_run_lifecycle.py | ||
| - git diff --check | ||
|
|
||
| Loop policy: | ||
| - Engineer implements the smallest correct change and runs the target tests. | ||
| - Reviewer reviews only the resulting diff and affected tests. | ||
| - Reviewer reports only P1/P2 findings. | ||
| - Engineer fixes only accepted P1/P2 findings and reruns the same target tests. | ||
| - Verifier reruns the exact target tests and reports pass/fail only. | ||
|
|
||
| Stop conditions: | ||
| - At most one review/fix/retest cycle. | ||
| - Escalate architectural redirection or scope expansion to the human. | ||
| - Ignore non-blocking optimization suggestions. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Set the session state to
cancelledhere.handle_cancelled()updates the run record, but it never updatessession.turn_status. After this refactor,SessionManager.run_agent()persists whatever state the handler leaves behind, so user-initiated cancels now stick at"cancelling"(and some other cancellation paths can fall back to"idle"in thefinallyblock) instead of ending as"cancelled".Proposed fix
async def handle_cancelled(self, session: RuntimeTurnErrorSession) -> None: if self.cancel_observation is not None: self.cancel_observation() await self.turn_run.finish_if_started( session, status="cancelled", result={}, error="cancelled", ) + session.turn_status = "cancelled" + session.last_failure_details = None🤖 Prompt for AI Agents