Skip to content

fix(agent-server): recover conversations after PID reuse - #4897

Open
jstar0 wants to merge 1 commit into
OpenHands:mainfrom
jstar0:codex/4893-stale-run-recovery
Open

fix(agent-server): recover conversations after PID reuse#4897
jstar0 wants to merge 1 commit into
OpenHands:mainfrom
jstar0:codex/4893-stale-run-recovery

Conversation

@jstar0

@jstar0 jstar0 commented Sep 8, 2026

Copy link
Copy Markdown

HUMAN:

I tested the lease unit suite, the conversation-service restart cases including a persisted RUNNING state with a reused PID, and the event-service suite.

AGENT:

This pull request was prepared by an AI agent (OpenHands) on behalf of jstar0.

Why

When an agent-server restarts quickly, especially as PID 1 in a container, the replacement process can reuse the PID recorded in a conversation lease. The existing liveness check treats that PID as the original owner and skips the conversation until the lease TTL expires. A conversation left in RUNNING state is then unavailable through the normal resume API.

Summary

  • Record a process-local token in new conversation leases.
  • Treat a same-host, same-PID lease with a different process token as owned by a replaced process, allowing safe takeover and fencing by the existing generation mechanism.
  • Preserve same-process re-claim behavior, cross-host TTL protection, and legacy lease compatibility.
  • Add lease and conversation-service regressions for PID reuse and persisted RUNNING recovery.

Issue Number

Fixes #4893

How to Test

From the repository root:

uv run pytest -q tests/agent_server/test_conversation_lease.py tests/agent_server/test_conversation_service.py tests/agent_server/test_event_service.py
uv run pre-commit run --files openhands-agent-server/openhands/agent_server/conversation_lease.py tests/agent_server/test_conversation_lease.py tests/agent_server/test_conversation_service.py

Results:

  • Agent-server lease, conversation-service, and event-service tests: 237 passed
  • Ruff format, Ruff lint, pycodestyle, Pyright, import dependency rules, and tool subclass registration: passed

The new conversation-service regression persists a RUNNING conversation, simulates a still-valid lease from a previous process that reused the current PID, and verifies that startup takes over the lease and loads the conversation through the existing stale-run recovery path.

Video/Screenshots

Not applicable: this is an agent-server lease and conversation lifecycle fix.

Type

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

Notes

Lease files written by older versions without a process token retain the existing conservative behavior. Cross-host ownership still relies on lease expiration because local PID information cannot establish liveness on another host.

  • A human has tested these changes.

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.

agent-server: conversation stuck in execution_status=RUNNING after sandbox is paused/stopped mid-run (unresumable via API)

1 participant