Skip to content

fix(agent-server): release terminal run permits promptly - #5403

Merged
neubig merged 6 commits into
mainfrom
fix/stress-concurrency-stability
Oct 3, 2026
Merged

neubig merged 6 commits into
mainfrom
fix/stress-concurrency-stability

Conversation

@neubig

@neubig neubig commented Sep 30, 2026 •

Copy link
Copy Markdown
Member

HUMAN:


AGENT:

Why

A conversation could publish terminal FINISHED status before returning its global run permit. At exact capacity, another valid start could receive a spurious ConversationRunLimitExceeded. The run body was mistaken for its own active successor while executing its finally tail.

Summary

  • release a terminal run permit before its callback tail completes
  • preserve already-accepted re-arm continuations by waiting for capacity
  • isolate agent-server tests from real user profile/settings/skills directories
  • add a deterministic callback-tail regression test

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 -q

Result 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

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

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

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:4ea9aef-python

Run

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

All tags pushed for this build

ghcr.io/openhands/agent-server:4ea9aef-golang-amd64
ghcr.io/openhands/agent-server:4ea9aef242696d1c56d23bb6427a40e25425cb4c-golang-amd64
ghcr.io/openhands/agent-server:fix-stress-concurrency-stability-golang-amd64
ghcr.io/openhands/agent-server:4ea9aef-golang_tag_1.21-bookworm-amd64
ghcr.io/openhands/agent-server:4ea9aef-golang-arm64
ghcr.io/openhands/agent-server:4ea9aef242696d1c56d23bb6427a40e25425cb4c-golang-arm64
ghcr.io/openhands/agent-server:fix-stress-concurrency-stability-golang-arm64
ghcr.io/openhands/agent-server:4ea9aef-golang_tag_1.21-bookworm-arm64
ghcr.io/openhands/agent-server:4ea9aef-java-amd64
ghcr.io/openhands/agent-server:4ea9aef242696d1c56d23bb6427a40e25425cb4c-java-amd64
ghcr.io/openhands/agent-server:fix-stress-concurrency-stability-java-amd64
ghcr.io/openhands/agent-server:4ea9aef-eclipse-temurin_tag_17-jdk-amd64
ghcr.io/openhands/agent-server:4ea9aef-java-arm64
ghcr.io/openhands/agent-server:4ea9aef242696d1c56d23bb6427a40e25425cb4c-java-arm64
ghcr.io/openhands/agent-server:fix-stress-concurrency-stability-java-arm64
ghcr.io/openhands/agent-server:4ea9aef-eclipse-temurin_tag_17-jdk-arm64
ghcr.io/openhands/agent-server:4ea9aef-python-amd64
ghcr.io/openhands/agent-server:4ea9aef242696d1c56d23bb6427a40e25425cb4c-python-amd64
ghcr.io/openhands/agent-server:fix-stress-concurrency-stability-python-amd64
ghcr.io/openhands/agent-server:4ea9aef-python-node-runtime-amd64
ghcr.io/openhands/agent-server:4ea9aef-python-arm64
ghcr.io/openhands/agent-server:4ea9aef242696d1c56d23bb6427a40e25425cb4c-python-arm64
ghcr.io/openhands/agent-server:fix-stress-concurrency-stability-python-arm64
ghcr.io/openhands/agent-server:4ea9aef-python-node-runtime-arm64
ghcr.io/openhands/agent-server:4ea9aef-python-minimal-amd64
ghcr.io/openhands/agent-server:4ea9aef242696d1c56d23bb6427a40e25425cb4c-python-minimal-amd64
ghcr.io/openhands/agent-server:fix-stress-concurrency-stability-python-minimal-amd64
ghcr.io/openhands/agent-server:4ea9aef-python-node-runtime-minimal-amd64
ghcr.io/openhands/agent-server:4ea9aef-python-minimal-arm64
ghcr.io/openhands/agent-server:4ea9aef242696d1c56d23bb6427a40e25425cb4c-python-minimal-arm64
ghcr.io/openhands/agent-server:fix-stress-concurrency-stability-python-minimal-arm64
ghcr.io/openhands/agent-server:4ea9aef-python-node-runtime-minimal-arm64
ghcr.io/openhands/agent-server:4ea9aef-python-slim-amd64
ghcr.io/openhands/agent-server:4ea9aef242696d1c56d23bb6427a40e25425cb4c-python-slim-amd64
ghcr.io/openhands/agent-server:fix-stress-concurrency-stability-python-slim-amd64
ghcr.io/openhands/agent-server:4ea9aef-python-node-runtime-slim-amd64
ghcr.io/openhands/agent-server:4ea9aef-python-slim-arm64
ghcr.io/openhands/agent-server:4ea9aef242696d1c56d23bb6427a40e25425cb4c-python-slim-arm64
ghcr.io/openhands/agent-server:fix-stress-concurrency-stability-python-slim-arm64
ghcr.io/openhands/agent-server:4ea9aef-python-node-runtime-slim-arm64
ghcr.io/openhands/agent-server:4ea9aef-golang
ghcr.io/openhands/agent-server:4ea9aef242696d1c56d23bb6427a40e25425cb4c-golang
ghcr.io/openhands/agent-server:fix-stress-concurrency-stability-golang
ghcr.io/openhands/agent-server:4ea9aef-golang_tag_1.21-bookworm
ghcr.io/openhands/agent-server:4ea9aef-java
ghcr.io/openhands/agent-server:4ea9aef242696d1c56d23bb6427a40e25425cb4c-java
ghcr.io/openhands/agent-server:fix-stress-concurrency-stability-java
ghcr.io/openhands/agent-server:4ea9aef-eclipse-temurin_tag_17-jdk
ghcr.io/openhands/agent-server:4ea9aef-python-minimal
ghcr.io/openhands/agent-server:4ea9aef242696d1c56d23bb6427a40e25425cb4c-python-minimal
ghcr.io/openhands/agent-server:fix-stress-concurrency-stability-python-minimal
ghcr.io/openhands/agent-server:4ea9aef-python-node-runtime-minimal
ghcr.io/openhands/agent-server:4ea9aef-python-slim
ghcr.io/openhands/agent-server:4ea9aef242696d1c56d23bb6427a40e25425cb4c-python-slim
ghcr.io/openhands/agent-server:fix-stress-concurrency-stability-python-slim
ghcr.io/openhands/agent-server:4ea9aef-python-node-runtime-slim
ghcr.io/openhands/agent-server:4ea9aef-python
ghcr.io/openhands/agent-server:4ea9aef242696d1c56d23bb6427a40e25425cb4c-python
ghcr.io/openhands/agent-server:fix-stress-concurrency-stability-python
ghcr.io/openhands/agent-server:4ea9aef-python-node-runtime

