Repository navigation
Adopt NeMo PR #13 lifecycle improvements for parakeet server - #8688
Merged
Merged
Conversation
…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]>
There was a problem hiding this comment.
2 issues found across 6 files
Confidence score: 4/5
- In
backend/tests/unit/test_gpu_worker_submit_lock.py, the test readsworker._runningoutside the lock aftersubmit(), 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 inerrorsbut never assert it stays empty, so real thread failures could be silently missed and CI could report false confidence—add an explicitassert not errorsafter 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: |
There was a problem hiding this comment.
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]>
7 tasks
Collaborator
Author
GPU Live Test Evidence (L4) — by @zenPod: Results
Concurrency Scaling
by AI for @beastoin |
This was referenced Jun 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adopts two key improvements from beastoin/NeMo#13 into the omi parakeet server:
_batches_inflightcounter (batch_engine.py) — Replaces the_flush_pendingflag-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_pendingreset after dequeue is restored (safe with the counter guard)._submit_lock(gpu_worker.py) — Adds athreading.Lockto prevent the stop/submit race condition wherestop()sets_running=Falsewhilesubmit()is between the ready check andqueue.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_inflightcounter in__init__, flush loop guard,_flush_batch()increment/decrement, restored early_flush_pendingresetbackend/parakeet/gpu_worker.py: Added_submit_lock, wrappedstop()and allsubmit*()methodsbackend/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=Truebackend/test.sh: Wired new test fileTest plan
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)backend/test.shpasses (only pre-existing unrelated failure intest_file_upload_endpoint_security.py)test_flush_pending_batch1.pystill passes with the counter approachTest detail table
batch_engine.py:__init__—_batches_inflight=0pytest tests/unit/test_parakeet_batch_engine.py::TestBatchesInflight -vbatch_engine.py:_flush_loop—_batches_inflight==0guardTestBatchesInflight::test_timer_flush_blocked_during_inflightbatch_engine.py:_flush_batch— increment after sem acquireTestBatchesInflight::test_full_batch_uses_second_inflight_slotbatch_engine.py:_flush_batch—_flush_pending=FalserestoreTestFlushPendingBatch1Regressionbatch_engine.py:_flush_batch— decrement in finallyTestBatchesInflight::test_batches_inflight_resets_after_gpu_error+test_batches_inflight_resets_after_oomgpu_worker.py:__init__—_submit_lockgpu_worker.py:stop()— set_running=Falseunder lockTestSubmitLockRace::test_stop_sets_running_false_atomicallygpu_worker.py:submit()— lock +_runningcheckTestSubmitLockRace::test_submit_after_stop_raises_shutting_down+test_concurrent_stop_and_submit_no_enqueue_to_dead_queuegpu_worker.py:submit_sync()— lock +_runningcheckTestSubmitLockRace::test_submit_sync_after_stop_raises_shutting_down+test_concurrent_stop_and_submit_sync_no_enqueuegpu_worker.py:submit_embedding_sync()— lock +_runningcheckTestSubmitLockRace::test_submit_embedding_sync_after_stop_raises_shutting_down+test_concurrent_stop_and_submit_embedding_sync_no_enqueueCloses #8686
by AI for @beastoin