Skip to content

fix(desktop): resync server event streams after Windows resumes from sleep - #65321

Merged
Hona merged 3 commits into
devfrom
resume-resync
Nov 21, 2026
Merged

Hona merged 3 commits into
devfrom
resume-resync

Conversation

@Hona

@Hona Hona commented Nov 21, 2026 •

Copy link
Copy Markdown
Member

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, then PBT_APMRESUMEAUTOMATIC) to the app's own power message window. Resume event driven, not a real sleep.

State Before After
App window after a driven resume event (not a real sleep) Before: the app window after the resume event After: the app window after the resume event

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

  • Bug fix

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 pageLifecycle handlers only react to online (which does not fire when Chromium never saw the network drop) and to a hidden page becoming visible again.

Main now listens for powerMonitor's resume and sends every app window a SystemResumed event. Each server connection then calls its existing connection.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 no onSystemResume, so the app's code path is a no-op there.

How did you verify your code works?

  • bun run typecheck:tsc in packages/desktop, bun typecheck in packages/app, bun run lint:changed origin/dev clean.
  • src/runtime/server/client.test.ts still passes (4 pass).
  • No new test: the resync behaviour belongs to packages/client and is covered there, and the change here is the wiring from powerMonitor to it.
  • On Windows, a driven resume event (posted power messages, not a real sleep): both builds reconnect, and the app window is unchanged (screenshots above).
  • Not tested: a real sleep and resume.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@Hona
Hona merged commit 32ae019 into dev Nov 21, 2026
10 checks passed
@Hona
Hona deleted the resume-resync branch November 21, 2026 10:40
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.

1 participant