Skip to content

Rules - "Category" is not locked when there are no non default tax rates. #100536

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: 9.4.73-0
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): ibellicotest+2766@gmail.com
Issue reported by: Applause Internal Team
Bug source: Pull Request QA execution
Device used: Motorola MotoG60 / Android 12 (Hybrid app) - Windows 11 / Chrome
App Component: Workspace Settings

Action Performed:

Prerequisite: Use an expensifail account.
Prerequisite 2: Account has a workspace with "Rules" and "Taxes" enabled.

  1. Open the staging.new.expensify.com website.
  2. Navigate to "Workspaces" > Workspace > "Taxes"
  3. Delete all non default taxes.
  4. Navigate to "Rules".
  5. Click on "Add Rule" > "Apply expense defaults" > "Category"
  6. Note that "Category" option is not locked, despite not having any available tax.
  7. Click on "Tax" field.
  8. Note that only "No results found" message is visible.

Expected Result:

"Category" option in "Apply expense defaults" should be locked if "Tax" feature is disabled or if there aren´t taxes available.

Actual Result:

"Category" field is not locked in "Apply expense defaults" despite user not having any non default tax available, and opening "Tax" field leads to a RHP with "No results found" message in it.

Workaround:

Unknown

Platforms:

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

Screenshots/Videos

Bug7253550_1788794224486.Tax_Rule_7.mp4

View all open jobs on GitHub

Applause Internal Information
Exported by: Julia Ponikarchuk
Bug ID: 7253550

