Skip to content

[Payment due @Krishna2323] Describe a rule from New rule and fall back to an agent rule - #103810

Merged
yuwenmemon merged 24 commits into
mainfrom
yuwen-683436-describeRuleAgentFallback
Oct 20, 2026
Merged

yuwenmemon merged 24 commits into
mainfrom
yuwen-683436-describeRuleAgentFallback

Conversation

@yuwenmemon

@yuwenmemon yuwenmemon commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

@puneetlath please review
cc @Krishna2323 @JmillsExpensify

Explanation of Change

Here's the plan: Admins describe a rule once, and we build a standard rule or, failing that, draft an agent rule. New rule shows the four rule templates, then a box to describe the rule. A rule answer opens that editor seeded on top, so Back returns to the description. unsupported and multipleRules open the agent rule page on the Write tab with the description prefilled and a banner explaining agent rules. Nothing saves before Create.

This sits behind the describeRule beta. Without the beta, New rule keeps "Describe agent rule". Needs product sign-off. On HOLD for App#104055, which this builds on for the category tax rate editor.

The Flag for review, Require fields and Spend editors now keep a seeded draft. With the beta, New rule has no agent option, so the Agents tab gets an Add agent rule row. The option descriptions are shorter for everyone.

Fixed Issues

$ https://github.com/Expensify/Expensify/issues/683436
PROPOSAL: N/A

Tests

Precondition: Enable the describeRule beta on the test account.

  1. As a workspace admin on a Control workspace, open Rules > New rule.
  2. Verify "Start with a template" lists the four rule types, and "Or just describe it below" shows a text box with Next at the bottom.
New rule with the templates and the describe section 3. Click into the box and out again, and verify no error shows. Tap Next with the box empty, and verify "Select a template or describe a rule to continue" shows above Next. Empty describe box: error above Next
  1. Describe "Flag meals expenses over $500 for review" and tap Next.
  2. Verify the Flag for review editor opens prefilled, and Back returns to New rule with the description kept.
Flag for review editor prefilled 6. Describe "Block gift cards and require receipts over $50" and tap Next. 7. Verify the agent rule page opens on the Write tab, with the description prefilled and the banner shown. Agent rule fallback with the banner 8. Tap Back, then Discard changes, and verify you return to New rule without saving anything. 9. Describe "dsfsdfsdf" and verify the inline error appears. Inline error for an unclear description 10. Open Flag for review from New rule, tap Describe, and verify the editor still uses the Describe modal. 11. On a workspace that has an agent rule, open the Agents tab and verify Add agent rule shows under the list. Add agent rule row under the Agents tab list 12. Tap Add agent rule and verify the agent rule page opens on the Suggested tab. 13. Open Categories, open a category, and tap Create new rule. Verify New rule lists the rule types without the describe section. 14. Turn the beta off with `Onyx.merge('betaOverrides', {describeRule: false})` in the console. Verify New rule lists the four rule types and Describe agent rule, without the describe section. New rule without the describeRule beta
  • Verify that no errors appear in the JS console

Offline tests

  1. Go offline on New rule and describe a rule.
  2. Verify Next stays disabled and nothing navigates.

QA Steps

Precondition: Enable the describeRule beta on the test account.

Same as tests

  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I verified any copy / text that was added to the app is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • If new assets were added or existing ones were modified, I verified that:
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg)
    • The assets load correctly across all supported platforms.
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If the PR adds or modifies the UI:
    • I asked an AI agent to review the changes for accessibility issues and addressed its findings.
    • I tested with a screen reader (VoiceOver on macOS) and verified all new/changed elements are reachable with a logical focus order.
    • I verified all new/changed elements have meaningful accessible names and roles.
    • I verified state changes are announced (e.g. checked/unchecked, expanded/collapsed, selected).
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari

@OSBotify

This comment has been minimized.

@codecov

codecov Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ Changes either increased or maintained existing code coverage, great job!

Files with missing lines Coverage Δ
src/ROUTES.ts 33.63% <100.00%> (+0.30%) ⬆️
src/libs/CategoryTaxRulesUtils.ts 90.76% <100.00%> (+3.88%) ⬆️
src/libs/ExpenseDefaultRuleUtils.ts 97.95% <100.00%> (+0.02%) ⬆️
src/libs/actions/Policy/Rules.ts 78.03% <100.00%> (+0.33%) ⬆️
...es/workspace/rules/AgentRules/AddAgentRulePage.tsx 90.14% <100.00%> (+90.14%) ⬆️
src/pages/workspace/rules/RulesNewPage.tsx 82.14% <100.00%> (+82.14%) ⬆️
src/pages/workspace/rules/tabs/RulesAgentsTab.tsx 64.58% <100.00%> (+64.58%) ⬆️
src/styles/index.ts 66.22% <ø> (ø)
src/styles/variables.ts 100.00% <ø> (ø)
src/pages/workspace/rules/DescribeRuleModal.tsx 95.65% <85.71%> (+8.69%) ⬆️
... and 8 more
... and 9 files with indirect coverage changes

@yuwenmemon
yuwenmemon marked this pull request as ready for review October 13, 2026 23:14
@yuwenmemon
yuwenmemon requested review from a team as code owners October 13, 2026 23:14
@melvin-bot
melvin-bot Bot requested review from dmkt9 and removed request for a team October 13, 2026 23:14
@melvin-bot

melvin-bot Bot commented Oct 13, 2026

Copy link
Copy Markdown

@dmkt9 Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@melvin-bot
melvin-bot Bot requested a review from garrettmknight October 13, 2026 23:14
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-13T23:28:44.999056Z 74eb5c7 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@melvin-bot
melvin-bot Bot removed the request for review from a team October 13, 2026 23:14

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 74eb5c7aaa

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

