Repository navigation
Description
New Chat Editor opens a broken editor when the remembered session type belongs to a remote agent host that isn't available in the current window.
VS Code remembers the last session type picked in the chat session-type picker (chat.userSelectedSessionType), and Chat: New Chat Editor reuses it. The storage is profile-wide, so a remote agent host type picked in one window (for example a Copilot CLI session on a host configured with chat.workspaceRemoteAgentHosts) is also used in windows that don't have that host, such as an empty window. There, New Chat Editor opens a blank untitled-<uuid> tab showing "The editor could not be opened due to an unexpected error", and the log shows:
Error: Unable to resolve resource remote-hex-3132372e302e302e313a383132332f6578616d706c652d686f7374-copilotcli:/untitled-<uuid>
at TextModelResolverService.doCreateReferencedObject
at TextResourceEditorInput.resolve
...
at ChatWidgetService.openSession
No chat editor is registered for that scheme in this window, so the URI falls through to a plain TextResourceEditorInput, and the text model resolver has no provider for it.
Cause
isNewChatSessionTypeUsable accepts any agent host session type as long as the agent host is enabled, without checking that this window actually has the remote host:
vscode/src/vs/workbench/contrib/chat/common/constants.ts
Lines 527 to 529 in 3ee7c48
| if (isAgentHostTarget(sessionType)) { | |
| return agentHostEnabled; | |
| } |
if (isAgentHostTarget(sessionType)) {
return agentHostEnabled;
}Remote agent hosts register a chat session contribution for each connected agent (remoteAgentHostChatContribution.ts). Requiring that contribution for remote-* types makes the remembered selection fall back to the computed default:
if (isAgentHostTarget(sessionType)) {
return agentHostEnabled && (!isRemoteAgentHostTarget(sessionType) || !!chatSessionsService.getChatSessionContribution(sessionType));
}Steps to reproduce
- In a window that has a remote agent host, pick a remote session type (for example Copilot CLI on that host) in the session-type picker.
- Open a window that doesn't have this host, for example an empty window.
- Run Chat: New Chat Editor.
Automated repro (insiders.vscode.dev)
The script below reproduces it on insiders.vscode.dev with mocked state. Opening /tunnel/<name> gives the window a remote authority, which is what enables the agent host on the web (webAgentHostEnablementService.ts). No tunnel actually exists, so the window has no remote agent hosts. The script stores a remote session type in chat.userSelectedSessionType, reloads, and runs Chat: New Chat Editor.
node repro.mjs: printsREPRODUCED(blankuntitled-…tab, error placeholder,Unable to resolve resourcein the console).node repro.mjs --patched: rewrites the minifiedisNewChatSessionTypeUsableinworkbench.web.main.internal.jswhile it loads, using the fix above. A Local chat editor opens and it printsNOT REPRODUCED.
Requires npm i playwright.
repro.mjs
// Repro: "New Chat Editor" opens a remembered remote agent host session type
// whose host is not configured in this window, failing with
// "Unable to resolve resource remote-...-copilotcli:/untitled-...".
import { chromium } from 'playwright';
import { mkdtempSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
const url = process.argv.slice(2).find(a => !a.startsWith('--')) ?? 'https://insiders.vscode.dev/tunnel/fake-repro-host';
const out = new URL('.', import.meta.url).pathname.replace(/^\/(\w:)/, '$1');
const hex = Buffer.from('127.0.0.1:8123/example-host').toString('hex');
const rememberedType = `remote-hex-${hex}-copilotcli`;
const context = await chromium.launchPersistentContext(mkdtempSync(join(tmpdir(), 'repro-')), { viewport: { width: 1400, height: 900 } });
if (process.argv.includes('--patched')) {
// Same hotfix as applied to the installed desktop bundles.
await context.route(/workbench\.web\.main\.internal\.js$/, async route => {
const response = await route.fetch();
const body = await response.text();
const pattern = /(\?\.hideFromSessionTypePicker\?!1:s===\w+\?\w+\(o,t,i&&n\):\w+\(s\)\?)i:/g;
const count = body.match(pattern)?.length ?? 0;
console.log(`patched ${count} occurrence(s)`);
await route.fulfill({ response, body: body.replace(pattern, '$1i&&(!s.startsWith("remote-")||!!e.getChatSessionContribution(s)):') });
});
}
const page = context.pages()[0] ?? await context.newPage();
const logs = [];
page.on('console', m => logs.push(`[${m.type()}] ${m.text()}`));
const t0 = Date.now();
page.on('framenavigated', f => { if (f === page.mainFrame()) console.log(`nav at ${Date.now() - t0}ms`); });
const waitWorkbench = () => page.waitForSelector('.monaco-workbench', { timeout: 90000 });
await page.goto(url);
// The tunnel page navigates once more right after its first load.
await page.waitForTimeout(5000);
await waitWorkbench();
// Mock: the profile remembers a session type of a remote agent host that this window does not have.
await page.evaluate(([key, value]) => new Promise((resolve, reject) => {
const req = indexedDB.open('vscode-web-state-db-global');
req.onerror = () => reject(req.error);
req.onsuccess = () => {
const tx = req.result.transaction('ItemTable', 'readwrite');
tx.objectStore('ItemTable').put(value, key);
tx.oncomplete = () => resolve();
tx.onerror = () => reject(tx.error);
};
}), ['chat.userSelectedSessionType', rememberedType]);
await page.reload();
await waitWorkbench();
// The fake tunnel asks for the tunnel's account type; dismiss it so it does not replace the command palette.
await page.locator('.quick-input-widget input[placeholder^="What type of account"]').waitFor({ timeout: 60000 });
console.log(`account picker at ${Date.now() - t0}ms`);
await page.keyboard.press('Escape');
// Cancelling shows a modal "requires a reload" dialog; close it without reloading.
await page.locator('.monaco-dialog-box').waitFor({ timeout: 15000 });
await page.locator('.monaco-dialog-box a.codicon-dialog-close').click();
await page.waitForTimeout(3000);
await page.screenshot({ path: `${out}after-escape.png` });
console.log(`F1 at ${Date.now() - t0}ms`);
await page.keyboard.press('F1');
await page.keyboard.type('New Chat Editor');
// The fake tunnel's connection UI can steal focus and close a slow palette; accept the focused exact row immediately.
await page.locator('.quick-input-list .monaco-list-row.focused[aria-label^="Chat: New Chat Editor,"]').waitFor({ state: 'attached', timeout: 15000 });
await page.keyboard.press('Enter');
await page.waitForTimeout(5000);
await page.screenshot({ path: `${out}repro${process.argv.includes('--patched') ? '-patched' : ''}.png` });
const tabs = await page.$$eval('.tabs-container .tab', ts => ts.map(t => t.getAttribute('aria-label')));
const placeholder = await page.evaluate(() => document.querySelector('.monaco-editor-pane-placeholder')?.textContent?.trim());
const errors = logs.filter(l => l.includes('Unable to resolve resource'));
console.log(JSON.stringify({ rememberedType, tabs, placeholder, errors: errors.map(e => e.split('\n')[0]) }, null, 2));
console.log(errors.length && placeholder ? 'REPRODUCED' : 'NOT REPRODUCED');
await context.close();Version: 1.145.0-insider, commit cd2259bdf72ec7421e70ae80999ceb46f8bd86fe (Windows desktop and insiders.vscode.dev). The code is unchanged on main at 3ee7c48cab066143744a42040d2778d5b4dc690f.
Activity