Skip to content

StuckDetector: repeating_action_error has no corrective-nudge step before hard STUCK termination #4331

Closed

Description

@VascoSch92

Summary

StuckDetector._is_stuck_repeating_action_error() (openhands-sdk/openhands/sdk/conversation/stuck_detector.py) already detects the pattern where the model repeats the same tool call and gets the same error back action_error times in a row (default threshold: 3). But once detected, the run loop (local_conversation.py) goes straight from "pattern detected" to a terminal STUCK status with no attempt at self-correction:

# local_conversation.py, sync run loop (async loop mirrors this)
if self._stuck_detector:
    is_stuck = self._stuck_detector.is_stuck()
    if is_stuck:
        logger.warning("Stuck pattern detected.")
        self._state.execution_status = ConversationExecutionStatus.STUCK
        continue   # -> loop sees STUCK at top -> break

This is asymmetric with how the SDK already treats a different weak-model failure mode. In response_dispatch.py, an EMPTY LLM response (no tool call, no content) gets _send_corrective_nudge() — an explicit injected message telling the model what it needs to do — and the loop continues. A model that instead keeps emitting a malformed tool call gets zero equivalent chance: it only ever sees the tool's own validation-error text repeated back to it, and if it doesn't self-correct from that alone within 3 tries, the conversation is killed unconditionally.

There's also existing precedent in this same file for "intercept a terminal status, inject feedback, and continue" — the stop-hook handling on FINISHED does exactly that (denies the stop, emits a feedback MessageEvent, sets status back to RUNNING, continues the loop). STUCK has no equivalent hook/nudge step.

Reproduction

Observed against openhands/glm-5.2 in production traffic (via an Agent Canvas deployment running SDK 1.39.1). The model repeatedly called file_editor with:

{"command": "create", "path": "/tmp/some_file.py"}

— well-formed JSON, but missing the required file_text argument. Each call got back:

Parameter `file_text` is required for command: create.

The model repeated the identical call (byte-identical arguments) 4 times in a row without ever including file_text, at which point _is_stuck_repeating_action_error tripped and the conversation was marked STUCK — mid-task, no further recovery possible without manual intervention.

Scanning conversations from the same deployment: 7/107 openhands/glm-5.2 conversations ended in STUCK, versus 0/85 for openai/gpt-5.6-sol over the same window. Of those 7, the failure signature was always the model repeating one identical malformed/no-op action (missing file_text, bare C-c terminal action, or an empty terminal command) — never a genuine unbreakable loop where a nudge clearly wouldn't have helped.

Related issues/PRs (none of which cover this exact gap)

Suggested approach

Extend the corrective-nudge pattern from #3997 to the repeating_action_error (and arguably repeating_action_observation) stuck patterns:

  • Before flipping to STUCK, if this is the first time the pattern is detected for the current identical-action streak, emit one explicit corrective nudge (naming the repeated action and its error) instead of terminating, and let the loop continue.
  • Only transition to STUCK if the identical action+error pattern continues after the nudge — i.e. give the model exactly one extra, higher-salience chance beyond the passive tool-observation feedback it's already ignoring.
  • This is additive/opt-in-by-default-safe in the same sense as feat(agent): configurable content_response_policy for content-without-tool-call responses (#3992) #3997: today this path is 100% terminal, so a bounded extra attempt cannot make outcomes worse, only recover a fraction of cases for free.
  • Pairs well with reviving DRAFT: feat(stuck-detector): emit typed StuckPatternDetected event with reason codes #3565's typed stuck-reason codes, so harnesses that do still end up with a terminal STUCK can tell "gave it a nudge and it still didn't recover" apart from other stuck reasons for triage/auto-reporting.

Happy to help scope/implement this if there's appetite — it's a small, well-contained change following an existing pattern in the same file.

Activity

  1. added
    enhancement
    on Aug 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions