App icon indicating copy to clipboard operation
App copied to clipboard

[Due for payment 2026-11-19] Support better rule creation suggestions

Open Valforte opened this issue 2 months ago • 35 comments

We want to support the following new feature.

We've recently worked on this feature: https://github.com/Expensify/App/pull/99164. The feature detects when a user makes an update to a transaction, and shows a 'Do you want to create an expense default for this' banner. Some of the problems with this approach are:

  1. If the user signs out and signs back in, they can see the same popup on the same transaction they already dismissed it on
  2. Just because the user changes a transaction once, doesn't mean they always want to, so they could receive excess popups that are not helpful/are always ignored

The solutions of the problem is:

  1. Lets start storing the number of times that a user updates a transaction (based on a specific merchant) in the backend. For example, a user could consistently update a 'starbucks' purchase to the 'coffee' category. (already deployed)
  2. Instead of always showing the 'Create a rule' popup, once the user has made the same change a few times in a determined span of time

Implementation details

  • In order to provide a better experience we will start by storing the changes for a specific field for 1 month
  • The popup will be shown if the user makes the same change 2 times during that 1 month period
  • The popup visibility will be mandated by a suggestNewRuleCreation response field in the UpdateMoneyRequest or UpdateMoneyRequestVendor command
  • The fields that we will be monitoring at this moment are category, tag, tax, comment, billable, reimbursable and vendor
Issue OwnerCurrent Issue Owner: @mallenexpensify

Valforte avatar Sep 18 '26 03:09 Valforte

@Krishna2323 let me know if you need anything!

Valforte avatar Sep 18 '26 15:09 Valforte

Please assign me too for review

situchan avatar Sep 18 '26 16:09 situchan

situ reviewed the previous one too, so assigning them to review

JS00001 avatar Sep 18 '26 16:09 JS00001

I'll start working on this today.

Krishna2323 avatar Sep 21 '26 14:09 Krishna2323

@situchan Whoops! This issue is 2 days overdue. Let's get this updated quick!

melvin-bot[bot] avatar Sep 21 '26 21:09 melvin-bot[bot]

@Valforte @JS00001 I logged the raw responses from UpdateMoneyRequestCategory and UpdateMoneyRequestTag across three identical Starbucks + Fees edits. suggestNewRuleCreation isn't in any of them, so the backend side doesn't look live yet.

A few questions before I start:

  1. Is the backend part built and deployed? If not, I'll wait rather than guessing the response shape.

  2. What exactly does the app get back? One yes/no for the whole edit, or one per field? This matters because a single expense can have a few edits, so one suggested rule could set category, tag, and tax together. If a user is over the threshold for category but not tag, a single yes/no leaves me guessing which fields belong in the rule.

  3. When does it become a yes? On the 2nd edit or the 3rd? And does "the same change" mean the same merchant + field, or the same merchant + field + new value? For example, if someone sets Starbucks to Coffee once, then to Meals once, is that two changes or one of each?

  4. Should edits count when we can't show a prompt anyway? There are two cases: editing from a list of expenses, where there is no expense open to show the prompt on, and a user without permission to create rules. If those still count, the count gets used up and no prompt ever appears. Can the backend skip those, or should the app send a flag?

  5. Is it okay to lose the prompt offline? Today the prompt appears instantly, before the server responds, so it works without a connection. If the backend decides, there won't be a prompt until the user reconnects.

  6. Vendor. You list it as monitored, but it's not part of the prompt today and is behind the vendorMatching beta. Auto-matched vendors go through the same command and shouldn't count. Should we handle this in this PR or as a follow-up?

Krishna2323 avatar Sep 22 '26 14:09 Krishna2323

Ok that's on me! I missed the Web-E pass trough so the new response is never hitting the app. I'm getting that done super quick!

  1. One bool per Auth call, In practice it translate to one per field, because newdot sends one command per field. There's a case for multiedits, if any one of those hit the treshold it would return true, but we can skip it for multiedits at this moment.
  2. Fires on the 2nd identical edit, and only on the edit that reaches that number 2. 3rd+ will return false
  • Identical means: same policyID + merchant + field + value.
  • If the customer categorizes a Starbucks transaction as Coffee and a second one as Meals it wouldn't trigger the rule suggestion (both return $response['suggestNewRuleCreation'] = false). After they edit a third Starbucks transaction as Coffee it would trigger the rule suggestion for that edit, returning $response['suggestNewRuleCreation'] = true
  • There's a 30-day window for the same edits
  1. If the user has no permission we would store it, I can change it later to not store it, it makes sense.
  • For when there is no expense open to show, I believe the FE can store the flag it received for that specific transaction and then show the banner when the expense is opened
  1. I believe it's okay to lose it while offline, it would get the flag back from the BE when reconnecting and then show the banner.
  2. We can handle it in a follow up, no problem

Valforte avatar Sep 23 '26 21:09 Valforte

@situchan Huh... This is 4 days overdue. Who can take care of this?

melvin-bot[bot] avatar Sep 23 '26 21:09 melvin-bot[bot]

I'm looking for a BE contributor to take this over the finish line. I can try to take a look tomorrow if nobody volunteers

JS00001 avatar Sep 24 '26 16:09 JS00001

What's the current status of this issue and how can I help? 😄

hungvu193 avatar Sep 24 '26 18:09 hungvu193

@hungvu193 thanks!! We're following this issue: https://github.com/Expensify/Expensify/issues/678355

We've merged one auth PR here: https://github.com/Expensify/Auth/pull/24518, which stores a merchantRuleSuggestionEdits NVP when a user edits an expense. We currently return suggestNewRuleCreation from auth (which is a boolean), when a user has made a specific number of similar edits on expenses.

It looks like we need one more web-e PR to make sure that the suggestNewRuleCreation field is returned to e/app, which is where we currently are: https://github.com/Expensify/App/issues/101504#issuecomment-5802928037

Gabriel had started on a PR for this, so we can take a similar approach, but lets create a new PR for this

JS00001 avatar Sep 24 '26 18:09 JS00001

Thanks for the heads-up! I'll take a look today!

hungvu193 avatar Sep 25 '26 02:09 hungvu193

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

melvin-bot[bot] avatar Sep 28 '26 21:09 melvin-bot[bot]

https://github.com/Expensify/Web-Expensify/pull/56516 hit staging yesterday.

hungvu193 avatar Sep 29 '26 03:09 hungvu193

cc @Krishna2323 ^ The BE issues should be fixed now

JS00001 avatar Sep 29 '26 11:09 JS00001

@hungvu193 Whoops! This issue is 2 days overdue. Let's get this updated quick!

melvin-bot[bot] avatar Oct 02 '26 23:10 melvin-bot[bot]

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

melvin-bot[bot] avatar Oct 03 '26 01:10 melvin-bot[bot]

Not overdue.

hungvu193 avatar Oct 03 '26 01:10 hungvu193

@Krishna2323 any updates on this one?

JS00001 avatar Oct 05 '26 10:10 JS00001

I'll have the PR up today.

Krishna2323 avatar Oct 05 '26 13:10 Krishna2323