{"record":{"id":"c082b4d20fff402e","repo":"can1357/oh-my-pi","slug":"cannot-load-info-source-session-with-codexsessi","errorCode":null,"errorMessage":"Cannot load ${info.source} session with CodexSessionStore","messagePattern":"Cannot load (.+?) session with CodexSessionStore","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/session/codex-session-store.ts","lineNumber":544,"sourceCode":"\t\t\tsessions.push({\n\t\t\t\tsource: \"codex\",\n\t\t\t\tid,\n\t\t\t\tpath: filePath,\n\t\t\t\tcwd,\n\t\t\t\ttitle: indexed?.thread_name,\n\t\t\t\tcreated,\n\t\t\t\tmodified,\n\t\t\t});\n\t\t}\n\t\tsessions.sort(\n\t\t\t(left, right) => right.modified.getTime() - left.modified.getTime() || left.id.localeCompare(right.id),\n\t\t);\n\t\treturn sessions;\n\t}\n\n\t/** Converts one Codex rollout into a non-persistent OMP session. */\n\tasync load(info: ForeignSessionInfo): Promise<SessionManager> {\n\t\tif (info.source !== \"codex\") throw new Error(`Cannot load ${info.source} session with CodexSessionStore`);\n\t\tlet records: Record<string, unknown>[];\n\t\ttry {\n\t\t\trecords = await readJsonLines(info.path);\n\t\t} catch (error) {\n\t\t\tthrow new Error(`Unable to read Codex session ${info.id} at ${info.path}`, { cause: error });\n\t\t}\n\t\tif (records.length === 0) throw new Error(`Codex session ${info.id} at ${info.path} is empty or malformed`);\n\n\t\tconst metadata = records.find(record => record.type === \"session_meta\" && isRecord(record.payload));\n\t\tconst cwd =\n\t\t\tmetadata && isRecord(metadata.payload) ? (stringField(metadata.payload, \"cwd\") ?? info.cwd) : info.cwd;\n\t\tconst manager = SessionManager.inMemory(cwd);\n\t\tconst canonical = canonicalTexts(records);\n\t\tconst converted: ConvertedRecord[] = [];\n\t\tconst toolNames = new Map<string, string>();\n\t\tlet model = \"codex\";\n\t\tlet fallbackTimestamp = info.created.getTime();\n\t\tlet title = info.title;","sourceCodeStart":526,"sourceCodeEnd":562,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/session/codex-session-store.ts#L526-L562","documentation":"CodexSessionStore.load() only accepts foreign session infos whose source is 'codex'. Passing an info discovered by another store (claude, gemini, etc.) throws immediately. Each foreign-session store is source-specific by design.","triggerScenarios":"Calling `codexSessionStore.load(info)` where info.source is anything other than \"codex\" — typically because the info object came from listing a different provider's sessions or from a hand-constructed ForeignSessionInfo with the wrong source value.","commonSituations":"Generic session-picker code iterating a mixed list of foreign sessions and routing all of them to one store; refactor that swapped ClaudeSessionStore for CodexSessionStore; manual info construction with source left at its default.","solutions":["Route each ForeignSessionInfo to the store matching its source (info.source === 'codex' → CodexSessionStore)","Check info.source before calling load, or use a dispatch map from source to store","Fix the code that produced the info with the wrong source value"],"exampleFix":"// before\nconst manager = await codexStore.load(anyInfo);\n// after\nconst store = anyInfo.source === 'codex' ? codexStore : claudeStore;\nconst manager = await store.load(anyInfo);","handlingStrategy":"type-guard","validationCode":"function canLoadWithCodex(info: ForeignSessionInfo): boolean {\n  return info.source === 'codex';\n}","typeGuard":"function isCodexSessionInfo(info: ForeignSessionInfo): info is ForeignSessionInfo & { source: 'codex' } {\n  return info.source === 'codex';\n}","tryCatchPattern":"try {\n  const manager = await codexStore.load(info);\n} catch (err) {\n  if (err instanceof Error && err.message.startsWith('Cannot load')) {\n    throw new Error(`route ${info.source} sessions to their own store, not CodexSessionStore`);\n  }\n  throw err;\n}","preventionTips":["Build a source→store dispatch map instead of hardcoding one store in generic code","Brand per-source session info types so mismatches fail at compile time","Unit-test session routing to assert each source reaches its matching store"],"tags":["session","api-misuse","codex","guard"],"backgroundTag":"wrong-store-for-session-source","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}