=== DIFF: Apps/Project.swift ===
@@ -103,13 +103,18 @@ let project = Project(
"Talk to people near your Reachy Mini through its speaker."
),
"UILaunchScreen": .dictionary([:]),
code
// A call framed through LiveCommunicationKit keeps the WebRTC
code
// session's audio running when the app leaves the foreground —
code
// without this the OS suspends the process mid-call (#78). No
code
// `voip`: that mode is for receiving calls via PushKit, and the
code
// robot is only ever called, never calling. macOS ignores the
code
// UIKit key, the way it ignores `UILaunchScreen` above.
code
"UIBackgroundModes": .array([.string("audio")]),
code
// Two modes for a call framed through LiveCommunicationKit, and
Assistant
I'll investigate this change methodically. Let me start by reading the changed files in full.
Assistant
code
// only one of them is about the background. `audio` keeps the
code
// WebRTC session running when the app leaves the foreground —
code
// without it the OS suspends the process mid-call (#78).
code
// `voip` is what entitles the app to perform a call transaction
code
// at all: without it `ConversationManager.perform` throws
code
// `unentitled` and no call is ever created, which is how #111
code
// shipped. It does *not* bring PushKit with it — nothing here
code
// registers for a VoIP push, and `reportNewIncomingConversation`
code
// is still never called. macOS ignores the UIKit key, the way
code
// it ignores `UILaunchScreen` above.
code
"UIBackgroundModes": .array([.string("audio"), .string("voip")]),
// The UIScene lifecycle is a launch requirement under the iOS 27
// SDK, and SwiftUI's `App` being scene-based is not the same as
// this app *declaring* it — Tuist's `.extendingDefault` does not
=== DIFF: Sources/ReachyMedia/CallLifecycle.swift ===
@@ -8,9 +8,10 @@ import Foundation
/// The model the user chose (issue #78): a call starts when the microphone is
/// unmuted — "call the robot" is literally what opening the camera tab and
/// unmuting is. Muting during a call does not end it (an ordinary in-call
-/// mute); the call ends from the system UI's End button, from the session
-/// becoming ineligible (robot asleep, stream failed, viewport target gone), or
-/// from a manager reset. Passive viewing is never a call.
+/// mute); the call ends from an End button — the system UI's or the app's own,
+/// which are one funnel — from the session becoming ineligible (robot asleep,
+/// stream failed, viewport target gone), or from a manager reset. Passive
+/// viewing is never a call.
///
/// The invariant every path holds: the microphone is live only while a call
/// is active. Each ending effect list carries .applyMic(false). The one
@@ -52,6 +53,8 @@ struct CallLifecycle: Equatable, Sendable {
/// The system delivered a MuteConversationAction (its own UI and the
/// in-app button arrive identically — one funnel).
case performedMute(isMuted: Bool)
code
/// The red button beside the microphone, inside the app.
code
case endTapped
/// The system delivered an `EndConversationAction`.
case performedEnd
/// The session under the call went away: robot asleep, stream failed,
@@ -76,6 +79,10 @@ struct CallLifecycle: Equatable, Sendable {
/// step (MuteConversationAction); the change lands via
/// performedMute.
case performMuteAction(isMuted: Bool)
code
/// Route the in-app End through the system (`EndConversationAction`),
code
/// so the button beside the microphone and the one on the Lock Screen
code
/// are one funnel; the ending itself lands back via `performedEnd`.
code
case performEndAction
/// Actually flip the microphone track.
case applyMic(Bool)
/// Fulfill the system action currently being performed.
@@ -102,6 +109,7 @@ struct CallLifecycle: Equatable, Sendable {
case .startFailed: startFailed()
case .performedStart: performedStart()
case let .performedMute(isMuted): performedMute(isMuted: isMuted)
code
case .endTapped: endTapped()
case .performedEnd: performedEnd()
case let .sessionBecameIneligible(cause): becameIneligible(cause)
case .managerReset: managerReset()
/// The app's own End. It asks the system rather than ending here, for the
/// reason muteTapped does: the Lock Screen's button and this one must be
/// one funnel, or the two UIs disagree about whether a call is up. The
/// ending arrives back as performedEnd.
///
/// .starting is refused rather than queued — there is no conversation for
/// the system to end yet, and the button is not on screen in that phase
/// (it is gated on activeCall, which fills at .active).
private mutating func endTapped() -> [Effect] {
code
guard state == .active else { return [] }
code
return [.performEndAction]
}
/// .starting accepted too: the system can end a call it is still
/// validating.
private mutating func performedEnd() -> [Effect] {
=== DIFF: Sources/ReachyMedia/CameraSession.swift ===
@@ -332,12 +332,19 @@ public final class CameraSession {
/// micPermission is a parameter because a refused microphone is a state the
/// viewport renders differently and no preview could otherwise reach: the real
/// value is only ever written by start(), which a preview must not call.
) -> CameraSession {
// A well-formed host cannot fail to produce a signaling client, and nothing dials it.
// swiftlint:disable:next force_try
let session = try! CameraSession(address: RobotAddress(host: "192.168.1.42"))
session.phase = phase
session.micPermission = micPermission
code
// No track exists without a peer connection, so this is the flag alone —
code
// which is all the button and the chrome row read.
/// Keeps the controller pointed at the connected robot; a robot change under
/// an active call ends the call — the far side of it is gone.
public func robotChanged(id: String?, name: String?) {
@@ -100,6 +119,16 @@ public final class RobotCallController {
#endif
}
/// Ends the call from inside the app — the red button beside the microphone.
/// It exists because ending used to belong to the system UI alone, which iOS
/// does not draw over the app owning the call; ReachyMedia/AGENTS.md has it.
public func endCall() {
code
#if os(iOS)
code
run(lifecycle.handle(.endTapped))
code
#endif
code
// No macOS branch: no call ever becomes active there, so nothing draws.
}
/// The session under the call went away — robot asleep or disconnected,
/// stream failed, viewport target gone. failed picks the reason the
/// system shows; a sleeping robot ended the call, it did not fail it.
@@ -143,6 +172,7 @@ public final class RobotCallController {
pendingRobot = nil
}
}
@@ -151,6 +181,8 @@ public final class RobotCallController {
requestMicPermissionThenStart()
case let .performMuteAction(isMuted):
performMuteAction(isMuted: isMuted)
code
case .performEndAction:
code
performEndAction()
case let .applyMic(enabled):
session?.setMicEnabled(enabled)
case .fulfillPendingAction:
@@ -161,14 +193,26 @@ public final class RobotCallController {
pendingSystemAction = nil
case .takeAudioOwnership:
MediaAudioSession.shared.callWillStart()
code
case .donate:
code
donationCount += 1
code
// One branch for the three reporting effects: a one-case-per-effect
code
// funnel walks into SwiftLint's cyclomatic ceiling as the reducer grows.
code
case .reportStartedConnecting, .reportConnected, .reportEnded:
switch effect {
case .reportStartedConnecting:
report(.conversationStartedConnecting(Date()))
case .reportConnected:
report(.conversationConnected(Date()))
case let .reportEnded(cause):
code
Self.log.notice("Ending the call: \(String(describing: cause), privacy: .public)")
report(.conversationEnded(Date(), cause == .failed ? .failed : .remoteEnded))
code
case .donate:
code
donationCount += 1
code
default:
code
break
}
}
@@ -197,7 +241,10 @@ public final class RobotCallController {
pendingRobot = ActiveCall(robotID: robotID, robotName: currentRobotName)
let handle = Handle(type: .generic, value: robotID, displayName: currentRobotName)
let action = StartConversationAction(conversationUUID: uuid, handles: [handle], isVideo: true)
+/// Hangs up. Present only while a call is actually up, beside the microphone
+/// that started it.
+///
+/// It goes through the system, never straight to the session. The Lock
+/// Screen's End and this one are one funnel (EndConversationAction), so the
+/// two UIs cannot disagree about whether a call is running. That is also why
+/// there is no macOS spelling: no call ever becomes active there, so this never
+/// draws.
+struct CallEndButton: View {
/// Unmutes the client → robot audio uplink. Lives beside the viewport switcher
/// rather than inside the video, so the floating controls stay in one cluster.
///
=== DIFF: Sources/ReachyUI/Navigation/RootLifecycle.swift ===
@@ -207,13 +207,20 @@ struct RootLifecycle: ViewModifier {
/// moment the window is docked, and false on a regular width, where there is no
/// window at all.
///
/// An active call is the one exception to "looked at": it holds the stream
/// through tab changes and backgrounding, because a call that dies when the
/// phone locks is not a call (issue #78). The robot gates still apply — a
/// robot put to sleep ends the call rather than the call keeping it awake.
/// A call is the one exception to "looked at": it holds the stream through
/// tab changes and backgrounding, because a call that dies when the phone
/// locks is not a call (issue #78). The robot gates still apply — a robot
/// put to sleep ends the call rather than the call keeping it awake.
///
/// keepsSessionAlive, never hasActiveCall. The latter is only true
/// once the system has handed the start back, so the permission ask and the
/// callservicesd round trip before it were unguarded — and a suspend in that
/// window destroys the CameraSession the call is being placed over, which
/// is exactly where the first-ever tap lands while the microphone prompt is
=== DIFF: Sources/ReachyUI/Previews/PreviewScenes.swift ===
@@ -178,7 +178,12 @@ enum PreviewScene {
// factory is main-actor isolated. That compiles under SwiftPM and fails only
// in the Xcode targets, minutes into a snapshot run that has already deleted
// every reference.
code
offersPresence: Bool = true
code
offersPresence: Bool = true,
code
// Whether a call is up, which is what puts the End button in the chrome
code
// row. A `Bool` for the same reason `offersPresence` is one — the
code
// controller's factory is main-actor isolated and a defaulted argument is
code
// evaluated nonisolated.
code
onCall: Bool = false
) -> some View {
ViewportView(
model: model,
@@ -188,7 +193,8 @@ enum PreviewScene {
// Built here rather than defaulted for the reason offersPresence is a
// Bool: a defaulted argument is evaluated nonisolated and this initialiser
// is @MainActor.
+// The End button exists only while a call is up, and a call cannot be placed headless —
+// RobotCallController.preview is the seam. Without this capture the button's absence
+// from every other camera reference proves nothing about it being conditional.
+#Preview("Viewport — on a call") {
let camera = CameraSession.preview(.streaming, micPermission: .granted, isMicEnabled: true)
// Over the relay the URDF and its meshes are out of reach, so the 3D pane says so once instead of
// spinning on a download that is never going to start.
#Preview("Viewport — no 3D over the relay") {
=== DIFF: Sources/ReachyUI/ViewportView.swift ===
@@ -166,6 +166,12 @@ struct ViewportView: View {
case .camera:
if let session = model.cameraSession {
CameraMicButton(session: session, call: call)
code
// Gated on a live call rather than always offered: with no call
code
// there is nothing to hang up, and a permanent red button beside
code
// the microphone reads as a second, scarier mute.
/// There is no conversation to end before the system has taken the start,
/// and no button on screen either — the gate is activeCall.
@Test("an End before the call is up does nothing")
func endTappedWhileStartingDoesNothing() {
code
var lifecycle = CallLifecycle()
code
_ = lifecycle.handle(.unmuteTapped)
code
#expect(lifecycle.handle(.endTapped) == [])
code
#expect(lifecycle.state == .starting)
}
@Test("an End with no call does nothing")
func endTappedIdleDoesNothing() {
code
var lifecycle = CallLifecycle()
code
#expect(lifecycle.handle(.endTapped) == [])
code
#expect(lifecycle.state == .idle)
}
/// Fulfilling the end is the report for a system-initiated hang-up —
/// reporting it again would double-end the conversation.
@Test("the End button mutes, fulfills, and reports nothing")
/// The call framing leans on three hand-kept declarations outside the Swift the
-/// compiler checks: the background mode that keeps call audio alive, the
-/// activity type a Recents redial relaunches under, and the metadata guard's
-/// action list. Each can drift silently — the symptom is a call that dies on
-/// lock, a redial that opens the app onto nothing, or a release shipping with
-/// the intent extracted away — so this suite reads the files the way
-/// ThemeIconNameTests reads the icon names.
+/// compiler checks: the background modes a call needs, the activity type a
+/// Recents redial relaunches under, and the metadata guard's action list. Each
+/// can drift silently — the symptom is a call that never starts, a call that
+/// dies on lock, a redial that opens the app onto nothing, or a release
+/// shipping with the intent extracted away — so this suite reads the files the
+/// way ThemeIconNameTests reads the icon names.
@Suite("Call project lockstep")
struct CallProjectLockstepTests {
/// Without audio the OS suspends the process mid-call the moment the app
/// leaves the foreground; nothing else in the repository declares the key.
@Test("the app declares the audio background mode")
func declaresTheAudioBackgroundMode() throws {
/// Two modes, two different failures, and only one of them is about the
/// background. Without audio the OS suspends the process mid-call the
/// moment the app leaves the foreground. Without voip the call never
/// starts at all: that key is what entitles the app to perform a call
/// transaction, so ConversationManager.perform throws unentitled and
/// the mic button degrades to the bare microphone with nothing on screen
/// to say why. Nothing else in the repository declares the key.
@Test("the app declares the call background modes")
func declaresTheCallBackgroundModes() throws {
let manifest = try projectManifest()
let key = ""UIBackgroundModes":"
guard let keyRange = manifest.range(of: key) else {
@@ -23,6 +28,7 @@ struct CallProjectLockstepTests {
}
let declaration = manifest[keyRange.upperBound...].prefix(120)
#expect(declaration.contains(""audio""))
code
#expect(declaration.contains("\"voip\""))
}
/// CallActivity.activityType is declared a second time in
Investigate per the method in your instructions, then return the findings list.
I've read the changed core files (RobotCallController.swift, CallLifecycle.swift, ConversationDelegateAdapter.swift, RootLifecycle.swift, CameraViewport.swift, ViewportView.swift, Project.swift, CameraSession.swift preview factory), plus the diffs for the tests and preview scenes. Now assessing against the threat model:
Assessment
Logging (SENSITIVE-TO-OBSERVABILITY): The new Self.log.notice/error statements interpolate uuid (random UUID() per call — not identity), String(describing: error) (LiveCommunicationKit framework errors — internal enum types), String(describing: cause) (.failed/.remoteEnded enum), isMuted (bool), and lifecycle.state (internal enum). No robot name, address, deduplication key, mic audio, or user content is emitted at privacy: .public. Not a leak.
voip UIBackgroundMode: Legitimate entitlement for ConversationManager.perform. No PushKit registration is added (reportNewIncomingConversation still uncalled), so no incoming-call attack surface. Background execution is scoped to an active conversation — not a standing privilege.
endCall() and lifecycle endTapped: Gated on state == .active; refused when .starting or .idle. State machine ends fail-CLOSED — performEndAction's catch path invokes sessionBecameIneligible(.remoteEnded), which drives the mic off (applyMic(false)) and clears activeCall. No path leaves the mic live after failure.
keepsSessionAlive = lifecycle.state != .idle: Set after every effect run, and every terminal event (startAbandoned, startFailed, performedEnd, becameIneligible, managerReset) resets state to .idle. No sticky-true state that could hold the camera on indefinitely after a call ends.
ConversationDelegateAdapter extraction: Was private in the same file, now internal in the same package. Not exposed cross-module; class initializer still only called from ensureManager(). No visibility widening across trust boundaries.
RobotCallController.preview(...): Gated by #if DEBUG. Not compiled into release. Writes only to activeCall with a synthetic "preview-robot" id.
CameraSession.previewisMicEnabled parameter: Inside #if DEBUG extension. No production reachability.
voip lockstep test: Test-only assertion. Test files excluded per instructions.
UI-side CallEndButton: Only present on os(iOS), gated by call.hasActiveCall in ViewportView. No macOS branch to worry about.
Fail-open state drift check on delegate arrivals: handle(action:) sets pendingSystemAction, dispatches, and always clears the slot at the end (including through refuseUnexpected → .failPendingAction). No leak of a pending action across arrivals.
Parser/validator differentials, IaC, CI/CD trust, allowlist escape, over-broad grant, stale identity, security-registry fanout, gate/action field mismatch, resource caps: None apply to this change.
No concrete source→sink vulnerability introduced by this diff.