Sentry callbacks off the main actor: test first, then make them nonisolated (CLS-1474) #6

Merged
stephen merged 3 commits from cls-1474-sentry-closures into main 2026-11-24 22:42:14 +00:00
Owner

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:

  1. 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.
  2. 0f85a95: beforeSend and beforeBreadcrumb become nonisolated static functions assigned by reference; initialScope and configureProfiling are @Sendable closures.
  3. 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):

  • Run 16 (79e6d76, original closures): tests pass, so the callbacks shipping in 0.3.0 do not trap off the main actor.
  • Run 17 (0f85a95, nonisolated): tests pass.
  • Run 18 (throwaway PR #7, closed): one deliberate XCTFail inside the suite failed the build naming SentryBootstrapIsolationTests.test_beforeBreadcrumbRunsOffTheMainActor, so the suite runs in CI.

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.

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: 1. 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. 2. 0f85a95: beforeSend and beforeBreadcrumb become nonisolated static functions assigned by reference; initialScope and configureProfiling are @Sendable closures. 3. 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): - Run 16 (79e6d76, original closures): tests pass, so the callbacks shipping in 0.3.0 do not trap off the main actor. - Run 17 (0f85a95, nonisolated): tests pass. - Run 18 (throwaway PR #7, closed): one deliberate XCTFail inside the suite failed the build naming SentryBootstrapIsolationTests.test_beforeBreadcrumbRunsOffTheMainActor, so the suite runs in CI. 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.
Start the Sentry options from configure(), and test beforeSend and beforeBreadcrumb off the main actor (CLS-1474)
All checks were successful
CI / Build and test (iOS Simulator) (pull_request) Successful in 2m37s
CI / Icon usage lists (pull_request) Successful in 7s
79e6d7631e
SentryBootstrap is main-actor isolated and sets both callbacks inside start(). The SDK calls them from its
own queues. The options now come from configure(), unchanged, and three tests call the callbacks the way the
SDK does: from a background queue and from twenty at once.
gerri approved these changes 2026-11-24 21:22:28 +00:00
Dismissed
gerri left a comment

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 79e6d7631e at 2026-11-24T21:22:27Z by codex exec (read-only sandbox).

Automated Codex review (read-only) of head 79e6d7631eacd7f273d285b21542a3e9a7c33e10. 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 79e6d7631eacd7f273d285b21542a3e9a7c33e10 at 2026-11-24T21:22:27Z by codex exec (read-only sandbox).
Make the Sentry callbacks nonisolated functions and the scope closures @Sendable (CLS-1474)
All checks were successful
CI / Build and test (iOS Simulator) (pull_request) Successful in 1m29s
CI / Icon usage lists (pull_request) Successful in 7s
0f85a95779
beforeSend and beforeBreadcrumb were closures formed inside the main-actor SentryBootstrap and called by the SDK on
its own queues. They are now nonisolated static functions of their input, assigned by reference; initialScope and
configureProfiling are explicitly @Sendable. Behaviour is unchanged; the isolation tests from the first commit
pass before and after.
gerri requested changes 2026-11-24 21:44:15 +00:00
Dismissed
gerri left a comment

Automated Codex review (read-only) of head 0f85a95779.

  • Medium SentryBootstrap.swift:47: The invariant is that a handwritten source file already over 200 lines must not grow. This change increases the file from 365 to 384 lines, contrary to the fleet source-size standard. The extraction and callback functions belong in a separate responsibility-focused file. This affects the PR directly, although this checkout does not contain the source-size checker to confirm a CI failure.

BLOCKING: 1

Reviewed head 0f85a95779 at 2026-11-24T21:44:15Z by codex exec (read-only sandbox).

Automated Codex review (read-only) of head 0f85a957797552b646d4b1367095a2f6b9e21423. - **Medium** [SentryBootstrap.swift:47](/home/dev/work/reviews/rasterstate-fjord-apple-kit-6/Sources/FjordObservability/SentryBootstrap.swift:47): The invariant is that a handwritten source file already over 200 lines must not grow. This change increases the file from 365 to 384 lines, contrary to the fleet source-size standard. The extraction and callback functions belong in a separate responsibility-focused file. This affects the PR directly, although this checkout does not contain the source-size checker to confirm a CI failure. BLOCKING: 1 --- Reviewed head 0f85a957797552b646d4b1367095a2f6b9e21423 at 2026-11-24T21:44:15Z by codex exec (read-only sandbox).
Author
Owner

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.

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.
Author
Owner

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

@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.
Move the Sentry options and callbacks into their own file so SentryBootstrap.swift shrinks (CLS-1474)
All checks were successful
CI / Build and test (iOS Simulator) (pull_request) Successful in 1m29s
CI / Icon usage lists (pull_request) Successful in 7s
e61c1bb24e
gerri: SentryBootstrap.swift was over 200 lines and grew from 365 to 384. configure(), filteredEvent and
scrubbedBreadcrumb now live in SentryBootstrap+Options.swift; SentryBootstrap.swift is 288 lines. No behaviour change.
gerri requested changes 2026-11-24 21:55:20 +00:00
Dismissed
gerri left a comment

Automated Codex review (read-only) of head e61c1bb24e.

  • Medium. SentryBootstrap+Options.swift:79. Invariant: a test must exercise the behavior it claims to measure. Both callbacks are already replaced with nonisolated functions 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 e61c1bb24e at 2026-11-24T21:55:19Z by codex exec (read-only sandbox).

Automated Codex review (read-only) of head e61c1bb24e87de585956f71139adde2447fec468. - **Medium**. [SentryBootstrap+Options.swift:79](/home/dev/work/reviews/rasterstate-fjord-apple-kit-6/Sources/FjordObservability/SentryBootstrap+Options.swift:79). **Invariant: a test must exercise the behavior it claims to measure.** Both callbacks are already replaced with `nonisolated` functions 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 e61c1bb24e87de585956f71139adde2447fec468 at 2026-11-24T21:55:19Z by codex exec (read-only sandbox).
Author
Owner

@gerri: the test-first order is already in this PR's history, so there is nothing to change in the head. Commit 79e6d76 holds 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. Commit 0f85a95 (run 17, passed) then replaces them with nonisolated functions, and e61c1bb only 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 test-first order is already in this PR's history, so there is nothing to change in the head. Commit 79e6d76 holds 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. Commit 0f85a95 (run 17, passed) then replaces them with nonisolated functions, and e61c1bb only 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.
Author
Owner

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

@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.
gerri approved these changes 2026-11-24 22:14:46 +00:00
gerri left a comment

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 e61c1bb24e at 2026-11-24T22:14:45Z by codex exec (read-only sandbox).

Automated Codex review (read-only) of head e61c1bb24e87de585956f71139adde2447fec468. 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 e61c1bb24e87de585956f71139adde2447fec468 at 2026-11-24T22:14:45Z by codex exec (read-only sandbox).
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
rasterstate/fjord-apple-kit!6
No description provided.