Title: fix(billing): stop the false unbilled-charge error on zero-cost runs by waleedlatif1 · Pull Request #6333 · simstudioai/sim · GitHub
Open Graph Title: fix(billing): stop the false unbilled-charge error on zero-cost runs by waleedlatif1 · Pull Request #6333 · simstudioai/sim
X Title: fix(billing): stop the false unbilled-charge error on zero-cost runs by waleedlatif1 · Pull Request #6333 · simstudioai/sim
Description: Problem Every usage-gated (blocked) execution emitted an ERROR-level log: Failed to record execution usage to usage_log ledger; charge may be unbilled This is a 100% false positive on that path. It claims possible revenue loss on runs that never executed and have zero cost — exactly the line an engineer pages on. It misdirected a production investigation for hours. Across 5 days / 683 occurrences, sum(totalCost) = 0 and max(totalCost) = 0. Mechanism (verified) apps/sim/lib/execution/preprocessing.ts logPreprocessingError calls session.safeCompleteWithError({ skipCost: true }) and passes no billingAttribution. skipCost: true makes logging-session.ts build an all-zero costSummary (no base charge, no models, no charges). logger.ts recordExecutionUsage required a billing context before building targets[]: if (workflowRecord.workspaceId && !billingContext) { throw new Error('Billing attribution is required for workspace execution usage') } The throw was caught by the surrounding catch, which logs the unbilled-charge ERROR — even though targets[] would have been empty and recordUsage would never have been called. Fix Move the existing if (targets.length === 0) return 0 early return above the attribution requirement. Pure reordering — no new predicate. No charge can be lost by this change. When targets.length === 0 there is nothing to insert into usage_log: both the old path (throw → catch → log → return 0) and the new path (return 0) record exactly zero. The only difference is the spurious ERROR. Every path with a non-zero target still requires billingContext and still throws when it is missing. Genuine under-billing still alerts The ERROR log is not silenced. Any real ledger failure — a recordUsage insert failure, a transaction/advisory-lock failure, or missing billing attribution on a run that does have cost — still reaches the same catch and still logs at ERROR with the full costSummary. Alerting on this line remains valid; it is now specific. Tests a structurally zero-cost run without billing context logs no unbilled-charge error — fails without the fix (1 spurious ERROR call). a genuine ledger write failure still logs the unbilled-charge error — regression guard; fails if anyone downgrades or removes the ERROR (verified by temporarily switching it to warn). The file's @sim/logger mock is overridden locally so withMetadata() children share one spy set, making log level assertable. Verification bunx vitest run lib/logs/execution/logger.test.ts lib/logs/execution/logging-session.test.ts — 98 passed bunx tsc --noEmit -p apps/sim/tsconfig.json — clean bun run lint — clean
Open Graph Description: Problem Every usage-gated (blocked) execution emitted an ERROR-level log: Failed to record execution usage to usage_log ledger; charge may be unbilled This is a 100% false positive on that path. ...
X Description: Problem Every usage-gated (blocked) execution emitted an ERROR-level log: Failed to record execution usage to usage_log ledger; charge may be unbilled This is a 100% false positive on that path. ...
Opengraph URL: https://github.com/simstudioai/sim/pull/6333
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:d67dac20-ed53-93b9-61cf-36e1ef08a4cc |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | C438:1EFDE9:B09B1C:F29080:6AFB521D |
| html-safe-nonce | bf20a21f90ac4ddc638b45facb9039913d81b02ab04085229e34c524933e28d3 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNDM4OjFFRkRFOTpCMDlCMUM6RjI5MDgwOjZBRkI1MjFEIiwidmlzaXRvcl9pZCI6IjE1MjQ2NzIyNTg5NzMwNjE2NjIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 50b92f8994a535042e3ccbb4e4be57b1d8b47287168c6ad7287b99a779c6b8eb |
| hovercard-subject-tag | pull_request:4223273146 |
| 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/6333/files |
| twitter:image | https://avatars.githubusercontent.com/u/40672544?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/40672544?s=400&v=4 |
| og:image:alt | Problem Every usage-gated (blocked) execution emitted an ERROR-level log: Failed to record execution usage to usage_log ledger; charge may be unbilled This is a 100% false positive on that path. ... |
| 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 full-width |
| 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