Skip to content

fix(diarizer/offline): propagate cancellation to workers - #886

Open
CiprianSpiridon wants to merge 2 commits into
FluidInference:mainfrom
CiprianSpiridon:fix/offline-diarizer-cancellation-upstream
Open

fix(diarizer/offline): propagate cancellation to workers#886
CiprianSpiridon wants to merge 2 commits into
FluidInference:mainfrom
CiprianSpiridon:fix/offline-diarizer-cancellation-upstream

Conversation

@CiprianSpiridon

Copy link
Copy Markdown
Contributor

Why is this change needed?

OfflineDiarizerManager.prepare launches segmentation and embedding inference as
detached tasks. Detached tasks do not inherit cancellation from the caller, so
cancelling process(URL) during a long recording can leave Core ML work running
after the caller has given up. That prevents clients from reliably preempting
offline diarization when a higher-priority audio or transcription task needs the
device.

Changes

  • Run segmentation and embedding extraction as children of one throwing task
    group rather than as detached tasks.
  • Cancel the sibling worker and terminate the segmentation stream when either
    worker fails or is cancelled.
  • Keep the structured scope alive until both inference workers have terminated,
    so returning CancellationError is also the shutdown boundary.
  • Add a real-file regression that cancels after inference begins, requires the
    call to return within two seconds, and verifies that progress does not continue
    afterward.

There is no public API change. Successful diarization still returns the same
prepared segmentation and embedding results.

Test Plan

  • swift format lint --configuration .swift-format Sources/FluidAudio/Diarizer/Offline/Core/OfflineDiarizerManager.swift Tests/FluidAudioTests/Diarizer/Offline/OfflineDiarizerCancellationTests.swift
  • swift test --parallel --num-workers 8 (2,332 discovered tests, exit 0)
  • FLUIDAUDIO_CANCELLATION_TEST_AUDIO=/private/tmp/EN2002a.Mix-Headset.wav swift test --filter OfflineDiarizerCancellationTests
    • Passed with the project's official AMI EN2002a single-distant-microphone
      meeting and locally cached production diarization models.
    • Cancellation completed in 0.918 seconds on an Apple M3 Max running macOS
      26.3, with no progress after the call returned.

The real-file regression skips when FLUIDAUDIO_CANCELLATION_TEST_AUDIO or the
offline diarization models are unavailable, so the repository does not need to
bundle a large meeting recording or model artifacts.

Notes

The repository-wide format and test commands still emit existing warnings from
untouched files, including the unhandled sample_medical.arpa test fixture. The
changed files are format-clean, and the complete test command exits successfully.

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.

1 participant