Repository navigation
docs(sdk): document FIFOLock held across arun()'s await (Q4 of #3341) - #3400
Conversation
arun() holds the state lock (FIFOLock) across 'await astep'. That is safe only because every other state mutator is dispatched via run_in_executor onto a worker thread; FIFOLock is reentrant by OS thread id, so a state-mutating coroutine awaited on the event-loop thread would silently re-enter the lock and corrupt history. Make this load-bearing invariant explicit with a comment at the await site and a note on FIFOLock. Comment-only; no behavior change.
Python API breakage checks — ✅ PASSEDResult: ✅ PASSED |
REST API breakage checks (OpenAPI) — ✅ PASSEDResult: ✅ PASSED |
all-hands-bot
left a comment
There was a problem hiding this comment.
Taste Rating: 🟡 Acceptable. The warning is useful, but one sentence overstates the executor invariant; I left one inline comment.
[RISK ASSESSMENT] 🟢 LOW — documentation-only, no runtime behavior change.
VERDICT: Comment until the wording is clarified.
This review was generated by an AI agent (OpenHands) on behalf of the requester.
Was this automated review useful? React with 👍 or 👎 to this review to help us measure review quality.
Workflow run: https://github.com/OpenHands/software-agent-sdk/actions/runs/26503939638
all-hands-bot
left a comment
There was a problem hiding this comment.
✅ QA Report: PASS
Runtime SDK verification confirms the PR documents the FIFO lock/arun() async invariant without changing observed lock behavior.
Does this PR achieve its stated goal?
Yes. The stated goal was documentation-only: make the lock-across-await invariant and FIFOLock's thread-based reentrancy explicit. Running the SDK on main showed the underlying same-thread coroutine reentry behavior existed but both warnings were absent; running the same verification on 830ed290 showed both warnings present while imports and runtime lock behavior remained unchanged.
| Phase | Result |
|---|---|
| Environment Setup | ✅ make build completed successfully; SDK imports worked via uv run python. |
| CI Status | 🟡 At time checked: 15 successful, 12 in progress, 3 skipped; no failures observed. |
| Functional Verification | ✅ Before/after runtime introspection showed the new warnings are present and behavior is unchanged. |
Functional Verification
Test 1: Documentation warning appears for the actual SDK objects while lock behavior remains unchanged
Step 1 — Establish baseline without the PR:
Checked out origin/main and ran a Python script that imported FIFOLock and LocalConversation, demonstrated same-event-loop-thread reentry while a lock holder was suspended across await, and inspected the runtime doc/source text exposed by Python introspection:
git checkout origin/main >/tmp/qa_checkout_base.log 2>&1 && uv run python - <<'PY'
import asyncio, inspect, subprocess
from openhands.sdk.conversation.fifo_lock import FIFOLock
from openhands.sdk.conversation.impl.local_conversation import LocalConversation
# creates one holder coroutine and one contender coroutine sharing one FIFOLock
# then prints import status, observed lock events, and whether the new warnings exist
PYOutput excerpt:
commit=5c11fece
import_ok=FIFOLock,LocalConversation
runtime_reentry_events=holder acquired | contender acquired while holder awaited | holder releasing
fifolock_doc_asyncio_warning_present=False
arun_lock_across_await_warning_present=False
This confirms the invariant the PR describes is real: another coroutine on the same event-loop thread can acquire the thread-reentrant lock while the holder is suspended. It also establishes the baseline documentation gap: neither warning was present on main.
Step 2 — Apply the PR's changes:
Checked out docs/fifolock-await-invariant and reset to the PR commit 830ed2909e2cad7f4fa5e63efb040bf0e8f8b12f.
Step 3 — Re-run with the PR in place:
Ran the same SDK import/introspection/lock-behavior script:
git checkout docs/fifolock-await-invariant >/tmp/qa_checkout_pr.log 2>&1 && git reset --hard 830ed2909e2cad7f4fa5e63efb040bf0e8f8b12f >/tmp/qa_reset_pr.log 2>&1 && uv run python - <<'PY'
import asyncio, inspect, subprocess
from openhands.sdk.conversation.fifo_lock import FIFOLock
from openhands.sdk.conversation.impl.local_conversation import LocalConversation
# same script as baseline
PYOutput excerpt:
commit=830ed290
import_ok=FIFOLock,LocalConversation
runtime_reentry_events=holder acquired | contender acquired while holder awaited | holder releasing
fifolock_doc_asyncio_warning_present=True
arun_lock_across_await_warning_present=True
This shows the PR achieves its documentation goal: the FIFOLock asyncio/task warning and the arun() lock-across-await warning are now visible through the actual SDK source/doc objects. The identical runtime_reentry_events output also supports the PR's claim of no behavior change.
Issues Found
None.
This review was created by an AI agent (OpenHands) on behalf of the user.
Reword the comment above astep() to reflect that astep()'s own state mutations are intentional and part of the locked critical section. The run_in_executor requirement applies only to unrelated concurrent mutators, not to native async Agent.astep / ACPAgent.astep that mutate on the event-loop thread.
all-hands-bot
left a comment
There was a problem hiding this comment.
✅ QA Report: PASS
Verified the documentation-only change by importing the SDK from base and PR branches and exercising FIFOLock behavior; the PR documents the observed invariant without changing runtime behavior.
Does this PR achieve its stated goal?
Yes. The PR set out to make the FIFOLock/arun lock-across-await invariant explicit without changing behavior. On main, the imported SDK did not expose the new FIFOLock docstring/source warnings; on the PR branch, the same probes returned True for the new warnings. The runtime lock probe behaved identically before and after: same event-loop coroutines re-enter the lock while held, while a worker thread waits until release.
| Phase | Result |
|---|---|
| Environment Setup | ✅ make build completed and installed the repo packages with uv sync --dev. |
| CI Status | QA Changes by OpenHands); no failing checks observed. |
| Functional Verification | ✅ Imported and exercised SDK lock behavior on both base and PR branches. |
Functional Verification
Test 1: Documentation visibility and FIFOLock runtime invariant
Step 1 — Reproduce / establish baseline (without the fix):
Ran:
git checkout main >/tmp/qa_checkout_main.out 2>&1 && \
echo '--- BASE main ---' && \
uv run python /tmp/qa_fifolock_runtime.pyObserved relevant output:
--- BASE main ---
FIFOLock doc mentions OS thread id: False
FIFOLock doc mentions asyncio task: False
LocalConversation.arun source mentions state lock held across await: False
LocalConversation.arun source mentions run_in_executor: False
Same event-loop coroutine re-entered while held: True
Worker thread attempted acquire while held: True
Worker thread acquired before release: False
Worker thread acquired after release: True
Worker acquisition observed main release started: True
This establishes the baseline: the runtime behavior already matches the invariant, but the newly claimed documentation warnings are absent on main.
Step 2 — Apply the PR's changes:
Checked out docs/fifolock-await-invariant at c58f62ecac1d8876f6a087a9f59cada81df2451e.
Step 3 — Re-run with the fix in place:
Ran:
git checkout docs/fifolock-await-invariant >/tmp/qa_checkout_pr.out 2>&1 && \
echo '--- PR docs/fifolock-await-invariant ---' && \
uv run python /tmp/qa_fifolock_runtime.pyObserved relevant output:
--- PR docs/fifolock-await-invariant ---
FIFOLock doc mentions OS thread id: True
FIFOLock doc mentions asyncio task: True
LocalConversation.arun source mentions state lock held across await: True
LocalConversation.arun source mentions run_in_executor: True
Same event-loop coroutine re-entered while held: True
Worker thread attempted acquire while held: True
Worker thread acquired before release: False
Worker thread acquired after release: True
Worker acquisition observed main release started: True
This confirms the PR adds the intended documentation markers while preserving the same lock behavior observed on main.
Issues Found
None.
This QA review was created by an AI agent (OpenHands) on behalf of the user.
|
@OpenHands fix the pre-commit checks and update the branch |
|
I'm on it! VascoSch92 can track my progress at all-hands.dev |
Co-authored-by: openhands <openhands@all-hands.dev>
SummaryAddressed @VascoSch92's comment "fix the pre-commit checks and update the branch" on PR #3400. Checklist
ConcisenessChanges are minimal and on-scope:
No extraneous edits. |
|
✅ Review complete. This review was performed through OpenHands Cloud Automation. You can log in and view the conversation here. |
all-hands-bot
left a comment
There was a problem hiding this comment.
Taste Rating: 🟢 Good taste — Accurate, targeted documentation of a genuinely non-obvious concurrency invariant.
fifo_lock.py — FIFOLock docstring addition
The new Note is technically accurate: FIFOLock calls threading.get_ident() for reentrancy, so any two asyncio tasks on the same OS thread share the same owner identity and silently re-enter. The general rule ("Only hold it across an await when no other task on that thread can acquire it") is a correct, actionable contract for callers.
local_conversation.py — inline comment before await self.agent.astep()
The 12-line block does exactly what was needed:
- It explicitly exempts
astep()'s own mutations — including native asyncAgent.astep/ACPAgent.astepthat callon_eventon the event-loop thread — as intentional members of the critical section, which removes the ambiguity that a prior review raised about over-broad wording. - It narrows the invariant to unrelated state mutators, and correctly prescribes
run_in_executoras the dispatch mechanism for those. - The failure mode is clearly stated: a concurrent same-thread coroutine would silently re-enter and corrupt history.
The two places (docstring and call site) are coherent and complementary — reading one doesn't require the other.
Minor observations (non-blocking)
Convention with no enforcement: The prescription "Such unrelated mutators must be dispatched via run_in_executor onto a worker thread" is a design invariant enforced only by convention. A future contributor adding a new async state mutator may not find this comment. A follow-up could add a brief note in a CONTRIBUTING.md or an architectural doc that lists this as a known constraint on arun()'s execution model — but this is out of scope for a documentation-only PR and is not required to merge.
Documentation scope: The comment sits inside the else: branch that covers the non-ACP path only. The ACP path releases the state lock before its await astep() and re-acquires it after, so the invariant doesn't apply there. The placement is correct and appropriately scoped.
[RISK ASSESSMENT]
[Overall PR]
VERDICT:
✅ Worth merging — The change accurately documents a load-bearing invariant that was previously implicit, makes the failure mode greppable, and leaves no behavior difference.
KEY INSIGHT: Thread-id-keyed reentrancy and asyncio cooperative scheduling are an invisible trap; making the contract explicit at both the lock definition and the await site is the right way to guard it.
This review was generated by an AI agent (OpenHands) on behalf of the user through OpenHands Automation. View conversation
all-hands-bot
left a comment
There was a problem hiding this comment.
✅ QA Report: PASS
Verified the docs-only PR by comparing baseline vs PR documentation visibility and exercising the affected SDK lock/conversation behavior; the PR achieves its stated goal with no functional regression observed.
Does this PR achieve its stated goal?
Yes. On main, the FIFOLock pydoc output and greppable source warning text were absent; on the PR branch, pydoc exposes the new FIFOLock note and git grep finds both intended warnings. I also exercised FIFOLock and a minimal Conversation.arun() path on both branches; observed behavior was identical, matching the PR's “No behavior change” claim.
| Phase | Result |
|---|---|
| Environment Setup | ✅ make build completed and installed the uv workspace dependencies |
| CI Status | ✅ Existing checks are passing; only this qa-changes check was still in progress, and cleanup-on-approval was skipped |
| Functional Verification | ✅ Baseline/PR documentation delta verified; runtime smoke behavior unchanged |
Functional Verification
Test 1: Developer-facing documentation warning is newly visible
Step 1 — Reproduce / establish baseline (without the fix):
Checked out origin/main (58cfdcef) and ran:
OPENHANDS_SUPPRESS_BANNER=1 uv run python -m pydoc openhands.sdk.conversation.fifo_lock.FIFOLock | grep -F 'reentrancy is keyed by OS thread id' || echo 'pydoc note not found'
git grep -n -E 'state lock is held across this await|reentrancy is keyed by OS thread id' -- openhands-sdk/openhands/sdk/conversation/fifo_lock.py openhands-sdk/openhands/sdk/conversation/impl/local_conversation.py || echo 'warning text not found'Observed:
pydoc note not found
warning text not found
This establishes the baseline: the lock/task reentrancy warning and the arun() await-site warning were not available to a developer via pydoc/search before the PR.
Step 2 — Apply the PR's changes:
Checked out docs/fifolock-await-invariant at 47922a7e.
Step 3 — Re-run with the fix in place:
Ran the same commands and observed:
| Note: reentrancy is keyed by OS thread id, not by asyncio task, so the
openhands-sdk/openhands/sdk/conversation/fifo_lock.py:28: Note: reentrancy is keyed by OS thread id, not by asyncio task, so the
openhands-sdk/openhands/sdk/conversation/impl/local_conversation.py:1212: # The state lock is held across this await. Mutations
This confirms the stated documentation goal: the FIFOLock warning is visible through runtime documentation, and both intended comments are greppable at their target locations.
Test 2: FIFOLock behavior still matches the documented invariant
Step 1 — Reproduce / establish baseline (without the fix):
On origin/main, ran a short script using the real FIFOLock that: (1) acquires the lock in one coroutine, awaits another coroutine on the same event-loop thread, and has the inner coroutine acquire the lock; and (2) confirms a worker thread blocks while the main thread holds the lock.
OPENHANDS_SUPPRESS_BANNER=1 uv run python /tmp/fifolock_qa.pyObserved:
{
"same_event_loop_reentry_markers": [
"outer-acquired",
"inner-reentered-same-thread",
"outer-after-inner"
],
"worker_thread_serialization": {
"worker_blocked_until_main_thread_released": true,
"worker_acquired_after_release": true,
"worker_wait_seconds": 0.15
}
}This confirms the underlying behavior described by the new docs: same-thread coroutines can re-enter, while a different OS thread is serialized.
Step 2 — Apply the PR's changes:
Checked out docs/fifolock-await-invariant at 47922a7e.
Step 3 — Re-run with the fix in place:
Ran the same script and observed the same result:
{
"same_event_loop_reentry_markers": [
"outer-acquired",
"inner-reentered-same-thread",
"outer-after-inner"
],
"worker_thread_serialization": {
"worker_blocked_until_main_thread_released": true,
"worker_acquired_after_release": true,
"worker_wait_seconds": 0.15
}
}This supports the PR's “No behavior change” claim while confirming the documentation accurately describes the lock behavior.
Test 3: Minimal Conversation.arun() still completes
Step 1 — Reproduce / establish baseline (without the fix):
On origin/main, ran a minimal SDK conversation with a custom async agent whose astep() awaits briefly and marks the conversation finished:
OPENHANDS_SUPPRESS_BANNER=1 uv run python /tmp/conversation_arun_qa.pyObserved:
execution_status=finished
events=1
This establishes that the async conversation path completed successfully before the docs-only change.
Step 2 — Apply the PR's changes:
Checked out docs/fifolock-await-invariant at 47922a7e.
Step 3 — Re-run with the fix in place:
Ran the same smoke script and observed:
execution_status=finished
events=1
This confirms the changed arun() area still behaves the same for a real SDK conversation using an async astep().
Issues Found
None.
This review was created by an AI agent (OpenHands) on behalf of the user.
…nds#3341) (OpenHands#3400) Co-authored-by: openhands <openhands@all-hands.dev>
…nds#3341) (OpenHands#3400) Co-authored-by: openhands <openhands@all-hands.dev>
What
Q4 of #3341, documentation only.
arun()holds the state lock (FIFOLock) acrossawait self.agent.astep(...). Two comments make that implicit, load-bearing invariant explicit:awaitsite inarun()— why holding the lock across the await is safe, and the rule it depends on;FIFOLock— that reentrancy is keyed by OS thread id, not by asyncio task.Why
The lock-across-
awaitis safe today only because every other state mutator is dispatched viarun_in_executoronto a worker thread. SinceFIFOLockis thread-reentrant, a state-mutating coroutine awaited on the event-loop thread would silently re-enter the lock — no block, no error — and corrupt history. Nothing in the code recorded that rule; this turns it into a greppable warning so a future async mutator (or the Q5 refactor) doesn't trip over it.No behavior change.
Verification
ruff format --checkandruff checkcleanAgent 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-nodejs22-slimgolang: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:47922a7-pythonRun
All tags pushed for this build
About Multi-Architecture Support
47922a7-python) is a multi-arch manifest supporting both amd64 and arm6447922a7-python-amd64) are also available if needed