Skip to content

fix(sdk): avoid switch_llm deadlock when the run loop holds the state lock - #3486

Merged
VascoSch92 merged 2 commits into
mainfrom
vasco/fix-switch-llm-deadlock
Jun 3, 2026
Merged

VascoSch92 merged 2 commits into
mainfrom
vasco/fix-switch-llm-deadlock

Conversation

@VascoSch92

@VascoSch92 VascoSch92 commented Jun 3, 2026 •

Copy link
Copy Markdown
Member
  • A human has tested these changes.

Why

Invoking the switch_llm tool mid-conversation deadlocks the conversation
runtime: the call never completes, no SwitchLLMObservation is emitted, and the
conversation hangs in running. Regression introduced in v1.23.0 by async LLM
completion (#3284).

Root cause: run()/arun() hold the ConversationState FIFO lock across the
entire agent step, while tools execute on worker threads (run_in_executor).
switch_llm() — reached by the tool via switch_profile() — re-acquires that
same lock from the tool worker thread. The lock is reentrant per thread, so the
cross-thread re-acquire blocks: the run loop holds the lock and is blocked
awaiting the tool, while the tool is blocked awaiting the lock.

Confirmed in pure SDK (no agent-server) by driving arun() with a switch_llm
tool call — the worker thread parks in FIFOLock.acquire ← switch_llm
(with self._state:) while the event-loop thread holds _state across
await astep().

Summary

  • Track when an agent step is executing while the run loop holds the state lock
    (_step_holds_state_lock), set around step()/astep() in run()/arun().
  • switch_llm() reuses that already-held lock instead of re-acquiring it across
    threads. Standalone switch_llm()/switch_profile() calls (no active run)
    acquire the lock exactly as before.

Issue Number

Closes #3485

How to Test

New regression test test_switch_llm_tool_during_arun_does_not_deadlock drives
arun() with an agent that emits a switch_llm tool call, bounded by a timeout
so a regression fails fast instead of hanging:

  • Before the fix: 1 failed in 10.12s (deadlock → arun() cancelled →
    conversation paused, not finished).
  • After the fix: 1 passed in 0.10s (switch applied, conversation
    finished).
uv run pytest tests/sdk/conversation/test_switch_model.py tests/sdk/conversation/test_interrupt.py -q
# 34 passed

Broader sweep (run/arun, parallel tool execution, message-while-finishing):
182 passed. pre-commit (ruff, pycodestyle, pyright) passes on the changed
files.

Type

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

Agent Server images for this PR

• 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 amd64, arm64 nikolaik/python-nodejs:python3.13-nodejs22-slim 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:c8d3dfb-python

Run

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

All tags pushed for this build

ghcr.io/openhands/agent-server:c8d3dfb-golang-amd64
ghcr.io/openhands/agent-server:c8d3dfbca53f6b8c42eb1c8a40caa8cc0f4b2e22-golang-amd64
ghcr.io/openhands/agent-server:vasco-fix-switch-llm-deadlock-golang-amd64
ghcr.io/openhands/agent-server:c8d3dfb-golang_tag_1.21-bookworm-amd64
ghcr.io/openhands/agent-server:c8d3dfb-golang-arm64
ghcr.io/openhands/agent-server:c8d3dfbca53f6b8c42eb1c8a40caa8cc0f4b2e22-golang-arm64
ghcr.io/openhands/agent-server:vasco-fix-switch-llm-deadlock-golang-arm64
ghcr.io/openhands/agent-server:c8d3dfb-golang_tag_1.21-bookworm-arm64
ghcr.io/openhands/agent-server:c8d3dfb-java-amd64
ghcr.io/openhands/agent-server:c8d3dfbca53f6b8c42eb1c8a40caa8cc0f4b2e22-java-amd64
ghcr.io/openhands/agent-server:vasco-fix-switch-llm-deadlock-java-amd64
ghcr.io/openhands/agent-server:c8d3dfb-eclipse-temurin_tag_17-jdk-amd64
ghcr.io/openhands/agent-server:c8d3dfb-java-arm64
ghcr.io/openhands/agent-server:c8d3dfbca53f6b8c42eb1c8a40caa8cc0f4b2e22-java-arm64
ghcr.io/openhands/agent-server:vasco-fix-switch-llm-deadlock-java-arm64
ghcr.io/openhands/agent-server:c8d3dfb-eclipse-temurin_tag_17-jdk-arm64
ghcr.io/openhands/agent-server:c8d3dfb-python-amd64
ghcr.io/openhands/agent-server:c8d3dfbca53f6b8c42eb1c8a40caa8cc0f4b2e22-python-amd64
ghcr.io/openhands/agent-server:vasco-fix-switch-llm-deadlock-python-amd64
ghcr.io/openhands/agent-server:c8d3dfb-nikolaik_s_python-nodejs_tag_python3.13-nodejs22-slim-amd64
ghcr.io/openhands/agent-server:c8d3dfb-python-arm64
ghcr.io/openhands/agent-server:c8d3dfbca53f6b8c42eb1c8a40caa8cc0f4b2e22-python-arm64
ghcr.io/openhands/agent-server:vasco-fix-switch-llm-deadlock-python-arm64
ghcr.io/openhands/agent-server:c8d3dfb-nikolaik_s_python-nodejs_tag_python3.13-nodejs22-slim-arm64
ghcr.io/openhands/agent-server:c8d3dfb-golang
ghcr.io/openhands/agent-server:c8d3dfbca53f6b8c42eb1c8a40caa8cc0f4b2e22-golang
ghcr.io/openhands/agent-server:vasco-fix-switch-llm-deadlock-golang
ghcr.io/openhands/agent-server:c8d3dfb-golang_tag_1.21-bookworm
ghcr.io/openhands/agent-server:c8d3dfb-java
ghcr.io/openhands/agent-server:c8d3dfbca53f6b8c42eb1c8a40caa8cc0f4b2e22-java
ghcr.io/openhands/agent-server:vasco-fix-switch-llm-deadlock-java
ghcr.io/openhands/agent-server:c8d3dfb-eclipse-temurin_tag_17-jdk
ghcr.io/openhands/agent-server:c8d3dfb-python
ghcr.io/openhands/agent-server:c8d3dfbca53f6b8c42eb1c8a40caa8cc0f4b2e22-python
ghcr.io/openhands/agent-server:vasco-fix-switch-llm-deadlock-python
ghcr.io/openhands/agent-server:c8d3dfb-nikolaik_s_python-nodejs_tag_python3.13-nodejs22-slim

About Multi-Architecture Support

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

… lock (#3485)

run()/arun() hold the ConversationState lock across the agent step while
tools execute on worker threads. switch_llm() (reached by the switch_llm
tool via switch_profile) re-acquired that lock from the tool worker thread,
deadlocking against the run loop that already held it and was blocked
awaiting the tool. No SwitchLLMObservation was ever emitted and the
conversation hung in 'running' (regression from async LLM completion,
#3284).

Track when a step holds the state lock and have switch_llm() reuse it
instead of re-acquiring it across threads.

Closes #3485
@github-actions

github-actions Bot commented Jun 3, 2026 •

Copy link
Copy Markdown
Contributor

Python API breakage checks — ✅ PASSED

Result: ✅ PASSED

Action log

@github-actions

github-actions Bot commented Jun 3, 2026 •

Copy link
Copy Markdown
Contributor

REST API breakage checks (OpenAPI) — ✅ PASSED

Result: ✅ PASSED

Action log

all-hands-bot commented Jun 3, 2026 •

Copy link
Copy Markdown
Collaborator

✅ Review complete.

This review was performed through OpenHands Cloud Automation. You can log in and view the conversation here.

@github-actions

github-actions Bot commented Jun 3, 2026 •

Copy link
Copy Markdown
Contributor

Coverage

Coverage Report •
FileStmtsMissCoverMissing
openhands-sdk/openhands/sdk/conversation/impl
   local_conversation.py6815591%89, 335, 340, 487, 533, 602, 618, 694, 939–940, 1017–1018, 1021, 1134, 1137–1138, 1162, 1195–1196, 1199, 1205, 1286, 1289, 1293–1294, 1298–1299, 1302, 1309, 1334, 1338, 1341, 1360, 1412, 1415, 1454, 1462, 1466–1468, 1475, 1587, 1592, 1702, 1704, 1708–1709, 1720–1721, 1746, 1941, 1945, 2015, 2022–2023
TOTAL28889826471% 

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

✅ QA Report: PASS

Verified the SDK switch_llm tool no longer leaves an async conversation run stuck when invoked mid-arun() step.

Does this PR achieve its stated goal?

Yes. I reproduced the reported behavior on origin/main: the same SDK conversation scenario ended PAUSED instead of FINISHED and the process required an outer timeout (exit code 124). On the PR branch at 18a8e2f, the identical scenario completed normally with ConversationExecutionStatus.FINISHED and the active model switched to fast-model; standalone switch_profile() also continued to work.

Phase Result
Environment Setup ✅ uv run created the project .venv, installed workspace packages, and SDK imports succeeded.
CI Status 🟡 As checked during QA: 21 successful checks, 8 in progress, 1 older QA run cancelled, 2 skipped; no completed failing checks observed.
Functional Verification ✅ Base reproduced stuck/paused behavior; PR completed the same real SDK conversation flow successfully.
Functional Verification

Test 1: switch_llm tool during async conversation run

Step 1 — Reproduce / establish baseline (without the fix):
Checked out origin/main at 6feb56a2 and ran a short SDK script that creates a Conversation, sends a user message, and calls conversation.arun() with a scripted assistant response containing both switch_llm and finish tool calls:

git checkout origin/main
timeout 8s env HOME=/tmp/ohqa_home_base OPENHANDS_SUPPRESS_BANNER=1 \
  uv run python /tmp/qa_switch_llm_deadlock.py

Observed output excerpt:

HEAD is now at 6feb56a2 fix: prevent deep-merge when switching agent_kind settings variant (#3483)
[Profile Store] Loaded profile `fast` from /tmp/ohqa_home_base/.openhands/profiles/fast.json
arun() interrupted via task cancellation
Emitting synthetic error for orphaned action ... (switch_llm)
Emitting synthetic error for orphaned action ... (finish)
RESULT arun completed
STATUS ConversationExecutionStatus.PAUSED
EXPECTED_STATUS ConversationExecutionStatus.FINISHED
MODEL fast-model
EVENT_COUNT 7
[Command finished with exit code 124]

This confirms the bug exists on the base branch: the run does not reach FINISHED, orphaned tool actions are emitted after cancellation, and the outer timeout kills the still-stuck process.

Step 2 — Apply the PR's changes:
Checked out vasco/fix-switch-llm-deadlock at 18a8e2f.

Step 3 — Re-run with the fix in place:
Ran the same SDK script with a fresh isolated HOME/profile directory:

git checkout vasco/fix-switch-llm-deadlock
timeout 8s env HOME=/tmp/ohqa_home_pr2 OPENHANDS_SUPPRESS_BANNER=1 \
  uv run python /tmp/qa_switch_llm_deadlock.py

Observed output excerpt:

Switched to branch 'vasco/fix-switch-llm-deadlock'
18a8e2fb
[Profile Store] Loaded profile `fast` from /tmp/ohqa_home_pr2/.openhands/profiles/fast.json
RESULT arun completed
STATUS ConversationExecutionStatus.FINISHED
EXPECTED_STATUS ConversationExecutionStatus.FINISHED
MODEL fast-model
EVENT_COUNT 6
[Command finished with exit code 0]

This confirms the fix works for the PR's stated goal: the mid-step switch_llm tool call returns, the conversation finishes, and the active LLM profile changes to fast-model.

Test 2: Standalone profile switching still works

On the PR branch, I also exercised the related non-run-loop path by creating a Conversation and calling conversation.switch_profile('fast') directly:

HOME=/tmp/ohqa_home_standalone OPENHANDS_SUPPRESS_BANNER=1 uv run python - <<'EOF_PY'
# Script created a Conversation with default-model, saved profile fast-model,
# then called conversation.switch_profile('fast').
EOF_PY

Observed output excerpt:

BEFORE default-model
[Profile Store] Loaded profile `fast` from /tmp/ohqa_home_standalone/.openhands/profiles/fast.json
AFTER fast-model
[Command finished with exit code 0]

This shows the standalone switching path still behaves as expected outside an active run.

Issues Found

None.

This review was created by an AI agent (OpenHands) on behalf of the user.

@malhotra5 malhotra5 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

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

Solid fix for a genuine deadlock. The root cause analysis is accurate, the change is minimal and well-scoped, and the regression test is well-designed (deterministic tool sequence, timeout-bounded to fail fast on regressions, and verifies the model switch actually took effect). A couple of minor observations below. The synchronous run() path received the same guard (lines 1029-1035) but has no dedicated regression test — low priority since tools are async in practice, but worth tracking.

This review was generated by an AI agent (OpenHands) on behalf of the user through OpenHands Automation. View conversation

@enyst

enyst commented Jun 3, 2026

Copy link
Copy Markdown
Member

@OpenHands /codereview this PR. Post your feedback as a comment and mention me in it.

@openhands-ai

openhands-ai Bot commented Jun 3, 2026

Copy link
Copy Markdown

I'm on it! enyst can track my progress at all-hands.dev

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

@enyst reviewed.

🟡 Taste Rating: Acceptable

The core fix is small and aimed at the real deadlock: the run loop holds ConversationState while awaiting the agent step, while the switch_llm tool runs on a worker thread and previously tried to reacquire the same thread-reentrant lock. The new regression test exercises the real async tool path and I confirmed it locally:

uv run pytest tests/sdk/conversation/test_switch_model.py::test_switch_llm_tool_during_arun_does_not_deadlock -q
# 1 passed

[IMPROVEMENT OPPORTUNITIES]

  • [openhands-sdk/openhands/sdk/conversation/impl/local_conversation.py:771] Lock-scope precision: _step_holds_state_lock is conversation-wide, so any switch_llm() / switch_profile() caller during an active agent step bypasses _state, not only the switch_llm tool worker that is part of that step. That includes public callers such as the agent-server /{conversation_id}/switch_profile endpoint (conversation_router.py:357). The tested path is good, but this broadens the unlocked mutation path for self.agent / _state.agent. I’d prefer narrowing the bypass to the internal tool execution path (for example, a private helper or explicit internal flag used by SwitchLLMExecutor) so ordinary public switches during a run continue to serialize on the state lock rather than opportunistically skipping it.

[TESTING GAPS]

  • No blocking gap. The regression test is focused and would have caught the reported hang. If the lock bypass remains conversation-wide, a follow-up concurrency test for an external switch_profile() racing with arun() would make the intended behavior explicit.

[RISK ASSESSMENT]

  • [Overall PR] ⚠️ Risk Assessment: 🟡 MEDIUM

This touches the core conversation run loop, tool execution, and model switching behavior. The production bug is real and the fix is pragmatic, but the state-lock bypass is a concurrency-sensitive change. Per the repo-specific review policy, I’m leaving this as a COMMENT rather than an approval because run-loop/tool-execution changes can plausibly affect agent behavior/evals and I don’t see eval evidence linked here; a human maintainer should decide whether lightweight eval validation is needed.

VERDICT:
✅ Worth merging after maintainer review: the fix addresses the deadlock and the regression test is solid, but please consider tightening the lock-bypass scope or explicitly accepting the broader public-call behavior.

KEY INSIGHT:
The right abstraction is “this specific tool call is executing under the run loop’s already-held state lock,” not simply “some agent step is currently holding the lock.”


Improve this review? If any feedback above seems incorrect or irrelevant to this repository, you can teach the reviewer to do better:

  1. Add a .agents/skills/custom-codereview-guide.md file to your branch (or edit it if one already exists) with the /codereview trigger and the context the reviewer is missing (e.g., "Security concerns about X do not apply here because Y"). See the customization docs for the required frontmatter format.
  2. Re-request a review - the reviewer reads guidelines from the PR branch, so your changes take effect immediately.
  3. When your PR is merged, the guideline file goes through normal code review by repository maintainers.

Resolve with AI? Install the iterate skill in your agent and run /iterate to automatically drive this PR through CI, review, and QA until it's merge-ready.

Was this review helpful? React with 👍 or 👎 to give feedback.

This PR review comment was created by an AI agent (OpenHands) on behalf of @enyst.

@openhands-ai

openhands-ai Bot commented Jun 3, 2026

Copy link
Copy Markdown

Since my last summary, there were no additional code or repository changes.

  • ✅ The PR review request was fully addressed: I inspected the PR/issue context, reviewed the changed files, ran the targeted regression test, and posted a GitHub COMMENT review mentioning @enyst.
  • ✅ Instructions were followed faithfully: I did not modify code, did not push changes, and included an AI disclosure in the GitHub review comment.
  • ✅ The work remained concise: no extraneous tracked changes were made. A temporary review body file was removed after posting.
  • ✅ Verification completed: the targeted regression test passed (1 passed).

Address review feedback on #3486:

- Only skip the state lock when it is held by a different thread (the run
  loop). When the caller already owns it (a sync step, or the switch_profile
  /switch_llm endpoint reentering on the event-loop thread), acquire it
  normally — FIFOLock is reentrant for the owning thread. This keeps the
  bypass to the deadlock-prone cross-thread tool path instead of every
  switch during an active run.
- Reword comments: nullcontext() skips the lock, it does not 'reuse' it.
- Test: resolve tools via include_default_tools instead of register_tool so
  the global tool registry is not mutated across tests.
@VascoSch92
VascoSch92 requested a review from all-hands-bot June 3, 2026 16:15

all-hands-bot commented Jun 3, 2026 •

Copy link
Copy Markdown
Collaborator

✅ Review complete.

This review was performed through OpenHands Cloud Automation. You can log in and view the conversation here.

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

Code Review: fix(sdk): avoid switch_llm deadlock when the run loop holds the state lock

Summary

This is a well-targeted fix for a real and reproducible deadlock. The root cause analysis in the PR description is accurate: arun() holds the ConversationState FIFO lock across await astep(), tools execute on worker threads via run_in_executor, and switch_llm() previously attempted a cross-thread re-acquisition of that same lock — causing a classic ABBA-style deadlock. The fix is minimal, focused, and ships with a deterministic regression test that fails fast on a regression.


Correctness Analysis

skip_lock guard condition:

skip_lock = self._step_holds_state_lock and not self._state.owned()

This two-part condition is correct:

  • _step_holds_state_lock ensures the bypass only applies when the run loop is actively executing a step (not during standalone switch_llm() calls, such as from the /switch_profile endpoint outside of a run).
  • not self._state.owned() correctly distinguishes the deadlock scenario (cross-thread: event-loop holds lock, worker calls switch_llm) from the safe re-entrant scenario (same event-loop thread calling switch_llm while already owning the lock). This relies on FIFOLock.owned() returning True only for the current thread — the comment confirms this intent, and the lock's behavior is critical for correctness here.

Thread safety of _step_holds_state_lock:
The boolean flag is written by the event-loop thread and read by the tool worker thread without explicit synchronization. This is safe under CPython's GIL: simple boolean assignments and reads are atomic at the bytecode level, so the worker will see either True or False with no torn-read risk. The write at _step_holds_state_lock = True happens-before the await astep() call, which schedules the tool worker — so the worker always observes True when the flag matters.

Lock-bypass window:
When skip_lock=True, writes to self.agent and self._state.agent execute without the lock held. This is safe in the primary scenario because the run loop is parked awaiting the tool future — it cannot concurrently read self.agent while blocked on await astep(). However, as previously noted by @enyst, the flag is conversation-wide: if a concurrent external caller (e.g., the agent-server switch_profile endpoint) invokes switch_llm() while a step is in progress, it will also skip the lock. The risk is narrow in practice (the flag is only True during the step interval, not across the full run loop), but the bypass is broader than strictly necessary for the fix.

Synchronous run() path:
The run() path correctly receives the same guard. In the synchronous case, step() executes on the calling thread which already holds _state, so re-entrant lock acquisition is handled by FIFOLock's per-thread reentrancy and the owned() check. No deadlock risk exists in practice (synchronous tool execution would not cross threads), but the defensive guard is harmless and keeps both paths consistent.


Test Quality

The regression test is well-designed:

  • Uses a deterministic tool sequence (switch_llm + finish in a single step) to exercise the exact deadlock path.
  • Bounded by asyncio.wait_for(..., timeout=10) so a regression surfaces as a fast failure rather than a hung suite.
  • Verifies both liveness (execution_status == FINISHED) and correctness (agent.llm.model == "fast-model").
  • Uses include_default_tools=["FinishTool", "SwitchLLMTool"] which correctly resolves from BUILT_IN_TOOL_CLASSES without polluting the module-level tool registry.

One gap (already noted in prior reviews): the synchronous run() path has no dedicated regression test. Low priority since sync tool execution does not cross threads, but a coverage follow-up would be complete.


Risk Assessment

🟡 MEDIUM — This touches the core conversation run loop and tool execution. The primary fix is correct and the regression test is solid. The residual risk is the broader-than-necessary lock-bypass scope for concurrent external switch_profile calls during an active step (flagged by @enyst). Whether that warrants a follow-up narrowing (e.g., using an internal execution context flag rather than a conversation-wide bool) is a maintainer judgment call.

Overall verdict: The fix addresses the production deadlock with minimal, well-reasoned changes. The regression test would catch a reintroduction. Ready to merge with maintainer awareness of the lock-scope caveat.

This review was generated by an AI agent (OpenHands) on behalf of the user through OpenHands Automation. View conversation

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

⚠️ QA Report: PASS WITH ISSUES

Functional QA confirms the PR fixes the async switch_llm deadlock and preserves related switch paths, but current GitHub CI is not green.

Does this PR achieve its stated goal?

Yes. I reproduced the reported SDK behavior on origin/main: an async conversation with a switch_llm tool call only returned after the 3s timeout cancellation and ended paused, not finished. On PR commit c8d3dfbca53f6b8c42eb1c8a40caa8cc0f4b2e22, the same user-facing SDK conversation completed in 0.01s, ended finished, and switched the model to fast-model.

Phase Result
Environment Setup ✅ make build completed successfully; no tests/linters were run.
CI Status ⚠️ sdk-tests and unresolved-review-threads are failing; QA/image build checks are still in progress and some artifact checks are skipped.
Functional Verification ✅ Before/after SDK script reproduced the old hang/cancel behavior and verified the PR completes async + sync switch flows.
Functional Verification

Test 1: Async switch_llm tool during arun()

Step 1 — Reproduce baseline without the fix:
Checked out origin/main, then ran OPENHANDS_SUPPRESS_BANNER=1 uv run python /tmp/qa_switch_llm_deadlock.py async-tool:

mode=async-tool
outcome=returned
duration_seconds=3.01
status=paused
model=fast-model
events=7

This confirms the bug: the call only returned after the 3s asyncio.wait_for cancellation path, and the conversation ended paused instead of finished.

Step 2 — Apply the PR's changes:
Checked out PR commit c8d3dfbca53f6b8c42eb1c8a40caa8cc0f4b2e22.

Step 3 — Re-run with the fix in place:
Ran the same command, OPENHANDS_SUPPRESS_BANNER=1 uv run python /tmp/qa_switch_llm_deadlock.py async-tool:

mode=async-tool
outcome=returned
duration_seconds=0.01
status=finished
model=fast-model
events=6

This confirms the fix works: the conversation no longer waits for cancellation, emits the expected completion path, finishes normally, and the LLM switch takes effect.

Test 2: Related PR switch paths

On PR commit c8d3dfbca53f6b8c42eb1c8a40caa8cc0f4b2e22, I also exercised the synchronous tool path and direct switch_llm() call that the PR says should remain supported.

Ran OPENHANDS_SUPPRESS_BANNER=1 uv run python /tmp/qa_switch_llm_deadlock.py sync-tool:

mode=sync-tool
outcome=returned
duration_seconds=0.01
status=finished
model=fast-model
events=6

Ran OPENHANDS_SUPPRESS_BANNER=1 uv run python /tmp/qa_switch_llm_deadlock.py direct:

mode=direct
status=idle
model=manual-model

These side checks show the synchronous run-loop switch path finishes quickly, and standalone switch_llm() still updates the conversation model while idle.

Issues Found

  • 🟠 CI status: GitHub currently reports Run tests / sdk-tests and Review Thread Gate / unresolved-review-threads as failing, with several Agent Server image build jobs still in progress. I did not rerun tests per QA instructions.

This review was created by an AI agent (OpenHands) on behalf of the user.

@VascoSch92
VascoSch92 merged commit fb0c40f into main Jun 3, 2026
46 of 48 checks passed
@VascoSch92
VascoSch92 deleted the vasco/fix-switch-llm-deadlock branch June 3, 2026 16:33
pengzhang-create pushed a commit to Pyromind-Dynamics/software-agent-sdk that referenced this pull request Aug 13, 2026
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.

switch_llm deadlocks the conversation runtime (regression in v1.23.0, async LLM completion #3284)

4 participants