fix(billing): reconcile Cloudflare usage per meter run - #4897
Conversation
Code Review SummaryStatus: 2 Issues Found | Recommendation: Address before merge Executive SummaryDropping the isolation retry removed the fan-out, but the replacement makes any path-less provider error abort the entire reconciliation and discard rows and raw diagnostics that the single-run path would have returned as partial. Overview
Issue Details (click to expand)WARNING
SUGGESTION
Previously reported issues now resolved
Files Reviewed (2 files)
Notes and assumptions
Fix these issues in Kilo Cloud Previous Review Summaries (4 snapshots, latest commit f45e618)Current summary above is authoritative. Previous snapshots are kept for context only. Previous review (commit f45e618)Status: 3 Issues Found | Recommendation: Address before merge Executive SummaryThe new per-run isolation retry fixes the batch-wide partial marking, but it re-fans a failed batch into one request per plan with no backoff, which amplifies the throttling and complexity errors that trigger it and can abort the whole reconciliation on a retry timeout or retained-byte overflow. Overview
Issue Details (click to expand)WARNING
SUGGESTION
Previously reported issues now resolved
Files Reviewed (3 files)
Notes and assumptions
Fix these issues in Kilo Cloud Previous review (commit 51bd340)Status: 4 Issues Found | Recommendation: Address before merge Executive SummaryThe new 15-alias batching fixes all five previous findings, but a single Cloudflare GraphQL error without a Overview
Issue Details (click to expand)WARNING
SUGGESTION
Previously reported issues now resolved
Files Reviewed (5 files)
Notes and assumptions
Fix these issues in Kilo Cloud Previous review (commit 20d2835)Status: 5 Issues Found | Recommendation: Address before merge Executive SummaryNo application code changed since the previous review; the per-run Cloudflare retention check still throws instead of degrading, so one out-of-retention interval in the displayed page blocks reconciliation of every other selected record. Overview
Issue Details (click to expand)WARNING
SUGGESTION
Files Reviewed (5 files)
Notes and assumptions
Fix these issues in Kilo Cloud Previous review (commit b860dc0)Status: 5 Issues Found | Recommendation: Address before merge Executive SummaryThe new per-run Cloudflare retention check throws instead of degrading, so a single out-of-retention interval in the displayed page blocks reconciliation of every other selected record. Overview
Issue Details (click to expand)WARNING
SUGGESTION
Files Reviewed (5 files)
Notes and assumptions
Reviewed by claude-opus-5 · Input: 34 · Output: 9.8K · Cached: 814.5K Review guidance: REVIEW.md from base branch |
| const MAX_INSTANCE_BATCH_SIZE = 50; | ||
| const MAX_PROVIDER_REQUESTS = 100; | ||
| const MAX_PROVIDER_QUERY_PLANS = 100; | ||
| const MAX_RUN_WINDOWS_PER_REQUEST = 15; |
There was a problem hiding this comment.
SUGGESTION: Batch size is not derived from the dataset's advertised field budget
A full batch selects 6 leaf fields per alias (dimensions.applicationId, dimensions.instanceId, and 4 sums), i.e. 90 for 15 aliases, while validateSettings still only asserts maxNumberOfFields >= REQUIRED_FIELDS.length (6) and the test fixture advertises maxNumberOfFields: 30. If Cloudflare applies that limit per request rather than per node, a full batch is rejected outright and takes 15 runs down together, even though the settings check reported the account as usable. Deriving the cap (e.g. Math.min(MAX_RUN_WINDOWS_PER_REQUEST, Math.max(1, Math.floor(settings.maxNumberOfFields / REQUIRED_FIELDS.length)))) would make the request provably within the advertised budget.
Reply with @kilocode-bot fix it to have Kilo Code address this issue.
There was a problem hiding this comment.
No behavior change: Cloudflare applies maxNumberOfFields per aliased dataset selection, not cumulatively across aliases. The account advertises 30 fields and a live 15-alias request selecting 6 fields per alias succeeds. Added an explanatory comment in f45e618.
Summary
instanceId. Each provider query is keyed by meter interval and bounded by its start/end with a five-second retrieval tolerance, preventing later wakes of the same Durable Object from contaminating earlier runs.Architecturally, the Cloudflare Analytics helper now accepts run-scoped queries and combines up to 15 independent filters through GraphQL aliases. Provider rows and partial-result state carry a run key through the router so reused instance IDs remain isolated without one HTTP request per run.
Verification
instanceIdcan map to separate continuous-awake generations with distinct start/end boundaries.Reviewer Notes
instanceIdidentifies the Durable Object but can recur across multiple meter generations.