thedotmack/claude-mem · error · Error
Auto-reprime failed for corpus
Error message
Auto-reprime failed for corpus "${corpus.name}" What it means
When a query fails because the corpus session expired, KnowledgeAgent.query() auto-reprimes and then re-checks the stored corpus; if the reprimed corpus still lacks a session_id, it throws this error. It indicates the recovery path itself failed — the prime() call did not produce (or persist) a fresh session_id.
Solutions
- Fix the underlying cause of the failed prime — check prime() logs and the Claude backend availability
- Verify the corpora directory is writable so corpusStore.write can persist the new session_id
- Manually run prime(corpus) and confirm the stored JSON now has session_id, then retry the query
- Check for concurrent processes rewriting the corpus file; serialize access or use file locking
Example fix
// before
const refreshedCorpus = this.corpusStore.read(corpus.name);
if (!refreshedCorpus || !refreshedCorpus.session_id) {
throw new Error(`Auto-reprime failed for corpus "${corpus.name}"`);
}
// after
const refreshedCorpus = this.corpusStore.read(corpus.name);
if (!refreshedCorpus || !refreshedCorpus.session_id) {
logger.error('WORKER', 'auto-reprime produced no session', { corpus: corpus.name });
await new Promise(r => setTimeout(r, 1000)); // brief backoff
await this.prime(corpus);
// then re-read and re-check before giving up
} Defensive patterns
Strategy: retry
Validate before calling
const corpus = corpusStore.read(name);
const readyToQuery = !!corpus && typeof corpus.session_id === 'string' && corpus.session_id.length > 0;
if (!readyToQuery) {
await agent.prime(corpus);
// re-read and confirm session_id exists before querying
} Try / catch
try {
return await agent.query(corpus, question);
} catch (err) {
if (err instanceof Error && err.message.startsWith('Auto-reprime failed')) {
// recovery path failed: check filesystem writability + backend health, then retry once manually
await agent.prime(corpus);
const fresh = corpusStore.read(corpus.name);
if (fresh?.session_id) return agent.query(fresh, question);
throw err;
}
throw err;
} Prevention
- Ensure the corpora directory is writable by the worker process
- Avoid concurrent writers to the same corpus file (lock or single-writer design)
- Monitor prime() success rates to catch backend outages before queries pile up
- Pin SDK versions so prime's session_id capture doesn't break silently
When it happens
Trigger: Auto-reprime path: prime() ran but returned without capturing a session_id (see error 155), the corpusStore.write() failed so the re-read has no session_id, or the re-read returned null because the corpus file was deleted between operations.
Common situations: Persistent backend problem during reprime (LLM down, quota exhausted); read-only filesystem preventing corpusStore.write from persisting the new session; concurrent process overwriting the corpus file mid-reprime; SDK response-shape change breaking prime's session capture.
Related errors
- BullMQ re-enqueue failed (will reconcile on startup)
- cannot process observation generation job after…
- cannot retry observation generation job after max_attempts…
- chroma-mcp connection in backoff
- chroma-mcp transport error during
AI-assisted analysis of thedotmack/claude-mem@d8bc9755e7 (2026-09-17).
Data as JSON: /api/errors/02f97f10da8e49f9.
Report an issue: GitHub.
Appendix: source
Thrown at src/services/worker/knowledge/KnowledgeAgent.ts:109
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;
}
logger.info('WORKER', `Session expired for corpus "${corpus.name}", auto-repriming...`);
await this.prime(corpus);
const refreshedCorpus = this.corpusStore.read(corpus.name);
if (!refreshedCorpus || !refreshedCorpus.session_id) {
throw new Error(`Auto-reprime failed for corpus "${corpus.name}"`);
}
const result = await this.executeQuery(refreshedCorpus, question);
if (result.session_id !== refreshedCorpus.session_id) {
refreshedCorpus.session_id = result.session_id;
this.corpusStore.write(refreshedCorpus);
}
return result;
}
}
async reprime(corpus: CorpusFile): Promise<string> {
corpus.session_id = null;
return this.prime(corpus);
}
private isSessionResumeError(error: unknown): boolean {
const message = error instanceof Error ? error.message : String(error);
return /session|resume|expired|invalid.*session|not found/i.test(message);View on GitHub (pinned to d8bc9755e7)