Skip to content

[Due for payment 2026-10-14] Expense-Deselecting category shows 0% tax rate briefly and changes to previous rate #100591

Closed

Description

@applause-bot

If you haven’t already, check out our contributing guidelines for onboarding. To join our Slack channel, fill out this form.


Version Number: V9.4.73-3
Reproducible in staging?: Yes
Reproducible in production?: N/A - new feature, doesn't exist in prod
If this was caught during regression testing, add the test name, ID and link from BrowserStack: #99420
Email or phone of affected tester (no customers): Applausetester+wiw@applause.expensifail.com
Issue reported by: Applause Internal Team
Bug source: Exploratory - Significant User Experience Deterioration
Device used: Redmi note 10s android 13
App Component: Money Requests

Action Performed:

Launch Expensifail account
2. Create workspace - enable taxes and add a tax rate
3. Enable rules - upgrade - add rule - apply expense default - category rule
4. Select all categories - set tax rate added in
step 2
5. Open Workspace chat
6. Create a manual expense with any category
7. Open the expense and deselect the category

Expected Result:

Deselecting category must not show 0% tax rate briefly.

Actual Result:

Deselecting category shows 0% tax rate briefly and changes to previous rate

Workaround:

Unknown

Platforms:

  • Android: App
  • Android: mWeb Chrome
  • iOS: App
  • iOS: mWeb Safari
  • iOS: mWeb Chrome
  • Windows: Chrome
  • MacOS: Chrome Safari

Screenshots/Videos

Bug7254185_1788866556728.Screenrecorder-2026-09-08-16-47-09-260.mp4

View all open jobs on GitHub

Applause Internal Information
Exported by: Nathan Lemma
Bug ID: 7254185

Issue OwnerCurrent Issue Owner: @mallenexpensify

