Skip to content

fix: clear stale preview URL from SQLite and prevent stale white screen on preview clear#2358

Open
dushyant-hada-90 wants to merge 1 commit into
AgentWrapper:mainfrom
dushyant-hada-90:fix/browser-clear-stale-preview
Open

fix: clear stale preview URL from SQLite and prevent stale white screen on preview clear#2358
dushyant-hada-90 wants to merge 1 commit into
AgentWrapper:mainfrom
dushyant-hada-90:fix/browser-clear-stale-preview

Conversation

@dushyant-hada-90

@dushyant-hada-90 dushyant-hada-90 commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Fixes #2352
Fixes #2347

Problem

When an agent deletes a workspace file that was previously auto-detected as a preview entry point (e.g. index.html), the preview poller would return ok=false from DiscoverEntry and silently skip the session. The preview_url in SQLite was never cleared, leaving a stale URL pointing at a file that no longer existed on disk.

This caused two visible problems:

  1. The embedded browser would render a 404 (or a stale cached page) with no explanation
  2. Opening a new session from the same project would auto-select the Browser tab due to the persisted non-empty preview_url, showing a blank browser instead of the Summary tab

Verified live against ao.db — all four active dummy sessions had stale preview_url values with missing workspace files:

dummy-14 | .../preview/files/index.html | revision 2 | index.html → MISSING
dummy-12 | .../preview/files/index.html | revision 3 | index.html → MISSING
dummy-10 | .../preview/files/index.html | revision 6 | index.html → MISSING
dummy-13 | .../preview/files/index.html | revision 3 | index.html → MISSING

Changes

Backend — internal/preview/poller.go
When DiscoverEntry returns ok=false, the poller now checks whether the session holds a workspace-scoped preview URL via the existing isWorkspacePreviewURL helper. If so, it calls SetPreview(ctx, sess.ID, "") to clear the stale URL and deletes the session from p.seen so the next poll re-evaluates it. Manually set dev server URLs (e.g. http://localhost:5173) are not affected.

Frontend — browser-view-host.ts
The clear() handler now hides and moves the WebContentsView offscreen before navigating to about:blank, preventing the white page from painting over the placeholder. clearHistory() is called after the navigate so the back button is correctly disabled after a clear.

Frontend — useBrowserView.ts
Added a hasUrlRef guard to measureAndSend that prevents the requestAnimationFrame callback from making the native view visible when there is no URL. Also tightened the positioning effect to require both navState.url and active before showing the view.

Frontend — SessionView.tsx
Added an effect that detects when previewUrl transitions from set to empty (with an advancing previewRevision) and automatically switches the inspector to the Summary tab. Per-revision tracking ensures this fires exactly once per clear event.

Testing

  • Existing tests in poller_test.go, useBrowserView.test.tsx, BrowserPanel.test.tsx, and browser-view-host.test.ts updated and passing
  • Manually reproduced: agent deletes index.html → browser panel clears → inspector switches to Summary tab automatically

@dushyant-hada-90 dushyant-hada-90 force-pushed the fix/browser-clear-stale-preview branch from 453e9a0 to 28a4588 Compare July 2, 2026 18:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant