{"record":{"id":"169c79d8e5c68371","repo":"can1357/oh-my-pi","slug":"failed-to-import-sourcename-session-message","errorCode":null,"errorMessage":"Failed to import ${sourceName} session: ${message}","messagePattern":"Failed to import (.+?) session: (.+?)","errorType":"exception","errorClass":"SessionResolutionError","httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/main.ts","lineNumber":1675,"sourceCode":"\t\t\t\t\tprocess.exit(0);\n\t\t\t\t}\n\t\t\t\tconst foreignSession = foreignSessions.find(\n\t\t\t\t\tsession => session.id === selected.id && session.path === selected.path,\n\t\t\t\t);\n\t\t\t\tif (!foreignSession) {\n\t\t\t\t\tthrow new SessionResolutionError(`Selected ${sourceName} session is no longer available`);\n\t\t\t\t}\n\t\t\t\ttry {\n\t\t\t\t\tsessionManager = await logger.time(\n\t\t\t\t\t\t`import${sourceName}Session`,\n\t\t\t\t\t\tpersistForeignSession,\n\t\t\t\t\t\tstore,\n\t\t\t\t\t\tforeignSession,\n\t\t\t\t\t\t{ fallbackCwd: cwd, sessionDir: parsedArgs.sessionDir },\n\t\t\t\t\t);\n\t\t\t\t} catch (error) {\n\t\t\t\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\t\t\t\tthrow new SessionResolutionError(`Failed to import ${sourceName} session: ${message}`);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tsessionManager = await logger.time(\n\t\t\t\t\t\"createSessionManager\",\n\t\t\t\t\tcreateSessionManager,\n\t\t\t\t\tparsedArgs,\n\t\t\t\t\tcwd,\n\t\t\t\t\tsettingsInstance,\n\t\t\t\t);\n\t\t\t}\n\t\t} catch (error: unknown) {\n\t\t\tif (error instanceof SessionResolutionError) {\n\t\t\t\tprocess.stderr.write(`${chalk.red(`Error: ${error.message}`)}\\n`);\n\t\t\t\tif (error.hint) {\n\t\t\t\t\tprocess.stderr.write(`${chalk.dim(error.hint)}\\n`);\n\t\t\t\t}\n\t\t\t\tprocess.exit(1);\n\t\t\t}","sourceCodeStart":1657,"sourceCodeEnd":1693,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/main.ts#L1657-L1693","documentation":"Once a matching foreign session is found, main.ts calls `persistForeignSession(store, foreignSession, ...)` to convert and write it into omp's session store. Any error during conversion/persistence is rethrown as `SessionResolutionError: Failed to import <source> sessions: <message>`. The inner message carries the actual failure (parse error, write error, etc.).","triggerScenarios":"`--from-claude`/`--from-codex` where importing a matched session throws: malformed/unparseable message payloads in the foreign session, unsupported content types, disk write failure into the omp session dir, or `sessionDir` unwritable.","commonSituations":"Foreign tool wrote session data in a newer format omp doesn't parse; session contains edge-case content (images, tool payloads) the importer can't map; full disk or read-only directory; custom `--session-dir` pointing somewhere unusable.","solutions":["Read the wrapped inner message to identify the failing step (parse vs write) and the offending item.","Update omp to the latest version — foreign session format changes are handled by newer importers.","Try importing a different/older session to isolate a corrupt payload.","Check the omp session directory (or `--session-dir`) is writable and has free space.","As a workaround, copy essential context manually into a new omp session."],"exampleFix":"// before\nomp --from-codex   # importer fails on new session format\n\n// after\nbun install -g oh-my-pi@latest && omp --from-codex","handlingStrategy":"try-catch","validationCode":"import * as fs from \"node:fs\";\n// Ensure the destination session dir is writable with space before importing\nfs.accessSync(sessionDir ?? defaultSessionDir, fs.constants.W_OK);\nif (fs.statfsSync(sessionDir ?? defaultSessionDir).bavail * blockSize < minFreeBytes) throw new Error(\"Low disk space\");","typeGuard":null,"tryCatchPattern":"try {\n  await omp([\"--from-codex\"]);\n} catch (err) {\n  if (err instanceof SessionResolutionError && err.message.startsWith(\"Failed to import\")) {\n    console.error(\"Import failed; update omp or pick another session:\", err.message);\n  } else throw err;\n}","preventionTips":["Keep omp up to date so foreign-format changes are supported by the importer.","Ensure the omp session dir (or --session-dir) is writable and has disk space.","If a specific session fails repeatedly, treat it as corrupt and skip it."],"tags":["cli","session-import","persistence","foreign-tool"],"backgroundTag":"session-import-failed","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}