Skip to content

Keep Server Health off the main thread while it opens - #1055

Merged
ivanfenenko merged 1 commit into
mainfrom
fix/1053-server-health-page-stalls-while-opening
Nov 15, 2026
Merged

ivanfenenko merged 1 commit into
mainfrom
fix/1053-server-health-page-stalls-while-opening

Conversation

@ivanfenenko

@ivanfenenko ivanfenenko commented Nov 15, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

#1053: opening Server Health (Servers > active profile > Details) stalled mid-transition.

On a Pixel 9, a Perfetto trace of one tap on Details showed:

  • the main thread asleep on keystore2 binder calls for about 115 ms right after the push started, so no transition frames were drawn;
  • then a 46 ms frame when the report appeared;
  • then a second Keystore burst.

Android

  • DataStoreConnectionProfileStore runs its Keystore decrypts, writes and deletes on Dispatchers.IO. Every caller that loaded profiles on viewModelScope was paying this on Main.
  • New ConnectionProfileStore.catalogWithoutPasswords(). Server Health uses it because it only shows the name, protocol and active id.
  • ServerHealthViewModel reads the week of pings and builds the report on Dispatchers.Default. A live-status change now only updates the live fields instead of rebuilding the whole report on Main.
  • ServersViewModel loads the quick view off Main.

iOS

  • Opening Server Health doesn't touch the Keychain: the route carries the name and protocol. But the 7-day SwiftData fetch and the report build ran on the MainActor, because under approachable concurrency the store's nonisolated async methods run on the caller's actor.
  • ServerHealthViewModel and the Servers quick view now fetch and build in @concurrent functions. A range picked while a report is building still wins.

The wider audit of main-thread reads on both platforms is in #1054.

Checks

  • iOS and Android both covered
  • No UI change: same screens, same content
  • Tests run:
    • Android: :app:testDebugUnitTest and :opencode-kit:testDebugUnitTest, 3688 tests passing, plus a new test that fails if Server Health decrypts passwords.
    • iOS: ServerHealthViewModelTests, 8 tests passing on the simulator.
  • ktlint is clean on the changed files

Risks / Follow-ups

  • Not yet measured on a device after the change. The installed build is release-signed, so a local build can't replace it without wiping the saved profiles. Measuring needs a signed build (App Distribution from this head).
  • The report still appears a frame or two into the transition, now without the Keystore stall. If the remaining layout frame still shows, the next step is a placeholder at the final height or a lazy list.
  • Other screens still decrypt passwords they don't need (Home chrome, Settings summary). That now happens off Main and is tracked in Keep storage and Keychain reads off the main thread #1054.

🤖 Generated with Claude Code


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.


Note

Medium Risk
Touches connection profile loading and Keystore I/O threading; behavior should be unchanged but credential paths are security-sensitive and report timing/race handling shifted.

Overview
Fixes janky navigation when opening Server Health by moving expensive work off the UI thread on Android and iOS, without changing what the screens show.

On Android, Keystore password decrypts in DataStoreConnectionProfileStore now run on Dispatchers.IO, and a real catalogWithoutPasswords() path lets Server Health load profile name/protocol without decrypting. Server Health and the Servers quick view fetch up to a week (or a day) of pings and build reports on Dispatchers.Default, with pre-built BuiltHealth applied in publish so live updates don’t rebuild the full report on Main.

On iOS, seven-day store reads and report building run in @concurrent helpers from ServerHealthViewModel and the Servers quick view, with guards so a newer range selection wins if the user changes range mid-build.

Tests pin workDispatcher to the test scheduler and add coverage that Server Health binding never calls password-decrypting store APIs.

Reviewed by Cursor Bugbot for commit 11fec85. Bugbot is set up for automated code reviews on this repo. Configure here.

Android: opening Server Health decrypted every saved password through
Android Keystore on Main (binder calls to keystore2), freezing the push
transition for about 115 ms on a Pixel 9. The profile store now runs its
Keystore reads and writes on Dispatchers.IO, and Server Health reads the
profile catalog without passwords. Its week of pings and the report build
on Dispatchers.Default, and live status no longer rebuilds the report.
The Servers quick view loads off Main too.

iOS: the 7-day SwiftData fetch and report build ran on the MainActor
because the store's nonisolated async methods inherit the caller's actor.
Server Health and the Servers quick view now fetch and build in
@Concurrent functions.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ivanfenenko
ivanfenenko marked this pull request as ready for review November 15, 2026 21:40
@ivanfenenko

Copy link
Copy Markdown
Collaborator Author

@cursor review

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 11fec85. Configure here.

@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: 2 finding(s) that 2+ of 3 passes agreed on.

Outside the diff lines:

  • ios/OpenCode Mobile/OpenCode Mobile/UI/ServerHealth/ServerHealthViewModel.swift:143 low: Concurrent rebuilds with the same range can apply out of order
2 finding(s) from a single pass, not posted
  • android/opencode-kit/src/main/java/dev/opencode/mobile/data/local/DataStoreConnectionProfileStore.kt:60 high: saveProfile rollback can wipe a concurrent save (muse-spark-1.3-contributor)
  • android/app/src/main/java/dev/opencode/mobile/ui/serverhealth/ServerHealthViewModel.kt:141 medium: Stale range report overwrites the newly selected range (muse-spark-1.3-contributor)

opencode pr-review · passes: muse-spark-1.3-contributor, glm-5.3-flash, deepseek-v4.1-flash · $0.090

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