{"record":{"id":"b62482eee2ea006a","repo":"mastra-ai/mastra","slug":"stored-response-body-previous-response-id-was-n","errorCode":null,"errorMessage":"Stored response ${body.previous_response_id} was not found","messagePattern":"Stored response (.+?) was not found","errorType":"http","errorClass":"HTTPException","httpStatus":404,"severity":"error","filePath":"packages/server/src/server/handlers/responses.ts","lineNumber":669,"sourceCode":"      if (!previousResponseTurnRecord) {\n        const owningResponseTurnRecord = await findResponseTurnRecordAcrossAgents({\n          mastra,\n          responseId: body.previous_response_id,\n          requestContext,\n        });\n\n        if (owningResponseTurnRecord) {\n          if (owningResponseTurnRecord.metadata.agentId === body.agent_id) {\n            previousResponseTurnRecord = owningResponseTurnRecord;\n          } else {\n            throw new HTTPException(400, {\n              message: `Stored response ${body.previous_response_id} belongs to agent ${owningResponseTurnRecord.metadata.agentId}, not ${body.agent_id}`,\n            });\n          }\n        }\n\n        if (!previousResponseTurnRecord) {\n          throw new HTTPException(404, { message: `Stored response ${body.previous_response_id} was not found` });\n        }\n      }\n    } else {\n      if (!mastra) {\n        throw new HTTPException(500, { message: 'Mastra instance is required for agent-backed responses' });\n      }\n\n      previousResponseTurnRecord = await findResponseTurnRecordAcrossAgents({\n        mastra,\n        responseId: body.previous_response_id,\n        requestContext,\n      });\n\n      if (!previousResponseTurnRecord) {\n        throw new HTTPException(404, { message: `Stored response ${body.previous_response_id} was not found` });\n      }\n    }\n  }","sourceCodeStart":651,"sourceCodeEnd":687,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/server/src/server/handlers/responses.ts#L651-L687","documentation":"When previous_response_id is supplied, the server looks up the stored response turn record. If no record exists with that ID, prepareCreateResponseRequest throws this 404 — chaining requires a real, previously stored response.","triggerScenarios":"POST /api/responses with a previous_response_id that was never created, was created with store semantics off, was deleted, or exists in a different database/environment.","commonSituations":"Replaying old session ids against a fresh DB; typo'd or fabricated response ids; retention/cleanup removing old turns; pointing the client at another environment than where the response was stored.","solutions":["Verify the previous_response_id came from an actual prior response in the same environment/storage","Drop previous_response_id to start a new conversation","Check the server's storage backend contains the response turn record","Fix client caching so ids are taken from the latest stored response, not stale state"],"exampleFix":"// before\nconst r = await client.responses.create({ agent_id: 'a', previous_response_id: 'resp_hardcoded_123', input: 'more' });\n// after\nconst first = await client.responses.create({ agent_id: 'a', input: 'hi' });\nconst r = await client.responses.create({ agent_id: 'a', previous_response_id: first.id, input: 'more' });","handlingStrategy":"try-catch","validationCode":"if (previousResponseId && !(await responseExists(previousResponseId))) throw new Error(`Stored response ${previousResponseId} missing`);","typeGuard":"null","tryCatchPattern":"try {\n  return await client.responses.create({ agent_id, previous_response_id, input });\n} catch (e) {\n  if (e?.status === 404 && /was not found/.test(e.message)) {\n    return client.responses.create({ agent_id, input }); // start fresh conversation\n  }\n  throw e;\n}","preventionTips":["Only chain from response ids actually returned by prior stored responses","Clear stale ids after storage resets or environment switches","Check storage retention policies before long-lived chaining"],"tags":["server","http-404","responses-api","storage"],"backgroundTag":"resource-not-found","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}