fix: Add cloud infrastructure for user message routing#213
Merged
Conversation
The previous fix (41d7b4f) added daemon-side support for remote users, but the cloud server was missing critical infrastructure: 1. Added PresenceRegistry service - shared module that tracks online users, accessible to both WebSocket handler and API routes 2. Added CloudMessageBus service - event-based pub/sub for delivering messages to cloud users via their WebSocket connections 3. Updated /api/daemons/agents to return allUsers from presence registry so daemons can discover cloud-connected users 4. Updated /api/daemons/message to handle daemonId='cloud' case, delivering messages to users via CloudMessageBus 5. Updated server.ts to register/unregister users with presence registry and subscribe to CloudMessageBus for WebSocket delivery Message flow for cloud users: Agent -> Daemon -> POST /api/daemons/message (daemonId=cloud) -> CloudMessageBus.sendToUser() -> Presence WebSocket -> User Dashboard 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add test coverage for the new cloud infrastructure: - PresenceRegistry tests (17 tests): - User registration and unregistration - Last seen updates - Online status checks - getOnlineUsersForDiscovery() RemoteAgent format - CloudMessageBus tests (6 tests): - Event emission for user messages - Metadata inclusion - Multiple subscribers - Independent user message delivery 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
🤖 My Senior Dev — Analysis Complete👤 For @khaliqgant📁 Expert in View your contributor analytics → 📊 7 files reviewed • 3 high risk • 2 need attention 🚨 High Risk:
🚀 Open Interactive Review →The full interface unlocks features not available in GitHub:
💬 Chat here: 📖 View all 12 personas & slash commandsYou can interact with me by mentioning In PR comments or on any line of code:
Slash commands:
AI Personas (mention to get their perspective):
For the best experience, view this PR on myseniordev.com — includes AI chat, file annotations, and interactive reviews. |
khaliqgant
pushed a commit
that referenced
this pull request
Jan 18, 2026
Records completed work on cross-machine user message routing. - Added cloud infrastructure (PresenceRegistry, CloudMessageBus) - Created PR #213 with 23 comprehensive tests - Identified as missing feature (not regression) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
khaliqgant
pushed a commit
that referenced
this pull request
Jan 18, 2026
Records completed work on cross-machine user message routing. - Added cloud infrastructure (PresenceRegistry, CloudMessageBus) - Created PR #213 with 23 comprehensive tests - Identified as missing feature (not regression) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
khaliqgant
pushed a commit
that referenced
this pull request
Jan 18, 2026
Records completed work on cross-machine user message routing. - Added cloud infrastructure (PresenceRegistry, CloudMessageBus) - Created PR #213 with 23 comprehensive tests - Identified as missing feature (not regression) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
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
Completes the cross-machine user routing feature by adding missing cloud infrastructure. The previous daemon-side fix (PR #212, commit 41d7b4f) was correct but incomplete - the cloud server lacked the necessary components to actually discover and deliver messages to users.
Root Cause Analysis
Not a Regression - Missing Feature
Investigation via
git logandgit blamerevealed this is not a regression:The original cross-machine routing (commits ba37864, 37996c0) was designed exclusively for agent-to-agent communication. User routing was never implemented:
/api/daemons/agentsreturnedallAgentsbut neverallUsersWhy First Fix (41d7b4f) Didn't Work
The daemon-side code was correct:
isRemoteUser()methodallUsersfrom APIBut the cloud server never returned
allUsersbecause:onlineUsersMap was local to WebSocket handler in server.tsdaemonId: 'cloud'What This Fix Does
New Services
PresenceRegistry (
src/cloud/services/presence-registry.ts)getOnlineUsersForDiscovery()in RemoteAgent formatCloudMessageBus (
src/cloud/services/cloud-message-bus.ts)Updated Components
/api/daemons/agentsendpoint - Now returnsallUsersalongsideallAgents/api/daemons/messageendpoint - Special handling fortargetDaemonId === 'cloud'server.ts - Registers/unregisters users with presence registry, subscribes to message bus
Message Flow
Test Coverage
Added 23 new tests:
Files Changed
src/cloud/services/presence-registry.ts(new)src/cloud/services/cloud-message-bus.ts(new)src/cloud/services/presence-registry.test.ts(new)src/cloud/services/cloud-message-bus.test.ts(new)src/cloud/services/index.ts(exports)src/cloud/api/daemons.ts(allUsers + cloud routing)src/cloud/server.ts(presence registry + message bus)Test Plan
🤖 Generated with Claude Code