Skip to content

chore(billing-platform): Convert BalanceService dataclasses in protobufs#339

Open
brendanhsentry wants to merge 2 commits into
mainfrom
brendan/balance-service-protos
Open

chore(billing-platform): Convert BalanceService dataclasses in protobufs#339
brendanhsentry wants to merge 2 commits into
mainfrom
brendan/balance-service-protos

Conversation

@brendanhsentry

Copy link
Copy Markdown
Member

Turns dataclasses into protobufs

@github-actions

github-actions Bot commented Jun 30, 2026

Copy link
Copy Markdown

The latest Buf updates on your PR. Results from workflow ci / buf-checks (pull_request).

BuildFormatLintBreakingUpdated (UTC)
✅ passed✅ passed✅ passed✅ passedJun 30, 2026, 9:28 PM

@brendanhsentry
brendanhsentry marked this pull request as ready for review June 30, 2026 21:32
@brendanhsentry
brendanhsentry requested a review from a team as a code owner June 30, 2026 21:32
}

message UpsertContractBalanceResponse {
uint64 new_balance_cents = 1;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The response field new_balance_cents is a uint64, but the request's amount_cents is a signed int64. This can cause silent data corruption if a negative balance is returned.
Severity: HIGH

Suggested Fix

To prevent silent data corruption from negative balances, change the response field new_balance_cents from uint64 to int64. This ensures that both the request and response can correctly represent positive and negative monetary values.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location:
proto/sentry_protos/billing/v1/services/engagement/v1/endpoint_upsert_contract_balance.proto#L13

Potential issue: There is a type mismatch between the request field `amount_cents` which
is an `int64` and the response field `new_balance_cents` which is a `uint64`. If the
server-side logic calculates a negative balance, Protobuf's encoding will convert this
negative `int64` into a very large positive `uint64` via two's complement
representation. This results in silent data corruption, where the client receives an
incorrect and astronomically large balance without any error being raised. This can
happen if `amount_cents` is used for deductions that result in a negative total balance.

Also affects:

  • rust/src/sentry_protos.billing.v1.services.engagement.v1.rs:567~567

Did we get this right? 👍 / 👎 to inform future reviews.

@volokluev volokluev left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These names are not self explanatory, please add some documentation as to what these endpoints actually do


package sentry_protos.billing.v1.services.engagement.v1;

message AssignBalanceContractRequest {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does this actually do?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah you're right this is pretty bad. i have a PR to refactor in getsentry.

after that's merged, i'll come back and fix these protobuf messages

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants