affaan-m/ECC · error · Error
OpenCode session not found: ${explicitTarget}
Error message
OpenCode session not found: ${explicitTarget} What it means
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.
Source
Thrown at scripts/lib/session-adapters/opencode.js:146
const latest = findLatestSessionInfo(storageDir);
if (!latest) {
throw new Error('No OpenCode sessions found');
}
return { sessionInfoPath: latest, sourceTarget: { type: 'opencode', value: 'latest' } };
}
const absoluteExplicit = path.resolve(cwd, explicitTarget);
if (fs.existsSync(absoluteExplicit) && isSessionInfoFile(absoluteExplicit)) {
return { sessionInfoPath: absoluteExplicit, sourceTarget: { type: 'opencode-session-file', value: absoluteExplicit } };
}
const byId = findSessionInfoById(storageDir, explicitTarget);
if (byId) {
return { sessionInfoPath: byId, sourceTarget: { type: 'opencode', value: explicitTarget } };
}
throw new Error(`OpenCode session not found: ${explicitTarget}`);
}
if (isOpencodeSessionFileTarget(target, cwd)) {
const absoluteTarget = path.resolve(cwd, target);
return { sessionInfoPath: absoluteTarget, sourceTarget: { type: 'opencode-session-file', value: absoluteTarget } };
}
throw new Error(`Unsupported OpenCode session target: ${target}`);
}
function readMessageFiles(messageDir) {
if (!fs.existsSync(messageDir) || !fs.statSync(messageDir).isDirectory()) {
return [];
}
try {
return fs.readdirSync(messageDir)
.filter(name => name.startsWith('msg_') && name.endsWith('.json'))View on GitHub (pinned to 01e15490f0)
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).
Example fix
// before
adapter.open('opencode:abc', { cwd }); // not found
// after
const files = listSessionInfoFiles(storageDir);
adapter.open(`opencode:${path.basename(files[0], '.json')}`, { cwd });
// or
adapter.open('/abs/path/to/session-info.json', { cwd }); Defensive patterns
Strategy: validation
Validate before calling
const byId = findSessionInfoById(storageDir, explicitTarget);
const abs = path.resolve(cwd, explicitTarget);
if (!byId && !(fs.existsSync(abs) && isSessionInfoFile(abs))) {
const known = listSessionInfoFiles(storageDir).map(f => path.basename(f, '.json')).join(', ');
throw new Error(`OpenCode session not found: ${explicitTarget}. Known: ${known}`);
} Type guard
function opencodeTargetExists(target, cwd, storageDir) {
const abs = path.resolve(cwd, target);
return (fs.existsSync(abs) && isSessionInfoFile(abs))
|| Boolean(findSessionInfoById(storageDir, target));
} Try / catch
try { return resolveSessionInfoPath(target, cwd, options, context); }
catch (err) {
if (err.message.startsWith('OpenCode session not found:')) {
const list = listSessionInfoFiles(storageDir).map(f => path.basename(f, '.json'));
throw new Error(`${err.message}. Known sessions: ${list.join(', ')}`);
}
throw err;
} Prevention
- 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).
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Claude session not found: ${explicitTarget}
- Codex rollout session not found: ${explicitTarget}
- No OpenCode sessions found
- Unsupported OpenCode session target: ${target}
- Unable to load issue #${issueNumber} from ${repo}
AI-assisted analysis of affaan-m/ECC@01e15490f0 (2026-08-13).
Data as JSON: /api/errors/19c03deeabd5eacc.
Report an issue: GitHub.