Skip to content

fix(libsql): parse scientific notation cost aggregates#3296

Merged
serrrfirat merged 1 commit into
nearai:stagingfrom
serrrfirat:fix/admin-users-cost-decimal
May 6, 2026
Merged

fix(libsql): parse scientific notation cost aggregates#3296
serrrfirat merged 1 commit into
nearai:stagingfrom
serrrfirat:fix/admin-users-cost-decimal

Conversation

@serrrfirat
Copy link
Copy Markdown
Collaborator

Summary

  • fix libSQL user/admin usage cost aggregate parsing when SQLite emits scientific notation (for example, 7.5e-05)
  • cover the /api/admin/users caller path with a tiny-cost regression test

Root cause

The failing E2E job returned 500 from /api/admin/users because libSQL CAST(SUM(l.cost) AS TEXT) can produce scientific notation for small costs. rust_decimal::Decimal::from_str_exact rejects exponent notation, so user_summary_stats surfaced invalid cost value '7.5e-05'.

Verification

  • cargo fmt --check
  • cargo test --lib --no-default-features --features libsql test_admin_user_list_handles_tiny_costs_from_libsql -- --nocapture
  • cargo test --lib --no-default-features --features libsql test_user_summary_stats_with_jobs_and_costs -- --nocapture
  • cargo test --lib --no-default-features --features libsql test_user_usage_stats_with_calls -- --nocapture
  • cargo test --lib --no-default-features --features libsql test_admin_usage_summary_aggregates_in_db -- --nocapture
  • python -m pytest scenarios/test_settings_search.py::test_search_filters_user_rows -q (via Python 3.11 venv)
  • cargo check --no-default-features --features libsql -q

Risk

Low: scoped to libSQL parsing of text-rendered aggregate decimal values; PostgreSQL paths are unchanged.

@github-actions github-actions Bot added scope: channel/web Web gateway channel size: S 10-49 changed lines risk: medium Business logic, config, or moderate-risk modules contributor: core 20+ merged PRs labels May 6, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a helper function parse_libsql_decimal_text in the libSQL backend to correctly handle decimal values that may be returned in scientific notation, particularly for very small costs. Several locations in the database layer were updated to use this new parsing logic. Additionally, a regression test was added to ensure the admin user list API can process these small cost values without error. I have no feedback to provide as there were no review comments.

@serrrfirat serrrfirat merged commit b0cb233 into nearai:staging May 6, 2026
11 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor: core 20+ merged PRs risk: medium Business logic, config, or moderate-risk modules scope: channel/web Web gateway channel size: S 10-49 changed lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant