Repository navigation
feat(db): Repair money written in old units during the micro-USD rollout - #4041
Merged
Merged
Conversation
While 0119 and 0120 rolled out, the runtime before micro-USD still wrote cost metric rows, Brief costs, and stats counters in the old units. This migration converts those rows and sums the usage cost of the affected Conversations and their Automation runs again. Each statement is idempotent. The metrics table has no index on the old metric name, so the migration scans it once into a temporary table before it locks any row. Co-Authored-By: BYK <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
|
4 screenshot changes — 4 changed · 0 added · 0 removed Review screenshots in Frameshift
|
…able The migration test fixture runs each statement outside a transaction, so an ON COMMIT DROP table is gone before the next statement reads it. One statement with data-modifying CTEs scans the metrics table once and needs no session state.
BYK
approved these changes
Nov 22, 2026
22 tasks done
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
#3621 moved money to integer micro-USD. While its migrations (0119, 0120) rolled out, the previous runtime still wrote money in the old units, and nothing converted those rows afterwards:
cost_usdmetric rows, which every cost read now skips. The usage cost of those Conversations, and the cost of their Automation runs, came from one runtime and missed the other runtime's rows.cost_usdset.countcolumn, including cache warming dollar counters under their old names and units.Migration 0160 converts the old cost rows to
cost_micro_usd. When both runtimes wrote a cost row for the same Run, the later row wins. It then sums the usage cost of each affected Conversation again and copies it to their Automation runs. It also fillscost_micro_usdon those Brief versions and movescountamounts intovalue, using the micro-USD names for cache warming counters. Each statement touches only old-unit rows, so running it a second time changes nothing.The metrics table is large and has no index on
cost_usd. So the cost repair is one statement with data-modifying CTEs: it scans the table once, and finds the other rows of each affected Conversation by primary key.#3615 is a different repair: it fixed Automation run cost and last run after the 0117 rollout.
via @BYK.
--
View Session [Sentry]