-
Notifications
You must be signed in to change notification settings - Fork 2.6k
fix: unexpected error message when ctrl+c is entered while running recipe with sub-recipes #3550
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
Conversation
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.
Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.
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.
Pull Request Overview
This PR fixes error message suppression when Ctrl+C is pressed during task execution. The changes implement proper cancellation handling to prevent spurious error messages that occur when channels are closed due to task cancellation rather than actual errors.
Key changes:
- Added cancellation token support throughout the task execution pipeline
- Implemented error message suppression logic when tasks are cancelled and channels are closed
- Added cancellation handling in the CLI session to properly clean up subagent executions
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
workers.rs |
Added conditional error logging to suppress "channel closed" errors when task is cancelled |
tasks_manager.rs |
Added cancellation token tracking and management functionality |
task_execution_tracker.rs |
Added cancellation state tracking and error suppression logic |
subagent_execute_task_tool.rs |
Integrated cancellation token support into task execution flow |
lib/mod.rs |
Updated function signatures to accept cancellation tokens |
executor/mod.rs |
Added cancellation handling setup and tokio::select! for graceful cancellation |
agent.rs |
Added public method to cancel all subagent executions |
session/mod.rs |
Added Ctrl+C handler to cancel subagent executions |
| matches!(error, tokio::sync::mpsc::error::TrySendError::Closed(_)) | ||
| } | ||
|
|
||
| pub fn should_suppress_error( |
Copilot
AI
Jul 21, 2025
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.
The should_suppress_error method is marked as public but appears to be an internal implementation detail. Consider making this method private or documenting its public API contract if it's intended for external use.
| pub fn should_suppress_error( | |
| fn should_suppress_error( |
|
|
||
| pub async fn register_execution(&self, cancellation_token: CancellationToken) { | ||
| let mut tokens = self.active_tokens.write().await; | ||
| tokens.retain(|token| !token.is_cancelled()); |
Copilot
AI
Jul 21, 2025
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.
The cleanup of cancelled tokens happens on every registration. For high-frequency registrations, this could become inefficient. Consider implementing a periodic cleanup strategy or cleanup threshold to avoid O(n) operations on every registration.
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.
this is not high-frequency registrations
| if let Err(e) = state.result_sender.send(result).await { | ||
| tracing::error!("Worker failed to send result: {}", e); | ||
| let is_cancelled_channel_closed = state.task_execution_tracker.is_cancelled() | ||
| && e.to_string().contains("channel closed"); |
Copilot
AI
Jul 21, 2025
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.
Using string matching on error messages is fragile and could break if the error message format changes. Consider using pattern matching on the error type instead: matches!(e, tokio::sync::mpsc::error::SendError(_))
| && e.to_string().contains("channel closed"); | |
| && matches!(e, tokio::sync::mpsc::error::SendError(_)); |
|
just flagging this PR #3554 which may collide with this (but not sure) |
oh! thank you @michaelneale for the heads-up |
* main: (32 commits) fix: use sequential when sub recipe task is 1. (#3573) fix: track message id to keep like with like (#3572) Replace mcp_core::prompt with rmcp::model types (#3561) feat (ui): close recipe modals with esc key (#3568) feat: recipes can retry with success criteria (#3474) Env var to set Ollama request timeout (#3516) Updating docs to match new UI (#3552) Improve Claude Code provider error message for missing CLI (#3363) feat: Work around Gemini API tool call quirks (#3328) feat(ui): Source CashSans-Bold and improve overall text rendering (#3091) refactor: Use openapi for recipe endpoint types and in frontend (#3548) Fix Google Analytics error for local dev (#3544) Extension Library Improvements (#3541) fix(ui): enable selection of zero-config providers in desktop GUI (#3378) refactor: Renames recipe route to recipes to be consistent (#3540) Blog: Orchestrating 6 Subagents to Build a Collaborative API Playground (#3528) Catch json errors a little better (#3437) Rust debug (#3510) refactor: Centralise deeplink encode and decode into server (#3489) feat: deprecate jetbrains extension in favor of public one (#2589) ...
|
wendytang
left a comment
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.
|
I created a new PR #3599 to reuse the cancellation token created in agent.reply |
Handle CLI CTRL+C gracefully to cancel the tasks
fixes issue #3553