pi-dashboard icon indicating copy to clipboard operation
pi-dashboard copied to clipboard

bug: iOS CancellationError surfacing on navigation

Open samfoy opened this issue 7 months ago • 1 comments

Description

When navigating between chats or backgrounding the app, Swift's structured concurrency cancels in-flight Tasks. ChatViewModel.loadHistory() catches CancellationError and URLError.cancelled, but other async paths don't, causing error banners to flash briefly.

Steps to reproduce

  1. Open a chat in the iOS app
  2. While it's loading or streaming, quickly tap back to the chat list
  3. An error banner may flash briefly before disappearing

Expected behavior

Navigation cancellations are silently swallowed — they're not real errors.

Actual behavior

Error text like CancellationError or URLError Code=-999 briefly appears.

Likely uncaught paths

  • WebSocketManager.receiveLoop() — ws.receive() throws on task cancel, reconnect logic may trigger unnecessarily
  • SlotListViewModel polling — refresh in-flight when swapping chats
  • Image loading tasks in assistant messages

Suggested fix

Add a global helper and use it consistently:

func isCancellation(_ error: Error) -> Bool {
    error is CancellationError || (error as? URLError)?.code == .cancelled
}

Audit every do/catch in async viewmodels and networking:

} catch where isCancellation(error) {
    return // not a real error
}

Files to audit

  • ViewModels/ChatViewModel.swift (partially fixed)
  • ViewModels/SlotListViewModel.swift
  • Networking/WebSocketManager.swift
  • Networking/APIClient.swift

samfoy avatar Apr 19 '26 05:04 samfoy

Fixed in e2ed28f — added isCancellation() helper and guarded all async catch paths in ChatViewModel + ChatView .task chain.

samfoy avatar Apr 19 '26 05:04 samfoy