Skip to content
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

fix: improve stuck detection in UI mode #5595

Closed
wants to merge 2 commits into from
Closed

Conversation

enyst
Copy link
Collaborator

@enyst enyst commented Dec 14, 2024

Allow the agent to continue after it gets stuck.


(Original openhands comment)

The issue has been resolved by making the stuck detection UI-mode aware:

  1. In UI mode (with actual user):

    • Only consider history after the last user message
    • This allows users to naturally recover from stuck state by sending a new message
    • Agent needs to get stuck again (multiple steps) after user message to trigger error
  2. In headless mode (automated/testing):

    • Keep existing behavior of looking at full history
    • Fail fast with error when stuck is detected

The implementation:

  • Adds ui_mode parameter to stuck detection
  • Uses headless_mode flag to determine default behavior
  • Maintains backward compatibility
  • Includes comprehensive tests for both modes

Fix: #5480


To run this PR locally, use the following command:

docker run -it --rm   -p 3000:3000   -v /var/run/docker.sock:/var/run/docker.sock   --add-host host.docker.internal:host-gateway   -e SANDBOX_RUNTIME_CONTAINER_IMAGE=docker.all-hands.dev/all-hands-ai/runtime:1e739bd-nikolaik   --name openhands-app-1e739bd   docker.all-hands.dev/all-hands-ai/openhands:1e739bd

- Remove almost_stuck field from State class
- Remove almost_stuck counter from StuckDetector
- Simplify stuck detection logic to focus on actual loop detection
- Update tests to remove almost_stuck assertions
- Add UI mode awareness to stuck detection
- Only consider history after last user message in UI mode
- Keep existing behavior in headless mode
- Add comprehensive tests for both modes

Fix: #5480
@enyst enyst closed this Dec 14, 2024
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.

[Bug]: Cannot recover from "Agent stuck in loop"
2 participants