Skip to content

Report - System message generated for merchant rules not seen for track expense submitted to WS #82879

Closed

Description

@lanitochka17

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.22.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: #82438
Email or phone of affected tester (no customers): ibellicotest+2250@gmail.com
Issue reported by: Applause Internal Team
Bug source: Exploratory - Significant User Experience Deterioration
Device used: Motorola MotoG60 / Android 12 (Hybrid app) - Windows 11 / Chrome
App Component: Money Requests

Action Performed:

Prerequisite: Account has at least one workspace with rules enabled.
Prerequisite 2: Account has Self DM.

  1. Open the staging.new.expensify.com website.
  2. Navigate to "Workspace" > "Rules"
  3. Scroll down to "Merchant Rules" and select "Add Merchant Rule"
  4. Add any merchant in "For expenses with"
  5. Add any category and description in "Apply these updates" and save the rule.
  6. Navigate to Self DM.
  7. Create a manual expense with merchant added in step 4.
  8. Tap on "Submit to someone" and select workspace where rule were created.
  9. Submit the expense without adding any category or description.
  10. Navigate to workspace chat and open expense report.
  11. Note that "Category" and "Description" fields were updated via created merchant rule.
  12. Note that "Set the category to "XX" and description to "XX" via workspace rules" system message is not displayed.

Expected Result:

System generated message showing that category and description were updated via workspace rules, should be displayed when a track expense is submitted to workspace.

Actual Result:

System generated message showing that category and description were updated via workspace rules, is not displayed for track expenses submitted to workspace, despite fields being correclty updated. System message only appear when expense is created directly in workspace chat.

Workaround:

Unknown

Platforms:

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

Screenshots/Videos

Bug7081916_1771459098402.Set.mp4

View all open jobs on GitHub

Issue OwnerCurrent Issue Owner: @luacmartins

