Skip to content

fix(tui): honor realtime audio backpressure before draining queued chunks (#2122) - #2574

Open
turkonthelurk wants to merge 1 commit into
tetsuo-ai:mainfrom
turkonthelurk:cursor/fix-2122-realtime-audio-drain-823e
Open

turkonthelurk wants to merge 1 commit into
tetsuo-ai:mainfrom
turkonthelurk:cursor/fix-2122-realtime-audio-drain-823e

Conversation

@turkonthelurk

Copy link
Copy Markdown
Contributor

Closes #2122

Draft for review only. Not to be merged by automation; a maintainer decides when and whether it lands. Opened from fork turkonthelurk/agenc-core. Nothing pushed to main on either repo. Based on upstream main only. Independent of #2113 / draft #2573 and #2123. Does not enable production realtime admission.

Problem

createProcessRealtimeAudioPlayer recorded stdin backpressure (waitingForDrain) but flush() did not return while that flag was set. Every later enqueueBuffer() called flush() again, so stdin.write kept going after a false return and bypassed the managed 512 KiB queue.

Verified on upstream main at 6a2a92d: a fake stdin that always returns false accepted all twenty 64 KiB chunks (1,310,720 bytes) before any drain.

Change

  • flush() returns immediately while waitingForDrain is true.
  • Further writes resume only from the registered drain handler (and ignore a stale child after reset).
  • Error / close / format-change paths detach the drain listener and drop the queue.
  • Drop policy: oldest queued audio is dropped so the newest frames stay and the application-owned queue never exceeds 512 KiB.

Tests

Hermetic Vitest, fail-before / pass-after:

  • RED: 20 writes / 1,310,720 bytes before drain
  • GREEN: 1 write / 65,536 bytes before drain; after drain, only the newest 512 KiB is flushed
  • tests/tui/realtime: 7 files, 57 passed

This does not merge and does not enable production realtime admission.

Opened from fork turkonthelurk/agenc-core. Companion fork PR (to close): turkonthelurk#17

…unks

Stop flush from writing again while stdin is waiting for drain so the
512 KiB playback queue stays under application control. Resume only from
the drain handler, drop oldest queued frames when the cap is exceeded,
and detach the listener on error, close, and format change.

Co-authored-by: turk <turkonthelurk@users.noreply.github.com>
@sonarqubecloud

Copy link
Copy Markdown

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.

fix(tui): honor realtime audio backpressure before draining queued chunks

2 participants