fix: eliminate presence race by routing disconnect through AgentDO#106
Merged
khaliqgant merged 1 commit intomainfrom Mar 25, 2026
Merged
fix: eliminate presence race by routing disconnect through AgentDO#106khaliqgant merged 1 commit intomainfrom
khaliqgant merged 1 commit intomainfrom
Conversation
The HTTP disconnect route now sends a force-disconnect to AgentDO before hitting PresenceDO directly. Because the DO runtime serializes all handlers (fetch, webSocketMessage, webSocketClose), this guarantees the disconnect runs AFTER any in-flight WS ping heartbeat that would otherwise re-create the agent's presence entry. AgentDO /force-disconnect: 1. Closes all WebSockets (stops further pings) 2. Sends authoritative disconnect to PresenceDO The direct PresenceDO disconnect still follows as a safety net for cases where the AgentDO has no stored meta. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Preview deployed!
This preview shares the staging database and will be cleaned up when the PR is merged or closed. Run E2E testsnpm run e2e -- https://pr106-api.relaycast.dev --ciOpen observer dashboard |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
POST /v1/agents/disconnect) now sends aforce-disconnectto the AgentDO before hitting PresenceDO directly/force-disconnecthandler closes all WebSockets and sends the authoritative disconnect to PresenceDOProblem
When an agent disconnects, a WS ping heartbeat already in-flight on the AgentDO could arrive at PresenceDO after the HTTP disconnect deleted the agent entry, re-creating it. With no subsequent disconnect to clean it up, the agent would appear stuck "online" indefinitely.
Test plan
markOffline transitions agent to offlineno longer flakesmarkOnline brings agent back onlinestill works after reconnect🤖 Generated with Claude Code