Skip to content

Spend rules - Card number appears in Spend rule after deactivating card #87450

Closed

Description

@mitarachim

If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!


Version Number: 9.3.55-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: #86684
Email or phone of affected tester (no customers): applausetester+khcategory20@applause.expensifail.com
Issue reported by: Applause Internal Team
Bug source: Exploratory - Significant User Experience Deterioration
Device used: Mac 26.2 / Chrome
App Component: Workspace Settings

Action Performed:

Precondition:

  • Workspace is set up with Expensify Card feature.
  • Rules are enabled.
  • Workspace has at least one virtual card.
  1. Go to staging.new.expensify.com
  2. Go to workspace settings > Rules.
  3. Click Add spend rule.
  4. Add a card and add a spend rule, then save it.
  5. Go to workspace settings > Expensify Card.
  6. Deactivate the card used in Step 4.
  7. Go to Go to workspace settings > Rules.
  8. Scroll down to the created spend rule.

Expected Result:

Card number will not appear in Spend rule after deactivating card.

Actual Result:

Card number appears in Spend rule after deactivating card.

Workaround:

Unknown

Platforms:

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

Screenshots/Videos

Bug7125398_1775698460264.3.mp4

View all open jobs on GitHub

Activity

  1. added
    DeployBlockerCashThis issue or pull request should block deployment
    BugSomething is broken. Auto assigns a BugZero manager.
    DeployBlockerIndicates it should block deploying the API
    on Apr 9, 2026
  2. melvin-bot commented on Apr 9, 2026

    @melvin-bot

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

  3. melvin-bot commented on Apr 9, 2026

    @melvin-bot

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

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

    @MelvinBot
    Contributor

    Issue Analysis

    Root Cause: All three spend rule display components use filterInactiveCards as an Onyx selector when fetching the card list, which strips deactivated/closed cards from the lookup dictionary. The spend rule still stores those cardIDs, so the lookup returns undefined and the fallback renders the raw numeric card ID.

    Recommended Fix: In SpendRulesSection.tsx (and SpendRulePageBase.tsx), use an unfiltered card list for resolving card display names. Keep filterInactiveCards only in SpendRuleCardPage.tsx (the card picker), where filtering is intentional.

    Specifically:

    • SpendRulesSection.tsx:89 — remove the {selector: filterInactiveCards} option from the useOnyx call so deactivated cards remain in the lookup used at line 129.
    • SpendRulePageBase.tsx:57 — same change; the raw-ID fallback at line 93 will no longer trigger for deactivated cards.
    • SpendRuleCardPage.tsx:80 — keep filterInactiveCards here, since users should not be able to add deactivated cards to new rules.
    Investigation details

    Data flow:

    1. Spend rules store card references as cardIDs in the rule's filter AST on the backend (Card.ts:1652-1668).
    2. When a card is deactivated, the backend does not remove its cardID from existing spend rules.
    3. filterInactiveCards (CardUtils.ts:987-1003) removes cards with state CLOSED or STATE_DEACTIVATED.
    4. SpendRulesSection.tsx:128-136 iterates over the rule's cardIDs, looks each up in the filtered cardsList, gets undefined for deactivated cards, and falls back to displaying the raw ID string.

    Evidence chain:

    • Filter applied: SpendRulesSection.tsx:89 — useOnyx(..., {selector: filterInactiveCards})
    • Fallback triggered: SpendRulesSection.tsx:129 — const card = cardsList?.[cardID]; returns undefined
    • Raw ID displayed: SpendRulesSection.tsx:131 — return cardID;

    Alternative considered: Having the backend remove card references from spend rules on deactivation. This would be a more complete fix but is higher-risk for a deploy blocker. The frontend fix is safe and minimal.


    Next Steps: Reply with @MelvinBot implement this to create a draft PR, or @MelvinBot <your feedback> to refine this analysis.

  6. OSBotify commented on Apr 9, 2026

    @OSBotify
    Contributor

    Investigation Summary

    Classification: Frontend bug
    Causing PR: #86684 - Add spend rule base page by @luacmartins (High confidence)
    Related Issues: #86521

    Recommendation: REVERT

    PR #86684 introduced the spend rules feature and contains the bug where a deactivated card still appears in the spend rule summary. The fix requires changes to the App, and the issue is staging-only (new feature, not in production), making a clean revert the safest option.

    Assigned: @luacmartins (PR author), @suneox @JS00001 (approving reviewers)
    Labels: Keeping DeployBlockerCash (frontend App bug). DeployBlocker is also on the issue but this is a frontend fix.

    Evidence:

    • The melvin-bot already identified PR Add spend rule base page #86684 as the responsible PR (merged 2026-04-08, shortly before this report was filed on 2026-04-09).
    • PR Add spend rule base page #86684 introduced the entire SpendRulesSection spend rule display logic, the exact feature being tested in the reproduction steps.
    • The issue is staging-only (new feature, does not exist in prod), consistent with this PR being in the current staging deploy and not yet in production.

    Verification:

    • Affected file: src/pages/workspace/rules/SpendRules/SpendRulesSection.tsx
    • PR Add spend rule base page #86684 directly modifies this file, adding the createdRules logic and cardSummary display.
    • The card lookup uses cardsList filtered via filterInactiveCards in src/libs/CardUtils.ts.

    Root Cause:
    In SpendRulesSection.tsx (added by PR #86684), cardSummary is built by iterating over formValues.cardIDs stored in expensifyCardSettings.cardRules. When a card is deactivated, the card ID is not removed from existing rules. The deactivate action (src/libs/actions/Card.ts) optimistically nulls the card from cardsList, and filterInactiveCards also filters out STATE_DEACTIVATED (state=5) and CLOSED (state=6) cards. However, there is no code path in this PR to gracefully handle display of a card that was deactivated after a spend rule was created. The current fallback either returns the raw cardID string (if the card is fully removed from cardsList), or getCardDescriptionForSearchTable still shows the card number if the server returns a state that is not caught by the filter.

  7. removed
    DeployBlockerIndicates it should block deploying the API
    on Apr 9, 2026
  8. luacmartins commented on Apr 9, 2026

    @luacmartins
    Contributor

    This feature is behind an environment beta. No need to revert.

  9. suneox commented on Apr 9, 2026

    @suneox
    Contributor

    As I mentioned, when deactivating a card, we don’t have any documentation describing this behavior. So I think we should handle it as a separate issue. In this case, we would need a backend update api Card_Deactivate to clean up the unused PRIVATE_EXPENSIFY_CARD_SETTINGS

  10. added and removed
    DeployBlockerCashThis issue or pull request should block deployment
    on Apr 9, 2026
  11. JS00001 commented on Apr 13, 2026

    @JS00001
    Contributor

    Closing this in favor of #87669

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.DailyKSv2Engineering

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions