Skip to content

Robust token accounting and persistence warnings; add baseline-browser-mapping devDependency#61

Merged
Abdulmuiz44 merged 2 commits into
codex/ui-redesignfrom
codex/fix-upgrade-modal-for-credit-check-lsh01d
Apr 6, 2026
Merged

Robust token accounting and persistence warnings; add baseline-browser-mapping devDependency#61
Abdulmuiz44 merged 2 commits into
codex/ui-redesignfrom
codex/fix-upgrade-modal-for-credit-check-lsh01d

Conversation

@Abdulmuiz44
Copy link
Copy Markdown
Collaborator

Motivation

  • Ensure token usage and charging are robust against malformed or large values and avoid failing generation when user credits are low.
  • Prevent hard failures on DB write issues so responses can still be returned while surfacing persistence warnings.
  • Keep dependency graph consistent by adding a missing dev dependency needed in lockfile updates.

Description

  • Replace previous token cost logic with safe parsing and clamping: compute rawTokenCost, round and clamp to [1, 2_147_483_647], and derive creditsToCharge as Math.max(1, Math.min(tokenCost, creditsRemaining)).
  • Remove early error return when tokenCost > creditsRemaining so responses are still generated and allow charging up to remaining credits.
  • Replace thrown errors on Supabase update/insert failures with console.error logs and set a persistenceWarning string so the API returns the generated answer with a warning instead of failing.
  • Use creditsToCharge when calling incrementUserCredits, keep retry logic, and consolidate persistenceWarning and usageAccountingWarning into a single warning returned to callers.
  • Add baseline-browser-mapping to devDependencies in package.json and update the pnpm-lock.yaml snapshots to match the upgraded dependency versions.

Testing

  • Ran TypeScript checks with tsc --noEmit and the code type-checks successfully.
  • Executed the test suite with pnpm test and all tests passed.
  • Performed a local build with pnpm build to validate install and lockfile changes, and the build completed successfully.

Codex Task

@Abdulmuiz44 Abdulmuiz44 merged commit 8cda8d0 into codex/ui-redesign Apr 6, 2026
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant