Skip to content

URLError(.cancelled) is not recognized as cancellation in awaitUpload(), repainting cancelled dictations as .failed #324

Open

Description

@toufiqfarhan0

What happened?

In DictationSession+Pipeline.swift:awaitUpload, when an in-flight upload task throws on cancellation, the error is caught to avoid repainting a cancelled session as a failure:

do {
  return try await inFlight.value
} catch {
  // A cancel() that landed mid-request already tore this task down and set
  // .cancelled; the transport then surfaces a cancellation-shaped error
  // (URLError(.cancelled) / CancellationError). Leave the claimed phase
  // alone rather than repainting the user's cancel as a red failure.
  if Task.isCancelled || error is CancellationError { return nil }
  ...
  if let blurtError = error as? BlurtError {
    setPhase(.failed(blurtError))
  } else {
    setPhase(.failed(.sttFailed(underlying: error)))
  }
  return nil
}

The comment explicitly notes the expected cancellation errors: (URLError(.cancelled) / CancellationError).

However, the condition only checks Task.isCancelled || error is CancellationError. In Swift, URLError is a distinct type conforming to Error and is not CancellationError (error is CancellationError evaluates to false).

When an upload request is cancelled via cancelUpload() / upload?.cancel(), cancelRecording(), or when URLSession aborts an in-flight streamed upload, the underlying transport throws URLError(.cancelled). If pipelineTask is awaiting inFlight.value and has not yet had its task cancellation flag set, Task.isCancelled evaluates to false.

As a result, URLError(.cancelled) falls through to:

setPhase(.failed(.sttFailed(underlying: error)))

which repaints the cancelled session as a red failure on the overlay and logs an erroneous failure to developer-mode logs via seams.logFailure(...).

In contrast, other cancellation catch sites in the codebase (e.g. SelectionSpeechRouter+Command.swift:121 and AssemblyAISpeechSynthesizer.swift:92) explicitly check (error as? URLError)?.code == .cancelled.

Expected behavior

When inFlight.value throws URLError(.cancelled), awaitUpload should recognize it as cancellation ((error as? URLError)?.code == .cancelled) and return nil, leaving the phase alone.

macOS and Blurt versions

macOS 26.0+ · Blurt 0.1.71

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions