Repository navigation
Description
New fatal crash on the newest iOS build with sessions, 1.0.1 (34). It first appeared on 2026-10-19.
Crashlytics c093ceab5d92f7775252cc49bcf001c6: NSGenericException: Task created in a session that has been invalidated at closure #2 in EventsAPIClient.streamEvents(connection:path:directory:connectBudget:sessionToken:onHTTPResponse:onActivity:onDataLine:) (EventsAPIClient.swift:195 in build 34). That line is let (bytes, response) = try await session.bytes(for: request) inside bytesTask. On main it is line 202.
- Events: 1 event, 1 user (90d), all on 1.0.1 (34); last event 2026-10-19 12:04 CEST
- Device: iPhone17,1 (iPhone 16 Pro), iOS 26.6.1, foreground
- Stack (truncated):
-[__NSURLSessionLocal taskForClassInfo:]->objc_exception_throw->std::__terminate-> Kotlin/Crashlytics terminate handlers. This is an Objective-C exception, so Swifttry/catchcan't catch it.
Likely cause: streamEvents gets its URLSession from openStreamingSession(token:) and then starts session.bytes(for:) later, in a detached Task. That session can already be invalidated when the task is created:
openStreamingSessioncallsinvalidateAndCancel()on the new session whentoken < retiredBeforebut still returns it.installFreshStreamingSession/retireStreamingSession(ordeinit) can runinvalidateAndCancel()on owned dials betweenopenStreamingSessionand thebytesTaskbody, for example on token rotation or stall recovery (Reconnect without restarting when live updates stall #701/#701 Drop the stale REST pool when live updates stall #703).
Creating a task on an invalidated URLSession raises NSGenericException and kills the process. The code is unchanged on main @ 7ad92e7 (#703 only added onConnectBudgetExceeded), so iOS release 35 has it too.
Outcome: SSE dials never start a task on an invalidated URLSession. A retired or rejected dial ends as a normal transport/cancel outcome instead of crashing.
Remaining:
- Don't return an invalidated session from
openStreamingSession: throw, or returnnil, when the token is rejected - Hold the dial lease, or re-check that it is still owned under
sessionLock, beforesession.bytes(for:), and map a retired session toCancellationError/.transport - Add a test that retires the streaming session between open and dial
Crashlytics: c093ceab5d92f7775252cc49bcf001c6
Activity
#745 Never create an SSE task on an invalidated URLSession (#747)
ivanfenenko commentedon Oct 21, 2026
Crashlytics triage, 2026-10-21: the fix PR #747 (DialLease, never start an SSE task on an invalidated URLSession, merge commit 0485c17) was merged on 2026-10-20 at 11:27 CEST.
c093ceab5d92f7775252cc49bcf001c6is still at 1 event / 1 user on 1.0.1 (34). It has 0 events on 1.1.0 (35), but 35 only has 29 sessions so far.EventsAPIClient.swift. The same exception now also crashes inWorktreesAPIClient.data(for:)on 1.1.0 (35), which iOS crash: NSGenericException "Task created in a session that has been invalidated" (WorktreesAPIClient / EventsAPIClient) #777 tracks (Crashlytics3bf8d36d). That needs its own fix.Console: https://console.firebase.google.com/project/opencode-mobile-release/crashlytics/app/ios:dev.opencode.mobile/issues/c093ceab5d92f7775252cc49bcf001c6
ivanfenenko commentedon Oct 26, 2026
Crashlytics triage, 2026-10-26: the #747 fix (
0485c17f57) now ships in iOS Release run 36 (f083701be5, 2026-10-25 22:28 CET, https://github.com/opencode-mobile/opencode-mobile/actions/runs/40235676062).c093ceabhas had no new events since the last check. Crashlytics shows no sessions for build 36 yet, so closure is still unconfirmed. Earliest confirmation is around 2026-11-02, if build 36 has ~50+ sessions and 0 events by then.