Skip to content

fix(chat): guard agent-sessions reveal against transient tree-map desync (#309891)#310831

Open
maruthang wants to merge 2 commits intomicrosoft:mainfrom
maruthang:fix/issue-309891-agent-sessions-view-tree-error
Open

fix(chat): guard agent-sessions reveal against transient tree-map desync (#309891)#310831
maruthang wants to merge 2 commits intomicrosoft:mainfrom
maruthang:fix/issue-309891-agent-sessions-view-tree-error

Conversation

@maruthang
Copy link
Copy Markdown
Contributor

@maruthang maruthang commented Apr 16, 2026

WhatAsyncDataTree.getRelativeTop() no longer throws TreeError [...] Tree element not found during transient async-refresh races; it now returns null (the existing "not currently visible" semantic), so all consumers automatically get safe behavior.

Why — Originally guarded only at the AgentSessionsControl call site. Per @bpasero's review feedback, the fix belongs in the underlying base widget — every consumer of AsyncDataTree.getRelativeTop() would otherwise have to repeat the same try/catch when paired with hasNode().

AsyncDataTree.hasNode() consults this.nodes (the JS-side map). AsyncDataTree.getRelativeTop() calls this.getDataNode() and then the underlying tree model's getRelativeTop(), which consults a different map (compressedObjectTreeModel's nodes). During refreshAndRenderNode() there is a microtask gap where one map is updated and the other isn't, so hasNode() can return true while the deeper call throws TreeError [...] Tree element not found (#309891, 51 hits / 28 users).

HowAsyncDataTree.getRelativeTop() now wraps the underlying call in try/catch. On TreeError it returns null (matching the existing semantic for "not visible"); other errors continue to propagate. Reverted the call-site tryGetRelativeTop workaround in agentSessionsControl.ts — the call site is back to its upstream baseline.

Test plan — Manual: trigger the race by switching active editors while the agent-sessions list is mid-refresh. Pre-fix this reliably throws the TreeError when hit; post-fix the error is absorbed and the existing reveal(…, 0.5) fallback runs. No unit test added — reproducing the race deterministically requires driving AsyncDataTree.refreshAndRenderNode() across its await boundary, which would need a substantial harness.

Fixes #309891

@bpasero
Copy link
Copy Markdown
Member

bpasero commented Apr 17, 2026

I would prefer a change on the underlying base widget as it seems wrong every user of the API has to account for this.

cc @benibenj

microsoft#309891)

Per @bpasero's review on microsoft#310831 — moving the guard from the
agentSessionsControl call site into the underlying base widget so all
AsyncDataTree consumers benefit.

During an async refresh there is a microtask gap where AsyncDataTree.nodes
(consulted by hasNode) and the underlying tree model's node map can be out
of sync, so getDataNode or tree.getRelativeTop can throw TreeError even
though hasNode returned true.

Treat that transient TreeError as "not currently visible" by returning
null — consistent with the existing semantic that null means the element
is in the data source but not in view, so callers fall back to reveal()
which is safe to call across the gap.

Reverts the call-site try/catch in agentSessionsControl now that the base
widget handles it.
@maruthang
Copy link
Copy Markdown
Contributor Author

Thanks @bpasero — agreed. Moved the guard into AsyncDataTree.getRelativeTop() itself (it returns null on TreeError, consistent with the existing 'not currently visible' semantic) and reverted the call-site tryGetRelativeTop workaround so agentSessionsControl.ts is back to its upstream baseline. Now every consumer of AsyncDataTree paired with hasNode is automatically safe across the async-refresh gap. cc @benibenj

@vs-code-engineering
Copy link
Copy Markdown
Contributor

📬 CODENOTIFY

The following users are being notified based on files changed in this PR:

@joaomoreno

Matched files:

  • src/vs/base/browser/ui/tree/asyncDataTree.ts

@benibenj

Matched files:

  • src/vs/base/browser/ui/tree/asyncDataTree.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Unhandled Error] TreeError [AgentSessionsView] Tree element not found: [object Object]

2 participants