From fade5c65bb80c233ba87c2d3cd8d9fe5093fd79e Mon Sep 17 00:00:00 2001 From: Osvaldo Ortega Date: Tue, 24 Mar 2026 19:57:38 -0700 Subject: [PATCH] fix: prevent re-entrancy during tree model updates in AgentSessionsControl --- .../agentSessions/agentSessionsControl.ts | 26 ++++++++----------- .../agentSessions/agentSessionsViewer.ts | 12 --------- 2 files changed, 11 insertions(+), 27 deletions(-) diff --git a/src/vs/workbench/contrib/chat/browser/agentSessions/agentSessionsControl.ts b/src/vs/workbench/contrib/chat/browser/agentSessions/agentSessionsControl.ts index 6332d3fb12e..e11b2b2062d 100644 --- a/src/vs/workbench/contrib/chat/browser/agentSessions/agentSessionsControl.ts +++ b/src/vs/workbench/contrib/chat/browser/agentSessions/agentSessionsControl.ts @@ -344,11 +344,12 @@ export class AgentSessionsControl extends Disposable implements IAgentSessionsCo const step = () => { const elapsed = Date.now() - start; const progress = Math.min(elapsed / duration, 1); - // Ease-out curve const eased = 1 - Math.pow(1 - progress, 2); const currentHeight = Math.round(from + (to - from) * eased); if (list.hasNode(element)) { + isUpdatingHeight = true; list.updateElementHeight(element, currentHeight); + isUpdatingHeight = false; } if (progress < 1) { return requestAnimationFrame(step); @@ -404,22 +405,17 @@ export class AgentSessionsControl extends Disposable implements IAgentSessionsCo ); }; - // Listen to tree model changes — rebuild the section map - // and re-acquire the expanded element reference if still valid + // Listen to tree model changes — rebuild the section map. + // Use a flag to avoid re-entrancy since updateElementHeight + // triggers model changes. + let isUpdatingHeight = false; this._register(list.onDidChangeModel(() => { - const previousSectionLabel = expandedSectionLabel; - rebuildSectionMap(); - - // Re-acquire the show-more reference for the previously expanded section - if (previousSectionLabel) { - const newShowMoreItem = sectionToShowMore.get(previousSectionLabel); - if (newShowMoreItem && list.hasNode(newShowMoreItem)) { - expandedShowMoreElement = newShowMoreItem; - } else { - expandedShowMoreElement = undefined; - expandedSectionLabel = undefined; - } + if (isUpdatingHeight) { + return; } + expandedShowMoreElement = undefined; + expandedSectionLabel = undefined; + rebuildSectionMap(); })); // On mouseover, determine section from the hovered element diff --git a/src/vs/workbench/contrib/chat/browser/agentSessions/agentSessionsViewer.ts b/src/vs/workbench/contrib/chat/browser/agentSessions/agentSessionsViewer.ts index fc2f6133f50..750aec65269 100644 --- a/src/vs/workbench/contrib/chat/browser/agentSessions/agentSessionsViewer.ts +++ b/src/vs/workbench/contrib/chat/browser/agentSessions/agentSessionsViewer.ts @@ -406,18 +406,6 @@ export class AgentSessionRenderer extends Disposable implements ICompressibleTre } return Codicon.gitPullRequest; } - - // Fallback: check badge text for PR indicators - const badge = session.badge; - if (badge) { - const badgeText = typeof badge === 'string' ? badge : badge.value; - if (/\bmerged\b/i.test(badgeText) || /\$\(git-merge\)/.test(badgeText)) { - return Codicon.gitMerge; - } - if (/\bPR\s*#\d+/i.test(badgeText) || /\$\(git-pull-request\)/.test(badgeText)) { - return Codicon.gitPullRequest; - } - } } if (!session.isRead() && !session.isArchived()) {