Repository navigation
fix(desktop): resync server event streams after Windows resumes from sleep - #65321
Conversation
There was a problem hiding this comment.
Looks sound. I couldn't run the fix itself, since it needs the Windows desktop app and a real sleep and resume. Instead I traced the wiring from powerMonitor resume → emitIpcEvent to every main window (the same broadcast pattern as background-service.ts) → onSystemResume → connection.internal.resync. resync already does nothing unless the stream is started and connected, so it won't disturb streams that are reconnecting or stopped. The listener is registered after app.whenReady() and removed in a finalizer. The desktop and app type checks (typecheck:tsc) pass, and client.test.ts passes.
Public API unchanged: the new SystemResumed IPC event and onSystemResume platform hook are internal to the desktop app and its renderer.
No blocking concerns. A loopback sidecar will usually reconnect once after resume even though its socket survived; that is cheap and acceptable.
There was a problem hiding this comment.
The new commit only merges dev; the change itself is the same as the version I reviewed. After the merge, the desktop and app type checks (typecheck:tsc) pass and client.test.ts passes. I still couldn't run a real Windows sleep and resume. Public API unchanged. No new concerns.
# Conflicts: # packages/desktop/src/renderer/platform/index.ts
There was a problem hiding this comment.
The new commit only merges dev; the change itself is the same as the version I reviewed. After the merge, the desktop and app type checks (typecheck:tsc) pass and client.test.ts passes. A real Windows sleep and resume still hasn't been tested. Public API unchanged. No new concerns.
Screenshots
No visual change: the fix replaces the app's server event stream when Windows reports a resume, which the window does not show.
The stills are the app window on a dev build right after a resume event, driven by posting
WM_POWERBROADCAST(PBT_APMSUSPEND, thenPBT_APMRESUMEAUTOMATIC) to the app's own power message window. Resume event driven, not a real sleep.A driven suspend can't show the bug: Chromium takes the network down while it thinks the machine is suspended, so both builds see their stream fail and reconnect within a second of the resume. The case this fixes, a stream that still reads as connected after a real sleep, needs a real sleep: not captured.
Issue for this PR
No linked issue. Ported from the native Rune desktop build (
anomalyco/rune-desktop,apps/desktop/src/workspace/lifecycle/launch/network.rs), which wakes every server stream on resume.Type of change
What does this PR do?
When a Windows laptop wakes from sleep with the app window still visible, each server's event stream can still read as connected while its socket died during sleep. Nothing replaces it until the stream's idle watchdog fires: the renderer's
pageLifecyclehandlers only react toonline(which does not fire when Chromium never saw the network drop) and to a hidden page becoming visible again.Main now listens for
powerMonitor'sresumeand sends every app window aSystemResumedevent. Each server connection then calls its existingconnection.internal.resync(...), the same path that "Network connection restored" uses. A stream that is not connected ignores it, as it does today.The listener is installed only when
process.platform === "win32", so macOS and Linux are unchanged. The same wiring would help on macOS too; that is left for a separate change. The web platform has noonSystemResume, so the app's code path is a no-op there.How did you verify your code works?
bun run typecheck:tscinpackages/desktop,bun typecheckinpackages/app,bun run lint:changed origin/devclean.src/runtime/server/client.test.tsstill passes (4 pass).packages/clientand is covered there, and the change here is the wiring frompowerMonitorto it.Checklist