Activity

  1. added
    DeployBlockerCashThis issue or pull request should block deployment
    BugSomething is broken. Auto assigns a BugZero manager.
    on Sep 7, 2026
  2. applause-bot commented on Sep 7, 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/7b1a276872658febfead7acdb7a006e3763670b655735b54d37d91a45ca13122

  3. melvin-bot commented on Sep 7, 2026

    @melvin-bot

    @JS00001 recently merged #99420, but they are OOO right now, so I'll auto-assign someone else.

  4. github-actions commented on Sep 7, 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 7, 2026

    @melvin-bot

    Triggered auto assignment to @blimpich (DeployBlockerCash), see https://stackoverflowteams.com/c/expensify/questions/9980/ for more details.

  6. melvin-bot commented on Sep 7, 2026

    @melvin-bot

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

  7. melvin-bot commented on Sep 7, 2026

    @melvin-bot

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

  8. 2 remaining items

  9. MelvinBot commented on Sep 7, 2026

    @MelvinBot
    Contributor

    🔍 Investigation Summary

    Classification: Frontend bug
    Causing PR: #99420 - "Add category tax defaults to Expense defaults" by @Krishna2323 (High confidence)
    Related Issues: None found

    Recommendation: ROLL FORWARD

    The guard that locks the "Category" card counts all tax rates, while the tax picker it leads to hides the workspace default rate for category rules — so a workspace whose only remaining rate is the default passes the guard and lands on an empty picker. Reverting would pull a 43-file feature PR for a one-line predicate gap, and the whole flow is gated behind the rulesRevamp beta (CONST.BETAS.RULES_REVAMP), so @situchan's "not a blocker" read is correct on the code: it is also a reasonable demote candidate for the BZ/deploy owner.

    Assigned: @Krishna2323 (PR author), @JS00001 and @situchan (approving reviewers) — already assigned by Melvin
    Labels: No changes. DeployBlockerCash is kept — the cause is an Expensify/App PR, and the issue is not reproducible on production (new feature), so it is not eligible for automated removal. DeployBlocker was never applied. Demoting this is an internal judgement call given the beta gate; flagging it rather than doing it.

    📋 Detailed Analysis

    Evidence

    • Every file in the reported flow was created by Add category tax defaults to Expense defaults #99420 (merged 2026-09-04, item 40 in the deploy checklist): ExpenseDefaultTypePage.tsx, AddTaxPage.tsx, CategoryTaxRulesUtils.ts and RuleTaxesDisabledEmptyState.tsx are all additions in that PR's diff. There is no prior version of this screen, which matches "N/A - new feature, doesn't exist in prod".
    • The hasUsableTaxRates helper, the isLocked flag on the Category card, and the shouldHideTax filter in the tax picker are all introduced in the same diff — the guard and its consumer were written together and disagree with each other.
    • No other PR on the checklist touches these files.

    Beta gating (re: "Not blocker. The feature is behind beta")

    Confirmed in code. The beta is rulesRevamp — CONST.BETAS.RULES_REVAMP: 'rulesRevamp' — and every screen on the reported path is blocked without it:

    So a user without the beta cannot reach step 5 of the repro at all. That supports demoting rather than reverting.

    Verification

    Affected files, all modified/created by #99420:

    File Role
    src/libs/CategoryTaxRulesUtils.ts#L31-L34 hasUsableTaxRates — the guard that is wrong
    src/pages/workspace/rules/MerchantRules/ExpenseDefaultTypePage.tsx#L52, #L84-L86 consumes the guard as isLocked on the Category card
    src/pages/workspace/rules/MerchantRules/AddTaxPage.tsx#L32-L43, #L66-L79 the picker that renders "No results found"
    src/pages/workspace/rules/MerchantRules/MerchantRulePageBase.tsx#L532-L540 keeps the Tax row visible for category rules regardless of the guard

    Root Cause

    The availability guard and the option list it gates are computed from two different sets of tax rates.

    The guard counts every entry in policy.taxRates.taxes:

    // src/libs/CategoryTaxRulesUtils.ts:32-34
    function hasUsableTaxRates(policy: Policy | undefined): boolean {
        return !!policy?.tax?.trackingEnabled && Object.keys(policy?.taxRates?.taxes ?? {}).length > 0;
    }

    The picker, for a category rule, deliberately removes the workspace default rate (writing it would delete the rule rather than save it), plus disabled and pending-delete rates:

    // src/pages/workspace/rules/MerchantRules/AddTaxPage.tsx:33-43
    const isCategoryRule = isCategoryRuleDraft(form, categoryName);
    const defaultExternalID = policy?.taxRates?.defaultExternalID;
    const shouldHideTax = (taxKey: string) => isCategoryRule && taxKey === defaultExternalID;
    
    const taxItems = Object.entries(taxes)
        .filter(([taxKey, tax]) => !tax.isDisabled && tax.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE && !shouldHideTax(taxKey))
        ...

    After step 3 of the repro (delete all non-default taxes), policy.taxRates.taxes still holds the workspace default rate, so hasUsableTaxRates returns true → isLocked: !areTaxesEnabled is false → the Category card is unlocked and showTurnOnTaxesFirstExplainer never fires. Tapping through then reaches AddTaxPage, where areTaxesEnabled is also true so the picker branch renders — but taxItems is empty because the only remaining rate is the default one shouldHideTax strips. Hence "No results found" instead of the RuleTaxesDisabledEmptyState that was written for exactly this situation.

    The same gap exists for a workspace whose only rates are all isDisabled, or all pending deletion.

    Suggested fix (roll forward): make hasUsableTaxRates count only rates a category rule can actually select — exclude isDisabled, pendingAction === DELETE, and (for the category flow) taxRates.defaultExternalID — and have ExpenseDefaultTypePage, AddTaxPage and MerchantRulePageBase all read that one predicate. The codebase already has this shape for categories and tags in hasEnabledOptions, which does filter on enabled and pendingAction.


    💡 Suggested AI code review rule

    This bug looks like a recurring, mechanically detectable pattern, so it may be worth a coding-standards rule so the AI reviewer catches the next one. Proposed for Expensify/App:

    • Rule: CONSISTENCY-19 — Gate an entry point on the same filtered set its destination renders
    • Condition: When a lock/disable/empty-state guard decides whether a screen or option is reachable based on the size of an Onyx collection (policy.taxRates.taxes, policyCategories, policyTags, cards, …), it must be derived from the same predicate the destination uses to build its list — not a raw Object.keys(...).length > 0. Extract one shared hasUsableX() helper and call it from both sides.
    • Why: A raw count includes entries the destination filters out (isDisabled, pendingAction === DELETE, the workspace default rate), so the guard reports "available" and the user is routed to a picker rendering "No results found" with no way forward. That is exactly this deploy blocker.
    • Search pattern: rg 'Object\.(keys|values)\([^)]*(taxRates\?\.taxes|policyCategories|policyTags|Categories|Tags)[^)]*\)(\s*\?\?\s*\{\})?\)?\.length' and flag any hit used as a boolean gate whose corresponding list builder filters on isDisabled, enabled, pendingAction, or defaultExternalID.
    • Offending code (❌): CategoryTaxRulesUtils.ts#L31-L34 vs. its consumer AddTaxPage.tsx#L33-L43
    • Fix (✅): the shape already used for categories and tags — hasEnabledOptions

    The full rule file, with the ❌/✅ code inline in App's coding-standards format, would go in Expensify/App itself. If it's worth adding, a maintainer can open it there as a draft PR.

  10. added and removed
    DeployBlockerCashThis issue or pull request should block deployment
    on Sep 7, 2026
  11. blimpich commented on Sep 7, 2026

    @blimpich
    Contributor

    Demoting based of this comment

  12. removed their assignment
    on Sep 7, 2026
  13. Krishna2323 commented on Sep 8, 2026

    @Krishna2323
    Contributor

    @JS00001 @JmillsExpensify, what's the expected behavior here? If we lock category creation when only a default tax exists, what should we prompt the user with when we show the modal? We can't use the same "Category rules set a default tax rate. Turn on taxes in your workspace settings to use them." prompt since taxes are already enabled.

  14. JS00001 commented on Sep 8, 2026

    @JS00001
    Contributor

    I think we'd use a similar one, saying they need to create a non default rate, or something similar?

  15. added
    ReviewingHas a PR in review
    and removed on Sep 9, 2026
  16. JmillsExpensify commented on Sep 9, 2026

    @JmillsExpensify
    Contributor

    I'm fine going with Krishna's suggestion above.

  17. JS00001 commented on Sep 23, 2026

    @JS00001
    Contributor

    This is merged and is a part of the rules revamp

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

Metadata

Metadata

Labels

BugSomething is broken. Auto assigns a BugZero manager.EngineeringReviewingHas a PR in reviewWeeklyKSv2

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions