Fix stuck agent detection to allow 10 empty commands before marking as stuck #10750
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.
Summary
This PR fixes the stuck agent detection system to be more lenient with empty commands. Previously, agents were marked as stuck after just 4 identical empty commands, but agents legitimately need to send multiple empty commands to wait for output or monitor long-running processes.
Problem
When agents send multiple empty commands in a row (because they want to see more output or wait for processes), the system incorrectly identifies this as a stuck condition after only 4 empty commands. This leads to premature termination of legitimate agent operations.
Solution
_is_stuck_repeating_action_observation()
to require 10 identical pairs for empty commands vs 4 for regular commands_is_stuck_action_observation_pattern()
to skip empty commands to avoid duplicate detectionisinstance()
forCmdRunAction
Testing
Changes Made
Alternative Solutions Considered
The PR includes analysis of 7 alternative approaches (time-based detection, context-aware systems, etc.), with the current count-based fix being the optimal pragmatic solution that's simple, effective, and backward compatible.
Backward Compatibility
✅ Fully backward compatible - no breaking changes to existing functionality
@enyst can click here to continue refining the PR
To run this PR locally, use the following command:
GUI with Docker:
CLI with uvx: