Repository navigation
#1088 Keep one Home view model across server switches - #1089
Merged
Merged
Conversation
Home's view model was built inside AppRootHomeHost.body, so each profile switch (which re-renders the root) created another one. ProjectListHomeView kept only the first; the rest were retained by the endless live-updates task and left profile handlers on the shared coordinator. Every later switch made all of them run a full Home refresh. AppRootViewModel now owns one model for the app's life and passes it down. The live-updates loop captures self weakly, and coordinator registrations are returned as removable tokens that the model holds, so a discarded model both deallocates and stops delivering. Adds a deallocation regression test and keeps the save-counter registration in ServersSwitchTests alive for its fixture.
There was a problem hiding this comment.
Automated review: no finding that 2+ of 3 passes agreed on.
1 finding(s) from a single pass, not posted
ios/OpenCode Mobile/OpenCode Mobile/Domain/Connection/ActiveConnectionManager.swift:526medium: Registration-returning handler APIs silently drop callbacks when the token is not retained (deepseek-v4.1-flash)
opencode pr-review · passes: muse-spark-1.3-contributor, glm-5.3-flash, deepseek-v4.1-flash · $0.069 · 1 pass(es) stopped early
ivanfenenko
temporarily deployed
to
android-release
November 19, 2026 13:15 — with
GitHub Actions
Inactive
ivanfenenko
temporarily deployed
to
ios-release
November 19, 2026 13:15 — with
GitHub Actions
Inactive
ivanfenenko
temporarily deployed
to
android-release
November 19, 2026 13:15 — with
GitHub Actions
Inactive
ivanfenenko
temporarily deployed
to
ios-release
November 19, 2026 13:15 — with
GitHub Actions
Inactive
This was referenced Nov 19, 2026
ivanfenenko
added a commit
that referenced
this pull request
Nov 19, 2026
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.
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #1088.
Switching repeatedly between saved servers got slower each time because every switch built another Home view model.
AppRootHomeHost.bodycalledContainer.makeProjectListHomeViewModel()inline;ProjectListHomeViewkept only the first in its@State, and the rest were retained forever by the endlessTaskinstartObservingConnectionState()(strongselfoverliveUpdates.updates()). Each leaked model kept a live-updates subscription and leftonProfileSaved/onProfileClearedhandlers on the shared coordinator. Since a discarded model haspendingID == nil, every profile save made all of them run a fullrefresh()— probe, worktree listing, a session window per project, cache writes — on the MainActor.What changed
AppRootViewModelnow owns Home's model, creates it once on the firstenterHome(), and passes it intoAppRootHomeHost; nothing is constructed in a view body.startObservingConnectionState()capturesselfweakly over a snapshot ofliveUpdates, anddeinitcancels the task, so a discarded model cannot retain itself.ConnectionSessionCoordinatorhandler registration returns aRegistrationthat removes its handler when cancelled or released (idempotent, lock-guarded, coordinator held weakly). Home's model holds its three registrations.ServersSwitchTestsnow holds its save-counter registration for the fixture's lifetime.Evidence
Instrumented Debug build against the scenario harness, two saved servers, alternating five times:
The deallocation test fails with the strong capture restored and passes with the fix. No UI change, so there are no screenshots.
Checks
MainScreenViewModelis@HiltViewModelresolved once per Home nav entry; profile events areSharedFlows collected inviewModelScope(cancelled with the view model), not handler arrays; and live observation jobs are cancelled explicitly instopLiveObservations(). iOS now follows the same ownership model.ProjectListHomeViewModelTests,ConnectionSessionCoordinatorTests,ActiveConnectionManagerProtocolTests,ServersSwitchTestson the iOS simulator (pass).Risks
Home's model now lives for the app's life, so screen state (filters, dialogs) survives profile switches rather than resetting.
ProjectListHomeViewstill copies the injected model into its own@State; that is safe while exactly one model is created.