Conversation
The check_crashed_tasks() function was incorrectly detecting normal task completions as crashes. This happened because: 1. A task sends ToolEvent::Completed via the channel 2. The task terminates (is_finished() == true) 3. Before the event is processed, check_crashed_tasks() runs 4. It sees is_finished() == true and assumes it's a crash 5. It sends ANOTHER ToolEvent::Failed The fix properly awaits the JoinHandle to check if the task actually panicked or was cancelled. If handle.await returns Ok(()), we know the task completed normally and its event is just pending in the channel. This fixes the 'Subagent task terminated unexpectedly (possible panic or cancellation)' error that appeared for tools like ListSubagents, Glob, LS.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
The
check_crashed_tasks()function was incorrectly detecting normal task completions as crashes. Users were seeing error messages like:This happened for normal tools like
ListSubagents,Glob,LS, etc.Root Cause
There was a race condition in the crash detection logic:
ToolEvent::Completedvia the channelis_finished() == true)check_crashed_tasks()runs on a tickis_finished() == trueand incorrectly assumes it's a crashToolEvent::FailedThe original code assumed that if a task was finished but still in
running_tool_tasks, it must have crashed. But due to async event processing, there's a window where the task has finished and sent its event, but the event hasn't been processed yet.Solution
The fix properly awaits the
JoinHandleto check if the task actually panicked or was cancelled:handle.awaitreturnsOk(()), the task completed normally and its event is pending in the channel - we do NOT send a Failed eventhandle.awaitreturnsErr(JoinError), the task actually crashed (panic or cancellation) - we send a Failed eventTesting
cargo check -p cortex-tui✅cargo fmt✅