{"record":{"id":"19c03deeabd5eacc","repo":"affaan-m/ECC","slug":"opencode-session-not-found-explicittarget","errorCode":null,"errorMessage":"OpenCode session not found: ${explicitTarget}","messagePattern":"OpenCode session not found: (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/lib/session-adapters/opencode.js","lineNumber":146,"sourceCode":"      const latest = findLatestSessionInfo(storageDir);\n      if (!latest) {\n        throw new Error('No OpenCode sessions found');\n      }\n\n      return { sessionInfoPath: latest, sourceTarget: { type: 'opencode', value: 'latest' } };\n    }\n\n    const absoluteExplicit = path.resolve(cwd, explicitTarget);\n    if (fs.existsSync(absoluteExplicit) && isSessionInfoFile(absoluteExplicit)) {\n      return { sessionInfoPath: absoluteExplicit, sourceTarget: { type: 'opencode-session-file', value: absoluteExplicit } };\n    }\n\n    const byId = findSessionInfoById(storageDir, explicitTarget);\n    if (byId) {\n      return { sessionInfoPath: byId, sourceTarget: { type: 'opencode', value: explicitTarget } };\n    }\n\n    throw new Error(`OpenCode session not found: ${explicitTarget}`);\n  }\n\n  if (isOpencodeSessionFileTarget(target, cwd)) {\n    const absoluteTarget = path.resolve(cwd, target);\n    return { sessionInfoPath: absoluteTarget, sourceTarget: { type: 'opencode-session-file', value: absoluteTarget } };\n  }\n\n  throw new Error(`Unsupported OpenCode session target: ${target}`);\n}\n\nfunction readMessageFiles(messageDir) {\n  if (!fs.existsSync(messageDir) || !fs.statSync(messageDir).isDirectory()) {\n    return [];\n  }\n\n  try {\n    return fs.readdirSync(messageDir)\n      .filter(name => name.startsWith('msg_') && name.endsWith('.json'))","sourceCodeStart":128,"sourceCodeEnd":164,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/scripts/lib/session-adapters/opencode.js#L128-L164","documentation":"resolveSessionInfoPath throws this when an explicit OpenCode session identifier was provided but findSessionInfoById(storageDir, explicitTarget) found no matching session info file, and the target is not directly a session file path. The referenced OpenCode session does not exist locally.","triggerScenarios":"resolveSessionInfoPath called with explicitTarget set to a session id with no corresponding info file under storageDir — id from another machine, deleted session, or wrong storage dir.","commonSituations":"Sharing session ids between teammates without sharing storage; storage cleanup removing old sessions; passing a Claude/Codex id to the OpenCode adapter; case or truncation errors in the id.","solutions":["List session info files under the storage dir and use an exact id from a filename.","Pass the full path to the session info JSON file instead of an id.","Verify the storage dir resolution points at the machine where the session was created.","Trim the id; check for copy/paste truncation.","Recreate the session if its storage was deleted."],"exampleFix":"// before\nresolve('ses_abc123'); // unknown id -> throws\n// after\nconst available = fs.readdirSync(storageDir).filter(f => f.endsWith('.json'));\nif (!available.some(f => f.replace(/\\.json$/, '') === id)) {\n  throw new Error(`OpenCode session '${id}' not found. Available: ${available.join(', ')}`);\n}\nresolve(id);","handlingStrategy":"validation","validationCode":"const available = fs.readdirSync(storageDir).filter(f => f.endsWith('.json'));\nif (!available.some(f => f.replace(/\\.json$/, '') === sessionId)) throw new Error(`Session '${sessionId}' not in ${storageDir}`);","typeGuard":"function isKnownOpencodeSession(id, files) { return typeof id === 'string' && files.some(f => f.replace(/\\.json$/, '') === id); }","tryCatchPattern":"try { return adapter.resolveSessionInfoPath(id); } catch (e) { if (/^OpenCode session not found:/.test(e.message)) throw new Error(`List storage dir contents; '${id}' not found`); throw e; }","preventionTips":["Use ids copied from the storage directory on the same machine","Trim ids and watch for truncation","Pass the session JSON path when unsure of id format","Expect sessions to vanish after storage cleanup"],"tags":["session","opencode","not-found"],"backgroundTag":"entity-not-found","analyzedSha":"8321021c54d670126ce3b2969d5deb880b4b0c2a","analyzedAt":"2026-09-16T10:08:13.343Z","contentChangedAt":"2026-09-16T10:08:13.343Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}