Skip to content

refactor(sdk): change execution_status only through ConversationState.transition - #6620

Merged
VascoSch92 merged 3 commits into
mainfrom
vasco/conversation-status-transition
Nov 12, 2026
Merged

VascoSch92 merged 3 commits into
mainfrom
vasco/conversation-status-transition

Conversation

@VascoSch92

@VascoSch92 VascoSch92 commented Nov 7, 2026 •

Copy link
Copy Markdown
Member

HUMAN:


AGENT:

Why

Step 2 of #6456 starts with "a ConversationState.transition(to, reason) validated against a table and emitting the state-update event; migrate the ~60 assignments and forbid raw assignment with a CI grep." Today execution_status is assigned at 42 places in LocalConversation, Agent, ACPAgent, response_dispatch and EventService. No single place knows which moves are legal, which is the structure behind #884, #2720 and #1511.

Summary

  • ConversationState.transition(to, reason) checks the move against _ALLOWED_TRANSITIONS and raises InvalidExecutionStatusTransitionError for a move no code path makes. It logs execution_status <from> -> <to>: <reason> at debug level, then assigns through the existing autosave hook, so the change is persisted and published as a ConversationStateUpdateEvent exactly as before. Moving to the current status is a no-op.
  • All 42 assignments now call transition() with a short reason. No control flow changed.
  • The table keeps every move the code makes today. In practice the lifecycle is almost fully connected, so it rejects only three moves: ERROR → IDLE, FINISHED → STUCK and PAUSED → STUCK.
    • A run can fail, be paused or restart from any status.
    • A step can run under any status: condense(), a direct agent.step(), or the sync loop retrying after ACPAgent reported a prompt timeout as ERROR without raising. So FINISHED, WAITING_FOR_CONFIRMATION and STUCK can follow ERROR.
    • A pause can land mid-step: arun() releases the lock for LLM I/O and ACP steps run without it. So PAUSED may be followed by the step's outcome, or by IDLE in the ACP branch.
    • Why the three rejected moves never happen: stuck detection runs under the same lock right after the loop stops on PAUSED or FINISHED. Every IDLE write is guarded and the run loop stops on ERROR.
    • DELETING gets no special case. It is only ever set on the webhook payload, never on the state.
    • ERROR and PAUSED, which the run loop's exception handlers write, are reachable from every status, so a handler can never mask the original error.
  • A pre-commit hook, scripts/check_execution_status_writes.py, rejects any other execution_status assignment (plain, annotated, augmented, or setattr) in the four packages. It runs in the required Pre-commit checks job. The five conversation_service writes update the status index and the webhook payload, which copy the status rather than being ConversationState, so they carry a # status-write: marker.
before                                          after
state.execution_status = FINISHED   x 42 sites  state.transition(FINISHED, "agent finished")
  any move accepted, nothing checks it            -> table check -> autosave + state-update event
                                                pre-commit: raw writes rejected outside transition()

Issue Number

Part of #6456 (step 2, transition half).

How to Test

uv run pytest tests/sdk/conversation/test_state_transition.py tests/sdk/conversation/local/test_status_transition_flows.py tests/cross/test_check_execution_status_writes.py -q
uv run python scripts/check_execution_status_writes.py

Real run against gpt-5.5 through the All-Hands proxy, with LOG_LEVEL=DEBUG and the state-change callback wired as EventService wires it. It covers confirmation mode, reject, a sync run, a new message after FINISHED, arun(), and pause then resume. Each step reaches its expected status, and the debug log shows every move with its reason:

idle -> running: run started
running -> waiting_for_confirmation: action needs user confirmation
waiting_for_confirmation -> idle: pending actions rejected
idle -> running: run started
running -> finished: agent replied with a message
finished -> idle: new user message after the run ended
idle -> running: run started                       (arun)
running -> finished: agent replied with a message
finished -> idle: new user message after the run ended
idle -> paused: pause requested
paused -> running: run started
running -> finished: agent replied with a message

With an invalid key, the auth-failure path goes running → error through transition() and raises ConversationRunError as before.

A first, stricter table broke real flows, which a second review reproduced. Each now has a test:

  • Sync run() with ACPAgent after a prompt timeout. On retry, the turn's FINISHED was ERROR → FINISHED. After three timeouts, stuck detection was ERROR → STUCK. Both made run() raise ConversationRunError.
  • condense(), or a direct agent.step(), on an errored conversation with a pending finish action or a hook-blocked message raised instead of finishing.
  • A base_state.json left at "deleting" by a foreign writer made the error handlers raise and mask the original error.

test_status_transition_flows.py covers the first two. test_moves_found_in_review_stay_allowed pins those moves plus the PAUSED → IDLE race in the ACP branch of arun().

Suites run one at a time, as CI runs them:

  • tests/sdk: 8142 passed.
  • tests/agent_server: 3008 passed. The five test_event_service.py tests that mock the state now give the mock a transition() that sets the status.
  • tests/cross: 713 passed, including test_conversation_parity.py and test_remote_conversation_live_server.py.
  • tests/tools: 1057 passed.

The remaining local failures don't touch the status code; none of their tracebacks mention transition or execution_status:

  • terminal heredoc/exit-code cases on macOS;
  • git tag under a global ssh tag-signing config;
  • canvas-extension backend and one MCP test, which already fail on main.

Video/Screenshots

N/A

Type

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

Notes

  • This is the first half of step 2. The RunController in EventService (one request_run() owning the permit, task and rerun intent behind idle/admitting/running/draining/closing) is the follow-up PR. It will build on transition().
  • Tests still set execution_status directly to arrange fixtures. The hook only scans package code.
  • Code outside this repo that assigns state.execution_status directly keeps working. Only SDK code is held to the table.

🐳 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:f535323-python

Run

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

All tags pushed for this build

ghcr.io/openhands/agent-server:f535323-golang-amd64
ghcr.io/openhands/agent-server:f535323b7a4678f78bffd97858407f5ae88f1954-golang-amd64
ghcr.io/openhands/agent-server:vasco-conversation-status-transition-golang-amd64
ghcr.io/openhands/agent-server:f535323-golang_tag_1.21-bookworm-amd64
ghcr.io/openhands/agent-server:f535323-golang-arm64
ghcr.io/openhands/agent-server:f535323b7a4678f78bffd97858407f5ae88f1954-golang-arm64
ghcr.io/openhands/agent-server:vasco-conversation-status-transition-golang-arm64
ghcr.io/openhands/agent-server:f535323-golang_tag_1.21-bookworm-arm64
ghcr.io/openhands/agent-server:f535323-java-amd64
ghcr.io/openhands/agent-server:f535323b7a4678f78bffd97858407f5ae88f1954-java-amd64
ghcr.io/openhands/agent-server:vasco-conversation-status-transition-java-amd64
ghcr.io/openhands/agent-server:f535323-eclipse-temurin_tag_17-jdk-amd64
ghcr.io/openhands/agent-server:f535323-java-arm64
ghcr.io/openhands/agent-server:f535323b7a4678f78bffd97858407f5ae88f1954-java-arm64
ghcr.io/openhands/agent-server:vasco-conversation-status-transition-java-arm64
ghcr.io/openhands/agent-server:f535323-eclipse-temurin_tag_17-jdk-arm64
ghcr.io/openhands/agent-server:f535323-python-amd64
ghcr.io/openhands/agent-server:f535323b7a4678f78bffd97858407f5ae88f1954-python-amd64
ghcr.io/openhands/agent-server:vasco-conversation-status-transition-python-amd64
ghcr.io/openhands/agent-server:f535323-python-node-runtime-amd64
ghcr.io/openhands/agent-server:f535323-python-arm64
ghcr.io/openhands/agent-server:f535323b7a4678f78bffd97858407f5ae88f1954-python-arm64
ghcr.io/openhands/agent-server:vasco-conversation-status-transition-python-arm64
ghcr.io/openhands/agent-server:f535323-python-node-runtime-arm64
ghcr.io/openhands/agent-server:f535323-python-minimal-amd64
ghcr.io/openhands/agent-server:f535323b7a4678f78bffd97858407f5ae88f1954-python-minimal-amd64
ghcr.io/openhands/agent-server:vasco-conversation-status-transition-python-minimal-amd64
ghcr.io/openhands/agent-server:f535323-python-node-runtime-minimal-amd64
ghcr.io/openhands/agent-server:f535323-python-minimal-arm64
ghcr.io/openhands/agent-server:f535323b7a4678f78bffd97858407f5ae88f1954-python-minimal-arm64
ghcr.io/openhands/agent-server:vasco-conversation-status-transition-python-minimal-arm64
ghcr.io/openhands/agent-server:f535323-python-node-runtime-minimal-arm64
ghcr.io/openhands/agent-server:f535323-python-slim-amd64
ghcr.io/openhands/agent-server:f535323b7a4678f78bffd97858407f5ae88f1954-python-slim-amd64
ghcr.io/openhands/agent-server:vasco-conversation-status-transition-python-slim-amd64
ghcr.io/openhands/agent-server:f535323-python-node-runtime-slim-amd64
ghcr.io/openhands/agent-server:f535323-python-slim-arm64
ghcr.io/openhands/agent-server:f535323b7a4678f78bffd97858407f5ae88f1954-python-slim-arm64
ghcr.io/openhands/agent-server:vasco-conversation-status-transition-python-slim-arm64
ghcr.io/openhands/agent-server:f535323-python-node-runtime-slim-arm64
ghcr.io/openhands/agent-server:f535323-golang
ghcr.io/openhands/agent-server:f535323b7a4678f78bffd97858407f5ae88f1954-golang
ghcr.io/openhands/agent-server:vasco-conversation-status-transition-golang
ghcr.io/openhands/agent-server:f535323-golang_tag_1.21-bookworm
ghcr.io/openhands/agent-server:f535323-java
ghcr.io/openhands/agent-server:f535323b7a4678f78bffd97858407f5ae88f1954-java
ghcr.io/openhands/agent-server:vasco-conversation-status-transition-java
ghcr.io/openhands/agent-server:f535323-eclipse-temurin_tag_17-jdk
ghcr.io/openhands/agent-server:f535323-python-minimal
ghcr.io/openhands/agent-server:f535323b7a4678f78bffd97858407f5ae88f1954-python-minimal
ghcr.io/openhands/agent-server:vasco-conversation-status-transition-python-minimal
ghcr.io/openhands/agent-server:f535323-python-node-runtime-minimal
ghcr.io/openhands/agent-server:f535323-python-slim
ghcr.io/openhands/agent-server:f535323b7a4678f78bffd97858407f5ae88f1954-python-slim
ghcr.io/openhands/agent-server:vasco-conversation-status-transition-python-slim
ghcr.io/openhands/agent-server:f535323-python-node-runtime-slim
ghcr.io/openhands/agent-server:f535323-python
ghcr.io/openhands/agent-server:f535323b7a4678f78bffd97858407f5ae88f1954-python
ghcr.io/openhands/agent-server:vasco-conversation-status-transition-python
ghcr.io/openhands/agent-server:f535323-python-node-runtime

About Multi-Architecture Support

  • Each variant tag (e.g., f535323-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., f535323-python-amd64) are also available if needed

….transition

execution_status was assigned at 42 sites across LocalConversation, Agent,
ACPAgent, response dispatch and EventService, with no single place that
knew which moves are legal. ConversationState.transition(to, reason) now
checks the move against a status table, logs the reason at debug level and
assigns through the existing autosave hook, so the change is persisted and
published as a ConversationStateUpdateEvent as before.

The table keeps every move the code makes today (ERROR, PAUSED and RUNNING
from any live status; a pause landing mid-step followed by the step's
outcome) and rejects the rest, e.g. leaving DELETING or reaching FINISHED
from ERROR.

A pre-commit hook, scripts/check_execution_status_writes.py, rejects any
other execution_status assignment in package code. The five server-side
mirror writes (status index records, the webhook payload) carry a
"# status-write:" marker.

Part of #6456 (step 2, transition half).
@datadog-official

This comment has been minimized.

@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

REST API breakage checks (OpenAPI) — ✅ PASSED

Result: ✅ PASSED

Action log

@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Coverage

Coverage Report •
FileStmtsMissCoverMissing
openhands-agent-server/openhands/agent_server
   conversation_service.py128310092%190–191, 273, 294, 483–484, 650, 657–658, 759, 850, 902–903, 910, 943–944, 960, 992, 996, 1009, 1029, 1050–1051, 1060, 1129, 1139, 1164, 1170–1171, 1175–1176, 1184, 1211, 1217, 1311, 1317, 1322, 1328, 1336–1337, 1346–1349, 1358, 1371, 1389, 1426, 1430–1434, 1457, 1506, 1519, 1527, 1585–1586, 1590, 1804, 1882, 2007, 2010, 2017–2019, 2022–2023, 2029, 2039, 2043, 2072, 2081, 2140–2142, 2173, 2304, 2307, 2334, 2344, 2349–2352, 2366, 2377, 2389–2390, 2422, 2520, 2580, 2638, 2653–2654, 3060, 3113, 3116, 3129
   event_service.py112311090%165, 171–172, 305–306, 436, 440, 445, 472, 479, 514, 517–518, 522–523, 534, 540, 611–612, 618, 674–675, 796, 816, 845, 854, 878–879, 883, 931, 966, 970–971, 1006, 1013, 1019, 1233, 1263, 1266, 1344, 1362, 1376, 1547–1548, 1603, 1637, 1793–1796, 1800, 1843, 1847, 1854, 1868, 1882, 1906, 1953–1955, 2039, 2061, 2064–2065, 2090, 2096, 2098, 2114, 2116, 2123, 2131, 2133–2134, 2138, 2155, 2207, 2213, 2222–2223, 2230, 2245, 2256, 2297–2300, 2380–2381, 2383–2390, 2392–2393, 2403, 2414, 2430–2431, 2442, 2469, 2475, 2481, 2490–2491, 2513, 2523
