Repository navigation
Add controller API cancel_all_and_wait() - #1555
Merged
Merged
Conversation
Gin890
marked this pull request as ready for review
October 11, 2026 02:46
Mysticial
reviewed
Oct 11, 2026
Mysticial
reviewed
Oct 11, 2026
Gin890
marked this pull request as draft
October 17, 2026 05:31
Collaborator
Author
|
Tested using Claude Cloud to rewrite the PR. It cost $6 using Claude Opus 5.5 Extra effort. Quite expensive! I can't imagine how much I had used in my day job by now. I still need to read the rewritten PR to understand what the AI agent wrote |
Mysticial
approved these changes
Oct 17, 2026
Mysticial
left a comment
Collaborator
There was a problem hiding this comment.
Approved, but rename the function from wait_for_all_commands_cancelled() to cancel_all_and_wait().
wait_for_all_commands_cancelled()cancel_all_and_wait()
cancel_all_commands() only starts the cancellation: it returns as soon as the cancel request is handed to the connection, and the host marks its command queue empty at that moment, so waiting for the queue proves nothing. AbstractController::cancel_all_and_wait() cancels all commands and wait for it to ensure when the function returns the controller is now neutral Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Gin890
force-pushed
the
wait-all-cancel
branch
from
October 19, 2026 04:29
7b04289 to
a7dea34
Compare
Gin890
marked this pull request as ready for review
October 19, 2026 04:29
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.
cancel_all_commands()only starts the cancellation. It returns as soon as the cancel request is handed to the connection, and the host marks its command queue empty at that moment, so waiting for the queue proves nothing.AbstractController::cancel_all_and_wait(timeout)cancels, then blocks until the device acks the cancel or the timeout passes. Per review, it uses the PABotBase2 reliable connection'swait_for_pending()instead of a no-op and a timer thread.We didn't need to block on a cancel before because programs run serially and users can watch the result on the video capture screen. An AI agent needs the command and the in-game result to be accurately in sync to reduce its chance of making a mistake.
Changes
ReliableStreamConnectionPushing: exposewait_for_pending(timeout). The PABotBase2ReliableStreamConnectionalready implements it.CommandQueueManager::wait_for_cancel(timeout): ifsend_cancel()hit a full send buffer, the cancel is only stored and hasn't been sent yet. Keep retrying it until the timeout, then wait for the device to ack everything sent so far.AbstractController::cancel_all_and_wait()is now pure virtual:m_state_lockas before, then wait outside it.cqCancelhas no ack, so it cancels and returns false.PybindSwitchProController::cancel_all_and_wait(timeout_millis)forwards to it. It returns false if the controller is not ready.Semantics
Testing
CommandQueueManager::wait_for_cancel()was tested against a fake connection under ThreadSanitizer, with no races reported. The cases were:wait_for_all()being releasedGenerated by Claude Code