Repository navigation
fix(conversation): let run() resume a detector-STUCK conversation - #6668
Conversation
run() reset STUCK to RUNNING, but the stuck detector still saw the repeated action/observation pairs since the last user message and set STUCK again before any LLM call. Only a new user message got the conversation moving. Resuming from STUCK now starts a fresh detection window at the end of the history, as a new user message does, in both run() and arun(). Fixes #6648 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013ArwwLKWzfpSTpRccheeWP
REST API breakage checks (OpenAPI) — ✅ PASSEDResult: ✅ PASSED |
Coverage Report •
|
||||||||||||||||||||||||||||||
all-hands-bot
left a comment
There was a problem hiding this comment.
This review was posted by an AI agent (OpenHands).
Verdict: approve. No material correctness, security, or compatibility findings on head 9302afda.
Scope
The change belongs here: it modifies the SDK's conversation run loop and stuck detector (openhands-sdk/openhands/sdk/conversation/), which this repository owns. No cross-repo boundary issue.
What was verified on the workspace checkout of this head
StuckDetector.mark_resumed()samples the last event id on the active branch and_events_since_last_user_message()slices events after it, mirroring how events after a new user message are excluded. Both paths are correct, including the stale-id case (event removed via navigation/fork): the slice degrades to the full post-user-message window, which is the pre-fix behavior and cannot hide new repetitions. Slicing by id rather than index is the safer choice for a movable HEAD.- The resume boundary's semantics match the
send_messagepath: no user message can be appended between_resume_if_stuck()and the first detection pass, becausesend_messageserializes against the run on the same FIFO/state lock. mark_resumed()is called under the state lock in both_run()and_arun(), before STUCK → RUNNING. These are the only STUCK → RUNNING transition sites;send_messageresets STUCK to IDLE and is unchanged.RemoteConversation.run()still raisesConversationRunErroron stuck status, so remote behavior is untouched.- Detection is not weakened: after a resume, repeating the same pattern re-sticks after the same configured thresholds (the fresh window only removes already-counted events; new events accumulate normally, and the action-error nudge path shares the same window so it cannot re-fire on old errors). A resume grants one more fair try, exactly as described.
- Compatibility:
_resumed_after_event_idand_last_nudged_error_event_idare private (in-memory) state; no public API, serialized event, or persisted-settings shape changes. The boundary is intentionally not persisted; a conversation restored while STUCK gets the window at the nextrun(), which is the only point it is needed.
Tests and CI
tests/sdk/conversation/local/test_agent_status_transition.py: 15/15 pass on this head, including the two new detector-driven resume tests forrun()andarun().- Regression value confirmed: the two new tests applied to an unpatched
maincheckout fail (conversation re-sticks with zero new LLM calls), so they genuinely cover the reported bug through the real detector path, not hand-seeded state. - Full
tests/sdk/conversation: 987 passed, 1 failure (test_slow_mcp_servers_start_side_by_side). That test also fails on unpatchedmainin this environment (MCP stdio startup timing), so it is pre-existing flakiness, not caused by this PR; CI on this exact head is green for the corresponding workflows. - Stuck-detector and validation-loop tests (
tests/cross/test_stuck_detector.py,test_stuck_detector_config.py,test_validation_loops.py): pass. The three secret-masking parity/live-server failures in the fulltests/crossrun also fail identically on unpatchedmainin this environment (environment secret-injection difference), not related to this change. - GitHub Actions on
9302afda: all code/test/build checks pass. The single failing check, "Validate PR description", is a linked-issue readiness gate: the umbrella issue #6660 is referenced in the PR body and carries noready-for-devlabel, while the actual target issue #6648 is labeledready-for-dev. That is a repo process gate for the author/automation to resolve (e.g. drop the umbrella reference from the body), not a defect in the code; flagging it here so it is visible.
Acceptance criteria (issue #6648, at this head)
run()after a real detector-STUCK makes at least one further LLM call: delivered, with tests that fail on main.- Repeated behavior during the resumed run still ends STUCK: delivered via unchanged thresholds.
- Both
run()andarun()covered by regression tests: delivered. - Persisted-STUCK resume behaves like in-memory: delivered (window set at run() entry regardless of how STUCK arose).
S01.stuck-recovermap bullet updated and known-failure note removed: delivered.
✅ APPROVED
|
@all-hands-bot Please solve conflicts here |
# Conflicts: # .agents/skills/verify-sdk/references/feature-map/S01-agent-loop.md
|
Resolved the merge conflicts. ✅ The branch had one conflicting file after rebasing onto the latest
The conflict was in the I merged the latest Generated by OpenHands AI on behalf of the user. |
- F04.delete: deleting closes the open socket with 4004 before the run is paused, so the socket sees no PauseEvent or InterruptEvent (#5757). - F05.stuck-rerun: /run on a detector-STUCK conversation starts a fresh detection window (#6668), so the looping stub runs four more steps. - F06.restart-persist: a socket open across a restart is closed with 1012. - F07: the #6745 race gotcha names every bullet it can hit under load. - F03: history notes removed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013ArwwNZe7p1P7oMgnFNYcy
The delta 9bf835c..fb75ae9 (#6783, #5757, #6668, #6676) was replayed live: 16 agent-server and 13 SDK families, with an independent re-check of the edited agent-server families. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013ArwwNZe7p1P7oMgnFNYcy
HUMAN:
This PR proposes a fix for a bug uncovered during the first full agentic run of
verify-sdk.AGENT:
I'm an AI agent (Claude Code) helping Engel Nyst (@enyst) with project maintenance.
Requested by Engel · project thread
Why
After stuck detection stops a conversation,
run()resets STUCK to RUNNING, but the detector still sees the repeated action/observation pairs since the last user message and sets STUCK again before any LLM call. So only a new user message got a detected-stuck conversation moving, althoughrun()from STUCK is meant to retry (test_run_recovers_from_stucksets STUCK by hand with no repeated events, so it never met this).Summary
StuckDetector.mark_resumed()starts a fresh detection window at the current end of the history: only events after that point count, the same way events after a new user message count.run()andarun()call it when they resume from STUCK (under the state lock, before the status goes back to RUNNING). Other starting states are unchanged.S01.stuck-recovernow states the expected behavior.Issue Number
Fixes #6648 (umbrella #6660)
How to Test
run()andarun(): four identical tool calls make the conversation STUCK through the real detector; a second run makes one more LLM call and finishes. Onmainthe LLM call count stays at 4.script_left0 and statusfinished(was 2 andstuck). The whole S01 family passes.tests/sdk/conversation(988 passed), plus the stuck-detector, validation-loop and parity tests intests/crossand the goal-loop and event-service tests intests/agent_server(240 passed).Video/Screenshots
Not applicable.
Type
Notes
The resume boundary lives on the in-memory detector and is not persisted. A conversation restored from disk while STUCK sets it when
run()starts, which is the only point it is needed.Cross-repo dependencies: none.
Generated by Claude Code
🐳 Agent Server images for this PR — GHCR package, pull/run commands, and all pushed tags (click to expand)
• GHCR package: https://github.com/OpenHands/agent-sdk/pkgs/container/agent-server
Variants & Base Images
eclipse-temurin:17-jdkpython-node-runtimepython-node-runtimepython-node-runtimegolang:1.21-bookwormPull (multi-arch manifest)
# Each variant is a multi-arch manifest supporting both amd64 and arm64 docker pull ghcr.io/openhands/agent-server:729fa8f-pythonRun
All tags pushed for this build
About Multi-Architecture Support
729fa8f-python) is a multi-arch manifest supporting both amd64 and arm64729fa8f-python-amd64) are also available if needed