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 code/extensions/che-remote/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,22 @@ async function updateDevfile(cheApi: any): Promise<boolean> {
return false;
}

try {
await vscode.commands.executeCommand('che-remote.command.prepareForRestart');
} catch (error) {
// Best-effort: if the signal doesn't reach the browser, the restart
// flow falls back to the normal disconnection handling.
}

try {
await devfileService.updateDevfile(devfileContext.devWorkspace.spec?.template);
} catch (error) {
try {
await vscode.commands.executeCommand('che-remote.command.cancelRestart');
} catch (_) {
// best-effort cleanup
}

if (error.body && error.body.message) {
const action = await vscode.window.showErrorMessage('Failed to update Devfile.', {
modal: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,13 @@ export class DevWorkspaceAssistant {
private static readonly POLL_INTERVAL_MS = 2000;
private static readonly STOP_TIMEOUT_MS = 10000;

private _isStopping = false;
/**
* Tracks the intentional workspace lifecycle action in progress:
* - 'idle': no action, disconnection handler shows normal dialogs
* - 'restartPending': devfile update is about to happen; if extension host dies, redirect to dashboard
* - 'stopping': doRestart/stopWorkspace is running on browser side, handler should not interfere
*/
private _pendingAction: 'idle' | 'restartPending' | 'stopping' = 'idle';
private dashboardUrl: string | undefined;
private getDevWorkspaceUrl: string | undefined;
private startingDevWorkspaceUrl: string | undefined;
Expand All @@ -62,6 +68,12 @@ export class DevWorkspaceAssistant {
CommandsRegistry.registerCommand('che-remote.command.stopWorkspaceAndRedirectToDashboard', () => {
this.stopWorkspaceAndRedirectToDashboard();
});
CommandsRegistry.registerCommand('che-remote.command.prepareForRestart', () => {
this._pendingAction = 'restartPending';
});
CommandsRegistry.registerCommand('che-remote.command.cancelRestart', () => {
this._pendingAction = 'idle';
});
}

async getDevWorkspace(): Promise<DevWorkspaceLike> {
Expand Down Expand Up @@ -193,29 +205,29 @@ export class DevWorkspaceAssistant {
);
}

get isStopping(): boolean {
return this._isStopping;
get pendingAction(): 'idle' | 'restartPending' | 'stopping' {
return this._pendingAction;
}

private async doRestart(): Promise<void> {
this._isStopping = true;
this._pendingAction = 'stopping';
try {
await this.stopWorkspaceViaDashboardApi();
await this.waitForStopped();
this.startWorkspace();
} catch (e) {
this._isStopping = false;
this._pendingAction = 'idle';
throw e;
}
}

async stopWorkspaceAndRedirectToDashboard(): Promise<void> {
this._isStopping = true;
this._pendingAction = 'stopping';
try {
await this.stopWorkspaceViaDashboardApi();
this.goToDashboard();
} catch (e) {
this._isStopping = false;
this._pendingAction = 'idle';
throw e;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,12 @@ export class CheDisconnectionHandler {
return;
}

if (this.devWorkspaceAssistant.isStopping) {
const pendingAction = this.devWorkspaceAssistant.pendingAction;
if (pendingAction === 'restartPending') {
this.devWorkspaceAssistant.startWorkspace();
return;
}
if (pendingAction === 'stopping') {
return;
}

Expand Down