{"record":{"id":"f63886fe8eb9f7ed","repo":"can1357/oh-my-pi","slug":"could-not-switch-to-resumed-project-resumedcwd","errorCode":null,"errorMessage":"Could not switch to resumed project ${resumedCwd} (${error instanceof Error ? error.message : String(error)}); failed to restore launch directory ${launchCwd}: ${rollbackError instanceof Error ? rollbackError.message : String(rollbackError)}","messagePattern":"Could not switch to resumed project (.+?) \\((.+?)\\); failed to restore launch directory (.+?): (.+?)","errorType":"exception","errorClass":"SessionResolutionError","httpStatus":null,"severity":"critical","filePath":"packages/coding-agent/src/main.ts","lineNumber":779,"sourceCode":"\t\tif (normalizePathForComparison(sessionManager.getCwd()) !== normalizePathForComparison(cwd)) {\n\t\t\tsessionManager.adoptRecordedCwd();\n\t\t}\n\t} catch (error) {\n\t\t// The process cwd is already committed to the target. If rescoping the\n\t\t// cwd-derived state fails, undo the whole transition instead of building\n\t\t// the session with target-scoped cwd and launch-scoped settings.\n\t\tlogger.warn(\"Could not rescope to resumed project directory\", { cwd, error: String(error) });\n\t\ttry {\n\t\t\tsetProjectDir(launchCwd);\n\t\t\tsessionManager.setCwdWithoutRelocation(launchCwd);\n\t\t\tclearPluginRootsAndCaches();\n\t\t\tawait preloadPluginRoots(os.homedir(), launchCwd);\n\t\t\t// Settings.#cwd was already assigned the destination; re-scope it\n\t\t\t// back so path-derived values and project saves target the launch\n\t\t\t// project, not the failed resume target.\n\t\t\tawait activeSettings.reloadForCwd(launchCwd);\n\t\t} catch (rollbackError) {\n\t\t\tthrow new SessionResolutionError(\n\t\t\t\t`Could not switch to resumed project ${resumedCwd} (${error instanceof Error ? error.message : String(error)}); failed to restore launch directory ${launchCwd}: ${rollbackError instanceof Error ? rollbackError.message : String(rollbackError)}`,\n\t\t\t);\n\t\t}\n\t\treturn { cwd: launchCwd, chdirFailed: resumedCwd };\n\t}\n\treturn { cwd };\n}\n\nfunction notifyResumeCwdFallback(parsedArgs: Args, resumedProject: ResumedProjectResult, cwd: string): void {\n\tif (!resumedProject.chdirFailed) return;\n\twriteStartupNotice(\n\t\tparsedArgs,\n\t\t`${chalk.yellow(`Could not switch to resumed project ${resumedProject.chdirFailed}; staying in ${cwd}.`)}\\n`,\n\t);\n}\n\n/**\n * Resolve the effective model allow-list from an explicit `--models` scope or,","sourceCodeStart":761,"sourceCodeEnd":797,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/main.ts#L761-L797","documentation":"switchToResumedProject chdirs into the resumed session's project and reloads settings; if that fails it rolls back to the launch directory. When both the switch AND the rollback fail (rollback includes restoring plugin roots and activeSettings.reloadForCwd), it throws a SessionResolutionError combining the original error and the rollback error.","triggerScenarios":"Resuming a session from another project where (a) chdir/preload into resumedCwd failed (deleted dir, permissions), and (b) restoration of launchCwd also failed (launch dir deleted, settings reload threw).","commonSituations":"Both the original and target project directories were moved/renamed/deleted between sessions; permission changes on project folders; settings file corruption making reloadForCwd throw during rollback.","solutions":["Read the two embedded messages: fix the resumedCwd problem first (recreate the directory or pick a session whose project exists).","Fix the launch directory problem (cd to an existing directory before launching omp).","Check settings files in both directories are readable/valid JSON.","Verify filesystem permissions on both project paths."],"exampleFix":"// before\ncd /old/deleted/project && omp --resume <id-of-session-in-also-deleted-dir>\n// after\ncd /existing/project && omp --resume <id>","handlingStrategy":"try-catch","validationCode":"import * as fsSync from \"node:fs\";\nif (!fsSync.existsSync(launchCwd) || !fsSync.existsSync(resumedCwd)) {\n  console.error(\"Both launch and resume project dirs must exist before resuming across projects.\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  await resumeAcrossProjects(...);\n} catch (err) {\n  if (err.message.startsWith(\"Could not switch to resumed project\")) {\n    // parse both parenthesized causes and fix paths/settings before retrying\n  }\n}","preventionTips":["Launch omp from a stable, existing directory when planning cross-project resumes.","Keep settings files valid and readable in all project roots.","Recreate renamed project paths, or start fresh sessions, instead of resuming into missing dirs."],"tags":["cli","session-resolution","filesystem","settings"],"backgroundTag":"cwd-switch-rollback-failed","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}