{"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":"exception","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/01e15490f04e29cfefe3896951f43db46994d8ee/scripts/lib/session-adapters/opencode.js#L128-L164","documentation":"resolveSessionInfoPath got an explicit target that is not 'latest', did not match an existing session-info file on disk (absoluteExplicit check failed), and findSessionInfoById(storageDir, explicitTarget) returned null. The OpenCode adapter could not locate a session-info JSON whose basename (minus .json) equals the requested id.","triggerScenarios":"Passing an OpenCode session id that was never created, was deleted, or lives in a different storage directory. Typo in the id. Pointing the adapter at the wrong project/storage root so findSessionInfoById cannot see the file.","commonSituations":"Copy-paste error in a session id. Session pruned by OpenCode cleanup. Running on a different machine/project than where the session was created. OpenCode version stores session-info under a different subdirectory.","solutions":["List session-info files to confirm the id: listSessionInfoFiles(storageDir) and inspect basenames without the .json suffix.","If the session exists elsewhere, point the storage root or project id at that location before resolving.","Pass the absolute path to the session-info JSON as the target to hit the absoluteExplicit branch.","Verify the id matches the filename exactly (basename without .json)."],"exampleFix":"// before\nadapter.open('opencode:abc', { cwd }); // not found\n\n// after\nconst files = listSessionInfoFiles(storageDir);\nadapter.open(`opencode:${path.basename(files[0], '.json')}`, { cwd });\n// or\nadapter.open('/abs/path/to/session-info.json', { cwd });","handlingStrategy":"validation","validationCode":"const byId = findSessionInfoById(storageDir, explicitTarget);\nconst abs = path.resolve(cwd, explicitTarget);\nif (!byId && !(fs.existsSync(abs) && isSessionInfoFile(abs))) {\n  const known = listSessionInfoFiles(storageDir).map(f => path.basename(f, '.json')).join(', ');\n  throw new Error(`OpenCode session not found: ${explicitTarget}. Known: ${known}`);\n}","typeGuard":"function opencodeTargetExists(target, cwd, storageDir) {\n  const abs = path.resolve(cwd, target);\n  return (fs.existsSync(abs) && isSessionInfoFile(abs))\n    || Boolean(findSessionInfoById(storageDir, target));\n}","tryCatchPattern":"try { return resolveSessionInfoPath(target, cwd, options, context); }\ncatch (err) {\n  if (err.message.startsWith('OpenCode session not found:')) {\n    const list = listSessionInfoFiles(storageDir).map(f => path.basename(f, '.json'));\n    throw new Error(`${err.message}. Known sessions: ${list.join(', ')}`);\n  }\n  throw err;\n}","preventionTips":["List session-info files before resolving a bare id.","Sync session-info files into the local storage dir for cross-machine runs.","Match the id exactly to the filename (without .json)."],"tags":["opencode","session-resolution","not-found"],"backgroundTag":null,"analyzedSha":"01e15490f04e29cfefe3896951f43db46994d8ee","analyzedAt":"2026-08-13T00:31:08.655Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}