Linger is An Open-Source Personal Agent That Runs Fully on Your PC. We aim to break Big Tech’s grip on AI by bringing powerful local AI to everyday computers through efficient model–harness co-design, so everyone can run their own.
fix(web): preserve recording across PiP transitions
muterC3db4f5650f6c
diff --git a/apps/web/AGENTS.md b/apps/web/AGENTS.mdindex a7e38bdd..e8a2e59a 100644--- a/apps/web/AGENTS.md+++ b/apps/web/AGENTS.md@@ -63,6 +63,18 @@ build:assets` to check the initial JS budget.must not trigger repeated hover enter/leave; sidebar expansion and Chat listcollapse remain explicit button actions. Pointer movement only resizes duringan active drag; keyboard resizing and double-click reset remain available.+- Recording picture-in-picture collapse remembers that window's actual+ expanded outer dimensions and restores both dimensions with an absolute+ resize inside the user's click, bounded by the current screen. A pending+ native resize must not replace the saved expanded size with collapsed+ metrics. Collapse never closes the window or stops the recording; native+ window placement remains under browser control.+- Recording and Voice Mode distinguish the native window's close action from+ back to tab through the shared PiP return detection. Back to tab keeps the+ session running in the page and exposes a Float action; close ends it.+ Recording moves one portal host between documents so paused state, Ask+ drafts and transcript scroll survive the move. Hide it while classifying a+ native close, and ignore a late result after unmount or a replacement window.- Gmail and Outlook message approvals show the subject and recipients once.The subject row toggles the preview and owns its hover highlight; therecipient line stays outside the control. The shared AutoHeight transitiondiff --git a/apps/web/src/features/rooms/voice-control/recording-window.test.tsx b/apps/web/src/features/rooms/voice-control/recording-window.test.tsxindex 10bed401..a334c6e9 100644--- a/apps/web/src/features/rooms/voice-control/recording-window.test.tsx+++ b/apps/web/src/features/rooms/voice-control/recording-window.test.tsx@@ -1,6 +1,7 @@import { QueryClient, QueryClientProvider } from "@tanstack/react-query";import {act,+ cleanup,fireEvent,render,screen,@@ -204,6 +205,7 @@ function renderWindow(return {routes,rerender: (value: VoiceControlContextValue) => view.rerender(tree(value)),+ unmount: view.unmount,};}@@ -213,6 +215,8 @@ beforeEach(() => {openRecordingWindow();});afterEach(() => {+ // Unmount portals before removing their picture-in-picture documents.+ cleanup();Reflect.deleteProperty(window, "documentPictureInPicture");document.querySelectorAll("iframe").forEach((frame) => frame.remove());});@@ -541,14 +545,15 @@ describe("Recording window", () => {renderWindow(voice);await act(() => openVoicePip("recording"));const floating = within(frame.contentDocument!.body);- expect(+ expectInDocument(await floating.findByRole("region", { name: "Recording window" }),- ).toBeInTheDocument();+ frame.contentDocument!,+ );// Minimizing from inside the floating window shrinks it to its top row.fireEvent.click(floating.getByRole("button", { name: "Minimize recording" }),);- expect(pipWindow.resizeBy).toHaveBeenCalledWith(0, 104 - 720);+ expect(pipWindow.resizeTo).toHaveBeenCalledWith(420, 136);act(() => pipWindow.close());expect(@@ -565,9 +570,10 @@ describe("Recording window", () => {const voice = voiceValue();renderWindow(voice);await act(() => openVoicePip("recording"));- expect(+ expectInDocument(within(frame.contentDocument!.body).getByRole("tab", { name: "Ask" }),- ).toBeInTheDocument();+ frame.contentDocument!,+ );act(() => pipWindow.close());await waitFor(() => expect(voice.leavePage).toHaveBeenCalledOnce());@@ -576,6 +582,224 @@ describe("Recording window", () => {);});+ it("returns to the page without stopping and preserves pause and Ask when floated again", async () => {+ vi.useFakeTimers();+ try {+ const first = stubPictureInPicture();+ const voice = voiceValue();+ renderWindow(voice);+ await act(() => openVoicePip("recording"));+ const floating = within(first.frame.contentDocument!.body);+ await act(async () => {+ fireEvent.click(+ floating.getByRole("button", { name: "Pause recording" }),+ );+ });+ fireEvent.click(floating.getByRole("tab", { name: "Ask" }));+ const draft = floating.getByRole<HTMLTextAreaElement>("textbox", {+ name: "Ask about this recording",+ });+ fireEvent.change(draft, {+ target: { value: "Keep this draft while changing windows" },+ });+ act(() => {+ first.pipWindow.close();+ document.dispatchEvent(new Event("visibilitychange"));+ });+ expect(+ screen.queryByRole("region", { name: "Recording window" }),+ ).toBeNull();+ await act(() => vi.advanceTimersByTimeAsync(300));+ expect(+ screen.getByRole("region", { name: "Recording window" }),+ ).toBeVisible();+ expect(+ screen.getByRole("button", { name: "Resume recording" }),+ ).toBeVisible();+ expect(+ screen.getByRole("textbox", { name: "Ask about this recording" }),+ ).toBe(draft);+ expect(draft.value).toBe("Keep this draft while changing windows");+ expect(voice.leavePage).not.toHaveBeenCalled();+ expect(voice.stopCapture).not.toHaveBeenCalled();++ const second = stubPictureInPicture();+ await act(async () => {+ fireEvent.click(+ screen.getByRole("button", { name: "Float recording window" }),+ );+ await second.requestWindow.mock.results[0]?.value;+ });+ const refloated = within(second.frame.contentDocument!.body);+ expectInDocument(+ refloated.getByRole("region", { name: "Recording window" }),+ second.frame.contentDocument!,+ );+ expectInDocument(+ refloated.getByRole("button", { name: "Resume recording" }),+ second.frame.contentDocument!,+ );+ expect(+ refloated.getByRole("textbox", { name: "Ask about this recording" }),+ ).toBe(draft);+ expect(draft.value).toBe("Keep this draft while changing windows");+ expect(+ screen.queryByRole("region", { name: "Recording window" }),+ ).toBeNull();+ expect(second.requestWindow).toHaveBeenCalledOnce();+ expect(voice.leavePage).not.toHaveBeenCalled();+ } finally {+ vi.useRealTimers();+ }+ });++ it("ignores a pending native close after a new floating window opens", async () => {+ vi.useFakeTimers();+ try {+ const first = stubPictureInPicture();+ const voice = voiceValue();+ renderWindow(voice);+ await act(() => openVoicePip("recording"));+ act(() => first.pipWindow.close());+ const second = stubPictureInPicture();+ await act(() => openVoicePip("recording"));+ await act(() => vi.advanceTimersByTimeAsync(300));+ expectInDocument(+ within(second.frame.contentDocument!.body).getByRole("region", {+ name: "Recording window",+ }),+ second.frame.contentDocument!,+ );+ expect(voice.leavePage).not.toHaveBeenCalled();+ } finally {+ vi.useRealTimers();+ }+ });++ it("does not end recording from a close classification after unmount", async () => {+ vi.useFakeTimers();+ try {+ const { pipWindow } = stubPictureInPicture();+ const voice = voiceValue();+ const { unmount } = renderWindow(voice);+ await act(() => openVoicePip("recording"));+ act(() => pipWindow.close());+ unmount();+ await act(() => vi.advanceTimersByTimeAsync(300));+ expect(voice.leavePage).not.toHaveBeenCalled();+ } finally {+ vi.useRealTimers();+ }+ });++ it("restores the user's full window size across repeated minimize cycles", async () => {+ const { frame, pipWindow } = stubPictureInPicture();+ const voice = voiceValue();+ renderWindow(voice);+ await act(() => openVoicePip("recording"));+ const floating = within(frame.contentDocument!.body);+ pipWindow.resizeTo(560, 492);+ pipWindow.resizeTo.mockClear();++ for (let cycle = 0; cycle < 3; cycle++) {+ fireEvent.click(+ floating.getByRole("button", { name: "Minimize recording" }),+ );+ expect(pipWindow.outerWidth).toBe(560);+ expect(pipWindow.innerHeight).toBe(104);+ fireEvent.click(floating.getByRole("button", { name: "Open recording" }));+ expect(pipWindow.outerWidth).toBe(560);+ expect(pipWindow.outerHeight).toBe(492);+ }+ expect(voice.stopCapture).not.toHaveBeenCalled();+ expect(voice.leavePage).not.toHaveBeenCalled();+ expect(pipWindow.close).not.toHaveBeenCalled();++ pipWindow.resizeTo(620, 552);+ fireEvent.click(+ floating.getByRole("button", { name: "Minimize recording" }),+ );+ fireEvent.click(floating.getByRole("button", { name: "Open recording" }));+ expect(pipWindow.outerWidth).toBe(620);+ expect(pipWindow.outerHeight).toBe(552);+ });++ it("restores width even when the browser narrows the minimized window", async () => {+ const { frame, pipWindow } = stubPictureInPicture();+ renderWindow(voiceValue());+ await act(() => openVoicePip("recording"));+ const floating = within(frame.contentDocument!.body);+ pipWindow.resizeTo(580, 512);+ fireEvent.click(+ floating.getByRole("button", { name: "Minimize recording" }),+ );+ pipWindow.resizeTo(360, 136);+ fireEvent.click(floating.getByRole("button", { name: "Open recording" }));+ expect(pipWindow.outerWidth).toBe(580);+ expect(pipWindow.outerHeight).toBe(512);+ });++ it("does not overwrite the expanded size while a resize is still pending", async () => {+ const { frame, pipWindow } = stubPictureInPicture();+ renderWindow(voiceValue());+ await act(() => openVoicePip("recording"));+ const floating = within(frame.contentDocument!.body);+ pipWindow.resizeTo(560, 492);+ fireEvent.click(+ floating.getByRole("button", { name: "Minimize recording" }),+ );+ // Browsers can impose a minimum larger than the requested compact height.+ pipWindow.resizeTo(560, 180);+ // Native resize requests may return before the window metrics change.+ pipWindow.resizeTo.mockImplementation(() => undefined);+ fireEvent.click(floating.getByRole("button", { name: "Open recording" }));+ fireEvent.click(+ floating.getByRole("button", { name: "Minimize recording" }),+ );+ fireEvent.click(floating.getByRole("button", { name: "Open recording" }));+ expect(pipWindow.resizeTo).toHaveBeenLastCalledWith(560, 492);+ });++ it("fits the saved size to the current screen after moving between displays", async () => {+ const { frame, pipWindow } = stubPictureInPicture();+ renderWindow(voiceValue());+ await act(() => openVoicePip("recording"));+ const floating = within(frame.contentDocument!.body);+ pipWindow.resizeTo(700, 752);+ fireEvent.click(+ floating.getByRole("button", { name: "Minimize recording" }),+ );+ pipWindow.screen.availWidth = 640;+ pipWindow.screen.availHeight = 600;+ fireEvent.click(floating.getByRole("button", { name: "Open recording" }));+ expect(pipWindow.resizeTo).toHaveBeenLastCalledWith(640, 600);+ });++ it("keeps recording and its controls usable when native resize is refused", async () => {+ const { frame, pipWindow } = stubPictureInPicture();+ const voice = voiceValue();+ renderWindow(voice);+ await act(() => openVoicePip("recording"));+ const floating = within(frame.contentDocument!.body);+ pipWindow.resizeTo.mockImplementation(() => {+ throw new Error("Resize refused");+ });+ fireEvent.click(+ floating.getByRole("button", { name: "Minimize recording" }),+ );+ expectInDocument(+ floating.getByRole("button", { name: "Open recording" }),+ frame.contentDocument!,+ );+ fireEvent.click(floating.getByRole("button", { name: "Open recording" }));+ expectInDocument(+ floating.getByRole("tab", { name: "Transcript" }),+ frame.contentDocument!,+ );+ expect(voice.stopCapture).not.toHaveBeenCalled();+ expect(voice.leavePage).not.toHaveBeenCalled();+ });+it("does not show the window in the page while the closed one stops", async () => {const { pipWindow } = stubPictureInPicture();let finishStop = () => {};@@ -587,7 +811,7 @@ describe("Recording window", () => {renderWindow(voice);await act(() => openVoicePip("recording"));act(() => pipWindow.close());- expect(voice.leavePage).toHaveBeenCalledOnce();+ await waitFor(() => expect(voice.leavePage).toHaveBeenCalledOnce());expect(screen.queryByRole("region", { name: "Recording window" }),).toBeNull();@@ -610,7 +834,7 @@ describe("Recording window", () => {);});- it("marks the window ending the moment the floating window closes", async () => {+ it("hides the closed window while distinguishing close from return to page", async () => {const { pipWindow } = stubPictureInPicture();let finishStop = () => {};const voice = voiceValue({@@ -621,10 +845,12 @@ describe("Recording window", () => {renderWindow(voice);await act(() => openVoicePip("recording"));act(() => pipWindow.close());- expect(screen.getByTestId("window-state")).toHaveTextContent("ending");expect(screen.queryByRole("region", { name: "Recording window" }),).toBeNull();+ await waitFor(() =>+ expect(screen.getByTestId("window-state")).toHaveTextContent("ending"),+ );await act(async () => finishStop());await waitFor(() =>expect(screen.getByTestId("window-state")).toHaveTextContent("closed"),@@ -651,24 +877,46 @@ describe("Recording window", () => {});});+function expectInDocument(element: HTMLElement, target: Document) {+ // Adopted nodes retain their creation realm; containment works across windows.+ expect(target.body.contains(element)).toBe(true);+ expect(element.isConnected).toBe(true);+}+function stubPictureInPicture() {const frame = document.createElement("iframe");document.body.append(frame);const listeners: (() => void)[] = [];const pipWindow = {document: frame.contentDocument!,+ innerWidth: 420,innerHeight: 720,+ outerWidth: 420,+ outerHeight: 752,+ screen: { availWidth: 1440, availHeight: 900 },addEventListener: (type: string, listener: () => void) => {if (type === "pagehide") listeners.push(listener);},close: vi.fn(() => listeners.splice(0).forEach((listener) => listener())),- resizeBy: vi.fn(),+ resizeTo: vi.fn((width: number, height: number) => {+ pipWindow.outerWidth = width;+ pipWindow.innerWidth = width;+ pipWindow.outerHeight = height;+ pipWindow.innerHeight = height - 32;+ }),+ resizeBy: vi.fn((width: number, height: number) => {+ pipWindow.resizeTo(+ pipWindow.outerWidth + width,+ pipWindow.outerHeight + height,+ );+ }),};+ const requestWindow = vi.fn(async () => pipWindow);Object.defineProperty(window, "documentPictureInPicture", {configurable: true,- value: { requestWindow: vi.fn(async () => pipWindow) },+ value: { requestWindow },});- return { frame, pipWindow };+ return { frame, pipWindow, requestWindow };}describe("Recording window placement", () => {diff --git a/apps/web/src/features/rooms/voice-control/recording-window.tsx b/apps/web/src/features/rooms/voice-control/recording-window.tsxindex 6b2769e5..2bec1d28 100644--- a/apps/web/src/features/rooms/voice-control/recording-window.tsx+++ b/apps/web/src/features/rooms/voice-control/recording-window.tsx@@ -10,7 +10,10 @@ import { createPortal } from "react-dom";import {closeVoicePip,onVoicePipClosedByHuman,+ openVoicePip,+ returnedToOpener,useVoicePip,+ voicePipSupported,} from "../chat/voice-mode/voice-pip";import {RecordingAnswers,@@ -31,9 +34,15 @@ import {} from "./voice-control-context";import { VoiceFocusSurface, type RecordingView } from "./voice-focus-surface";-// Inner heights of the picture-in-picture window: the top row alone, or open.-// Collapsed keeps the docked title bar (36px) and the header row (68px).-const pipHeights = { collapsed: 104, expanded: 720 };+// Inner height that keeps the docked title bar and recording controls visible.+const collapsedPipHeight = 104;+interface ExpandedPipSize {+ window: Window;+ width: number;+ height: number;+ collapsedWidth?: number;+ collapsedHeight?: number;+}// Where the window sits in the page: 16px from the right, 64px from the top.const pageInset = { right: 16, top: 64, width: 420 };@@ -42,32 +51,48 @@ const pageInset = { right: 16, top: 64, width: 420 };* behind it. Where the browser supports it the window floats over other tabs* and apps; otherwise it floats over the page. Minimizing it leaves only its* top row and keeps recording; Stop, or closing the open floating window, ends- * the recording.+ * the recording. Back to tab keeps recording in the page window.*/export default function RecordingWindow() {const windowState = useRecordingWindow();const livekit = useOptionalVoiceControl();const voice = livekit;const pip = useVoicePip("recording");+ const expandedPipSize = useRef<ExpandedPipSize | undefined>(undefined);const status = voice?.captureState?.status;const [lastView, setLastView] = useState<RecordingView>("transcript");const view = windowState.minimized ? undefined : lastView;- // Once the window has floated over other apps, losing that window means the- // Human closed it. It never falls back into the page then: the page shows- // nothing while the recording stops, so no second window flashes up. Only- // a stop that failed brings the window back, minimized, into the page.+ // Hide the surface while distinguishing native close from back to tab,+ // matching Voice Mode. Only back to tab keeps recording in the page.const [floated, setFloated] = useState(false);+ const [backInPage, setBackInPage] = useState(false);if (pip && !floated) setFloated(true);- const pipClosed = floated && !pip;+ if (pip && backInPage) setBackInPage(false);+ const pipClosed = floated && !pip && !backInPage;++ // Moving one portal host preserves pause timing, Ask drafts and transcript+ // scroll state; changing the portal target would remount the recording UI.+ const [portalHost] = useState(() => document.createElement("div"));+ const portalParent =+ voice && !windowState.ending && !pipClosed+ ? (pip?.document.body ?? document.body)+ : undefined;+ useLayoutEffect(() => {+ if (!portalParent) return;+ portalParent.append(portalHost);+ return () => portalHost.remove();+ }, [portalHost, portalParent]);// The desktop's close button on the floating window ends the recording the// way Stop does, whether the window was open or minimized to its top row.const voiceRef = useRef(voice);+ const pipRef = useRef(pip);const endingRef = useRef(false);const closedByHumanRef = useRef(() => {});useLayoutEffect(() => {voiceRef.current = voice;+ pipRef.current = pip;closedByHumanRef.current = () => {if (endingRef.current) return;endingRef.current = true;@@ -87,19 +112,22 @@ export default function RecordingWindow() {});};});- useEffect(- () =>- onVoicePipClosedByHuman("recording", () => closedByHumanRef.current()),- [],- );- // The same close noticed from this side, should the window's own close- // event be missed.useEffect(() => {- if (pipClosed) closedByHumanRef.current();- }, [pipClosed]);- // The auto start is spent once a recording runs, so a remounted window- // (moving between its floating window and the page remounts it) cannot- // start a second recording when this one stops.+ let mounted = true;+ const unsubscribe = onVoicePipClosedByHuman("recording", () => {+ void returnedToOpener().then((returned) => {+ if (!mounted || pipRef.current) return;+ if (returned) setBackInPage(true);+ else closedByHumanRef.current();+ });+ });+ return () => {+ mounted = false;+ unsubscribe();+ };+ }, []);+ // Spend auto start once, so re-opening this window cannot start a second+ // recording when this one stops.useEffect(() => {if (status === "recording" || status === "starting")consumeRecordingAutoStart();@@ -119,11 +147,42 @@ export default function RecordingWindow() {setLastView(next);expandRecordingWindow();} else minimizeRecordingWindow();- // Runs inside the click, which is what lets the window resize itself.+ // Keep native resize inside the click so it retains user activation.if (pip && Boolean(next) !== Boolean(view)) {- const height = next ? pipHeights.expanded : pipHeights.collapsed;+ const chromeHeight = Math.max(0, pip.outerHeight - pip.innerHeight);+ const collapsedHeight = collapsedPipHeight + chromeHeight;+ let expanded = expandedPipSize.current;+ if (expanded?.window !== pip) expanded = undefined;+ // A rapid second click can precede the native expansion. Do not save+ // the still-collapsed metrics as the user's expanded window size.+ if (+ !next &&+ (!expanded ||+ pip.outerWidth !== expanded.collapsedWidth ||+ pip.outerHeight !== expanded.collapsedHeight)+ ) {+ expanded = {+ window: pip,+ width: pip.outerWidth,+ height: pip.outerHeight,+ };+ expandedPipSize.current = expanded;+ }+ if (next && expanded) {+ expanded.collapsedWidth = pip.outerWidth;+ expanded.collapsedHeight = pip.outerHeight;+ }+ const width = next && expanded ? expanded.width : pip.outerWidth;+ const height = next+ ? (expanded?.height ?? pip.outerHeight)+ : collapsedHeight;try {- pip.resizeBy(0, height - pip.innerHeight);+ // Restore both outer dimensions: a browser-clamped width must not+ // become the starting point for another relative shrink/expand cycle.+ pip.resizeTo(+ Math.min(width, pip.screen.availWidth || width),+ Math.min(height, pip.screen.availHeight || height),+ );} catch {// The Human can still drag the window to size.}@@ -160,9 +219,7 @@ export default function RecordingWindow() {window.addEventListener("pointermove", move);window.addEventListener("pointerup", end);};- // Nothing renders in the page while a closed floating window's recording- // stops.- if (!voice || windowState.ending || pipClosed) return null;+ if (!voice) return null;return createPortal(<divaria-label="Recording window"@@ -186,12 +243,19 @@ export default function RecordingWindow() {<RecordingPanelautoStart={windowState.autoStart}floating={pip ? "pip" : "page"}+ onFloat={+ !pip && voicePipSupported()+ ? () => {+ void openVoicePip("recording");+ }+ : undefined+ }onMoveStart={startMove}onViewChange={changeView}view={view}/></div>,- pip?.document.body ?? document.body,+ portalHost,);}@@ -259,12 +323,14 @@ export function pinchedPlacement(view: PinchZoom) {function RecordingPanel({autoStart,floating,+ onFloat,onMoveStart,onViewChange,view,}: {autoStart: boolean;floating: "page" | "pip";+ onFloat?: () => void;onMoveStart: (event: PointerEvent<HTMLDivElement>) => void;onViewChange: (view: RecordingView | undefined) => void;view?: RecordingView;@@ -283,6 +349,7 @@ function RecordingPanel({<VoiceFocusSurfaceautoStart={autoStart}floating={floating}+ onFloat={onFloat}onMoveStart={onMoveStart}onExit={() => {// Saving finishes in the background; the sidebar's Recording tooldiff --git a/apps/web/src/features/rooms/voice-control/voice-focus-surface.tsx b/apps/web/src/features/rooms/voice-control/voice-focus-surface.tsxindex 14b06e83..9001fe7e 100644--- a/apps/web/src/features/rooms/voice-control/voice-focus-surface.tsx+++ b/apps/web/src/features/rooms/voice-control/voice-focus-surface.tsx@@ -6,6 +6,7 @@ import {Loading03Icon,Mic01Icon,PauseIcon,+ PictureInPictureOnIcon,PlayIcon,StopIcon,} from "@hugeicons/core-free-icons";@@ -49,6 +50,7 @@ export function VoiceFocusSurface({autoStart = false,floating = "page",onExit,+ onFloat,onMoveStart,onViewChange,panels,@@ -58,6 +60,8 @@ export function VoiceFocusSurface({/** A picture-in-picture window fills its own window instead of floating. */floating?: "page" | "pip";onExit: () => void;+ /** Returns the page window to the always-on-top browser window. */+ onFloat?: () => void;/** Starts moving the page window from its hover title bar. */onMoveStart?: (event: PointerEvent<HTMLDivElement>) => void;onViewChange?: (view: RecordingView | undefined) => void;@@ -249,6 +253,17 @@ export function VoiceFocusSurface({</button>) : null}<span className="flex-1" />+ {onFloat ? (+ <button+ aria-label="Float recording window"+ className={styles.windowButton}+ onClick={onFloat}+ title="Float over other tabs and apps"+ type="button"+ >+ <Icon icon={PictureInPictureOnIcon} />+ </button>+ ) : null}</div>);return (