Skip to content

fix(cli): suppress MSP garbage before CLI welcome message#613

Merged
nerdCopter merged 1 commit into
emuflight:masterfrom
nerdCopter:fix/efc-cli-suppress-garbage
Jun 23, 2026
Merged

fix(cli): suppress MSP garbage before CLI welcome message#613
nerdCopter merged 1 commit into
emuflight:masterfrom
nerdCopter:fix/efc-cli-suppress-garbage

Conversation

@nerdCopter

@nerdCopter nerdCopter commented Jun 23, 2026

Copy link
Copy Markdown
Member

AI Generated pull-request

Summary

  • Before this fix, every byte received while CONFIGURATOR.cliValid was false was written directly to the CLI output display via writeToOutput(currentChar). Buffered MSP response frames (e.g. repeated MSP_BOXNAMES polls from a previous tab) appeared as binary garbage characters before "Entering CLI Mode" on every CLI tab open.
  • Fix: accumulate bytes silently until 'CLI' is found in the welcome message, then display only from 'Entering CLI Mode' onwards. MSP frames queued before the welcome message are discarded from the display without affecting serial communication or protocol state.
  • The garbage became more visible recently as more firmware features were enabled (more/larger MSP responses buffered during initial connection), surfacing this latent display bug.
  • Possible side-effect: may also stabilise the autocomplete cache build, which begins immediately after cliValid transitions to true.

Test plan

  • Open CLI tab — no MSP binary garbage appears before "Entering CLI Mode, type 'exit' to return, or 'help'"
  • Welcome message and # prompt display correctly
  • Autocomplete builds normally after connection
  • exit and reconnect cycle works correctly
  • Hardware verified: HELIOSPRING (F405)

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced CLI initialization to filter extraneous startup text and properly display the welcome message and command prompt.

When the CLI tab opens, buffered MSP response frames (e.g. repeated
MSP_BOXNAMES polls from the previous tab) were displayed as binary
garbage because every incoming byte was written to the output display
while CONFIGURATOR.cliValid was false.

Fix: accumulate bytes silently until 'CLI' is found in the welcome
message, then display only from 'Entering CLI Mode' onwards. MSP
frames queued before the welcome message are discarded from the
display without affecting serial communication.

More visible after recent firmware PRs because more enabled features
→ more/larger MSP responses buffered during initial connection.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jun 23, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

In TABS.cli.read, pre-CLI characters are now silently accumulated into validateText instead of being written to the output UI when cliValid is false. After CLI entry is confirmed, only the welcome text from the "Entering CLI" marker onward is extracted, split by line, and written to the output with correct <br> handling.

Changes

CLI pre-entry output suppression and welcome rendering

Layer / File(s) Summary
Silent buffering and welcome message rendering
src/js/tabs/cli.js
While CONFIGURATOR.cliValid is false, incoming characters are buffered in validateText without any UI write. Once CLI entry is detected, the substring starting at "Entering CLI" is extracted, split on CR/LF variants, and written line-by-line via writeLineToOutput; the final prompt line is written via writeToOutput to suppress a trailing <br>.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix(cli): suppress MSP garbage before CLI welcome message' directly and clearly describes the main change: suppressing binary garbage from MSP responses that appeared before the CLI welcome message. It accurately reflects the primary objective of the PR.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/js/tabs/cli.js (1)

465-490: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Gate cliValid transition on confirmed welcome marker

At Line 467, CONFIGURATOR.cliValid flips to true before confirming Entering CLI exists. If a chunk contains "CLI" but not the full welcome marker, state transitions early, welcome rendering is skipped, and autocomplete may start from an invalid state.

