Repository navigation
requesthandler: Keep Parallel batch results in request order - #13
Merged
Merged
Conversation
A RequestBatch with executionType Parallel runs each request as its own thread-pool task, and each task appended its result when it finished, so the results came back in completion order. The protocol layer labels results[i] with the requestType and requestId of requests[i], so with a slow request first (a full-size GetSourceScreenshot) and fast ones after it every result was attached to another request (upstream obsproject/obs-websocket#1317). The results vector now has one slot per request and each task writes to its request's index; the batch waits for a finished count instead of the vector's size. Parallel results now come back in request order, as serial batches already do. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
zackees
approved these changes
Oct 16, 2026
zackees
left a comment
Member
There was a problem hiding this comment.
Reviewed the diff. Each Parallel task now writes to results[i] under the mutex and the batch waits on a finished count, so results line up with requests[i] as WebSocketServer_Protocol.cpp expects. Empty batch still returns at once (0 == 0), serial modes untouched, lambda captures i by value and request by reference into a vector that is not resized. The RED/GREEN evidence (test_ws_batch_order, 3 of 5 fail before, 5 of 5 after) lives in the obs-studio PR, which is still to come; the fork has no test lane beyond markdown lint.
5 of 6 tasks
5 of 6 tasks
5 tasks done
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.
A RequestBatch with
executionType: 2(Parallel) runs each request as its own thread-pool task, and each task appended its result when it finished (RequestBatchHandler.cppline 217), so the results came back in completion order.WebSocketServer_Protocol.cpp(lines 336-339) labelsresults[i]with therequestTypeandrequestIdofrequests[i], so a batch with a slow request first (a full-sizeGetSourceScreenshot) and quick ones after it returned every result under another request's label (upstream obsproject/obs-websocket#1317, reported by wesbos). Clients that match results byrequestIdread the wrong data.The results vector now has one slot per request, each task writes its result at its request's index, and the batch waits for a finished count instead of the vector's size. Parallel results now come back in request order, as SerialRealtime and SerialFrame batches already do. The serial modes are unchanged.
Tested in obs-rust/obs-studio with
test_ws_batch_order(3 of 5 fail before, 5 of 5 pass after, both libobs lanes), in a full OBS build (frontend + obs-websocket) in both lanes, and end to end over obs-websocket: the release returns 20 of 20 Parallel batches mislabelled, a build with this commit 0 of 20.Refs obs-rust/obs-studio#813. The obs-rust/obs-studio PR that moves the submodule to this commit carries the regression test and closes the issue.
🤖 Generated with Claude Code