Skip to content

Remove unsafe assertions from search, domain, hold, and per diem flows - #103895

Merged
blimpich merged 3 commits into
Expensify:mainfrom
KJ21-ENG:seatbelt-v2/batch-20261013-run-3-8d8f57b8
Oct 19, 2026
Merged

blimpich merged 3 commits into
Expensify:mainfrom
KJ21-ENG:seatbelt-v2/batch-20261013-run-3-8d8f57b8

Conversation

@KJ21-ENG

@KJ21-ENG KJ21-ENG commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Explanation of Change

Remove unsafe assertions from search, domain membership, Hold and per diem actions. Search validates the generated parser fields consumed by autocomplete and highlighting, and keeps border/ref handling typed. SCIM success responses keep every string token, including the empty string; missing or non-string tokens enter the existing error/retry state. Membership, Hold and per diem updates retain their existing data operations.

Fixed Issues

$ #94739
PROPOSAL: #94739 (comment)

Tests

Checked-in parser, search-input, domain and expense-action tests cover the changed boundaries. The focused run passed 439 tests in ten suites; current upstream test jobs, lint and typecheck passed. Action tests cover malformed SCIM responses with the existing error/retry renderer unchanged.

Platforms: web, mWeb and native, including iOS for Search border interpolation and live highlighting.

Search input

Setup: Use a signed-in account with Search access.

  1. Open Search and focus, then blur, the query input. Verify usable focus and the normal borders for the current theme.
  2. Enter text. Verify it is readable.
  3. Clear the text, then close and reopen Search. Verify the query remains empty.
  4. Enter merchant:"Acme\,Inc". Verify the escaped value highlights without an input error.
  5. Clear the query and enter columns:date. Verify date highlights as valid.
  6. Clear the query and enter columns:unknown-column. Verify the unknown value stays unhighlighted and typing remains responsive.

Hold

Setup: Open an eligible expense's existing thread with Hold available.

  1. Choose Hold.
  2. Enter a reason and submit. Verify the held indicator and reason appear in the same thread.
  3. Remove the hold. Verify the held state clears.

Offline tests

Setup: Load the eligible expense and its existing thread while connected.

  1. Disconnect the network.
  2. Apply Hold with a reason.
  3. Reconnect. Verify the indicator and reason settle in the same thread without duplicate creation.
  4. Remove the hold. Verify the held state clears.

QA Steps

Same as tests.

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If new assets were added or existing ones were modified, I verified that:
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg)
    • The assets load correctly across all supported platforms.
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If the PR adds or modifies the UI:
    • I asked an AI agent to review the changes for accessibility issues and addressed its findings.
    • I tested with a screen reader (VoiceOver on macOS) and verified all new/changed elements are reachable with a logical focus order.
    • I verified all new/changed elements have meaningful accessible names and roles.
    • I verified state changes are announced (e.g. checked/unchecked, expanded/collapsed, selected).
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Recordings (2)

Recording 1 shows Windows Chrome Search focus, clearing, escaped-merchant and column highlighting. Recording 2 shows Hold and Remove hold in an existing thread, with an obstructed submit label. Console errors were observed without confirmed attribution to this PR. Native/mobile/Safari and offline reconnect results are unverified.

01-search-focus-highlighting-desktop.mp4
02-hold-remove-desktop.mp4

Seatbelt-Operation: 593570c7-465b-4e60-836c-0bbaedbef4c6
Seatbelt-Operation: 3977d0cd-ed13-4370-833c-8df981994e39
@KJ21-ENG
KJ21-ENG marked this pull request as ready for review October 16, 2026 21:21
@KJ21-ENG
KJ21-ENG requested review from a team as code owners October 16, 2026 21:21
@melvin-bot
melvin-bot Bot requested review from ikevin127 and removed request for a team October 16, 2026 21:21
@melvin-bot

melvin-bot Bot commented Oct 16, 2026

Copy link
Copy Markdown

