Skip to content

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

fix(remote): drop a deleted remote session from every cached list

vastsa3aa74a432200
diff --git a/apps/desktop/electron/main/remote/remote-backend.ts b/apps/desktop/electron/main/remote/remote-backend.ts
index 1ffe21baa..0fc5d91c7 100644
--- a/apps/desktop/electron/main/remote/remote-backend.ts
+++ b/apps/desktop/electron/main/remote/remote-backend.ts
@@ -51,6 +51,12 @@ export type RemoteBackendOptions = {
client: RemoteRacpClient;
hostLabel?: string;
onSnapshot?: (snapshot: RacpSessionSnapshot) => void;
+ /**
+ * Called after the Host confirms a `session/delete`. RACP publishes no delete
+ * event, so this is the only signal that the row left the host and must be
+ * dropped from this desktop's cached lists.
+ */
+ onSessionDeleted?: (hostSessionId: string) => void;
/** Injectable id source for RACP request contexts; defaults to a UUID. */
newRequestId?: () => string;
};
@@ -311,7 +317,9 @@ export function createRemoteBackend(options: RemoteBackendOptions): RemoteBacken
return { updated: result.updated === true };
}
case IPC.invoke.sessionDelete: {
- await client.request("session/delete", { sessionId: hostIdFor(args) });
+ const hostSessionId = hostIdFor(args);
+ await client.request("session/delete", { sessionId: hostSessionId });
+ options.onSessionDeleted?.(hostSessionId);
return { ok: true };
}
case IPC.invoke.toolResolvePermission: {
diff --git a/apps/desktop/electron/main/remote/remote-host-connection.ts b/apps/desktop/electron/main/remote/remote-host-connection.ts
index 218b162a3..881dae041 100644
--- a/apps/desktop/electron/main/remote/remote-host-connection.ts
+++ b/apps/desktop/electron/main/remote/remote-host-connection.ts
@@ -90,6 +90,13 @@ export function createRemoteHostConnection(options: RemoteHostConnectionOptions)
bridge.restoreSnapshot(snapshot);
background(ensure(snapshot.session.id));
},
+ onSessionDeleted(hostSessionId: string) {
+ // The Host publishes no delete event, so the confirmed delete is the
+ // only signal that the row must leave every list on this desktop.
+ unregister(hostSessionId);
+ background(enqueue(() => subscriptions.remove(hostSessionId)));
+ emit(IPC.event.sessionsChanged, { reason: "remote.session.deleted" });
+ },
});
const subscriptions = createRemoteSubscriptions({ client, alive, handle: event => bridge.handle(event),
recover: id => background(recover(id)), log: (message, error) => log("warn", message, error),
diff --git a/apps/desktop/src/stores/slices/queue-slice.ts b/apps/desktop/src/stores/slices/queue-slice.ts
index 0b5bc4baf..dc3fb3f2c 100644
--- a/apps/desktop/src/stores/slices/queue-slice.ts
+++ b/apps/desktop/src/stores/slices/queue-slice.ts
@@ -449,13 +449,14 @@ export function createQueueSlice({
// Keeps the session readable without any plugin: the owning host derives
// a short title from this prompt but leaves it replaceable, so an
// installed title plugin can still upgrade it after the first turn. A
- // remote session derives on its own host, and the host refuses the write
- // once the session was renamed. A native Pi session owns its title
- // outside this host, so it keeps whatever that surface shows.
+ // remote session derives on its own host: the backend router forwards
+ // this same call to the owning `pi-host`, whose `session/deriveTitle`
+ // refuses the write once the session was renamed, so a remote session
+ // must not be excluded here. A native Pi session owns its title outside
+ // this host, so it keeps whatever that surface shows.
if (
isDefaultSessionTitle(current?.title) &&
current?.source !== "pi-native"
- && !isRemoteSession(current)
) {
const nextTitle = promptFallbackSessionTitle(content, untitledTaskTitle());
if (!isDefaultSessionTitle(nextTitle)) {
diff --git a/apps/desktop/test/remote-backend.test.mjs b/apps/desktop/test/remote-backend.test.mjs
index 6c09952b1..b6f4f3c67 100644
--- a/apps/desktop/test/remote-backend.test.mjs
+++ b/apps/desktop/test/remote-backend.test.mjs
@@ -374,6 +374,29 @@ test("sessionDeriveTitle asks the host and reports whether it applied the title"
assert.deepEqual(refusedResult, { updated: false });
});
+test("sessionDelete reports the confirmed host delete so cached lists drop the row", async () => {
+ const deleted = [];
+ const applied = makeBackend({ "session/delete": () => ({ ok: true }) }, {
+ onSessionDeleted: (hostSessionId) => deleted.push(hostSessionId),
+ });
+ const result = await applied.backend.invoke(IPC.invoke.sessionDelete, [REMOTE_SESSION_ID]);
+ assert.deepEqual(result, { ok: true });
+ assert.deepEqual(applied.client.calls[0].params, { sessionId: HOST_SESSION_ID });
+ assert.deepEqual(deleted, [HOST_SESSION_ID]);
+
+ // A refused delete leaves the desktop's cached lists untouched.
+ const refusedHosts = [];
+ const refused = makeBackend(
+ { "session/delete": () => { throw new Error("the session has an active turn"); } },
+ { onSessionDeleted: (hostSessionId) => refusedHosts.push(hostSessionId) },
+ );
+ await assert.rejects(
+ refused.backend.invoke(IPC.invoke.sessionDelete, [REMOTE_SESSION_ID]),
+ /active turn/,
+ );
+ assert.deepEqual(refusedHosts, []);
+});
+
test("toolResolvePermission decodes the encoded requestId back to the host approval id", async () => {
const requestId = makeRemoteApprovalRequestId(REMOTE_SESSION_ID, "approval-77");
const { backend, client } = makeBackend({
diff --git a/apps/desktop/test/remote-host-connection.test.mjs b/apps/desktop/test/remote-host-connection.test.mjs
index 424b5e86f..439e16dad 100644
--- a/apps/desktop/test/remote-host-connection.test.mjs
+++ b/apps/desktop/test/remote-host-connection.test.mjs
@@ -158,6 +158,38 @@ test("a session.archived event unregisters the backend and lets the id fall thro
assert.equal(router.resolveBackend(IPC.invoke.sessionGet, [{ id: remoteId }]), null);
});
+test("a confirmed remote session delete drops the row and refreshes the sidebar", async () => {
+ const { conn, router, client, events } = setup({
+ sessions: [makeSession("s1"), makeSession("s2")],
+ });
+ await conn.open();
+ const remoteId = makeRemoteSessionId(HOST_KEY, "s1");
+ assert.ok(router.resolveBackend(IPC.invoke.sessionGet, [{ id: remoteId }]));
+ const outcome = await router.route(IPC.invoke.sessionDelete, [remoteId]);
+ assert.deepEqual(outcome, { remote: true, value: { ok: true } });
+ assert.ok(
+ client.calls.some(
+ (entry) => entry.method === "session/delete" && entry.params.sessionId === "s1",
+ ),
+ "the host must receive the delete",
+ );
+ // The deleted session stops being routable, and its event stream is released.
+ assert.equal(router.resolveBackend(IPC.invoke.sessionGet, [{ id: remoteId }]), null);
+ const notice = events.find(
+ (event) =>
+ event.channel === IPC.event.sessionsChanged &&
+ event.payload.reason === "remote.session.deleted",
+ );
+ assert.ok(notice, "a confirmed delete must refresh the renderer's session list");
+ await new Promise((resolve) => setImmediate(resolve));
+ assert.ok(
+ client.calls.some(
+ (entry) => entry.method === "events/unsubscribe" && entry.params.subscriptionId === "sub-s1",
+ ),
+ "the deleted session's subscription must be released",
+ );
+});
+
test("close detaches the listener and unregisters every session", async () => {
const { conn, router, client } = setup({ sessions: [makeSession("s1"), makeSession("s2")] });
await conn.open();
diff --git a/apps/desktop/test/session-title-prompt-fallback.test.mjs b/apps/desktop/test/session-title-prompt-fallback.test.mjs
index d884bf77a..9ccf46094 100644
--- a/apps/desktop/test/session-title-prompt-fallback.test.mjs
+++ b/apps/desktop/test/session-title-prompt-fallback.test.mjs
@@ -40,7 +40,7 @@ test("the first prompt becomes an immediate title, collapsed and capped", () =>
assert.equal(promptFallbackSessionTitle("界".repeat(60), "New task"), "界".repeat(48));
});
-test("the fallback only fires for a still-untitled local session", () => {
+test("the fallback only fires for a still-untitled session the owning host can title", () => {
assert.equal(isDefaultSessionTitle(promptFallbackSessionTitle("Fix login", "New task")), false);
assert.equal(isDefaultSessionTitle(untitledTaskTitle()), true);
// A placeholder is recognized in every shipped locale, not just the active one.
@@ -55,10 +55,13 @@ test("the fallback only fires for a still-untitled local session", () => {
}
assert.match(queueSlice, /isDefaultSessionTitle\(current\?\.title\)/);
assert.match(queueSlice, /current\?\.source !== "pi-native"/);
- // A remote session derives on its own host, so the gate does not exclude it.
+ // A remote session derives on its own host through this same call — the
+ // backend router forwards it to the owning `pi-host` — so the gate must not
+ // exclude remote ids: doing so left every remote task unnamed.
+ assert.doesNotMatch(queueSlice, /!isRemoteSession\(/);
assert.doesNotMatch(
queueSlice,
- /isDefaultSessionTitle\(current\?\.title\)[\s\S]{0,140}source !== "remote"/,
+ /isDefaultSessionTitle\(current\?\.title\)[\s\S]{0,200}source !== "remote"/,
);
assert.match(queueSlice, /api\s+\.deriveSessionTitle\(sessionId, nextTitle\)/);
assert.match(queueSlice, /if \(!isDefaultSessionTitle\(nextTitle\)\)/);