Skip to content

Keep native receipt creates on disk and stop moving expenses the server rejected - #107935

Merged
mountiny merged 5 commits into
Expensify:mainfrom
callstack-internal:eliran/3293-lost-create-456
Nov 27, 2026
Merged

mountiny merged 5 commits into
Expensify:mainfrom
callstack-internal:eliran/3293-lost-create-456

Conversation

@elirangoshen

@elirangoshen elirangoshen commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Explanation of Change

Some expenses never reach the server, and the move queued after them fails with a 456 ("Could not retrieve all transactionIDs"). This PR fixes the three App-side causes:

  1. Native receipt creates are now saved to disk while being sent. canPersistRequest skipped any request holding a File, and native receipts are RN Files, so an app killed mid-upload lost the create. The skip is now web-only: on native the receipt file stays in the app's folder and still uploads after a restart. A RN File keeps its name and type on the prototype, so they are now copied onto the file when it is queued; otherwise a receipt restored from disk would be sent without a filename or type.
  2. An expense whose create the server rejected can no longer be added to a report. New hasCreateFailed keeps it out of "Add existing expense" and the move-to-report permission. A create that is only pending can still be moved.
  3. A failed move now shows an error on the expense instead of silently putting it back on its old report. A later move that works clears it.

Fixed Issues

$ #106959
PROPOSAL:

Automated Tests

  • tests/unit/PersistedRequestsNativeTest.ts (new): with the native variant, a receipt create holding a File stays on disk as the ongoing request while it is sent, with the queued move still behind it, and updateOngoingRequest stores it too. A queued receipt keeps its name and type when stored as JSON. The mock keeps them on the prototype like a RN File. All three cases fail against the previous behavior.
  • tests/unit/canEditFieldOfMoneyRequestTest.ts: moving to a report is not allowed when the create was rejected, and is still allowed while the create is only pending.
  • tests/unit/AddExistingExpenseTest.ts: "Add existing expense" leaves out an expense whose create was rejected, and keeps one whose create is only pending.
  • tests/actions/TransactionTest.ts: a failed move puts the expense back on its report with the error, and a later move that works clears it.
  • tests/unit/PersistedRequests.ts and tests/unit/RequestsKeptOnSAMLSignOutTest.ts now load the web variant explicitly, because Jest resolves .native files by default and these cases cover web.

Tests

Rejected create is not offered in "Add existing expense":

  1. Sign in as a workspace admin with two distance rates on the workspace.
  2. Go offline and create a distance expense on the workspace using the second rate.
  3. In another session of the same account that is online, delete that rate.
  4. Go back online in the first session and verify the expense shows "Unexpected error submitting this expense".
  5. Create a new report, then tap Add expense > Add existing expense.
  6. Verify the rejected expense is not in the list, while other unreported expenses are.

Failed move shows an error:

  1. Go to Troubleshoot and turn on "Simulate failing network requests".
  2. Move an expense to another report.
  3. Verify the expense goes back to its old report and shows "Unexpected error editing this expense. Please try again later."
  4. Turn "Simulate failing network requests" off and move the expense again.
  5. Verify it moves and the error is gone.

Receipt create survives an app kill during upload (iOS):

  1. Turn on a very slow network, for example Settings > Developer > Network Link Conditioner > Very Bad Network.
  2. Share a photo from Photos into Expensify and submit it as an expense.
  3. While it is still uploading, force-quit the app.
  4. Turn off the network conditioner and open the app.
  5. Verify the expense is created with its receipt and has no error.
  • Verify that no errors appear in the JS console

Offline tests

  1. Go offline, create an expense, and move it to another report.
  2. Go online and verify the create goes through first and then the move, with no error on the expense.

QA Steps

  • 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 qa-after-add-existing qa-after-failed-move-error qa-before-add-existing

A request holding a File was never written to disk while in flight. On
native the receipt create is such a request, so an app killed mid-upload
lost the create while the move queued behind it survived and got a 456.
On native the receipt lives in the app's own folder and the upload is
rebuilt from its path, so it can be stored like any other request.
The failed create leaves the expense on screen with an error, but the
server has no such expense, so moving it or adding it to a report only
fails with a 456. A create that is still queued keeps working, since the
queue sends the move after it.
A failed ChangeTransactionsReport put the expense back on its report
with no message, so the user couldn't tell it didn't sync.
@elirangoshen
elirangoshen marked this pull request as ready for review November 25, 2026 13:03
@elirangoshen
elirangoshen requested review from a team as code owners November 25, 2026 13:03
@expensify-chore-bot
expensify-chore-bot Bot requested review from jayeshmangwani and removed request for a team November 25, 2026 13:03
@expensify-chore-bot

