Skip to content

Stop the mixer save when the flight controller refuses a servo rule - #2871

Open
sensei-hacker wants to merge 2 commits into
iNavFlight:maintenance-9.xfrom
sensei-hacker:servo-mixer-save-refused
Open

sensei-hacker wants to merge 2 commits into
iNavFlight:maintenance-9.xfrom
sensei-hacker:servo-mixer-save-refused

Conversation

@sensei-hacker

Copy link
Copy Markdown
Member

Pairs with the firmware PRs iNavFlight/inav#12284 (release/9.1) and iNavFlight/inav#12285 (maintenance-10.x). With those, the FC answers MSP2_INAV_SET_SERVO_MIXER with an MSP error when a servo rule uses an input the board doesn't support, such as RC channel 19–34 on a 512 KB board.

Problem

The configurator never looked at MSP error replies. The decoder sets unsupported when the FC replies $X!, but callbacks never received that flag.

So when the FC refused a servo rule, the Mixer tab carried on: it wrote the EEPROM, rebooted, and the rule was gone. Nothing told the user.

Changes

  • MSP callbacks now get error: true when the FC's reply was an error. Nothing changes on the wire, and existing callbacks ignore the extra field.

  • sendServoMixer still sends every rule. If the FC refused any, it:

    • logs each refused rule with its number and input name;
    • opens a "Mixer not saved" dialog;
    • stops before the EEPROM write and the reboot.

    An optional second callback tells the caller about the refusal.

  • Defaults dialog: if a rule is refused while a preset is being applied, it uses that callback to close its progress window, so the dialog isn't left stuck.

On firmware without #12284/#12285 the FC never refuses a servo rule, so nothing changes there.

Testing

  • New test: tests/servo-mixer-save-refused.test.mjs runs the real MSPHelper.js. It covers all rules accepted, one or two rules refused, the last rule refused, the refusal callback, and the error flag reaching callbacks. Five of its six cases fail on the old code; the all-accepted case passes on both.
  • Existing test: tests/msp-parse-failure-recovery.test.mjs gets a stub for the new jbox import.
  • npm test: all pass.
  • On SITL, through the Mixer tab's Save button:
Firmware Rules Result
#12284, no 34-channel support one rule with RC Channel 20 Log line and dialog, no EEPROM write or reboot, still connected
#12284, no 34-channel support inputs 0–43 Saved and rebooted, all rules read back
#12284 + #12281 (34-channel SITL) 36 rules, inputs 0–59 Saved and rebooted, all rules read back
Unmodified release/9.1 inputs 36–59 Saved and rebooted, all rules read back

The defaults-dialog refusal path is covered only by the unit test, because no preset uses RC channel 19–34.

The FC answers MSP2_INAV_SET_SERVO_MIXER with an MSP error when a rule
uses an input the board doesn't support, such as RC channel 19-34 on a
512 KB board. The configurator never looked at error replies, so the
save went on to write the EEPROM and reboot, and the rule was silently
dropped.

MSP callbacks now get the reply's error flag. sendServoMixer still sends
every rule, then names each refused one in the log and a dialog, and
stops the save before the EEPROM write and reboot. The defaults dialog
closes its progress window when that happens.
@sensei-hacker sensei-hacker added this to the 9.1.2 milestone Dec 6, 2026
@qodo-code-review

Copy link
Copy Markdown
Contributor

ⓘ Qodo reviews are paused because the subscription is no longer active. Ask your workspace admin to reactivate the subscription to resume reviews. Manage billing

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Dec 6, 2026 •

Copy link
Copy Markdown

PR Summary by Qodo

Stop mixer save when FC refuses a servo rule

🐞 Bug fix 🧪 Tests 🕐 20-40 Minutes

Grey Divider

AI Description

• Servo mixer save no longer writes EEPROM or reboots when the FC refuses any rule.
• Refused rules are logged by number and input name, and a "Mixer not saved" dialog opens.
• MSP callbacks receive error: true on FC error replies; the wire protocol is unchanged.
Merge Risk 🟡 Medium

Blast radius 🟡 Medium 💥 2 capabilities

  • 2 affected capabilities within one bounded functional scope: flight-controller-mixer-configuration-workflows.
  • The changed helper is consumed by the mixer tab's end-to-end save chain, where servo rules precede timer/settings persistence and reboot.
  • This is one bounded mixer-configuration integration, not an independent capability per helper or protocol hop.
  • The defaults dialog is a separate user operation within the same bounded flight-controller configuration integration: it applies preset settings and mixer rules, then selects profiles and persists configuration.
  • It is distinct from the mixer tab save operation because its user outcome is preset adoption and retryability after refusal, not ordinary mixer saving.
