Skip to content

Handle local turn errors in executor - #436

Merged
delete-cloud merged 2 commits into
mainfrom
dogfood/local-daemon-turn-error-hooks
Jun 2, 2026
Merged

delete-cloud merged 2 commits into
mainfrom
dogfood/local-daemon-turn-error-hooks

Conversation

@delete-cloud

@delete-cloud delete-cloud commented Jun 2, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • add an on_turn_error lifecycle hook to LocalDaemonExecutor.execute_runtime
  • invoke the hook for adapter.run_turn failures, including asyncio.CancelledError
  • route SessionManager's fatal/cancel/generic runtime turn error handling through that hook while keeping bootstrap fallback behavior stable

Tests

  • uv run pytest tests/coding_agent/test_local_daemon_executor.py -v
  • uv run pytest tests/ui/test_session_manager_runtime.py -k "local_daemon_executor or closes_cached_runtime_after_turn_failure or reraises_fatal_tool_execution_error or reraises_owner_conflict or cancel_session_turn or bootstrap_fails" -v
  • uv run pytest tests/ui/test_session_manager_runtime.py -v
  • uv run pytest tests/ui/test_session_manager_public_api.py -k "run_agent or ensure_session_runtime" -v
  • uv run ruff check src/coding_agent/executors src/coding_agent/server/session_manager.py tests/coding_agent/test_local_daemon_executor.py tests/ui/test_session_manager_runtime.py tests/ui/test_session_manager_public_api.py && git diff --check

Review fallback

If CodeRabbit is rate-limited, skipped, or otherwise does not inspect the diff, run local subagent P1/P2 review before merge.

Summary by CodeRabbit

  • Bug Fixes
    • Centralized error handling for local daemon turn execution failures through a new callback mechanism
    • Enhanced session management to better track and report daemon runtime turn errors
    • Improved consistency in how fatal, cancellation, and generic runtime turn errors are processed
    • Better error propagation ensures clearer failure reporting and session status updates

@coderabbitai

coderabbitai Bot commented Jun 2, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@delete-cloud, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 51 minutes and 13 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 4a77b46f-4c0a-4962-98dd-53945f795ec3

📥 Commits

Reviewing files that changed from the base of the PR and between 41e9cfa and f6369bc.

📒 Files selected for processing (3)
  • coding-agent/.opencode/prompts/tasks/local-daemon-pr14-turn-error-lifecycle.md
  • coding-agent/src/coding_agent/server/session_manager.py
  • coding-agent/tests/ui/test_session_manager_runtime.py
📝 Walkthrough

Walkthrough

This PR implements a turn-error lifecycle hook for local daemon execution, allowing SessionManager.run_agent to intercept adapter exceptions (including cancellations) during turn execution and centralize error handling without duplicating exception handlers.

Changes

Turn Error Lifecycle Handling

Layer / File(s) Summary
Hook contract and executor invocation
src/coding_agent/executors/local_daemon.py, src/coding_agent/executors/__init__.py
RuntimeTurnFailedHook type alias is defined for exceptions and bindings; LocalDaemonRuntimeExecution gains an on_turn_error field; execute_runtime wraps adapter.run_turn in try/except to invoke the hook (awaiting if needed) and re-raise the original exception.
Session manager error handling
src/coding_agent/server/session_manager.py
run_agent defines a turn_error_handled flag and helper functions for fatal, cancellation, and generic turn errors that set session status/failure details, close runtime, and (for generic failures) emit wire messages; the local daemon execution is wired with an on_turn_error callback, and surrounding exception handlers only run if the callback did not already handle the error.
Test coverage and specification
tests/coding_agent/test_local_daemon_executor.py, tests/ui/test_session_manager_runtime.py, .opencode/prompts/tasks/local-daemon-pr14-turn-error-lifecycle.md
FailingRuntimeAdapter test double raises exceptions from run_turn; tests verify the hook is invoked on generic exceptions and asyncio.CancelledError, with proper re-raising; integration test asserts the hook is wired in session manager execution; task specification documents scope, files, and validation commands.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

  • delete-cloud/Coding-Agent-Loop#427: Both PRs modify the local-daemon runtime execution plumbing—LocalDaemonRuntimeExecution/LocalDaemonExecutor.execute_runtime and how SessionManager.run_agent routes local runtime turns—so the main PR's new on_turn_error hook is an extension of the same codepath introduced here.
  • delete-cloud/Coding-Agent-Loop#384: Both PRs modify SessionManager.run_agent in coding-agent/src/coding_agent/server/session_manager.py to change how session failure/turn status details are computed/recorded around turn outcomes, though #384 focuses on TurnOutcome-to-turn_status/last_failure_details logic while the main PR additionally adds on_turn_error handling for local-daemon runtime exceptions.

Poem

A hook that catches errors mid-turn,
When adapters stumble, lessons we learn.
The daemon's dance now handles each fall—
SessionManager orchestrates through it all. 🐰✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Handle local turn errors in executor' directly and clearly describes the main change: adding error handling for turn failures in the local daemon executor.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch dogfood/local-daemon-turn-error-hooks

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@delete-cloud
delete-cloud merged commit eb1dd99 into main Jun 2, 2026
1 check passed
@delete-cloud
delete-cloud deleted the dogfood/local-daemon-turn-error-hooks branch June 2, 2026 17:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant