Skip to content

Isolate server switches on iOS and Android - #1104

Merged
ivanfenenko merged 2 commits into
mainfrom
fix/server-switch-isolation
Nov 23, 2026
Merged

ivanfenenko merged 2 commits into
mainfrom
fix/server-switch-isolation

Conversation

@ivanfenenko

@ivanfenenko ivanfenenko commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Makes a server switch one boundary on iOS and Android, so work started for one server cannot read from, write to, or paint on another.

  • Switch order: bind the new connection before live caches reload, tie loaders to the connection they started on, and keep only one current Home load.
  • Remove and Clear All: health and address checks only update existing profiles. iOS profile changes now run in order, and removing an inactive server leaves the active one running.
  • Pinned work: new-session create and first prompt, composer drafts, and delayed cache writes stay with the profile they started on.
  • Health checks: results are tied to their connection. Android v2 session calls now surface HTTP errors.
  • Speed: Home starts live data after its cached paint without waiting for the health check, saved-protocol checks return sooner, and model catalog reloads are coalesced.
  • Storage: drafts and model picks are keyed by profile id with a migration, added projects are read by profile, and the session cache keeps the 200 most recently used transcripts per profile.

Checks

  • Android: :app:assembleDebug, :hexcode:assembleDebug, and testDebugUnitTest pass (4,687 tests, 0 failed). ktlint reports only existing violations, none on changed lines.
  • iOS: OpenCode Mobile unit tests pass (3,799 Swift Testing, 126 XCTest), and xcodebuild analyze passes.
  • Hex Code iOS: 675 tests pass.
  • Regression tests cover the switch races, migrations, cache bound, and first-send recovery.
  • Not run: a device, simulator session, or live v1/v2 server.

Evidence

None yet. This changes behavior across a live server switch, so it still needs a scenario-harness pass on both platforms before it is marked ready.

Issue

No linked issue.

Risks / Follow-ups

  • Only the first send of a new session is pinned. Other in-flight mutations can still reach a newly bound server in a narrow window.
  • If a server accepts a first prompt but the switch loses its response, the draft stays and a resend can duplicate it.
  • A saved-protocol check waits up to 750 ms for /global/health. A slower server that changed protocol is corrected by the next full detection.
  • Worktree inventory stays keyed by URL on Android because it is cleared on every switch.
  • Frame timing was not measured, so the responsiveness gain is unconfirmed. SSE event filtering was deliberately left out until it is.
  • Package.resolved on main is stale, and local iOS builds rewrite it. That change is not included here.

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

Bind the new connection before live caches reload, tie loads, sends, drafts and cache writes to their profile, protect profile removal, and stop Home waiting on the health check.
@ivanfenenko
ivanfenenko marked this pull request as ready for review November 23, 2026 07:34

@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 2 passes agreed on.

4 finding(s) from a single pass, not posted
  • android/app/src/main/java/dev/opencode/mobile/data/local/sessioncache/SessionCacheDao.kt:166 medium: Transcript trim counts empty placeholder rows (muse-spark-1.3-contributor)
  • android/app/src/main/java/dev/opencode/mobile/domain/connection/ConnectionSessionCoordinator.kt:283 medium: SSE rebuild closes a new server client opened in the gap (muse-spark-1.3-contributor)
  • ios/OpenCode Mobile/OpenCode Mobile/Domain/Connection/ActiveConnectionManager.swift:65 medium: Pinned iOS capabilities drop v2 features (muse-spark-1.3-contributor)
  • android/app/src/main/java/dev/opencode/mobile/data/local/DataStoreComposerDraftStore.kt:85 medium: saveDetached cleanup drops an equal queued detached save, losing the draft write (glm-5.3-flash)

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

A wake was broadcast with no replay, so one arriving after the retry
loop checked for it but before it subscribed was dropped. The stream
then sat out the full auth backoff instead of reconnecting, which also
made DefaultForegroundEventStreamTest fail intermittently.

Count wakes instead, so the wait sees any wake newer than the attempt.
@ivanfenenko
ivanfenenko added this pull request to the merge queue Nov 23, 2026
Merged via the queue into main with commit 556a255 Nov 23, 2026
@ivanfenenko
ivanfenenko deleted the fix/server-switch-isolation branch November 23, 2026 09:20
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