Skip to content

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.

fix(ios): a call hung up from its Live Activity still leaves its line

leepokai8bee89da26fd
diff --git a/apps/ios/Kit/Sources/CodyncUI/Call/CallLink.swift b/apps/ios/Kit/Sources/CodyncUI/Call/CallLink.swift
index 92a9ddd8..8131e3d3 100644
--- a/apps/ios/Kit/Sources/CodyncUI/Call/CallLink.swift
+++ b/apps/ios/Kit/Sources/CodyncUI/Call/CallLink.swift
@@ -102,7 +102,11 @@ final class CallLink {
/// The call is over: its line in the chat, with what's left of the transcript.
func end(seconds: Int) {
- serial { [self] in await model.endCall(botId, seconds: seconds, call: call, lines: drain(withOpen: true)) }
+ model.beginCallEnd()
+ serial { [self] in
+ await model.endCall(botId, seconds: seconds, call: call, lines: drain(withOpen: true))
+ model.finishCallEnd()
+ }
}
/// The lines finished so far (`withOpen`: and the one still being said), out of the buffer: trimmed, Chinese in
diff --git a/apps/ios/Kit/Sources/CodyncUI/Call/CallView.swift b/apps/ios/Kit/Sources/CodyncUI/Call/CallView.swift
index 498eac01..1617d218 100644
--- a/apps/ios/Kit/Sources/CodyncUI/Call/CallView.swift
+++ b/apps/ios/Kit/Sources/CodyncUI/Call/CallView.swift
@@ -63,12 +63,13 @@ struct CallView: View {
begin(cloud: VoiceSettings.provider)
}
.onDisappear {
+ // First, so the connection outlives the engine: the end is sent after the engine's last lines.
+ link?.end(seconds: Int(Date.now.timeIntervalSince(startedAt)))
session?.end()
countCloudMinutes()
isSpeaking = false
interrupt = nil
model.endVoiceCall(callID)
- link?.end(seconds: Int(Date.now.timeIntervalSince(startedAt)))
quality.report()
activity?.end()
}
diff --git a/apps/ios/Kit/Sources/CodyncUI/Store/BotStore+Connection.swift b/apps/ios/Kit/Sources/CodyncUI/Store/BotStore+Connection.swift
index e1110563..4fbb4841 100644
--- a/apps/ios/Kit/Sources/CodyncUI/Store/BotStore+Connection.swift
+++ b/apps/ios/Kit/Sources/CodyncUI/Store/BotStore+Connection.swift
@@ -69,7 +69,19 @@ extension BotStore {
if !retired { stopIfIdle() }
}
- private var hasBackgroundWork: Bool { !voiceCalls.isEmpty || shortcutSends > 0 }
+ /// A call's end on its way to the computer keeps the connection the call kept: a call ended in the background
+ /// (from its Live Activity) would otherwise drop it before the computer writes the call's line.
+ func beginCallEnd() {
+ callEnds += 1
+ if streamTask == nil { restartStream() }
+ }
+
+ func finishCallEnd() {
+ callEnds -= 1
+ if !retired { stopIfIdle() }
+ }
+
+ private var hasBackgroundWork: Bool { !voiceCalls.isEmpty || shortcutSends > 0 || callEnds > 0 }
private func stopIfIdle() {
if !isActive && !hasBackgroundWork {
diff --git a/apps/ios/Kit/Sources/CodyncUI/Store/BotStore.swift b/apps/ios/Kit/Sources/CodyncUI/Store/BotStore.swift
index 01faaa70..e8094058 100644
--- a/apps/ios/Kit/Sources/CodyncUI/Store/BotStore.swift
+++ b/apps/ios/Kit/Sources/CodyncUI/Store/BotStore.swift
@@ -118,6 +118,8 @@ public final class BotStore {
/// The newest cue each call heard (`CallCue.seq`), kept across engine switches: a replayed one isn't said again.
@ObservationIgnored var heardCues: [UUID: Int64] = [:]
@ObservationIgnored var shortcutSends = 0
+ /// Calls whose end is still on its way to the computer.
+ @ObservationIgnored var callEnds = 0
var saveTask: Task<Void, Never>?
var rewound = false
/// Events stayed undecodable after the rewind.
diff --git a/apps/ios/Kit/Tests/CodyncUITests/StoreTests.swift b/apps/ios/Kit/Tests/CodyncUITests/StoreTests.swift
index c6be9efb..f678086a 100644
--- a/apps/ios/Kit/Tests/CodyncUITests/StoreTests.swift
+++ b/apps/ios/Kit/Tests/CodyncUITests/StoreTests.swift
@@ -214,6 +214,26 @@ private func botEvent(_ id: String, name: String, rev: Int) -> String {
#expect(await until { await fake.shutdownCount == 1 })
}
+@MainActor @Test func aCallsEndKeepsTheConnectionUntilItReachesTheComputer() async throws {
+ let (storage, suite) = context()
+ defer { UserDefaults(suiteName: suite)?.removePersistentDomain(forName: suite) }
+ let fake = FakeRemote(.ready(.relay))
+ let store = BotStore(computer: randomComputer("Mac"), storage: storage) { _ in fake }
+ defer { store.retire() }
+ store.setActive(true)
+ #expect(await until { await fake.subscribed })
+ let call = UUID()
+ store.beginVoiceCall(call, hear: { _ in }, end: {})
+ store.setActive(false)
+ // Hung up from the Live Activity, with the app in the background.
+ store.beginCallEnd()
+ store.endVoiceCall(call)
+ try await Task.sleep(for: .milliseconds(30))
+ #expect(await fake.shutdownCount == 0, "the call's end still has to reach the computer")
+ store.finishCallEnd()
+ #expect(await until { await fake.shutdownCount == 1 })
+}
+
@MainActor @Test func retiringStoreEndsVoiceCallAndPreventsLaterSends() async throws {
let (storage, suite) = context()
defer { UserDefaults(suiteName: suite)?.removePersistentDomain(forName: suite) }