Handle DB failures and tighten token accounting; add baseline-browser-mapping devDependency#63
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 42f250653f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (error) { | ||
| console.error('[chat_update_failed]', { userId: authorId, chatId, error }) | ||
| persistenceWarning = 'We generated your response, but could not save this chat message.' | ||
| } else { |
There was a problem hiding this comment.
Surface chat persistence failures through existing error path
When the chat update/insert fails here, the function now logs and sets persistenceWarning instead of returning an error, then still returns a successful payload. The only caller (components/PromptShell.tsx, where the result is destructured into answer, sessionId, chatId, and error) does not read warning, so in this failure mode the UI treats the response as saved even though nothing was persisted. This creates silent data loss on refresh whenever Supabase writes fail.
Useful? React with 👍 / 👎.
Motivation
Description
rawTokenCost = Number(generationResult.usage.totalTokens ?? 0)then sanitize usingNumber.isFinite,Math.round, and clamp to1..2_147_483_647, and computecreditsToChargeasMath.max(1, Math.min(tokenCost, creditsRemaining)).console.error, set apersistenceWarning, and trackchatPersistedso generation still returns an answer even if DB persistence fails.creditsToChargewhen callingincrementUserCreditsand retry accounting up tomaxAccountingAttempts, emitting ausageAccountingWarningand logging if accounting fails.persistenceWarningandusageAccountingWarninginto a singlewarningfield and computesessionIdreturned ascurrentSessionIdonly when the chat was actually persisted.baseline-browser-mappingtodevDependenciesinpackage.jsonand updatepnpm-lock.yamlaccordingly.Testing
Codex Task