can1357/oh-my-pi · critical · SessionResolutionError

Could not switch to resumed project ${resumedCwd} (${error i

Error message

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)}

What it means

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.

Source

Thrown at packages/coding-agent/src/main.ts:779

		if (normalizePathForComparison(sessionManager.getCwd()) !== normalizePathForComparison(cwd)) {
			sessionManager.adoptRecordedCwd();
		}
	} catch (error) {
		// The process cwd is already committed to the target. If rescoping the
		// cwd-derived state fails, undo the whole transition instead of building
		// the session with target-scoped cwd and launch-scoped settings.
		logger.warn("Could not rescope to resumed project directory", { cwd, error: String(error) });
		try {
			setProjectDir(launchCwd);
			sessionManager.setCwdWithoutRelocation(launchCwd);
			clearPluginRootsAndCaches();
			await preloadPluginRoots(os.homedir(), launchCwd);
			// Settings.#cwd was already assigned the destination; re-scope it
			// back so path-derived values and project saves target the launch
			// project, not the failed resume target.
			await activeSettings.reloadForCwd(launchCwd);
		} catch (rollbackError) {
			throw new SessionResolutionError(
				`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)}`,
			);
		}
		return { cwd: launchCwd, chdirFailed: resumedCwd };
	}
	return { cwd };
}

function notifyResumeCwdFallback(parsedArgs: Args, resumedProject: ResumedProjectResult, cwd: string): void {
	if (!resumedProject.chdirFailed) return;
	writeStartupNotice(
		parsedArgs,
		`${chalk.yellow(`Could not switch to resumed project ${resumedProject.chdirFailed}; staying in ${cwd}.`)}\n`,
	);
}

/**
 * Resolve the effective model allow-list from an explicit `--models` scope or,

View on GitHub (pinned to 9690622007)

Solutions

  1. Read the two embedded messages: fix the resumedCwd problem first (recreate the directory or pick a session whose project exists).
  2. Fix the launch directory problem (cd to an existing directory before launching omp).
  3. Check settings files in both directories are readable/valid JSON.
  4. Verify filesystem permissions on both project paths.

Example fix

// before
cd /old/deleted/project && omp --resume <id-of-session-in-also-deleted-dir>
// after
cd /existing/project && omp --resume <id>
Defensive patterns

Strategy: try-catch

Validate before calling

import * as fsSync from "node:fs";
if (!fsSync.existsSync(launchCwd) || !fsSync.existsSync(resumedCwd)) {
  console.error("Both launch and resume project dirs must exist before resuming across projects.");
}

Try / catch

try {
  await resumeAcrossProjects(...);
} catch (err) {
  if (err.message.startsWith("Could not switch to resumed project")) {
    // parse both parenthesized causes and fix paths/settings before retrying
  }
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31). Data as JSON: /api/errors/f63886fe8eb9f7ed. Report an issue: GitHub.