@ikevin127 Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@melvin-bot
melvin-bot Bot requested review from trjExpensify and removed request for a team October 16, 2026 21:21
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-16T22:25:32.840233Z 957eaa2 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

});
const wrapperBorderColorAnimatedStyle = useAnimatedStyle(() => {
const borderColors = [wrapperBorderColor, focusedBorderColor].map((color) => {
processColor(color);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

❌ CONSISTENCY-18 (docs)

The standalone processColor(color); call discards its return value, so at a glance it reads as dead code. Its actual purpose is non-obvious: processColor throws on invalid color input, so this call exists only to surface that error eagerly for every endpoint (the test uses the default border and preserves endpoint error order until worklet execution relies on it throwing 'first-invalid'). Nothing in the surrounding code reveals that intent, and the adjacent comment only explains the later convertToRGBA coercion, not this call.

Add a comment explaining why the result is intentionally ignored, e.g.:

const borderColors = [wrapperBorderColor, focusedBorderColor].map((color) => {
    // Validate each endpoint up front so an invalid color throws here, preserving the original error order.
    processColor(color);
    if (typeof color === 'string') {
        return color;
    }
    ...
});

Reviewed at: 957eaa2 | Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Valid comment, should be addressed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed the unused processColor call and the redundant color conversion. String colors pass through; opaque colors fall back to the active theme's border color.

@ikevin127

ikevin127 commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
  • I checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified that the composer does not automatically focus or open the keyboard on mobile unless explicitly intended. This includes checking that returning the app from the background does not unexpectedly open the keyboard.
  • I verified tests pass on all platforms & I tested again on:
    • Android: HybridApp
    • Android: mWeb Chrome
    • iOS: HybridApp
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified proper code patterns were followed (see Reviewing the code)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If the PR adds or modifies the UI:
    • I asked an AI agent to review the changes for accessibility issues and addressed its findings.
    • I tested with a screen reader (VoiceOver on macOS) and verified all new/changed elements are reachable with a logical focus order.
    • I verified all new/changed elements have meaningful accessible names and roles.
    • I verified state changes are announced (e.g. checked/unchecked, expanded/collapsed, selected).
  • For any bug fix or new feature in this PR, I verified that sufficient unit tests are included to prevent regressions in this flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Screen.Recording.2026-10-17.at.17.46.05.mov

Comment thread src/libs/actions/IOU/PerDiem.ts Outdated
const newTransaction: OnyxTypes.Transaction = {
// eslint-disable-next-line @typescript-eslint/non-nullable-type-assertion-style
...(transaction as OnyxTypes.Transaction),
const newTransaction: NonNullable<OnyxSetInput<typeof ONYXKEYS.COLLECTION.TRANSACTION_DRAFT>> = {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

src/libs/actions/IOU/PerDiem.ts L88 / L121 / L158

🟠 Removing the cast exposes what ...transaction does when transaction is undefined: we still call Onyx.set with a partial object on transactionsDraft_undefined. The new test in tests/actions/IOU/PerDiemTest.ts L142/L182 now asserts that junk key gets written, so the bug becomes expected behavior.

Can we return early in all 3 functions instead ?

if (!transaction) {
    return;
}
const newTransaction: OnyxTypes.Transaction = {
    ...transaction,
    // ...
};

That also lets newTransaction stay OnyxTypes.Transaction (no NonNullable<OnyxSetInput<...>> copied 3 times), and the test can assert Onyx.set was never called.

As it stands, any per diem rate edit that runs before the draft loads creates an orphan transactionsDraft_undefined entry that never gets cleaned up.

@KJ21-ENG KJ21-ENG Oct 19, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added an early return to all three per-diem editors when the transaction is missing, before any Onyx write. Kept normal Transaction types for valid edits and added checks that no orphan transaction is created.

Comment thread src/libs/SearchAutocompleteUtils.ts Outdated
const parsedAutocomplete = parse(input) as SearchAutocompleteResult;
const parsedAutocomplete: unknown = parse(input);
if (!isAutocompleteParserResult(parsedAutocomplete)) {
throw new Error('Invalid autocomplete parser result');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

src/libs/SearchAutocompleteUtils.ts L340

🟠 parseForLiveMarkdown is the live-markdown worklet parser, and live-markdown doesn't wrap custom parsers in a try/catch. If this new guard ever fails, we throw on the UI thread on every keystroke in the Search input, which crashes native.

Since we're adding the shape check, let's degrade gracefully and skip highlighting:

if (!isAutocompleteParserResult(parsedAutocomplete)) {
    return [];
}

@KJ21-ENG KJ21-ENG Oct 19, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Changed an invalid parser-result shape to return an empty highlight list, so it does not introduce a new worklet exception. The existing parser's own exception behavior is unchanged.

Comment thread src/libs/actions/IOU/Hold.ts Outdated
const allTransactions = getAllTransactions();
const iouReportActions = getAllReportActions(reportID);
const holdReportActions: Array<OnyxTypes.ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.IOU>> = [];
const holdReportActions: OnyxTypes.ReportAction[] = [];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

src/libs/actions/IOU/Hold.ts L635

🟡 Widening holdReportActions to OnyxTypes.ReportAction[] throws away the IOU type for every consumer of getHoldReportActionsAndTransactions, so getOriginalMessage(holdReportAction) now returns the union of every original message type.

We can narrow up front with the existing guard and keep the original type, with no cast:

const holdReportActions: Array<OnyxTypes.ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.IOU>> = [];

for (const action of Object.values(iouReportActions)) {
    if (!isMoneyRequestAction(action)) {
        continue;
    }
    const transactionID = getOriginalMessage(action)?.IOUTransactionID;
    // ...

Behavior is the same, because a non-IOU action already resolves to no transaction and hits continue.

@KJ21-ENG KJ21-ENG Oct 19, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Moved the existing IOU action guard before transaction lookup and kept the returned hold actions typed as IOU actions. Added coverage for a non-IOU action without widening the return type.

Comment on lines +134 to +142
const borderColors = [wrapperBorderColor, focusedBorderColor].map((color) => {
processColor(color);
if (typeof color === 'string') {
return color;
}

// Interpolation coerces opaque colors to zero channels. Keep that behavior and the literal transparent marker on string endpoints.
const [red, green, blue, alpha] = convertToRGBA(color);
return `rgba(${Math.round(red * 255)}, ${Math.round(green * 255)}, ${Math.round(blue * 255)}, ${alpha})`;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

src/components/Search/SearchAutocompleteInput.tsx L134-142

🟡 Besides the bot's point: convertToRGBA already runs the color through processColorInitially itself, so the separate processColor(color) adds nothing. In practice both endpoints are theme strings anyway (theme.border or ViewStyle overrides from callers). Can we simplify to a string check ?

const toBorderColor = (color: ColorValue) => (typeof color === 'string' ? color : defaultBorderColor);
// ...
borderColor: interpolateColor(focusedSharedValue.get() ? 1 : 0, [0, 1], [toBorderColor(wrapperBorderColor), toBorderColor(focusedBorderColor)], 'RGB'),

This drops the processColor/convertToRGBA imports and the hand-built rgba(...) string. An opaque PlatformColor would then fall back to the default border instead of the current transparent black.

@KJ21-ENG KJ21-ENG Oct 19, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Simplified the interpolation inputs: keep string colors as supplied and use the current theme border for opaque colors. Removed both conversion calls. Tests check the installed interpolation behavior and dark-theme fallback.

Comment thread src/libs/actions/IOU/Hold.ts Outdated
// If the transaction thread report wasn't created before, we create it optimistically
if (!initialReportID) {
if (createdThread) {
const transactionThreadReport = createdThread;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

src/libs/actions/IOU/Hold.ts L235

🟢 Nit: const transactionThreadReport = createdThread; is just an alias. Can we use createdThread directly in this block ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed the redundant transactionThreadReport alias and used createdThread directly in that block.

@ikevin127

Copy link
Copy Markdown
Contributor

@KJ21-ENG PR has no blockers but needs changes: I'd ask for 4 fixes and 1 nit - posted above ☝️

The bots have already covered the standalone processColor(color) call (github-actions asked for a comment explaining it), so I don't repeat that.

The rest of the diff looks fine: the Domain membership objects built by assignment, the getScimToken string guard (including empty-string tokens), the POLICY_ID constant swap (that code is only reached for the POLICY_ID filter), the Hold createdThread ?? initialReport`` change and the globalThis` switch in TestHelper.

Please tag me once addressed 🙌

@trjExpensify

Copy link
Copy Markdown
Contributor

PR doesn’t need product input as a refactor PR. Unassigning and unsubscribing myself.

@trjExpensify
trjExpensify removed their request for review October 19, 2026 13:56
Seatbelt-Operation: reviewer-fix-103895-400f83b6-66e0-4864-aee1-52ef51a6f153
@KJ21-ENG

Copy link
Copy Markdown
Contributor Author

@ikevin127 Could you please check this once you get a chance, Thanks!

@ikevin127 ikevin127 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 LGTM - The author pushed one commit (6f93a93) that fixes all 6 of my threads plus the bot's processColor thread, but the Explanation of Change now understates two behavior changes.

@KJ21-ENG I won't block on it but it will be good to have it state the behaviour changes correctly:

PR description, Explanation of Change

🟡 "Membership, Hold and per diem updates retain their existing data operations" isn't accurate anymore. Can we update it to say that:

  • the per diem subrate editors now skip the draft write when the transaction is missing (no more transactionsDraft_undefined);
  • moving held expenses only selects IOU actions;
  • opaque platform border colors in the Search input fall back to the theme border

@melvin-bot
melvin-bot Bot requested a review from blimpich October 19, 2026 23:07
@blimpich
blimpich merged commit aa85064 into Expensify:main Oct 19, 2026
41 of 45 checks passed
@OSBotify

Copy link
Copy Markdown
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@github-actions

Copy link
Copy Markdown
Contributor

🚧 blimpich has triggered a test Expensify/App build. You can view the workflow run here.

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/blimpich in version: 9.5.15-1 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

@MelvinBot

Copy link
Copy Markdown
Contributor

No help site update is needed: this PR only replaces unsafe type assertions with type guards in Search, Domain, Hold, and Per diem code, so no feature, label, or documented behavior changes for users.


view run

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/grgia in version: 9.5.15-3 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

Bundle Size Analysis (Sentry):

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.

6 participants