fix(desktop): keep preview automation when leaving a thread #7200
Closedmaslinedwin(GitHub profile, opens in a new tab)wants to merge 6 commits into
main fromrefs/pull/7200/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
- apps/desktop/src/preview/Manager.ts lines 2944 to 2950OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -2919,3 +2939,12 @@29192939 webContentsId: wc.id,29202940 },29212941 () => wc.capturePage(),2942+ ).pipe(2943+ Effect.timeout(Duration.millis(AUTOMATION_CAPTURE_TIMEOUT_MS)),2944+ Effect.mapError((error) =>2945+ Cause.isTimeoutError(error)2946+ ? new PreviewOperationError({2947+ operation: "automationSnapshot.capturePage",2948+ tabId,2949+ webContentsId: wc.id,2950+ cause: new Error("UnknownVizError"),apps/desktop/src/preview/Manager.ts lines 2987 to 2989OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -2951,4 +2983,7 @@29512983 ) {29522984 const wc = yield* requireWebContents(tabId);29532985 return yield* withControlSession(tabId, wc, "snapshot", (send) =>2954- captureAutomationSnapshot(tabId, wc, send),2986+ captureAutomationSnapshot(tabId, wc, send).pipe(2987+ Effect.catchIf(2988+ (error): error is PreviewOperationError =>2989+ isPreviewOperationError(error) && isUnknownVizCause(error.cause),
- apps/desktop/src/preview/Manager.ts line 967OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -949,3 +960,8 @@949960 const onMessage: BrowserControlSession["onMessage"] = (_event, method, params) => {950961 runFork(handleDebuggerMessage(method, params));951962 };963+ const onDetach = () => {964+ // Chromium can drop the debugger when a guest is hidden offscreen.965+ // Forget the stale session so the next automation call reattaches;966+ // do not restore here or a hidden guest can loop attach/detach.967+ runFork(detachControlSession(wc.id));apps/desktop/src/preview/Manager.ts line 2992OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -2951,4 +2983,10 @@29512983 ) {29522984 const wc = yield* requireWebContents(tabId);29532985 return yield* withControlSession(tabId, wc, "snapshot", (send) =>2954- captureAutomationSnapshot(tabId, wc, send),2986+ captureAutomationSnapshot(tabId, wc, send).pipe(2987+ Effect.catchIf(2988+ (error): error is PreviewOperationError =>2989+ isPreviewOperationError(error) && isUnknownVizCause(error.cause),2990+ () =>2991+ Effect.gen(function* () {2992+ yield* detachControlSession(wc.id);
- apps/desktop/src/preview/Manager.ts line 2995OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -2951,4 +2983,13 @@29512983 ) {29522984 const wc = yield* requireWebContents(tabId);29532985 return yield* withControlSession(tabId, wc, "snapshot", (send) =>2954- captureAutomationSnapshot(tabId, wc, send),2986+ captureAutomationSnapshot(tabId, wc, send).pipe(2987+ Effect.catchIf(2988+ (error): error is PreviewOperationError =>2989+ isPreviewOperationError(error) && isUnknownVizCause(error.cause),2990+ () =>2991+ Effect.gen(function* () {2992+ yield* detachControlSession(wc.id);2993+ yield* restoreControlSession(tabId, wc);2994+ return yield* captureAutomationSnapshot(tabId, wc, send);2995+ }),apps/desktop/src/preview/Manager.ts line 2994OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -2951,4 +2983,12 @@29512983 ) {29522984 const wc = yield* requireWebContents(tabId);29532985 return yield* withControlSession(tabId, wc, "snapshot", (send) =>2954- captureAutomationSnapshot(tabId, wc, send),2986+ captureAutomationSnapshot(tabId, wc, send).pipe(2987+ Effect.catchIf(2988+ (error): error is PreviewOperationError =>2989+ isPreviewOperationError(error) && isUnknownVizCause(error.cause),2990+ () =>2991+ Effect.gen(function* () {2992+ yield* detachControlSession(wc.id);2993+ yield* restoreControlSession(tabId, wc);2994+ return yield* captureAutomationSnapshot(tabId, wc, send);apps/desktop/src/preview/Manager.ts line 967OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -949,3 +960,8 @@949960 const onMessage: BrowserControlSession["onMessage"] = (_event, method, params) => {950961 runFork(handleDebuggerMessage(method, params));951962 };963+ const onDetach = () => {964+ // Chromium can drop the debugger when a guest is hidden offscreen.965+ // Forget the stale session so the next automation call reattaches;966+ // do not restore here or a hidden guest can loop attach/detach.967+ runFork(detachControlSession(wc.id));
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:M
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- apps/desktop/src/preview/Manager.ts line 1004OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -974,0 +984,21 @@984+ Effect.gen(function* () {985+ const current = sessions.get(wc.id);986+ const owns = current === undefined || current === control;987+ yield* attempt(988+ { operation: "detachControlSession", webContentsId: wc.id },989+ () => {990+ wc.debugger.off("message", onMessage);991+ wc.debugger.off("detach", onDetach);992+ if (owns && wc.debugger.isAttached()) wc.debugger.detach();993+ },994+ ).pipe(Effect.ignore);995+ return [owns, sessions] as const;996+ }),997+ );998+ if (!ownsDebugger) return;999+ yield* Ref.update(diagnosticsRef, (diagnostics) =>1000+ replaceMap(diagnostics, (copy) => {1001+ copy.delete(wc.id);1002+ }),1003+ );1004+ }),apps/desktop/src/preview/Manager.ts line 3036Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -2952,3 +3006,13 @@29523006 const wc = yield* requireWebContents(tabId);29533007 return yield* withControlSession(tabId, wc, "snapshot", (send) =>29543008 captureAutomationSnapshot(tabId, wc, send),3009+ ).pipe(3010+ Effect.catchTags({3011+ PreviewCaptureUnavailableError: () =>3012+ Effect.gen(function* () {3013+ yield* detachControlSession(wc.id);3014+ return yield* withControlSession(tabId, wc, "snapshot", (send) =>3015+ captureAutomationSnapshot(tabId, wc, send),3016+ );3017+ }),3018+ }),
- apps/desktop/src/preview/Manager.ts line 1172Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -1122,3 +1166,7 @@11221166 });11231167 } else {11241168 const error = Option.getOrNull(Cause.findErrorOption(exit.cause));1169+ if (isPreviewCaptureUnavailableError(error)) {1170+ // Retryable compositor miss: drop this attempt so a later success1171+ // is the only snapshot row in the action timeline.1172+ yield* dropAction(tabId, actionEvent.id);
- apps/desktop/src/preview/Manager.ts line 1173OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -1122,3 +1166,8 @@11221166 });11231167 } else {11241168 const error = Option.getOrNull(Cause.findErrorOption(exit.cause));1169+ if (isPreviewCaptureUnavailableError(error)) {1170+ // Retryable compositor miss: drop this attempt so a later success1171+ // is the only snapshot row in the action timeline.1172+ yield* dropAction(tabId, actionEvent.id);1173+ return;
t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.


Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID:
200d78ec-f392-4dbf-964a-dc32ab309f1cYou can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share