feat(server): mark host offline within ~90s of sleep, not ~5min - #34
Merged
Conversation
A sleeping/hibernated host is frozen, not disconnected — the OS sends no TCP FIN — so the server only learns it is gone via the idle sweep. Lower WS_IDLE_TIMEOUT_MS from 5min to 90s and ALARM_INTERVAL_MS from 60s to 30s so a stale 'host online' clears within ~90-120s. 90s is 3x the agent's 30s presence heartbeat, so a single dropped heartbeat can't flap a live host offline. Adds 89s/91s boundary tests to pin the threshold.
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
…xistence A sleeping host's WebSocket lingers until the idle sweep reaps it (up to ~90s), during which the host was reported online. Gate both the mobile presence snapshot and connect_request routing on lastMessageTime being within the idle window, so a stale host shows offline immediately instead of after the sweep. Complements the agent's proactive offline-on-sleep notification.
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
Makes the mobile app's view of host online/offline status accurate, in two layers.
1. Faster reaping of a silent host
A sleeping/hibernated host is frozen, not disconnected (no TCP FIN), so the server only learns it's gone via the idle sweep. Previously ~5 min; now:
WS_IDLE_TIMEOUT_MS: 5 min → 90 sALARM_INTERVAL_MS: 60 s → 30 s90 s is 3× the agent's 30 s presence heartbeat, so a single dropped heartbeat can't flap a live host offline. Added 89 s/91 s boundary tests.
2. Presence gated on heartbeat freshness, not just socket existence
Even within the 90 s window, a lingering-but-stale socket was reported online. Now both the mobile presence snapshot and
connect_requestrouting checklastMessageTimeis within the idle window, so a stale (asleep) host shows offline immediately — a connecting mobile getshost_offlineinstead of aconnect_requestthat never reaches a frozen host. Added two freshness tests.This is the server half of the accuracy work; the agent half (pmux-agent #53) proactively closes the connection before sleeping so offline is instant when it fires, with this freshness gate as the backstop for when that notice can't be sent (macOS hard sleep, or
keep_awakemasking).Testing
292 tests pass.
Companion PRs
agent restart, proactive offline-on-sleep)