Proposed fix
 if (!CONFIGURATOR.cliValid && validateText.indexOf('CLI') !== -1) {
-    GUI.log(i18n.getMessage('cliEnter'));
-    CONFIGURATOR.cliValid = true;
-    // Display only from 'Entering CLI Mode' onwards; MSP garbage before it is discarded
-    const cliMsgStart = validateText.indexOf('Entering CLI');
-    if (cliMsgStart >= 0) {
+    // Display only from 'Entering CLI Mode' onwards; MSP garbage before it is discarded
+    const cliMsgStart = validateText.indexOf('Entering CLI');
+    if (cliMsgStart >= 0) {
+        GUI.log(i18n.getMessage('cliEnter'));
+        CONFIGURATOR.cliValid = true;
         const welcomeText = validateText.substring(cliMsgStart);
         const lines = welcomeText.split(/\r?\n|\r/);
         for (let j = 0; j < lines.length; j++) {
             if (j < lines.length - 1) {
                 writeLineToOutput(lines[j]);
             } else if (lines[j].length > 0) {
                 writeToOutput(lines[j]); // prompt line — no trailing <br>
             }
         }
-    }
-    // begin output history with the prompt (last line of welcome message)
-    // this is to match the content of the history with what the user sees on this tab
-    const lastLine = validateText.split("\n").pop();
-    this.outputHistory = lastLine;
-    validateText = "";
-
-    if (CliAutoComplete.isEnabled() && !CliAutoComplete.isBuilding()) {
-        // start building autoComplete
-        CliAutoComplete.builderStart();
+        // begin output history with the prompt (last line of welcome message)
+        // this is to match the content of the history with what the user sees on this tab
+        const lastLine = welcomeText.split(/\r?\n|\r/).pop();
+        this.outputHistory = lastLine;
+        validateText = "";
+
+        if (CliAutoComplete.isEnabled() && !CliAutoComplete.isBuilding()) {
+            // start building autoComplete
+            CliAutoComplete.builderStart();
+        }
     }
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/js/tabs/cli.js` around lines 465 - 490, The `CONFIGURATOR.cliValid` flag
is set to true immediately after checking for "CLI" in the validateText, but
before confirming that the full "Entering CLI" welcome marker actually exists.
Move the `CONFIGURATOR.cliValid = true;` assignment to execute only after the
condition `if (cliMsgStart >= 0)` is confirmed true, ensuring the cliValid state
transitions only when the complete welcome marker is actually found and
processed.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@src/js/tabs/cli.js`:
- Around line 465-490: The `CONFIGURATOR.cliValid` flag is set to true
immediately after checking for "CLI" in the validateText, but before confirming
that the full "Entering CLI" welcome marker actually exists. Move the
`CONFIGURATOR.cliValid = true;` assignment to execute only after the condition
`if (cliMsgStart >= 0)` is confirmed true, ensuring the cliValid state
transitions only when the complete welcome marker is actually found and
processed.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4d38b52c-11d6-484b-ab3e-3a442e2e718b

📥 Commits

Reviewing files that changed from the base of the PR and between 8b20614 and 0e65fef.

📒 Files selected for processing (1)
  • src/js/tabs/cli.js
📜 Review details
⏰ Context from checks skipped due to timeout. (6)
  • GitHub Check: build (ubuntu-24.04, linux-x64)
  • GitHub Check: build (macos-26-intel, macos-x86_64)
  • GitHub Check: build (windows-2022, windows-x64, x64)
  • GitHub Check: build (macos-26, macos-arm64)
  • GitHub Check: build (windows-2022, windows-ia32, ia32)
  • GitHub Check: Codacy Static Code Analysis
🔇 Additional comments (1)
src/js/tabs/cli.js (1)

406-409: LGTM!

@nerdCopter

Copy link
Copy Markdown
Member Author

@coderabbitai AI generated comment

Declining as proposed — the fix would introduce a regression.

The firmware has two welcome strings depending on compile flags:

#ifndef MINIMAL_CLI
    cliPrintLine("\r\nEntering CLI Mode, type 'exit' to return, or 'help'");
#else
    cliPrintLine("\r\nCLI");   // only "CLI" — no "Entering CLI"
#endif

Moving `cliValid = true` inside `if (cliMsgStart >= 0)` (where `cliMsgStart = indexOf('Entering CLI')`) means any MINIMAL_CLI firmware would never trigger the condition — `cliValid` stays `false` permanently, autocomplete never starts, CLI is broken for that variant.

The `indexOf('CLI')` gate is intentional and pre-existing (unchanged from the prior release). It correctly covers both firmware forms. The `indexOf('Entering CLI')` check added in this PR is display-only — it controls what text to render, not whether CLI mode is active. These are deliberately separate concerns.

@coderabbitai

coderabbitai Bot commented Jun 23, 2026

Copy link
Copy Markdown

Tip

For best results, initiate chat on the files or code changes.

@nerdCopter: You're absolutely right — that's a clear and complete explanation. I missed the MINIMAL_CLI firmware variant where the welcome string is just "CLI" with no "Entering CLI" prefix. Tying cliValid = true to indexOf('Entering CLI') would silently break CLI for that build target entirely. The two-level check — indexOf('CLI') for activation gating and indexOf('Entering CLI') for display trimming — is the correct design. Withdrawing the suggestion.

(ᓀ‸ᓂ)


✏️ Learnings added
Learnt from: nerdCopter
URL: https://github.com/emuflight/EmuConfigurator/pull/613

Timestamp: 2026-06-23T18:53:49.093Z
Learning: In EmuFlight firmware (src/js/tabs/cli.js), CLI welcome message detection must use `indexOf('CLI')` (not `indexOf('Entering CLI')`) as the activation gate for `cliValid`, because MINIMAL_CLI firmware only sends `"\r\nCLI"` while full firmware sends `"\r\nEntering CLI Mode, type 'exit' to return, or 'help'"`. Using `indexOf('Entering CLI')` for the activation gate would permanently break MINIMAL_CLI builds. The `indexOf('Entering CLI')` check in this PR is intentionally display-only — it controls which text to render to the output, not whether CLI mode is active. These are deliberately separate concerns.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

@nerdCopter nerdCopter merged commit 4f47350 into emuflight:master Jun 23, 2026
8 checks passed
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