affaan-m/ECC · error · Error

No OpenCode sessions found

Error message

No OpenCode sessions found

What it means

resolveSessionInfoPath was called with target 'latest' (or opencode:latest) but findLatestSessionInfo(storageDir) returned null. The OpenCode adapter found no session-info JSON files in the resolved OpenCode storage directory.

Source

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

  return files
    .map(filePath => ({ filePath, updatedMs: readSessionUpdatedMs(filePath) }))
    .sort((a, b) => b.updatedMs - a.updatedMs)[0].filePath;
}

function findSessionInfoById(storageDir, sessionId) {
  return listSessionInfoFiles(storageDir)
    .find(filePath => path.basename(filePath, '.json') === sessionId) || null;
}

function resolveSessionInfoPath(target, cwd, options, context) {
  const explicitTarget = parseOpencodeTarget(target);
  const storageDir = resolveStorageDir(options, context);

  if (explicitTarget) {
    if (explicitTarget === 'latest') {
      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}`);
  }

View on GitHub (pinned to 01e15490f0)

Solutions

  1. Run OpenCode at least once so it creates a session-info file, then retry 'latest'.
  2. Verify the storage directory resolveStorageDir points at exists and contains session info JSON files.
  3. If the storage root or project id is overridden, set them to the values that actually hold the sessions.
  4. Pass an explicit session id or absolute path instead of 'latest'.

Example fix

// before
adapter.open('opencode:latest', { cwd });

// after
adapter.open('opencode:<known-session-id>', { cwd });
// or run `opencode` once to seed the storage directory, then retry 'latest'
Defensive patterns

Strategy: validation

Validate before calling

const latest = findLatestSessionInfo(storageDir);
if (!latest) {
  throw new Error(`No OpenCode sessions in ${storageDir}; run 'opencode' first or pass an explicit session id.`);
}

Type guard

function hasAnyOpencodeSession(storageDir) {
  return listSessionInfoFiles(storageDir).length > 0;
}

Try / catch

try { return resolveSessionInfoPath('latest', cwd, options, context); }
catch (err) {
  if (err.message === 'No OpenCode sessions found') {
    throw new Error('No OpenCode sessions found. Pass an explicit session id or session-info path.');
  }
  throw err;
}

Prevention

When it happens

Trigger: Requesting the latest OpenCode session on a machine where OpenCode has never run, or where the storage directory is set to an empty/non-existent path. OPENCODE storage root or the project id is overridden so resolveStorageDir points elsewhere.

Common situations: Fresh environment with no OpenCode sessions. CI container with isolated HOME lacking the OpenCode storage dir. Project id passed via context does not match any stored session. OpenCode version writes to a different storage layout.

Related errors


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