Behavioral complexity 🔴 High 🧩 State transitions, Coordinated invariants

  • Before, a refused servo step could terminate the preset flow without an explicit restoration sequence.
  • After, refusal enters a three-step ordered chain: restore control profile, restore battery profile, then clear applied_defaults before closing UI and resuming updates.
  • The new correctness condition is that partial preset changes, selected profiles, the retry marker, modal state, and updater state remain coherent across each interruption point.
Potential damage 🟡 Medium 🩹 Incorrect results

  • If this capability regresses, accepted servo rules could be applied without a coherent completed save, or a refusal could be mishandled and leave a partially applied mixer.
  • The source supports stopping before EEPROM save and reboot on detected refusals, but a failed capability still requires the user to correct or remove the refused rule and save again.
  • Reverting code stops new behavior but does not automatically repair any already stored or active mixer state.
  • Recoverable by correcting/removing unsupported rules and saving again; no automatic repair or compensation path is shown.
Assessed commit cde5aea
Diagram

sequenceDiagram
    participant Mixer as Mixer tab / Defaults
    participant Helper as MSPHelper.sendServoMixer
    participant FC as Flight controller
    participant User as User
    Mixer->>Helper: save (sendServoMixer)
    loop each servo rule
        Helper->>FC: MSP2_INAV_SET_SERVO_MIXER
        FC-->>Helper: reply (error flag if refused)
    end
    alt any rule refused
        Helper->>User: GUI.log per rule + Mixer not saved modal
        Helper-->>Mixer: onRefused (stop, no EEPROM write or reboot)
    else all accepted
        Helper-->>Mixer: onComplete
        Mixer->>FC: EEPROM write and reboot
    end
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Pre-validate servo rule inputs in the configurator
  • ➕ Catches unsupported inputs before any MSP traffic
  • ➕ Could show the problem inline in the Mixer tab
  • ➖ Duplicates firmware input limits in the configurator and needs upkeep per firmware version
  • ➖ Board capability (RAM/flash, channel count) is not always known to the configurator
  • ➖ Old firmware would still need the refusal path

Recommendation: Keep the firmware-reported refusal as the source of truth and handle it in the configurator. The alternative is to validate inputs client-side against board capabilities before sending. That would duplicate firmware limits and would need board-capability data the configurator may not have, so the PR's approach is the better fit. Client-side pre-validation could still be added later as a UX improvement.

Files changed (5) +335 / -11

Enhancement (1) +9 / -0
messages.jsonAdd English strings for refused servo mixer rules +9/-0

Add English strings for refused servo mixer rules

• Adds servoMixerRuleRefused (rule number and input name), servoMixerNotSavedTitle, and servoMixerNotSaved. The last one explains that the settings were not written and the FC was not rebooted.

locale/en/messages.json

Bug fix (2) +52 / -11
MSPHelper.jsPass FC error flag to callbacks and stop servo mixer save on refusal +45/-10

Pass FC error flag to callbacks and stop servo mixer save on refusal

• completeRequest now adds 'error: dataHandler.unsupported === 1' to callback payloads. sendServoMixer sends every rule, counts refused ones through onReply, and then either calls onCompleteCallback or, if any were refused, logs each one, opens a jBox modal, and calls the new optional onRefused callback. The jbox import was added for the modal.

js/msp/MSPHelper.js

defaults_dialog.jsClose defaults progress window when servo mixer is refused +7/-1

Close defaults progress window when servo mixer is refused

• The servo mixer step in the preset chain now passes an onRefused callback. On refusal it closes the saving modal, resumes the periodic status updater, and shows the container, so the dialog is not left stuck.

js/defaults_dialog.js

Tests (2) +274 / -0
msp-parse-failure-recovery.test.mjsStub the new jbox import in the parse-failure recovery test +1/-0

Stub the new jbox import in the parse-failure recovery test

• Adds a rewrite rule that replaces the jbox import in MSPHelper.js with an inert module, so the existing test can still load the file.

tests/msp-parse-failure-recovery.test.mjs

servo-mixer-save-refused.test.mjsAdd regression tests for refused servo mixer saves +273/-0

Add regression tests for refused servo mixer saves

