thedotmack/claude-mem · error · Error

Corpus "${corpus.name}" has no session — call prime first

Error message

Corpus "${corpus.name}" has no session — call prime first

What it means

Thrown by KnowledgeAgent.query when corpus.session_id is null — query() requires an existing primed session to resume. The contract is: call prime() first (which captures and persists session_id), then query(). Calling query on an unprimed or explicitly nulled corpus violates that contract.

Source

Thrown at src/services/worker/knowledge/KnowledgeAgent.ts:86

        }
      } else {
        throw error;
      }
    }

    if (!sessionId) {
      throw new Error(`Failed to capture session_id while priming corpus "${corpus.name}"`);
    }

    corpus.session_id = sessionId;
    this.corpusStore.write(corpus);

    return sessionId;
  }

  async query(corpus: CorpusFile, question: string): Promise<QueryResult> {
    if (!corpus.session_id) {
      throw new Error(`Corpus "${corpus.name}" has no session — call prime first`);
    }

    try {
      const result = await this.executeQuery(corpus, question);
      if (result.session_id !== corpus.session_id) {
        corpus.session_id = result.session_id;
        this.corpusStore.write(corpus);
      }
      return result;
    } catch (error) {
      if (!this.isSessionResumeError(error)) {
        if (error instanceof Error) {
          logger.error('WORKER', `Query failed for corpus "${corpus.name}"`, {}, error);
        } else {
          logger.error('WORKER', `Query failed for corpus "${corpus.name}" (non-Error thrown)`, { thrownValue: String(error) });
        }
        throw error;
      }

View on GitHub (pinned to d768ba3643)

Solutions

  1. Call await agent.prime(corpus) before agent.query(corpus, question).
  2. After reprime() (which nulls session_id), await its returned session before querying.
  3. Guard callers: if (!corpus.session_id) await agent.prime(corpus); before query().

Example fix

// before
const result = await agent.query(corpus, question); // corpus.session_id === null

// after
if (!corpus.session_id) {
  await agent.prime(corpus);
}
const result = await agent.query(corpus, question);
Defensive patterns

Strategy: validation

Validate before calling

if (!corpus.session_id) {
  await agent.prime(corpus);
}
const result = await agent.query(corpus, question);

Type guard

function isPrimed(c: CorpusFile): c is CorpusFile & { session_id: string } {
  return typeof c.session_id === 'string' && c.session_id.length > 0;
}

Try / catch

try {
  await agent.query(corpus, question);
} catch (err) {
  if (err instanceof Error && /has no session — call prime first/.test(err.message)) {
    await agent.prime(corpus);
    return agent.query(corpus, question);
  }
  throw err;
}

Prevention

When it happens

Trigger: query(corpus, question) invoked on a CorpusFile whose session_id is null: a freshly created corpus never primed, or one whose session_id was cleared by reprime() (which sets it to null before re-priming).

Common situations: Forgetting to call prime() after creating a corpus; calling query() concurrently with/after reprime() before prime completed; corpus loaded from disk with a null session_id (never primed or session expired and was cleared).

Related errors


AI-assisted analysis of thedotmack/claude-mem@d768ba3643 (2026-08-12). Data as JSON: /api/errors/3a3ad230abcceb51. Report an issue: GitHub.