Skip to content

#1088 Harden coordinator handler registrations - #1090

Merged
ivanfenenko merged 1 commit into
mainfrom
fix/1088-registration-hardening
Nov 19, 2026
Merged

ivanfenenko merged 1 commit into
mainfrom
fix/1088-registration-hardening

Conversation

@ivanfenenko

@ivanfenenko ivanfenenko commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Follow-up to #1089, from an independent review. #1088 stays closed; this hardens what landed.

What changed

  • Swift 6 readiness, without moving work off the main thread. Registration and registration(removing:) are nonisolated, and the lock-guarded handler arrays are nonisolated(unsafe), so a released token can remove its entry from any thread. ConnectionSessionCoordinator itself stays MainActor-inferred: an earlier draft marked the whole class nonisolated and an independent review caught that this moved profile-change work, handler delivery and ActiveConnectionManager calls onto the gate's background executor. The shape here typechecks under both -swift-version 5 and -swift-version 6 with -default-isolation MainActor.
  • Main-thread regression test. profileSavesDeliverHandlersOnTheMainActor asserts with MainActor.assertIsolated() inside a saved handler. It fails with the broad nonisolated variant and passes with this one.
  • No handler destruction under the lock. A registration moves removed handlers into a local and releases them after unlocking, so a handler whose deinit cancels another registration cannot re-enter the coordinator's non-recursive NSLock.
  • Root ownership test. AppRootHomeOwnershipTests proves enterHome() and a profile save reuse the same Home model; this is the invariant #1088 Keep one Home view model across server switches #1089 introduced and nothing covered it. It waits on the real enterHome → onForeground → startIfConnected → hasActiveConnection signal, not a sleep.
  • Cleanup. Removed the now-unused Container.makeProjectListHomeViewModel() (the last way to build a Home model in a body) and the 200 ms sleep in the deallocation test.

Checks

  • iOS and Android both covered, or the reason one is not — iOS only; Android's Hilt-scoped Home view model and SharedFlow collectors have no equivalent registration lifetime.
  • Screenshots for UI changes — no visual change.
  • Tests run — ConnectionSessionCoordinatorTests, ProjectListHomeViewModelTests, AppRootHomeOwnershipTests, ActiveConnectionManagerProtocolTests, ServersSwitchTests on the iOS simulator (pass), plus the Swift 5/Swift 6 isolation typechecks.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review: no finding that 2+ of 3 passes agreed on.

opencode pr-review · passes: muse-spark-1.3-contributor, glm-5.3-flash, deepseek-v4.1-flash · $0.081 · 1 pass(es) stopped early

Follow-up to #1089, from an independent review.

- Handler removal releases the removed closures after the coordinator
  lock, so a handler whose deinit cancels another registration cannot
  deadlock.
- The registration token is nonisolated and removes entries from the
  lock-guarded handler storage, but the coordinator itself stays
  MainActor-inferred: profile-change work and handler delivery must stay
  on the main thread. A new test asserts a saved handler runs isolated
  to MainActor.
- Add a test that a profile save reuses the root's Home model; it is the
  invariant #1089 introduced and nothing covered it.
- Drop the unused Container.makeProjectListHomeViewModel factory and the
  200 ms sleep in the deallocation test.
@ivanfenenko
ivanfenenko force-pushed the fix/1088-registration-hardening branch from b5915b8 to 62207f2 Compare November 19, 2026 15:20
@ivanfenenko
ivanfenenko added this pull request to the merge queue Nov 19, 2026
Merged via the queue into main with commit 9ca48af Nov 19, 2026
@ivanfenenko
ivanfenenko deleted the fix/1088-registration-hardening branch November 19, 2026 15: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.

1 participant