From d5759e67a2f2183b911d16887107f9463aa44b93 Mon Sep 17 00:00:00 2001
From: Kelvin Amoaba <97001695+AmoabaKelvin@users.noreply.github.com>
Date: Tue, 10 Nov 2026 20:48:45 +0000
Subject: [PATCH 001/114] fix(browser): keep unsent page notes across restarts
and ask before closing a tab that has them (#40851)
* fix(browser): keep unsent page notes across restarts and ask before closing a tab that has them
Unsent browser notes lived only in the renderer store and hydration reset them, so a reload, restart or tab close lost them. Each saved browser page now carries its unsent notes, hydration restores them, and every close path (tab strip, keyboard, CLI, phone) asks before discarding them. A page script's window.close() can't discard them.
* fix(browser): keep tabs with unsent notes open on bulk close, like pinned tabs
---
.../browser-page-window-close.test.ts | 15 +++-
.../host-guest/browser-page-window-close.ts | 3 +-
.../layout/close/PinnedTabCloseDialog.tsx | 55 ++++++++-----
.../use-terminal-bulk-close-actions.ts | 8 +-
.../ipc-events-close-routing-test-harness.ts | 1 +
.../browser-request-ipc-bridge.owner.test.ts | 1 +
.../ipc-events/browser-request-ipc-bridge.ts | 44 +++--------
.../browser-tab-close-with-reply.ts | 52 +++++++++++++
.../ipc-events/session-tab-ipc-bridge.ts | 7 +-
src/renderer/src/i18n/locales/en.json | 5 +-
.../workspace-session-browser-tabs.ts | 24 ++++--
.../persistence/workspace-session-patch.ts | 9 ++-
.../persistence/workspace-session.ts | 5 +-
.../workspace/tabs/workspace-tab-commands.ts | 9 ++-
.../annotations/browser-page-annotation.ts | 13 ++++
...browser-annotation-session-restore.test.ts | 76 ++++++++++++++++++
.../hydration/browser-hydration-state.ts | 23 ++++--
.../browser-workspace-doc-location.test.ts | 1 +
.../tabs/closing/pinned-tab-close-guard.ts | 16 ++--
.../slices/tabs/pinned-tab-close-confirm.ts | 6 +-
.../workspace-layout-frame-store-view.ts | 3 +-
.../browser-page-annotation-schema.ts | 77 +++++++++++++++++++
.../languages/protected-copy-keys.json | 2 +
.../workspace-session-browser-schema.ts | 5 +-
.../workspace-session-state-types.ts | 6 +-
25 files changed, 374 insertions(+), 92 deletions(-)
create mode 100644 src/renderer/src/hooks/ipc-events/browser-tab-close-with-reply.ts
create mode 100644 src/renderer/src/store/slices/browser/hydration/browser-annotation-session-restore.test.ts
create mode 100644 src/shared/browser/annotations/browser-page-annotation-schema.ts
diff --git a/src/renderer/src/components/browser-pane/host-guest/browser-page-window-close.test.ts b/src/renderer/src/components/browser-pane/host-guest/browser-page-window-close.test.ts
index 257250b024a..7f10e7912b4 100644
--- a/src/renderer/src/components/browser-pane/host-guest/browser-page-window-close.test.ts
+++ b/src/renderer/src/components/browser-pane/host-guest/browser-page-window-close.test.ts
@@ -12,9 +12,15 @@ vi.mock('@/lib/workspace/tabs/workspace-tab-commands', () => ({
import { handleGuestWindowCloseMessage } from './browser-page-window-close'
import { BROWSER_GUEST_WINDOW_CLOSE_CHANNEL } from '../../../../../shared/browser-guest-window-close'
-function seedTab(pageId: string, isPinned = false, siblingPageIds: string[] = []): void {
+function seedTab(
+ pageId: string,
+ isPinned = false,
+ siblingPageIds: string[] = [],
+ browserAnnotationsByPageId: Record = {}
+): void {
storeState.value = {
closeBrowserPage: closeBrowserPageMock,
+ browserAnnotationsByPageId,
browserTabsByWorktree: { 'wt-1': [{ id: 'ws-1' }] },
browserPagesByWorkspace: { 'ws-1': [{ id: pageId }, ...siblingPageIds.map((id) => ({ id }))] },
unifiedTabsByWorktree: {
@@ -40,6 +46,13 @@ describe('window.close() from a browser page', () => {
expect(dispatchMock).not.toHaveBeenCalled()
})
+ it('never discards unsent notes', () => {
+ seedTab('page-n', false, [], { 'page-n': [{ id: 'note-1' }] })
+ closeFrom('page-n', { back: false, forward: false })
+ expect(dispatchMock).not.toHaveBeenCalled()
+ expect(closeBrowserPageMock).not.toHaveBeenCalled()
+ })
+
it('closes only the calling page when its Orca tab holds other pages', () => {
seedTab('page-e', false, ['page-sibling'])
closeFrom('page-e', { back: false, forward: false })
diff --git a/src/renderer/src/components/browser-pane/host-guest/browser-page-window-close.ts b/src/renderer/src/components/browser-pane/host-guest/browser-page-window-close.ts
index 452f602c2b1..5b37f60164e 100644
--- a/src/renderer/src/components/browser-pane/host-guest/browser-page-window-close.ts
+++ b/src/renderer/src/components/browser-pane/host-guest/browser-page-window-close.ts
@@ -32,7 +32,8 @@ export function handleGuestWindowCloseMessage(
const tab = (state.unifiedTabsByWorktree[owner.worktreeId] ?? []).find(
(candidate) => candidate.contentType === 'browser' && candidate.entityId === owner.workspaceId
)
- if (tab?.isPinned) {
+ // A script may not discard what the user pinned or left unsent; the page's notes are all it closes.
+ if (tab?.isPinned || (state.browserAnnotationsByPageId[pageId]?.length ?? 0) > 0) {
return
}
pagesOpenedByPage.delete(pageId)
diff --git a/src/renderer/src/components/terminal-pane/layout/close/PinnedTabCloseDialog.tsx b/src/renderer/src/components/terminal-pane/layout/close/PinnedTabCloseDialog.tsx
index 576c72f73ea..36b9280f7da 100644
--- a/src/renderer/src/components/terminal-pane/layout/close/PinnedTabCloseDialog.tsx
+++ b/src/renderer/src/components/terminal-pane/layout/close/PinnedTabCloseDialog.tsx
@@ -25,6 +25,7 @@ export default function PinnedTabCloseDialog(): React.JSX.Element {
const [previousRequest, setPreviousRequest] = useState(request)
const tabLabel = request?.tabLabel.trim()
+ const unsentNotes = request?.unsentNotes === true
// Reset new requests before paint without reviving a cancelled request’s checkbox state.
if (request !== previousRequest) {
@@ -53,16 +54,26 @@ export default function PinnedTabCloseDialog(): React.JSX.Element {
- {t(
- 'auto.components.terminal.pane.PinnedTabCloseDialog.6c190f295a',
- 'Close pinned tab?'
- )}
+ {unsentNotes
+ ? t(
+ 'auto.components.terminal.pane.PinnedTabCloseDialog.unsent_notes_title',
+ 'Discard unsent notes?'
+ )
+ : t(
+ 'auto.components.terminal.pane.PinnedTabCloseDialog.6c190f295a',
+ 'Close pinned tab?'
+ )}
- {t(
- 'auto.components.terminal.pane.PinnedTabCloseDialog.0d1963f4a6',
- 'This tab is pinned. Are you sure you want to close it?'
- )}
+ {unsentNotes
+ ? t(
+ 'auto.components.terminal.pane.PinnedTabCloseDialog.unsent_notes_description',
+ "This tab has notes you haven't sent. Closing it discards them."
+ )
+ : t(
+ 'auto.components.terminal.pane.PinnedTabCloseDialog.0d1963f4a6',
+ 'This tab is pinned. Are you sure you want to close it?'
+ )}
{tabLabel ? (
@@ -70,19 +81,21 @@ export default function PinnedTabCloseDialog(): React.JSX.Element {
{tabLabel}
) : null}
-
- setDontAskAgain(checked === true)}
- />
-
-
+ {unsentNotes ? null : (
+
+ setDontAskAgain(checked === true)}
+ />
+
+
+ )}