Repository navigation
fix(agent-server): release terminal run permits promptly - #5403
Conversation
Also isolate agent-server tests from user profile directories. The separate durable-persistence serialization issue remains tracked in #5402. Co-authored-by: openhands <openhands@all-hands.dev>
REST API breakage checks (OpenAPI) — ✅ PASSEDResult: ✅ PASSED |
Co-authored-by: openhands <openhands@all-hands.dev>
Coverage Report •
|
||||||||||||||||||||
|
all-hands-bot
left a comment
There was a problem hiding this comment.
This review was posted by an AI agent (OpenHands).
Review: fix(agent-server): release terminal run permits promptly
No material correctness, security, compatibility, or acceptance-criterion defect found on head f44dfb64. The change is in-scope for this repository (agent-server conversation lifecycle) and addresses the linked issue #5404 exactly.
Verification of the fix. _maybe_end_run_session() previously deferred release whenever self._run_task was not done. Since the run body calls settle() from its own finally, that condition was always true there, so the permit was only returned from the task's done callback — after wait_for_pending and the final state publish. The new task-identity check (asyncio.current_task() vs self._run_task) correctly distinguishes "this run" from a successor in a different task, so the permit is returned at terminal status while a genuine successor still defers release. I traced the surrounding paths: the non-async settle() done-callback always runs with no current task (current is None != task), so it will not end the session prematurely; the re-arm wait_for_capacity=True path reuses the live session slot (owner is not None) and never acquires a fresh token, so the new blocking branch does not deadlock; close()/teardown still drops pins and returns the permit exactly once; and the /goal and ACP supersede pin paths are unaffected. No double-release or leak was found.
Local tests. uv run pytest tests/agent_server/test_run_admission.py -q → 15 passed. The new test_terminal_status_implies_released_permit is a faithful deterministic regression: holding wait_for_pending open reproduces the exact window the issue describes.
Current-head checks. All CI checks on f44dfb64 pass except Validate PR description. That gate fails only because the HUMAN: section of the PR body is still the empty template placeholder ("Validate HUMAN note, PR template, and linked-issue readiness" → Add a short human-written note between HUMAN: and AGENT:). This is a PR-body hygiene requirement and part of the workflow's human-review handoff; it is not a code defect and does not affect the review verdict. The author is expected to add the human note before merge.
Out of scope / not a regression. The concurrency stress test still exceeds its wall-clock budget locally (test_concurrent_conversations_isolated_and_fast, concurrent 1.28s > budget 0.77s), but that is the synchronous durable-persistence serialization tracked separately as #5402, which the PR explicitly documents as unresolved and unmodified. agent-server-stress-tests passed on CI for this head. The linked issues #5404 and #5402 are both open with priority:low + ready-for-dev, and every acceptance criterion in #5404's triage is addressed by the diff and/or existing coverage.
✅ APPROVED
Generated by OpenHands AI agent on behalf of Graham Neubig. Co-authored-by: openhands <openhands@all-hands.dev>
HUMAN:
AGENT:
Why
A conversation could publish terminal
FINISHEDstatus before returning its global run permit. At exact capacity, another valid start could receive a spuriousConversationRunLimitExceeded. The run body was mistaken for its own active successor while executing itsfinallytail.Summary
Issue Number
Fixes #5404. The independent durable-persistence timing problem remains #5402.
How to Test
OH_PERSISTENCE_DIR=/tmp/sdk-stress-test-persistence uv run pytest tests/agent_server/test_run_admission.py -qResult after rebasing on current main:
15 passed in 2.40s.The complete stress timing test still reproduces #5402 (
0.7394s > 0.6466s); this PR does not hide that result by widening its budget or weakening durability.Video/Screenshots
Not applicable; this is a server concurrency lifecycle change. The deterministic test holds the asynchronous callback tail open after terminal status and directly verifies the semaphore permit is already returned.
Design Doc
Not included; implementation and regression are localized to run admission lifecycle.
Type
Notes
The HUMAN section remains intentionally untouched for a human reviewer. This PR does not alter the plain
>=constraints or dependency changes from #5391.This pull request was created by an AI agent (OpenHands) on behalf of the requesting user.
🐳 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
eclipse-temurin:17-jdkpython-node-runtimepython-node-runtimepython-node-runtimegolang: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:4ea9aef-pythonRun
All tags pushed for this build
About Multi-Architecture Support
4ea9aef-python) is a multi-arch manifest supporting both amd64 and arm644ea9aef-python-amd64) are also available if needed