Open source Grok Bot alternative, Bring your own agent and subscription: message Claude Code, Codex, Gemini CLI, Cursor, Copilot and 40+ AI agents as bots on your own computer, from iPhone, Mac, Windows, Linux or terminal. Agent-agnostic and free. Also a Muse and Dots alternative. Built in Rust.
Rust acpagent-client-protocolai-agentsai-assistantclaudeclaude-codecodexcoding-agentscursorgeminigemini-cligrok-bot-alternativeiosiphonelinuxmacosmcpopen-sourcerustself-hosted
fix(ios): keep voice calls connected in background
leepokai6f72eaf7e68f
diff --git a/docs/features/voice-call.md b/docs/features/voice-call.mdindex 91b45fb9..db05c578 100644--- a/docs/features/voice-call.md+++ b/docs/features/voice-call.md@@ -22,8 +22,51 @@ The bot is the same agent on the computer; the call only changes how you talk toevery client shows as "Voice chat · 00:16".- The host receives recognized text; the Cloudflare transport sees encrypted channel frames.Codync does not forward microphone audio to the host. Speech recognition may use Apple services- when on-device recognition is unavailable. `UIBackgroundModes: audio` keeps the call alive with- the screen locked.+ when on-device recognition is unavailable. `UIBackgroundModes: audio` permits+ background microphone capture and speech playback during an active call.+- While a call is listening or speaking, it retains the computer's transport across+ foreground/background transitions. Ending or failing the last call releases that+ connection when backgrounded, restoring normal push delivery. Removing the computer+ or switching accounts ends its calls and closes the transport.+- Final replies and approval notices are delivered from the store's incoming events+ directly to the audio session, rather than waiting for a SwiftUI view update.+ Replayed final replies, other bots and thread replies are not read into this call.++## Background verification++Store regression tests cover sending a recognized utterance after backgrounding,+delivering a final reply without view updates, returning to the foreground without+restarting an active call's connection, ending the last call, and retiring the+store. They do not simulate iOS audio or background scheduling.++On a physical iPhone, start a voice call with a connected bot, return to the Home+Screen, then speak a request. Verify that it sends successfully and the reply is+read aloud while Codync remains backgrounded. Also start a long reply in Codync,+return Home during playback, and verify that speech continues. End the call and+confirm that ordinary background notification behavior resumes. For App Review,+the recording must capture both the physical device and the audible reply.++## App Review recording++The 2.2.1 (22) review requested a screen recording on a **physical device** for+Guideline 2.5.4. Record these steps using a connected computer and a bot:++1. Open its conversation and tap the waveform button with an empty composer.+2. Allow microphone and Speech Recognition access. Speak a short request and+ show the recognized message and the bot's spoken reply.+3. While a long reply is being read, return to the Home Screen. Keep recording+ long enough to demonstrate audible playback continuing in the background.+4. Return to Codync and end the call.++Ensure the resulting file contains the audible reply. If the screen recorder+cannot capture the call audio, record the physical phone externally with another+device so both its screen and speaker are audible. Include the recording and+these navigation steps in App Review Information for future submissions.++Simulator recordings are useful for UI checks but are not the physical-device+evidence Apple requested. A `simctl io ... recordVideo` probe on 2026-09-30+produced an H.264 video track with no audio track. Transport regression tests+verify background reply delivery and retirement, not iOS audio behavior.## Design: realtime voice with your own key (not implemented)diff --git a/kit/Sources/CodyncUI/Call/CallSession.swift b/kit/Sources/CodyncUI/Call/CallSession.swiftindex 013ac31f..7cc454e7 100644--- a/kit/Sources/CodyncUI/Call/CallSession.swift+++ b/kit/Sources/CodyncUI/Call/CallSession.swift@@ -19,7 +19,11 @@ final class CallSession {case failed(String)}- private(set) var phase: Phase = .starting+ private(set) var phase: Phase = .starting {+ didSet { onActivityChanged?(!ended && (phase == .listening || phase == .speaking)) }+ }+ /// Keep the transport attached while audio is active, even without a visible UI update.+ @ObservationIgnored var onActivityChanged: ((Bool) -> Void)?/// What you're saying right now (live caption).private(set) var heard = ""/// The reply being read aloud.@@ -72,6 +76,7 @@ final class CallSession {guard let recognizer, recognizer.isAvailable else {return fail("Speech recognition isn't available for this language right now.")}+ guard !ended else { return }do {let audio = AVAudioSession.sharedInstance()try audio.setCategory(.playAndRecord, mode: .voiceChat, options: [.defaultToSpeaker, .allowBluetoothHFP])@@ -79,12 +84,12 @@ final class CallSession {} catch {return fail("Couldn't start audio: \(error.localizedDescription)")}- guard !ended else { return }listen()}func end() {ended = true+ onActivityChanged?(false)stopListening()synthesizer.stopSpeaking(at: .immediate)try? AVAudioSession.sharedInstance().setActive(false, options: .notifyOthersOnDeactivation)diff --git a/kit/Sources/CodyncUI/Call/CallView.swift b/kit/Sources/CodyncUI/Call/CallView.swiftindex 9fcce615..5616f807 100644--- a/kit/Sources/CodyncUI/Call/CallView.swift+++ b/kit/Sources/CodyncUI/Call/CallView.swift@@ -8,16 +8,17 @@ import SwiftUI/// read aloud, and the chat gets a "Voice chat · 00:16" line when the call ends.struct CallView: View {let botId: String+ @Binding var isSpeaking: Bool+ @Binding var interrupt: (() -> Void)?let close: () -> Void@Environment(BotStore.self) private var model@Environment(\.accessibilityReduceMotion) private var reduceMotion@State private var session: CallSession?+ @State private var callID = UUID()@State private var startedAt = Date.now@State private var settings = falseprivate var bot: Bot? { model.bots[botId] }- /// The newest final reply; each new one is read aloud.- private var lastReply: Entry? { model.chat(botId).last { $0.kind == "agent" && $0.data.final == true } }private var color: Color { bot.map { AvatarPalette.color($0.avatarColor) } ?? Palette.accent }var body: some View {@@ -38,19 +39,29 @@ struct CallView: View {.animation(Motion.reduced(Motion.fade, reduceMotion), value: session?.phase).onAppear {let session = CallSession { [model, botId] in model.send($0, to: botId) }+ session.onActivityChanged = { [weak session, model, botId, callID] active in+ if active {+ model.beginVoiceCall(callID, botId: botId,+ speak: { [weak session] in session?.speak($0) },+ end: { [weak session] in session?.end() })+ } else {+ model.endVoiceCall(callID)+ }+ }self.session = sessionstartedAt = .nowTask { await session.start() }}.onDisappear {session?.end()+ isSpeaking = false+ interrupt = nil+ model.endVoiceCall(callID)model.logCall(botId, seconds: Int(Date.now.timeIntervalSince(startedAt)))}- .onChange(of: lastReply?.id) { _, _ in- if let text = lastReply?.data.text { session?.speak(text) }- }- .onChange(of: bot?.needsInput) { _, needs in- if needs == true { session?.speak("\(bot?.name ?? "The bot") needs your approval in the chat.") }+ .onChange(of: session?.phase) { _, phase in+ isSpeaking = phase == .speaking+ interrupt = phase == .speaking ? { session?.interrupt() } : nil}.codyncSheet(isPresented: $settings) { CallSettingsView() }}@@ -139,17 +150,18 @@ private struct CallLevelDots: View {let x = CGFloat(i) * spacing + spacing / 2let wave = (sin(Double(i) * 0.55 - t * 6) + 1) / 2let amount: Double = if speaking {- 0.35 + 0.65 * wave+ 0.5 + 0.5 * wave} else if level > 0.05 {- Double(level) * (0.4 + 0.6 * wave)+ max(0.2, Double(level)) * (0.45 + 0.55 * wave)} else if working {0.25 * ((sin(t * 2.4) + 1) / 2)} else {- 0+ 0.08}- let height = 3 + CGFloat(amount) * (size.height - 3)- let rect = CGRect(x: x - 1.5, y: (size.height - height) / 2, width: 3, height: height)- canvas.fill(Path(roundedRect: rect, cornerRadius: 1.5), with: .color(color.opacity(0.3 + 0.7 * amount)))+ let height = 4 + CGFloat(amount) * (size.height - 4)+ let rect = CGRect(x: x - 1.25, y: (size.height - height) / 2, width: 2.5, height: height)+ let tint = speaking ? Palette.accent : color+ canvas.fill(Path(roundedRect: rect, cornerRadius: 1.25), with: .color(tint.opacity(0.5 + 0.5 * amount)))}}}diff --git a/kit/Sources/CodyncUI/Store/BotStore.swift b/kit/Sources/CodyncUI/Store/BotStore.swiftindex ab4ae22a..21ac3bf8 100644--- a/kit/Sources/CodyncUI/Store/BotStore.swift+++ b/kit/Sources/CodyncUI/Store/BotStore.swift@@ -98,6 +98,13 @@ public final class BotStore {private var streamTask: Task<Void, Never>?private var eventsTask: Task<Void, Never>?private var isActive = true+ private struct VoiceCall {+ let botId: String+ let startRev: Int64+ let speak: @MainActor (String) -> Void+ let end: @MainActor () -> Void+ }+ @ObservationIgnored private var voiceCalls: [UUID: VoiceCall] = [:]private var saveTask: Task<Void, Never>?private var rewound = false@@ -196,8 +203,11 @@ public final class BotStore {/// Permanently detach a store (account switch, computer removed). Late async/// callbacks still hold it, but it writes nothing and calls no hooks anymore.public func retire() {+ let calls = Array(voiceCalls.values)+ voiceCalls.removeAll()setActive(false)retired = true+ for call in calls { call.end() }saveTask?.cancel()dropTimer?.cancel()onConnected = nil@@ -217,8 +227,9 @@ public final class BotStore {guard !retired else { return }isActive = activeif active {- restartStream()- } else {+ // Returning to the foreground must not interrupt a live call's sends.+ if voiceCalls.isEmpty || streamTask == nil { restartStream() }+ } else if voiceCalls.isEmpty {// Disconnect so the host knows we're gone and sends pushes instead.stopTransport()saveCache()@@ -226,12 +237,28 @@ public final class BotStore {}public func restartStream() {- guard isActive, !retired else { return }+ guard isActive || !voiceCalls.isEmpty, !retired else { return }stopTransport()if connection != .online { setConnection(.connecting) }streamTask = Task { [weak self] in await self?.runStream() }}+ /// Audio owns this subscription, so background calls don't depend on SwiftUI updates.+ func beginVoiceCall(_ id: UUID, botId: String, speak: @escaping @MainActor (String) -> Void,+ end: @escaping @MainActor () -> Void) {+ guard !retired, voiceCalls[id] == nil else { return }+ voiceCalls[id] = VoiceCall(botId: botId, startRev: rev, speak: speak, end: end)+ if streamTask == nil { restartStream() }+ }++ func endVoiceCall(_ id: UUID) {+ guard voiceCalls.removeValue(forKey: id) != nil else { return }+ if !isActive && voiceCalls.isEmpty {+ stopTransport()+ saveCache()+ }+ }+private func stopTransport() {streamTask?.cancel()streamTask = nil@@ -439,11 +466,17 @@ public final class BotStore {screen = newScreenif hostRev < rev { rev = 0 }case let .bot(bot):+ let neededInput = bots[bot.id]?.needsInput == truebots[bot.id] = botbump(bot.rev)onBotUpdated?(bot)onRosterChanged?()if bot.unread > 0 { acknowledgeVisibleConversations(bot.id) }+ if bot.needsInput && !neededInput {+ for call in Array(voiceCalls.values) where call.botId == bot.id {+ call.speak("\(bot.name) needs your approval in the chat.")+ }+ }case let .botDeleted(id, r):bots[id] = nilentries[id] = nil@@ -451,9 +484,15 @@ public final class BotStore {if selection == id { selection = nil }onRosterChanged?()case let .entry(e):+ let wasFinal = entries[e.botId]?.first(where: { $0.id == e.id })?.data.final == trueupsert(e)bump(e.rev)acknowledgeVisibleConversations(e.botId, entry: e)+ if e.kind == "agent", e.threadId == nil, e.data.final == true, !wasFinal, let text = e.data.text {+ for call in Array(voiceCalls.values) where call.botId == e.botId && e.rev > call.startRev {+ call.speak(text)+ }+ }case let .usage(u):setUsage(u)case let .screen(s):diff --git a/kit/Sources/CodyncUI/Thread/Composer.swift b/kit/Sources/CodyncUI/Thread/Composer.swiftindex 2a19d0d4..10ce3eef 100644--- a/kit/Sources/CodyncUI/Thread/Composer.swift+++ b/kit/Sources/CodyncUI/Thread/Composer.swift@@ -11,6 +11,8 @@ struct Composer: View {var thread: String?/// Starts a voice call; while the box is empty it takes the send button's place.var onCall: (() -> Void)?+ /// Interrupts the bot while it is speaking in a voice call.+ var onInterrupt: (() -> Void)?@Environment(BotStore.self) private var model@Environment(\.accessibilityReduceMotion) private var reduceMotion@State private var draft = ""@@ -158,7 +160,19 @@ struct Composer: View {.padding(.vertical, fieldPadding).sendOnReturn(submit)Group {- if working && draft.isEmpty {+ if let onInterrupt, draft.isEmpty, files.isEmpty {+ Button(action: onInterrupt) {+ Image(systemName: "stop.fill")+ .font(.system(size: 12, weight: .bold))+ .frame(width: InterfaceMetrics.value(mac: 28, mobile: 34), height: InterfaceMetrics.value(mac: 28, mobile: 34))+ .background(Palette.danger, in: Circle())+ .foregroundStyle(.white)+ .contentTransition(.symbolEffect(.replace))+ }+ .buttonStyle(.plain)+ .accessibilityLabel("Interrupt")+ .help("Interrupt")+ } else if working && draft.isEmpty {Button {model.stop(botId)} label: {@@ -197,6 +211,7 @@ struct Composer: View {.help("Send")}}+ .animation(Motion.layout, value: onInterrupt != nil).padding(.bottom, max(0, (lineHeight + 2 * fieldPadding - buttonSize) / 2)).animation(Motion.layout, value: isEmpty)}diff --git a/kit/Sources/CodyncUI/Thread/ThreadView.swift b/kit/Sources/CodyncUI/Thread/ThreadView.swiftindex c41f9085..b75f69ff 100644--- a/kit/Sources/CodyncUI/Thread/ThreadView.swift+++ b/kit/Sources/CodyncUI/Thread/ThreadView.swift@@ -26,6 +26,8 @@ public struct ThreadView: View {@State private var availableWidth: CGFloat = 800@State private var compactDetails = false@State private var calling = false+ @State private var callSpeaking = false+ @State private var interruptCall: (() -> Void)?@State private var showRoutines = false@State private var routineId: String?@State private var routineRequest = UUID()@@ -154,7 +156,9 @@ public struct ThreadView: View {.safeAreaInset(edge: .bottom) {VStack(spacing: 6) {#if os(iOS)- Composer(botId: botId, onCall: bot?.isGroup == false ? { calling = true } : nil)+ Composer(botId: botId,+ onCall: !calling && bot?.isGroup == false ? { calling = true } : nil,+ onInterrupt: callSpeaking ? interruptCall : nil)#elseComposer(botId: botId)#endif@@ -178,7 +182,9 @@ public struct ThreadView: View {// Grok Bot's call: a bar floating over the chat, which stays readable and usable..overlay(alignment: .top) {if calling {- CallView(botId: botId) { withAnimation(Motion.reduced(Motion.layout, reduceMotion)) { calling = false } }+ CallView(botId: botId, isSpeaking: $callSpeaking, interrupt: $interruptCall) {+ withAnimation(Motion.reduced(Motion.layout, reduceMotion)) { calling = false }+ }.padding(.top, 4).transition(.move(edge: .top).combined(with: .opacity))}diff --git a/kit/Tests/CodyncUITests/StoreTests.swift b/kit/Tests/CodyncUITests/StoreTests.swiftindex 60cc5258..88eee99f 100644--- a/kit/Tests/CodyncUITests/StoreTests.swift+++ b/kit/Tests/CodyncUITests/StoreTests.swift@@ -14,6 +14,8 @@ actor FakeRemote: RemoteTransport {private(set) var readReceipts: [Data] = []private var failReadReceipts = falseprivate(set) var readAttempts = 0+ private(set) var shutdownCount = 0+ private var isShutdown = falsefunc setReadFailure(_ fail: Bool) { failReadReceipts = fail }private(set) var enqueued: [String] = []@@ -38,6 +40,7 @@ actor FakeRemote: RemoteTransport {}private func respond(_ method: String, _ body: Data) throws -> Data {+ guard !isShutdown else { throw HostError.unreachable }switch method {case "hello":return Data(#"{"hostId":"h1","name":"Mac","version":"3.0.0","os":"macos","backends":[],"rev":0}"#.utf8)@@ -62,6 +65,7 @@ actor FakeRemote: RemoteTransport {private func addEvents(_ c: AsyncThrowingStream<Data, Error>.Continuation) { eventSinks.append(c) }private func addState(_ c: AsyncStream<LinkState>.Continuation) {+ isShutdown = falsec.yield(state)stateSinks.append(c)}@@ -86,6 +90,8 @@ actor FakeRemote: RemoteTransport {}func shutdown() async {+ shutdownCount += 1+ isShutdown = truefor s in eventSinks { s.finish() }for s in stateSinks { s.finish() }eventSinks = []@@ -125,6 +131,88 @@ private func botEvent(_ id: String, name: String, rev: Int) -> String {#"{"type":"bot","bot":{"id":"\#(id)","name":"\#(name)","rev":\#(rev),"lastAt":\#(rev)}}"#}+@MainActor @Test func voiceCallSendsAndReceivesInBackgroundWithoutViewUpdates() async throws {+ let (storage, suite) = context()+ defer { UserDefaults(suiteName: suite)?.removePersistentDomain(forName: suite) }+ let fake = FakeRemote(.ready(.direct))+ let store = BotStore(computer: randomComputer("Mac"), route: .channel, clientKind: "ios", storage: storage) { fake }+ defer { store.retire() }+ store.setActive(true)+ #expect(await until { await fake.subscribed })+ await fake.emit(botEvent("b1", name: "Bot", rev: 1))+ #expect(await until { store.connection == .online })++ let call = UUID()+ var spoken: [String] = []+ store.beginVoiceCall(call, botId: "b1", speak: { spoken.append($0) }, end: {})+ store.setActive(false)+ // Allow shutdown to run if backgrounding incorrectly scheduled one.+ try await Task.sleep(for: .milliseconds(30))+ store.send("spoken while backgrounded", to: "b1")+ #expect(await until { store.chat("b1").first?.id == "e1" })+ #expect(await fake.sent == ["spoken while backgrounded"])+ #expect(await fake.shutdownCount == 0)++ let reply = #"{"type":"entry","entry":{"id":"reply","seq":2,"botId":"b1","rev":2,"kind":"agent","turn":1,"data":{"text":"The answer","final":true},"createdAt":1,"updatedAt":1}}"#+ await fake.emit(reply)+ #expect(await until { spoken == ["The answer"] })+ await fake.emit(reply) // Event replays must not read the same reply twice.+ await fake.emit(#"{"type":"entry","entry":{"id":"thread","seq":3,"botId":"b1","threadId":"root","rev":3,"kind":"agent","turn":1,"data":{"text":"Thread answer","final":true},"createdAt":1,"updatedAt":1}}"#)+ await fake.emit(#"{"type":"entry","entry":{"id":"other","seq":4,"botId":"b2","rev":4,"kind":"agent","turn":1,"data":{"text":"Other bot","final":true},"createdAt":1,"updatedAt":1}}"#)+ #expect(await until { store.chat("b2").last?.id == "other" })+ #expect(spoken == ["The answer"])++ store.setActive(true)+ #expect(await fake.shutdownCount == 0)+ store.endVoiceCall(call)+ #expect(await fake.shutdownCount == 0) // Foreground keeps the ordinary connection.+ store.setActive(false)+ #expect(await until { await fake.shutdownCount == 1 })+}++@MainActor @Test func lastVoiceCallEndingDisconnectsBackgroundStore() async throws {+ let (storage, suite) = context()+ defer { UserDefaults(suiteName: suite)?.removePersistentDomain(forName: suite) }+ let fake = FakeRemote(.ready(.relay))+ let store = BotStore(computer: randomComputer("Mac"), route: .channel, clientKind: "ios", storage: storage) { fake }+ defer { store.retire() }+ store.setActive(true)+ #expect(await until { await fake.subscribed })+ await fake.emit(botEvent("b1", name: "Bot", rev: 1))+ #expect(await until { store.connection == .online })+ let first = UUID(), second = UUID()+ store.beginVoiceCall(first, botId: "b1", speak: { _ in }, end: {})+ store.beginVoiceCall(second, botId: "b1", speak: { _ in }, end: {})+ store.setActive(false)+ store.endVoiceCall(first)+ try await Task.sleep(for: .milliseconds(30))+ #expect(await fake.shutdownCount == 0)+ store.endVoiceCall(second)+ #expect(await until { await fake.shutdownCount == 1 })+}++@MainActor @Test func retiringStoreEndsVoiceCallAndPreventsLaterSends() async throws {+ let (storage, suite) = context()+ defer { UserDefaults(suiteName: suite)?.removePersistentDomain(forName: suite) }+ let fake = FakeRemote(.ready(.direct))+ let store = BotStore(computer: randomComputer("Mac"), route: .channel, clientKind: "ios", storage: storage) { fake }+ store.setActive(true)+ #expect(await until { await fake.subscribed })+ await fake.emit(botEvent("b1", name: "Bot", rev: 1))+ #expect(await until { store.connection == .online })+ let call = UUID()+ var ended = false+ store.beginVoiceCall(call, botId: "b1", speak: { _ in Issue.record("Retired call received speech") }, end: { ended = true })+ store.setActive(false)+ store.retire()+ #expect(ended)+ #expect(await until { await fake.shutdownCount == 1 })+ store.send("must not send", to: "b1")+ store.beginVoiceCall(UUID(), botId: "b1", speak: { _ in }, end: {})+ #expect(store.chat("b1").isEmpty)+ #expect(await fake.sent.isEmpty)+}+@MainActor @Test func offlineSendsWaitInTheMailbox() async throws {let (storage, suite) = context()defer { UserDefaults(suiteName: suite)?.removePersistentDomain(forName: suite) }