Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 7 additions & 17 deletions app/actions/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ export async function generateAnswer({ prompt, tool, authorId, authorEmail, atta
const title = existingTitle || (prompt.slice(0, 50) + (prompt.length > 50 ? '...' : ''))

let savedChatId = chatId
let persistenceWarning: string | undefined

if (chatId) {
// Update existing row
Expand All @@ -185,13 +186,7 @@ export async function generateAnswer({ prompt, tool, authorId, authorEmail, atta

if (error) {
console.error('[chat_update_failed]', { userId: authorId, chatId, error })
const errorMessage = 'Your response was generated, but we could not save this chat. Please try again.'
return {
answer: errorMessage,
sessionId: sessionId,
chatId: chatId,
error: errorMessage
}
persistenceWarning = 'We generated your response, but could not save this chat message.'
Comment on lines 187 to +189
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Surface persistence failures through existing error channel

This change converts chat save failures into warning only, but the current caller path still checks result.error (see components/PromptShell.tsx where error is destructured and handled) and does not consume warning, so persistence outages become silent data-loss events: users see a normal answer even though the message was not stored and are never prompted to retry. Please keep a machine-readable error signal for persistence failures (or wire warning in the caller) before removing the old error return behavior.

Useful? React with 👍 / 👎.

}
} else {
// Insert new row
Expand All @@ -211,15 +206,8 @@ export async function generateAnswer({ prompt, tool, authorId, authorEmail, atta

if (error) {
console.error('[chat_insert_failed]', { userId: authorId, sessionId: currentSessionId, error })
const errorMessage = 'Your response was generated, but we could not save this chat. Please try again.'
return {
answer: errorMessage,
sessionId: currentSessionId,
chatId: chatId,
error: errorMessage
}
}
if (data?.id) {
persistenceWarning = 'We generated your response, but could not save this chat message.'
} else if (data?.id) {
savedChatId = data.id
}
}
Expand Down Expand Up @@ -261,11 +249,13 @@ export async function generateAnswer({ prompt, tool, authorId, authorEmail, atta
})
}

const warning = [persistenceWarning, usageAccountingWarning].filter(Boolean).join(' ') || undefined

revalidatePath('/')
revalidatePath('/history')
if (usageAccountingSucceeded) {
revalidatePath('/profile')
}

return { answer, sessionId: currentSessionId, chatId: savedChatId, warning: usageAccountingWarning }
return { answer, sessionId: currentSessionId, chatId: savedChatId, warning }
}