Skip to content

Auto-recover active sessions after signaling disconnects#321

Merged
Jayian1890 merged 7 commits intodevfrom
capy/auto-recover-signaling-discover
Apr 24, 2026
Merged

Auto-recover active sessions after signaling disconnects#321
Jayian1890 merged 7 commits intodevfrom
capy/auto-recover-signaling-discover

Conversation

@zortos293
Copy link
Copy Markdown
Collaborator

@zortos293 zortos293 commented Apr 16, 2026

Description

Implement bounded automatic recovery for active sessions when signaling disconnects unexpectedly (e.g., after VPN toggle or network path changes). The renderer now attempts to reclaim and reconnect to the same session instead of immediately tearing down state.

Recovery Logic (src/renderer/src/App.tsx):

  • Attempt recovery only while stream state is in live launch phases (queue, setup, starting, connecting, streaming)
  • Execute up to 2 attempts with delays [0ms, 3000ms] before failing
  • Prefer matching the exact sessionId; fall back to matching the tracked appId if the same session is not found
  • If recovery fails, surface a user-facing launchError and reset to idle state
  • If recovery succeeds, normal offer/WebRTC handling resumes

Explicit Shutdown Guard:

  • Add SignalingRecoveryState ref to track recovery attempts and explicit shutdown intent
  • Call markExplicitSignalingShutdown in handleStopStream and handleDismissLaunchError to prevent automatic recovery after user-initiated stops
  • Reset recovery state on new game launches and navbar resume attempts

Shared Resume Helpers:

  • Extract resolveSessionClaimAppId to safely resolve the appId for session claims
  • Extract applyClaimedSessionAndConnect to centralize session application and signaling connection
  • Refactor claimAndConnectSession to use the extracted helpers

Signaling Event Handler:

  • Replace immediate teardown on disconnected events with a call to attemptSessionRecovery
  • Reset recovery counters on successful offer/streaming transition

Open OPE-063 OPE-063

@zortos293 zortos293 added the capy Generated by capy.ai label Apr 16, 2026 — with Capy AI
@zortos293 zortos293 added the Testing this issue/pr is being tested not ready for official build yet label Apr 16, 2026
@zortos293 zortos293 requested a review from Jayian1890 April 16, 2026 17:55
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
@zortos293
Copy link
Copy Markdown
Collaborator Author

@Jayian1890 if you can test this due to my sub ended so

@Kief5555 Kief5555 requested a review from Copilot April 20, 2026 16:04
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds bounded automatic recovery in the renderer (App.tsx) to reclaim and reconnect to an existing CloudMatch session after unexpected signaling disconnects (e.g., network/VPN changes), instead of immediately tearing down stream state.

Changes:

  • Introduces SignalingRecoveryState + helpers to track recovery attempts, delays, explicit shutdown intent, and appId context.
  • Implements attemptSessionRecovery flow that queries active sessions, re-claims the best candidate, and reconnects signaling with a limited retry budget.
  • Refactors session resume path by extracting resolveSessionClaimAppId and applyClaimedSessionAndConnect, and updates signaling event handling to use recovery on disconnected.

