Skip to content

The agent that grows with you

fix(desktop): backend claimed-id set is the one owner for live project overlays

teknium1ba94d111e23b
diff --git a/apps/desktop/src/app/chat/sidebar/index.tsx b/apps/desktop/src/app/chat/sidebar/index.tsx
index b7bc8ae140b..2d24ef862ef 100644
--- a/apps/desktop/src/app/chat/sidebar/index.tsx
+++ b/apps/desktop/src/app/chat/sidebar/index.tsx
@@ -163,6 +163,7 @@ import {
PROJECT_PREVIEW_COUNT,
ProjectBackRow,
ProjectMenu,
+ projectOwnerBySessionId,
projectTreeCwd,
reconcileEnteredProjectSessions,
sessionBucketId,
@@ -1050,7 +1051,7 @@ export function ChatSidebar({
enteredProject,
enteredProjectOverlaySessions,
removedSessionIds,
- projectOwnerBySessionId(agentProjectTree)
+ projectOwnerBySessionId(agentProjectTree ?? [])
)
: undefined,
[enteredProject, enteredProjectOverlaySessions, removedSessionIds, agentProjectTree]
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 8484b6909cb..7bdd50ab1b1 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
@@ -616,35 +616,44 @@ describe('sessionProjectColor', () => {
})
describe('overlayLiveLanes', () => {
- it('does not inject a backend-owned sibling worktree session into an ancestor project', () => {
- const sibling = makeCwdSession('/work/repos/app-2/src', { id: 'sibling', git_repo_root: null })
+ // Issue layout: explicit "work" (/work) + explicit "app" (/work/repos/app);
+ // the session's cwd is the SIBLING linked worktree /work/repos/app-2, which
+ // the backend's git common-root probe assigns to "app" while the renderer's
+ // cwd walk alone only finds "work".
+ it.each([null, '/work/repos/app'])(
+ 'entering an ancestor project does not inject a backend-owned sibling worktree session (git_repo_root=%s)',
+ gitRepoRoot => {
+ const sibling = makeCwdSession('/work/repos/app-2', { id: 'sibling', git_repo_root: gitRepoRoot })
+ const ancestor = projectNode({
+ id: 'p_work',
+ path: '/work',
+ repos: [{ id: '/work', label: 'work', path: '/work', groups: [], sessionCount: 0 }]
+ })
+ const appRepo = {
+ id: '/work/repos/app',
+ label: 'app',
+ path: '/work/repos/app',
+ groups: [lane({ id: '/work/repos/app-2', label: 'app-2', path: '/work/repos/app-2', sessions: [] })],
+ sessionCount: 0
+ }
+ // Overview snapshot: the row sits beyond the preview window, so only the
+ // backend's claimed-id set knows the owner.
+ const repo = projectNode({ id: 'p_app', path: '/work/repos/app', previewSessions: [], sessionIds: ['sibling'] })
+ const owners = projectOwnerBySessionId([ancestor, repo])
- const ancestor = projectNode({
- id: 'p_work',
- path: '/work',
- repos: [{ id: '/work', label: 'work', path: '/work', groups: [], sessionCount: 0 }]
- })
+ const enteredAncestor = overlayLiveLanes(ancestor, [sibling], new Set(), owners)
+ const enteredRepo = overlayLiveLanes({ ...repo, repos: [appRepo] }, [sibling], new Set(), owners)
- const repo = projectNode({
- id: 'p_app',
- path: '/work/repos/app',
- repos: [
- {
- id: '/work/repos/app',
- label: 'app',
- path: '/work/repos/app',
- groups: [lane({ id: '/work/repos/app-2', label: 'app-2', path: '/work/repos/app-2', sessions: [sibling] })],
- sessionCount: 1
- }
- ],
- previewSessions: [sibling],
- sessionCount: 1
- })
-
- const overlaid = overlayLiveLanes(ancestor, [sibling], new Set(), projectOwnerBySessionId([ancestor, repo]))
+ expect(enteredAncestor.sessionCount).toBe(0)
+ expect(enteredRepo.repos[0].groups.find(g => g.id === '/work/repos/app-2')?.sessions.map(s => s.id)).toEqual([
+ 'sibling'
+ ])
+ // A row the tree does not know yet (just created) still lands by cwd.
+ const fresh = makeCwdSession('/work/notes', { id: 'fresh', git_repo_root: null })
- expect(overlaid.sessionCount).toBe(0)
- })
+ expect(overlayLiveLanes(ancestor, [fresh], new Set(), owners).sessionCount).toBe(1)
+ }
+ )
it('keeps an overview preview visible when the hydrated drill-in is stale', () => {
const staleHistory = makeCwdSession('/www/app', {
@@ -1116,19 +1125,30 @@ describe('overlayLiveLanes', () => {
})
describe('overlayLivePreviews', () => {
- it('keeps a backend-owned sibling worktree session out of an ancestor preview when git_repo_root is null', () => {
- const sibling = makeCwdSession('/work/repos/app-2/src', { id: 'sibling', git_repo_root: null })
- const ancestor = projectNode({ id: 'p_work', path: '/work', previewSessions: [], sessionCount: 0 })
- const repo = projectNode({ id: 'p_app', path: '/work/repos/app', previewSessions: [sibling], sessionCount: 1 })
+ it.each([null, '/work/repos/app'])(
+ 'shows a backend-owned sibling worktree session only under its repo project (git_repo_root=%s)',
+ gitRepoRoot => {
+ const sibling = makeCwdSession('/work/repos/app-2', { id: 'sibling', git_repo_root: gitRepoRoot })
+ const ancestor = projectNode({ id: 'p_work', path: '/work', previewSessions: [], sessionCount: 0 })
+ const repo = projectNode({
+ id: 'p_app',
+ path: '/work/repos/app',
+ previewSessions: [sibling],
+ sessionCount: 1,
+ sessionIds: ['sibling']
+ })
- const previews = overlayLivePreviews([ancestor, repo], [sibling], [
- makeProject('p_work', ['/work']),
- makeProject('p_app', ['/work/repos/app'])
- ], 3)
+ const previews = overlayLivePreviews(
+ [ancestor, repo],
+ [sibling],
+ [makeProject('p_work', ['/work']), makeProject('p_app', ['/work/repos/app'])],
+ 3
+ )
- expect(previews.p_work).toBeUndefined()
- expect(previews.p_app?.map(session => session.id)).toEqual(['sibling'])
- })
+ expect(previews.p_work).toBeUndefined()
+ expect(previews.p_app?.map(session => session.id)).toEqual(['sibling'])
+ }
+ )
it('merges live sessions into a project preview, live first, capped to the limit', () => {
const project = projectNode({
id: '/www/app',
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 1c91a5acf41..c6ec5f1aacd 100644
--- a/apps/desktop/src/app/chat/sidebar/projects/workspace-groups.ts
+++ b/apps/desktop/src/app/chat/sidebar/projects/workspace-groups.ts
@@ -69,6 +69,9 @@ export interface SidebarProjectTree {
lastActive?: number
// Up to N most-recent sessions for the overview preview (set by `projects.tree`).
previewSessions?: SessionInfo[]
+ // Every session id the backend assigned to this project — the authoritative
+ // owner set the live overlay keys on (complete, unlike `previewSessions`).
+ sessionIds?: string[]
}
/** Path split into segments, ignoring trailing slashes and mixed separators. */
@@ -487,13 +490,15 @@ export function projectOwnerBySessionId(projects: SidebarProjectTree[]): Readonl
const owners = new Map<string, string>()
for (const project of projects) {
- const sessions = [
- ...(project.previewSessions ?? []),
- ...project.repos.flatMap(repo => repo.groups.flatMap(group => group.sessions))
+ const ids = [
+ ...(project.sessionIds ?? []),
+ // Older backends only carry the rows themselves.
+ ...(project.previewSessions ?? []).map(session => session.id),
+ ...project.repos.flatMap(repo => repo.groups.flatMap(group => group.sessions.map(session => session.id)))
]
- for (const session of sessions) {
- owners.set(session.id, project.id)
+ for (const id of ids) {
+ owners.set(id, project.id)
}
}
diff --git a/apps/shared/src/gateway-contract.generated.ts b/apps/shared/src/gateway-contract.generated.ts
index 22abb8c358e..0b077ff69fd 100644
--- a/apps/shared/src/gateway-contract.generated.ts
+++ b/apps/shared/src/gateway-contract.generated.ts
@@ -1958,6 +1958,7 @@ export interface ProjectTreeNode {
totalCostUsd?: number
repos?: ProjectTreeRepo[]
previewSessions?: ProjectTreeSession[]
+ sessionIds?: string[]
}
export interface ProjectTreeRepo {
id: string
diff --git a/apps/shared/src/gateway-contract.openrpc.json b/apps/shared/src/gateway-contract.openrpc.json
index c9bb42c9aab..41f58c7fda3 100644
--- a/apps/shared/src/gateway-contract.openrpc.json
+++ b/apps/shared/src/gateway-contract.openrpc.json
@@ -20770,6 +20770,13 @@
},
"title": "Previewsessions",
"type": "array"
+ },
+ "sessionIds": {
+ "items": {
+ "type": "string"
+ },
+ "title": "Sessionids",
+ "type": "array"
}
},
"required": [
diff --git a/tests/tui_gateway/test_project_tree.py b/tests/tui_gateway/test_project_tree.py
index feaa00ad1b6..a731d2a5e3c 100644
--- a/tests/tui_gateway/test_project_tree.py
+++ b/tests/tui_gateway/test_project_tree.py
@@ -405,6 +405,8 @@ def test_overview_drops_session_rows_but_keeps_counts_and_previews():
assert project["sessionCount"] == 4
assert len(project["previewSessions"]) == 3
+ # The claimed-id set stays complete in overview mode; it is the renderer's ONE owner.
+ assert sorted(project["sessionIds"]) == sorted(s["id"] for s in sessions)
# Lanes carry structure + counts but no rows in overview mode.
assert all(g["sessions"] == [] for repo in project["repos"] for g in repo["groups"])
assert project["repos"][0]["sessionCount"] == 4
diff --git a/tui_gateway/contracts/projects_pets.py b/tui_gateway/contracts/projects_pets.py
index d0d76aeb5af..e90a93bcbb6 100644
--- a/tui_gateway/contracts/projects_pets.py
+++ b/tui_gateway/contracts/projects_pets.py
@@ -273,6 +273,7 @@ class ProjectTreeNode(Result):
totalCostUsd: float = 0.0
repos: list[ProjectTreeRepo] = Field(default_factory=list)
previewSessions: list[ProjectTreeSession] = Field(default_factory=list)
+ sessionIds: list[str] = Field(default_factory=list)
class ProjectsTreeParams(ProfileParams):
diff --git a/tui_gateway/project_tree.py b/tui_gateway/project_tree.py
index 126b99f5392..20f1e8ce11d 100644
--- a/tui_gateway/project_tree.py
+++ b/tui_gateway/project_tree.py
@@ -344,7 +344,11 @@ def _project_node(
(s.get("input_tokens") or 0) + (s.get("output_tokens") or 0) for s in rows),
"totalCostUsd": sum(
float(s.get("actual_cost_usd") or s.get("estimated_cost_usd") or 0) for s in rows),
- "repos": repos, "previewSessions": preview_sessions}
+ "repos": repos, "previewSessions": preview_sessions,
+ # Every claimed row, not just the preview window: the renderer's live overlay
+ # uses this as the ONE owner (a sibling worktree row with git_repo_root NULL
+ # re-classifies to an ancestor project by cwd alone).
+ "sessionIds": [s["id"] for s in rows if s.get("id")]}
node.update(flags)
return node