Skip to content

fix: [SDK-5059] stop dropping iOS crashes we cannot attribute - #1811

Merged
abdulraqeeb33 merged 5 commits into
mainfrom
ar/sdk-5059
Nov 19, 2026
Merged

abdulraqeeb33 merged 5 commits into
mainfrom
ar/sdk-5059

Conversation

@abdulraqeeb33

@abdulraqeeb33 abdulraqeeb33 commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Description

One Line Summary

Stops the crash handler silently discarding OneSignal crashes whose stack cannot name us, and keeps our frames out of tail calls so they reach the handler in the first place.

Details

Motivation

Resolves SDK-5059. OSLogCrashHandler only persisted a crash when a stack frame named OneSignal, and forwarded everything else to the previous handler. Three separate things made that unsafe, each verified rather than theorized.

Tail calls erase the frame. At -O2, a method whose last act is a system call that raises compiles to a bare b with no frame setup, so it never enters callStackReturnAddresses. Reproduced on a minimal +[OSThing boom] ending in [NSException raise:format:]:

-O2:                          -O2 -fno-optimize-sibling-calls:
  b  objc_msgSend$raise:...     stp x29, x30, [sp, #-16]!
                                bl  objc_msgSend$raise:...
                                ldp x29, x30, [sp], #16
                                ret

The dangerous real shape is any SDK method whose final act is a system call that raises: objectAtIndex: out of range, setValue:forUndefinedKey:, NSJSONSerialization. The system frame is skipped as a system image, the elided OneSignal caller is gone, and the surviving frames belong to the app.

The symbol rules missed most of the SDK. They matched only -[OneSignal / +[OneSignal, but the source declares 112 distinct OS-prefixed ObjC classes against 46 OneSignal-prefixed ones. Swizzled categories matched nothing at all, because they land on system classes and name us only in the selector: -[UIApplication setOneSignalDelegate:], -[UNUserNotificationCenter onesignalRequestAuthorizationWithOptions:completionHandler:].

The symbol fallback cannot fire where it was needed. This is the finding that reshaped the fix. dladdr only reports symbols that survive linking, and release builds strip the local symbols naming our ObjC methods and Swift functions, so dli_sname comes back nil. Confirmed three ways:

  • Running a real raised exception through the handler, the frames in the non-framework image all returned nil while system frames resolved.
  • A standalone simulator binary resolved +[OSProbe probe] until strip -x, then returned nil.
  • An app target in Release resolves to STRIP_INSTALLED_PRODUCT = YES with STRIP_STYLE = all.

A non-nil result is not trustworthy either, since dladdr reports the nearest preceding exported symbol. In the captured stack it labelled a -[NSException raise] frame as -[NSException initWithCoder:].

So image matching is the only reliable signal, and it only holds while we ship as separate frameworks. Where it does not hold, dropping turns real crashes into silence indistinguishable from no crashes at all.

Scope

Three changes.

  1. -fno-optimize-sibling-calls on the 11 shipping framework targets and the OneSignal static library, across Debug/Release/Test. Each target's existing OTHER_CFLAGS is preserved rather than switched to $(inherited), which would have newly pulled the project-level -all_load into targets that currently override it. ObjC only: swiftc -Xllvm -disable-tail-calls is accepted silently but emits byte-identical assembly, so it is not worth shipping.

  2. Symbol matching now reads both halves of an -[Class selector] symbol. An onesignal-named selector counts anywhere, covering swizzled categories on system classes. The bare OS class prefix counts only inside the image we share with the host, since our own frameworks are already identified by the module list and the image path, and dladdr does resolve ObjC names in unstripped third-party frameworks where OS would claim unrelated classes such as Aliyun's -[OSSClient ...].

  3. OSOwnImage resolves where our own code lives through dladdr at startup, once, not on the crash path. A frame matching that image counts as ours, which also covers wrappers that repackage or rename the frameworks and that the fixed module list cannot see. When that image is the host's main executable, sharesHostExecutable is true: the crash is captured instead of discarded and tagged ossdk.crash.attributed = false for server-side filtering, and the image match is switched off, because every host frame would otherwise match it and read as ours.

    The executable is found by MH_EXECUTE filetype rather than image index 0. Inserted libraries take the low indices, so on a real app launch the executable sits behind libRPAC, libXCTestBundleInject and libMainThreadChecker; reproduced on the iOS 18.6 and 26.2 simulators, where it is at index 3.

Behavior that does not change. Every integration shipping today uses vendored xcframeworks, so sharesHostExecutable is false and the drop behaves exactly as before. The widened capture only applies where attribution is provably impossible.

What this costs. In the static-link case the SDK now persists and uploads crashes originating entirely in host app code, including their stack traces. That is deliberate, per the discussion on the ticket: the alternative is dropping our own crashes with no signal that anything was missed. Volume is filtered server-side on ossdk.crash.attributed.

Not covered. In a statically linked app, a host or third-party class named OS… compiled into the host binary would still be read as ours. Accepted: over-capturing is recoverable server-side, silently dropping our own crashes is not.

Dependency

Requires OneSignal-KMP-SDK#34, which adds attributed to CrashData. Android lands in lockstep, and the submodule gets repointed to the release tag before merge.

The submodule cannot point at that PR's branch in the meantime. main here pins KMP at b5c7bbea, which is on KMP's unmerged new-session-events branch rather than KMP main, and OSSessionService needs it for FeatureFlag.sdkSessionsV2ApiCutover. PR #34 is correctly based on KMP main, so it does not carry that commit. The pin therefore points at ar/sdk-5059-on-new-session-events, which is the same change applied on top of b5c7bbea. Both go away once #34 merges and is tagged.

Testing

Unit testing

812 tests on UnitTestApp_TestPlan_Reduced. All crash-attribution tests pass. Two unrelated user-module tests (testBasicCombiningUserUpdateDeltas_resultsInOneRequest, testLoggingInAgainAsTheSameUserStoresTheNewToken, "A Request was still in flight at teardown") flake on the iOS 26.2 simulator and pass on 18.6 and on re-run.

Previous tests drove attribution with hand-written frames, which is the seam this bug fell through. New tests raise a real NSException through a small ObjC @try trampoline and run the installed handler against the addresses the runtime captured, so callStackReturnAddresses, dladdr and attribution all execute for real:

  • testCapturesExceptionThrownThroughOneSignalFrame and testIgnoresExceptionThrownEntirelyInHostFrames guard the real resolution path in both directions.
  • testCapturesHostFramesUnattributedWhenSdkSharesTheHostImage and testCapturesExceptionThroughOneSignalFrameAsAttributed assert the tag itself through a recording reporter, not just that a file was written.
  • testIgnoresHostFramesWhenSdkSharesTheHostImage, testIgnoresThirdPartyOSPrefixedClass and testIgnoresOSPrefixedClassOutsideTheSharedHostImage pin the boundaries of the two rules.
  • testRecognizesStaticOSPrefixedObjCClass, testRecognizesStaticSwizzledCategoryOnSystemClass and testRecognizesRepackagedFrameworkByOwnImage cover the widened matching.

The attribution tests now pass an explicit OSOwnImage modelling static or dynamic linkage instead of relying on a default, so a test can no longer pass by supplying a nil image path.

Reverting the two attribution fixes turns seven tests red, including three that predate this PR. The two real-throw tests listed first pass in both states by design; they are regression guards for the dladdr path, not proof of the fix. The MH_EXECUTE change is verified by the simulator measurement above rather than by a test, since faking dyld's image list is not worth the machinery.

Manual testing

Not performed. The tail-call behavior was verified by reading compiler output directly rather than on device, and the dladdr behavior by running a stripped and unstripped probe binary on the iOS 18.6 simulator. Worth an on-device pass against a release build before release.

Affected code checklist

  • Notifications
  • Outcomes
  • Sessions
  • In-App Messaging
  • REST API requests
  • Public API changes

Checklist

Overview

  • I have filled out all REQUIRED sections above
  • PR does one thing
  • Any Public API changes are explained in the PR details and conform to existing APIs

Testing

  • I have included test coverage for these changes, or explained why they are not needed
  • All automated tests pass, or I explained why that is not possible
  • I have personally tested this on my device, or explained why that is not possible

Final pass

  • Code is as readable as possible.
  • I have reviewed this PR myself, ensuring it meets each checklist item

AR Abdul Azeez and others added 3 commits November 17, 2026 10:03
At -O2 a method whose last act is a system call that raises compiles to a bare
b, tearing the frame down before the throw. The frame never reaches
callStackReturnAddresses, so a crash in SDK code arrives with only host frames
and the uncaught-exception handler declines it.

Compile the shipping targets with -fno-optimize-sibling-calls, which restores
the bl and the frame. This is ObjC only; swiftc accepts
-Xllvm -disable-tail-calls but emits identical code, so it is not worth
shipping.

Co-authored-by: Cursor <cursoragent@cursor.com>
The handler only kept a crash when a frame named OneSignal, and treated every
other stack as the host's. Three gaps made that unsafe:

Most of the ObjC surface uses the OS prefix, not OneSignal, and swizzled
categories land on system classes where only the selector names us. Match both
halves of an -[Class selector] symbol instead.

dladdr cannot see us at all once the SDK is linked into the host executable:
release builds strip the local symbols that name our ObjC methods and Swift
functions, and a non-nil dli_sname is the nearest exported symbol, which can
belong to someone else. Resolve our own image through dladdr at startup and
treat attribution as unreliable when it is the main executable, capturing those
crashes rather than discarding them. Matching that image also covers wrappers
that repackage or rename the frameworks.

Record the verdict on CrashData so a crash we could not attribute is visible as
ossdk.crash.attributed=false rather than absent, and filter server-side.

Tests now drive the installed handler with the addresses a real throw captured,
which is the seam the injected-frame tests fell through.

Co-authored-by: Cursor <cursoragent@cursor.com>
Picks up the ossdk.crash.attributed flag on CrashData. Repoint to the release
tag once the KMP change lands.

Co-authored-by: Cursor <cursoragent@cursor.com>
@abdulraqeeb33
abdulraqeeb33 requested a review from a team November 17, 2026 16:55
Review of the first pass found the image match and the shared-image gate
undoing each other. Statically linked, ownImage.path is the host binary, so
every host frame matched it and the crash saved as attributed=true, which is
exactly the signal the tag exists to carry.

Also: image 0 is not the main executable. Inserted libraries take the low
indices, so on a real app launch the executable sits behind libRPAC,
libXCTestBundleInject and libMainThreadChecker, and sharesHostExecutable read
false. Find it by MH_EXECUTE filetype instead.

Restrict the bare OS class prefix to the image we share with the host. Our own
frameworks are already covered by the module list and the image path, and
dladdr resolves ObjC names in unstripped third-party frameworks, where OS would
claim unrelated classes such as Aliyun's -[OSSClient ...].

Tests now model static and dynamic linkage explicitly rather than passing a nil
image path, which hid the first bug, and assert the tag through a recording
reporter instead of counting files.

Co-authored-by: Cursor <cursoragent@cursor.com>

@fadi-george fadi-george 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.

Thanks, all four look good.

Keeps the pin in step with the PR branch; the change is the exported @Property
doc and extra test coverage, no behavior.

Co-authored-by: Cursor <cursoragent@cursor.com>
@abdulraqeeb33
abdulraqeeb33 requested a review from nan-li November 18, 2026 21:41
@abdulraqeeb33
abdulraqeeb33 merged commit f91dc9a into main Nov 19, 2026
6 checks passed
@abdulraqeeb33
abdulraqeeb33 deleted the ar/sdk-5059 branch November 19, 2026 14:38
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