Activity

  1. added
    DeployBlockerCashThis issue or pull request should block deployment
    BugSomething is broken. Auto assigns a BugZero manager.
    on Sep 8, 2026
  2. applause-bot commented on Sep 8, 2026

    @applause-bot
    Author

    While Applause doesn't embed attachments for this bug, here are the links for quick view:
    https://platform.applause.com/services/links/v1/external/a01143f07179556dc012345135bebb996f1157e35ce2ca336ba8ebf03802e150

  3. melvin-bot commented on Sep 8, 2026

    @melvin-bot

    You have been assigned to this deploy blocker because you recently merged this PR: #99420

  4. github-actions commented on Sep 8, 2026

    @github-actions
    Contributor

    👋 Friendly reminder that deploy blockers are time-sensitive ⏱ issues! Check out the open `StagingDeployCash` deploy checklist to see the list of PRs included in this release, then work quickly to do one of the following:

    1. Identify the pull request that introduced this issue and revert it.
    2. Find someone who can quickly fix the issue.
    3. Fix the issue yourself.
  5. melvin-bot commented on Sep 8, 2026

    @melvin-bot

    @JS00001 @situchan you have been assigned to this deploy blocker because you reviewed the offending PR: #99420

  6. melvin-bot commented on Sep 8, 2026

    @melvin-bot

    @Krishna2323 you have been assigned to this deploy blocker because you authored the offending PR: #99420

  7. melvin-bot commented on Sep 8, 2026

    @melvin-bot

    💬 A slack conversation has been started in #expensify-open-source

  8. MelvinBot commented on Sep 8, 2026

    @MelvinBot
    Contributor

    🔍 Investigation Summary

    Classification: Frontend bug (fix belongs in Expensify/App), but not a regression from this release
    Causing PR: None on this checklist. The optimistic code that produces the 0% flash is byte-identical on production and staging. #99420 - "Add category tax defaults to Expense defaults" by @Krishna2323 is not the cause (High confidence it is not) — it only adds a bulk UI for creating the same category tax rules that already exist in production.
    Related Issues: #99410 (the issue #99420 implements)

    Recommendation: DEMOTE

    The flash-then-revert comes from pre-existing production logic (getCategoryTaxDetails + getUpdatedTransaction), so reverting #99420 would not fix it — the rules already stored on the policy would still trigger it, and the same repro is reachable on production via Workspace → Categories → category → Default tax rate. It is a transient display flicker that self-corrects to the server value, so it should be demoted and fixed by roll-forward with the one-line guard below.

    Assigned: No new assignees. @Krishna2323, @JS00001, @situchan were auto-assigned by Melvin for #99420 — that PR isn't the cause, but they own this area and the targeted fix below is small if they want to take it.
    Labels: No changes made. DeployBlockerCash intentionally left in place — production reproducibility is listed as N/A by the reporter, and per triage rules the label shouldn't be removed on an unverified production repro. An internal engineer should confirm the production repro (steps below) and then demote.

    📋 Detailed Analysis

    Evidence

    Diffed production...staging for every file in the category → tax code path:

    File production vs staging
    src/libs/TransactionUtils/index.ts — getCategoryTaxDetails + the category branch of getUpdatedTransaction identical (the only release diff in this file adds isScanFailedTransactionMovedOnPayment / shouldSplitScanFailedTransactions)
    src/libs/actions/IOU/MoneyRequest.ts — setMoneyRequestCategory identical
    src/pages/iou/request/step/DynamicIOURequestStepCategory.tsx (deselect handler) identical (blob d06fc0765e692aebd8d1d0d475d0556996fa18e4 on both refs)
    src/libs/CategoryUtils.ts — getCategoryDefaultTaxRate only file that changed, via #99420

    The single staging-only change is f10b9d0bd101928aa0bdd0bca755ed36f8a1a2cd from #99420, which swapped a loose matcher for the strict one:

    -const categoryDefaultTaxRate = expenseRules?.find((rule) => rule.applyWhen.some((when) => when.value === categoryName))?.tax?.field_id_TAX?.externalID;
    +const categoryDefaultTaxRate = getCategoryExpenseRule(expenseRules, categoryName)?.tax?.field_id_TAX?.externalID;

    This cannot produce the reported symptom: on deselect the category name is '', and both the old and the new matcher fail to match any rule for '', so both fall through to the identical return defaultTaxRate; branch. #99420 also writes its rules with the same SET_POLICY_CATEGORY_TAX command production already uses (setPolicyCategoryTaxes, with setPolicyCategoryTax now a one-item wrapper), so the stored rule shape is unchanged too.

    Production repro (why this is not new): production already exposes a per-category default tax rate at Workspace → Categories → category → Default tax rate (CategorySettingsPage, gated only on policy.tax.trackingEnabled, saving through DynamicCategoryDefaultTaxRatePage → setPolicyCategoryTax). Set a tax rate on one category there, create an expense in that category, then deselect the category: the same flash should occur. #99420 only makes the setup faster (all categories at once) — it does not change the runtime behaviour.

    Verification

    Affected files (all at staging e824ab763b1cddf2f28fe0fc9f7e8f24dd5b3466):

    1. Deselect sends an empty category — DynamicIOURequestStepCategory.tsx#L174-L193: const updatedCategory = isSelectedCategory ? '' : categorySearchText; → updateMoneyRequestCategory({category: ''}).
    2. Optimistic overwrite — TransactionUtils/index.ts#L1019-L1027 inside getUpdatedTransaction, reached from getUpdateMoneyRequestParams.
    3. The derivation — TransactionUtils/index.ts#L3269-L3285 (getCategoryTaxDetails).
    4. The fallback — CategoryUtils.ts#L99-L111 (getCategoryDefaultTaxRate).
    5. Same shape on the create/draft flow — MoneyRequest.ts#L681-L710 (setMoneyRequestCategory).

    None of these, except item 4, differ from production, and item 4's change is inert for an empty category name.

    Root Cause

    getUpdatedTransaction recomputes the category default tax on any category change, including clearing it:

    if (Object.hasOwn(transactionChanges, 'category') && typeof transactionChanges.category === 'string') {
        updatedTransaction.category = transactionChanges.category;
        const {categoryTaxCode, categoryTaxAmount, categoryTaxValue} = getCategoryTaxDetails(transactionChanges.category, transaction, policy, getCurrencyDecimals);
        if (categoryTaxCode && categoryTaxAmount !== undefined && categoryTaxValue) { /* overwrite taxCode/taxAmount/taxValue */ }
    }

    With category === '':

    1. getCategoryDefaultTaxRate(taxRules, '', defaultTaxCode) finds no rule for '' and returns the workspace default (getDefaultTaxCode → policy.taxRates.defaultExternalID, i.e. id_TAX_EXEMPT at 0% — see CONST.DEFAULT_TAX).
    2. getTaxValue returns the string '0%', which is truthy, and categoryTaxAmount becomes 0, which is !== undefined — so the guard passes and the optimistic transaction is written with the 0% exempt rate. That is the brief 0% the tester sees.
    3. The server response is authoritative and, judging by the observed outcome, the backend does not reset the tax rate when the category is cleared — it returns the previous (category rule) rate, so the row snaps back.

    The frontend is optimistically applying a "recompute the default" that the backend never performs for a cleared category.

    Targeted fix (roll forward). Guard on an empty category inside getCategoryTaxDetails so both call sites (getUpdatedTransaction and setMoneyRequestCategory) are covered:

    function getCategoryTaxDetails(category: string, transaction: OnyxEntry<Transaction>, policy: OnyxEntry<Policy>, getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals']) {
        const taxRules = policy?.rules?.expenseRules?.filter((rule) => rule.tax);
        // Clearing the category has no category default to apply. The backend leaves the tax rate alone, so recomputing
        // here would optimistically write the workspace default (Tax exempt, 0%) and then bounce back to the server value.
        if (!category || !taxRules || taxRules.length === 0 || isDistanceRequest(transaction)) {
            return {categoryTaxCode: undefined, categoryTaxAmount: undefined, categoryTaxValue: undefined};
        }
        ...

    If the product intent is instead that clearing the category should reset the tax to the workspace default, then the frontend is right and the backend needs a matching change — otherwise the value will always bounce back and the flicker cannot be fixed in App alone.

  9. 38 remaining items

  10. melvin-bot commented on Oct 13, 2026

    @melvin-bot

    Triggered auto assignment to @mallenexpensify (Awaiting Payment)

  11. melvin-bot commented on Oct 13, 2026

    @melvin-bot

    Payment Summary

    Resolving PRs:

    BugZero Checklist (@mallenexpensify)

    • I have confirmed assignees, roles, and Upwork contracts look correct
    • I have paid out Upwork contracts / manual NewDot requests
    • [BugZero Assignee] I have created a GH issue for creating/updating the regression test once above steps have been agreed upon
  12. melvin-bot commented on Oct 16, 2026

    @melvin-bot

    @mallenexpensify Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

  13. mallenexpensify commented on Oct 16, 2026

    @mallenexpensify
    Contributor

    @situchan this issue and/or PR mention a deploy blocker or a regression. Before the payment date, post one of the three options in step 20 of the C+ doc: it was a regression, it was not, or you did not review the offending PR. If you don't post, the default is to reduce payment.

  14. situchan commented on Oct 18, 2026

    @situchan
    Contributor

    The bug happened in production before our PR. (2nd evidence: #100591 (comment))
    I didn't specifically post because I already mentioned offending PR (I did not review)) in checklist.

  15. mallenexpensify commented on Oct 19, 2026

    @mallenexpensify
    Contributor

    Payment Summary

    Contributor: @Krishna2323 due $250 via NewDot
    Contributor+: @situchan due $250 via NewDot

  16. laurenreidexpensify commented on Oct 21, 2026

    @laurenreidexpensify
    Contributor

    Approved @Krishna2323 $250 New Expensify

  17. trjExpensify commented on Nov 3, 2026

    @trjExpensify
    Contributor

    approved $250 for @situchan

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

Metadata

Metadata

Labels

Awaiting PaymentAuto-added when associated PR is deployed to productionBugSomething is broken. Auto assigns a BugZero manager.DailyKSv2Engineering

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions