Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(remote-desktop): discard foreground leases on signaling loss
Dash Huange6e41820516f
diff --git a/apps/mobile/src/remote-desktop/RemoteDesktopScreen.tsx b/apps/mobile/src/remote-desktop/RemoteDesktopScreen.tsxindex fb117af819..2c09b1c0ba 100644--- a/apps/mobile/src/remote-desktop/RemoteDesktopScreen.tsx+++ b/apps/mobile/src/remote-desktop/RemoteDesktopScreen.tsx@@ -297,10 +297,6 @@ export function RemoteDesktopSession({const connecting = useRef(false);const ready = useRef(false);const streaming = useRef(false);- // A relay route can briefly disappear while this viewer's RTC stream lives.- // Keep only this lease for at most 8 s (host lease is 12 s); never reset links- // shared by other tasks or devices to recover a desktop viewer.- const transientFailureAt = useRef<number | null>(null);const mediaAttempt = useRef<string | null>(null);const receiveWindow = useRef({since: Date.now(),@@ -661,7 +657,6 @@ export function RemoteDesktopSession({timing.current?.("stopped");timing.current = null;generation.current++;- transientFailureAt.current = null;unlockFrame.current?.(false);unlockFrame.current = null;presentation.current = false;@@ -1267,7 +1262,6 @@ export function RemoteDesktopSession({// when a local transition timed out, retry a release or restore the// local bit so a held key cannot stay down behind a view-only phone.if (active.current !== current || presentation.current) return;- transientFailureAt.current = null;if (result.controlling === false) {// startInput can still be settling while this heartbeat was in// flight. Clearing a pending take-control here would leave later@@ -1286,13 +1280,6 @@ export function RemoteDesktopSession({}).catch((cause) => {if (active.current !== current) return;- if (- streaming.current &&- remoteDesktopErrorCode(cause) === "DEVICE_OFFLINE"- ) {- transientFailureAt.current ??= Date.now();- if (Date.now() - transientFailureAt.current < 8000) return;- }// A missing reply does not prove renewal failed; the next interval// retries within the lease. Explicit host revocation still stops us.if (@@ -1501,27 +1488,15 @@ export function RemoteDesktopSession({]);useEffect(() => {if (link.status !== "online") {- // A prepared native background lease survives signaling loss; ordinary- // inline streams retain the bounded transient-disconnect grace below.+ // Only a prepared background presentation can survive host signaling loss.+ // The host stops foreground leases, so discard ours before reconnecting.if (presentation.current ||(NativeRemoteDesktopView && pipPrepared.current))return;- if (!active.current || !streaming.current) {- pause();- return;- }- transientFailureAt.current ??= Date.now();- const lease = active.current;- const timer = setTimeout(- () => {- if (active.current === lease && linkRef.current.status !== "online")- pause();- },- Math.max(0, 8000 - (Date.now() - transientFailureAt.current)),- );- return () => clearTimeout(timer);+ pause();+ return;}if (!active.current) void connectRef.current();else restoreInlinePresentationRef.current();diff --git a/apps/mobile/src/remote-desktop/__tests__/screen.test.tsx b/apps/mobile/src/remote-desktop/__tests__/screen.test.tsxindex 9d7466dda9..d80a9d4f52 100644--- a/apps/mobile/src/remote-desktop/__tests__/screen.test.tsx+++ b/apps/mobile/src/remote-desktop/__tests__/screen.test.tsx@@ -363,8 +363,12 @@ const visibleInputHint = () =>const button = (key: string) =>host.querySelector<HTMLButtonElement>(`[aria-label="remoteDesktop.${key}"]`)!;beforeEach(async () => {- await AsyncStorage.removeItem("cindy.mobile.remote-desktop.show-mouse-buttons.v1").catch(() => undefined);- await AsyncStorage.removeItem("cindy.mobile.remote-desktop.audio.v1").catch(() => undefined);+ await AsyncStorage.removeItem(+ "cindy.mobile.remote-desktop.show-mouse-buttons.v1",+ ).catch(() => undefined);+ await AsyncStorage.removeItem("cindy.mobile.remote-desktop.audio.v1").catch(+ () => undefined,+ );(globalThis as any).IS_REACT_ACT_ENVIRONMENT = true;vi.clearAllMocks();fixture.beginBackgroundTransition.mockImplementation(@@ -3102,7 +3106,7 @@ describe("remote desktop controls", () => {expect(fixture.invoke).toHaveBeenCalledTimes(1);expect(requests().some((r) => r.op === "start")).toBe(false);});- it("keeps live video through a brief relay route interruption", async () => {+ it("replaces the foreground lease after even a brief relay interruption", async () => {await connect();act(() =>fixture.message!({@@ -3112,14 +3116,14 @@ describe("remote desktop controls", () => {fixture.status = "offline";act(() => root.render(<RemoteDesktopScreen />));await act(async () => vi.advanceTimersByTimeAsync(2000));- expect(requests().filter((r) => r.op === "stop")).toHaveLength(0);+ expect(requests().filter((r) => r.op === "stop")).toHaveLength(1);fixture.status = "online";await act(async () => root.render(<RemoteDesktopScreen />));await act(async () => vi.advanceTimersByTimeAsync(9000));- expect(requests().filter((r) => r.op === "start")).toHaveLength(1);- expect(requests().filter((r) => r.op === "stop")).toHaveLength(0);+ expect(requests().filter((r) => r.op === "start")).toHaveLength(2);+ expect(requests().filter((r) => r.op === "stop")).toHaveLength(1);});- it("bounds offline video grace and still obeys explicit host revocation", async () => {+ it("immediately releases foreground video when signaling goes offline", async () => {await connect();act(() =>fixture.message!({@@ -3128,11 +3132,10 @@ describe("remote desktop controls", () => {);fixture.status = "offline";act(() => root.render(<RemoteDesktopScreen />));- await act(async () => vi.advanceTimersByTimeAsync(8100));expect(requests().filter((r) => r.op === "stop")).toHaveLength(1);});it.each(["DEVICE_OFFLINE", "ACCESS_REVOKED"])(- "limits transient heartbeat handling to offline errors: %s",+ "discards the foreground lease on a definitive heartbeat error: %s",async (code) => {await connect();act(() =>@@ -3147,13 +3150,7 @@ describe("remote desktop controls", () => {: original(...args),);await act(async () => vi.advanceTimersByTimeAsync(3100));- expect(requests().filter((r) => r.op === "stop")).toHaveLength(- code === "DEVICE_OFFLINE" ? 0 : 1,- );- if (code === "DEVICE_OFFLINE") {- await act(async () => vi.advanceTimersByTimeAsync(9000));- expect(requests().some((r) => r.op === "stop")).toBe(true);- }+ expect(requests().filter((r) => r.op === "stop")).toHaveLength(1);},);it("renews again after a lost heartbeat reply without replacing the live lease", async () => {@@ -3643,7 +3640,9 @@ describe("remote desktop controls", () => {await connect();act(() => button("operations").click());expect(button("rightClick")).toBeNull();- expect(button("showMouseButtons").getAttribute("aria-checked")).toBe("false");+ expect(button("showMouseButtons").getAttribute("aria-checked")).toBe(+ "false",+ );await act(async () => button("showMouseButtons").click());expect(button("showMouseButtons").getAttribute("aria-checked")).toBe("true",diff --git a/docs/remote-desktop.md b/docs/remote-desktop.mdindex 08d97fb768..516e889bfb 100644--- a/docs/remote-desktop.md+++ b/docs/remote-desktop.md@@ -565,11 +565,12 @@ not merely successful delivery of the lock request. An installed session lockeris required. Real phone clipboard, lock and sound playback still need end-to-endvalidation with the running development build.-When the mobile viewer is already streaming, a transient relay `DEVICE_OFFLINE`-gets at most eight seconds to recover. A brief link-status transition does not-tear down a healthy RTC stream. Explicit revocation, local stop, backgrounding-and host lease expiry retain their existing behavior. Recovery is scoped to this-viewer; it never resets a shared relay or another peer's pending requests.+Foreground mobile viewers release their lease immediately when signaling goes+offline or heartbeat reports `DEVICE_OFFLINE`, matching the host's teardown.+Returning online starts a fresh lease instead of retaining a dead RTC peer.+Authorized background presentations retain their existing signaling-loss policy;+heartbeat timeouts alone do not prove lease revocation. Recovery is scoped to+this viewer; it never resets a shared relay or another peer's pending requests.Hyprland cursor overlay uses `ext-image-copy-capture-v1` on the video helper'sWayland connection. Bounded PNG cursor images and hotspots reuse the existing