{"record":{"id":"da0e5adaa9ac3d5c","repo":"multica-ai/multica","slug":"get-working-directory-w","errorCode":null,"errorMessage":"get working directory: %w","messagePattern":"get working directory: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/cmd/multica/cmd_repo.go","lineNumber":350,"sourceCode":"\treturn nil\n}\n\nfunc runRepoCheckout(cmd *cobra.Command, args []string) error {\n\trepoURL := args[0]\n\n\tdaemonPort := os.Getenv(\"MULTICA_DAEMON_PORT\")\n\tif daemonPort == \"\" {\n\t\treturn fmt.Errorf(\"MULTICA_DAEMON_PORT not set (this command is intended to be run by an agent inside a daemon task)\")\n\t}\n\n\tworkspaceID := os.Getenv(\"MULTICA_WORKSPACE_ID\")\n\tagentName := os.Getenv(\"MULTICA_AGENT_NAME\")\n\ttaskID := os.Getenv(\"MULTICA_TASK_ID\")\n\n\t// Use current working directory as the checkout target.\n\tworkDir, err := os.Getwd()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"get working directory: %w\", err)\n\t}\n\n\treqBody := map[string]any{\n\t\t\"url\":           repoURL,\n\t\t\"workspace_id\":  workspaceID,\n\t\t\"workdir\":       workDir,\n\t\t\"ref\":           repoCheckoutRef,\n\t\t\"agent_name\":    agentName,\n\t\t\"task_id\":       taskID,\n\t\t\"checkout_mode\": strings.TrimSpace(os.Getenv(\"MULTICA_REPO_CHECKOUT_MODE\")),\n\t\t\"retry_busy\":    true,\n\t}\n\n\tdata, err := json.Marshal(reqBody)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"encode request: %w\", err)\n\t}\n","sourceCodeStart":332,"sourceCodeEnd":368,"githubUrl":"https://github.com/multica-ai/multica/blob/2c0912b6ec764b373d44eeea1e80f0d9f11ab417/server/cmd/multica/cmd_repo.go#L332-L368","documentation":"runRepoCheckout wraps the error from os.Getwd(), which it calls to pass the current working directory as the checkout target in the request body (\"workdir\" field). os.Getwd fails when the process's working directory has been deleted or the OS cannot determine it (permission loss on a parent directory, unlinked cwd).","triggerScenarios":"The shell or agent process is sitting in a directory that was deleted (common in CI cleanup steps or agents that rm -rf their workdir), or the path to cwd is no longer searchable/executable for the process.","commonSituations":"Agent tasks that delete and recreate their working directory while the CLI still runs from the old inode; containerized runs where the workdir was mounted over or removed; restricted environments revoking execute permission on a parent dir.","solutions":["cd into an existing directory before running the command (in shell: cd \"$PWD\" or cd /tmp first to force re-resolution).","If an agent framework deleted the workdir, recreate it and restart the task.","Check permissions on every parent of the intended workdir (need +x to traverse)."],"exampleFix":"# before: cwd was deleted\nmultica repo checkout https://github.com/acme/api\n\n# after\nmkdir -p /workspace && cd /workspace && multica repo checkout https://github.com/acme/api","handlingStrategy":"validation","validationCode":"wd, err := os.Getwd()\nif err != nil {\n\t// force re-anchoring to a known-good dir before continuing\n\tif err := os.Chdir(os.TempDir()); err != nil {\n\t\treturn fmt.Errorf(\"recover working directory: %w\", err)\n\t}\n\twd, _ = os.Getwd()\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Agents should recreate a deleted workdir and cd into it before running checkout.","Avoid rm -rf of the cwd while commands still execute from it.","Keep +x (traverse) permission on all parents of the working directory."],"tags":["go","filesystem","working-directory","cli"],"backgroundTag":null,"analyzedSha":"2c0912b6ec764b373d44eeea1e80f0d9f11ab417","analyzedAt":"2026-08-15T13:25:18.241Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}