Activity

  1. added
    DeployBlockerCashThis issue or pull request should block deployment
    ExternalAdded to denote the issue can be worked on by a contributor
    BugSomething is broken. Auto assigns a BugZero manager.
    on Feb 19, 2026
  2. added
    Help WantedApply this label when an issue is open to proposals by contributors
    on Feb 19, 2026
  3. melvin-bot commented on Feb 19, 2026

    @melvin-bot

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

  4. melvin-bot commented on Feb 19, 2026

    @melvin-bot

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

  5. melvin-bot commented on Feb 19, 2026

    @melvin-bot

    Triggered auto assignment to Contributor-plus team member for initial proposal review - @rojiphil (External)

  6. melvin-bot commented on Feb 19, 2026

    @melvin-bot

    Triggered auto assignment to @johncschuster (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details. Please add this bug to a GH project, as outlined in the SO.

  7. melvin-bot commented on Feb 19, 2026

    @melvin-bot

    Unable to auto-create job on Upwork. The BZ team member should create it manually for this issue.

  8. 6 remaining items

  9. HiepPP commented on Feb 19, 2026

    @HiepPP
    Contributor

    Proposal

    Please re-state the problem that we are trying to solve in this issue.

    When a user submits a tracked expense to a workspace, the expense fields (category, description, etc.) are correctly updated by merchant rules, but the informational system message explaining which fields were changed and linking to the workspace rules page does not appear in the chat. This creates a confusing user experience where changes happen silently without explanation. The message does appear correctly when an expense is created directly in a workspace chat, indicating the feature works but is not invoked in the tracked expense flow.

    What is the root cause of that problem?

    The client-side rendering logic in src/libs/ModifiedExpenseMessage.ts requires two specific properties to be present in a MODIFIED_EXPENSE report action's originalMessage object before displaying the workspace rules attribution message:

    1. policyRulesModifiedFields - an object mapping which expense fields were changed by rules
    2. policyID - the workspace identifier used to construct a link to the rules page

    The check occurs at lines 513-522:

    const hasPolicyRulesModifiedFields = isReportActionOriginalMessageAnObject && 'policyRulesModifiedFields' in reportActionOriginalMessage && 'policyID' in reportActionOriginalMessage;
    if (hasPolicyRulesModifiedFields) {
    const rulePolicyID = reportActionOriginalMessage.policyID;
    const policyRulesModifiedFields = reportActionOriginalMessage.policyRulesModifiedFields;
    if (policyRulesModifiedFields && rulePolicyID) {
    // eslint-disable-next-line @typescript-eslint/no-deprecated
    return getPolicyRulesModifiedMessage(translateLocal, policyRulesModifiedFields, rulePolicyID);
    }
    }

    When expenses are created directly within a workspace, the backend (Web-Expensify) correctly populates these fields in the MODIFIED_EXPENSE action. However, when a tracked expense is submitted to a workspace, the backend commands responsible for this flow do not populate policyRulesModifiedFields or policyID, even when merchant rules are successfully applied and modify the expense fields.

    This is fundamentally a data contract violation. The client and backend have an implicit contract documented in the comment at lines 247-248:

    * ModifiedExpense::getNewDotComment in Web-Expensify should match this.
    * If we change this function be sure to update the backend as well.

    The backend is responsible for populating originalMessage with rule modification metadata. The client correctly handles whatever the backend provides. The tracked expense submission flow simply bypasses the metadata population that occurs in the direct creation flow.

    What changes do you think we should make in order to solve the problem?

    This issue requires a backend-only fix in the Web-Expensify/Auth repository. No App repository changes are needed.

    The following backend API commands need to be updated to populate policyRulesModifiedFields and policyID in the MODIFIED_EXPENSE report action when merchant rules modify expense fields:

    1. CategorizeTrackedExpense - invoked from src/libs/actions/IOU/index.ts:6396
    2. ShareTrackedExpense - invoked from src/libs/actions/IOU/index.ts:6490
    3. AddTrackedExpenseToPolicy - invoked from src/libs/actions/IOU/index.ts:6048

    For each command, when merchant rules are applied and modify expense fields:

    Step 1: Determine which fields were modified by merchant rules (category, tag, comment/description, billable, reimbursable, tax)

    Step 2: Create the MODIFIED_EXPENSE report action (this already happens)

    Step 3: Populate originalMessage.policyRulesModifiedFields with the modified field names and their new values:

    // Example structure matching the type at src/types/onyx/OriginalMessage.ts:838-849
    policyRulesModifiedFields: {
        category?: string;      // e.g., "Travel"
        tag?: string;           // e.g., "Tag1,Tag2"
        comment?: string;       // description field (backend key name)
        merchant?: string;
        billable?: boolean;
        reimbursable?: boolean;
        tax?: { field_id_TAX: { name: string; value: string; externalID: string } };
    }

    Step 4: Populate originalMessage.policyID with the workspace policy ID

    The complete expected action structure:

    {
      "actionName": "MODIFIED_EXPENSE",
      "reportActionID": "generated-uuid",
      "originalMessage": {
        "policyID": "workspace-policy-id",
        "policyRulesModifiedFields": {
          "category": "Travel",
          "comment": "Description set by rule"
        }
      }
    }

    The client-side rendering code at src/libs/ModifiedExpenseMessage.ts:205-242 will then automatically display the properly formatted message using the translation strings defined in src/languages/en.ts:1506-1515.

    What alternative solutions did you explore? (Optional)

    Alternative 1: Client-side optimistic message generation

    The client could attempt to predict which fields the backend will modify and create an optimistic MODIFIED_EXPENSE action with policyRulesModifiedFields. This was rejected because:

    • Merchant rule evaluation logic exists only on the backend - duplicating it client-side would create maintenance burden and potential for drift
    • The client creates MOVED_TRANSACTION actions optimistically (see src/libs/actions/IOU/index.ts:5951), not MODIFIED_EXPENSE actions
    • Would require reconciling optimistic state with backend response, adding complexity

    Alternative 2: Modify the client check to not require policyID

    We could modify the check at line 513 to only require policyRulesModifiedFields without policyID. This was rejected because:

    • The link to workspace rules (/workspaces/:policyID/rules) would be broken without the policy ID
    • Breaks the established pattern where both fields are always provided together
    • The unit tests in tests/unit/ModifiedExpenseMessageTest.ts:821-899 expect both fields

    Alternative 3: Fetch policy rules and re-evaluate on the client after submission

    After a tracked expense is submitted, the client could fetch the workspace's merchant rules and determine which fields should have been modified. This was rejected because:

    • Adds unnecessary network requests
    • Rule evaluation timing matters - the backend may apply rules based on state that has since changed
    • Violates the single source of truth principle (backend owns rule application)

    Files Modified

    • Backend (Web-Expensify): CategorizeTrackedExpense, ShareTrackedExpense, AddTrackedExpenseToPolicy commands
    • App repository: No changes required

    Verification Checklist

    • Client rendering code is correct and displays message when data is present
    • Type definitions support policyRulesModifiedFields and policyID (src/types/onyx/OriginalMessage.ts:828-849)
    • Unit tests confirm message generation works with correct input (tests/unit/ModifiedExpenseMessageTest.ts:821-899)
    • Backend changes to populate missing fields (pending Web-Expensify implementation)
    • E2E test: Create tracked expense with merchant rules, submit to workspace, verify system message appears
    • Integration test: Verify CATEGORIZE_TRACKED_EXPENSE response includes policyRulesModifiedFields when rules match

    Edge Cases for Backend Implementation

    1. Partial rule application: Include only fields actually modified, not all fields the rule could modify
    2. Multiple matching rules: Aggregate all rule-triggered changes into single policyRulesModifiedFields object
    3. No matching rules: Do not include policyRulesModifiedFields property at all
    4. Rule modifies field user already set: Include in policyRulesModifiedFields to show the rule overrode user input
  10. m-natarajan commented on Feb 19, 2026

    @m-natarajan

    Reproduce, Chrome / v9.3.22-4

    Screen.Recording.2026-02-19.at.18.33.57.mp4
  11. added
    ReviewingHas a PR in review
    and removed
    ExternalAdded to denote the issue can be worked on by a contributor
    Help WantedApply this label when an issue is open to proposals by contributors
    BugSomething is broken. Auto assigns a BugZero manager.
    on Feb 19, 2026
  12. luacmartins commented on Feb 19, 2026

    @luacmartins
    Contributor

    PR in review

  13. luacmartins commented on Mar 3, 2026

    @luacmartins
    Contributor

    This is done

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

Metadata

Metadata

Labels

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions