{"record":{"id":"dc2e76387dad99f2","repo":"Yeachan-Heo/oh-my-codex","slug":"session-pointer-context-failure","errorCode":"session_pointer_context_failure","errorMessage":"Unable to resolve the selected session pointer root: ${errorMessage(cause)}","messagePattern":"Unable to resolve the selected session pointer root: (.+?)","errorType":"exception","errorClass":"SessionPointerLaunchAbort","httpStatus":null,"severity":"error","filePath":"src/hooks/session.ts","lineNumber":3623,"sourceCode":"\n/**\n * Archive first and remove an owned pointer only after that history write\n * succeeds. Present unusable pointer evidence is never repaired or archived.\n */\nexport async function writeSessionEnd(\n  cwd: string,\n  sessionId: string,\n  options: Pick<SessionStartOptions, 'context' | 'platform' | 'regularFileSync'> & {\n    binding?: LaunchSessionBinding;\n    postLaunchCwd?: string;\n  } = {},\n): Promise<{ comparison: LifecycleCleanupEvidence['comparison']; capability: CapabilityCloseEvidence[] }> {\n  const candidateSessionId = normalizeSessionId(sessionId);\n  let context: SessionPointerContext;\n  try {\n    context = options.context ?? resolveSessionPointerContext(cwd);\n  } catch (error) {\n    throw contextAbort(cwd, candidateSessionId, error);\n  }\n  if (!candidateSessionId) {\n    const cause = new Error('A valid session ID is required to end a session pointer.');\n    throw resolvedAbort(context, {\n      code: 'session_pointer_io_failure',\n      operation: 'pointer-classify',\n      lockPath: context.lockPath,\n      reason: cause.message,\n      cause,\n    });\n  }\n\n  if (!options.binding) {\n    throw resolvedAbort(context, {\n      code: 'session_pointer_io_failure', operation: 'pointer-classify', candidateSessionId,\n      lockPath: context.lockPath, reason: 'A live launch binding is required to end a session pointer.',\n    });\n  }","sourceCodeStart":3605,"sourceCodeEnd":3641,"githubUrl":"https://github.com/Yeachan-Heo/oh-my-codex/blob/3ad79a8a6fe6e95fdbb8c00e40716fffe4011ce2/src/hooks/session.ts#L3605-L3641","documentation":"resolveSessionPointerContext(cwd) threw while setting up a session-pointer teardown (end-session) operation, and the error is re-surfaced through contextAbort — i.e. the session pointer root (state dir / lock path derived from cwd) could not be resolved for this working directory. The subsequent missing-session-ID guard shown would raise session_pointer_io_failure instead; this message corresponds to the context-resolution failure path (contextAbort / session_pointer_context_failure).","triggerScenarios":"Calling endSession with a cwd for which the pointer context cannot be derived: the state root env/config resolves to an invalid path, realpath fails (ENOENT parents, permission denied), or platform context resolution rejects the directory.","commonSituations":"Running end-session from a deleted working directory (cwd removed by another process); STATE_DIR-style env var pointing to a nonexistent/unwritable path; nested containers where the cwd is a broken mount; calling with a cwd string that is not an absolute path.","solutions":["Ensure the cwd you pass still exists (pwd works) and is absolute.","Fix or unset the env var / config that determines the state root so it resolves to a real writable directory.","mkdir -p the intended state root before calling endSession.","If the process's cwd was deleted, restart the operation from a valid directory."],"exampleFix":"// before\nawait endSession(deletedCwd, sessionId);\n\n// after\nconst cwd = fs.realpathSync(process.cwd()); // valid dir\nawait endSession(cwd, sessionId);","handlingStrategy":"validation","validationCode":"import { promises as fsp } from 'node:fs';\nconst abs = path.isAbsolute(cwd) ? cwd : path.resolve(cwd);\nawait fsp.access(abs); // throws if the directory is gone\nawait ensureStateRootWritable(); // mkdir -p the configured state root","typeGuard":"const isExistingAbsDir = (p: unknown): p is string =>\n  typeof p === 'string' && path.isAbsolute(p) && fs.existsSync(p);","tryCatchPattern":"try { await endSession(cwd, sessionId); } catch (e) { if (isContextFailure(e)) { const safe = path.resolve(process.cwd()); return endSession(safe, sessionId); } throw e; }","preventionTips":["Validate cwd exists (and is absolute) before calling session APIs.","Bootstrap the state root (mkdir -p) at process startup.","Don't delete the working directory out from under a running process."],"tags":["session","context","cwd","resolution","state-dir"],"backgroundTag":"working-directory-resolution-failed","analyzedSha":"3ad79a8a6fe6e95fdbb8c00e40716fffe4011ce2","analyzedAt":"2026-08-27T22:18:39.783Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}