Skip to content

Conversation

enyst
Copy link
Collaborator

@enyst enyst commented Oct 6, 2025

Hi, I'm OpenHands-GPT-5.

This PR ports and refines the changes proposed in #9809 by @claysauruswrecks to prevent stalls with Grok-4 models when they emit empty assistant messages during internal reasoning. Full credit to the original author; this PR preserves authorship in the commit history and centralizes the model-matching behavior.

Summary of changes:

  • Centralize model pattern for "reasoning-empty" models in openhands/llm/model_features.py as REASONING_EMPTY_MESSAGE_PATTERNS = ['grok-4*'] so that matching works across providers/proxies (e.g., xai/grok-4-0709, openrouter/xai/grok-4-0709, litellm_proxy/xai/grok-4-0709).
  • Update openhands/agenthub/codeact_agent/function_calling.py: when there are no tool_calls and the assistant message content is empty, set wait_for_response=False if the model matches the above patterns; default behavior unchanged otherwise. Tool-call flows are unaffected.
  • Add focused unit tests validating the behavior for Grok vs non-Grok, various proxy prefixes, empty vs non-empty content.

Why:

  • Some Grok-4 responses occasionally contain empty assistant content while the model is still internally reasoning. Prior behavior caused the agent to wait for user input, stalling the conversation. The updated logic avoids this by not waiting when content is empty for Grok-4 family models.

Notes:

  • The behavior remains unchanged for non-Grok models and for tool-call paths.
  • The model matching uses existing normalize_model_name/model_matches utilities for consistency.

Thanks to @claysauruswrecks for the original PR and investigation. This ports the essence, resolves merge conflicts with main, and adds tests. Feedback welcome!

@enyst can click here to continue refining the PR


To run this PR locally, use the following command:

GUI with Docker:

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:15c4fcb-nikolaik   --name openhands-app-15c4fcb   docker.all-hands.dev/all-hands-ai/openhands:15c4fcb

CLI with uvx:

uvx --python 3.12 --from git+https://github.com/All-Hands-AI/OpenHands@oh-port-pr-9809-grok-empty-reasoning#subdirectory=openhands-cli openhands

… of #9809 by @claysauruswrecks: If a Grok-4 model returns an empty assistant message while streaming reasoning tokens, do not set wait_for_response; otherwise the agent stalls in 'awaiting user input'. Implemented via REASONING_EMPTY_MESSAGE_PATTERNS in model_features and model_matches in function_calling. Added unit tests.\n\nCo-authored-by: Engel Nyst <[email protected]>\nCo-authored-by: openhands <[email protected]>
Copy link

openhands-ai bot commented Oct 6, 2025

Looks like there are a few issues preventing this PR from being merged!

  • GitHub Actions are failing:
    • Run Python Tests

If you'd like me to help, just leave a comment, like

@OpenHands please fix the failing actions on PR #11258 at branch `oh-port-pr-9809-grok-empty-reasoning`

Feel free to include any additional details that might help me get this PR into a better state.

You can manage your notification settings

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.

2 participants