Skip to content

fix: keep shared receipts out of the folder the iOS share extension wipes - #98974

Open
adhorodyski wants to merge 3 commits into
Expensify:mainfrom
callstack-internal:2790-share-receipt-destroy
Open

fix: keep shared receipts out of the folder the iOS share extension wipes#98974
adhorodyski wants to merge 3 commits into
Expensify:mainfrom
callstack-internal:2790-share-receipt-destroy

Conversation

@adhorodyski

@adhorodyski adhorodyski commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Explanation of Change

Two things destroy a shared receipt before its expense uploads: the share extension wipes its folder on every new share, and it writes files with .completeFileProtection, which makes them unreadable while the device is locked. Either way the request goes out without the receipt and the user gets a $0 expense with no error.

Shared receipts drop at 2.05% against a 0.59% iOS baseline (Aug 8 to Aug 18, 101 of 4,938).

  • SubmitDetailsPage moves the file into Documents/Receipts-Upload before reading it, through the same ReceiptStorage.adopt the camera and gallery paths use, and points the draft receipt at the moved copy.
  • ShareViewController drops the protection option. checkFileExists logs the stat code, so a locked device stops looking like a deleted file.

The protection fix that reaches iOS users is https://github.com/Expensify/Mobile-Expensify/pull/14063, because HybridApp builds Mobile-Expensify/iOS/SmartScanExtension. The copy here only keeps the two from diverging.

Fixed Issues

$ #98980
PROPOSAL: N/A

MOBILE-EXPENSIFY: https://github.com/Expensify/Mobile-Expensify/pull/14063

Tests

iOS native, HybridApp build.

Share A, then share B before A uploads

  1. Go offline
  2. Share a receipt into Expensify from Photos or Files, pick a participant, and submit. The request stays in the offline queue
  3. Share a second, different receipt and submit that too
  4. Go online
  5. Verify both expenses upload with their own receipt image. Before this change the first one arrives at $0 with no image

Locked device

  1. Go offline, share a receipt, and submit
  2. Lock the device
  3. Restore the network while locked and wait for the queue to flush
  4. Unlock and verify the expense has its receipt

Share regression sweep

  1. Share a JPEG, a PNG, a PDF and a HEIC. Verify each one shows on the confirmation screen and submits with its receipt
  2. Share a file, then replace, crop and rotate the receipt before submitting. Verify the edited image is what uploads
  3. Share into a chat through the Share tab. Verify the attachment posts as before
  4. Share a URL and plain text. Verify both behave as before

Other capture paths

  1. Scan a receipt with the camera, from the gallery, and through replace. Verify each one attaches
  2. Submit a distance expense. Verify it goes through normally

Automated

tests/ui/SubmitDetailsPageTest.tsx covers three cases of the share submit: the adopted uri reaches readFileAsync, a failed adopt logs and still submits with the shared path, and a retry after a failed read adopts and reads the durable copy rather than the emptied shared path. tests/unit/checkFileExistsTest.ts covers the locked-device case, where an EPERM still reports missing but the code reaches telemetry.

  • Verify that no errors appear in the JS console

Offline tests

The share A then share B case above runs offline by design. Also:

  1. Go offline, share a receipt, and submit
  2. Force-kill and relaunch the app
  3. Verify the queued expense still previews its receipt, then go online and verify it uploads with the image

QA Steps

The steps above, on the staging HybridApp build, on a physical iPhone with a passcode set.

  • 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 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 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
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari

A receipt shared into the app stays in the app-group `sharedFiles` folder until
it uploads. The iOS share extension clears that whole folder on every new share,
so sharing a second receipt deletes the first one while it is still queued, and
the request goes out with no receipt: a $0 expense and no error. Shared receipts
drop at ~2% against a 0.6% iOS baseline, and they are the only drops that do not
cross an app upgrade.

Adopt the shared file into the receipts folder at submit, the way every other
capture path already does, so the wipe cannot reach a pending receipt. A failed
move falls back to the shared path, because turning a 2% silent drop into a 100%
blocked submit is the worse trade.

The extension also wrote those files with `.completeFileProtection`, which makes
them unreadable while the device is locked. `RNFS.moveFile` is a rename and
preserves the protection class, so the adopt alone does not fix it. Drop the
option here; the same one-line change ships separately in Mobile-Expensify's
`SmartScanExtension`, which is the copy HybridApp actually builds.

`checkFileExists` turned every stat rejection into a plain `false`, so a locked
device and a deleted file were indistinguishable. Log the error code on the
`[Receipt]` spine so the residual drops can be attributed.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor

⚠️ This PR is possibly changing native code and/or updating libraries, it may cause problems with HybridApp. Please check if any patch updates are required in the HybridApp repo and run an AdHoc build to verify that HybridApp will not break. Ask Contributor Plus for help if you are not sure how to handle this. ⚠️

@adhorodyski

Copy link
Copy Markdown
Contributor Author

@codex review

@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: 88bb3a6d46

