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

Method materializeReservedTaskWorkspace

src/node/services/taskService.ts:2612–2680  ·  view source on GitHub ↗
(
    plan: TaskLaunchPlan,
    sourceRuntime: Runtime,
    initLogger: InitLogger
  )

Source from the content-addressed store, hash-verified

2610 }
2611
2612 private async materializeReservedTaskWorkspace(
2613 plan: TaskLaunchPlan,
2614 sourceRuntime: Runtime,
2615 initLogger: InitLogger
2616 ): Promise<MaterializedTaskLaunch | null> {
2617 const entry = findWorkspaceEntry(this.config.loadConfigOrDefault(), plan.taskId);
2618 if (entry?.workspace.taskStatus !== "starting") {
2619 return null;
2620 }
2621
2622 const existing = await this.getExistingMaterializedTaskLaunch(
2623 plan,
2624 sourceRuntime,
2625 entry.workspace
2626 );
2627 if (existing) {
2628 taskQueueDebug("TaskService.startReservedAgentTask reusing materialized workspace", {
2629 taskId: plan.taskId,
2630 workspacePath: existing.workspacePath,
2631 });
2632 return existing;
2633 }
2634
2635 const projectPath = stripTrailingSlashes(plan.parentMeta.projectPath);
2636 return await this.runProjectForkExclusive(projectPath, async () => {
2637 const entryBeforeFork = findWorkspaceEntry(this.config.loadConfigOrDefault(), plan.taskId);
2638 if (entryBeforeFork?.workspace.taskStatus !== "starting") {
2639 return null;
2640 }
2641
2642 const forkResult = await orchestrateFork({
2643 sourceRuntime,
2644 projectPath: plan.parentMeta.projectPath,
2645 sourceWorkspaceName: plan.parentMeta.name,
2646 newWorkspaceName: plan.workspaceName,
2647 initLogger,
2648 config: this.config,
2649 sourceWorkspaceId: plan.parentWorkspaceId,
2650 sourceRuntimeConfig: plan.parentRuntimeConfig,
2651 parentMetadata: plan.parentMeta,
2652 allowCreateFallback: true,
2653 ...(plan.preferredTrunkBranch != null
2654 ? { preferredTrunkBranch: plan.preferredTrunkBranch }
2655 : {}),
2656 trusted:
2657 this.config
2658 .loadConfigOrDefault()
2659 .projects.get(stripTrailingSlashes(plan.parentMeta.projectPath))?.trusted ?? false,
2660 multiProjectExperimentEnabled: this.workspaceService.isExperimentEnabled(
2661 EXPERIMENT_IDS.MULTI_PROJECT_WORKSPACES
2662 ),
2663 });
2664
2665 if (!forkResult.success) {
2666 throw new Error(`Task fork failed: ${forkResult.error}`);
2667 }
2668
2669 return {

Callers 1

Calls 9

findWorkspaceEntryFunction · 0.90
taskQueueDebugFunction · 0.90
stripTrailingSlashesFunction · 0.90
orchestrateForkFunction · 0.90
loadConfigOrDefaultMethod · 0.80
getMethod · 0.65
isExperimentEnabledMethod · 0.65

Tested by

no test coverage detected