Copy link
Copy Markdown

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

@expensify-chore-bot
expensify-chore-bot Bot requested review from JmillsExpensify and removed request for a team November 25, 2026 13:03

@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: d9f3281aad

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/libs/actions/Transaction.ts Resolved
@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-25T13:19:48.584466Z d9f3281 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.

A React Native File keeps its name and type on its prototype, so a queued
receipt create written to disk came back after a restart without them and
was uploaded as an unnamed, untyped part. Copy them onto the file when the
request is queued, and reuse the same helper where the upload is rebuilt.

A move that failed and then succeeded on retry kept the earlier error on
the expense, so clear errors in the move's success data.

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

No product review required.

@jayeshmangwani

Copy link
Copy Markdown
Contributor

Failed move shows an error:

  1. In session A, go offline and move an expense to another report.
  2. In session B, delete that expense.
  3. Bring session A back online and verify the expense goes back to its old report and shows "Unexpected error editing this expense. Please try again later."

@elirangoshen, I'm trying to test this scenario, but when I move the expense in Session A(offline), delete it from Session B(online), and then bring Session A back online, it successfully moves to the other report that we selected while offline.

offline-chanding-report.mov

@elirangoshen

Copy link
Copy Markdown
Contributor Author

Failed move shows an error:

  1. In session A, go offline and move an expense to another report.
  2. In session B, delete that expense.
  3. Bring session A back online and verify the expense goes back to its old report and shows "Unexpected error editing this expense. Please try again later."

@elirangoshen, I'm trying to test this scenario, but when I move the expense in Session A(offline), delete it from Session B(online), and then bring Session A back online, it successfully moves to the other report that we selected while offline.

offline-chanding-report.mov

@jayeshmangwani thanks, that's my mistake in the test steps, not a bug in the PR.

I've changed the step to make the move fail on purpose:

  1. Go to Troubleshoot and turn on "Simulate failing network requests".
  2. Move an expense to another report.
  3. Verify the expense goes back to its old report and shows "Unexpected error editing this expense. Please try again later."
  4. Turn "Simulate failing network requests" off and move the expense again.
  5. Verify it moves and the error is gone

let me know its ok now

@jayeshmangwani

Copy link
Copy Markdown
Contributor

@elirangoshen , everything looks good in testing. I noticed just one small issue: when we move the expense, the error message Unexpected error editing this expense. Please try again later appears twice.
Screenshot 2026-11-26 at 9 10 50 PM

The error row under the expense already shows its message errors, so the
row's own red line now keeps only the receipt errors instead of repeating
the same message.
@elirangoshen

Copy link
Copy Markdown
Contributor Author

@elirangoshen , everything looks good in testing. I noticed just one small issue: when we move the expense, the error message Unexpected error editing this expense. Please try again later appears twice. Screenshot 2026-11-26 at 9 10 50 PM

please try now

@jayeshmangwani

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 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 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
    • 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
    • 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 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).
  • 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.mov
Android: mWeb Chrome
mweb-chrome.mov
iOS: HybridApp
ios.mov
iOS: mWeb Safari
mweb-dafari.mov
MacOS: Chrome / Safari
web-test-1.mov
web-test-2.mov

@jayeshmangwani jayeshmangwani 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 mountiny November 26, 2026 16:46
@jayeshmangwani

Copy link
Copy Markdown
Contributor

please try now

thanks, working well now

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

Thank you both

@mountiny
mountiny merged commit d2c0f2a into Expensify:main Nov 27, 2026
38 of 41 checks passed
@melvin-bot melvin-bot Bot added the Emergency label Nov 27, 2026
@melvin-bot

melvin-bot Bot commented Nov 27, 2026

Copy link
Copy Markdown

@mountiny looks like this was merged without a test passing. These checks had not passed on a18335c when it was merged:

Please add a note explaining why this was done and remove the Emergency label if this is not an emergency.

@github-actions

Copy link
Copy Markdown
Contributor

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

@github-actions

Copy link
Copy Markdown
Contributor

@OSBotify

OSBotify commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/mountiny in version: 9.5.56-0 🚀

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

@MelvinBot

Copy link
Copy Markdown
Contributor

No help site update needed — this PR fixes receipt-upload reliability and failed expense moves without adding a feature, changing the normal workflow, or making existing article instructions incorrect.


view run

@OSBotify

OSBotify commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/mountiny in version: 9.5.56-2 🚀

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

Bundle Size Analysis (Sentry):

@mountiny mountiny removed the Emergency label Dec 2, 2026
@mountiny

mountiny commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

This was not an emergency. The Claude review action was broken on main, so proceeded to merge anyway.

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