Skip to content

Treat URLError.cancelled as cancellation in awaitUpload - #326

Open
toufiqfarhan0 wants to merge 1 commit into
AssemblyAI:mainfrom
toufiqfarhan0:fix/await-upload-cancellation
Open

toufiqfarhan0 wants to merge 1 commit into
AssemblyAI:mainfrom
toufiqfarhan0:fix/await-upload-cancellation

Conversation

@toufiqfarhan0

Copy link
Copy Markdown

What & why

Fixes #324

In DictationSession+Pipeline.swift:awaitUpload, cancelled in-flight requests that throw URLError(.cancelled) were not recognized as cancellation because the catch statement only checked Task.isCancelled || error is CancellationError. In Swift, URLError is not an instance of CancellationError.

When upload is cancelled (via cancelUpload(), cancelRecording(), or URLSession aborts), URLError(.cancelled) fell through to setPhase(.failed(.sttFailed(underlying: error))), erroneously repainting the cancelled dictation as a red failure and logging an error.

This PR adds || (error as? URLError)?.code == .cancelled, matching the comment on line 205 (// (URLError(.cancelled) / CancellationError)) and the pattern used in SelectionSpeechRouter+Command.swift and AssemblyAISpeechSynthesizer.swift.

How it was tested

  • Added unit test transcriberThrowingURLErrorCancelledIsIgnored in CancelRaceTests.swift asserting that a transcriber throwing URLError(.cancelled) does not set .failed.

  • Verified repository integrity checks:

    • scripts/check-invariants.sh passed ("14 settled decisions hold").
    • scripts/check-portability.sh passed ("37 shell scripts carry no GNU-only idioms").
    • scripts/check-release-notes.sh passed.
    • Python evals test suite (evals/dictation-prompt/test_eval.py) passed (151 passed).
  • scripts/check.sh passes (or CI will, if I'm not on a Mac)

  • I read AGENTS.md and this doesn't reintroduce anything deliberately removed

  • Docs updated if behavior changed

When an in-flight upload task throws URLError(.cancelled), treat it as cancellation in awaitUpload() rather than repainting the cancelled dictation as a red failure. Resolves AssemblyAI#324.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant