Skip to content

Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins

fix(live-voice): close widget review gaps

vastsa35aec49ceddb
diff --git a/apps/desktop/electron/main/live-voice/widget-window.ts b/apps/desktop/electron/main/live-voice/widget-window.ts
index f48fa7788..2c3d15393 100644
--- a/apps/desktop/electron/main/live-voice/widget-window.ts
+++ b/apps/desktop/electron/main/live-voice/widget-window.ts
@@ -254,6 +254,10 @@ export function createLiveVoiceWidget(input: {
savePosition();
current.hide();
}
+ // The renderer reports its presentation after installing its event
+ // subscription. Replay here so a state sent during page load cannot be
+ // lost before React is ready to receive it.
+ sendView();
return;
}
void ensureWindow().then((created) => {
@@ -280,7 +284,7 @@ export function createLiveVoiceWidget(input: {
requestAction(action) {
const main = input.getMainWindow();
if (!main || main.isDestroyed()) return;
- if (action === "details" || action === "settings") {
+ if (action === "details" || action === "settings" || action === "resume") {
// The details surface and the Settings route live in the main window,
// so the action has to hand the user over to it.
if (main.isMinimized()) main.restore();
diff --git a/apps/desktop/src/features/voice/live/LiveVoiceDetails.tsx b/apps/desktop/src/features/voice/live/LiveVoiceDetails.tsx
index ad3220da5..66a5b5b78 100644
--- a/apps/desktop/src/features/voice/live/LiveVoiceDetails.tsx
+++ b/apps/desktop/src/features/voice/live/LiveVoiceDetails.tsx
@@ -3,7 +3,7 @@ import type { TFunction } from "i18next";
import type { LiveCallView, LiveStatus, LiveTranscriptSegment } from "@pi-desktop/shared";
import { IconClose, IconExternal } from "../../../components/icons";
import { AnchoredMenu } from "../../../components/settings/AnchoredMenu";
-import { Panel, TooltipButton } from "../../../components/ui";
+import { Button, Panel, TooltipButton } from "../../../components/ui";
import { useAppStore } from "../../../stores/app-store";
import { liveVoiceApi } from "./live-voice-api";
import { formatWorkSessionLabel } from "./live-voice-presentation";
@@ -11,13 +11,14 @@ import { liveWorkDecision, operationAwaitsDecision } from "./live-work-decision"
import { LiveWorkDecisionNotice } from "./LiveWorkDecisionNotice";
import { LiveWorkOperations } from "./LiveWorkOperations";
-export function LiveVoiceDetails({ t, call, status, transcripts, open, onClose, anchorRef }: {
+export function LiveVoiceDetails({ t, call, status, transcripts, open, onClose, onResumePlayback, anchorRef }: {
t: TFunction;
call: LiveCallView;
status: LiveStatus | null;
transcripts: LiveTranscriptSegment[];
open: boolean;
onClose: () => void;
+ onResumePlayback: () => void;
anchorRef: RefObject<HTMLElement | null>;
}) {
const activeSessionId = useAppStore((state) => state.activeSessionId);
@@ -86,6 +87,11 @@ export function LiveVoiceDetails({ t, call, status, transcripts, open, onClose,
<Panel className="live-voice-details">
<div className="live-voice-panel-heading">
<strong>{t("liveVoice.details")}</strong>
+ {call.playbackBlocked ? (
+ <Button size="sm" variant="secondary" onClick={onResumePlayback}>
+ {t("liveVoice.resumePlayback")}
+ </Button>
+ ) : null}
<TooltipButton type="button" className="icon-btn icon-btn-square" tooltip={t("common.close")} onClick={onClose}>
<IconClose size={15} aria-hidden="true" />
</TooltipButton>
diff --git a/apps/desktop/src/features/voice/live/LiveVoiceStatusHost.tsx b/apps/desktop/src/features/voice/live/LiveVoiceStatusHost.tsx
index ffac77a38..2f4136e6b 100644
--- a/apps/desktop/src/features/voice/live/LiveVoiceStatusHost.tsx
+++ b/apps/desktop/src/features/voice/live/LiveVoiceStatusHost.tsx
@@ -76,7 +76,11 @@ export function LiveVoiceStatusHost() {
runAction(() => controller.toggleMute(), "mute");
break;
case "resume":
- runAction(() => controller.resumePlayback(), "playback");
+ // IPC cannot transfer transient user activation from the widget
+ // renderer. Main focuses this window for the widget press; the user
+ // must click the owner-frame control below so AudioContext/media play
+ // runs in a real gesture handler.
+ setDetailsOpen(true);
break;
case "end":
runAction(() => controller.end());
@@ -105,6 +109,7 @@ export function LiveVoiceStatusHost() {
transcripts={snapshot.transcripts}
open={detailsOpen}
onClose={() => setDetailsOpen(false)}
+ onResumePlayback={() => runAction(() => controller.resumePlayback(), "playback")}
anchorRef={anchorRef}
/>
) : null}
diff --git a/apps/desktop/src/features/voice/live/LiveVoiceWidget.tsx b/apps/desktop/src/features/voice/live/LiveVoiceWidget.tsx
index d8ed5dc4b..5a2cbfb2a 100644
--- a/apps/desktop/src/features/voice/live/LiveVoiceWidget.tsx
+++ b/apps/desktop/src/features/voice/live/LiveVoiceWidget.tsx
@@ -52,7 +52,10 @@ export function LiveVoiceWidget() {
const callId = state.call?.callId;
- useEffect(() => liveVoiceApi.onWidgetState((next) => setState(next)), []);
+ // Subscribe in a layout effect before reporting the presentation below. The
+ // main process replays its latest state in response to that report, closing
+ // the did-finish-load/passive-effect race for the first call snapshot.
+ useLayoutEffect(() => liveVoiceApi.onWidgetState((next) => setState(next)), []);
// Every call starts with a clean presentation: a failure the user dismissed
// during the last call must not stay silent during the next one.
diff --git a/apps/desktop/test/fixtures/live-voice-interaction-runner.cjs b/apps/desktop/test/fixtures/live-voice-interaction-runner.cjs
index df2dea6a6..9ce64a6ed 100644
--- a/apps/desktop/test/fixtures/live-voice-interaction-runner.cjs
+++ b/apps/desktop/test/fixtures/live-voice-interaction-runner.cjs
@@ -263,17 +263,17 @@ async function playbackScenario() {
await check("blocked output exposes Resume sound with details closed",
`s.snapshot.call.playbackBlocked && ${button("Resume sound")} && ${noDialog}`);
await click(button("Resume sound"));
- // The retry is refused in the owner frame, which is the only place that knows
- // it: it reports the code and the widget names it in place, so the failure is
- // visible without the details surface.
- await check("failed playback retry is visible without opening details",
- `s.snapshot.errorCode === 'LIVE_PLAYBACK_FAILED' && document.body.textContent.includes('LIVE_PLAYBACK_FAILED') && ui.all('[role=status]').length > 0 && ${button("Resume sound")} && ${noDialog} && s.counts.play >= 2`);
- await check("failed playback retry is visible without opening details",
- `s.snapshot.errorCode === 'LIVE_PLAYBACK_FAILED' && document.body.textContent.includes('LIVE_PLAYBACK_FAILED') && ui.all('[role=status]').length > 0 && ${button("Resume sound")} && ${noDialog} && s.counts.play >= 2`);
+ // Widget IPC cannot carry transient user activation. The owner window is
+ // focused and exposes a real owner-frame control for the retry.
+ await check("widget playback recovery hands off to the owner frame",
+ `ui.dialog(${JSON.stringify(details)}) && ${button("Resume sound", details)} && s.counts.play === 1`);
+ await click(button("Resume sound", details));
+ await check("failed playback retry is visible after owner-frame activation",
+ `s.snapshot.errorCode === 'LIVE_PLAYBACK_FAILED' && document.body.textContent.includes('LIVE_PLAYBACK_FAILED') && ${button("Resume sound", details)} && s.counts.play >= 2`);
await evaluate("window.liveVoiceFixture.blockPlayback(false)");
- await click(button("Resume sound"));
- await check("successful user retry clears playback blockage and error",
- `!s.snapshot.call.playbackBlocked && !s.snapshot.errorCode && !${button("Resume sound")} && ${noDialog}`);
+ await click(button("Resume sound", details));
+ await check("successful owner-frame retry clears playback blockage and error",
+ `!s.snapshot.call.playbackBlocked && !s.snapshot.errorCode && !${button("Resume sound", details)}`);
await click(button("End call", bar));
await wait("playback call ended", "!s.snapshot.stopping && s.snapshot.call?.phase === 'ended'");
await clean();
diff --git a/apps/desktop/test/live-voice-widget.test.mjs b/apps/desktop/test/live-voice-widget.test.mjs
index 62d848672..a36d5b8e8 100644
--- a/apps/desktop/test/live-voice-widget.test.mjs
+++ b/apps/desktop/test/live-voice-widget.test.mjs
@@ -98,3 +98,43 @@ test("only the widget's own actions and box are accepted on its channels", async
"the widget cannot move itself: the window layer owns the position",
);
});
+
+test("widget IPC handlers enforce renderer ownership", async (t) => {
+ const server = await createServer({
+ root: fileURLToPath(new URL("..", import.meta.url)),
+ configFile: false,
+ server: { middlewareMode: true, hmr: false, ws: false },
+ appType: "custom",
+ optimizeDeps: { noDiscovery: true, include: [] },
+ });
+ t.after(() => server.close());
+ const { registerLiveVoiceIpc } = await server.ssrLoadModule("/electron/main/ipc/live-voice-ipc.ts");
+ const handlers = new Map();
+ const mainId = 11;
+ const widgetId = 22;
+ const registrar = {
+ ipcMain: {},
+ handle() {},
+ handleWithEvent(channel, handler) { handlers.set(channel, handler); },
+ assertMainWindowSender(event) {
+ if (event.sender.id !== mainId) throw Object.assign(new Error("wrong sender"), { errorCode: "PERMISSION_DENIED" });
+ },
+ };
+ const actions = [];
+ const widget = {
+ owns: (id) => id === widgetId,
+ setPresentation() {},
+ requestAction: (action) => actions.push(action),
+ setIssue() {},
+ };
+ const service = new Proxy({}, { get: () => async () => ({}) });
+ registerLiveVoiceIpc({ registrar, service, getMainWindow: () => ({ webContents: { id: mainId } }), widget });
+ const invoke = (channel, senderId, value) => handlers.get(channel)({ sender: { id: senderId } }, value);
+ await invoke("pi-desktop/voice/live/widget/action", widgetId, { action: "mute" });
+ assert.deepEqual(actions, ["mute"]);
+ await assert.rejects(() => invoke("pi-desktop/voice/live/widget/action", mainId, { action: "mute" }), { errorCode: "PERMISSION_DENIED" });
+ await assert.rejects(() => invoke("pi-desktop/voice/live/widget/visibility", mainId, { visible: true, width: 380, height: 60 }), { errorCode: "PERMISSION_DENIED" });
+ await assert.rejects(() => invoke("pi-desktop/voice/live/widget/action", 33, { action: "end" }), { errorCode: "PERMISSION_DENIED" });
+ await invoke("pi-desktop/voice/live/widget/issue", mainId, { callId: "call-a", code: null });
+ await assert.rejects(() => invoke("pi-desktop/voice/live/widget/issue", widgetId, { callId: "call-a", code: null }), { errorCode: "PERMISSION_DENIED" });
+});