{"record":{"id":"3a3ad230abcceb51","repo":"thedotmack/claude-mem","slug":"corpus-corpus-name-has-no-session-call-prim","errorCode":null,"errorMessage":"Corpus \"${corpus.name}\" has no session — call prime first","messagePattern":"Corpus \"(.+?)\" has no session — call prime first","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/services/worker/knowledge/KnowledgeAgent.ts","lineNumber":86,"sourceCode":"        }\n      } else {\n        throw error;\n      }\n    }\n\n    if (!sessionId) {\n      throw new Error(`Failed to capture session_id while priming corpus \"${corpus.name}\"`);\n    }\n\n    corpus.session_id = sessionId;\n    this.corpusStore.write(corpus);\n\n    return sessionId;\n  }\n\n  async query(corpus: CorpusFile, question: string): Promise<QueryResult> {\n    if (!corpus.session_id) {\n      throw new Error(`Corpus \"${corpus.name}\" has no session — call prime first`);\n    }\n\n    try {\n      const result = await this.executeQuery(corpus, question);\n      if (result.session_id !== corpus.session_id) {\n        corpus.session_id = result.session_id;\n        this.corpusStore.write(corpus);\n      }\n      return result;\n    } catch (error) {\n      if (!this.isSessionResumeError(error)) {\n        if (error instanceof Error) {\n          logger.error('WORKER', `Query failed for corpus \"${corpus.name}\"`, {}, error);\n        } else {\n          logger.error('WORKER', `Query failed for corpus \"${corpus.name}\" (non-Error thrown)`, { thrownValue: String(error) });\n        }\n        throw error;\n      }","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/thedotmack/claude-mem/blob/d768ba364302d12b76e69e4f021f0bb1d2d50ed6/src/services/worker/knowledge/KnowledgeAgent.ts#L68-L104","documentation":"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.","triggerScenarios":"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).","commonSituations":"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).","solutions":["Call await agent.prime(corpus) before agent.query(corpus, question).","After reprime() (which nulls session_id), await its returned session before querying.","Guard callers: if (!corpus.session_id) await agent.prime(corpus); before query()."],"exampleFix":"// before\nconst result = await agent.query(corpus, question); // corpus.session_id === null\n\n// after\nif (!corpus.session_id) {\n  await agent.prime(corpus);\n}\nconst result = await agent.query(corpus, question);","handlingStrategy":"validation","validationCode":"if (!corpus.session_id) {\n  await agent.prime(corpus);\n}\nconst result = await agent.query(corpus, question);","typeGuard":"function isPrimed(c: CorpusFile): c is CorpusFile & { session_id: string } {\n  return typeof c.session_id === 'string' && c.session_id.length > 0;\n}","tryCatchPattern":"try {\n  await agent.query(corpus, question);\n} catch (err) {\n  if (err instanceof Error && /has no session — call prime first/.test(err.message)) {\n    await agent.prime(corpus);\n    return agent.query(corpus, question);\n  }\n  throw err;\n}","preventionTips":["Always prime a corpus before querying; enforce via a wrapper that auto-primes.","After reprime() (which nulls session_id), await its result before querying.","Persist session_id so freshly-loaded corpora are queryable."],"tags":["knowledge-agent","corpus","session","contract-violation"],"backgroundTag":null,"analyzedSha":"d768ba364302d12b76e69e4f021f0bb1d2d50ed6","analyzedAt":"2026-08-12T23:52:55.241Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}