Repository navigation
Description
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 -> breakThis 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)
- [Bug]: Missing security_risk field in tool call causes unrecoverable validation error #1653 (closed) — same underlying failure class (model omits required
security_riskfield). Two attempted fixes, Emit AgentErrorEvent on function call validation errors #1660 ("emit AgentErrorEvent... enabling self-correction/retry") and Sanitize missing security_risk tool arg errors #1661 (friendlier error text), both closed unmerged. - [Bug]: Missing required parameters for function 'execute_bash': {'security_risk'} #4248 (open) — the same "missing required parameter" failure recurring today with
deepseek-reasoner. - Asymmetric handling of content-without-tool-call responses terminates agents driven by weaker/local models #3992 (open) + feat(agent): configurable content_response_policy for content-without-tool-call responses (#3992) #3997 (open, unmerged) — proposes making the content-without-tool-call dispatch path configurable between
finishandnudge, for the same "weaker/local models get hard-terminated instead of given a chance" reasoning. Doesn't touch the action-error stuck pattern. - DRAFT: feat(stuck-detector): emit typed StuckPatternDetected event with reason codes #3565 (closed draft, unmerged) — would have added
StuckDetector.detect_stuck_reason()returning typed codes (repeating_action_error,monologue,repeating_action_observation, …) instead of a bare boolean, so callers could distinguish why a conversation got stuck. Independently useful for triage, but doesn't address recovery.
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
STUCKif 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
STUCKcan 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