About Multi-Architecture Support

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

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>
@github-actions

github-actions Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

REST API breakage checks (OpenAPI) — ✅ PASSED

Result: ✅ PASSED

Action log

Co-authored-by: openhands <openhands@all-hands.dev>
@neubig
neubig marked this pull request as draft September 30, 2026 15:33
@github-actions

github-actions Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Coverage

Coverage Report •
FileStmtsMissCoverMissing
openhands-agent-server/openhands/agent_server
   event_service.py103112188%154, 160–161, 280–281, 403, 407, 412, 439, 446, 480, 483–484, 488–489, 500, 506, 535–537, 540–541, 630–631, 752, 772, 799, 823–824, 828, 836, 839, 855, 889, 893–894, 928, 935, 941, 1001, 1004, 1019–1020, 1108, 1138, 1141, 1219, 1237, 1251, 1409–1410, 1453, 1490, 1630–1633, 1637, 1680, 1684, 1691, 1705, 1719, 1743, 1790–1792, 1876, 1901, 1907, 1909, 1919, 1921, 1928, 1936, 1938–1939, 1943, 1991, 1997, 2006–2007, 2013–2016, 2024–2027, 2076–2078, 2138–2139, 2141–2148, 2150–2151, 2160–2161, 2163–2164, 2171–2172, 2174–2175, 2186, 2211, 2217, 2223, 2232–2233, 2255, 2265
TOTAL473051906960% 

@github-actions

github-actions Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor
  ✅ **PR Artifacts Cleaned Up**

  The `.pr/` directory is no longer present.

@neubig
neubig marked this pull request as ready for review October 3, 2026 20:33
@neubig
neubig requested a review from all-hands-bot October 3, 2026 20:33

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

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

Release conversation run permit before publishing terminal status

4 participants