Title: fix(billing): drop transaction wrapper in recordUsage to relieve pool contention by TheodoreSpeaks · Pull Request #4494 · simstudioai/sim · GitHub
Open Graph Title: fix(billing): drop transaction wrapper in recordUsage to relieve pool contention by TheodoreSpeaks · Pull Request #4494 · simstudioai/sim
X Title: fix(billing): drop transaction wrapper in recordUsage to relieve pool contention by TheodoreSpeaks · Pull Request #4494 · simstudioai/sim
Description: Summary Split recordUsage() in apps/sim/lib/billing/core/usage-log.ts into two independent statements (INSERT into usage_log, UPDATE on user_stats) instead of one wrapped transaction Under high concurrency for a single user (~90 workflow finishes in seconds), the transaction wrapper pinned pgbouncer connections through the entire user_stats row-lock wait, exhausting the pool and failing unrelated requests with query_wait_timeout and connection-terminated errors Without the transaction, each statement only holds its connection while executing, so contention stays inside Postgres's row-lock queue and does not bleed into the pool usage_log is the source of truth (immutable ledger); if the user_stats UPDATE fails after a successful INSERT the counter drifts and must be reconciled from usage_log out-of-band. The "row not found" case now logs a warning instead of throwing (no transaction to roll back) Type of Change Bug fix Testing Tested manually. bun run lint clean, bun run check:api-validation:strict passes, tsc --noEmit clean for the touched file. No tests directly cover recordUsage. Followup: add a periodic reconciler that SUMs usage_log per period and corrects user_stats.currentPeriodCost to recover from any UPDATE failures. Checklist Code follows project style guidelines Self-reviewed my changes Tests added/updated and passing No new warnings introduced I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)
Open Graph Description: Summary Split recordUsage() in apps/sim/lib/billing/core/usage-log.ts into two independent statements (INSERT into usage_log, UPDATE on user_stats) instead of one wrapped transaction Under high co...
X Description: Summary Split recordUsage() in apps/sim/lib/billing/core/usage-log.ts into two independent statements (INSERT into usage_log, UPDATE on user_stats) instead of one wrapped transaction Under high co...
Opengraph URL: https://github.com/simstudioai/sim/pull/4494
X: @github
Domain: github.com
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf |
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:05f8806b-3fde-493d-58c3-44342f182377 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | BE8C:487EF:A7CE54:E7832D:6AFB51B8 |
| html-safe-nonce | d961cf80ff4663dceef3eaf3676bae6f5e0af3a458eb6b09a0dc060119eedf53 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCRThDOjQ4N0VGOkE3Q0U1NDpFNzgzMkQ6NkFGQjUxQjgiLCJ2aXNpdG9yX2lkIjoiMTk0ODI3MTg2OTYyNjYzNDY4MCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 6471e27e57f23a6c918a60ee34e864d97f3dad87b9ae90ef83d6bcbcac7b4bb9 |
| hovercard-subject-tag | pull_request:3644583405 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/simstudioai/sim/pull/4494/files |
| twitter:image | https://avatars.githubusercontent.com/u/19564703?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/19564703?s=400&v=4 |
| og:image:alt | Summary Split recordUsage() in apps/sim/lib/billing/core/usage-log.ts into two independent statements (INSERT into usage_log, UPDATE on user_stats) instead of one wrapped transaction Under high co... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7122bb414b542dba14d71a3f0b9f6fd2abce715b9f5912d082800563e6c806d1 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/simstudioai/sim git https://github.com/simstudioai/sim.git |
| octolytics-dimension-user_id | 199344406 |
| octolytics-dimension-user_login | simstudioai |
| octolytics-dimension-repository_id | 912559512 |
| octolytics-dimension-repository_nwo | simstudioai/sim |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 912559512 |
| octolytics-dimension-repository_network_root_nwo | simstudioai/sim |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | cbf66c024bb6d10e6955baa7413c54cf13a201bb |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width