Skip to content

Core: a core that stops being master disengages what was engaged on it, and its RCS balancer gives the thrusters back - #2818

Merged
sarbian merged 2 commits into
devfrom
fix/core-master-handover
Nov 29, 2026
Merged

sarbian merged 2 commits into
devfrom
fix/core-master-handover

Conversation

@sarbian

@sarbian sarbian commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

Part of #2471 (audit epic, CORE); #2472 (audit epic, CTRL): HCORE-a2, HCTRL-a5 (Medium).

Summary

2 commits, 2 files changed.

Core: a core that stops being master disengages what was engaged on it, and its RCS balancer gives the thrusters back

The master core is the first running one in the vessel's part order. A core that stops being master (its ship docks to a station whose core comes first, or the player turns its MechJeb toggle off) gets no FixedUpdate or Drive any more, but nothing disengaged its modules: they stayed enabled with their users, frozen, and ran again when the core was master once more. After an undock, the ship's SmartASS, Translatron or rover hold turned the ship that the player had left beside the station, and the RCS balancer left the thrusters it had throttled at their last throttles for the rest of the session. The new master's balancer then took those throttled values as the originals.

When a core finds it is no longer master, it now removes every user other than the module itself from its modules, so each engaged module goes through its own disable path, and calls OnControlLost on them. The balancer restores its thrusters there and wraps them again if the core becomes master again. After a change of parts the balancer wraps the thrusters on the next tick: after a dock the new master's balancer runs before the old master's in that tick, while the old one still has its thrusters throttled, and it would take those throttles as the originals. On the next tick the old one has given them back.

The Utilities window's Autostage toggle is that window as a user of the staging controller, and the window saves it from that membership, so the release leaves that user in place: otherwise a core docked behind another one would save Autostage as off. The staging controller of a core that is not master does not run, so it does not stage meanwhile. The landing predictions toggle is not saved, so it is released with the rest.

Core: every core keeps its own local settings in the save, not only the master

Only the master core wrote its MechJebLocalSettings node into the save. A ship docked behind a station's core, saved and loaded, came back with its core's local settings at the part's defaults: SmartASS mode and target, rover heading, thrust limits, docking distances and flight recorder marks were lost for good, and showed when the ship undocked and its core was master again.

A core that is not master now still writes its local settings into the save. Only the master writes the global and vessel type files, as before.

Tested

MechJeb2_UI Spike 83 (KSP 1.12.5, 3.2x system, KSPCommunityFixes, MechJeb -c Debug), dev b85bdac against test/opus-medium, on the Mac: DockTug-light (two cores) docked to MJ Test Station, undocked, then the tug's master core switched off with the MechJeb toggle while its RCS balancer throttles.

former master engaged after the dock after the handover thrusters still throttled 2 s after
dev attitude controller thrust controller 2 of 8
this branch nothing nothing 0 of 8

The flowMult check right at the couple was inconclusive (the balanced tug had nothing throttled then). The local-settings commit was not tested in game.

These runs were on an earlier version of the branch, before its rebase on dev 6959f7c and before the balancer's next-tick wrap; the current head is built (Debug, no new warnings, MechJebLibTest passes) but not flown.

…t, and its RCS balancer gives the thrusters back

The master core is the first running one in the vessel's part order. A core that stops being master (its ship docks to a station whose core comes first, or the player turns its MechJeb toggle off) gets no FixedUpdate or Drive any more, but nothing disengaged its modules: they stayed enabled with their users, frozen, and ran again when the core was master once more. After an undock, the ship's SmartASS, Translatron or rover hold turned the ship that the player had left beside the station, and the RCS balancer left the thrusters it had throttled at their last throttles for the rest of the session. The new master's balancer then took those throttled values as the originals.

When a core finds it is no longer master, it now removes every user other than the module itself from its modules, so each engaged module goes through its own disable path, and calls OnControlLost on them. The balancer restores its thrusters there and wraps them again if the core becomes master again. After a change of parts the balancer wraps the thrusters on the next tick: after a dock the new master's balancer runs before the old master's in that tick, while the old one still has its thrusters throttled, and on the next tick it has given them back.

The Utilities window's Autostage toggle is that window as a user of the staging controller, and the window saves it from that membership, so the release leaves that user in place: otherwise a core docked behind another one would save Autostage as off. The staging controller of a core that is not master does not run, so it does not stage meanwhile. The landing predictions toggle is not saved, so it is released with the rest.
…he master

Only the master core wrote its MechJebLocalSettings node into the save. A ship docked behind a station's core, saved and loaded, came back with its core's local settings at the part's defaults: SmartASS mode and target, rover heading, thrust limits, docking distances and flight recorder marks were lost for good, and showed when the ship undocked and its core was master again.

A core that is not master now still writes its local settings into the save. Only the master writes the global and vessel type files, as before.
@github-actions

Copy link
Copy Markdown
Contributor

✅ Build Artifact 🚀

MechJeb2-18c70f5.zip (built from 255d0aa)

@sarbian
sarbian merged commit 2597e23 into dev Nov 29, 2026
3 checks passed
@sarbian
sarbian deleted the fix/core-master-handover branch November 29, 2026 20:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant