{"record":{"id":"4dcced2b0ec0f3f4","repo":"moeru-ai/airi","slug":"failed-to-load-the-target-chat-session-4dcced","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/session-store.ts","lineNumber":341,"sourceCode":"      void persistSession(sessionId)\n  }\n\n  function setSessionMessages(sessionId: string, next: ChatHistoryItem[]) {\n    replaceSessionMessages(sessionId, next)\n  }\n\n  function appendSessionMessage(sessionId: string, message: ChatHistoryItem) {\n    ensureSession(sessionId)\n    replaceSessionMessages(sessionId, [\n      ...(sessionMessages.value[sessionId] ?? []),\n      message,\n    ])\n  }\n\n  /** Removes one message by stable id or by its current history index. */\n  async function deleteMessage(payload: DeleteChatMessagePayload): Promise<void> {\n    if (!await loadSession(payload.sessionId))\n      throw new Error('Failed to load the target chat session')\n\n    const nextMessages = getSessionMessages(payload.sessionId).filter((message, messageIndex) => {\n      if (payload.messageId)\n        return message.id !== payload.messageId\n      if (payload.index !== undefined)\n        return messageIndex !== payload.index\n      return true\n    })\n\n    setSessionMessages(payload.sessionId, nextMessages)\n  }\n\n  /**\n   * Hydrate a single session's messages from IDB into memory. Idempotent —\n   * subsequent calls for the same id are no-ops.\n   *\n   * Use when:\n   * - The drawer is opening, the user is switching to a session, or any","sourceCodeStart":323,"sourceCodeEnd":359,"githubUrl":"https://github.com/moeru-ai/airi/blob/f679616c34f1cf6d282c8d64264242af944b3fed/packages/stage-ui/src/stores/chat/session-store.ts#L323-L359","documentation":"deleteMessage in the chat session store requires the target session to be hydrated first: loadSession(payload.sessionId) returning false (unknown id, deleted session, or a swallowed IndexedDB/cloud hydration error) is converted into this throw. The message deletion itself is a pure in-memory filter plus persist, so the only way to reach the error is the session not being loadable.","triggerScenarios":"Deleting a message from a session removed in another tab; acting on a stale sessionId retained by the messages component; IndexedDB failures (quota, corruption, restricted storage) during hydration; session list refreshed elsewhere while a delete action was pending.","commonSituations":"Message action menus rendered from cached history after the session was cleared; multi-tab usage; environments with flaky storage (private browsing, embedded webviews).","solutions":["Ensure the session is selected/loaded before showing per-message delete actions.","Refresh the sessions/messages state when this error occurs and clear stale ids.","Investigate storage health if the session is expected to exist.","For index-based deletes, recompute indices from the freshly loaded messages."],"exampleFix":"// before\nawait chatSession.deleteMessage({ sessionId, index })\n\n// after\nif (!await chatSession.loadSession(sessionId)) {\n  await refreshSessions()\n  toast.info('This chat no longer exists')\n  return\n}\nawait chatSession.deleteMessage({ sessionId, index })","handlingStrategy":"validation","validationCode":"if (!await chatSession.loadSession(sessionId)) {\n  await refreshSessions()\n  return\n}\nawait chatSession.deleteMessage(payload)","typeGuard":null,"tryCatchPattern":"try {\n  await chatSession.deleteMessage({ sessionId, messageId })\n}\ncatch (error) {\n  if (errorMessageFrom(error) === 'Failed to load the target chat session') {\n    await refreshSessions()\n    return\n  }\n  throw error\n}","preventionTips":["Prefer messageId over index for deletes so shifted indices cannot target the wrong turn.","Close message action menus when the session changes or unloads.","After session deletion elsewhere, refresh the messages view before allowing edits.","Validate storage availability before rendering message edit affordances in restricted environments."],"tags":["chat","session","indexeddb","state"],"backgroundTag":"session-not-found","analyzedSha":"f679616c34f1cf6d282c8d64264242af944b3fed","analyzedAt":"2026-08-18T17:29:58.153Z","contentChangedAt":"2026-08-18T17:29:58.153Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}