Skip to content

fix(chat): tolerate legacy command metadata that exceeds the money decimal scale - #131

Merged
jakubfilinger-b merged 2 commits into
devfrom
fix/chat-legacy-command-metadata-money-scale
Sep 3, 2026
Merged

fix(chat): tolerate legacy command metadata that exceeds the money decimal scale#131
jakubfilinger-b merged 2 commits into
devfrom
fix/chat-legacy-command-metadata-money-scale

Conversation

@jakubfilinger-b

Copy link
Copy Markdown
Collaborator

What

toSystemMessage now canonicalizes the money strings in chat command metadata (amount, perRecipient) when a message is read: trailing zeros trimmed, fraction truncated to MONEY_SCALE (18).

Why

A rain command message persisted by the retired SQL rain split stored its share as numeric(38,20), so metadata.amount / metadata.perRecipient carry more fraction digits than MoneyAmountSchema now allows. getGlobalMessages validates the whole batch against ChatMessageSchema, so a single such historical row made the endpoint return a 500 for every viewer loading global chat. Observed on a downstream operator's dev environment (5 legacy rows).

Acceptance

  • getGlobalMessages returns a legacy rain message whose metadata amounts have 20 decimal places, canonicalized to a contract-valid form, and the row parses against ChatMessageSchema.
  • New regression test in chat.service.int.test.ts.
  • check:types, oxlint, oxfmt pass; full test:integration green (1228 passing).

Comment thread packages/core/src/engagement/chat/service/chat.service.ts Outdated
Comment thread packages/core/src/engagement/chat/service/chat.service.ts

@damianrzepka damianrzepka left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Review: fixes the reported bug correctly. Legacy rain-split rows with numeric(38,20) amounts now canonicalize on read and pass ChatMessageSchema; regression test added and passing (ran the full chat.service.int.test.ts suite locally - 138/138). Lint clean on the touched files. Traced getGlobalMessages end to end (viewer id from session, query filters intact, read-only, output matches contract) - same code path also covers getRoomMessages and listAdminRoomMessages, no other reader of chatMessage.metadata in the repo.

One inline note on chat.service.ts:299 - the canonicalization also silently reformats amounts that were never invalid (trims trailing zeros unconditionally), not just the legacy over-precision rows. Doesn't break the contract or lose value, so not blocking, but worth tightening to only touch the actually-broken rows.

GO.

…cimal scale

A rain command message persisted by the retired SQL rain split stored its
share as numeric(38,20), so metadata.amount / metadata.perRecipient carry
more fraction digits than MoneyAmountSchema now allows. getGlobalMessages
validates the whole batch against ChatMessageSchema, so one such historical
row returned a 500 for every viewer loading global chat.

Canonicalize the command metadata money fields on read (trim trailing
zeros, truncate to MONEY_SCALE) in toSystemMessage.
@jakubfilinger-b
jakubfilinger-b force-pushed the fix/chat-legacy-command-metadata-money-scale branch from f2f1fb7 to 7140561 Compare September 3, 2026 09:32
@jakubfilinger-b
jakubfilinger-b merged commit 953bcd0 into dev Sep 3, 2026
2 checks passed
@jakubfilinger-b
jakubfilinger-b deleted the fix/chat-legacy-command-metadata-money-scale branch September 3, 2026 10:08
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.

4 participants