refactor: consolidatate cancellation - #45
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
💤 Files with no reviewable changes (1)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughThis PR centralizes ChangesBareLoop execution and lifecycle refactor
Sequence Diagram(s)sequenceDiagram
participant Caller
participant process_turn
participant run_turn_body
participant CancelSignal
Caller->>process_turn: invoke turn
process_turn->>run_turn_body: run turn body
process_turn->>CancelSignal: race turn completion with cancellation
alt cancellation first
CancelSignal-->>process_turn: notified
process_turn->>Caller: on_turn_end(error="cancelled")
process_turn-->>Caller: LoopError::Cancelled
else turn completes
run_turn_body-->>process_turn: result
process_turn-->>Caller: return result
end
sequenceDiagram
participant dispatch_tools
participant dispatch_tool_with_recovery
participant Tool
participant Reflector
dispatch_tools->>dispatch_tool_with_recovery: dispatch sequentially
dispatch_tool_with_recovery->>Tool: invoke tool
Tool-->>dispatch_tool_with_recovery: result or error
dispatch_tool_with_recovery->>Reflector: recover tool error
Reflector-->>dispatch_tool_with_recovery: action and correction
dispatch_tool_with_recovery->>dispatch_tool_with_recovery: fire tool post observer
Possibly related PRs
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/engine/bare/stream.rs (1)
44-69: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick winStale
# Errorsdoc after removing the inline cancellation race.With Line 69 now awaiting
stream.next()directly, the inline path no longer returnsLoopError::Cancelledmid-stream — only the handler path (stream_turn_via_handler) can. Line 44 ("ReturnsLoopError::Cancelledif the cancellation signal fires mid-stream") overstates this and should be scoped to the handler path or clarified that cancellation is now handled byprocess_turn'sselect!.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/engine/bare/stream.rs` around lines 44 - 69, The `stream_turn` doc comment is stale because the inline path no longer returns `LoopError::Cancelled` mid-stream after switching to `stream.next().await` directly. Update the `stream_turn` documentation to reflect that cancellation is now handled by `process_turn`’s `select!`, and only `stream_turn_via_handler` can surface mid-stream cancellation; keep the wording scoped to the `stream_turn`/`stream_turn_via_handler` behavior so the `# Errors` section matches the current control flow.
🧹 Nitpick comments (2)
src/engine/bare/dispatch.rs (1)
449-452: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueDuplicated doc line. The first sentence of
dispatch_via_pipeline's rustdoc is repeated verbatim (Lines 449 and 451).✏️ Proposed fix
/// Dispatch a tool call through the middleware pipeline. /// - /// Dispatch a tool call through the middleware pipeline. - /// /// Builds a [`ToolDispatchContext`] and delegates to the pipeline's🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/engine/bare/dispatch.rs` around lines 449 - 452, The rustdoc for dispatch_via_pipeline contains a duplicated opening sentence, so remove the repeated line and leave a single clear description for the function. Update the doc comment block in dispatch_via_pipeline so it only states the purpose once, keeping the rest of the documentation unchanged.src/engine/bare.rs (1)
3499-3678: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winThe cancellation tests are a good addition, but note
process_turn_cancel_during_dispatch_fires_turn_endonly assertsturn_ends == 1and never inspects the resultingSessionResult. A regression like theself.budgetloss flagged at Lines 1209–1226 would pass silently. Consider asserting the reported budget (e.g.total_turns/token counts) after cancel-during-dispatch.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/engine/bare.rs` around lines 3499 - 3678, Add an assertion in process_turn_cancel_during_dispatch_fires_turn_end that inspects the returned SessionResult from BareLoop::run, not just the turn_ends observer count. The current test can miss regressions like the self.budget loss, so capture the result from agent.run("Use slow tool").await and verify the reported budget fields (such as total_turns and token counts) are still correct after cancellation during dispatch. Keep the existing cancel and turn_end checks, but extend the test to validate SessionResult preserves budget state.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@src/engine/bare/stream.rs`:
- Around line 44-69: The `stream_turn` doc comment is stale because the inline
path no longer returns `LoopError::Cancelled` mid-stream after switching to
`stream.next().await` directly. Update the `stream_turn` documentation to
reflect that cancellation is now handled by `process_turn`’s `select!`, and only
`stream_turn_via_handler` can surface mid-stream cancellation; keep the wording
scoped to the `stream_turn`/`stream_turn_via_handler` behavior so the `# Errors`
section matches the current control flow.
---
Nitpick comments:
In `@src/engine/bare.rs`:
- Around line 3499-3678: Add an assertion in
process_turn_cancel_during_dispatch_fires_turn_end that inspects the returned
SessionResult from BareLoop::run, not just the turn_ends observer count. The
current test can miss regressions like the self.budget loss, so capture the
result from agent.run("Use slow tool").await and verify the reported budget
fields (such as total_turns and token counts) are still correct after
cancellation during dispatch. Keep the existing cancel and turn_end checks, but
extend the test to validate SessionResult preserves budget state.
In `@src/engine/bare/dispatch.rs`:
- Around line 449-452: The rustdoc for dispatch_via_pipeline contains a
duplicated opening sentence, so remove the repeated line and leave a single
clear description for the function. Update the doc comment block in
dispatch_via_pipeline so it only states the purpose once, keeping the rest of
the documentation unchanged.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: efc93d92-9efa-455d-aa9e-5e7e0b71f24d
📒 Files selected for processing (7)
src/compact.rssrc/engine/bare.rssrc/engine/bare/compact.rssrc/engine/bare/dispatch.rssrc/engine/bare/emission.rssrc/engine/bare/message.rssrc/engine/bare/stream.rs
refactor: consolidatate cancellation
No description provided.