Skip to content

Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.

fix(linux): stop re-paying stale portal sessions on every Wayland paste (#1629)

Gabriel Stein12749e5acd9f
diff --git a/resources/linux-fast-paste.c b/resources/linux-fast-paste.c
index d2d9ebfdd..c30c13803 100644
--- a/resources/linux-fast-paste.c
+++ b/resources/linux-fast-paste.c
@@ -39,6 +39,13 @@ typedef enum {
#define PORTAL_IFACE "org.freedesktop.portal.RemoteDesktop"
#define REQUEST_IFACE "org.freedesktop.portal.Request"
+/* Method replies are immediate on a healthy portal (user interaction arrives via
+ * Response signals, not the call reply). A stale RemoteDesktop session can leave
+ * a sync call hanging inside a signal callback, which blocks the main loop and
+ * defeats the 10s watchdog below — so bound every call instead of using the
+ * default (25s) D-Bus timeout. */
+#define PORTAL_CALL_TIMEOUT_MS 3000
+
/* evdev keycodes for portal mode */
#define PORTAL_KEY_LEFTCTRL 29
#define PORTAL_KEY_LEFTSHIFT 42
@@ -85,7 +92,7 @@ static void portal_emit_key(PortalData *app, gint32 keycode, guint32 pressed,
g_dbus_connection_call_sync(app->conn, PORTAL_BUS, PORTAL_PATH,
PORTAL_IFACE, "NotifyKeyboardKeycode",
g_variant_new("(o@a{sv}iu)", app->session_handle, opts, keycode, pressed),
- NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &err);
+ NULL, G_DBUS_CALL_FLAGS_NONE, PORTAL_CALL_TIMEOUT_MS, NULL, &err);
if (err) { fprintf(stderr, "%s: %s\n", label, err->message); g_clear_error(&err); }
}
@@ -196,7 +203,7 @@ static void on_select_devices_response(GDBusConnection *conn, const char *sender
PORTAL_IFACE, "Start",
g_variant_new("(os@a{sv})", app->session_handle, "",
g_variant_builder_end(&opts)),
- NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &err);
+ NULL, G_DBUS_CALL_FLAGS_NONE, PORTAL_CALL_TIMEOUT_MS, NULL, &err);
g_free(request_path);
if (err) {
@@ -260,7 +267,7 @@ static void on_create_session_response(GDBusConnection *conn, const char *sender
PORTAL_IFACE, "SelectDevices",
g_variant_new("(o@a{sv})", app->session_handle,
g_variant_builder_end(&opts)),
- NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &err);
+ NULL, G_DBUS_CALL_FLAGS_NONE, PORTAL_CALL_TIMEOUT_MS, NULL, &err);
g_free(request_path);
if (err) {
@@ -318,7 +325,7 @@ static int paste_via_portal(paste_mode_t mode, const char *restore_token, int co
g_dbus_connection_call_sync(app.conn, PORTAL_BUS, PORTAL_PATH,
PORTAL_IFACE, "CreateSession",
g_variant_new("(@a{sv})", g_variant_builder_end(&opts)),
- NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &err);
+ NULL, G_DBUS_CALL_FLAGS_NONE, PORTAL_CALL_TIMEOUT_MS, NULL, &err);
g_free(request_path);
if (err) {
diff --git a/src/helpers/clipboard.js b/src/helpers/clipboard.js
index ce39a329e..047911be9 100644
--- a/src/helpers/clipboard.js
+++ b/src/helpers/clipboard.js
@@ -117,6 +117,9 @@ class ClipboardManager {
this.linuxFastPastePath = null;
this.linuxFastPasteChecked = false;
this.portalDenied = false;
+ this.portalFailed = false;
+ this.uinputTimedOut = false;
+ this.xtestTimedOut = false;
this._kwinScriptPath = null;
this.pasteQueue = Promise.resolve();
@@ -553,10 +556,14 @@ class ClipboardManager {
});
let timedOut = false;
+ // 15s only for the first grant (no token yet) so the permission dialog has
+ // time. With a saved token the session is pre-approved, so fail fast instead
+ // of hanging on a stale RemoteDesktop session that no longer responds (#1614).
+ const timeoutMs = restoreToken ? 2500 : 15000;
const timeoutId = setTimeout(() => {
timedOut = true;
killProcess(proc, "SIGKILL");
- }, 15000); // Portal may show a user dialog, allow more time
+ }, timeoutMs);
proc.on("close", (code) => {
if (timedOut) return reject(new Error("linux-fast-paste --portal timed out"));
@@ -1592,9 +1599,21 @@ class ClipboardManager {
if (isWayland) {
const tryUinputPaste = async () => {
+ if (this.uinputTimedOut) {
+ throw new Error("uinput timed out earlier this session, skipping");
+ }
const args = ["--uinput"];
appendModeFlag(args);
- await spawnFastPaste(args, "uinput");
+ try {
+ await spawnFastPaste(args, "uinput");
+ } catch (error) {
+ // A timeout means uinput hangs in this environment (unlike a fast
+ // error, which can be transient) — don't re-pay 2s on every paste.
+ if (error?.message === "linux-fast-paste timed out") {
+ this.uinputTimedOut = true;
+ }
+ throw error;
+ }
this.safeLog("✅ Paste successful using native linux-fast-paste (uinput)");
debugLogger.info(
"Paste successful",
@@ -1636,8 +1655,11 @@ class ClipboardManager {
"clipboard"
);
} else {
+ // Timeout or service error: the session stays broken until app
+ // restart, so skip the portal from now on (#1614).
+ this.portalFailed = true;
debugLogger.warn(
- "linux-fast-paste --portal failed, falling back",
+ "linux-fast-paste --portal failed, skipping portal for this session",
{ error: portalError?.message },
"clipboard"
);
@@ -1652,7 +1674,7 @@ class ClipboardManager {
// on X11. uinput causes clipboard desync (X11 clipboard vs Wayland input).
// GNOME: uinput first because the portal often times out or shows a
// confusing permission dialog, causing a 10s+ delay (issue #494).
- if (isKde && linuxFastPaste && !this.portalDenied) {
+ if (isKde && linuxFastPaste && !this.portalDenied && !this.portalFailed) {
const portalPaste = await tryPortalPaste();
if (portalPaste) return { method: "portal", ...portalPaste };
try {
@@ -1672,7 +1694,7 @@ class ClipboardManager {
"clipboard"
);
}
- if (!this.portalDenied) {
+ if (!this.portalDenied && !this.portalFailed) {
const portalPaste = await tryPortalPaste();
if (portalPaste) return { method: "portal", ...portalPaste };
}
@@ -1687,7 +1709,7 @@ class ClipboardManager {
}
// XTest/XWayland fallback: works for XWayland apps on any Wayland compositor
- if (xwaylandAvailable) {
+ if (xwaylandAvailable && !this.xtestTimedOut) {
const xtestArgs = [];
if (targetWindowId) xtestArgs.push("--window", targetWindowId);
appendModeFlag(xtestArgs);
@@ -1705,6 +1727,9 @@ class ClipboardManager {
restoreComplete: restoreClipboard(),
};
} catch (xtestError) {
+ if (xtestError?.message === "linux-fast-paste timed out") {
+ this.xtestTimedOut = true;
+ }
debugLogger.warn(
"XTest/XWayland fallback also failed",
{ error: xtestError?.message },
diff --git a/src/helpers/selectionManager.js b/src/helpers/selectionManager.js
index 9d2f587da..168bbaf44 100644
--- a/src/helpers/selectionManager.js
+++ b/src/helpers/selectionManager.js
@@ -368,14 +368,23 @@ class SelectionManager {
const result = await runSpawn(binary, args, { timeout: COPY_TIMEOUT_MS });
return { success: result.success, target };
}
- if (this.clipboardManager._runPortalPaste && !this.clipboardManager.portalDenied) {
+ if (
+ this.clipboardManager._runPortalPaste &&
+ !this.clipboardManager.portalDenied &&
+ !this.clipboardManager.portalFailed
+ ) {
try {
await this.clipboardManager._runPortalPaste(binary, {
copy: true,
terminal: isTerminal,
});
return { success: true, target };
- } catch {
+ } catch (err) {
+ // Same session-level memory as the paste path (#1614): a stale
+ // portal session would otherwise stall every selection capture.
+ if (err?.message !== "portal-denied" && err?.message !== "portal-dismissed") {
+ this.clipboardManager.portalFailed = true;
+ }
return { success: false };
}
}