Skip to content

[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

Closed

Description

@m-natarajan

If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!


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:

  1. Open app
  2. Click camera to scan receipt
  3. Camera opens
  4. 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:

  • Android: App
  • Android: mWeb Chrome
  • iOS: App
  • iOS: mWeb Safari
  • iOS: mWeb Chrome
  • Windows: Chrome
  • MacOS: Chrome / Safari

Screenshots/Videos

Image Image

View all open jobs on GitHub

Issue OwnerCurrent Issue Owner: @dylanexpensify

Activity

  1. added
    ExternalAdded to denote the issue can be worked on by a contributor
    BugSomething is broken. Auto assigns a BugZero manager.
    on Feb 6, 2026
  2. added
    Help WantedApply this label when an issue is open to proposals by contributors
    on Feb 6, 2026
  3. melvin-bot commented on Feb 6, 2026

    @melvin-bot

    Triggered auto assignment to Contributor-plus team member for initial proposal review - @ikevin127 (External)

  4. melvin-bot commented on Feb 6, 2026

    @melvin-bot

    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.

  5. MelvinBot commented on Feb 6, 2026

    @MelvinBot
    Contributor

    This has been labelled "Needs Reproduction". Follow the steps here: https://stackoverflowteams.com/c/expensify/questions/16989

  6. samranahm commented on Feb 6, 2026

    @samranahm
    Contributor

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

    1. The camera captures a photo successfully
    2. The app attempts to crop the image to fit the viewfinder aspect ratio using cropImageToAspectRatio
    3. The function calls cropOrRotateImage which uses expo-image-manipulator's manipulateAsync
    4. On iOS, the library tries to create a CGContext for image processing
    5. If there are insufficient memory resources or invalid parameters, CGContext creation fails
    6. 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.

    1. 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);
            const originalSource = getPhotoSource(photo.path);
            const originalFile = {
                ...photo,
                source: originalSource,
            };
            
            setMoneyRequestReceipt(transactionID, originalSource, photo.path, !isEditing, 'image/jpeg');
            // ... handle the rest of the flow with original image
        });
    1. 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 image
            Log.warn('Error cropping image, using original', cropError);
            const originalSource = URL.createObjectURL(originalFile);
            // Continue with original image
        });
    1. Improve error logging in cropImageToAspectRatio utility:
    .catch((error) => {
        // Log specific image manipulation errors for debugging
        Log.warn('Error in cropImageToAspectRatio', error);
        return image;
    });

    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)

    N/A

  7. removed
    Help WantedApply this label when an issue is open to proposals by contributors
    on Feb 6, 2026
  8. 44 remaining items

  9. 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
  10. melvin-bot commented on Mar 23, 2026

    @melvin-bot

    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:

  11. melvin-bot commented on Mar 23, 2026

    @melvin-bot

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

  12. dylanexpensify commented on Mar 24, 2026

    @dylanexpensify
    Contributor

    coming up

  13. ikevin127 commented on Mar 28, 2026

    @ikevin127
    Contributor

    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:

    • 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.

  14. dylanexpensify commented on Mar 30, 2026

    @dylanexpensify
    Contributor

    Payment summary:

    Contributor+: @ikevin127 $250 via NewDot

    Please apply/request!

  15. garrettmknight commented on Apr 2, 2026

    @garrettmknight
    Contributor

    $250 approved for @ikevin127

  16. FitseTLT commented on Aug 18, 2026

    @FitseTLT
    Contributor

    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.

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

Metadata

Metadata

Labels

Awaiting PaymentAuto-added when associated PR is deployed to productionBugSomething is broken. Auto assigns a BugZero manager.DailyKSv2ExternalAdded to denote the issue can be worked on by a contributor

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions