Skip to content

feat(server): mark host offline within ~90s of sleep, not ~5min - #34

Merged
rbonestell merged 3 commits into
mainfrom
feat/faster-offline-detection
Jun 19, 2026
Merged

feat(server): mark host offline within ~90s of sleep, not ~5min#34
rbonestell merged 3 commits into
mainfrom
feat/faster-offline-detection

Conversation

@rbonestell

@rbonestell rbonestell commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

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 s
  • ALARM_INTERVAL_MS: 60 s → 30 s

90 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_request routing check lastMessageTime is within the idle window, so a stale (asleep) host shows offline immediately — a connecting mobile gets host_offline instead of a connect_request that 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_awake masking).

Testing

292 tests pass.

Companion PRs

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-io

snyk-io Bot commented Jun 19, 2026

Copy link
Copy Markdown

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Code Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@codecov-commenter

Copy link
Copy Markdown

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.
@rbonestell
rbonestell merged commit b0110f8 into main Jun 19, 2026
7 checks passed
@rbonestell
rbonestell deleted the feat/faster-offline-detection branch June 19, 2026 23:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants