Skip to content

The agent that grows with you

fix(desktop): keep a worktree lane whose only sessions are pinned

Brooklyn Nicholsonc3a381488524
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 7be1a5df210..7fb7166f9b6 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
@@ -893,7 +893,7 @@ describe('excludeProjectSessions', () => {
expect(filtered.sessionCount).toBe(1)
})
- it('drops a lane the filter emptied, and matching preview rows with it', () => {
+ it('keeps a lane the filter emptied — a worktree is structure, not a row', () => {
const pinnedRow = makeSession('/www/app/wt', { id: 'pinned' })
const project = projectNode({
@@ -913,7 +913,8 @@ describe('excludeProjectSessions', () => {
const filtered = excludeProjectSessions(project, session => session.id === 'pinned')
- expect(filtered.repos[0].groups).toEqual([])
+ expect(filtered.repos[0].groups.map(g => g.id)).toEqual(['wt'])
+ expect(filtered.repos[0].groups[0].sessions).toEqual([])
expect(filtered.previewSessions).toEqual([])
expect(filtered.sessionCount).toBe(0)
})
@@ -938,4 +939,29 @@ describe('excludeProjectSessions', () => {
expect(excludeProjectSessions(project, () => false)).toBe(project)
})
+
+ it('survives the live overlay: a lane left empty by the filter is not pruned', () => {
+ // The two run in sequence on an entered project (filter, then overlay), and
+ // the overlay drops lanes it empties — it must not take the filter's with it.
+ const pinnedRow = makeSession('/www/app/wt', { id: 'pinned' })
+
+ const project = projectNode({
+ id: '/www/app',
+ repos: [
+ {
+ id: '/www/app',
+ label: 'app',
+ path: '/www/app',
+ sessionCount: 1,
+ groups: [lane({ id: 'wt', label: 'wt', path: '/www/app/wt', sessions: [pinnedRow] })]
+ }
+ ],
+ sessionCount: 1
+ })
+
+ const filtered = excludeProjectSessions(project, session => session.id === 'pinned')
+ const overlaid = overlayLiveLanes(filtered, [], new Set(['someone-else']))
+
+ expect(overlaid.repos[0].groups.map(g => g.id)).toEqual(['wt'])
+ })
})
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 cc2623cd0da..55f36bf99f9 100644
--- a/apps/desktop/src/app/chat/sidebar/projects/workspace-groups.ts
+++ b/apps/desktop/src/app/chat/sidebar/projects/workspace-groups.ts
@@ -497,6 +497,10 @@ export function overlayRepoLanes(
): SidebarWorkspaceTree {
const repoRootKey = pathKey(repo.path)
let changed = false
+ // Lanes that arrived with no rows are not eviction casualties — they're real
+ // structure (a `git worktree list` lane, or one whose sessions are pinned
+ // away). The prune below is only allowed to drop lanes IT emptied.
+ const emptyOnInput = new Set(repo.groups.filter(g => !g.sessions.length).map(g => g.id))
// Snapshot lanes minus anything the user just deleted/archived.
const lanes = repo.groups.map(g => {
@@ -577,7 +581,7 @@ export function overlayRepoLanes(
// Drop lanes emptied by eviction (the server only emits non-empty lanes; the
// git-worktree enhancer re-adds any still-real worktree as an empty lane).
- const groups = sortWorktreeGroups(lanes.filter(g => g.sessions.length > 0))
+ const groups = sortWorktreeGroups(lanes.filter(g => g.sessions.length > 0 || emptyOnInput.has(g.id)))
return { ...repo, groups, sessionCount: groups.reduce((n, g) => n + g.sessions.length, 0) }
}
@@ -615,8 +619,13 @@ function overlayHomeLane(
* project subtree, recounting as lanes shrink. Used to keep pinned sessions out
* of the project lists: a pin belongs to the Pinned section, not to both. The
* predicate — rather than an id set — lets the caller match a pin on its
- * durable lineage-root id as well as the live one. Memo-stable: returns the
- * same ref when nothing matched.
+ * durable lineage-root id as well as the live one.
+ *
+ * Lanes SURVIVE being emptied. A worktree is structure (it exists on disk, you
+ * can still start work in it); pinning its last chat must not delete the branch
+ * from the tree — same reason the `git worktree list` enhancer injects lanes
+ * that never had a session. Only the rows move. Memo-stable: returns the same
+ * ref when nothing matched.
*/
export function excludeProjectSessions(
project: SidebarProjectTree,
@@ -627,17 +636,16 @@ export function excludeProjectSessions(
const repos = project.repos.map(repo => {
let repoChanged = false
- const groups = repo.groups.flatMap(group => {
+ const groups = repo.groups.map(group => {
const sessions = group.sessions.filter(session => !isExcluded(session))
if (sessions.length === group.sessions.length) {
- return [group]
+ return group
}
repoChanged = true
- // A lane emptied by the filter has nothing left to show.
- return sessions.length ? [{ ...group, sessions }] : []
+ return { ...group, sessions }
})
if (!repoChanged) {
diff --git a/apps/desktop/src/app/chat/sidebar/sessions-section.tsx b/apps/desktop/src/app/chat/sidebar/sessions-section.tsx
index b880eb87a92..8cd060bb02a 100644
--- a/apps/desktop/src/app/chat/sidebar/sessions-section.tsx
+++ b/apps/desktop/src/app/chat/sidebar/sessions-section.tsx
@@ -197,7 +197,14 @@ export function SidebarSessionsSection({
// A defined project list is itself content (even an empty project should
// render as a drill-in row so the user can see it exists).
const hasProjectOverview = Boolean(projectOverview?.length)
- const hasProjectContent = Boolean(projectContent && projectContent.sessionCount > 0)
+
+ // Lanes count as content even with no rows left in them: the backend only
+ // emits a lane that has sessions, so a lane surviving with zero rows means
+ // they were filtered out (pinned) — the branch is real and must still render.
+ // A genuinely empty project has no lanes at all and keeps its empty state.
+ const hasProjectContent = Boolean(
+ projectContent && (projectContent.sessionCount > 0 || projectContent.repos.some(repo => repo.groups.length > 0))
+ )
const showEmptyState =
forceEmptyState || (!hasGroupedSessions && !hasProjectOverview && !hasProjectContent && sessions.length === 0)