Skip to content

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

fix(remote): keep authoritative projectId in mixed-batch session decoration

koeria5b7af692892b
diff --git a/packages/host-runtime/src/host-ports.test.ts b/packages/host-runtime/src/host-ports.test.ts
index 7cf44f5ea..55cf50bfe 100644
--- a/packages/host-runtime/src/host-ports.test.ts
+++ b/packages/host-runtime/src/host-ports.test.ts
@@ -5,6 +5,7 @@ import {
createHostSessionPort,
fromHostQueueEntry,
toSessionSummary,
+ withSessionProjectIds,
} from "./host-ports.js";
describe("host ports", () => {
@@ -126,6 +127,56 @@ describe("host ports", () => {
expect(calls).toEqual(["session.get"]);
});
+ it("keeps an authoritative projectId in a mixed batch and only falls back byPath for records without one", async () => {
+ const host = {
+ async call<T>(method: string) {
+ if (method === "projects.list") {
+ return {
+ projects: [{ id: 7, path: "/p", name: "p" }],
+ } as T;
+ }
+ throw new Error(`unexpected ${method}`);
+ },
+ };
+ const summaries = await withSessionProjectIds(host, [
+ { id: "explicit", projectId: "authoritative-id", projectPath: "/p" },
+ { id: "missing", projectPath: "/p" },
+ ]);
+ // The explicit record keeps its own id — byPath must not overwrite it.
+ expect(summaries[0]).toMatchObject({ id: "explicit", projectId: "authoritative-id" });
+ // The record without an id is decorated from the projects table.
+ expect(summaries[1]).toMatchObject({ id: "missing", projectId: "7" });
+ });
+
+ it("decorates port.get with the same project id the session list decoration yields", async () => {
+ // Maintainer acceptance: the shared decoration (createHostSessionPort.get
+ // vs. session/list via withSessionProjectIds) must produce identical
+ // project ids for the same record, or attach snapshots ungroup rows.
+ const host = {
+ async call<T>(method: string, params?: Record<string, unknown>) {
+ if (method === "projects.list") {
+ return {
+ projects: [{ id: 7, path: "/remote/app", name: "app" }],
+ } as T;
+ }
+ if (method === "session.get") {
+ expect(params).toMatchObject({ id: "s1" });
+ return {
+ session: { id: "s1", projectPath: "/remote/app", messages: [] },
+ } as T;
+ }
+ throw new Error(`unexpected ${method}`);
+ },
+ };
+ const record = { id: "s1", projectPath: "/remote/app" };
+ const [listed] = await withSessionProjectIds(host, [record]);
+ const port = createHostSessionPort(() => host);
+ const attached = await port.get("s1");
+ expect(attached).not.toBeNull();
+ expect(attached!.projectId).toBe(listed!.projectId);
+ expect(attached!.projectId).toBe("7");
+ });
+
it("round-trips queue records through the host-core RPC shape", async () => {
const calls: Array<{ method: string; params: Record<string, unknown> }> =
[];
diff --git a/packages/host-runtime/src/host-ports.ts b/packages/host-runtime/src/host-ports.ts
index 7049965cc..b85a2e144 100644
--- a/packages/host-runtime/src/host-ports.ts
+++ b/packages/host-runtime/src/host-ports.ts
@@ -138,6 +138,11 @@ export async function withSessionProjectIds(
}
return records.map((record) => {
const summary = toSessionSummary(record);
+ // An authoritative projectId on the record itself wins; the byPath
+ // fallback only fills in records whose id is missing (otherwise a
+ // mixed batch would overwrite explicit ids that happen to share a
+ // path with a projects.list row).
+ if (record.projectId) return summary;
const projectId = record.projectPath
? byPath.get(record.projectPath)
: undefined;