Skip to content

feat: extract runtime turn wire notifier - #462

Merged
delete-cloud merged 1 commit into
mainfrom
dogfood/runtime-turn-wire
Jun 2, 2026
Merged

delete-cloud merged 1 commit into
mainfrom
dogfood/runtime-turn-wire

Conversation

@delete-cloud

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

Copy link
Copy Markdown
Owner

Summary

  • add RuntimeTurnWire to own generic error wire message emission for local daemon runtime turns
  • replace the inline SessionManager.run_agent generic error wire closure with the helper
  • add focused tests for emitted StreamDelta + TurnEnd(ERROR) sequence and session mismatch guard
  • update ADR-0058 implementation status for this narrow ownership movement

Tests

  • uv run pytest tests/coding_agent/test_runtime_turn_wire.py -v
  • uv run pytest tests/coding_agent/test_run_lifecycle.py -v
  • uv run pytest tests/ui/test_session_manager_runtime.py -k "turn_error or fatal_tool or bootstrap_fails or closes_cached_runtime" -v
  • uv run ruff check src/coding_agent/wire/__init__.py src/coding_agent/wire/runtime.py src/coding_agent/server/session_manager.py tests/coding_agent/test_runtime_turn_wire.py
  • uv run ruff format --check src/coding_agent/wire/__init__.py src/coding_agent/wire/runtime.py src/coding_agent/server/session_manager.py tests/coding_agent/test_runtime_turn_wire.py
  • git diff --check

Review policy

If CodeRabbit is rate-limited, skipped, pending without actionable review, or otherwise does not inspect the diff, this PR will get a local subagent P1/P2 review before merge.

Summary by CodeRabbit

  • Refactor

    • Refactored how generic errors are handled during local daemon runtime execution to improve modularity.
  • Tests

    • Added comprehensive tests validating error notification sequences and session identifier verification.
  • Documentation

    • Updated architecture documentation and task specifications to reflect the refactored error handling approach.

@coderabbitai

coderabbitai Bot commented Jun 2, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

This PR extracts SessionManager.run_agent's inline generic runtime-turn error handling into a dedicated wire-owned helper, RuntimeTurnWire. The new module defines a dataclass and protocol for session-validated error notification, emitting structured StreamDelta and TurnEnd messages. SessionManager is updated to use this helper, and comprehensive tests and architectural documentation are added to track the refactoring.

Changes

RuntimeTurnWire extraction for generic runtime-turn error handling

Layer / File(s) Summary
RuntimeTurnWire contract and module export
src/coding_agent/wire/runtime.py, src/coding_agent/wire/__init__.py
Introduces RuntimeTurnWireSession protocol with id field, type aliases for async emitter and optional logger callables, and RuntimeTurnWire frozen dataclass. Implements notify_generic_error() to validate session identity, log exceptions optionally, and emit error StreamDelta followed by TurnEnd(CompletionStatus.ERROR). Re-exported via wire package.
RuntimeTurnWire behavior tests
tests/coding_agent/test_runtime_turn_wire.py
Tests verify notify_generic_error() emits correct StreamDelta with error text and TurnEnd with error status, records log messages, and rejects mismatched session identities with ValueError.
SessionManager integration of RuntimeTurnWire
src/coding_agent/server/session_manager.py
Updates run_agent to construct RuntimeTurnWire for the turn and wire RuntimeTurnErrorHandler to use turn_wire.notify_generic_error() instead of inline _notify_generic_local_daemon_turn_error.
Architecture and task documentation updates
.opencode/prompts/tasks/local-daemon-pr39-runtime-turn-wire.md, docs/adr/0058-local-daemon-control-plane-executor-architecture.md
Adds task specification for refactoring scope and constraints, and updates ADR-0058 follow-up status to reflect delegation of generic error notification to RuntimeTurnWire.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • delete-cloud/Coding-Agent-Loop#458: Both PRs refactor SessionManager.run_agent's local-daemon turn error path by extracting generic error handling into RuntimeTurnErrorHandler, with this PR further wiring RuntimeTurnErrorHandler.notify_generic_error to a new wire-owned RuntimeTurnWire implementation.
  • delete-cloud/Coding-Agent-Loop#436: Both PRs modify local-daemon/runtime turn error handling in SessionManager—that PR routes adapter on_turn_error into session-level generic error/StreamDelta+TurnEnd emission, while this PR refactors that generic error wire emission into RuntimeTurnWire.notify_generic_error instead of being assembled inline in run_agent.
  • delete-cloud/Coding-Agent-Loop#427: Both PRs modify SessionManager.run_agent's runtime-turn flow—that PR refactors how local runtime is executed via LocalDaemonExecutor, while this PR refactors the generic runtime-turn error wiring/TurnEnd(ERROR) emission into RuntimeTurnWire within that same runtime-turn error path.

Poem

A wire was born in runtime's heart,
To handle errors, play its part— 🐰
No more inline chaos and pain,
Just structured messages through the main,
Clean, tested, and proud to stand. ✨

🚥 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 'feat: extract runtime turn wire notifier' directly and clearly summarizes the main change: extracting a new RuntimeTurnWire helper to encapsulate generic error wire message emission.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch dogfood/runtime-turn-wire

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

Copy link
Copy Markdown
Owner Author

Local review fallback because CodeRabbit remained pending/stack-only without producing an effective GitHub diff review.

Reviewer: Kepler (local subagent)
Scope: P1/P2 blockers only: correctness, security/data loss, test gaps, ADR-0058 scope drift.

Findings:

  • No P1/P2 findings.

Reviewer verification:

  • tests/coding_agent/test_runtime_turn_wire.py -v: 2 passed
  • tests/coding_agent/test_run_lifecycle.py -v: 21 passed
  • tests/ui/test_session_manager_runtime.py -k "turn_error or fatal_tool or bootstrap_fails or closes_cached_runtime" -v: 6 passed
  • scoped ruff check, ruff format --check, and git diff --check: passed.

@delete-cloud
delete-cloud merged commit 53c9e7d into main Jun 2, 2026
1 check was pending
@delete-cloud
delete-cloud deleted the dogfood/runtime-turn-wire branch June 2, 2026 23:30
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