You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: separate agent-server processes can attach to the same conversations_path and resume active conversations #2966
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.
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?
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.
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.
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.
Activity
VascoSch92 commentedon May 12, 2026
Hey @neubig
I dug into this and I think the per-conversation lease already covers option (3) from your proposed fixes:
conversation_lease.pywrites anowner_lease.jsonper conversation (TTL 45s, with owner instance ID, host, and PID).conversation_service.py,__aenter__catchesConversationLeaseHeldErrorand skips active conversations owned by another live server, so a secondagent-serverpointed at the sameconversations_pathcan't resume an already-running conversation.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-serveroutright when another live process is already using the sameconversations_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.
github-actions commentedon Jun 22, 2026
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.
VascoSch92 commentedon Jul 6, 2026
Closing this as resolved. The split-brain risk described here — a second
agent-serveron the sameconversations_pathattaching 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—ConversationLeasewrites anowner_lease.jsonper conversation directory (TTL 45s,FileLock-guarded, recording owner instance id, host, pid, and a monotonic generation).claim()raisesConversationLeaseHeldErrorwhen a live owner still holds an unexpired lease.event_service.py—EventService.start()callsself._lease.claim(), and every persisted write goes throughguarded_write(), so a stale owner is fenced off withConversationOwnershipLostErrorafter a takeover.conversation_service.py— the resume loop catchesConversationLeaseHeldErrorand skips the active conversation ("Skipping active conversation … owned by …"). A second server can't attach to a live-leased conversation.test_second_service_does_not_resume_active_running_conversationandtest_stale_owner_cannot_append_after_lease_takeoverboth pass.Timeline:
What this does not add is options (1)/(2): a directory-level exclusive startup lock that refuses the second
agent-serveroutright when another live process is using the sameconversations_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.