Skip to content

fix(conversation): let run() resume a detector-STUCK conversation - #6668

Merged
VascoSch92 merged 2 commits into
mainfrom
fix/stuck-run-resumes
Nov 12, 2026
Merged

VascoSch92 merged 2 commits into
mainfrom
fix/stuck-run-resumes

Conversation

@enyst

@enyst enyst commented Nov 9, 2026 •

Copy link
Copy Markdown
Member

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, although run() from STUCK is meant to retry (test_run_recovers_from_stuck sets 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() and arun() call it when they resume from STUCK (under the state lock, before the status goes back to RUNNING). Other starting states are unchanged.
  • If the agent repeats itself again, the detector stops it again after the usual thresholds, so a resume gives one more fair try rather than disabling detection.
  • The verify-sdk note on S01.stuck-recover now states the expected behavior.

Issue Number

Fixes #6648 (umbrella #6660)

How to Test

uv run pytest tests/sdk/conversation/local/test_agent_status_transition.py -q
export PATH="$PWD/.agents/skills/verify-sdk/scripts:$PATH"
sdk-map run --file S01 --only S01.stuck-recover
  • New tests for run() and arun(): four identical tool calls make the conversation STUCK through the real detector; a second run makes one more LLM call and finishes. On main the LLM call count stays at 4.
  • The map bullet: after resuming, script_left 0 and status finished (was 2 and stuck). The whole S01 family passes.
  • tests/sdk/conversation (988 passed), plus the stuck-detector, validation-loop and parity tests in tests/cross and the goal-loop and event-service tests in tests/agent_server (240 passed).

Video/Screenshots

Not applicable.

Type

  • Bug fix
  • Feature
  • Refactor
  • Breaking change
  • Docs / chore

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

Variant Architectures Base Image Docs / Tags
java amd64, arm64 eclipse-temurin:17-jdk Link
python-slim amd64, arm64 python-node-runtime Link
python-minimal amd64, arm64 python-node-runtime Link
python amd64, arm64 python-node-runtime Link
golang amd64, arm64 golang:1.21-bookworm Link

Pull (multi-arch manifest)

# Each variant is a multi-arch manifest supporting both amd64 and arm64
docker pull ghcr.io/openhands/agent-server:729fa8f-python

Run

docker run -it --rm \
  -p 8000:8000 \
  --name agent-server-729fa8f-python \
  ghcr.io/openhands/agent-server:729fa8f-python

All tags pushed for this build

ghcr.io/openhands/agent-server:729fa8f-golang-amd64
ghcr.io/openhands/agent-server:729fa8f37fcf9bdec5bab35f97cc23839acfd9a8-golang-amd64
ghcr.io/openhands/agent-server:fix-stuck-run-resumes-golang-amd64
ghcr.io/openhands/agent-server:729fa8f-golang_tag_1.21-bookworm-amd64
ghcr.io/openhands/agent-server:729fa8f-golang-arm64
ghcr.io/openhands/agent-server:729fa8f37fcf9bdec5bab35f97cc23839acfd9a8-golang-arm64
ghcr.io/openhands/agent-server:fix-stuck-run-resumes-golang-arm64
ghcr.io/openhands/agent-server:729fa8f-golang_tag_1.21-bookworm-arm64
ghcr.io/openhands/agent-server:729fa8f-java-amd64
ghcr.io/openhands/agent-server:729fa8f37fcf9bdec5bab35f97cc23839acfd9a8-java-amd64
ghcr.io/openhands/agent-server:fix-stuck-run-resumes-java-amd64
ghcr.io/openhands/agent-server:729fa8f-eclipse-temurin_tag_17-jdk-amd64
ghcr.io/openhands/agent-server:729fa8f-java-arm64
ghcr.io/openhands/agent-server:729fa8f37fcf9bdec5bab35f97cc23839acfd9a8-java-arm64
ghcr.io/openhands/agent-server:fix-stuck-run-resumes-java-arm64
ghcr.io/openhands/agent-server:729fa8f-eclipse-temurin_tag_17-jdk-arm64
ghcr.io/openhands/agent-server:729fa8f-python-amd64
ghcr.io/openhands/agent-server:729fa8f37fcf9bdec5bab35f97cc23839acfd9a8-python-amd64
ghcr.io/openhands/agent-server:fix-stuck-run-resumes-python-amd64
ghcr.io/openhands/agent-server:729fa8f-python-node-runtime-amd64
ghcr.io/openhands/agent-server:729fa8f-python-arm64
ghcr.io/openhands/agent-server:729fa8f37fcf9bdec5bab35f97cc23839acfd9a8-python-arm64
ghcr.io/openhands/agent-server:fix-stuck-run-resumes-python-arm64
ghcr.io/openhands/agent-server:729fa8f-python-node-runtime-arm64
ghcr.io/openhands/agent-server:729fa8f-python-minimal-amd64
ghcr.io/openhands/agent-server:729fa8f37fcf9bdec5bab35f97cc23839acfd9a8-python-minimal-amd64
ghcr.io/openhands/agent-server:fix-stuck-run-resumes-python-minimal-amd64
ghcr.io/openhands/agent-server:729fa8f-python-node-runtime-minimal-amd64
ghcr.io/openhands/agent-server:729fa8f-python-minimal-arm64
ghcr.io/openhands/agent-server:729fa8f37fcf9bdec5bab35f97cc23839acfd9a8-python-minimal-arm64
ghcr.io/openhands/agent-server:fix-stuck-run-resumes-python-minimal-arm64
ghcr.io/openhands/agent-server:729fa8f-python-node-runtime-minimal-arm64
ghcr.io/openhands/agent-server:729fa8f-python-slim-amd64
ghcr.io/openhands/agent-server:729fa8f37fcf9bdec5bab35f97cc23839acfd9a8-python-slim-amd64
ghcr.io/openhands/agent-server:fix-stuck-run-resumes-python-slim-amd64
ghcr.io/openhands/agent-server:729fa8f-python-node-runtime-slim-amd64
ghcr.io/openhands/agent-server:729fa8f-python-slim-arm64
ghcr.io/openhands/agent-server:729fa8f37fcf9bdec5bab35f97cc23839acfd9a8-python-slim-arm64
ghcr.io/openhands/agent-server:fix-stuck-run-resumes-python-slim-arm64
ghcr.io/openhands/agent-server:729fa8f-python-node-runtime-slim-arm64
ghcr.io/openhands/agent-server:729fa8f-golang
ghcr.io/openhands/agent-server:729fa8f37fcf9bdec5bab35f97cc23839acfd9a8-golang
ghcr.io/openhands/agent-server:fix-stuck-run-resumes-golang
ghcr.io/openhands/agent-server:729fa8f-golang_tag_1.21-bookworm
ghcr.io/openhands/agent-server:729fa8f-java
ghcr.io/openhands/agent-server:729fa8f37fcf9bdec5bab35f97cc23839acfd9a8-java
ghcr.io/openhands/agent-server:fix-stuck-run-resumes-java
ghcr.io/openhands/agent-server:729fa8f-eclipse-temurin_tag_17-jdk
ghcr.io/openhands/agent-server:729fa8f-python-minimal
ghcr.io/openhands/agent-server:729fa8f37fcf9bdec5bab35f97cc23839acfd9a8-python-minimal
ghcr.io/openhands/agent-server:fix-stuck-run-resumes-python-minimal
ghcr.io/openhands/agent-server:729fa8f-python-node-runtime-minimal
ghcr.io/openhands/agent-server:729fa8f-python-slim
ghcr.io/openhands/agent-server:729fa8f37fcf9bdec5bab35f97cc23839acfd9a8-python-slim
ghcr.io/openhands/agent-server:fix-stuck-run-resumes-python-slim
ghcr.io/openhands/agent-server:729fa8f-python-node-runtime-slim
ghcr.io/openhands/agent-server:729fa8f-python
ghcr.io/openhands/agent-server:729fa8f37fcf9bdec5bab35f97cc23839acfd9a8-python
ghcr.io/openhands/agent-server:fix-stuck-run-resumes-python
ghcr.io/openhands/agent-server:729fa8f-python-node-runtime

About Multi-Architecture Support

  • Each variant tag (e.g., 729fa8f-python) is a multi-arch manifest supporting both amd64 and arm64
  • Docker automatically pulls the correct architecture for your platform
  • Individual architecture tags (e.g., 729fa8f-python-amd64) are also available if needed

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
@github-actions

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

REST API breakage checks (OpenAPI) — ✅ PASSED

Result: ✅ PASSED

Action log

@github-actions

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Coverage

Coverage Report •
FileStmtsMissCoverMissing
openhands-sdk/openhands/sdk/conversation
   stuck_detector.py2291593%177, 257, 264, 299, 339–340, 342, 353–354, 416, 426, 429, 532–533, 539
openhands-sdk/openhands/sdk/conversation/impl
   local_conversation.py12656995%181, 395, 462, 498–501, 503, 759–760, 884, 1330, 1332, 1403, 1527, 1553, 1687, 1692–1697, 1750, 1771–1773, 1822, 2234–2236, 2239–2240, 2248–2249, 2253–2255, 2259–2260, 2544, 2547–2548, 2766, 2803, 2807, 2811, 2832, 2884, 2888, 2922, 2929–2930, 2938, 2942–2943, 2947, 2954, 3262–3263, 3281–3282, 3315, 3527, 3531, 3552, 3603, 3610–3611
TOTAL55581870684% 

@enyst
enyst marked this pull request as ready for review November 9, 2026 09:18
@enyst
enyst requested a review from all-hands-bot November 9, 2026 09:18

@all-hands-bot all-hands-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_message path: no user message can be appended between _resume_if_stuck() and the first detection pass, because send_message serializes 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_message resets STUCK to IDLE and is unchanged. RemoteConversation.run() still raises ConversationRunError on 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_id and _last_nudged_error_event_id are 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 next run(), 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 for run() and arun().
  • Regression value confirmed: the two new tests applied to an unpatched main checkout 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 unpatched main in 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 full tests/cross run also fail identically on unpatched main in 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 no ready-for-dev label, while the actual target issue #6648 is labeled ready-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() and arun() 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-recover map bullet updated and known-failure note removed: delivered.

✅ APPROVED

@all-hands-bot
all-hands-bot requested review from VascoSch92 and removed request for VascoSch92 November 9, 2026 09:44
@neubig
neubig requested a review from simonrosenberg November 9, 2026 18:17

@VascoSch92 VascoSch92 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@VascoSch92
VascoSch92 enabled auto-merge (squash) November 12, 2026 13:14
@VascoSch92

Copy link
Copy Markdown
Member

@all-hands-bot Please solve conflicts here

# Conflicts:
#	.agents/skills/verify-sdk/references/feature-map/S01-agent-loop.md
@all-hands-bot

Copy link
Copy Markdown
Collaborator

Resolved the merge conflicts. ✅

The branch had one conflicting file after rebasing onto the latest main:

  • .agents/skills/verify-sdk/references/feature-map/S01-agent-loop.md

The conflict was in the S01.stuck-recover bullet: main still carried the old "Known failure" note for #6648, while this PR's branch replaced it with an Expected: note describing the fixed behavior. Since this PR fixes #6648, I kept the PR's updated wording and dropped the obsolete "Known failure" note.

I merged the latest main into the branch and pushed the result. The PR is now MERGEABLE (previously CONFLICTING); the remaining BLOCKED state is from the pending simonrosenberg review, not a code conflict.

Generated by OpenHands AI on behalf of the user.

@VascoSch92
VascoSch92 merged commit fb75ae9 into main Nov 12, 2026
43 checks passed
@VascoSch92
VascoSch92 deleted the fix/stuck-run-resumes branch November 12, 2026 13:25
enyst added a commit that referenced this pull request Nov 12, 2026
- 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
enyst added a commit that referenced this pull request Nov 12, 2026
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
@enyst enyst mentioned this pull request Nov 12, 2026
1 of 5 tasks
@github-actions github-actions Bot mentioned this pull request Nov 19, 2026
2 of 8 tasks
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]: run() cannot get a stuck conversation moving; the detector sets STUCK again before any LLM call

5 participants