affaan-m/ECC · error · Error

Unsupported OpenCode session target: ${target}

Error message

Unsupported OpenCode session target: ${target}

What it means

resolveSessionInfoPath exhausted all branches: the target is not 'latest', not an explicit id with a matching file, and isOpencodeSessionFileTarget(target,cwd) returned false (file does not exist, is not a file, or isSessionInfoFile rejected it). The OpenCode adapter cannot interpret the target string.

Source

Thrown at scripts/lib/session-adapters/opencode.js:154

    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'))
      .map(name => path.join(messageDir, name));
  } catch {
    return [];
  }
}

function deriveModelFromMessages(messageFiles) {
  for (const filePath of messageFiles.slice(0, MAX_MESSAGE_SCAN)) {

View on GitHub (pinned to 01e15490f0)

Solutions

  1. Use one of the supported forms: 'latest', an OpenCode session id, or an absolute/relative path to an existing session-info file.
  2. Confirm the path exists and isSessionInfoFile accepts it.
  3. Pass the correct cwd for relative paths.
  4. For structured targets, pass { type: 'opencode', value: <id-or-path> }.

Example fix

// before
adapter.open('opencode:my-project', { cwd }); // unsupported

// after
adapter.open('opencode:latest', { cwd });
// or
adapter.open('/abs/path/to/session-info.json', { cwd });
// or structured
adapter.open({ type: 'opencode', value: '/abs/path/to/session-info.json' }, { cwd });
Defensive patterns

Strategy: validation

Validate before calling

function assertOpencodeTargetShape(target, cwd) {
  if (target === 'latest') return;
  const abs = path.resolve(cwd, target);
  const isFile = fs.existsSync(abs) && fs.statSync(abs).isFile() && isSessionInfoFile(abs);
  const byId = findSessionInfoById(resolveStorageDir({}, {}), target);
  if (!isFile && !byId) {
    throw new Error(`Unsupported OpenCode target: ${target}. Use 'latest', a session id, or a session-info path.`);
  }
}

Type guard

function isOpencodeTargetPlausible(target, cwd) {
  if (target === 'latest') return true;
  if (typeof target !== 'string') return false;
  const abs = path.resolve(cwd, target);
  return fs.existsSync(abs) && fs.statSync(abs).isFile() && isSessionInfoFile(abs);
}

Try / catch

try { return resolveSessionInfoPath(target, cwd, options, context); }
catch (err) {
  if (err.message.startsWith('Unsupported OpenCode session target:')) {
    throw new Error(`${err.message}. Supported: 'latest' | session id | path to a session-info file.`);
  }
  throw err;
}

Prevention

When it happens

Trigger: Passing a target that is neither an OpenCode id nor a path to an existing session-info file (e.g. a project name, directory, or arbitrary JSON file). The referenced file does not exist. The file does not satisfy isSessionInfoFile (wrong location or naming).

Common situations: User passes a bare project name or message id. Relative path resolved against the wrong cwd. File is present but in a location isSessionInfoFile does not recognize.

Related errors


AI-assisted analysis of affaan-m/ECC@01e15490f0 (2026-08-13). Data as JSON: /api/errors/160410afaeefe976. Report an issue: GitHub.