if (!policy?.areCategoriesEnabled || policyCategories) {
return;
}
openPolicyCategoriesPage(policyID);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Wait for categories before applying the generated rule

When the categories collection is absent, openPolicyCategoriesPage() only starts an asynchronous request while the describe modal remains usable. If GenerateRule responds before that request—or the categories request fails—DescribeRuleModal calls withPolicyCategory() with policyCategories still undefined, which permanently removes a generated category before opening the flag-for-review, require-fields, or merchant editor. On a cold cache this can therefore turn a valid category-based description into an incomplete draft; defer handling/submission until categories have loaded rather than merely initiating the fetch.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Yuwen's Agent) Thanks — real race, but I think the current design handles it acceptably and the proposed deferral would add scope I'd want to confirm first.

  • The page already prefetches categories on focus (useFocusEffect → fetchPolicyCategories) and on reconnect (useNetwork), specifically so the collection is present before an answer arrives (see the comment at RulesNewPage.tsx:98-99).
  • generateRule only fires on form submit, which is seconds after focus, while the category read is a plain API read started at focus. So the read resolves well before the LLM round-trip returns in the normal case.
  • When withPolicyCategory drops the category, seedDraftAndNavigate still opens the editor with a reviewable draft. The admin sees the empty category and picks it before saving — no silent incomplete rule is persisted.

Gating submission on a loaded collection adds a loading/recovery path (product behavior), so I'll leave it as a trade-off for now rather than expand scope here.

@yuwenmemon
yuwenmemon added this pull request to stack #103951 October 13, 2026 23:39
@yuwenmemon
yuwenmemon force-pushed the yuwen-683436-describeRuleAgentFallback branch 2 times, most recently from 496fd34 to dbcbc6a Compare October 13, 2026 23:54
@OSBotify

This comment has been minimized.

@yuwenmemon
yuwenmemon requested a review from a team as a code owner October 14, 2026 06:47
@OSBotify

This comment has been minimized.

@OSBotify

This comment has been minimized.

@yuwenmemon

Copy link
Copy Markdown
Contributor Author

(Yuwen's Agent) Thanks 🦜 — applied all 10 locale refinements in 6982ac1. The German fixes also align the du→Sie formality with Expensify's formal-address convention.

@yuwenmemon

Copy link
Copy Markdown
Contributor Author

@yuwenmemon
yuwenmemon requested review from Krishna2323 and removed request for dmkt9 October 14, 2026 19:28
@JmillsExpensify
JmillsExpensify self-requested a review October 14, 2026 20:22
JS00001
JS00001 previously approved these changes Oct 20, 2026
@Krishna2323

Copy link
Copy Markdown
Contributor

I'm testing the latest changes on native devices. I'll probably finish before the CI checks are done.

@Krishna2323 Krishna2323 left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! :shipit:

Screenshots/Videos

Android: HybridApp
android_hybrid.mp4
MacOS: Chrome / Safari
web_chrome.mp4

@melvin-bot
melvin-bot Bot requested a review from chuckdries October 20, 2026 22:45
@melvin-bot

melvin-bot Bot commented Oct 20, 2026

Copy link
Copy Markdown

@chuckdries Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@yuwenmemon
yuwenmemon requested a review from francoisl October 20, 2026 22:53
@yuwenmemon
yuwenmemon merged commit bc54f60 into main Oct 20, 2026
46 of 48 checks passed
@yuwenmemon
yuwenmemon deleted the yuwen-683436-describeRuleAgentFallback branch October 20, 2026 23:38
@github-actions

Copy link
Copy Markdown
Contributor

🚧 yuwenmemon has triggered a test Expensify/App build. You can view the workflow run here.

yuwenmemon added a commit that referenced this pull request Oct 20, 2026
@OSBotify

Copy link
Copy Markdown
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/yuwenmemon in version: 9.5.16-0 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

@MelvinBot

Copy link
Copy Markdown
Contributor

No help site update needed. The describe-a-rule flow is behind the describeRule beta. The changes everyone sees are shorter option descriptions on New rule, where the option names stay the same, and an extra Add agent rule row on the Agents tab. Neither change makes a sentence in Workspace Rules wrong.


view run

@mitarachim

Copy link
Copy Markdown

Deploy Blocker #104648 was identified to be related to this PR.

@jponikarchuk

jponikarchuk commented Oct 22, 2026 •

Copy link
Copy Markdown

This PR failing because of the issue #104688
This issue is reproducible in: Web, Android app

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/yuwenmemon in version: 9.5.18-0 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 cancelled 🔪

@MelvinBot

Copy link
Copy Markdown
Contributor

A help site update is needed. I opened Docs updates for E/A#103810 Update New rule option descriptions in Workspace Rules.

This PR shortened three New rule option descriptions for all users. The Workspace Rules article still quoted the old text:

  • Flag for review – Notify approvers when expenses exceed category limits.
  • Set field requirements – Require specific expense fields or waive requiring them.
  • Apply expense defaults – Update fields without the submitter doing anything.

The docs PR changes only those three bullets to match the new UI copy. I didn't document the parts behind the describeRule beta, such as the describe section and the removal of Describe agent rule.

@yuwenmemon, please review the linked help site PR and confirm it reflects the current behavior. Then mark the linked help site PR Ready for review


view run

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/grgia in version: 9.5.18-1 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

Bundle Size Analysis (Sentry):

@melvin-bot

melvin-bot Bot commented Oct 23, 2026

Copy link
Copy Markdown

🤖 Payment issue created: #104872

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.