[$175] [Sentry: APP-PPF] UpdateMoneyRequestDescription returns 402 Maximum Size Exceeded comment
Summary
Editing an expense description can pass client validation but fail when saved, showing “Unexpected error editing this expense. Please try again later.”
- Sentry: APP-PPF
- Impact: 1 user, 1 event
- First seen: 2026-11-27 16:42 UTC
- Platform: web, Edge on Windows
- Release:
[email protected] - Route:
/search/view/:reportID/ - Error:
Expense API Error: UpdateMoneyRequestDescription returned 402 - Mechanism: handled (
captureMessage), level error
Top first-party frames
src/libs/actions/OnyxUpdates.ts:160—trackExpenseApiErrorsrc/libs/telemetry/trackExpenseCreationError.ts:145—Sentry.captureMessage
Root cause
The description form validates raw character count, but the save action converts the description into HTML. Auth limits the saved HTML comment to 1,000 bytes.
Formatted content containing links and line breaks can pass frontend validation but exceed that backend limit. Investigation confirmed the backend rejection: 402 Maximum Size Exceeded comment.
Suggested fix
Validate the UTF-8 byte size of the parsed HTML before submitting. When it exceeds the backend limit, retain the input and display a clear validation error rather than submitting and showing a generic failure.
Verification
Test descriptions containing links, many line breaks, and multibyte characters around the 1,000-byte boundary. Confirm oversized values are blocked locally with actionable feedback and valid values save successfully.
Upwork Automation - Do Not Edit
- Upwork Job URL: https://www.upwork.com/jobs/~022127210899966344568
- Upwork Job ID: 2127210899966344568
- Last Price Increase: 2026-11-30
Issue Owner
Current Issue Owner: @mukhrr
Triggered auto assignment to Contributor-plus team member for initial proposal review - @mukhrr (External)
Job added to Upwork: https://www.upwork.com/jobs/~022127210899966344568
Proposal
What is the root cause of that problem?
The editor validates the input text, but the save action submits HTML. Formatting can expand a description beyond the server’s limit even when the input passes validation.
Confidence: medium. The validation mismatch is confirmed in code and reproduced on web. The exact production event and the asserted UTF-8 byte limit could not be independently verified because production-log access was unavailable.
Code evidence and alternatives checked
- The description validator checks JavaScript string length against 1,000.
- The save action instead submits
getParsedComment(comment)as the description, without checking its serialized size. - The parser does not truncate descriptions to this limit.
- Trimming is not the explanation: FormProvider prepares input before both validation and submission.
- Inline description editing also checks input length, so fixing only the description form would leave another entry point exposed.
What changes do you think we should make in order to solve the problem?
Add shared validation of the same normalized, parsed description that will be submitted, covering the description form and inline editing. When oversized, retain the input, show an actionable field error, and prevent submission.
Before selecting the sizing calculation, confirm the endpoint’s precise server contract. If it is 1,000 UTF-8 bytes as reported, reuse the existing byte-length validator.
Implementation safeguards and regression coverage
- Reuse isValidInputLength if UTF-8 sizing is confirmed.
- Do not substitute getCommentLength: it implements a different escaped-length calculation for AddComment.
- Test immediately below, at, and above the confirmed serialized limit with links, internal newlines, escaped characters, and multibyte text.
- Assert rejected inputs remain editable without an API call or navigation. Preserve unchanged-description and split-draft behavior.
- Avoid truncating HTML or changing the shared parser globally.
Web reproduction results
🤖 Web test steps verification results: ⚠️ partial
Short descriptions saved successfully. HTML-expanding links passed local validation, then failed after submission and rolled back. Multibyte boundary checks remain unverified.
| Step | Status |
|---|---|
Save a short descriptionThe saved value persisted after reopening the editor. |
✅ |
Save input under 1,000 characters whose HTML exceeds 1,000A 426-character input containing links expanded to 1,946 HTML characters. It passed local validation, then rolled back with the reported generic error. The application-level response code was unavailable.![]() |
✅ |
Compare 500 versus 501 é charactersBlocked by input automation appending rather than replacing text; no product conclusion. This leaves byte-versus-character enforcement unresolved. |
❌ |
Next Steps for Contributor+ team:
To accept: @MelvinBot implement [this](https://github.com/Expensify/App/issues/108282) to create a draft PR.
To refine: @MelvinBot <your feedback>
To reject: Explain why you are rejecting Melvin's proposal.
Proposal
Please re-state the problem that we are trying to solve in this issue? Editing an expense description can pass the form's client-side validation but fail when saved, showing "Unexpected error editing this expense. Please try again later." The save call UpdateMoneyRequestDescription returns 402 Maximum Size Exceeded comment because Auth limits the saved HTML comment to 1,000 bytes, while the form only checks the raw character count. What is the root cause of that problem? I verified the diagnosis in the issue against the code on main. The mismatch is between what the form measures and what the server receives:
-
The description form validates the raw markdown text length in src/pages/iou/request/step/DynamicIOURequestStepDescription.tsx:118: if (values.moneyRequestComment.length > CONST.DESCRIPTION_LIMIT) — .length counts UTF-16 code units of the markdown the user typed.
-
CONST.DESCRIPTION_LIMIT is 1000 (src/CONST/index.ts:7007).
-
On submit, updateComment (DynamicIOURequestStepDescription.tsx:130-136) trims the value and, for the edit action, calls updateMoneyRequestDescription (line 159). The save action converts the markdown to HTML first — src/libs/actions/IOU/UpdateMoneyRequest.ts:1603: const parsedComment = getParsedComment(comment);, then params.description = parsedComment; and API.write(WRITE_COMMANDS.UPDATE_MONEY_REQUEST_DESCRIPTION, params, onyxData);.
-
getParsedComment (src/libs/ReportUtils.ts:7921) parses the markdown into HTML (links, line breaks, mentions). That HTML is what Auth measures against its 1,000-byte limit — and HTML is longer than the markdown it came from: ○ each link label becomes label, adding roughly 15-30 bytes of markup per link; ○ each line break becomes
(+5 bytes); ○ a CJK character counts as 1 unit in .length but 3 bytes in UTF-8; an emoji counts as 2 units but 4 bytes. -
So a description of, say, 950 characters with a few links and line breaks passes the form check but produces HTML over 1,000 bytes, and the backend rejects it with 402. The user only finds out after submitting, via a generic error. (Note: getParsedComment skips parsing entirely only when text.length > CONST.MAX_MARKUP_LENGTH (10000, src/CONST/index.ts:6984), so every description under the form's 1,000-character limit goes through the HTML-expanding path.) What changes do you think we should make in order to solve the problem? Validate the UTF-8 byte size of the exact HTML that will be saved, in the form's validate function in src/pages/iou/request/step/DynamicIOURequestStepDescription.tsx, so an oversized description is blocked locally with a clear error and the input is retained: const validate = (values: FormOnyxValues
): FormInputErrors => { const errors = {}; if (values.moneyRequestComment.length > CONST.DESCRIPTION_LIMIT) { addErrorMessage(errors, 'moneyRequestComment', translate('common.error.characterLimitExceedCounter', values.moneyRequestComment.length, CONST.DESCRIPTION_LIMIT)); }
const parsedComment = getParsedComment(values.moneyRequestComment.trim(), {reportID: report?.reportID}); const parsedByteLength = new TextEncoder().encode(parsedComment).length; if (parsedByteLength > CONST.DESCRIPTION_LIMIT) { addErrorMessage(errors, 'moneyRequestComment', translate('common.error.characterLimitExceedCounter', parsedByteLength, CONST.DESCRIPTION_LIMIT)); }
return errors; }; Notes on the implementation: • Keep the existing character-count check first: it is cheap, preserves the current counter UX for plain-text overflow, and runs before the parse. • Pass the same {reportID} the save path has in scope, so mention expansion matches what updateMoneyRequestDescription will send (the form already has report in scope — it is used in updateComment). • getParsedComment is synchronous and the form's validate runs synchronously on submit, so this fits the existing FormProvider validation flow: the submit is blocked, the error shows inline on the field, and the user's input stays in the editor. • This is a form-level fix, so it covers both entry points that share this form: editing an existing description and the split-expense draft path (setDraftSplitTransaction in updateComment), since validate runs before either branch. • No change to the save action itself: the backend limit is a server rule, and the App-side fix is to never submit a value that is known to exceed it. What alternative solutions did you explore? (Optional) • Raise the backend limit: the 1,000-byte cap lives in Auth, outside this repo — not something an App-side fix can change. • Truncate the HTML before sending: would silently lose user content (links, line breaks) and could produce broken markup. • Guard inside updateMoneyRequestDescription before API.write: the action has no channel to show a field-level validation error — the user would still see a generic failure, just earlier. The form is the only place the error can be shown with the input retained. What are the regression risks? (Optional) • Validate-time parse vs save-time parse: if the two parses ever differ (e.g. mention expansion depends on report context), the byte check could disagree with the saved HTML. Mitigated by passing the same reportID the save path uses; the check only blocks when the parsed HTML the user is about to send is over the limit, so it cannot block a value that would save successfully. • Plain-ASCII descriptions: unformatted text parses to HTML of essentially the same size, so descriptions that saved before keep saving — the check only fires on values that would have failed with 402. What specific scenarios should we test?
-
A description of ~950 characters containing 3 links: blocked locally with a clear validation error, input retained, no API call.
-
A description with 20+ line breaks under the character limit but over 1,000 bytes of HTML: blocked locally.
-
A description of ~400 CJK characters (under 1,000 characters, over 1,000 UTF-8 bytes): blocked locally.
-
A plain-ASCII description of ~900 characters with no formatting: saves successfully, unchanged behavior.
-
Boundary: parsed HTML of exactly 1,000 bytes saves; 1,001 bytes is blocked.
Addendum — use the existing byte-length validator: ValidationUtils.isValidInputLength (src/libs/ValidationUtils.ts) already validates UTF-8 byte length via StringUtils.getUTF8ByteLength and returns both isValid and byteLength for the error copy — it is what merchant-name validation uses with CONST.MERCHANT_NAME_MAX_BYTES. The byte check in the fix above should reuse it: const {isValid, byteLength} = isValidInputLength(parsedComment, CONST.DESCRIPTION_LIMIT); and pass byteLength to the characterLimitExceedCounter message when !isValid. Same behavior, no new sizing code.
(Vit's agent) @MelvinBot implement this proposal with the confirmed server limit below.
Confirmed server limit: the backend rejects UpdateMoneyRequestDescription with 402 Maximum Size Exceeded comment when the submitted comment is more than 1,000 UTF-8 bytes. It measures the exact string that App sends, which is the HTML output of getParsedComment(), not the Markdown that the user types. The backend does not change the value before it checks the size.
Examples of how the parsed HTML grows:
| Input | Characters | Parsed HTML bytes |
|---|---|---|
a + newline + b |
3 | 8 (a<br />b) |
see https://example.com/x |
25 | 103 |
a & b < c |
9 | 16 |
500 × é |
500 | 1,000 (passes) |
501 × é |
501 | 1,002 (fails) |
What to build:
- Add one shared validator. It runs
getParsedComment()on the same normalized value that the save path submits, then checks the result withisValidInputLength(parsedComment, CONST.DESCRIPTION_LIMIT). - Use that validator in
DynamicIOURequestStepDescription.tsxand inTransactionInlineEdit.ts. Both check only the.lengthof the raw input today. - When the value is too long, keep the input, show a field error, and do not call the API. Do not show the HTML byte count as a character count, because it does not match what the user typed.
- Do not truncate the HTML, and do not change the shared parser.
Tests: cover values just below, at, and just above 1,000 bytes of parsed HTML. Include links, line breaks, escaped characters such as & and <, and multibyte text such as the é cases above. Also confirm that an unchanged description still saves without an error.
🤖 Web test steps verification results: ❌ fail
Browser verification was blocked: dev NewDot rendered a blank page and remained suspended after a retry. The requested browser assertions could not be tested.
| Step | Status |
|---|---|
Verify description boundaries and inline editingThe blank page prevented testing saves, field errors, input retention, unchanged descriptions, and API-call suppression. |
❌ |
Draft PR created: Validate expense descriptions against the saved HTML byte limit, assigned to mountiny.
Implemented shared 1,000-byte parsed-HTML validation, localized field errors, retained invalid inline input, and unchanged-description handling. No parser changes or truncation.
Passed: 356 focused tests, typecheck, lint, spelling, formatting, Storybook smoke test, and code review.
Incomplete: Full Jest and changed-file compiler checks timed out. Translation dry-run failed with a ts-node configuration error. These limitations are documented in the PR; browser verification remains required before marking it ready.
view run · no recording available
@mukhrr can you continue with the Melvin PR, please?