{"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/d8bc9755e74915e5c3b999181e10a67c889bce2a/src/services/worker/knowledge/KnowledgeAgent.ts#L68-L104","documentation":"KnowledgeAgent.query() requires the corpus to have been primed: corpus.session_id must be set, otherwise it throws. The session_id ties queries to an existing Claude conversation that already ingested the corpus, so querying without one is an invalid state, not a retryable failure.","triggerScenarios":"Calling query() on a freshly loaded CorpusFile whose session_id was never written (prime never ran), on a corpus file created by another tool without priming, or on a hand-edited JSON corpus file where session_id was removed.","commonSituations":"Deploying a new corpus file and immediately running queries without a prime step; restoring corpus JSON from backup where session_id was null; a previous prime crashed (see error 155) leaving the file without a session; stale in-memory CorpusFile object.","solutions":["Call agent.prime(corpus) once before the first query to establish the session","Reload the corpus via corpusStore.read() to pick up a session_id written by another process","If the file legitimately has no session_id, prime it rather than hand-editing the JSON","Automate priming in your pipeline so query always follows a successful prime"],"exampleFix":"// before\nconst corpus = corpusStore.read('docs');\nconst answer = await agent.query(corpus, 'what changed?'); // throws\n// after\nlet corpus = corpusStore.read('docs');\nif (!corpus.session_id) {\n  await agent.prime(corpus);\n  corpus = corpusStore.read('docs');\n}\nconst answer = await agent.query(corpus, 'what changed?');","handlingStrategy":"validation","validationCode":"function isPrimed(corpus: { session_id?: string | null }): corpus is typeof corpus & { session_id: string } {\n  return typeof corpus.session_id === 'string' && corpus.session_id.length > 0;\n}\n// usage\nif (!isPrimed(corpus)) await agent.prime(corpus);","typeGuard":"function hasSession(c: { session_id?: string | null }): c is typeof c & { session_id: string } {\n  return typeof c.session_id === 'string' && c.session_id.length > 0;\n}","tryCatchPattern":"try {\n  return await agent.query(corpus, question);\n} catch (err) {\n  if (err instanceof Error && err.message.includes('has no session')) {\n    await agent.prime(corpus);\n    const fresh = corpusStore.read(corpus.name);\n    return agent.query(fresh, question);\n  }\n  throw err;\n}","preventionTips":["Always prime a new corpus before its first query — encode this in your pipeline","Never hand-edit corpus JSON in ways that can clear session_id","Restore corpus files together with their primed state, or re-prime after restore","Reload corpora from disk after external processes may have primed them"],"tags":["state-management","knowledge-base","lifecycle"],"backgroundTag":"invalid-state-transition","analyzedSha":"d8bc9755e74915e5c3b999181e10a67c889bce2a","analyzedAt":"2026-09-17T16:40:26.182Z","contentChangedAt":"2026-09-17T16:40:26.182Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}