moeru-ai/airi · error
[chat-session] loadSession failed for
Error message
[chat-session] loadSession failed for
What it means
loadSession wraps the whole load path — reading the canonical conversation from IDB, optional cloud pull via pullCloudMessages, and ensureSession — in a try/catch. On failure it logs the sessionId plus the error and returns false; crucially it does NOT mark the session as loaded, so the next loadSession call retries rather than fast-returning on stale state, and the loadingSessions map entry is always drained in finally.
Source
Thrown at packages/stage-ui/src/stores/chat/session-store.ts:435
refreshActiveSessionSystemMessage()
}
// Local and cloud hydration are separate. A failed cloud pull leaves
// the local view usable and keeps the next selection eligible to retry.
if (needsCloudHydration())
await pullCloudMessages(sessionId)
// Missing IDB payloads still need a valid canonical conversation.
// This action runs in the elected leader, so the initialized history
// is published once rather than independently by every follower.
ensureSession(sessionId)
return true
}
catch (err) {
// Do NOT add to loadedSessions on failure — the next call should
// retry rather than fast-return on stale "already loaded" state.
console.warn('[chat-session] loadSession failed for', sessionId, errorMessageFrom(err))
return false
}
})()
loadingSessions.set(sessionId, loadPromise)
try {
return await loadPromise
}
finally {
// Always drain the loading map so a transient failure does not leave
// a permanent wedge entry.
loadingSessions.delete(sessionId)
}
}
/** Forces the next session load to merge the latest IndexedDB record into memory. */
async function refreshSession(sessionId: string): Promise<boolean> {
staleSessions.add(sessionId)View on GitHub (pinned to f679616c34)
Solutions
- Read the logged cause: IDB errors (NotFoundError/DataError) point to missing/renamed object stores — clear stale DB or add a schema migration.
- For cloud pull failures, re-authenticate the sync backend and retry loading the session (retry is automatic on next call).
- Add defensive deserialization so one corrupted record cannot fail the whole session load.
- If storage was evicted, accept the loss path: ensureSession will rebuild an empty canonical conversation on the next successful load.
Defensive patterns
Strategy: retry
Validate before calling
function sessionExistsInIdb(sessionId: string): Promise<boolean> {
// lightweight existence probe before full load, if the IDB wrapper exposes it
return idbStore.has(sessionId)
} Type guard
function isCloudSyncError(err: unknown): boolean {
const msg = errorMessageFrom(err)
return msg.includes('401') || msg.includes('403') || msg.includes('fetch failed')
} Try / catch
try {
return await loadSessionInternal(sessionId)
}
catch (err) {
// do not mark loaded; next call retries (existing contract)
if (isCloudSyncError(err)) {
// prompt re-auth for the sync backend, then call loadSession again
}
console.warn('[chat-session] loadSession failed for', sessionId, errorMessageFrom(err))
return false
} Prevention
- Add schema migration/versioning for stored conversations to survive app upgrades.
- Re-auth cloud sync tokens proactively before they expire.
- Defensively validate deserialized records so one bad session cannot fail the load path repeatedly.
When it happens
Trigger: The IDB read transaction aborts (version change, connection closed), stored data fails to deserialize into the expected conversation shape, or the cloud-sync pull throws (auth failure, network, unexpected response) when a cloud backend is configured.
Common situations: Browser evicted/cleared IDB data while the app cached an in-memory session list; app version upgrade changing the stored schema without migration; sync token/session expired causing pullCloudMessages to reject; corrupted record for one session after a crash mid-write.
Related errors
- [chat-session] persist task failed:
- [mmd] motion file "${descriptor.name}" (${descriptor.id}) no
- Failed to load the target chat session
- Failed to load the target chat session
AI-assisted analysis of moeru-ai/airi@f679616c34 (2026-08-18).
Data as JSON: /api/errors/7d1974a22584a318.
Report an issue: GitHub.