Comment thread opennow-stable/src/renderer/src/App.tsx
Comment on lines +2731 to +2745
} else if (event.type === "disconnected") {
console.warn("Signaling disconnected:", event.reason);
const recovered = await attemptSessionRecovery(event.reason).catch((error) => {
console.error("[Recovery] Signaling recovery failed:", error);
throw error;
});
if (!recovered) {
clientRef.current?.dispose();
clientRef.current = null;
setLaunchError({
stage: streamStatusToLoadingStage(streamStatusRef.current),
title: "Session Connection Lost",
description: "The connection to your running session was lost and could not be restored automatically. Try resuming it again from the app.",
});
resetLaunchRuntime({ keepLaunchError: true, keepStreamingContext: true });
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

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

The disconnected handler treats any attemptSessionRecovery result of false as a hard failure and surfaces a user-facing "Session Connection Lost" error. When attemptSessionRecovery returns false because explicitShutdown was set (user-initiated stop/dismiss) or the status is non-recoverable, this can incorrectly show an error UX for an intentional shutdown. Consider explicitly checking signalingRecoveryRef.current.explicitShutdown (or returning a distinct result) and early-returning without setting launchError in that case.

Copilot uses AI. Check for mistakes.
Comment thread opennow-stable/src/renderer/src/App.tsx
@Jayian1890
Copy link
Copy Markdown
Collaborator

Woah. How am I just seeing this. Lol. Yeah I'll test it.

…ng. Added generation state to manage recovery attempts and prevent stale session applications. Updated relevant functions to utilize generation checks for improved session handling.
…ed a helper function to determine if a claimed reconnect can proceed based on recovery generation and explicit shutdown status, enhancing session management and logging clarity.
…wn and non-recoverable stream statuses. This prevents unnecessary error handling and improves logging clarity during disconnect scenarios.
@Jayian1890 Jayian1890 self-assigned this Apr 24, 2026
Copy link
Copy Markdown
Collaborator

@Jayian1890 Jayian1890 left a comment

Choose a reason for hiding this comment

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

Successfully reconnects after changing wifi-networks, and also after toggling vpn.

…eamline recovery process. This change simplifies the connection flow during recovery attempts.
@Jayian1890 Jayian1890 merged commit 933cd9a into dev Apr 24, 2026
6 checks passed
Kief5555 added a commit that referenced this pull request Apr 25, 2026
* Fix Epic ownership guard and owned store glow (#334)

* Add Windows ARM64 release builds to pipeline (#340)

* Restore Windows ARM64 build artifacts in release pipeline

* fix(ci): match linux x64 artifact upload names

* Add 'Hide Server Selector' setting to skip free-tier queue modal

* Add Discord activity clearing functionality to rich presence (#349)

* Remove Game Hub media handling and refactor ControllerLibraryPage (#350)

* Remove Game Hub media handling from ControllerLibraryPage

* Refactor initial category index logic in ControllerLibraryPage for clarity

* Replace useEffect with useLayoutEffect for improved layout handling in ControllerLibraryPage

* Merge branch 'dev' into Jayian1890/controller-mode-patch-042226

* Add flake.nix again (#343)

* Fix Nix npm packaging

* Update

* Add nix instruction in README.md

* Delete symbolic Link

* change requested changes and add desktop items

* Update README.md

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update flake.nix

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update README.md

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Zortos <zortosdev@proton.me>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Kiefer <67562560+Kief5555@users.noreply.github.com>
Co-authored-by: Kiefer <kieferlin1001@gmail.com>
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Co-authored-by: DINEXXL <dinexxl@noreply.codeberg.org>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Switch macOS jobs to Blacksmith runners (#352)

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* feat: implement DiscordStatusMonitor to periodically sync RPC activity with active cloud gaming sessions

* feat: add initial sync handling in DiscordStatusMonitor to clear stale status on startup

* Fix Settings search to show relevant sections only (scope-aware filtering + sidebar UX polish) (#353)

* settings

* Update opennow-stable/src/renderer/src/components/SettingsPage.tsx

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* do capy's suggestion

Co-authored-by: Copilot <copilot@github.com>

* Auto-recover active sessions after signaling disconnects (#321)

* Implement bounded auto-recovery for active sessions after signaling disconnects

* Enhance signaling recovery mechanism by introducing generation tracking. Added generation state to manage recovery attempts and prevent stale session applications. Updated relevant functions to utilize generation checks for improved session handling.

* Refactor claimed session handling to improve recovery logic. Introduced a helper function to determine if a claimed reconnect can proceed based on recovery generation and explicit shutdown status, enhancing session management and logging clarity.

* Enhance signaling recovery logic by adding checks for explicit shutdown and non-recoverable stream statuses. This prevents unnecessary error handling and improves logging clarity during disconnect scenarios.

* Remove explicit shutdown check from signaling connection logic to streamline recovery process. This change simplifies the connection flow during recovery attempts.

---------

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Co-authored-by: Jared <jared@interlacedpixel.com>

* Add multi-account auth support with quick account switcher UI (#355)

* chore(release): prepare v0.3.3

* chore(release): prepare v0.3.4

* chore(release): prepare v1.3.5

* chore(release): prepare v0.3.5

* Update README.md to include TestFlight badge and iOS packaging target

* update AGENTS.md

* chore(release): prepare v0.3.6

* Add multi-account auth support with quick account switcher UI

* Add confirmation modal for account removal

* Fix account switch session validation during refresh (#4)

* Fix account switch session validation during refresh

* Fail switch-account refresh when user identity cannot be verified

* Update opennow-stable/src/main/gfn/auth.ts

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: PriyanshAg-1 <204138848+PriyanshAg-1@users.noreply.github.com>
Co-authored-by: priyanshrv1-oss <priyanshrv1@gmail.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Fix async session state in handleSwitchAccount - pass fresh session to refreshNavbarActiveSession to avoid stale auth token

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* Fix all remaining Copilot review issues: auth session null returns, error recovery state sync, ARIA semantics, SavedAccount type usage

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* fix: use menu ARIA roles in account dropdown and return getSession() after logout

Agent-Logs-Url: https://github.com/priyanshrv1-oss/OpenNOW1/sessions/bc9cb33e-8e97-4cf8-8986-2a9a584abddc

Co-authored-by: PriyanshAg-1 <204138848+PriyanshAg-1@users.noreply.github.com>

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* fix: add role=none to structural wrappers in menu and fix embedded line numbers in TS files

Agent-Logs-Url: https://github.com/priyanshrv1-oss/OpenNOW1/sessions/f707cd73-f431-41cf-96a8-c5e0c34ab939

Co-authored-by: PriyanshAg-1 <204138848+PriyanshAg-1@users.noreply.github.com>

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* Change logoutAll to logout in auth service

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* Update opennow-stable/src/main/gfn/auth.ts

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Fixed errors and improved session auth flows

* fix: improve session handling and error recovery in AuthService and App components; update Navbar accessibility roles

* Update opennow-stable/src/main/gfn/auth.ts

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* Resolve styling issues

* Resolve startup issues

---------

Co-authored-by: Zortos <zortosdev@proton.me>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Co-authored-by: PriyanshAg-1 <204138848+PriyanshAg-1@users.noreply.github.com>
Co-authored-by: priyanshrv1-oss <priyanshrv1@gmail.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Priyansh Agarwal <2k22.cse.32203@gmail.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>

* Improve stream pointer responsiveness under load. (#354)

* Improve stream pointer responsiveness under load.

Reduce mouse input hot-path overhead with residual delta accumulation, adaptive flush scheduling, cached scale conversion, and tuned raw-input filtering while adding diagnostics and targeted tests.

Made-with: Cursor

* Refactor mouse input handling in GfnWebRtcClient to maintain pending deltas until a non-zero packet is sent. This change prevents loss of quantized integer deltas during server scaling, improving responsiveness and accuracy of mouse movements.

* Enhance mouse input handling in GfnWebRtcClient by preventing re-arming of the mouse flush timer during teardown. This change ensures that the timer does not continue to operate after it has been cleared, improving resource management and stability.

* Refactor App and StreamView components to remove Esc hold release indicator functionality. This includes the removal of related state management, CSS styles, and UI elements, streamlining the codebase and improving maintainability.

* Refactor setActivity function in discordRpc.ts to update lastActivity only after successful RPC call, improving state management.

* Update flake.nix to reference the correct path for opennow-logo.png and enhance Discord RPC state management by introducing pendingActivity for improved activity handling.

* Enhance Discord RPC state management by consuming pendingActivity after processing, preventing reprocessing of failed attempts. Simplify activity title and start time assignment in DiscordStatusMonitor for improved clarity.

* Reset pendingActivity to null on setActivity failure in discordRpc.ts to ensure proper state management during error handling.

---------

Co-authored-by: Zortos <zortosdev@proton.me>
Co-authored-by: Jared Terrance <jared@interlacedpixel.com>
Co-authored-by: DINEXXL <105819287+DINEXXL@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Co-authored-by: DINEXXL <dinexxl@noreply.codeberg.org>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: zaloguj12 <patrik.ostafin@gmail.com>
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: PriyanshAg-1 <204138848+PriyanshAg-1@users.noreply.github.com>
Co-authored-by: priyanshrv1-oss <priyanshrv1@gmail.com>
Co-authored-by: Priyansh Agarwal <2k22.cse.32203@gmail.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

capy Generated by capy.ai Testing this issue/pr is being tested not ready for official build yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants