{"record":{"id":"5c58002e1cdadeaa","repo":"mastra-ai/mastra","slug":"harness-session-sessionid-was-not-found","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/base.ts","lineNumber":21,"sourceCode":"\nexport abstract class HarnessStorage extends StorageDomain {\n  constructor() {\n    super({\n      component: 'STORAGE',\n      name: 'HARNESS',\n    });\n  }\n\n  abstract loadSession(sessionId: string): Promise<SessionRecord | null>;\n\n  abstract saveSession(record: SessionRecord): Promise<void>;\n\n  abstract listSessions(): Promise<SessionRecord[]>;\n\n  async updateSession(sessionId: string, updates: SessionRecordUpdate): Promise<SessionRecord> {\n    const record = await this.loadSession(sessionId);\n    if (!record) {\n      throw new Error(`Harness session \"${sessionId}\" was not found`);\n    }\n\n    const next: SessionRecord = {\n      ...record,\n      ...updates,\n      id: record.id,\n      createdAt: record.createdAt,\n      lastActivityAt: updates.lastActivityAt ?? new Date(),\n    };\n    await this.saveSession(next);\n    return next;\n  }\n\n  async appendPendingItem(sessionId: string, item: HarnessPendingItemRecord): Promise<SessionRecord> {\n    const record = await this.loadSession(sessionId);\n    if (!record) {\n      throw new Error(`Harness session \"${sessionId}\" was not found`);\n    }","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/storage/domains/harness/base.ts#L3-L39","documentation":"`HarnessStorage.updateSession` loads the session record by id and throws this error when `loadSession` returns nothing. It guarantees updates only apply to sessions that actually exist in the harness storage backend. All pending-item helpers (`appendPendingItem`, `updatePendingItem`, `removePendingItem`) funnel through it, so a missing session surfaces here.","triggerScenarios":"Calling `updateSession(sessionId, updates)` with a sessionId that was never created, was already deleted, or exists only in a different storage backend/instance.","commonSituations":"Reusing a sessionId from a previous process run against a fresh in-memory store; using an id from one harness backend while updating another (e.g. Postgres vs in-memory); truncated or transformed ids; cleanup job deleted the session before the update arrived.","solutions":["Create the session first (e.g. `createSession`) and use the returned record's id for subsequent updates.","Check session existence with `loadSession(sessionId)` or `listSessions()` before updating.","Confirm you are pointing at the same storage instance/backend where the session was created.","Log/inspect the sessionId being used; verify it is not stale from an earlier run."],"exampleFix":"// before\nawait harnessStorage.updateSession('sess-abc', { status: 'completed' }); // throws if absent\n// after\nconst existing = await harnessStorage.loadSession('sess-abc');\nif (existing) {\n  await harnessStorage.updateSession('sess-abc', { status: 'completed' });\n}","handlingStrategy":"try-catch","validationCode":"const record = await storage.loadSession(sessionId);\nif (!record) throw new Error(`Refusing to update missing session ${sessionId}`);","typeGuard":"function hasSession(r: SessionRecord | null | undefined): r is SessionRecord {\n  return r != null && typeof r.id === 'string';\n}","tryCatchPattern":"try {\n  await storage.updateSession(sessionId, updates);\n} catch (e) {\n  if (e instanceof Error && e.message.includes('was not found')) {\n    await storage.createSession({ id: sessionId, ...baseFields });\n    await storage.updateSession(sessionId, updates);\n    return;\n  }\n  throw e;\n}","preventionTips":["Persist sessions in a durable backend if they must survive restarts.","Always obtain sessionIds from createSession's return value.","Check loadSession before batch update operations.","Include sessionId in error logs to spot stale ids quickly."],"tags":["storage","harness","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"}