Skip to content

fix(preview): keep previews alive across switches and cache browser links - #118

Merged
Leeeon233 merged 2 commits into
mainfrom
fix/keep-preview-alive-on-switch
Nov 20, 2026
Merged

Leeeon233 merged 2 commits into
mainfrom
fix/keep-preview-alive-on-switch

Conversation

@Leeeon233

Copy link
Copy Markdown
Collaborator

Summary

Keep remote previews (managed browser, iOS Simulator, and Android Emulator) alive in memory across conversation switches instead of tearing down or reconnecting on every switch, and optimize the browser preview UX with cached links, background verification, and on-demand regeneration.

Key Changes

  • In-memory preview retention (SessionPreviewCache):
    • Added bounded in-memory SessionPreviewCache (max 4 device previews, max 4 browser previews) retaining SessionSimulator, live SimulatorStreamView (isRetainedByCache = true), and BrowserPreviewController (WKWebView) across conversation switches.
    • Updated SimulatorPreview and SimulatorStreamView so detaching a cached stream from a view does not disconnect it, while still disconnecting when backgrounded and tearing down cleanly on explicit Stop, LRU eviction, workspace switch, logout (LodyApplication), or memory warning.
    • Capability URLs and preview tokens stay strictly in memory (never written to UserDefaults or disk).
  • Cloud runtime contract (sessionPreview):
    • Added status action, optional restart flag, and expiresAt / active response fields to packages/cloud-runtime, regenerated RuntimeContract.generated.swift, and updated runtime unit tests.
  • Browser preview link caching & UX (BrowserPreviewController, SessionController+Tools):
    • Reopening a cached browser preview opens immediately and runs a background status check with a right-side navigation spinner + non-blocking "Checking preview link…" banner while keeping the page visible.
    • Copying the link returns the cached valid URL immediately without waiting for an RPC.
    • When expired or confirmed inactive (active === false), shows an on-demand "Regenerate preview link" icon button that generates a new link (restart: true) and navigates back to the last browsed path, query, and fragment.
    • On check timeout / transient error, displays "Unable to confirm connection right now" while keeping the current page visible.

Testing

  • pnpm check (typecheck, contract:check, i18n:check, native:sources, licenses:check, format:check) — passed
  • pnpm test — 300/300 JS tests + 62/62 Python tests passed
  • xcrun --sdk iphonesimulator swiftc -parse on all modified/added Swift files — passed
  • swift build --package-path packages/lody-core — passed

…inks

- Add bounded in-memory SessionPreviewCache (max 4 device previews, max 4 browser previews) keeping SessionSimulator, live SimulatorStreamView, and BrowserPreviewController alive across conversation switches until explicit Stop, LRU eviction, workspace switch, logout, or memory warning.
- Update SimulatorPreview and SimulatorStreamView so cached streams survive view detachment while still disconnecting when backgrounded.
- Extend cloud-runtime sessionPreview contract with status action, restart flag, expiresAt, and active status, and regenerate RuntimeContract.generated.swift.
- Cache browser preview links in memory for instant open and instant copy, verify link liveness in the background while keeping WKWebView visible, show unconfirmed warning on transient check failure, and expose an on-demand regenerate button that restores the last browsed path, query, and fragment.

Model: gemini-4-neon-medium
…te server/simulator

- Extend cloud-runtime preview contract, runtime revokePreview, and sharing handlers with capability-gated stopProcess (previewStopProcess) and shutdownDevice (iosSimulatorShutdown / androidEmulatorShutdown), omitting optional flags on normal disconnect for backward compatibility.
- Expose numeric per-machine protocolCapabilities in Catalog and SessionCatalog.
- Add disconnect menu options in BrowserPreviewController, SimulatorController, and session action bar chips offering safe preview-only disconnect and destructive process/device termination when supported by the host CLI.
- Update Localizable.xcstrings (EN & zh-Hans) and add revoke stopProcess unit test.

Model: gemini-4-neon-medium
Leeeon233 added a commit to LodyAI/Lody that referenced this pull request Nov 20, 2026
…rminate server/simulator

- Add optional capability-gated `stopProcess` (Web preview) and `shutdownDevice` (iOS Simulator / Android Emulator) parameters to preview stop RPCs and advertise `previewStopProcess`, `iosSimulatorShutdown`, and `androidEmulatorShutdown` machine protocol capabilities.
- Implement guarded CLI termination for loopback dev-server processes (current UID only, excluding Lody ancestor PIDs) and exact-target simulator/emulator shutdown (never killing adb server or physical devices, and denying agent-initiated shutdown).
- Replace single disconnect buttons in Web/Desktop browser and device preview toolbars with `PreviewDisconnectButton` (safe default primary click + downward arrow menu offering preview-only vs. close-and-terminate/shutdown).
- Update `apps/mobile/ios` (LodyAI/lody-ios#118) and `apps/mobile/android` (LodyAI/lody-android#15) submodule pointers with matching disconnect menus and split buttons.

Model: gemini-4-neon-medium
@Leeeon233
Leeeon233 merged commit 5b42e15 into main Nov 20, 2026
2 of 5 checks passed
Leeeon233 added a commit to LodyAI/Lody that referenced this pull request Nov 20, 2026
- Merge origin/main into fix/keep-preview-alive-on-switch.
- Update apps/mobile/ios to 5b42e153 (LodyAI/lody-ios#118 on main).
- Update apps/mobile/android to a15bb94 (LodyAI/lody-android#15 on main).

Model: gemini-4-neon-medium
Leeeon233 added a commit to LodyAI/Lody that referenced this pull request Nov 20, 2026
…che browser links (#2973)

* fix(preview): keep previews alive across conversation switches and cache browser links

- Keep live Web/Desktop Managed Preview iframes and device preview viewers (iOS Simulator & Android Emulator) parked in bounded in-memory LRU caches across conversation switches, only tearing down on explicit Stop, eviction, logout, or non-ready transition.
- Keep opened SessionDetail sidebar tabs mounted while hidden so switching between sidebar tabs does not unmount preview panels.
- Cache remote browser preview connection and expiresAt in memory so reopening or copying a valid link is instant without blocking on resolving-machine or RPC.
- Verify cached browser links in the background while keeping the preview page visible, show an unconfirmed warning on timeout/transient failure, and expose an on-demand regenerate button in the address bar that recreates the link and restores the last browsed page.
- Update apps/mobile/ios (LodyAI/lody-ios#118) and apps/mobile/android (LodyAI/lody-android#15) submodule pointers with matching native mobile preview retention and link caching UX.

Model: gemini-4-neon-medium

* feat(preview): add split disconnect button to stop preview only or terminate server/simulator

- Add optional capability-gated `stopProcess` (Web preview) and `shutdownDevice` (iOS Simulator / Android Emulator) parameters to preview stop RPCs and advertise `previewStopProcess`, `iosSimulatorShutdown`, and `androidEmulatorShutdown` machine protocol capabilities.
- Implement guarded CLI termination for loopback dev-server processes (current UID only, excluding Lody ancestor PIDs) and exact-target simulator/emulator shutdown (never killing adb server or physical devices, and denying agent-initiated shutdown).
- Replace single disconnect buttons in Web/Desktop browser and device preview toolbars with `PreviewDisconnectButton` (safe default primary click + downward arrow menu offering preview-only vs. close-and-terminate/shutdown).
- Update `apps/mobile/ios` (LodyAI/lody-ios#118) and `apps/mobile/android` (LodyAI/lody-android#15) submodule pointers with matching disconnect menus and split buttons.

Model: gemini-4-neon-medium
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