Skip to content

The agent that grows with you

fix(desktop): preserve lane session recency order

Mustafad40dda7db6c5
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 931a4dad5c6..ccea21f80a8 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
@@ -768,6 +768,50 @@ describe('overlayLiveLanes', () => {
expect(groups[0].sessions.map(s => s.id).sort()).toEqual(['fresh', 'old'])
})
+ it('preserves backend recency order when live sessions overlay a lane', () => {
+ const recentlyActive = makeSession('/www/app', {
+ id: 'recently-active',
+ git_branch: 'main',
+ started_at: 1,
+ last_active: 3
+ })
+
+ const newlyCreated = makeSession('/www/app', {
+ id: 'newly-created',
+ git_branch: 'main',
+ started_at: 2,
+ last_active: 2
+ })
+
+ const project = projectNode({
+ id: '/www/app',
+ repos: [
+ {
+ id: '/www/app',
+ label: 'app',
+ path: '/www/app',
+ sessionCount: 2,
+ groups: [
+ lane({
+ id: '/www/app::branch::main',
+ label: 'main',
+ isMain: true,
+ path: '/www/app',
+ sessions: [recentlyActive, newlyCreated]
+ })
+ ]
+ }
+ ]
+ })
+
+ const overlaid = overlayLiveLanes(project, [recentlyActive, newlyCreated])
+
+ expect(overlaid.repos[0].groups[0].sessions.map(session => session.id)).toEqual([
+ 'recently-active',
+ 'newly-created'
+ ])
+ })
+
it('adds a new session to an existing worktree lane keyed by a divergent id (matches by path)', () => {
// Backend keyed the worktree lane off a branch-style id (no live git probe),
// but the lane PATH is the worktree dir. A new session under that worktree
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 52370653baa..605ce38eef7 100644
--- a/apps/desktop/src/app/chat/sidebar/projects/workspace-groups.ts
+++ b/apps/desktop/src/app/chat/sidebar/projects/workspace-groups.ts
@@ -449,7 +449,7 @@ export function sessionProjectColor(session: SessionInfo, projects: ProjectInfo[
}
const upsertSession = (rows: SessionInfo[], session: SessionInfo): SessionInfo[] =>
- [session, ...rows.filter(row => row.id !== session.id)].sort((a, b) => b.started_at - a.started_at)
+ [session, ...rows.filter(row => row.id !== session.id)].sort((a, b) => sessionRecency(b) - sessionRecency(a))
/**
* The lane a live session belongs to WITHIN a known repo root, by path — the