{"record":{"id":"f2196e3e300f03ed","repo":"mastra-ai/mastra","slug":"harness-session-sessionid-was-not-found-f2196e","errorCode":null,"errorMessage":"Harness session \"${sessionId}\" was not found","messagePattern":"Harness session \"(.+?)\" was not found","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/core/src/storage/domains/harness/inmemory.ts","lineNumber":53,"sourceCode":"  }\n\n  async loadSession(sessionId: string): Promise<SessionRecord | null> {\n    const record = this.#sessions.get(sessionId);\n    return record ? cloneSessionRecord(record) : null;\n  }\n\n  async saveSession(record: SessionRecord): Promise<void> {\n    this.#sessions.set(record.id, cloneSessionRecord(record));\n  }\n\n  async listSessions(): Promise<SessionRecord[]> {\n    return [...this.#sessions.values()].map(cloneSessionRecord);\n  }\n\n  override async updateSession(sessionId: string, updates: SessionRecordUpdate): Promise<SessionRecord> {\n    const record = this.#sessions.get(sessionId);\n    if (!record) {\n      throw new Error(`Harness session \"${sessionId}\" was not found`);\n    }\n\n    const next = cloneSessionRecord({\n      ...record,\n      ...updates,\n      id: record.id,\n      createdAt: record.createdAt,\n      lastActivityAt: updates.lastActivityAt ?? new Date(),\n    });\n    this.#sessions.set(sessionId, next);\n    return cloneSessionRecord(next);\n  }\n}\n","sourceCodeStart":35,"sourceCodeEnd":67,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/storage/domains/harness/inmemory.ts#L35-L67","documentation":"The in-memory harness storage overrides `updateSession` and looks the session up directly in its `#sessions` map; it throws this error when the id is absent. Because this override does not route through `loadSession` like the base class, the same missing-session condition raises here for in-memory stores.","triggerScenarios":"Calling `updateSession` on an `InMemoryHarnessStorage` instance with an id not in its map: never created, already deleted, or created on a different instance.","commonSituations":"Multiple in-memory instances (per-test or per-request scoping) with ids shared across them; test setup that forgot to seed the session; hot-reload replacing the store instance between calls.","solutions":["Seed the session on the same in-memory instance via `createSession` before updating.","Assert in tests that setup created the session on the exact instance under test.","Centralize storage instance creation (DI/container) so all code shares one store.","Check `listSessions()` output on that instance to confirm what actually exists."],"exampleFix":"// before\nconst store = new InMemoryHarnessStorage();\nstore.updateSession('sess-1', updates); // throws: map empty\n// after\nconst store = new InMemoryHarnessStorage();\nawait store.createSession({ id: 'sess-1', /* ... */ });\nawait store.updateSession('sess-1', updates);","handlingStrategy":"validation","validationCode":"const store = getSharedHarnessStorage(); // one instance, not ad-hoc\nconst sessions = await store.listSessions();\nif (!sessions.some(s => s.id === sessionId)) {\n  await store.createSession({ id: sessionId });\n}\nawait store.updateSession(sessionId, updates);","typeGuard":"function isTrackedSession(sessions: SessionRecord[], id: string): boolean {\n  return sessions.some(s => s.id === id);\n}","tryCatchPattern":"try {\n  await store.updateSession(sessionId, updates);\n} catch (e) {\n  if (e instanceof Error && e.message.includes('was not found')) {\n    throw new Error(`Session ${sessionId} not in in-memory store; check instance reuse`);\n  }\n  throw e;\n}","preventionTips":["Never create multiple InMemoryHarnessStorage instances for the same logical dataset.","Seed sessions in test setup on the exact instance under test.","Provide the store via DI/container so all modules share it.","Remember in-memory stores reset on restart — use persistent storage for durability."],"tags":["storage","harness","in-memory","session-not-found"],"backgroundTag":"entity-not-found","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}