MCPcopy
hub / github.com/coder/mux / rollbackFailedTaskCreate

Method rollbackFailedTaskCreate

src/node/services/taskService.ts:3974–4028  ·  view source on GitHub ↗
(
    runtime: Runtime,
    projectPath: string,
    workspaceName: string,
    taskId: string,
    options?: {
      /**
       * Skip physical workspace deletion. Required for isolation: "none" tasks whose runtime
       * resolves this task's name to the shared parent checkout (e.g. SSHRuntime.deleteWorkspace
       * goes through the persisted-path override) — deleting it would destroy the parent's
       * working tree. Session/config cleanup still runs.
       */
      preservePhysicalWorkspace?: boolean;
    }
  )

Source from the content-addressed store, hash-verified

3972 }
3973
3974 private async rollbackFailedTaskCreate(
3975 runtime: Runtime,
3976 projectPath: string,
3977 workspaceName: string,
3978 taskId: string,
3979 options?: {
3980 /**
3981 * Skip physical workspace deletion. Required for isolation: "none" tasks whose runtime
3982 * resolves this task's name to the shared parent checkout (e.g. SSHRuntime.deleteWorkspace
3983 * goes through the persisted-path override) — deleting it would destroy the parent's
3984 * working tree. Session/config cleanup still runs.
3985 */
3986 preservePhysicalWorkspace?: boolean;
3987 }
3988 ): Promise<void> {
3989 try {
3990 await this.config.removeWorkspace(taskId);
3991 } catch (error: unknown) {
3992 log.error("Task.create rollback: failed to remove workspace from config", {
3993 taskId,
3994 error: getErrorMessage(error),
3995 });
3996 }
3997
3998 this.workspaceService.emit("metadata", { workspaceId: taskId, metadata: null });
3999
4000 if (options?.preservePhysicalWorkspace) {
4001 log.debug("Task.create rollback: preserving shared parent checkout", { taskId });
4002 } else {
4003 try {
4004 const deleteResult = await runtime.deleteWorkspace(projectPath, workspaceName, true);
4005 if (!deleteResult.success) {
4006 log.error("Task.create rollback: failed to delete workspace", {
4007 taskId,
4008 error: deleteResult.error,
4009 });
4010 }
4011 } catch (error: unknown) {
4012 log.error("Task.create rollback: runtime.deleteWorkspace threw", {
4013 taskId,
4014 error: getErrorMessage(error),
4015 });
4016 }
4017 }
4018
4019 try {
4020 const sessionDir = this.config.getSessionDir(taskId);
4021 await fsPromises.rm(sessionDir, { recursive: true, force: true });
4022 } catch (error: unknown) {
4023 log.error("Task.create rollback: failed to remove session directory", {
4024 taskId,
4025 error: getErrorMessage(error),
4026 });
4027 }
4028 }
4029
4030 private isForegroundAwaiting(workspaceId: string): boolean {
4031 const count = this.foregroundAwaitCountByWorkspaceId.get(workspaceId);

Callers 1

createMethod · 0.95

Calls 6

getErrorMessageFunction · 0.90
debugMethod · 0.80
emitMethod · 0.65
deleteWorkspaceMethod · 0.65
getSessionDirMethod · 0.65
removeWorkspaceMethod · 0.45

Tested by

no test coverage detected