• Runs the real MSPHelper.js, msp.js, servoMixRule.js and the rule collection against a stubbed MSP.send_message. Covers all accepted, one, two and last-rule refusals, the refusal callback, and the error flag through the real handleResponse path.

tests/servo-mixer-save-refused.test.mjs

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Dec 6, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (1) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Action required

1. Refused presets switch the active profiles ✓ Resolved Bug Correctness

Resolving commit: cde5aea

Resolution reason
On servo-mixer refusal, the dialog now re-selects the previously active control and battery profiles
(via abandonPreset) before closing the modal, and clears applied_defaults so the dialog reappears;
EEPROM save and reboot remain suppressed.
Description
The defaults-dialog refusal handler closes the progress window without restoring the control and
battery profiles selected before setSettings began. When a preset's servo rule is refused, the
earlier profile loop has left both profiles at index 2, and the chain stops before its queued
restoration steps run.


Remediation recommended

2. An incomplete preset hides the defaults ✓ Resolved Bug Correctness

Resolving commit: cde5aea

Resolution reason
On the servo-mixer refusal path, the handler now calls
privateScope.abandonPreset(currentControlProfile, currentBatteryProfile), which re-selects the
previous control and battery profiles and writes applied_defaults to 0 via mspHelper.setSetting
before closing the modal, resuming the status updater and showing the container again. This clears
the marker so the dialog is not hidden on reconnect. It differs from the suggested fix only in that
it restores the profiles too and is implemented as a helper chain rather than inline; the core
concern (the success marker stays in FC memory after a refused preset) is resolved.
Description
The new refusal handler restores the dialog UI but leaves the earlier applied_defaults setting in
flight-controller memory. When a preset rule is refused and the configurator reconnects without a
controller reset, init() sees that nonzero marker and skips the defaults dialog even though the
preset chain never finished.

3. A refused save leaves live mixer changes 🐞 Bug ≡ Correctness
Description
sendServoMixer continues sending rules after a refusal, then suppresses the completion callback
without restoring rules the controller accepted. When an earlier rule is refused, accepted rules
remain changed in the controller's live mixer while EEPROM retains the old configuration and the
promised reboot does not occur.
Code

js/msp/MSPHelper.js[R2452-2455]

+            if (servoIndex < FC.SERVO_RULES.getServoRulesCount()) {
+                sendMixer();
+            } else if (refusedRules.length > 0) {
+                reportRefusedServoRules(refusedRules);
Evidence
Each rule is sent as a write, including those following an error reply. The refusal branch prevents
the Mixer save chain from reaching its EEPROM write and reboot, so accepted writes are not cleared
by that reboot.

js/msp/MSPHelper.js[2448-2460]
js/msp/MSPHelper.js[2479-2482]
tabs/mixer.js[50-70]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
A refused rule stops persistence and reboot, but accepted servo-rule writes remain active in controller memory, including rules sent after the refusal.
## Fix Focus Areas
- js/msp/MSPHelper.js[2448-2460]
- js/msp/MSPHelper.js[2479-2482]
## Recommended Fix
Add an explicit recovery path for a rejected batch that restores the previously active mixer in controller memory. Preserve the refusal report and do not persist the rejected configuration.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Tip of the day
💡 Did you know, you can start a comment with 'qodo' or '@qodo' to chat about any finding

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@github-actions

github-actions Bot commented Dec 6, 2026 •

Copy link
Copy Markdown

Configurator test build ready — commit cde5aea

Download build artifacts for PR #2871

Available platforms (scroll to the Artifacts section at the bottom of the run page):

  • Windows x64 (ZIP, MSI) and x32 (ZIP, MSI)
  • macOS arm64 (ZIP, DMG) and x64 (ZIP, DMG)
  • Linux x64 (DEB, RPM, ZIP) and aarch64 (DEB, RPM, ZIP)

A GitHub login is required to download artifacts. Build is for testing only.

Applying a preset switches through every control and battery profile and
sets applied_defaults before it sends the mixer. When the flight
controller refuses a servo rule, the defaults dialog now selects the
profiles that were active before and sets applied_defaults back to 0, so
the dialog is offered again on the next connection.

The refusal message now says the flight controller keeps using the rules
it accepted until it reboots.

The MSPHelper test setup that two tests had copied is one helper,
tests/helpers/mspHelperLoader.mjs.
@sonarqubecloud

sonarqubecloud Bot commented Dec 6, 2026

Copy link
Copy Markdown

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant