{"record":{"id":"3a69e2acddef13bc","repo":"paperclipai/paperclip","slug":"working-directory-does-not-exist-on-remote-target","errorCode":null,"errorMessage":"Working directory does not exist on remote target: \"${cwd}\"${detail ? ` (${detail})` : \"\"}","messagePattern":"Working directory does not exist on remote target: \"(.+?)\"(.+?)\\)` : \"\"\\}","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/adapter-utils/src/execution-target.ts","lineNumber":1016,"sourceCode":"  const result = await runAdapterExecutionTargetShellCommand(runId, target, script, {\n    cwd: target.kind === \"remote\" ? target.remoteCwd : cwd,\n    env: options.env,\n    timeoutSec: options.timeoutSec ?? 15,\n    graceSec: options.graceSec ?? 5,\n    onLog: options.onLog,\n  });\n\n  if (result.timedOut) {\n    throw new Error(`Timed out checking working directory on remote target: \"${cwd}\"`);\n  }\n  if ((result.exitCode ?? 1) !== 0) {\n    const detail = (result.stderr || result.stdout || \"\").trim();\n    if (createIfMissing) {\n      throw new Error(\n        `Could not create working directory \"${cwd}\" on remote target${detail ? `: ${detail}` : \".\"}`,\n      );\n    }\n    throw new Error(\n      `Working directory does not exist on remote target: \"${cwd}\"${detail ? ` (${detail})` : \"\"}`,\n    );\n  }\n}\n\nexport function adapterExecutionTargetSessionIdentity(\n  target: AdapterExecutionTarget | null | undefined,\n): Record<string, unknown> | null {\n  if (!target || target.kind === \"local\") return null;\n  if (target.transport === \"ssh\") return buildRemoteExecutionSessionIdentity(target.spec);\n  return {\n    transport: \"sandbox\",\n    providerKey: target.providerKey ?? null,\n    environmentId: target.environmentId ?? null,\n    leaseId: target.leaseId ?? null,\n    remoteCwd: target.remoteCwd,\n  };\n}","sourceCodeStart":998,"sourceCodeEnd":1034,"githubUrl":"https://github.com/paperclipai/paperclip/blob/67001ec6eb96ae601aa27bc91d9b2415d665334a/packages/adapter-utils/src/execution-target.ts#L998-L1034","documentation":"Thrown by ensureAdapterExecutionTargetDirectory when createIfMissing is false (the default) and the `[ -d <cwd> ]` check fails on a remote target. The directory does not exist and the caller did not ask to create it, so the operation cannot proceed.","triggerScenarios":"Calling ensureAdapterExecutionTargetDirectory(runId, target, cwd, options) where createIfMissing is false or unset, target.kind === 'remote', and the `[ -d <cwd> ]` shell command exits non-zero.","commonSituations":"The workspace directory was never cloned/created on the remote; a previous workspace setup step failed silently; the lease points to a fresh filesystem where the expected repo checkout is missing; the path is wrong relative to where the workspace was actually created.","solutions":["Pass createIfMissing: true if the directory should be auto-created.","Ensure the workspace clone/checkout step runs before calling ensureAdapterExecutionTargetDirectory.","Verify the cwd path matches where the workspace was actually initialized on the remote.","Check that a prior workspace restore or git sync step did not fail."],"exampleFix":"// before\nawait ensureAdapterExecutionTargetDirectory(runId, target, cwd, {});\n// after\nawait ensureAdapterExecutionTargetDirectory(runId, target, cwd, { createIfMissing: true });","handlingStrategy":"validation","validationCode":"// Check directory existence with a probe before calling\nasync function remoteDirExists(runner: CommandRunner, cwd: string): Promise<boolean> {\n  const result = await runner.execute({\n    command: \"sh\",\n    args: [\"-c\", `[ -d ${cwd} ] && echo yes || echo no`],\n    cwd: \"/\",\n    timeoutMs: 10_000,\n  });\n  return result.stdout.trim() === \"yes\";\n}","typeGuard":null,"tryCatchPattern":"try {\n  await ensureAdapterExecutionTargetDirectory(runId, target, cwd, {});\n} catch (err) {\n  if (err instanceof Error && err.message.includes(\"does not exist on remote target\")) {\n    // Retry with createIfMissing if the workspace should auto-create\n    await ensureAdapterExecutionTargetDirectory(runId, target, cwd, { createIfMissing: true });\n  } else {\n    throw err;\n  }\n}","preventionTips":["Pass createIfMissing: true when the workspace directory may not yet exist.","Ensure the workspace clone/checkout step runs before directory verification.","Log workspace setup steps to diagnose missing directories."],"tags":["filesystem","remote","execution-target","adapter-utils"],"backgroundTag":null,"analyzedSha":"67001ec6eb96ae601aa27bc91d9b2415d665334a","analyzedAt":"2026-08-12T12:05:45.408Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}