Skip to content

fix(desktop): keep sleep/wake reconnect on the primary backend (salvage of #74552) - #87872

Merged
teknium1 merged 1 commit into
mainfrom
salvage/74552-sleepwake-reconnect
Aug 16, 2026
Merged

fix(desktop): keep sleep/wake reconnect on the primary backend (salvage of #74552)#87872
teknium1 merged 1 commit into
mainfrom
salvage/74552-sleepwake-reconnect

Conversation

@teknium1

Copy link
Copy Markdown
Contributor

Summary

Salvages #74552 by @fangliquanflq: stops Desktop sleep/wake (and any primary WebSocket drop) from rewiring the window-owned primary chat socket to the currently active secondary profile's backend.

Fixes #74551.

Changes

  • apps/desktop/src/app/gateway/hooks/use-gateway-boot.ts
    • attemptReconnect now dials the window-owned primary backend with no-arg desktop.getConnection() (matching boot and softSwitch at the other two call sites), instead of desktop.getConnection($activeGatewayProfile.get()) which retargeted the primary socket at a secondary profile's backend after a live swap.
    • publish(conn) is gated on isActivePrimary(), so a background-profile view no longer inherits the primary descriptor (mode/baseUrl) and breaks image.attach / fs / media routing ([Bug] Desktop (a376ca0): image upload fails on remote profile — "image not found: <local_path>" #46651).
    • Secondary profiles keep reconnecting via the existing reconnectSecondaryGateways() registry path — reconnectNow() (wired to power-resume, online, and visibilitychange) already calls it before nudging the primary loop, so all wake signals funnel through the fixed path; no sibling site carries the wrong-profile lookup.
  • apps/desktop/src/app/gateway/hooks/use-gateway-boot.test.tsx
    • Regression test: activate secondary profile coder with its own backend, drop the primary socket, assert the reconnect never queries coder's descriptor, redials the primary wsUrl, and leaves the active secondary's $connection untouched.
    • Multi-profile-aware fakeDesktop() (per-profile connection descriptors) plus store resets in beforeEach/afterEach.

Cherry-picked onto current main with one test-file conflict (main's #71873 project-dir seeding test landed in the same region); resolved by keeping both tests. The fix required no adaptation to #87600's ensureGatewayAgent/mutex work — the reconnect loop's seam is unchanged and the new test passes against the post-#87600 store shape.

Validation

Check Result
npx vitest run src/app/gateway/hooks/use-gateway-boot.test.tsx 8/8 passed (7 existing + 1 new regression)
npm run check:lint (apps/desktop: tsc ×3 + eslint) 0 errors (112 pre-existing warnings, none new)
python3 scripts/audit_pr_attribution.py --fix all contributor emails mapped

Credit

Authored by @fangliquanflq — cherry-picked from #74552 with authorship preserved (fangliquanflq <fangliquan@qq.com>).

Infographic

Sleep-wake reconnect

@teknium1
teknium1 enabled auto-merge (rebase) August 16, 2026 17:54
@github-actions

github-actions Bot commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

૮ >ﻌ< ა ci review

running on 30f3d00 — fix(apps): dial primary sleep/wake reconnect at window backe


waiting for more jobs to start…

⚠️ Warnings

OSV vulnerability scan · View job

5 known vulnerabilities found in pinned dependencies.

How to fix:

Review the findings in the Security tab. Update the affected dependencies if a patched version is available.

@teknium1
teknium1 merged commit c23605e into main Aug 16, 2026
38 checks passed
@teknium1
teknium1 deleted the salvage/74552-sleepwake-reconnect branch August 16, 2026 18:00
@alt-glitch alt-glitch added type/bug Something isn't working P3 Low — cosmetic, nice to have comp/desktop Electron desktop app (apps/desktop/*) area/profiles Multi-profile isolation, HERMES_HOME scoping labels Aug 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/profiles Multi-profile isolation, HERMES_HOME scoping comp/desktop Electron desktop app (apps/desktop/*) P3 Low — cosmetic, nice to have type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Desktop sleep/wake reconnect wires the primary chat to the wrong profile backend

3 participants