fix: prevent Maintenance Sleep to keep WebSocket bridge alive#512
fix: prevent Maintenance Sleep to keep WebSocket bridge alive#512
Conversation
macOS can enter Maintenance Sleep even when NSActivityUserInitiated (0x00FFFFFF) is held, suspending network I/O and causing mobile clients to see connection refused for 5-10 minute windows. Adding NSActivityLatencyCritical (0xFF00000000) to the activity options prevents Maintenance Sleep and all deep-idle states, keeping WsBridgeServer reachable at all times. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
🔍 Multi-Model Code Review — PR #512fix: prevent Maintenance Sleep to keep WebSocket bridge alive CI StatusFindings🟡 MODERATE — Magic number cast when named enum members exist (2/3 reviewers)File: The comment states these flags are "not in .NET Catalyst bindings" — this is incorrect. Reflection of the installed The raw hex cast Suggested fix: Replace Discarded Findings (adversarial round)LatencyCritical scoped to full app lifetime (1/3 reviewers → 0/3 after adversarial): One reviewer suggested scoping Verified Correct ✅
Test CoverageNo new tests needed — this is a platform configuration change (single constant), not a logic change. The test plan in the PR description (manual lock-screen verification + Re-Review (after fix commit)Previous Finding Status
Re-Review ResultsAll 3 reviewers confirmed the fix is clean:
Updated Recommendation✅ Approve — the single finding is fully addressed. Clean, correct, well-commented change. |
Replace `(NSActivityOptions)0xFF00FFFFFF` with the explicit OR of the two named constants — `UserInitiated | LatencyCritical` — which are available in the .NET Catalyst bindings. Also removes the incorrect comment claiming the flags are absent from the bindings. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Fixed — replaced the magic number cast with |
Summary
NSActivityOptionsinAppDelegate.csfrom0x00FFFFFFto0xFF00FFFFFFby addingNSActivityLatencyCritical(0xFF00000000)NSActivityUserInitiatedalone does not prevent Maintenance Sleep — macOS can still enter deep idle and suspend network I/ONSActivityLatencyCritical, Maintenance Sleep is blocked entirely, keepingWsBridgeServerreachable while the Mac is locked or idleProblem
Mobile clients were seeing "connection refused" for 5–10 minute windows. Diagnosed via
pmset -g log: Mac entered Maintenance Sleep at 13:16:02 (triggered by a Spotlight indexing job), DarkWake at 13:31:39 — 15 minutes of network suspension with no app-level indication.Test plan
pmset -g logshows no Maintenance Sleep entries while the activity is held🤖 Generated with Claude Code