openhands-sdk/openhands/sdk/agent
   acp_agent.py183716191%348–349, 498–499, 526, 564, 643, 648, 781, 808, 814, 899, 940, 1204–1206, 1263–1264, 1348, 1368, 1611–1612, 1662, 1664, 1668, 1672, 1695, 1721, 1724–1727, 1793–1794, 1799, 1815, 1823, 2088, 2202, 2214, 2227, 2295, 2298–2299, 2316–2317, 2333, 2483, 2488, 2538–2539, 2541, 2683, 2821–2824, 2829, 2973, 3072, 3098–3099, 3115–3116, 3397–3398, 3402–3404, 3407–3412, 3416–3418, 3422, 3426–3427, 3430–3431, 3434, 3775, 3790–3791, 3794–3796, 3804, 3808, 3812–3813, 3819–3820, 3832–3833, 3836, 3884, 3889–3891, 3895–3896, 3928, 3965–3966, 4017, 4245–4247, 4250–4251, 4311, 4495, 4503–4504, 4507, 4550–4551, 4554, 4562–4566, 4573, 4575, 4579, 4582, 4591–4595, 4602, 4638–4639, 4657–4660, 4663, 4667–4669, 4671, 4675–4676, 4901, 4903, 4938, 4941–4942, 5023–5024, 5038–5039, 5095–5096
   agent.py5173094%334, 490, 494, 848–849, 856–857, 990–991, 994, 996, 1015–1016, 1022, 1027, 1065–1066, 1073–1074, 1119, 1126, 1173–1174, 1459, 1556–1557, 1559, 1589, 1638, 1645
   response_dispatch.py88594%165, 219, 343–345
openhands-sdk/openhands/sdk/conversation
   state.py322698%325, 467–468, 477–479
openhands-sdk/openhands/sdk/conversation/impl
   local_conversation.py12317194%181, 395, 462, 494–497, 499, 755–756, 869, 1257–1258, 1263, 1278, 1280, 1351, 1455, 1481, 1615, 1620–1625, 1678, 1699–1701, 1750, 2158–2160, 2163–2164, 2172–2173, 2175–2176, 2180–2181, 2464, 2467–2468, 2685, 2722, 2726, 2730, 2751, 2803, 2807, 2841, 2848–2849, 2857, 2861–2862, 2866, 2873, 3181–3182, 3200–3201, 3234, 3446, 3450, 3471, 3522, 3529–3530
TOTAL55477872884% 

The first table rejected moves that real flows make, turning them into
ConversationRunError:

- sync run() with ACPAgent after a prompt timeout: the agent sets ERROR
  without raising and the loop retries, so the retried turn's FINISHED
  (and stuck detection's STUCK) follows ERROR;
- condense() or a direct agent.step() on an errored or stuck conversation
  with a pending finish action or a hook-blocked message writes FINISHED;
- pause() landing between the ACP branch's two lock sections makes the
  final-iteration IDLE follow PAUSED;
- a base_state.json left at DELETING made the exception handlers' ERROR
  and PAUSED writes raise and mask the original error.

The table now rejects only moves no code path makes (ERROR -> IDLE,
FINISHED -> STUCK, PAUSED -> STUCK) and gives DELETING, which is never set
on the state, no special case.

Part of #6456.

@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).

