Skip to content

Adopt NeMo PR #13 lifecycle improvements for parakeet server - #8688

Merged
beastoin merged 4 commits into
mainfrom
fix/adopt-nemo-pr13-lifecycle-8686
Jun 30, 2026
Merged

beastoin merged 4 commits into
mainfrom
fix/adopt-nemo-pr13-lifecycle-8686

Conversation

@beastoin

@beastoin beastoin commented Jun 30, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Adopts two key improvements from beastoin/NeMo#13 into the omi parakeet server:

  1. _batches_inflight counter (batch_engine.py) — Replaces the _flush_pending flag-only approach with a counter that tracks active GPU batches. The 2ms flush timer only fires when _batches_inflight == 0, preventing batch=1 spam while still allowing full batches to use the second inflight slot (max_inflight=2). The early _flush_pending reset after dequeue is restored (safe with the counter guard).

  2. _submit_lock (gpu_worker.py) — Adds a threading.Lock to prevent the stop/submit race condition where stop() sets _running=False while submit() is between the ready check and queue.put(), which could enqueue work to dead queues. All three submit methods (submit, submit_sync, submit_embedding_sync) are protected.

Changes

  • backend/parakeet/batch_engine.py: Added _batches_inflight counter in __init__, flush loop guard, _flush_batch() increment/decrement, restored early _flush_pending reset
  • backend/parakeet/gpu_worker.py: Added _submit_lock, wrapped stop() and all submit*() methods
  • backend/tests/unit/test_parakeet_batch_engine.py: 5 new tests (second inflight slot, error recovery, timer blocking, OOM reset, empty-pending early-return)
  • backend/tests/unit/test_gpu_worker_submit_lock.py: 7 new tests (post-stop rejection for all submit methods, concurrent race for all 3 paths with enqueue-after-stop assertion, atomicity)
  • backend/tests/unit/test_parakeet_gpu_worker.py: Updated queue-full tests to set _running=True
  • backend/test.sh: Wired new test file

Test plan

  • All 37 parakeet-related tests pass (python3 -m pytest tests/unit/test_parakeet_batch_engine.py tests/unit/test_gpu_worker_submit_lock.py tests/unit/test_flush_pending_batch1.py -v → 37 passed)
  • Full backend/test.sh passes (only pre-existing unrelated failure in test_file_upload_endpoint_security.py)
  • Existing regression test test_flush_pending_batch1.py still passes with the counter approach
  • CODEx reviewer: PR_APPROVED_LGTM
  • CODEx tester: TESTS_APPROVED
  • Live GPU test (requires L4/T4 GPU — not available on VPS)

Test detail table

Path ID Changed path Assertion intent Test command Result
P1 batch_engine.py:__init__ — _batches_inflight=0 Counter initialized to 0 pytest tests/unit/test_parakeet_batch_engine.py::TestBatchesInflight -v PASS
P2 batch_engine.py:_flush_loop — _batches_inflight==0 guard Timer blocked during GPU work TestBatchesInflight::test_timer_flush_blocked_during_inflight PASS
P3 batch_engine.py:_flush_batch — increment after sem acquire Counter tracks active GPU batches TestBatchesInflight::test_full_batch_uses_second_inflight_slot PASS
P4 batch_engine.py:_flush_batch — _flush_pending=False restore Early reset safe with counter TestFlushPendingBatch1Regression PASS
P5 batch_engine.py:_flush_batch — decrement in finally Counter resets after GPU error/OOM TestBatchesInflight::test_batches_inflight_resets_after_gpu_error + test_batches_inflight_resets_after_oom PASS
P6 gpu_worker.py:__init__ — _submit_lock Lock created All submit_lock tests PASS
P7 gpu_worker.py:stop() — set _running=False under lock Atomic stop TestSubmitLockRace::test_stop_sets_running_false_atomically PASS
P8 gpu_worker.py:submit() — lock + _running check No enqueue after stop TestSubmitLockRace::test_submit_after_stop_raises_shutting_down + test_concurrent_stop_and_submit_no_enqueue_to_dead_queue PASS
P9 gpu_worker.py:submit_sync() — lock + _running check No enqueue after stop TestSubmitLockRace::test_submit_sync_after_stop_raises_shutting_down + test_concurrent_stop_and_submit_sync_no_enqueue PASS
P10 gpu_worker.py:submit_embedding_sync() — lock + _running check No enqueue after stop TestSubmitLockRace::test_submit_embedding_sync_after_stop_raises_shutting_down + test_concurrent_stop_and_submit_embedding_sync_no_enqueue PASS

