Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,19 @@
from published versions since it shows up in the VS Code extension changelog
tab and is confusing to users. Add it back between releases if needed. -->

## Unreleased

### Added

- Support bundles include the VS Code window log, which records the editor's
remote connection and reconnect attempts.
- When VS Code gives up on the remote connection, the extension offers to
create a support bundle, and offers it again after a reload for up to a day.

### Fixed

- Support bundles include logs from Cursor Glass workspaces.

## [v1.18.4](https://github.com/coder/vscode-coder/releases/tag/v1.18.4) 2026-12-03

### Added
Expand Down
33 changes: 24 additions & 9 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -456,16 +456,19 @@ export class Commands {
});
}

public async supportBundle(target?: WorkspaceTarget): Promise<void> {
await this.diagnosticTelemetry.trace("support_bundle", (telemetry) =>
/** Returns the saved bundle, or undefined if none was created. */
public supportBundle(
target?: WorkspaceTarget,
): Promise<vscode.Uri | undefined> {
return this.diagnosticTelemetry.trace("support_bundle", (telemetry) =>
this.runSupportBundle(target, telemetry),
);
}

private async runSupportBundle(
target: WorkspaceTarget | undefined,
telemetry: DiagnosticTrace,
): Promise<void> {
): Promise<vscode.Uri | undefined> {
const resolved = await this.resolveDiagnosticWorkspace(
target,
"supportBundle",
Expand Down Expand Up @@ -554,14 +557,25 @@ export class Commands {
return;
}

const action = await vscode.window.showInformationMessage(
`Support bundle saved to ${result.value.fsPath}`,
"Reveal in File Explorer",
);
if (action === "Reveal in File Explorer") {
await vscode.commands.executeCommand("revealFileInOS", result.value);
// Not awaited: the notification can close without resolving.
void this.offerToRevealSupportBundle(result.value);
return result.value;
}

private async offerToRevealSupportBundle(bundle: vscode.Uri): Promise<void> {
try {
const action = await vscode.window.showInformationMessage(
`Support bundle saved to ${bundle.fsPath}`,
"Reveal in File Explorer",
);
if (action === "Reveal in File Explorer") {
await vscode.commands.executeCommand("revealFileInOS", bundle);
}
} catch (error) {
this.logger.warn("Could not reveal the support bundle", error);
}
}

private promptSupportBundlePath(): Thenable<vscode.Uri | undefined> {
const defaultName = `coder-support-${Math.floor(Date.now() / 1000)}.zip`;
return vscode.window.showSaveDialog({
Expand All @@ -578,6 +592,7 @@ export class Commands {
"",
"\u2022 Deployment and workspace diagnostics",
"\u2022 Coder extension and connection logs from recent VS Code windows",
"\u2022 VS Code window logs, including remote connection events",
"\u2022 Remote SSH extension logs",
"\u2022 Locally recorded telemetry",
"\u2022 Coder extension settings",
Expand Down
10 changes: 10 additions & 0 deletions src/common/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ import * as path from "node:path";

import type { Logger } from "../logging/logger";

/** Whether a file system call failed because the path does not exist. */
export function isEnoent(error: unknown): boolean {
return (
typeof error === "object" &&
error !== null &&
"code" in error &&
error.code === "ENOENT"
);
}

const transientRenameCodes: ReadonlySet<string> = new Set([
"EPERM",
"EACCES",
Expand Down
137 changes: 137 additions & 0 deletions src/connectionFailure/connectionFailureMonitor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
import * as path from "node:path";
import * as vscode from "vscode";

import { resolveLogContext } from "../supportBundle/logFiles";

import { LogFileReader } from "./logFileReader";
import { parseWindowLogLine, type WindowLogEvent } from "./windowLog";

import type { SshTelemetry } from "../instrumentation/ssh";
import type { Logger } from "../logging/logger";

export type ConnectionFailure = Exclude<
WindowLogEvent,
"extension_host_restarted"
>;

export interface ConnectionFailureMonitorOptions {
readonly codeLogDir: string;
readonly telemetry: SshTelemetry;
readonly logger: Logger;
}

/**
* VS Code waits up to 2s for the extension host's exit info before it logs a restart:
* https://github.com/microsoft/vscode/blob/e54c42b3917fa85e6f8e7c1eef3853f4db66cef6/src/vs/workbench/services/extensions/common/abstractExtensionService.ts#L899-L925
*/
const EXTENSION_HOST_RESTART_WAIT_MS = 3000;
const POLL_INTERVAL_MS = 250;

/**
* Watches the window log and fires `onDidFail` once, when VS Code gives up on
* the remote connection.
*/
export class ConnectionFailureMonitor implements vscode.Disposable {
private readonly failEmitter = new vscode.EventEmitter<ConnectionFailure>();
public readonly onDidFail = this.failEmitter.event;

private disposed = false;
private timer: NodeJS.Timeout | undefined;
private extensionHostLostAt: number | undefined;
private readFailing = false;

private constructor(
private readonly options: ConnectionFailureMonitorOptions,
) {}

public static start(
options: ConnectionFailureMonitorOptions,
): ConnectionFailureMonitor {
const monitor = new ConnectionFailureMonitor(options);
const logContext = resolveLogContext(options.codeLogDir);
if (logContext) {
const logPath = path.join(logContext.currentWindowPath, "renderer.log");
void monitor.poll(new LogFileReader(logPath));
} else {
options.logger.debug(
"Unrecognized log directory layout; not monitoring connection failures",
);
}
return monitor;
}

public dispose(): void {
this.disposed = true;
clearTimeout(this.timer);
this.failEmitter.dispose();
}

private async poll(reader: LogFileReader): Promise<void> {
const lines = await this.readNewLines(reader);
if (this.disposed) {
return;
}
const failure = this.findFailure(lines);
if (failure) {
this.fail(failure);
} else {
this.timer = setTimeout(() => void this.poll(reader), POLL_INTERVAL_MS);
}
}

/**
* Reads the lines added since the last poll. Never throws: a failed read
* returns no lines, is retried next poll, and is logged once per outage.
*/
private async readNewLines(reader: LogFileReader): Promise<string[]> {
try {
const lines = await reader.readNewLines();
this.readFailing = false;
return lines;
} catch (error) {
if (!this.readFailing) {
this.options.logger.debug(
"Could not read the VS Code window log",
error,
);
}
this.readFailing = true;
return [];
}
}

/**
* A lost extension host only counts as a failure if VS Code does not
* restart it within the wait.
*/
private findFailure(lines: readonly string[]): ConnectionFailure | undefined {
for (const line of lines) {
const event = parseWindowLogLine(line);
if (event === "extension_host_restarted") {
this.extensionHostLostAt = undefined;
} else if (event === "extension_host_connection_lost") {
// Restarts are logged at info level; above it a recovery looks like a failure.
if (vscode.env.logLevel <= vscode.LogLevel.Info) {
this.extensionHostLostAt ??= Date.now();
}
} else if (event) {
return event;
}
}
const lostAt = this.extensionHostLostAt;
return lostAt !== undefined &&
Date.now() - lostAt >= EXTENSION_HOST_RESTART_WAIT_MS
? "extension_host_connection_lost"
: undefined;
}

private fail(failure: ConnectionFailure): void {
const { logger, telemetry } = this.options;
logger.warn(`VS Code gave up on the remote connection: ${failure}`);
// Write out buffered debug logs before a reload can drop them.
logger.flush("remote_connection_failed");
telemetry.connectionFailed(failure);
this.failEmitter.fire(failure);
this.dispose();
}
}
134 changes: 134 additions & 0 deletions src/connectionFailure/connectionFailurePrompt.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
import * as vscode from "vscode";

import { vscodeProposed } from "../vscode/proposed";

import type { CoderApi } from "../api/coderApi";
import type { Logger } from "../logging/logger";
import type { MementoManager } from "../storage/mementoManager";

export interface ConnectionFailurePromptOptions {
readonly safeHostname: string;
readonly remoteAuthority: string;
readonly workspaceName: string;
readonly client: Pick<CoderApi, "getBuildInfo">;
readonly mementoManager: MementoManager;
readonly logger: Logger;
}

/**
* Offers a support bundle after a connection failure. The failure stays
* stored until a bundle is saved or the user dismisses the offer, so the
* next successful connection offers it again.
*/
export class ConnectionFailurePrompt {
public constructor(
private readonly options: ConnectionFailurePromptOptions,
) {}

/**
* Offers a bundle for a failure stored by an earlier window, once VS Code
* connects to the remote. Never throws.
*/
public async offerForPreviousFailure(): Promise<void> {
const { mementoManager, safeHostname, remoteAuthority, workspaceName } =
this.options;
if (mementoManager.getConnectionFailure(safeHostname) !== remoteAuthority) {
return;
}
try {
await this.waitForConnection();
} catch (error) {
this.options.logger.debug(
"Not offering a support bundle for the previous failure; the connection failed",
error,
);
return;
}
this.showPrompt(
`The previous connection to ${workspaceName} failed. Create a support bundle to capture diagnostics?`,
);
}

/**
* Stores the failure, then offers a support bundle if the deployment is
* reachable, since the bundle needs it. Never throws.
*/
public async offerForFailure(): Promise<void> {
const {
client,
mementoManager,
safeHostname,
remoteAuthority,
workspaceName,
logger,
} = this.options;
try {
await mementoManager.setConnectionFailure(safeHostname, remoteAuthority);
} catch (error) {
logger.warn("Could not store the connection failure", error);
}
try {
await client.getBuildInfo();
} catch (error) {
logger.info(
"Deployment is unreachable; offering a support bundle on the next connection",
error,
);
return;
}
this.showPrompt(
`The connection to ${workspaceName} failed. Create a support bundle to capture diagnostics?`,
);
}

/**
* Shows the notification without awaiting it: it can close without
* resolving, which keeps the failure stored for the next connection.
*/
private showPrompt(message: string): void {
void vscodeProposed.window
.showErrorMessage(message, "Create Support Bundle")
.then(
(choice) => this.handleChoice(choice),
(error: unknown) =>
this.options.logger.warn(
"Could not show the support bundle prompt",
error,
),
);
}

/** Keeps the failure stored if the user chose a bundle but none was saved. */
private async handleChoice(choice: string | undefined): Promise<void> {
const { mementoManager, safeHostname, logger } = this.options;
try {
if (choice === "Create Support Bundle") {
const bundle = await vscodeProposed.commands.executeCommand<
vscode.Uri | undefined
>("coder.supportBundle");
if (!bundle) {
return;
}
}
await mementoManager.clearConnectionFailure(safeHostname);
} catch (error) {
logger.warn("Could not create the support bundle", error);
}
}

/**
* Resolves once VS Code is connected, and rejects if it cannot connect.
* VS Code registers the remote file system after its first request over
* the connection, and holds file system calls until then:
* https://github.com/microsoft/vscode/blob/e54c42b3917fa85e6f8e7c1eef3853f4db66cef6/src/vs/workbench/services/remote/common/remoteFileSystemProviderClient.ts#L20-L49
*/
private async waitForConnection(): Promise<void> {
await vscode.workspace.fs.stat(
vscode.Uri.from({
scheme: "vscode-remote",
authority: this.options.remoteAuthority,
path: "/",
}),
);
}
}
Loading
Loading