Skip to content

The agent that grows with you

fix(desktop): list a chat the backend filed in Home even when it carries a cwd

unsupportedpastels798b8bf52be9
diff --git a/apps/desktop/src/app/chat/sidebar/projects/workspace-groups.test.ts b/apps/desktop/src/app/chat/sidebar/projects/workspace-groups.test.ts
index 6997c056a06..698dc0895d5 100644
--- a/apps/desktop/src/app/chat/sidebar/projects/workspace-groups.test.ts
+++ b/apps/desktop/src/app/chat/sidebar/projects/workspace-groups.test.ts
@@ -1157,6 +1157,19 @@ describe('overlayLiveLanes', () => {
expect(overlayLiveLanes(home, [makeCwdSession('/www/app', { id: 'fresh' })])).toBe(home)
})
+ it('lists a cwd-carrying chat the snapshot filed in Home (#139909)', () => {
+ // A Desktop chat stamped with the bare home dir: the backend files it in
+ // Home, but the unhydrated tree carries only its id (`sessionIds`), so the
+ // overlay is the only thing that can paint its row.
+ const stamped = makeCwdSession('C:\\Users\\wrain', { id: 'stamped' })
+ const home = { ...homeNode([]), previewSessions: [stamped], sessionCount: 1, sessionIds: ['stamped'] }
+
+ const overlaid = overlayLiveLanes(home, [stamped], new Set(), projectOwnerBySessionId([home]))
+
+ expect(overlaid.repos[0].groups[0].sessions.map(s => s.id)).toEqual(['stamped'])
+ expect(overlaid.sessionCount).toBe(1)
+ })
+
// #77591 C: compression rotates the live id (root -> tip) while the snapshot
// still holds the older segment. Both are one conversation, so one row.
it.each([
@@ -1477,4 +1490,17 @@ describe('project filter row rule (#97762)', () => {
expect(sessionBucketId(sibling, explicit, owners)).toBe('p_app')
expect(sessionProjectColor(sibling, explicit, owners)).toBe('#abc')
})
+
+ // #139909: the backend files a home-dir-stamped chat in Home; its cwd alone
+ // would make it a phantom project named after the home dir.
+ it('files a row the backend placed in Home under Home, cwd or not', () => {
+ const stamped = makeCwdSession('/home/me', { id: 'stamped', git_repo_root: null })
+
+ const owners = projectOwnerBySessionId([
+ projectNode({ id: NO_PROJECT_ID, isNoProject: true, sessionIds: ['stamped'] })
+ ])
+
+ expect(sessionBucketId(stamped, projects, owners)).toBe(NO_PROJECT_ID)
+ expect(sessionMatchesProjectFilter(stamped, [NO_PROJECT_ID], projects, owners)).toBe(true)
+ })
})
diff --git a/apps/desktop/src/app/chat/sidebar/projects/workspace-groups.ts b/apps/desktop/src/app/chat/sidebar/projects/workspace-groups.ts
index 716fda43010..31225be9d4b 100644
--- a/apps/desktop/src/app/chat/sidebar/projects/workspace-groups.ts
+++ b/apps/desktop/src/app/chat/sidebar/projects/workspace-groups.ts
@@ -164,9 +164,9 @@ export const NO_PROJECT_ID = '__no_project__'
/**
* A session with nowhere to be placed: no cwd and no recorded repo root. These
- * are the rows the Home bucket owns, and the only ones the live overlay can
- * hand it — a row WITH a cwd that the backend still couldn't place (junk root,
- * deleted workspace) needs the backend's probes, so it waits for the snapshot.
+ * are the rows the Home bucket owns on sight — a row WITH a cwd that the
+ * backend couldn't place (junk root, deleted workspace) needs the backend's
+ * probes, so Home takes it only once the snapshot's owner map files it there.
*/
export const isDetachedSession = (session: SessionInfo): boolean =>
!(session.cwd || '').trim() && !(session.git_repo_root || '').trim()
@@ -487,12 +487,17 @@ export function liveSessionProjectId(
return repoRoot
}
-/** The lane a row files under: its live project, or Home for detached (cwd-less) rows. */
+/** The lane a row files under: Home when the backend filed it there or it is
+ * detached (cwd-less), else its live project. */
export function sessionBucketId(
session: SessionInfo,
explicitProjects: ProjectInfo[],
owners: ReadonlyMap<string, string> = NO_OWNERS
): null | string {
+ if (ownerOf(owners, session) === NO_PROJECT_ID) {
+ return NO_PROJECT_ID
+ }
+
return liveSessionProjectId(session, explicitProjects, owners) ?? (isDetachedSession(session) ? NO_PROJECT_ID : null)
}
@@ -800,11 +805,13 @@ export function overlayRepoLanes(
}
/**
- * Home's overlay: its rows have no cwd to place, so this is a plain upsert of
- * detached live sessions into its single lane — a brand-new project-less chat
- * shows the instant it's created, matching the flat Recents list. A chat the
- * authoritative owner map gives to a named project stays out, even while its
- * live copy is briefly detached (else it lists in both places).
+ * Home's overlay: a plain upsert into its single lane of the live sessions
+ * that are detached or that the owner map already files in Home — a brand-new
+ * project-less chat shows the instant it's created, and a chat the backend put
+ * in Home despite its cwd (the bare home dir, a deleted workspace) shows even
+ * though the unhydrated tree carries only its id (#139909). A chat the owner
+ * map gives to a named project stays out, even while its live copy is briefly
+ * detached (else it lists in both places).
*/
function overlayHomeLane(
project: SidebarProjectTree,
@@ -820,14 +827,18 @@ function overlayHomeLane(
const belongs = (session: SessionInfo): boolean => !removed.has(session.id) && !ownedElsewhere(session)
const lane = project.repos[0]?.groups[0]
- const detached = live.filter(session => isDetachedSession(session) && belongs(session))
+
+ const homed = (session: SessionInfo): boolean =>
+ isDetachedSession(session) || ownerOf(owners, session) === NO_PROJECT_ID
+
+ const arrivals = live.filter(session => homed(session) && belongs(session))
const kept = (lane?.sessions ?? []).filter(belongs)
- if (!detached.length && kept.length === (lane?.sessions.length ?? 0)) {
+ if (!arrivals.length && kept.length === (lane?.sessions.length ?? 0)) {
return project
}
- const sessions = detached.reduce(upsertSession, kept)
+ const sessions = arrivals.reduce(upsertSession, kept)
const nextLane = { id: NO_PROJECT_ID, label: project.label, path: null, sessions }
return {