Closes #8686

by AI for @beastoin

beastoin and others added 3 commits June 30, 2026 10:00
…ng GPU work

Adopts NeMo PR #13 approach: tracks active GPU batches with a counter.
The flush_loop timer only fires when _batches_inflight == 0, preventing
batch=1 spam while still allowing full-batch dispatches to use the
second inflight slot. Restores the early _flush_pending reset after
dequeue (safe now with the counter guard).

Closes #8686 (part 1/2)

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Wraps stop() and all submit*() methods with a threading.Lock so that
_running=False is set atomically before any concurrent submit can
enqueue work to a dead queue. Prevents the race where stop() sets
_running=False while submit() is between the ready check and queue.put.

Closes #8686 (part 2/2)

Co-Authored-By: Claude Opus 4.6 <[email protected]>
- OOM path: verify _batches_inflight resets to 0 after CUDA OOM
- Empty pending: verify counter resets when flush finds no work
- Concurrent submit_sync + stop: race test for sync submit path
- Concurrent submit_embedding_sync + stop: race test for embedding path

Co-Authored-By: Claude Opus 4.6 <[email protected]>

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 issues found across 6 files

Confidence score: 4/5

  • In backend/tests/unit/test_gpu_worker_submit_lock.py, the test reads worker._running outside the lock after submit(), which creates a TOCTOU window and can cause flaky pass/fail behavior in concurrent runs—move the state check under the same lock (or assert via a synchronized signal) before merging.
  • In backend/tests/unit/test_gpu_worker_submit_lock.py, submitter threads collect exceptions in errors but never assert it stays empty, so real thread failures could be silently missed and CI could report false confidence—add an explicit assert not errors after joining threads.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="backend/tests/unit/test_gpu_worker_submit_lock.py">

<violation number="1" location="backend/tests/unit/test_gpu_worker_submit_lock.py:89">
P2: TOCTOU race in concurrent test: reads worker._running outside the lock after submit() returns, creating false-positive flakiness.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

for _ in range(50):
try:
fut, item = worker.submit({"audio_paths": ["/tmp/x.wav"]}, loop)
if not worker._running and item is not None:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: TOCTOU race in concurrent test: reads worker._running outside the lock after submit() returns, creating false-positive flakiness.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At backend/tests/unit/test_gpu_worker_submit_lock.py, line 89:

<comment>TOCTOU race in concurrent test: reads worker._running outside the lock after submit() returns, creating false-positive flakiness.</comment>

<file context>
@@ -0,0 +1,116 @@
+            for _ in range(50):
+                try:
+                    fut, item = worker.submit({"audio_paths": ["/tmp/x.wav"]}, loop)
+                    if not worker._running and item is not None:
+                        enqueued_after_stop.append(True)
+                except Exception as e:
</file context>

- Sync/embedding race tests now assert no enqueue after stop
- Empty-pending test directly exercises _flush_batch early return branch

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@beastoin

Copy link
Copy Markdown
Collaborator Author

GPU Live Test Evidence (L4) — by @zen

Pod: parakeet-bench-pr8688 (L4 GPU, gcr.io/based-hardware-dev/parakeet:be73da3)
Branch: fix/adopt-nemo-pr13-lifecycle-8686

Results

Check Result
Server startup (batch + stream models) CLEAN — no errors
Single request transcription PASS
Concurrent load (100 requests, 0 failures) PASS
Batch metrics (101 reqs → 63 batches) Batching works
Server logs during load 0 errors/exceptions

Concurrency Scaling

Conc OK Fail Wall(s) p50(s) p99(s) RPS Result
1 20 0 6.09 0.270 0.922 3.3 PASS
2 20 0 3.10 0.270 0.661 6.4 PASS
4 20 0 3.51 0.431 1.314 5.7 PASS
8 20 0 1.77 0.691 1.238 11.3 PASS
16 20 0 1.97 1.229 1.789 10.1 PASS

_batches_inflight counter and _submit_lock working correctly under load. Safe to merge.

by AI for @beastoin

@beastoin beastoin left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@beastoin
beastoin merged commit b6a75bf into main Jun 30, 2026
7 checks passed
@beastoin
beastoin deleted the fix/adopt-nemo-pr13-lifecycle-8686 branch June 30, 2026 11:34
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.

Adopt NeMo PR #13 gpu_worker lifecycle fixes + batches_inflight for parakeet

1 participant