Repository navigation
fix: improve conversation resilience for long-running and resumed sessions - #2384
Merged
Merged
Conversation
…sions Three targeted fixes for issues discovered while running headless benchmark sessions with non-OpenAI models (kimi-k2.5, minimax-m2.5): 1. Sanitize raw control characters in tool_call.arguments (agent.py) Some LLMs emit literal U+0000–U+001F bytes instead of JSON escape sequences (\n, \t, etc.) in tool_call.arguments. json.loads() rejects these per RFC 8259, poisoning the session permanently. Added sanitize_json_control_chars() to escape them before parsing. 2. EventLog._get_single_item: recover from stale in-memory index When the in-memory index (_idx_to_id) becomes stale—e.g. after external file modifications or concurrent writes—_path(i) raises KeyError. Now catches KeyError, rebuilds the index from disk via _scan_and_build_index(), and retries once before raising IndexError. 3. Allow STUCK conversations to resume on new user message or run() Previously STUCK was a terminal state: send_message() did not reset it and run() exited immediately. A persisted STUCK state would permanently kill the session on resume. Now: - send_message() resets STUCK → IDLE (like FINISHED → IDLE) - run() includes STUCK in its pre-loop status reset Co-authored-by: openhands <openhands@all-hands.dev>
Contributor
API breakage checks (Griffe)Result: Passed |
Contributor
Agent server REST API breakage checks (OpenAPI)Result: Failed Log excerpt (first 1000 characters) |
Contributor
Coverage Report •
|
|||||||||||||||||||||||||||||||||||||||||||||
xingyaoww
marked this pull request as ready for review
March 11, 2026 13:45
all-hands-bot
approved these changes
Mar 11, 2026
all-hands-bot
left a comment
Collaborator
There was a problem hiding this comment.
🟢 Good taste - Elegant, focused fixes for real production bugs.
Three pragmatic bug fixes discovered in benchmark runs with non-OpenAI models. Clean implementations, well-tested, no unnecessary complexity:
- Control char sanitization: Simple regex transformation to make malformed LLM output valid JSON
- EventLog recovery: Defensive one-time index rebuild on stale access
- STUCK recovery: Treats STUCK like ERROR - recoverable, not permanently terminal
Testing: 13 new/updated tests covering real behavior (parsing JSON, loading events, transitioning states). No issues found.
Verdict: ✅ Approve - Solid bug fixes that make broken sessions recoverable without changing core architecture.
5 tasks
StressTestor
pushed a commit
to StressTestor/software-agent-sdk
that referenced
this pull request
Jun 1, 2026
…sions (OpenHands#2384) Co-authored-by: openhands <openhands@all-hands.dev>
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Three targeted fixes for issues discovered while running headless benchmark sessions (via
openhands-aiSDK) with non-OpenAI models (kimi-k2.5, minimax-m2.5). These bugs cause conversations to become permanently "poisoned" — unable to recover even after resume — in long-running or multi-session scenarios.Problem
Users running the SDK in headless/benchmark mode with certain LLMs encounter three classes of session-killing bugs:
Malformed
tool_call.arguments: Some models emit raw control characters (literal\n,\t, NUL bytes) instead of JSON escape sequences (\\n,\\t).json.loads()rejects these per RFC 8259, causing anAgentErrorEventthat poisons the conversation permanently.Stale EventLog in-memory index: When the in-memory
_idx_to_idmapping becomes stale (e.g., after external file modifications, concurrent writes, or event healing),_path(i)raisesKeyError, crashing the session instead of recovering.STUCK status permanently kills sessions:
ConversationExecutionStatus.STUCKis a terminal state —send_message()doesn't reset it andrun()exits immediately. If a STUCK state is persisted to disk, the conversation can never recover on resume.Changes
Fix 1: Sanitize control characters in tool_call.arguments
Files:
agent/utils.py,agent/agent.pysanitize_json_control_chars()utility that escapes raw U+0000–U+001F bytes to their JSON-legal equivalents (\n,\t,\uXXXX)json.loads(tool_call.arguments)in_get_action_event()fix_malformed_tool_arguments()but operates at the character levelFix 2: EventLog stale index recovery
Files:
conversation/event_store.py_get_single_item(): catchKeyErrorfrom_path(), rebuild index from disk via_scan_and_build_index(), retry onceIndexErrorif the index still doesn't exist after rebuild (graceful degradation)Fix 3: STUCK status recovery on resume
Files:
conversation/impl/local_conversation.pysend_message(): now resets STUCK → IDLE (like FINISHED → IDLE), treating a new user message as an implicit "unstick" signalrun(): includes STUCK in the pre-loop status reset (alongside IDLE, PAUSED, ERROR)Tests
sanitize_json_control_chars()covering: valid JSON passthrough, literal newline/tab/NUL/CR, multi-char combinations, already-escaped sequences, empty input, realistic tool_call payloadstest_run_recovers_from_stuckandtest_send_message_resets_stuck_to_idleContext
These issues were discovered by a user running the SDK for the AgentBench benchmark harness. They had to maintain 5 monkey-patches downstream to work around these bugs. This PR upstreams 3 of those fixes (the ones with clear root causes in the SDK). The remaining 2 patches (conversation healer for poisoned events and
ToolCallMatchingProperty.manipulation_indicesusingset.remove()on orphaned IDs) may warrant separate PRs after further investigation.Agent Server images for this PR
• GHCR package: https://github.com/OpenHands/agent-sdk/pkgs/container/agent-server
Variants & Base Images
eclipse-temurin:17-jdknikolaik/python-nodejs:python3.13-nodejs22golang: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:6190e69-pythonRun
All tags pushed for this build
About Multi-Architecture Support
6190e69-python) is a multi-arch manifest supporting both amd64 and arm646190e69-python-amd64) are also available if needed