Scope: The change is entirely inside the Python SDK and Agent Server (conversation status lifecycle, a pre-commit guard, and tests), which this repository owns per AGENTS.md. Linked issue #6456 is open and carries ready-for-dev, so the product/architecture direction is present. Continuing with the technical review.

Verification performed on the current head (ba2daa1):

  • I traced every transition() call site against the _UNREACHED_MOVES table. The three rejected moves are genuinely unreachable: (1) ERROR -> IDLE - send_message() writes IDLE only from FINISHED/STUCK, reject_pending_actions() only from WAITING_FOR_CONFIRMATION, the sync loop's final-iteration IDLE write is guarded by FINISHED/WAITING_FOR_CONFIRMATION, and the async ACP loop breaks on ERROR/STUCK before its IDLE write; (2) FINISHED -> STUCK and (3) PAUSED -> STUCK - the stuck check runs after the loop's break on PAUSED/STUCK and after the FINISHED stop-hook branch, so _check_stuck_or_nudge() never sees those statuses; the async loop has no stuck check at all. ERROR and PAUSED stay reachable from every status, so the run loop's exception handlers can never themselves raise and mask the original error - verified for the LLMAuthenticationError handler, the generic except Exception handler, _emit_run_limit_error, the EventService backstop, and the ACP init-state error path.
  • The table deliberately allows ERROR -> FINISHED/STUCK (ACP prompt-timeout retry), PAUSED -> IDLE (pause landing mid-step), and DELETING -> ERROR (foreign base_state.json writer); each of these is pinned by test_moves_found_in_review_stay_allowed or test_status_transition_flows.py.
  • Ran locally: the PR's focused tests pass (28/28 in test_state_transition.py, test_status_transition_flows.py, test_check_execution_status_writes.py), scripts/check_execution_status_writes.py exits 0 over the tree, tests/agent_server/test_event_service.py passes (130, including the five tests adapted to _status_tracking_mock), and the local/remote conversation suites pass (414 + the lifecycle/pause/confirmation/auth-error files).
  • The five remaining raw writes in conversation_service.py update the server-side index record and the webhook payload - mirrors, not ConversationState - so the # status-write: markers are appropriate. The guard covers plain, annotated, augmented, chained, multiline, and setattr forms (unit-tested), and test_package_sources_pass gives full-tree CI coverage independent of which files a commit touches.
  • Backward compatibility is preserved: the table constrains only transition(); code outside the repo that assigns execution_status directly keeps working, and no OpenAPI/serialized-event surface changed (Check OpenAPI Schema passed).

CI note (not a finding): the sdk-tests job on this head fails on exactly one test, test_local_conversation_mcp.py::test_failing_mcp_server_keeps_the_other_servers_tools[invalid-entry] (pydantic ValidationError from coerce_mcp_config; 8158 passed, 1 failed). I reproduced the identical failure at the merge base 9f9bd44 (1 failed, 2 passed locally, 3/3 runs deterministic), and this PR touches neither mcp/config.py nor that test file. The param was removed on main in #6613 after this branch was cut. The failure is pre-existing and unrelated to this PR; all other checks on this head pass, including pre-commit with the new hook.

No material correctness, security, compatibility, or acceptance-criterion defect found on the current head.

✅ APPROVED

@VascoSch92
VascoSch92 marked this pull request as ready for review November 11, 2026 14:31
@VascoSch92
VascoSch92 requested a review from enyst November 11, 2026 14:31
@VascoSch92
VascoSch92 merged commit ccee494 into main Nov 12, 2026
49 of 50 checks passed
@VascoSch92
VascoSch92 deleted the vasco/conversation-status-transition branch November 12, 2026 10:30
@enyst enyst mentioned this pull request Nov 12, 2026
1 of 5 tasks
enyst pushed a commit that referenced this pull request Nov 13, 2026
#6620 added a lifecycle test that relies on run() stepping again after a
turn sets ERROR without raising, which is the resend this PR stops (#6645).
Keep the test's purpose (ERROR -> RUNNING -> FINISHED goes through
transition()) by finishing on the next run() instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013ArwwLKWzfpSTpRccheeWP
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.

2 participants