Skip to content

Realtime & Dictation streaming bugs: RealtimeTranscriber lifecycle/over-1000ms finish()/URLSession leak, stale turns abort, and ChunkedRequestBody / 413 fallback bugs #343

Open

Description

@Pizzylee001

Summary

Four verified bugs in the Realtime recording and Dictation streaming transport layers:

  1. RealtimeTranscriber lifecycle races, unchunked finish(), and URLSession leak (Sources/AssemblyAI/Realtime/RealtimeTranscriber.swift:56,62-119,137-142,182-190)

    • No isClosed state: if cancel() or finish() reaches the actor before start() (unstructured tasks in TranscriptsModel+Recording.swift:42,112,123), close() invalidates session and start() subsequently calls session.webSocketTask(with:) on an invalidated URLSession.
    • send(_ pcm:) appends to pending before guard task != nil, growing pending unboundedly after close().
    • start() does not drain pre-start pending, and finish() transmits pending in a single .data(tail) frame without chunking to maximumChunkBytes (32,000 B = 1000 ms), violating AssemblyAI v3's 1000 ms frame ceiling (and can send an odd byte count).
    • Concurrent finish() calls overwrite the single terminated continuation slot (leaking the first). Missing deinit leaks session when recorder.start throws in TranscriptsModel+Recording.swift:31-37.
  2. TranscriptsModel.liveTranscriptionFailed leaks WebSocket and allows stale turns task to abort a later recording (App/Blurt/Blurt/Wizard/TranscriptsModel+Recording.swift:42-52,88-94,151-155)

  3. ChunkedRequestBody.send masks or swallows AssemblyAIError.audioTooShort (Sources/AssemblyAI/ChunkedRequestBody.swift:85-91,171-205)

    • When streamedBody throws audioTooShort (AssemblyAITranscriber.swift:231-234), pipe.drain exits via defer { output.close() }, sending clean EOF instead of aborting fetch. If fetch throws URLError, lines 199-204 never run (flashing an error pill on a stray tap); if the server returns 200 OK, line 201 (!(200..<300)) swallows audioTooShort.
  4. 413 audio_too_large live-cap fallback duplicates up to 18 min of PCM in an unbounded buffer (Sources/BlurtEngine/STT/AssemblyAITranscriber.swift:149-168,211-240)

    • let body lives in transcribe()'s outer scope and liveFeed is not finished on LiveCapExceeded. When pipe.drain exits mid-write (bodyStreamClosed/cancel), body's onTermination does not fire until transcribe() returns, so streamedBody's producer keeps copying all post-120 s audio into body's unbounded buffer (~3x RAM).
    • (Minor) AssemblyAITranscriber.makeConfigData (line 274) re-reads rewriteMode() instead of using its mode parameter.

Suggested Fix

  • Add explicit State + deinit + chunked drainPending + waiter array to RealtimeTranscriber; cancel turns/realtime and guard turns by recording.url in TranscriptsModel+Recording.
  • Cancel fetch on producer failure in ChunkedRequestBody.send; scope body inside do and call liveFeed.finish() immediately on LiveCapExceeded.

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