Skip to content

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

fix(renderer): surface refused background writes and external opens

liuzixiang91ec00c1bd70
diff --git a/apps/desktop/src/stores/slices/session-slice.ts b/apps/desktop/src/stores/slices/session-slice.ts
index 3a6a21b40..efda58be7 100644
--- a/apps/desktop/src/stores/slices/session-slice.ts
+++ b/apps/desktop/src/stores/slices/session-slice.ts
@@ -622,11 +622,21 @@ export function createSessionSlice({
thinkingLevel: selected.thinkingLevel,
});
} else {
- void api.configureSession(id, {
+ // The active-session branch reports a refused write through its
+ // flush; a background session must not drop the pin silently,
+ // because the row keeps the optimistic value while the host
+ // reverts to the previous model on the next launch.
+ const pinWrite = api.configureSession(id, {
mode: selected.mode,
providerId: pin.providerId,
modelId: pin.modelId,
});
+ void pinWrite.catch((error) => {
+ get().showToast(
+ error instanceof Error ? error.message : String(error),
+ { variant: "error" },
+ );
+ });
}
}
}
diff --git a/apps/desktop/src/stores/slices/work-panel-slice.ts b/apps/desktop/src/stores/slices/work-panel-slice.ts
index c0702a4d2..90af311e5 100644
--- a/apps/desktop/src/stores/slices/work-panel-slice.ts
+++ b/apps/desktop/src/stores/slices/work-panel-slice.ts
@@ -412,7 +412,11 @@ export function createWorkPanelSlice({
);
if (!hasBrowser) {
if (/^https?:\/\//i.test(url.trim())) {
- void api.browserOpenExternal(url.trim());
+ // `shell.openExternal` rejects when the OS has no handler or a policy
+ // blocks the URL; without this the click looked like a no-op.
+ void api
+ .browserOpenExternal(url.trim())
+ .catch((error) => get().showToast(String(error), { variant: "error" }));
}
return;
}
diff --git a/apps/desktop/test/background-write-failures.test.mjs b/apps/desktop/test/background-write-failures.test.mjs
new file mode 100644
index 000000000..f29a382e3
--- /dev/null
+++ b/apps/desktop/test/background-write-failures.test.mjs
@@ -0,0 +1,35 @@
+import assert from "node:assert/strict";
+import { readFile } from "node:fs/promises";
+import test from "node:test";
+
+const read = (path) => readFile(new URL(path, import.meta.url), "utf8");
+const [sessionSlice, workPanelSlice] = await Promise.all([
+ read("../src/stores/slices/session-slice.ts"),
+ read("../src/stores/slices/work-panel-slice.ts"),
+]);
+
+function callAt(source, needle) {
+ const start = source.indexOf(needle);
+ assert.ok(start >= 0, `${needle} missing`);
+ return source.slice(start, start + 500);
+}
+
+test("a background session-pin write reports a refusal", () => {
+ // The active-session branch flushes through a catch that toasts. A pin on
+ // another session must not be the one path that drops its failure: the row
+ // keeps the optimistic value while the host still holds the old model.
+ const call = callAt(sessionSlice, "api.configureSession(id,");
+ assert.match(call, /\.catch\(/);
+ assert.match(call, /showToast/);
+ // The active-session branch is unchanged: it reports through its flush.
+ assert.match(sessionSlice, /void get\(\)\.configureActiveSession\(/);
+});
+
+test("the OS-browser fallback reports a refused open", () => {
+ // shell.openExternal rejects when the platform has no handler or a policy
+ // blocks the URL; without a catch the click is indistinguishable from a
+ // no-op, which is how the sibling pluginViewClose path already handles it.
+ const call = callAt(workPanelSlice, "browserOpenExternal(url.trim())");
+ assert.match(call, /\.catch\(/);
+ assert.match(call, /showToast/);
+});