You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Due for payment 2026-03-30] "Calling the register Async. Function has failed caused by image context has been lost.” when attempting to take a photo of receipt from in app or via Safari Website. #81702
Version Number: Mobile website: 9.3.7-3, App: 9.3.14 Reproducible in staging?: Needs Reproduction (Unable to reproduce) Reproducible in production?: Needs Reproduction If this was caught during regression testing, add the test name, ID and link from BrowserStack: Email or phone of affected tester (no customers): Logs:https://stackoverflow.com/c/expensify/questions/4856 Expensify/Expensify Issue URL: Issue reported by:@abbagail Slack conversation (hyperlinked to channel name): #Expensify Bugs
Action Performed:
Open app
Click camera to scan receipt
Camera opens
Try to take a photo
Expected Result:
Photo uploads and starts smart scanning or added as a receipt
Actual Result:
Error message displayed : "Attachment error. Calling the register Async. Function has failed caused by image context has been lost."
Workaround:
Unknown
Platforms:
Select the officially supported platforms where the issue was reproduced:
Please re-state the problem that we are trying to solve in this issue.
When attempting to take a photo of a receipt from within the app or via Safari website, users encounter an "Attachment error. Calling the register Async. Function has failed caused by image context has been lost." error message. This prevents users from successfully capturing and uploading receipt photos for expense reporting.
What is the root cause of that problem?
The error originates from the expo-image-manipulator library used for image processing. Specifically, the error "image context has been lost" is thrown by the iOS native code when CGContext creation fails in ImageFixOrientationTransformer.swift.
This happens when:
The camera captures a photo successfully
The app attempts to crop the image to fit the viewfinder aspect ratio using cropImageToAspectRatio
The function calls cropOrRotateImage which uses expo-image-manipulator's manipulateAsync
On iOS, the library tries to create a CGContext for image processing
If there are insufficient memory resources or invalid parameters, CGContext creation fails
The library throws ImageContextLostException with the message "Image context has been lost"
The current code lacks proper error handling for this specific failure case. In the native implementation (index.native.tsx), the cropImageToAspectRatio promise doesn't have a .catch() handler, so when image manipulation fails, the error bubbles up and crashes the receipt capture flow.
What changes do you think we should make in order to solve the problem?
Add comprehensive error handling to gracefully recover from image manipulation failures by using the original uncropped image as a fallback when cropping fails.
Add error handling to native scan implementation:
IOURequestStepScan/index.native.tsx
cropImageToAspectRatio(imageObject,viewfinderLayout.current?.width,viewfinderLayout.current?.height,undefined,photo.orientation).then(({file, filename, source})=>{}).catch((cropError: string)=>{Log.warn('Error cropping image, using original',cropError);constoriginalSource=getPhotoSource(photo.path);constoriginalFile={
...photo,source: originalSource,};setMoneyRequestReceipt(transactionID,originalSource,photo.path,!isEditing,'image/jpeg');// ... handle the rest of the flow with original image});
Add similar error handling to web implementation:
IOURequestStepScan/index.tsx
cropImageToAspectRatio(imageObject,viewfinderLayout.current?.width,viewfinderLayout.current?.height,shouldAlignTop).then(({file, filename, source})=>{// Handle successful crop...}).catch((cropError: string)=>{// If cropping fails, use the original imageLog.warn('Error cropping image, using original',cropError);constoriginalSource=URL.createObjectURL(originalFile);// Continue with original image});
Improve error logging in cropImageToAspectRatio utility:
.catch((error)=>{// Log specific image manipulation errors for debuggingLog.warn('Error in cropImageToAspectRatio',error);returnimage;});
This approach ensures that when expo-image-manipulator fails due to memory constraints or other iOS-specific issues, the user can still successfully upload their receipt - it just won't be cropped to the viewfinder aspect ratio. The original photo will be preserved and processed normally.
What alternative solutions did you explore? (Optional)
changed the title [-]"Calling the register Async. Function has failed caused by image context has been lost.” when attempting to take a photo of receipt from in app or via Safari Website.[/-][+][Due for payment 2026-03-30] "Calling the register Async. Function has failed caused by image context has been lost.” when attempting to take a photo of receipt from in app or via Safari Website.[/+]on Mar 23, 2026
The solution for this issue has been 🚀 deployed to production 🚀 in version 9.3.41-4 and is now subject to a 7-day regression period 📆. Here is the list of pull requests that resolve this issue:
@ikevin127 The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed. Please copy/paste the BugZero Checklist from here into a new comment on this GH and complete it. If you have the K2 extension, you can simply click: [this button]
[Contributor] The offending PR has been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake.
Link to comment: N/A - Result of the original design
[Contributor] If the regression was CRITICAL (e.g. interrupts a core flow) A discussion in #expensify-open-source has been started about whether any other steps should be taken (e.g. updating the PR review checklist) in order to catch this type of bug sooner.
Link to discussion: N/A
[Contributor] If it was decided to create a regression test for the bug, please propose the regression test steps using the template below to ensure the same bug will not reach production again.
[BugZero Assignee] Create a GH issue for creating/updating the regression test once above steps have been agreed upon.
Link to issue:
Regression Test Proposal
Prerequisites:
iPhone 15 or 16 or 17 Pro / Pro Max
Camera set to 48MP
Test steps:
Open Create → Scan receipt
Take a photo using the shutter button
Expected: Photo captures and proceeds to confirmation - no error dialog, no crash, no hang
Additional test for picking from browser:
Open any chat
Tap attachment → "Choose from gallery"
Select a 48MP HEIC photo
Expected: no error dialog, image attaches successfully
Do we agree 👍 or 👎.
✅ I checked on both alleged regressions mentioned above and it turns out none of them were caused by our PR, so no penalty.
Regression from the fix here, per the BZ checklist.
#85231 fell back to the original file on HEIC conversion failure. It's still HEIC, the server rejects it, so uploads failed silently. Reported as #95825, fixed in #96024.
Activity
melvin-bot commentedon Feb 6, 2026
Triggered auto assignment to Contributor-plus team member for initial proposal review - @ikevin127 (
External)melvin-bot commentedon Feb 6, 2026
Triggered auto assignment to @dylanexpensify (
Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details. Please add this bug to a GH project, as outlined in the SO.MelvinBot commentedon Feb 6, 2026
This has been labelled "Needs Reproduction". Follow the steps here: https://stackoverflowteams.com/c/expensify/questions/16989
samranahm commentedon Feb 6, 2026
Proposal
Please re-state the problem that we are trying to solve in this issue.
When attempting to take a photo of a receipt from within the app or via Safari website, users encounter an "Attachment error. Calling the register Async. Function has failed caused by image context has been lost." error message. This prevents users from successfully capturing and uploading receipt photos for expense reporting.
What is the root cause of that problem?
The error originates from the
expo-image-manipulatorlibrary used for image processing. Specifically, the error "image context has been lost" is thrown by the iOS native code whenCGContextcreation fails inImageFixOrientationTransformer.swift.This happens when:
cropImageToAspectRatiocropOrRotateImagewhich usesexpo-image-manipulator'smanipulateAsyncCGContextfor image processingCGContextcreation failsImageContextLostExceptionwith the message "Image context has been lost"The current code lacks proper error handling for this specific failure case. In the native implementation (
index.native.tsx), thecropImageToAspectRatiopromise doesn't have a.catch()handler, so when image manipulation fails, the error bubbles up and crashes the receipt capture flow.What changes do you think we should make in order to solve the problem?
Add comprehensive error handling to gracefully recover from image manipulation failures by using the original uncropped image as a fallback when cropping fails.
IOURequestStepScan/index.native.tsx
IOURequestStepScan/index.tsx
This approach ensures that when
expo-image-manipulatorfails due to memory constraints or other iOS-specific issues, the user can still successfully upload their receipt - it just won't be cropped to the viewfinder aspect ratio. The original photo will be preserved and processed normally.What alternative solutions did you explore? (Optional)
N/A
44 remaining items
[-]"Calling the register Async. Function has failed caused by image context has been lost.” when attempting to take a photo of receipt from in app or via Safari Website.[/-][+][Due for payment 2026-03-30] "Calling the register Async. Function has failed caused by image context has been lost.” when attempting to take a photo of receipt from in app or via Safari Website.[/+]melvin-bot commentedon Mar 23, 2026
The solution for this issue has been 🚀 deployed to production 🚀 in version 9.3.41-4 and is now subject to a 7-day regression period 📆. Here is the list of pull requests that resolve this issue:
If no regressions arise, payment will be issued on 2026-03-30. 🎊
For reference, here are some details about the assignees on this issue:
melvin-bot commentedon Mar 23, 2026
@ikevin127 The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed. Please copy/paste the BugZero Checklist from here into a new comment on this GH and complete it. If you have the K2 extension, you can simply click: [this button]
dylanexpensify commentedon Mar 24, 2026
coming up
ikevin127 commentedon Mar 28, 2026
BugZero Checklist:
[Contributor] The offending PR has been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake.
Link to comment: N/A - Result of the original design
[Contributor] If the regression was CRITICAL (e.g. interrupts a core flow) A discussion in #expensify-open-source has been started about whether any other steps should be taken (e.g. updating the PR review checklist) in order to catch this type of bug sooner.
Link to discussion: N/A
[Contributor] If it was decided to create a regression test for the bug, please propose the regression test steps using the template below to ensure the same bug will not reach production again.
[BugZero Assignee] Create a GH issue for creating/updating the regression test once above steps have been agreed upon.
Link to issue:
Regression Test Proposal
Prerequisites:
Test steps:
Additional test for picking from browser:
Do we agree 👍 or 👎.
✅ I checked on both alleged regressions mentioned above and it turns out none of them were caused by our PR, so no penalty.
dylanexpensify commentedon Mar 30, 2026
Payment summary:
Contributor+: @ikevin127 $250 via NewDot
Please apply/request!
garrettmknight commentedon Apr 2, 2026
$250 approved for @ikevin127
FitseTLT commentedon Aug 18, 2026
Regression from the fix here, per the BZ checklist.
#85231 fell back to the original file on HEIC conversion failure. It's still HEIC, the server rejects it, so uploads failed silently. Reported as #95825, fixed in #96024.