Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/src/main/kotlin/ai/opencode/app/AppFeature.kt
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,10 @@ class AppFeature : Reducer<AppFeature.State, AppFeature.Action> {

private fun homeDelegate(state: State, action: HomeFeature.DelegateAction): Reduced<State, Action> = when (action) {
is HomeFeature.DelegateAction.ServerSwitchTapped -> switchServer(action.server, state)
is HomeFeature.DelegateAction.SessionOnServerTapped -> {
val pending = NotificationDestination(serverKey = action.server.persistenceID, sessionID = action.sessionID)
switchServer(action.server, state.copy(pendingNotification = pending), preservingPending = true)
}
is HomeFeature.DelegateAction.ServerRenamed -> Reduced(renameServer(action.server, action.name, state))
is HomeFeature.DelegateAction.EditServerRequested -> Reduced(editServer(action.server, state))
is HomeFeature.DelegateAction.ServerRemovalConfirmed -> Reduced(state, confirmRemoval(action.server, state))
Expand Down
9 changes: 7 additions & 2 deletions app/src/main/kotlin/ai/opencode/app/AppFeatureServerFlow.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ import kotlin.time.Duration.Companion.seconds
// A switch from the drawer keeps the Home it left, and goes back to it if the server fails or
// doesn't answer in [ServerFlowTunables.timeout].

internal fun AppFeature.switchServer(server: OpenCodeServer, state: AppFeature.State): Reduced<AppFeature.State, AppFeature.Action> {
internal fun AppFeature.switchServer(
server: OpenCodeServer,
state: AppFeature.State,
preservingPending: Boolean = false,
): Reduced<AppFeature.State, AppFeature.Action> {
val home = state.home ?: return Reduced(state)
var next = state.copy(home = home.copy(serverSwitchNote = null))
// Picking the server in use while another connects turns back.
Expand All @@ -29,7 +33,7 @@ internal fun AppFeature.switchServer(server: OpenCodeServer, state: AppFeature.S
next = next.copy(returnServer = home.server)
val keepsHome = next.keepsHome(switchingTo = server)
if (keepsHome) next = next.showingSwitch(server)
val connecting = selectServer(server, next, keepingHome = keepsHome)
val connecting = selectServer(server, next, preservingPending = preservingPending, keepingHome = keepsHome)
val attempt = connecting.state.connectionAttempt
if (!keepsHome || attempt == null) return connecting
val clock = dependency(Clock)
Expand Down Expand Up @@ -71,6 +75,7 @@ internal fun switchBack(state: AppFeature.State, reason: ServerSwitchNote.Reason
connectionAttempt = null,
connection = AppFeature.State.Connection.Connected,
returnServer = null,
pendingNotification = state.pendingNotification?.takeIf { it.serverKey != target.persistenceID },
).load(home.server)
// The target's health check remembered it as the server to reopen.
if (next.savedServer.value?.persistenceID != home.server.persistenceID) next.savedServer.set(home.server)
Expand Down
16 changes: 16 additions & 0 deletions app/src/test/kotlin/ai/opencode/app/ServerFlowTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import ai.opencode.feature.drawer.ServerMenuStatus
import ai.opencode.feature.drawer.ServerReachability
import ai.opencode.feature.drawer.ServerSwitchNote
import ai.opencode.feature.session.ServerFlowTunables
import ai.opencode.feature.system.NotificationDestination
import ai.opencode.server.CachedHomeSnapshot
import ai.opencode.server.OpenCodeClient
import ai.opencode.server.OpenCodeClientError
Expand Down Expand Up @@ -141,6 +142,21 @@ class ServerFlowTests {
store.finish()
}

@Test
fun aSessionOnAnotherServerWaitsForTheSwitchAndIsForgottenWhenItGoesBack() = runTest {
val clock = TestClock()
val store = store(connectedState(), clock = clock) { it.copy(health = { awaitCancellation() }) }
val pending = NotificationDestination(serverKey = studio.persistenceID, sessionID = "ses_studio")
store.send(delegate(HomeFeature.DelegateAction.SessionOnServerTapped(studio, "ses_studio"))) {
switching(it).copy(pendingNotification = pending)
}
clock.advance(ServerFlowTunables.timeout.seconds)
store.receiveCase<AppFeature.Action.ServerSwitchTimedOut> {
switchedBack(it, ServerSwitchNote.Reason.TimedOut(ServerFlowTunables.timeout)).copy(pendingNotification = null)
}
store.finish()
}

@Test
fun anUnreachableServerGoesBackAndIsMarkedInTheMenu() = runTest {
val store = store(connectedState()) { it.copy(health = { throw OpenCodeClientError("Offline") }) }
Expand Down
3 changes: 3 additions & 0 deletions core/src/main/kotlin/ai/opencode/core/sharing/SharedKeys.kt
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ object SharedKeys {
val sessionListShowsOpen = SharedKey.appStorage("session-list-shows-open", true)

val sessionListGrouping = SharedKey.appStorage("session-list-grouping", SessionListGrouping.None)

/** The saved servers (by `persistenceID`) whose sessions the drawer leaves out while another is in use. */
val sessionListHiddenServerIDs = SharedKey.appStorage<Set<String>>("session-list-hidden-servers", emptySet())
}

/** How the drawer groups the sessions under Pinned and Open. */
Expand Down
2 changes: 1 addition & 1 deletion docs/parity/core.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Status values: `todo`, `partial: <what is missing>`, `done`, `n/a: <reason and w
| `OpenCode/Core/ScrollsToTop.swift` | 31 | | n/a: Android has no status-bar tap that scrolls a list to the top, so there is nothing for a covered surface to hand on | |
| `OpenCode/Core/ServerID.swift` | 75 | see server.md | — | ported into `:server` |
| `OpenCode/Core/ServerIDClient.swift` | 55 | see server.md | — | ported into `:server` |
| `OpenCode/Core/SharedKeys.swift` | 978 | `core/.../sharing/SharedKeys.kt`, `core/.../sharing/InstallHistory.kt`, `server/.../ServerSharedKeys.kt`, `feature/voice/.../VoiceSharedKeys.kt`, `feature/transcript/.../SessionSeenWatermarks.kt` | done | primitive keys in `:core`; server-typed keys + `CachedHomeSnapshot`/`CachedTranscriptSnapshots`/`TranscriptCachePersistence` in `:server`; voice-typed keys in `:feature:voice`. Same ids and defaults. `remember` marks `installHistory` `.paired` (b13208e9); `InstallHistory` (iOS `AppFeature+Migrations.swift`) moved down to `:core` (`sharing/InstallHistory.kt`) so `:server`'s `remember` can write it, see app.md. Sync f657969b (drawer): `sessionSeenWatermarks` (`session-seen-watermarks.json`) with `SessionSeenWatermark`/`SessionSeenWatermarks` (64 entries, LRU) lives in `:feature:transcript` `SessionSeenWatermarks.kt`, because it compares IDs through `TranscriptTimeStamps.isBefore` Sync 3cea48b2 (9c94975e): `remember` keeps the saved entry's address order (`keepingAddressOrder` of the entry with the same `persistenceID`) and writes that entry; snapshots no longer call it. Sync 440b77f0 (f956e020): `serverVoiceProvider` doc (in `VoiceSharedKeys.kt`) now names the provider a server brokers calls on, no experiment. Sync 03adf07a (24057173): iOS writes `cachedHomeSnapshots` and `sessionReadDates` on a background writer (newest value, within 500 ms) and loads read the waiting value. Android's file keys already wrote on `LiveSharedBytes`' own thread; now `SharedReference.update` hands the encoding there too (`SharedBytes.writeEncoded`), only the newest waiting value is written, and a read returns it first. Going to the background flushes (`HomeFeatureConnection`). 31ccbb9e: `appLeftAt` (AppStorage `app-left-at`, an ISO instant or null). Android only: `dictation` (AppStorage `dictation`, on by default) for Settings › Sessions › Dictation. Android only, for the `sessionList` experiment: `openSessionKeys` (`open-sessions.json`, keyed as pins, last opened first), `sessionListShowsOpen` (AppStorage `session-list-shows-open`, on by default) and `sessionListGrouping` (AppStorage `session-list-grouping`, `SessionListGrouping` none / date / project). |
| `OpenCode/Core/SharedKeys.swift` | 978 | `core/.../sharing/SharedKeys.kt`, `core/.../sharing/InstallHistory.kt`, `server/.../ServerSharedKeys.kt`, `feature/voice/.../VoiceSharedKeys.kt`, `feature/transcript/.../SessionSeenWatermarks.kt` | done | primitive keys in `:core`; server-typed keys + `CachedHomeSnapshot`/`CachedTranscriptSnapshots`/`TranscriptCachePersistence` in `:server`; voice-typed keys in `:feature:voice`. Same ids and defaults. `remember` marks `installHistory` `.paired` (b13208e9); `InstallHistory` (iOS `AppFeature+Migrations.swift`) moved down to `:core` (`sharing/InstallHistory.kt`) so `:server`'s `remember` can write it, see app.md. Sync f657969b (drawer): `sessionSeenWatermarks` (`session-seen-watermarks.json`) with `SessionSeenWatermark`/`SessionSeenWatermarks` (64 entries, LRU) lives in `:feature:transcript` `SessionSeenWatermarks.kt`, because it compares IDs through `TranscriptTimeStamps.isBefore` Sync 3cea48b2 (9c94975e): `remember` keeps the saved entry's address order (`keepingAddressOrder` of the entry with the same `persistenceID`) and writes that entry; snapshots no longer call it. Sync 440b77f0 (f956e020): `serverVoiceProvider` doc (in `VoiceSharedKeys.kt`) now names the provider a server brokers calls on, no experiment. Sync 03adf07a (24057173): iOS writes `cachedHomeSnapshots` and `sessionReadDates` on a background writer (newest value, within 500 ms) and loads read the waiting value. Android's file keys already wrote on `LiveSharedBytes`' own thread; now `SharedReference.update` hands the encoding there too (`SharedBytes.writeEncoded`), only the newest waiting value is written, and a read returns it first. Going to the background flushes (`HomeFeatureConnection`). 31ccbb9e: `appLeftAt` (AppStorage `app-left-at`, an ISO instant or null). Android only: `dictation` (AppStorage `dictation`, on by default) for Settings › Sessions › Dictation. Android only, for the `sessionList` experiment: `openSessionKeys` (`open-sessions.json`, keyed as pins, last opened first), `sessionListShowsOpen` (AppStorage `session-list-shows-open`, on by default) and `sessionListGrouping` (AppStorage `session-list-grouping`, `SessionListGrouping` none / date / project) and `sessionListHiddenServerIDs` (AppStorage `session-list-hidden-servers`, the saved servers left out of the list; empty by default). |
| `OpenCode/Core/SoundEffectsClient.swift` | 135 | `core/.../sound/SoundEffectsClient.kt` | done | `SoundEffect` (priorities), `SoundEffectsClient` key (inert test value), `SharedKeys.soundEffectsVolume`/`soundEffectsSend` (same ids and defaults), `SoundEffectThrottle` (1 s, on `Clock.now()`), `SoundEffectOutput`, `LiveSoundEffects` (volume clamp, throttle, `LabMarks` mark) |
| `OpenCode/Core/SoundEffectsPlayback.swift` | 259 | `core/.../sound/SoundEffectsPlayback.kt`, `core/src/main/res/raw/sound_effect_*.wav` | done | Same state machine (eligibility checked once under the owner's lock, stop reasons, finish ids). `AudioSessionIdleState` is the owner's borrow surface in `:core` (the owner is in `:feature:voice`); `:app`'s `AppDependencies` installs voice's `AudioSessionOwner` behind it at the root (iOS `AudioSessionOwner.shared`); its own live value, a fallback, reads `AudioManager.mode` (idle = `MODE_NORMAL`). Notifications → `SoundEffectsEvent`s from `ProcessLifecycleOwner` (resume/pause/stop), `AudioDeviceCallback` (route) and the audio mode listener (a call interrupts). Players: one prepared `MediaPlayer` per sound, media usage with sonification content so cues follow media rather than ring volume (FB-05), no audio focus (`.ambient` mixes); `activate` refuses unless the ringer is normal (the silent switch). The sounds are bit-exact WAVs of iOS's CAFs. Plays on emulators (iOS silences simulators) |
| `OpenCode/Core/TapTarget.swift` | 53 | see core-ui.md | — | Sync ae029f85 (86ca6803, 6a173ff1): see core-ui.md. |
Expand Down
Loading
Loading