ℹ️ 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/pages/Share/SubmitDetailsPage.tsx Outdated
adhorodyski and others added 2 commits August 19, 2026 15:40
The adopt is a move, so the app-group path is empty once it lands. performUpload
kept reading the source off the draft, which still named the shared path, so a
retry after a failed read adopted a file that no longer existed, fell back to the
same dead path, and could never recover.

Write the durable uri back to the draft, the way every other capture path already
hands the durable uri downstream. The preview and the size check read the same
field, so they stop pointing at the file the move took away too.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Keep only the lines naming a constraint the code cannot show: the extension
wiping its folder, and the move emptying the shared path.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@adhorodyski

Copy link
Copy Markdown
Contributor Author

@MelvinBot review this PR

@MelvinBot

Copy link
Copy Markdown
Contributor

Review

Looks solid — ship it. The change correctly fixes two independent iOS receipt‑drop mechanisms (the share‑extension folder wipe, and .completeFileProtection making files unreadable while locked), the retry regression Codex flagged is genuinely resolved, and CI is green (all test jobs, typecheck, ESLint, and React Compiler pass; the only red check is Check independent approval, which is approval‑gating, not code).

I traced the submit path and it holds up:

  • performUpload adopts to the durable copy, writes the durable uri back to the draft via setMoneyRequestReceipt, and reads from the local uri variable (not the draft), so the read doesn't depend on the Onyx write landing.
  • The retry is correctly idempotent: on a second attempt currentReceiptSource is the durable uri, and native adopt short‑circuits via toDurableName/verify and re‑reads the moved copy instead of moveFile‑ing an already‑moved (missing) source. The new test in SubmitDetailsPageTest.tsx pins exactly this.
  • Web is unaffected — adopt is a no‑op that resolves to the source, so no spurious adopt failed alerts fire off‑native. A web smoke test of the general expense create/submit flow passed with no console/network errors (the Share screen itself is native‑share‑only and unreachable in a browser).

A few non‑blocking notes:

Details
  1. [Receipt]-prefixed telemetry inside a generic util (minor). checkFileExists is a general file‑existence helper but now emits logReceiptStatFailed ([Receipt] stat failed). Both current callers — validateReceiptFile and the receipt branch of prepareRequestPayload — are receipt paths, so the label is accurate today. But a future non‑receipt caller of this generic util would emit a mislabeled [Receipt] event. Consider passing a context/prefix, or dropping a comment noting the util is receipt‑scoped. Low priority.

  2. No trailing .catch on the final readFileAsync (edge, pre‑existing). readFileAsync reports failures through its onFailure callback (which resets formHasBeenSubmitted/isConfirming), so this is fine in practice. If its own promise ever rejected instead of invoking onFailure, the button would be stuck and the rejection unhandled. This matches the pre‑refactor behavior, so it's not a regression — just noting it.

  3. .completeFileProtection removal only touches the non‑shipping copy. As the PR body says, HybridApp builds Mobile-Expensify's extension, so the real iOS fix rides on the linked Mobile‑Expensify PR + submodule bump. Worth making sure that bump actually lands, otherwise shipping users keep hitting the locked‑file variant even after this merges. Removing the option drops the file to iOS's default protection class (completeUntilFirstUserAuthentication), i.e. readable after first unlock — which is the intent.

  4. Two knowingly‑unfixed cases (share landing while on the confirm screen; share‑to‑chat via ShareDetailsPage) are clearly called out in the description — nice transparency. A tracking follow‑up issue would be good if one doesn't exist yet.

None of these block merge. Nice, tightly‑scoped fix with good test coverage.

@adhorodyski
adhorodyski marked this pull request as ready for review August 19, 2026 14:20
@adhorodyski
adhorodyski requested review from a team as code owners August 19, 2026 14:20
@melvin-bot
melvin-bot Bot requested review from ZhenjaHorbach and trjExpensify and removed request for a team August 19, 2026 14:20
@melvin-bot

melvin-bot Bot commented Aug 19, 2026

Copy link
Copy Markdown

@ZhenjaHorbach 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 review from a team and mountiny and removed request for a team August 19, 2026 14:20
@melvin-bot

melvin-bot Bot commented Aug 19, 2026

Copy link
Copy Markdown

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

@github-actions

Copy link
Copy Markdown
Contributor

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

@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: 28eca70098

ℹ️ 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".

return false;
};

return statIsFile(decodedPath).catch((error: unknown) => (decodedPath === rawPath ? statFailed(error) : statIsFile(rawPath).catch(statFailed)));

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 Retain the first stat error across the raw-path fallback

When a normal percent-encoded URI is checked while its actual decoded file is locked, the decoded RNFS.stat can fail with EPERM, but this branch discards that error and probes the literal %20/%23 path next; that nonexistent fallback then reports ENOENT, which is the only code sent to receipt telemetry. This makes locked files look deleted in precisely the encoded-path scenario the new telemetry is intended to diagnose, so preserve the decoded-path error or report both failures when the fallback also fails.

Useful? React with 👍 / 👎.

@github-actions

Copy link
Copy Markdown
Contributor

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.

2 participants