{"record":{"id":"0ce11725fa461e80","repo":"can1357/oh-my-pi","slug":"failed-to-list-sourcename-sessions-message","errorCode":null,"errorMessage":"Failed to list ${sourceName} sessions: ${message}","messagePattern":"Failed to list (.+?) sessions: (.+?)","errorType":"exception","errorClass":"SessionResolutionError","httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/main.ts","lineNumber":1627,"sourceCode":"\n\t\t// Resolve native resume/fork flags or import one foreign transcript into a\n\t\t// fresh persisted OMP session before constructing the AgentSession.\n\t\tlet sessionManager: SessionManager | undefined;\n\t\tlet foreignSource: ForeignSessionSource | undefined;\n\t\ttry {\n\t\t\tforeignSource = resolveForeignSessionSource(parsedArgs);\n\t\t\tif (foreignSource) {\n\t\t\t\tif (isProtocolMode) {\n\t\t\t\t\tthrow new SessionResolutionError(`--from-${foreignSource} is not supported in ${mode} mode`);\n\t\t\t\t}\n\t\t\t\tconst sourceName = foreignSessionSourceName(foreignSource);\n\t\t\t\tconst store = (deps.createForeignSessionStore ?? createForeignSessionStore)(foreignSource);\n\t\t\t\tlet foreignSessions: ForeignSessionInfo[];\n\t\t\t\ttry {\n\t\t\t\t\tforeignSessions = await logger.time(`list${sourceName}Sessions`, () => store.list());\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 list ${sourceName} sessions: ${message}`);\n\t\t\t\t}\n\t\t\t\tif (foreignSessions.length === 0) {\n\t\t\t\t\twriteStartupNotice(parsedArgs, `${chalk.dim(`No ${sourceName} sessions found`)}\\n`);\n\t\t\t\t\tstopStartupWatchdog();\n\t\t\t\t\tprocess.exit(0);\n\t\t\t\t}\n\t\t\t\tconst choices = foreignSessions.map(foreignSessionInfoToSessionInfo);\n\t\t\t\tpauseStartupWatchdog();\n\t\t\t\tlet selected: SessionInfo | null;\n\t\t\t\ttry {\n\t\t\t\t\tselected = await logger.time(\n\t\t\t\t\t\t`select${sourceName}Session`,\n\t\t\t\t\t\tdeps.selectSession ?? selectSession,\n\t\t\t\t\t\tchoices,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttitle: `Import ${sourceName} Session`,\n\t\t\t\t\t\t\tscopeLabel: false,\n\t\t\t\t\t\t\tshowCwd: true,","sourceCodeStart":1609,"sourceCodeEnd":1645,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/main.ts#L1609-L1645","documentation":"When a foreign session source is selected, main.ts calls `store.list()` (timed/logged) to enumerate that tool's sessions. Any thrown error — underlying tool crash, unreadable session storage, JSON parse failure — is caught and rethrown as `SessionResolutionError: Failed to list <Claude|Codex> sessions: <message>`. The inner message names the real cause.","triggerScenarios":"`--from-claude`/`--from-codex` where the foreign store's `list()` throws: corrupt or unreadable session files, storage directory missing/permission-denied, unexpected schema in the foreign tool's session files.","commonSituations":"Foreign CLI (Claude/Codex) upgraded and changed its on-disk session format; session directory moved or partially deleted; disk/permission problems under `~/.claude`/`~/.codex`.","solutions":["Read the wrapped inner message — it identifies the failing file or cause — and fix that specific issue.","Verify the foreign tool still runs and its session directory exists and is readable (`ls ~/.claude/projects` or `~/.codex`).","Repair or remove the corrupt session file(s); if the foreign CLI changed format, upgrade omp to a matching version.","Fall back to resuming omp-native sessions without `--from-*`."],"exampleFix":"// before\nomp --from-claude   # EACCES on ~/.claude/projects\n\n// after\nchmod u+rx ~/.claude/projects\nomp --from-claude","handlingStrategy":"try-catch","validationCode":"import * as fs from \"node:fs\";\n// Sanity-check the foreign tool's session storage before importing\nfor (const dir of [\"~/.claude/projects\", \"~/.codex/sessions\"]) {\n  const p = dir.replace(\"~\", process.env.HOME ?? \"\");\n  fs.accessSync(p, fs.constants.R_OK | fs.constants.X_OK);\n}","typeGuard":null,"tryCatchPattern":"try {\n  await omp([\"--from-claude\"]);\n} catch (err) {\n  if (err instanceof SessionResolutionError && err.message.startsWith(\"Failed to list\")) {\n    console.error(\"Foreign session store unreadable:\", err.message);\n    // fall back to native sessions\n    await omp([]);\n  } else throw err;\n}","preventionTips":["Keep the foreign CLI (Claude/Codex) and omp versions in sync — format changes break listing.","Don't hand-edit or partially delete files under the foreign tool's session directories.","Back up session storage before cleaning it up."],"tags":["cli","session-import","filesystem","foreign-tool"],"backgroundTag":"session-list-failed","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}