Title: lab-ops-hub: /api/budget hardcodes estimated_overage_usd to 0 and undercounts D1 writes (PR #436) · Issue #442 · developing-today/code · GitHub
Open Graph Title: lab-ops-hub: /api/budget hardcodes estimated_overage_usd to 0 and undercounts D1 writes (PR #436) · Issue #442 · developing-today/code
X Title: lab-ops-hub: /api/budget hardcodes estimated_overage_usd to 0 and undercounts D1 writes (PR #436) · Issue #442 · developing-today/code
Description: Finding PR #436 (#436, head a772fc2f391234cbdd4ed169d9174b13e8994801, initial commit 98381153702ef50135230e1d941040e4bbb4f4db) makes /api/budget the centrepiece of pkgs/lab-ops-hub — the README says: "The budget endpoint is the point … s...
Open Graph Description: Finding PR #436 (#436, head a772fc2f391234cbdd4ed169d9174b13e8994801, initial commit 98381153702ef50135230e1d941040e4bbb4f4db) makes /api/budget the centrepiece of pkgs/lab-ops-hub — the README say...
X Description: Finding PR #436 (#436, head a772fc2f391234cbdd4ed169d9174b13e8994801, initial commit 98381153702ef50135230e1d941040e4bbb4f4db) makes /api/budget the centrepiece of pkgs/lab-ops-hub — the README say...
Opengraph URL: https://github.com/developing-today/code/issues/442
X: @github
Domain: github.com
IPv4 address: 140.82.114.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"lab-ops-hub: /api/budget hardcodes estimated_overage_usd to 0 and undercounts D1 writes (PR #436)","articleBody":"## Finding\n\nPR #436 (https://github.com/developing-today/code/pull/436, head `a772fc2f391234cbdd4ed169d9174b13e8994801`, initial commit `98381153702ef50135230e1d941040e4bbb4f4db`) makes `/api/budget` the centrepiece of `pkgs/lab-ops-hub` — the README says: \"The budget endpoint is the point … so the demo continuously proves it is costing $0 over the $5 plan.\" The implementation in `pkgs/lab-ops-hub/src/index.ts` cannot prove that:\n\n1. **The overage figure is a literal.** The budget handler (:140–:152) returns `estimated_overage_usd: 0` unconditionally. Each resource row in the same response carries `used`, `included`, and an overage rate, but no code ever compares `used` to `included` or computes an estimate — the endpoint would report $0 even after a limit is passed.\n2. **`d1_rows_written` is badly undercounted.** It reports `used: by.d1_write ?? 0`, but `logUsage(env, \"d1_write\", …)` is only called after a machine insert (:169) and a note insert (:182). D1 writes that never emit that event include: every `logUsage` ledger insert itself (:36 — at least one per request, for `worker_request`), the tasks insert (:208), the files-metadata insert (:225), the summary `UPDATE` (:197), the crawls insert (:264), and the queue consumer's `files` `UPDATE` (~:288). Actual D1 rows written are therefore many times the reported number (the `worker_request` ledger alone guarantees writes ≥ requests).\n\nVerified against the PR head code above; the package is not on `main` yet. Deduped: issue searches for `lab-ops-hub`, `budget`, `overage` return no existing issue. Cross-repo: the package exists only in this repo/PR.\n\n## Why it matters\n\nA self-check whose answer is hard-coded to \"$0, under budget\" is worse than no self-check: the first time usage actually exceeds an included amount (see the unauthenticated-endpoint exposure in the sibling issue), the dashboard will still claim $0 and the overage will be discovered on the Cloudflare bill instead.\n\n## Acceptance criteria\n\n- [ ] `estimated_overage_usd` is computed from the counted usage: for each resource with an `included` amount and a rate, `max(0, used - included) * rate`, summed (resources without a rate are excluded from the sum but still shown)\n- [ ] The `d1_write` counter covers every D1 write path (or the row is renamed/documented as \"counted application writes\" and the ledger's own writes are accounted for explicitly) — a request sequence of known writes (e.g. 1 task POST + 1 file POST + 1 crawl POST) moves the counter by the true number of rows written\n- [ ] A test or scripted check demonstrates the endpoint reports a non-zero estimate when recorded usage exceeds an included amount (e.g. by seeding `usage_events` past a threshold)\n","author":{"url":"https://github.com/dezren39","@type":"Person","name":"dezren39"},"datePublished":"2026-10-20T20:31:12Z","url":"https://github.com/developing-today/code/issues/442"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:4ba51c81-b7cd-12c6-496b-6ec74a02bb28 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D3CC:2EAB91:A24567:D30277:6B063729 |
| html-safe-nonce | 27b5afd9725f6c358e02231879d19799d94e664fa6b6450f558d8fec1616bb3b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEM0NDOjJFQUI5MTpBMjQ1Njc6RDMwMjc3OjZCMDYzNzI5IiwidmlzaXRvcl9pZCI6IjYyNDc3Mjg4NzUzMzA0ODQwMTAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | f90717222001ab77d3589e45ced9536beeaed584468215e28eecef775e077d69 |
| hovercard-subject-tag | issue:5949165052 |
| github-keyboard-shortcuts | repository,issues,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/_view_fragments/issues/show/developing-today/code/442/issue_layout |
| twitter:image | https://opengraph.githubassets.com/3555789ef5d720d57cc2030100b4f95dde1beaa1c25006b52c2bb1ea6e3719db/developing-today/code/issues/442 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/3555789ef5d720d57cc2030100b4f95dde1beaa1c25006b52c2bb1ea6e3719db/developing-today/code/issues/442 |
| og:image:alt | Finding PR #436 (#436, head a772fc2f391234cbdd4ed169d9174b13e8994801, initial commit 98381153702ef50135230e1d941040e4bbb4f4db) makes /api/budget the centrepiece of pkgs/lab-ops-hub — the README say... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | dezren39 |
| hostname | github.com |
| expected-hostname | github.com |
| None | c3584c853cd39700ecff6e2cf8364295ffdb5313e571046c41cd2479270f7df0 |
| turbo-cache-control | no-preview |
| go-import | github.com/developing-today/code git https://github.com/developing-today/code.git |
| octolytics-dimension-user_id | 26439447 |
| octolytics-dimension-user_login | developing-today |
| octolytics-dimension-repository_id | 627308783 |
| octolytics-dimension-repository_nwo | developing-today/code |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 627308783 |
| octolytics-dimension-repository_network_root_nwo | developing-today/code |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 9eb3bb1597d09170a5f282cd38ae376dee1a5ec1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width