From 07139c673141afb9a20e43e6edf05e1575103757 Mon Sep 17 00:00:00 2001 From: Kacper Sawicki Date: Thu, 10 Jul 2025 11:46:10 +0200 Subject: [PATCH 1/5] Set 'vscode_connection' as build reason on workspace start --- src/api.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/api.ts b/src/api.ts index 22de2618..d5c50a02 100644 --- a/src/api.ts +++ b/src/api.ts @@ -190,6 +190,8 @@ export async function startWorkspaceIfStoppedOrFailed( "start", "--yes", workspace.owner_name + "/" + workspace.name, + "--reason", + "vscode_connection" ]; const startProcess = spawn(binPath, startArgs); From 3c6373bfe15a263441d4570ca068a882b0b83a3a Mon Sep 17 00:00:00 2001 From: Kacper Sawicki Date: Mon, 14 Jul 2025 11:18:19 +0200 Subject: [PATCH 2/5] Fix lint --- src/api.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api.ts b/src/api.ts index d5c50a02..d1154c81 100644 --- a/src/api.ts +++ b/src/api.ts @@ -191,7 +191,7 @@ export async function startWorkspaceIfStoppedOrFailed( "--yes", workspace.owner_name + "/" + workspace.name, "--reason", - "vscode_connection" + "vscode_connection", ]; const startProcess = spawn(binPath, startArgs); From 98414b504132e08e9d725838044bf33073b30da9 Mon Sep 17 00:00:00 2001 From: Kacper Sawicki Date: Tue, 15 Jul 2025 15:03:59 +0200 Subject: [PATCH 3/5] Check cli version before adding --reason flag --- src/api.ts | 10 +++++++--- src/featureSet.ts | 6 ++++++ src/remote.ts | 4 ++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/api.ts b/src/api.ts index d1154c81..5bb46b3c 100644 --- a/src/api.ts +++ b/src/api.ts @@ -16,6 +16,7 @@ import { getHeaderArgs } from "./headers"; import { getProxyForUrl } from "./proxy"; import { Storage } from "./storage"; import { expandPath } from "./util"; +import { FeatureSet } from "./featureSet"; export const coderSessionTokenHeader = "Coder-Session-Token"; @@ -174,6 +175,7 @@ export async function startWorkspaceIfStoppedOrFailed( binPath: string, workspace: Workspace, writeEmitter: vscode.EventEmitter, + featureSet: FeatureSet ): Promise { // Before we start a workspace, we make an initial request to check it's not already started const updatedWorkspace = await restClient.getWorkspace(workspace.id); @@ -189,10 +191,12 @@ export async function startWorkspaceIfStoppedOrFailed( ...getHeaderArgs(vscode.workspace.getConfiguration()), "start", "--yes", - workspace.owner_name + "/" + workspace.name, - "--reason", - "vscode_connection", + workspace.owner_name + "/" + workspace.name ]; + if (featureSet.buildReason) { + startArgs.push(...['--reason', 'vscode_connection']) + } + const startProcess = spawn(binPath, startArgs); startProcess.stdout.on("data", (data: Buffer) => { diff --git a/src/featureSet.ts b/src/featureSet.ts index 958aeae5..21359caa 100644 --- a/src/featureSet.ts +++ b/src/featureSet.ts @@ -4,6 +4,7 @@ export type FeatureSet = { vscodessh: boolean; proxyLogDirectory: boolean; wildcardSSH: boolean; + buildReason: boolean; }; /** @@ -29,5 +30,10 @@ export function featureSetForVersion( wildcardSSH: (version ? version.compare("2.19.0") : -1) >= 0 || version?.prerelease[0] === "devel", + + // --reason flag was added in 2.25.0 + buildReason: + (version?.compare("2.25.0") || 0) >= 0 || + version?.prerelease[0] === "devel", }; } diff --git a/src/remote.ts b/src/remote.ts index 4a13ae56..23363b2d 100644 --- a/src/remote.ts +++ b/src/remote.ts @@ -68,6 +68,7 @@ export class Remote { workspace: Workspace, label: string, binPath: string, + featureSet: FeatureSet ): Promise { const workspaceName = `${workspace.owner_name}/${workspace.name}`; @@ -140,6 +141,7 @@ export class Remote { binPath, workspace, writeEmitter, + featureSet ); break; case "failed": @@ -159,6 +161,7 @@ export class Remote { binPath, workspace, writeEmitter, + featureSet ); break; } @@ -393,6 +396,7 @@ export class Remote { workspace, parts.label, binaryPath, + featureSet ); if (!updatedWorkspace) { // User declined to start the workspace. From 5189b50238e4540324466a0829fe9e45e516dfb3 Mon Sep 17 00:00:00 2001 From: Kacper Sawicki Date: Tue, 15 Jul 2025 16:17:39 +0200 Subject: [PATCH 4/5] Fix lint --- src/api.ts | 8 ++++---- src/remote.ts | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/api.ts b/src/api.ts index 5bb46b3c..063b7ae2 100644 --- a/src/api.ts +++ b/src/api.ts @@ -12,11 +12,11 @@ import * as vscode from "vscode"; import * as ws from "ws"; import { errToStr } from "./api-helper"; import { CertificateError } from "./error"; +import { FeatureSet } from "./featureSet"; import { getHeaderArgs } from "./headers"; import { getProxyForUrl } from "./proxy"; import { Storage } from "./storage"; import { expandPath } from "./util"; -import { FeatureSet } from "./featureSet"; export const coderSessionTokenHeader = "Coder-Session-Token"; @@ -175,7 +175,7 @@ export async function startWorkspaceIfStoppedOrFailed( binPath: string, workspace: Workspace, writeEmitter: vscode.EventEmitter, - featureSet: FeatureSet + featureSet: FeatureSet, ): Promise { // Before we start a workspace, we make an initial request to check it's not already started const updatedWorkspace = await restClient.getWorkspace(workspace.id); @@ -191,10 +191,10 @@ export async function startWorkspaceIfStoppedOrFailed( ...getHeaderArgs(vscode.workspace.getConfiguration()), "start", "--yes", - workspace.owner_name + "/" + workspace.name + workspace.owner_name + "/" + workspace.name, ]; if (featureSet.buildReason) { - startArgs.push(...['--reason', 'vscode_connection']) + startArgs.push(...["--reason", "vscode_connection"]); } const startProcess = spawn(binPath, startArgs); diff --git a/src/remote.ts b/src/remote.ts index 23363b2d..59f04562 100644 --- a/src/remote.ts +++ b/src/remote.ts @@ -68,7 +68,7 @@ export class Remote { workspace: Workspace, label: string, binPath: string, - featureSet: FeatureSet + featureSet: FeatureSet, ): Promise { const workspaceName = `${workspace.owner_name}/${workspace.name}`; @@ -141,7 +141,7 @@ export class Remote { binPath, workspace, writeEmitter, - featureSet + featureSet, ); break; case "failed": @@ -161,7 +161,7 @@ export class Remote { binPath, workspace, writeEmitter, - featureSet + featureSet, ); break; } @@ -396,7 +396,7 @@ export class Remote { workspace, parts.label, binaryPath, - featureSet + featureSet, ); if (!updatedWorkspace) { // User declined to start the workspace. From eee58de1456012d4950a639e9acf118e21eefa12 Mon Sep 17 00:00:00 2001 From: Kacper Sawicki Date: Tue, 22 Jul 2025 13:11:51 +0200 Subject: [PATCH 5/5] Update src/featureSet.ts Co-authored-by: Ethan <39577870+ethanndickson@users.noreply.github.com> --- src/featureSet.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/featureSet.ts b/src/featureSet.ts index 21359caa..67121229 100644 --- a/src/featureSet.ts +++ b/src/featureSet.ts @@ -31,7 +31,7 @@ export function featureSetForVersion( (version ? version.compare("2.19.0") : -1) >= 0 || version?.prerelease[0] === "devel", - // --reason flag was added in 2.25.0 + // The --reason flag was added to `coder start` in 2.25.0 buildReason: (version?.compare("2.25.0") || 0) >= 0 || version?.prerelease[0] === "devel",