{"record":{"id":"d9cf3f5acd6a094a","repo":"moeru-ai/airi","slug":"failed-to-load-the-target-chat-session","errorCode":null,"errorMessage":"Failed to load the target chat session","messagePattern":"Failed to load the target chat session","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/stage-ui/src/stores/chat.ts","lineNumber":395,"sourceCode":"\n  function appendSendError(sessionId: string, error: unknown) {\n    if (!chatSession.getSessionMessagesIfLoaded(sessionId))\n      return\n\n    chatSession.appendSessionMessage(sessionId, {\n      role: 'error',\n      content: errorMessageFrom(error) ?? 'Unknown chat operation failure',\n    })\n  }\n\n  async function executeSend(payload: ChatSendPayload): Promise<ChatSendResult> {\n    const providerId = activeProvider.value\n    const modelId = activeModel.value\n    if (!providerId || !modelId)\n      throw new Error('No active chat provider or model configured')\n\n    if (!await chatSession.loadSession(payload.sessionId))\n      throw new Error('Failed to load the target chat session')\n\n    const messageCount = chatSession.getSessionMessages(payload.sessionId).length\n    const chatProvider = await consciousnessStore.getChatProviderInstance(providerId)\n    if (!chatProvider)\n      throw new Error(`Failed to resolve chat provider \"${providerId}\"`)\n\n    await runtime.ingest(payload.text, {\n      model: modelId,\n      chatProvider,\n      attachments: payload.attachments,\n      input: payload.input,\n      toolReferences: payload.tools,\n      temperature: payload.temperature ?? consciousnessStore.activeTemperature,\n      topP: payload.topP ?? consciousnessStore.activeTopP,\n      // Resolve this function after the request reaches the per-session queue.\n      // The history then contains tool names from every earlier queued turn.\n      tools: async () => {\n        const references = collectToolReferences(payload.sessionId, payload.tools)","sourceCodeStart":377,"sourceCodeEnd":413,"githubUrl":"https://github.com/moeru-ai/airi/blob/f679616c34f1cf6d282c8d64264242af944b3fed/packages/stage-ui/src/stores/chat.ts#L377-L413","documentation":"executeSend calls chatSession.loadSession(sessionId), which hydrates a session's messages from IndexedDB (plus cloud sync when needed) and intentionally swallows internal errors, returning false when hydration fails or the id is unknown. This error means 'no loadable session with that id exists right now'. It is a storage/state problem, not a network chat failure.","triggerScenarios":"Sending to a sessionId that was deleted (drawer kept a stale id after deletion in another window); session never created before send; IndexedDB read failure (quota, corruption, blocked in restrictive browser modes); cloud hydration path failing for a cloud-backed session.","commonSituations":"Stale session ids persisted in UI state after the session was cleared elsewhere; browser storage eviction or corrupted IDB databases; multi-tab races where one tab clears sessions while another sends.","solutions":["Verify the session exists (check sessionMetas or the sessions list) and recreate it if the user expects it.","Refresh the session list in the UI when this error occurs so stale ids disappear.","Check browser storage health (quota, private-mode restrictions, IDB errors in devtools).","Create sessions through the session store API first and keep the generated id as the single source of truth."],"exampleFix":"// before\nawait chatStore.send({ sessionId, text })\n\n// after\nif (!chatSession.sessionMetas[sessionId]) {\n  sessionId = await chatSession.createSession(/* characterId, meta */)\n}\nawait chatStore.send({ sessionId, text })","handlingStrategy":"validation","validationCode":"// Ensure the session exists before sending\nif (!chatSession.sessionMetas[sessionId]) {\n  sessionId = await createOrReselectSession()\n}\nif (!await chatSession.loadSession(sessionId))\n  throw new Error(`Chat session ${sessionId} is not available`)\nawait chatStore.send({ sessionId, text })","typeGuard":null,"tryCatchPattern":"try {\n  await chatStore.send({ sessionId, text })\n}\ncatch (error) {\n  if (errorMessageFrom(error) === 'Failed to load the target chat session') {\n    await refreshSessions()\n    toast.info('This chat is no longer available; pick a session')\n    return\n  }\n  throw error\n}","preventionTips":["Always use session ids created by the session store; never fabricate them.","Refresh the sessions drawer after deletions so stale ids cannot be sent to.","When loadSession unexpectedly fails for an existing session, check IndexedDB health.","Keep a single source of truth for the active sessionId in app state."],"tags":["chat","session","indexeddb","state"],"backgroundTag":"session-not-found","analyzedSha":"f679616c34f1cf6d282c8d64264242af944b3fed","analyzedAt":"2026-08-28T13:11:01.995Z","contentChangedAt":"2026-08-28T13:11:01.995Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}