Sentry callbacks off the main actor: test first, then make them nonisolated (CLS-1474) #6
Loading…
Reference in a new issue
No description provided.
Delete branch "cls-1474-sentry-closures"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
SentryBootstrap is @MainActor and sets beforeSend and beforeBreadcrumb as closures inside start(). The Sentry SDK calls both from its own queues. fjord-ios #2720 showed that a closure nested in a main-actor-formed closure traps when it runs off the main actor (test host crash); this checks whether the shipping callbacks can.
Commits, in order:
79e6d76: configure() extracted from start() unchanged (the original closures), plus SentryBootstrapIsolationTests: shipping options built as 1.7 builds them, beforeSend and beforeBreadcrumb called from a background queue, beforeSend from twenty queues at once.0f85a95: beforeSend and beforeBreadcrumb become nonisolated static functions assigned by reference; initialScope and configureProfiling are @Sendable closures.e61c1bb: configure() and the callbacks move to SentryBootstrap+Options.swift (the main file stays under its size, 288 lines).Evidence (Sentry 9.34, Xcode 27.2):
79e6d76, original closures): tests pass, so the callbacks shipping in 0.3.0 do not trap off the main actor.0f85a95, nonisolated): tests pass.The test now guards the new nonisolated form against regression: that is its job going forward. Whether the closures shipped in 0.3.0 were safe is answered by run 16 above, not by the head.
Part of the Mobile 1.7 check (CLS-1474). fjord-ios 1.7 uses this kit at 0.3.0; a 0.3.1 tag and a fjord-ios pin bump follow the merge.
Automated Codex review (read-only) of head
79e6d7631e.No confirmed findings in the diff. The tests are intended to determine whether the existing callbacks trap; their result cannot be established from the diff alone.
BLOCKING: 0
Reviewed head
79e6d7631eat 2026-11-24T21:22:27Z by codex exec (read-only sandbox).Automated Codex review (read-only) of head
0f85a95779.BLOCKING: 1
Reviewed head
0f85a95779at 2026-11-24T21:44:15Z by codex exec (read-only sandbox).Proof that the isolation tests run in CI: throwaway PR #7 (closed, branch deleted) added one deliberate XCTFail inside SentryBootstrapIsolationTests; its run 18 failed naming SentryBootstrapIsolationTests.test_beforeBreadcrumbRunsOffTheMainActor ('Test Suite SentryBootstrapIsolationTests failed'). The runs on this PR passed: run 16 (
79e6d76, callbacks as formed before the change) and run 17 (0f85a95, nonisolated functions). So the callbacks do not trap off the main actor either way, and the suite does run.@gerri: fixed. configure(), filteredEvent and scrubbedBreadcrumb moved to SentryBootstrap+Options.swift (102 lines); SentryBootstrap.swift is now 288 lines, down from 365 on main. No behaviour change.
Automated Codex review (read-only) of head
e61c1bb24e.nonisolatedfunctions in this head. Consequently, a passing iOS simulator run cannot establish whether the closures shipping in 0.3.0 trap off the main actor, which is the stated purpose of this first commit. The concurrent test likewise measures the replacement. Keep the original closure implementations in the test-first commit, run the tests against them, and introduce the nonisolated callbacks in the subsequent fix commit.BLOCKING: 1
Reviewed head
e61c1bb24eat 2026-11-24T21:55:19Z by codex exec (read-only sandbox).@gerri: the test-first order is already in this PR's history, so there is nothing to change in the head. Commit
79e6d76holds the ORIGINAL closures (configure() extracted verbatim, beforeSend/beforeBreadcrumb still closures formed in the @MainActor SentryBootstrap) plus SentryBootstrapIsolationTests, and CI run 16 on exactly that commit passed: https://rasterhub.com/rasterstate/fjord-apple-kit/actions/runs/16 (Sentry 9.34, Xcode 27.2). That is the measurement of the closures shipping in 0.3.0. Commit0f85a95(run 17, passed) then replaces them with nonisolated functions, ande61c1bbonly moves code between files. The suite is proven to run by the throwaway run 18 (a deliberate XCTFail named SentryBootstrapIsolationTests.test_beforeBreadcrumbRunsOffTheMainActor and failed the build). I am not rewriting history (no force push); the PR body now lists the three runs. If you want the head itself to still measure the original closures, say so and I will add a test that builds the pre-change closures inline.@gerri: the shipped 0.3.0 closures were measured on the baseline commit
79e6d76, which keeps them unchanged: CI run 16 passed (https://rasterhub.com/rasterstate/fjord-apple-kit/actions/runs/16). Run 18 (throwaway PR #7, one deliberate XCTFail) failed naming SentryBootstrapIsolationTests.test_beforeBreadcrumbRunsOffTheMainActor, which proves the suite runs. The head's tests now guard the new nonisolated form against regression, which is their job going forward; the PR body says so. No code change.Automated Codex review (read-only) of head
e61c1bb24e.No actionable findings. The callbacks preserve the existing filtering and scrubbing paths, and the tests exercise both callbacks off the main actor. The reported run against the original closures also shows that the tests establish runtime behavior, not whether a callback is declared
nonisolated.BLOCKING: 0
Reviewed head
e61c1bb24eat 2026-11-24T22:14:45Z by codex exec (read-only sandbox).