Conversation
…Observer optimization PR #312317 made MenuWorkbenchToolBar use IntersectionObserver to only subscribe to menu change events while the container is visible. This broke the account widget in the Agent Sessions titlebar because both registerAction2 calls were inside AccountWidgetContribution (WorkbenchPhase.AfterRestored). By the time the contribution ran, the TitleBarRightLayout toolbar container was already has-no-actions class), the observer had fired with isIntersecting:false, and it had stopped listening. The late-registered menu items were never picked up. Fix: move registerAction2 calls to module level so the actions are present in Menus.TitleBarRightLayout when MenuWorkbenchToolBar first renders. The container has items from the start, stays visible, and the IntersectionObserver keeps the subscription active so subsequent actionViewItemService changes are picked up. The actionViewItemService.register calls remain inside the contribution since they require instantiationService. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
c853472 to
5d6a04f
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a regression in the Agents Sessions window where the account widget (avatar/sign-in) could remain missing from the desktop titlebar after the MenuWorkbenchToolBar visibility-based (IntersectionObserver) subscription optimization.
Changes:
- Registers the two titlebar widget actions (
SessionsTitleBarUpdateWidgetAction,SessionsTitleBarAccountWidgetAction) at module load soMenus.TitleBarRightLayoutis non-empty on first render. - Keeps
IActionViewItemService.register(...)insideAccountWidgetContribution, wiring the created widget instances to module-level variables so the actions can dispatch to the instantiated widgets.
Show a summary per file
| File | Description |
|---|---|
| src/vs/sessions/contrib/accountMenu/browser/account.contribution.ts | Moves titlebar action registration to module scope and bridges action execution to late-instantiated custom titlebar widgets. |
Copilot's findings
Comments suppressed due to low confidence (2)
src/vs/sessions/contrib/accountMenu/browser/account.contribution.ts:807
- This fix relies on the timing of these
registerAction2calls (the actions must already be present inMenus.TitleBarRightLayoutbefore the toolbar is created). Consider adding a small unit test (similar tosessions/test/browser/layoutActions.test.ts) that imports this module and assertsMenuRegistry.getMenuItems(Menus.TitleBarRightLayout)containssessions.action.titleBarUpdateWidgetandsessions.action.titleBarAccountWidget, to prevent regressions from future refactors/optimizations.
constructor() {
super({
id: SessionsTitleBarUpdateWidgetAction,
title: localize2('agentsUpdateTitleBar', "Agents Update"),
menu: {
id: Menus.TitleBarRightLayout,
group: 'navigation',
order: 99,
when: ContextKeyExpr.and(IsAuxiliaryWindowContext.toNegated(), SessionsWelcomeVisibleContext.toNegated()),
}
});
}
run(): void { }
});
registerAction2(class extends Action2 {
constructor() {
super({
id: SessionsTitleBarAccountWidgetAction,
title: localize2('agentsAccountStatusTitleBar', "Agents Account and Status"),
menu: {
id: Menus.TitleBarRightLayout,
group: 'navigation',
order: 100,
when: IsAuxiliaryWindowContext.toNegated(),
}
});
}
run(): void { }
});
class AccountWidgetContribution extends Disposable implements IWorkbenchContribution {
static readonly ID = 'workbench.contrib.sessionsWidget';
src/vs/sessions/contrib/accountMenu/browser/account.contribution.ts:770
- Registering these commands at module load means the titlebar right toolbar can render them before
AccountWidgetContributionruns (it’s stillWorkbenchPhase.AfterRestored). UntilactionViewItemService.register(...)executes,MenuWorkbenchToolBarwill fall back to default action view items, which likely shows a plain "Agents Update" / "Agents Account and Status" entry and won’t apply the update widget’s hide/busy styling. Consider moving theactionViewItemService.register(...)setup to an earlier phase (e.g. BlockStartup/Ready) so the custom view items are available on the toolbar’s first render, or otherwise ensure these actions don’t surface as generic buttons before the widgets are registered.
// The actual widget rendering and interaction is handled by TitleBarUpdateWidget /
// TitleBarAccountWidget, which are custom view items registered via IActionViewItemService
// in AccountWidgetContribution. Those widgets attach their own DOM click handlers, so
// run() here is intentionally a no-op.
registerAction2(class extends Action2 {
- Files reviewed: 1/1 changed files
- Comments generated: 1
rebornix
approved these changes
Apr 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the account widget (avatar/sign-in button) disappearing from the Agent Sessions desktop titlebar after PR #312317.
Root Cause
PR #312317 introduced an
IntersectionObserveroptimization inMenuWorkbenchToolBarthat only subscribes toIMenu.onDidChangeandIActionViewItemService.onDidChangewhile the toolbar container is visible (isIntersecting === true).This created a chicken-and-egg deadlock for
Menus.TitleBarRightLayout:.titlebar-right-layout-containerstarts with CSSdisplay: none(empty menu →.has-no-actionsclass)registerAction2calls for the account/update actions lived insideAccountWidgetContribution(WorkbenchPhase.AfterRestored)AccountWidgetContributionran, theIntersectionObserverhad already fired withisIntersecting: falseand unsubscribed from menu changesThe session actions toolbar (Run, Terminal, Open in VS Code) was unaffected because its actions are all registered at module level and are present during the toolbar's first render.
Fix
Move the two
registerAction2calls to module level so both actions exist inMenus.TitleBarRightLayoutwhenMenuWorkbenchToolBarfirst calls_updateToolbar(). The container has items from the start, remains visible, and theIntersectionObserverstays subscribed — so the subsequentactionViewItemService.registercalls fromAccountWidgetContribution(which requireinstantiationService) are correctly picked up and trigger a toolbar rebuild with the custom widgets.The
actionViewItemService.registercalls remain inside the contribution. Module-level variables (_updateWidget,_accountWidget) bridge the dispatch from the module-levelrun()methods to the widget instances once they're created.