Fix LAN Bambu printer losing its connection when the cloud server connects (#17769)

The server-connected handler selects the agent's current machine again every time the cloud
server connects. For a LAN printer this makes the Bambu network plug-in unsubscribe the device,
which drops the LAN session that selecting the printer opened. A connect still in flight fails
with "called UnSubscribeDevice". One that already succeeded stays down with no connect result, so
the printer shows as connected while every command fails with -4 and Print fails with -4030.

Since #17086, OrcaSlicer connects the last LAN Bambu printer at startup, so a LAN user hits this
on most starts. A cloud reconnect later in a session drops the session the same way.

The selection is a cloud subscription, so a LAN printer does not need it. Move the re-select into
DeviceManager::reselect_cloud_machine(), which skips a LAN-mode printer and behaves as before for
any other machine.

Fixes #17766
This commit is contained in:
Alexander Vander Kelen authored and GitHub committed 2026-11-21 13:01:33 -06:00
1 parent f2eb53ebaa
commit a8a597c6d5
4 files changed
+62 -2

No files matched your search

@@ -70,9 +70,16 @@ public:
return 0;
}
int set_user_selected_machine(std::string dev_id) override
{
++selections;
return OrcaPrinterAgent::set_user_selected_machine(std::move(dev_id));
}
std::string published_device;
json published_message;
std::string connected_ca_file;
int selections{0};
private:
AgentInfo m_info;
@@ -277,6 +284,37 @@ TEST_CASE("Logging out cancels a pending last-machine restore", "[DeviceManager]
CHECK_FALSE(manager.has_pending_last_machine_restore());
}
TEST_CASE("A cloud server connection selects a cloud printer again but leaves a LAN printer alone", "[DeviceManager][integration]")
{
ScopedAppConfig app_config;
auto agent = std::make_shared<TestPrinterAgent>("integration-agent");
NetworkAgent network(nullptr, agent);
network.set_printer_agent(agent);
DeviceManager manager(&network, false, &app_config.config);
BBLocalMachine machine;
machine.dev_id = "integration-lan-device";
machine.dev_name = "Integration LAN device";
machine.dev_ip = "192.0.2.10";
machine.printer_type = "C11";
REQUIRE(manager.insert_local_device(machine, "lan", "free", "", "access-code") != nullptr);
manager.parse_user_print_info(machine_list_response(ORCA_CLOUD_PROVIDER, "integration-agent",
network.get_user_machine_list_generation(), "Cloud printer"));
REQUIRE(manager.get_user_machinelist().count("integration-device") == 1);
// The agent names the LAN printer once it is connected, as the Bambu network plugin does.
agent->set_user_selected_machine(machine.dev_id);
agent->selections = 0;
manager.reselect_cloud_machine();
CHECK(agent->selections == 0);
agent->set_user_selected_machine("integration-device");
agent->selections = 0;
manager.reselect_cloud_machine();
CHECK(agent->selections == 1);
CHECK(agent->get_user_selected_machine() == "integration-device");
}
TEST_CASE("A CA file stays with the agent that saved it when a device is rebound", "[DeviceManager][integration]")
{
ScopedAppConfig app_config;