Skip to content

[Bug]: separate agent-server processes can attach to the same conversations_path and resume active conversations #2966

Closed

Description

@neubig

Summary

Two agent-server processes that point at the same conversations_path can load the same persisted conversations, which creates split-brain behavior when one of those conversations is already active.

Why this matters

The default Config.conversations_path is workspace/conversations. In shared runtimes (for example an OpenHands Cloud sandbox), a second agent-server that starts with default settings can attach to the same persisted conversations as the server that is already backing the active session.

This is closely related to the scenario covered in #2943, where a second service resumes or attaches to a still-running conversation from the same persistence directory.

Expected behavior

A second agent-server should not be able to attach to or resume a conversation that is already owned by another live server process unless there is an explicit handoff.

Possible fixes

  • Acquire an exclusive startup lock for conversations_path.
  • Refuse startup when another live server is already using the same persistence directory.
  • Enforce conversation leases / ownership checks before resuming persisted active conversations.

Related context

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

Activity

  1. added
    bug
    and removed on Apr 26, 2026
  2. self-assigned this
    on May 11, 2026
  3. VascoSch92 commented on May 12, 2026

    @VascoSch92
    Member

    Hey @neubig

    I dug into this and I think the per-conversation lease already covers option (3) from your proposed fixes:

    • conversation_lease.py writes an owner_lease.json per conversation (TTL 45s, with owner instance ID, host, and PID).
    • In conversation_service.py, __aenter__ catches ConversationLeaseHeldError and skips active conversations owned by another live server, so a second agent-server pointed at the same conversations_path can't resume an already-running conversation.
    • There's a regression test for exactly this scenario: test_second_service_does_not_resume_active_running_conversation.

    That landed in #2943, and #3184 added host+PID-based stale-lease takeover so a restarted server isn't locked out by its own dead lease for the full TTL window.

    What's not done is options (1) and (2), i.e., a directory-level exclusive lock that refuses the second agent-server outright when another live process is already using the same conversations_path.

    Today the second server is allowed to start; it just can't attach to live-leased conversations.

    Do you think the per-conversation lease is enough to close this, or do you still want the stricter directory-level startup lock?

    Happy to open a follow-up PR for that.

  4. github-actions commented on Jun 22, 2026

    @github-actions
    Contributor

    This issue is stale because it has been open for 40 days with no activity. Remove the stale label or leave a comment, otherwise it will be closed in 10 days.

  5. VascoSch92 commented on Jul 6, 2026

    @VascoSch92
    Member

    Closing this as resolved. The split-brain risk described here — a second agent-server on the same conversations_path attaching to or resuming a conversation that's already owned by a live server — is now prevented by the per-conversation lease, which implements option (3) from the proposed fixes.

    Evidence on main:

    • conversation_lease.py — ConversationLease writes an owner_lease.json per conversation directory (TTL 45s, FileLock-guarded, recording owner instance id, host, pid, and a monotonic generation). claim() raises ConversationLeaseHeldError when a live owner still holds an unexpired lease.
    • event_service.py — EventService.start() calls self._lease.claim(), and every persisted write goes through guarded_write(), so a stale owner is fenced off with ConversationOwnershipLostError after a takeover.
    • conversation_service.py — the resume loop catches ConversationLeaseHeldError and skips the active conversation ("Skipping active conversation … owned by …"). A second server can't attach to a live-leased conversation.
    • Regression coverage: test_second_service_does_not_resume_active_running_conversation and test_stale_owner_cannot_append_after_lease_takeover both pass.

    Timeline:

    What this does not add is options (1)/(2): a directory-level exclusive startup lock that refuses the second agent-server outright when another live process is using the same conversations_path. Today the second server is still allowed to start; it just can't attach to any live-leased conversation. Since that fully satisfies the Expected behavior above, I'm treating the stricter directory-level lock as optional hardening rather than a blocker for this issue. Happy to open a dedicated follow-up if we decide we want it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions