Skip to content

fix Copilot - Not here page when click Create expense in delegate mode - #102346

Merged
Julesssss merged 8 commits into
Expensify:mainfrom
apeyada:fix-97769
Oct 20, 2026
Merged

Julesssss merged 8 commits into
Expensify:mainfrom
apeyada:fix-97769

Conversation

@apeyada

@apeyada apeyada commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Explanation of Change

The "Add expense" button and the page it opens used different checks. A report received from another session has no parentReportID/chatReportID, so the page rejected it and later steps couldn't find the workspace chat.

  • canRequestMoney: expense reports now use canAddTransaction, the same check the button uses.
  • New getChatReportFromMoneyRequestReport: when chatReportID is missing, finds the workspace chat from the report's policyID and ownerAccountID. Used by all the expense creation flows.
  • The recipient picker only offers workspaces when the flow starts from an expense report.

Fixed Issues

$ #97769
PROPOSAL: #97769 (comment)

Tests

Preconditions:

  • Account A grants Copilot access to Account B
  • Account B switches to act as Account A (delegate mode), open it in a secondary device
  • Have: an open report (which can have some actions)
  1. Open a submitted expense as Account B (acting as Account A)
  2. Click on 'Submit' button (or any other button) on the preview report
  3. Create a new report
  4. Go to Account A browser/device (not delegate mode)
  5. Go to workspace chat
  6. Click 'Add expense' button on empty report
  • Verify that no errors appear in the JS console

Offline tests

Same as Tests

QA Steps

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 followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and 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 followed the guidelines as stated in the Review Guidelines
  • 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 any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • 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.
  • 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
test2.mov
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari
test1.mov

@apeyada
apeyada marked this pull request as ready for review September 26, 2026 08:07
@apeyada
apeyada requested review from a team as code owners September 26, 2026 08:07
@melvin-bot
melvin-bot Bot requested review from situchan and trjExpensify and removed request for a team September 26, 2026 08:07
@melvin-bot

melvin-bot Bot commented Sep 26, 2026

Copy link
Copy Markdown

@situchan 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]

@codecov

codecov Bot commented Sep 26, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Looks like you've decreased code coverage for some files. Please write tests to increase, or at least maintain, the existing level of code coverage. See our documentation here for how to interpret this table.

Files with missing lines Coverage Δ
src/libs/ReportUtils.ts 88.65% <100.00%> (+0.15%) ⬆️
src/libs/actions/IOU/MoneyRequest.ts 78.61% <100.00%> (+1.31%) ⬆️
src/libs/actions/IOU/PerDiem.ts 94.73% <100.00%> (+1.87%) ⬆️
src/libs/actions/IOU/Split.ts 76.55% <100.00%> (+0.20%) ⬆️
src/libs/actions/IOU/TrackExpense.ts 84.63% <100.00%> (+0.46%) ⬆️
...p/confirmation/submission/useDistanceSubmission.ts 95.12% <100.00%> (-0.12%) ⬇️
...ep/confirmation/submission/usePerDiemSubmission.ts 90.00% <100.00%> (ø)
...nfirmation/submission/useTrackExpenseSubmission.ts 92.72% <100.00%> (-0.26%) ⬇️
... and 339 files with indirect coverage changes

@MelvinBot

MelvinBot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Code review

Verdict: Looks correct. I found no blocking issues. Required checks pass; only Check independent approval fails, and it waits for a reviewer approval.

Why the canRequestMoney change is safe: Removing the parent-chat lookup does not let non-owners add expenses. Expense reports still go through canAddTransaction, which requires the current user to be the submitter on a group policy (ReportUtils.ts:3053).

Suggestions (non-blocking):

  1. Other flows still read chatReportID directly. This PR works around a report that arrives without chatReportID and parentReportID. Other code still reads that field directly, for example submit in ReportWorkflow.ts:551. Those flows may still misbehave for the same report. Consider checking why the pushed report lacks these fields, or noting a follow-up.
  2. The fallback in the hook doesn't update. useExpenseSubmission.ts:275 runs during render. getPolicyExpenseChat reads the non-reactive deprecatedAllReports and scans all reports. If the workspace chat loads later, the hook won't re-render. It only runs when chatReportID is missing, so the cost is small.
  3. Screenshots are missing. The platform checkboxes are ticked, but every Screenshots/Videos section is empty.
What I checked
  • The empty {} draft passed from useExpenseSubmission does not block the new fallback. getReportOrDraftReport skips an empty draft and returns undefined, so the fallback still runs (ReportUtils.ts:1268).
  • Returning undefined for an IOU report with no chatReportID matches the old behavior.
  • Invoice reports are not affected, because isMoneyRequestReport covers only IOU and expense reports.
  • The unit tests cover all four branches of getChatReportFromMoneyRequestReport, plus the empty expense report case in getMoneyRequestOptions.

@MelvinBot

Copy link
Copy Markdown
Contributor

Regression check

Result: I found no confirmed regressions. For any expense or IOU report whose linked chat is loaded, the new code returns the same result as before. Behavior changes only for an expense report you own whose chat can't be found. That is the case this PR fixes.

Risks worth a look (none confirmed):

  1. The report picker still reads chatReportID directly. useReportSelectionActions.ts:128-136 sets the participant's reportID to undefined for the same broken report. requestMoney recovers, but code that reads the participant's reportID does not. Consider using getChatReportFromMoneyRequestReport here too.
  2. The fallback may pick the wrong chat. getPolicyExpenseChat returns the first match and does not skip archived chats. If an owner has two workspace chats in one workspace, the expense could go to the wrong one. I couldn't confirm this can happen.
  3. The page now opens when the chat isn't loaded at all. With no chatReportID, no parent, and no loaded workspace chat, the participant list is empty. I didn't trace how the confirmation step handles that. This should be rare.
  4. The fallback doesn't update and scans every report. useExpenseSubmission.ts:275 scans all reports on every render when chatReportID is missing. The hook won't re-render if the chat loads later.

Other findings:

  • The PR description is out of date. It says the recipient picker only offers workspaces for expense reports. Commit 5db3f7eabc ("remove unnecessary change") reverted that change.
  • One existing test never asserts. ReportUtilsTest.ts:4749-4762 calls expect inside a .then() it doesn't await or return, so the test passes regardless of the result. No test covers the rule this PR relaxes, or requestMoney using the fallback chat.
  • One doc comment is out of date. ReportUtils.ts:10824 still says "tied to a policy expense chat the user owns".
Scenarios I cleared

canRequestMoney:

  • The old parent-chat check only applied to expense reports where you are the only participant. Expense reports with more participants already went to canAddTransaction.
  • canAddTransaction still requires you to be the submitter on a group policy (ReportUtils.ts:3053).
  • These cases behave as before: self-approval reports, submitted or processing reports, personal policies, admins viewing an employee's report, reports someone else owns, invoice reports, archived reports, and IOU reports.
  • Inside getMoneyRequestOptions, expense reports still get only Submit and Track, never Split or Pay.
  • The Not here check, the composer "+" menu, and receipt drops now match the "Add expense" button.

The chat fallback in the expense flows:

  • With the report ID passed in, getMoneyRequestInformation still adds the expense to the existing report. It does not create a new report (MoneyRequestBuilder.ts:1424-1431).
  • Report preview reuse and the updates written to the chat work as they do when chatReportID is present.
  • Before this PR, the missing-chat case was worse: track expense fell back to the self DM, participants were empty, and per diem generated a new chat ID.
  • getPerDiemExpensePolicyID still returns the report's own policy.

I checked the code only and didn't run the app, because I found no suspected regression to reproduce. Jest passed in CI on this commit.


view run

@situchan

situchan commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible 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 checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified that the composer does not automatically focus or open the keyboard on mobile unless explicitly intended. This includes checking that returning the app from the background does not unexpectedly open the keyboard.
  • I verified tests pass on all platforms & I tested again on:
    • Android: HybridApp
    • Android: mWeb Chrome
    • iOS: HybridApp
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified proper code patterns were followed (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick).
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and 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 verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)
  • 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.
  • For any bug fix or new feature in this PR, I verified that sufficient unit tests are included to prevent regressions in this 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.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Android: HybridApp
Android: mWeb Chrome
iOS: HybridApp
iOS: mWeb Safari
MacOS: Chrome / Safari
102346.mov

@MelvinBot

MelvinBot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Regression check (follow-up)

Result: I found no regressions. This follow-up adds a web test and closes two risks the earlier code-only check left open.

Web smoke test (✅ pass on commit 2f5ae0b): Adding expenses from the workspace chat, an existing report, and a new empty report all worked. Each expense landed on the right report.

New report with its expense

Step Status
Create a manual expense from the workspace chatA report preview with Test Merchant $25.00 appeared in the workspace chat.
Report preview in workspace chat
✅
Add a second expense from inside that reportThe composer "+" menu opened Create expense with no Not here page. The same report then showed both expenses, total $37.50.
Same report with two expenses
✅
The report's create options show no Split or Pay"Add expense" offered Create expense, Track distance, and Add existing expense. The composer "+" offered Create expense, Track distance, Assign task, and Add attachment.
Composer plus menu on the report
✅
Create an empty report, then use its "Add expense" buttonThe new report received Third Merchant $9.99. The first report was unchanged.
New empty report
New report with its expense
✅
No JS console errorsNot verified. The web test tool can't read the console. No error screens or crash pages appeared.
⚠️

The test didn't reproduce the delegate-mode scenario from the linked issue. It needs two accounts with Copilot access.

Risks the earlier check left open:

  1. The fallback picks the wrong workspace chat. Low risk, and the codebase already relies on this lookup. About 25 existing callers use the same owner-plus-workspace lookup. When a member rejoins, App reuses and unarchives the old chat instead of creating a second one (Policy.ts:1751-1795). I couldn't confirm that the backend never creates duplicates.

  2. The page opens while the workspace chat isn't loaded. This causes no crash and no bad write. The confirmation step blocks submit with "Please select a participant" (useConfirmationValidation.ts:192-194). Two rough edges remain:

    • In the distance flow, the "To" row is hidden, so you can only go back.
    • In the manual flow, you can pick another recipient, and the expense then goes there instead of to the report.

    The same state was already reachable before this PR for reports with more than one participant.

Other screens that changed

After this PR, only three screens behave differently for an owner's open expense report with no linked chat:

All three now match the "Add expense" button, which already used canAddTransaction alone. The global create button, Search bulk actions, and quick actions don't call canRequestMoney, so they are unchanged.


view run · view recording

@situchan situchan 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

@melvin-bot
melvin-bot Bot requested a review from Julesssss September 26, 2026 08:55
trjExpensify
trjExpensify previously approved these changes Sep 28, 2026

@trjExpensify trjExpensify 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.

Makes sense. 👍

@apeyada

apeyada commented Oct 16, 2026

Copy link
Copy Markdown
Contributor Author

@Julesssss kind bump

@Julesssss Julesssss 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.

Oh sorry for delay here. Please can you merge main and resolve conflicts?

@apeyada

apeyada commented Oct 19, 2026

Copy link
Copy Markdown
Contributor Author

Please can you merge main and resolve conflicts?

Done thanks

@apeyada
apeyada requested a review from Julesssss October 19, 2026 22:04
@Julesssss
Julesssss merged commit 4bc2926 into Expensify:main Oct 20, 2026
34 of 35 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

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

@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/Julesssss 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. This PR is a bug fix: Add expense on an empty expense report now opens the expense flow as users already expect, and it doesn't change any feature, label, or step that an article describes.


view run

@OSBotify

Copy link
Copy Markdown
Contributor

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

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

@MelvinBot

Copy link
Copy Markdown
Contributor

No help site update needed. This PR fixes a bug where Add expense on an empty expense report synced from another session (for example, a Copilot session) failed. After the fix, the button works as users already expect, and no help article sentence becomes incorrect.


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):

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.

6 participants