GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — fix(browser): keep the pane's tabs when its window detaches by endynamoo · Pull Request #64742 · anomalyco/opencode Conversation
|
| if (reason) return close(state, reason, event.type === "client.closed" || reason === "browser.pane.missing") | ||
| // Only a session that no longer exists forgets its tabs. A window that navigated or detached its registration keeps | ||
| // them: they are saved per server and session, and the pane restores them when it registers again. | ||
| if (reason) return close(state, reason, reason === "browser.pane.missing") |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This is the actual fix. But client.closed also arrives when the user closes the session's shell tab (model.ts session.removed → stop() → connection.close()), not only on a session switch. After this change, only a missing session clears the saved tabs: a closed session tab's browser tabs come back if it is reopened, and saved tab entries pile up. Is that intended? If not, the window would need to say whether it is closing the tab or just detaching.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| if (event.type === "handshake.unsupported") return "browser.pane.unsupported" | ||
|
|
||
| if (event.type === "owner.closed" || event.type === "client.closed") return "browser.pane.registration.closed" | ||
| if (event.type === "owner.closed" || event.type === "client.closed") return "browser.pane.suspended" |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Changing this reason doesn't help the bug. connection.close() calls stop() (unsubscribes) before sending client.close, so the tabs sent with this event never reach the window. For owner.closed, the window has already navigated away or been destroyed. It also no longer matches ipc.ts, which documents suspended as idle eviction or the plugin going away, and window closes as registration.closed. I'd keep the old reason here.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| } | ||
| // A window that just mounted registers with an empty inventory; the tabs saved for this server and session are what | ||
| // it restores from. A window that already shows tabs keeps its own inventory, which is newer than the saved one. | ||
| const restore = event.restore?.tabs.length |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This isn't needed for the fix. After session.removed the attachment is deleted, so it registers again with restore: undefined and the saved tabs are already used on the base. An attachment that sends an explicitly empty inventory had already saved that empty state through save-restore. I'd drop this change so the fix stays minimal.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
A window that detached its binding - every session switch, and the remount a compaction causes - closed it and the pane deleted the tabs saved for that server and session. The strip came back empty and nothing restored it, while the pages stayed alive in main. A closed binding now keeps its saved tabs and releases only its pages; the tabs return when the window registers again, and a window that registers with an empty inventory restores them instead of letting the empty inventory win. The close reason stays `browser.pane.registration.closed`, so the window still backs off and retries, as `ipc.ts` documents. Saved tabs are still cleaned up: the window marks the close `forget` when the session itself is gone (`session.removed`), and main deletes the saved tabs then, as it already did for `browser.pane.missing`.
|
Thanks, both comments were right and the patch follows them.
On confirming the path: yes, a session switch reaches it, through the re-register rather than |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I couldn't verify this: it needs the desktop app's built-in browser, which this sandbox can't run. With the PR, bun test src/browser in packages/gui-plugins passes and tsc -b is clean. The public API is unchanged: the new optional forget field on the browser pane's close input is internal to the built-in plugin and backwards compatible.
The close reason is back to browser.pane.registration.closed, so the docs in ipc.ts and the window's retry hold again. The createConnecting change is still there.
The new forget flag comes from session.removed, and that probably brings the bug back (inline). session.removed doesn't mean the session was deleted. It fires when a session key leaves sessions.list(), the list of sessions owned by open shell tabs, and switching sessions inside a shell tab drops the old session's key. On that path main deletes the saved tabs again, as before this PR. Main already deletes them itself when a session is gone (browser.pane.missing), so the window may not need to send forget at all.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| sessions: Object.fromEntries(listed(state.sessions).filter((entry) => !sessionKeys.includes(entry[0]))), | ||
| }, | ||
| effects: gone.flatMap(([key, attachment]) => [...stop(key, attachment.phase), detach(key)]), | ||
| effects: gone.flatMap(([key, attachment]) => [...stop(key, attachment.phase, true), detach(key)]), |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
session.removed means the session's key left sessions.list() (sessions owned by open shell tabs), not that the session was deleted. host-apis.tsx builds those keys from each shell tab's sessionId/routeSessionId. Switching sessions inside a shell tab drops the old session's key, so this sends forget: true and main deletes the saved tabs: the bug from #64734 again. A deleted session is already handled by browser.pane.missing in main. Unless there is a signal that the session or its tab is really gone, I'd not forget here.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…loses A window that closes its binding - every session switch, and the remount a compaction causes - made the pane delete the tabs saved for that server and session. A session switch therefore emptied the strip for good: the saved row was gone, so the next registration had nothing to restore. Only a session that no longer exists deletes its saved tabs now, as main already does for `browser.pane.missing`. Everything else keeps them, so `registered` restores them from the saved inventory. The close reason stays `browser.pane.registration.closed`, so `ipc.ts` still describes every close and the window keeps its retry with backoff. Kept deliberately: closing a session's shell tab keeps that session's browser tabs, and they come back if it is reopened. Row cleanup stays with main, which deletes them when the session is gone.
|
Right on all three, and the patch is now the minimal one.
So the diff is now one condition in |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I couldn't verify this in the app: it needs the desktop app's built-in browser, which this sandbox can't run. Reading the code, it now removes only the deletion that caused the bug: a window closing its binding (on a session switch or a compaction) no longer deletes the session's saved browser tabs. With the PR, bun test src/browser in packages/gui-plugins passes and tsc -b is clean. The public API is unchanged.
The extra close reason, the createConnecting change and the forget flag are gone. The description says that keeping a closed session tab's browser tabs is deliberate.
One trade-off for maintainers to accept: main only deletes a session's saved tabs (browser.pane.missing) when that session is opened again and turns out to be gone. Rows for deleted sessions that are never reopened stay in storage.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
Review pane browser tabs are deleted when the session detaches (session switch, compaction)
There was an error while loading. Please reload this page.