Repository navigation
fix(machine): rebuild a cleaned-up driver instead of reusing it - #635
Merged
knipknap merged 2 commits intoOct 26, 2026
Merged
Conversation
Switching the active machine disconnects the previous one, which runs
driver.cleanup() and then queues rebuild_driver(). With the driver
class and arguments unchanged, rebuild_driver() asked the cleaned-up
driver to absorb the settings via update_settings(). A driver that
opts in (the Ruida adapter) accepted, so the machine kept a driver
whose backend had been released. Switching back to that machine then
failed every reconnect ("Direct mode requires the direct backend")
and its status stayed Unknown until Rayforge was restarted.
Only offer update_settings() to a driver that is still set up, so a
cleaned-up driver is always replaced by a fresh one.
medoix
force-pushed
the
fix/ruida-reconnect-after-switch
branch
from
October 26, 2026 03:17
eea8894 to
7ed051b
Compare
medoix
marked this pull request as ready for review
October 26, 2026 03:22
Contributor
|
Thanks for the fix! |
This branch was previously deployed
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.
What does this PR change?
Switching the active machine away from a Ruida machine and back left it stuck at status Unknown. Every reconnect attempt failed with
RPA reconnect attempt failed: Direct mode requires the direct backenduntil Rayforge was restarted (or TUI mode was toggled to force a rebuild).The cause is in
MachineController.MachineManager.set_active_machine()disconnects the previous machine, andcontroller.disconnect()runsdriver.cleanup()and then queuesrebuild_driver(). With the driver class and arguments unchanged,rebuild_driver()asked the cleaned-up driver to absorb the settings throughupdate_settings(). The Ruida adapter opts in, so it returned True and the machine kept a driver whose backendcleanup()had already released.rebuild_driver()now only offersupdate_settings()to a driver that is still set up (did_setup). A cleaned-up driver is always replaced by a fresh one, which is what the queued rebuild after a disconnect intends.Why did you choose this specific architectural approach?
did_setupis already the base driver's record of whethersetup()has run, andDriver.cleanup()clears it, so the controller can tell a live driver from a released one without knowing anything about the driver. That keeps the fix in the one place that decides between reuse and rebuild, and covers any driver that opts in toupdate_settings(), not only the Ruida adapter.Alternatives considered:
_backendis None. That fixes only one driver and leavesupdate_settings()accepting settings on an object that has been cleaned up.update_settings()return False after cleanup. Same problem: every opt-in driver would need the same guard.How did you manually test this locally?
Two Ruida lasers configured as separate machines: an RDC8445S over TCP (Wi-Fi) and an RDLC-V26.60.20 controller over UDP, both with auto-connect on.
Tests:
tests/machine/models/test_machine_controller.pygains a test that disconnects an opt-in driver and checks it is replaced rather than reused; it fails without the change. The machine and Ruida driver test folders pass apart fromtest_end_failed_carries_messageandtest_failed_job_reports_error_message, which fail the same way on unmodified main in my environment.Checklist
this code.