Skip to content

Conversation

@nicoschmdt
Copy link
Contributor

@nicoschmdt nicoschmdt commented Oct 28, 2025

fix: #2343

Had to add a timeout to ignore old mavlink messages and avoid having the store set up dated information regarding the autopilot firmware.

Tested going between the SITL board and the Navigator. The Change Board and Install Firmware code flow were both considered.

Summary by Sourcery

Add a timeout to filter out outdated MAVLink parameter messages after resets, refactor parameter storage indexing to use parameter names, and ensure the frontend store is reset when changing boards to trigger fresh parameter downloads.

Bug Fixes:

  • Ignore stale MAVLink parameter messages received within 500ms of a fetcher reset to prevent outdated autopilot data

Enhancements:

  • Use parameter names as keys in ParametersTable for direct lookups and simplify update logic
  • Trigger a reset of the autopilot parameters store in BoardChangeDialog to force re-download of parameters

@sourcery-ai
Copy link

sourcery-ai bot commented Oct 28, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Introduces a reset timestamp and message debounce in the ParameterFetcher to discard stale MAVLink parameters after a reset, refactors the ParametersTable to key entries by parameter name for direct updates, and triggers an autopilot store reset on board changes to force parameter re-download.

Sequence diagram for autopilot board change triggering parameter re-download

sequenceDiagram
actor User
participant "BoardChangeDialog.vue"
participant "autopilot_data (store)"
participant "ParameterFetcher"
User->>"BoardChangeDialog.vue": Initiate board change
"BoardChangeDialog.vue"->>"autopilot_data (store)": reset()
"autopilot_data (store)"->>"ParameterFetcher": reset()
"ParameterFetcher"->>"ParameterFetcher": reset_timestamp = performance.now()
"ParameterFetcher"->>"ParameterFetcher": Clear parameter table
Note over "ParameterFetcher": New parameters will be fetched
Loading

Entity relationship diagram for ParametersTable refactor

erDiagram
PARAMETERS_TABLE {
  string parametersDict
  boolean metadata_loaded
}
PARAMETER {
  string name
  number value
  string id
  Range range
  number default
}
PARAMETERS_TABLE ||--o{ PARAMETER : contains by name
Loading

Class diagram for updated ParameterFetcher and ParametersTable

classDiagram
class ParameterFetcher {
  - min_update_interval_ms: number
  - reset_timestamp: number
  + constructor()
  + reset()
  + updateStore(): void
  + setupWs(): void
}
class ParametersTable {
  - parametersDict: Parameter[]
  - metadata_loaded: boolean
  + updateParam(param_name: string, param_value: number): void
  + parameters(): Parameter[]
}
ParameterFetcher --> ParametersTable: uses
Loading

File-Level Changes

Change Details Files
Debounce MAVLink parameter messages after reset in ParameterFetcher
  • Add reset_timestamp property and set it in reset()
  • Ignore messages within 500ms of reset in setupWs callback
  • Clear reset_timestamp after debounce window to resume processing
core/frontend/src/types/autopilot/parameter-fetcher.ts
Use parameter names as keys in ParametersTable for direct lookup
  • Change parametersDict key type from number to string
  • Store parameters by name instead of id in addParameter
  • Simplify updateParam to use direct name lookup and drop entry search
core/frontend/src/types/autopilot/parameter-table.ts
Invoke store reset on board change to trigger autopilot parameter re-download
  • Import autopilot_data store in BoardChangeDialog.vue
  • Call autopilot_data.reset() after successful board change
core/frontend/src/components/autopilot/BoardChangeDialog.vue

Assessment against linked issues

Issue Objective Addressed Explanation
#2343 Trigger the frontend to re-download autopilot parameters when the board is changed.
#2343 Trigger the frontend to re-download autopilot parameters when the firmware is changed.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes - here's some feedback:

  • Extract the 500ms “ignore old messages” window into a named constant or configuration option instead of a magic number for easier tuning and clarity.
  • Rename reset_timestamp to a more descriptive identifier (for example ignoreWindowStart) so its purpose of suppressing stale MAVLink messages is clearer.
  • Since parametersDict now uses string keys, consider introducing a type alias or renaming it (e.g. parametersByName) and audit all its consumers to prevent any downstream mismatches.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Extract the 500ms “ignore old messages” window into a named constant or configuration option instead of a magic number for easier tuning and clarity.
- Rename reset_timestamp to a more descriptive identifier (for example ignoreWindowStart) so its purpose of suppressing stale MAVLink messages is clearer.
- Since parametersDict now uses string keys, consider introducing a type alias or renaming it (e.g. parametersByName) and audit all its consumers to prevent any downstream mismatches.

## Individual Comments

### Comment 1
<location> `core/frontend/src/types/autopilot/parameter-fetcher.ts:95-97` </location>
<code_context>

   setupWs(): void {
     this.listener.setCallback((receivedMessage) => {
+      // Ignore messages received after reset for 500ms
+      const message_age = performance.now() - this.reset_timestamp
+      if (this.reset_timestamp > 0) {
+        if (message_age < 500) {
+          return
</code_context>

<issue_to_address>
**suggestion:** The 500ms message ignore window may be too short or too long depending on system latency.

Consider making the 500ms window configurable to accommodate different latency conditions, or add documentation explaining the choice of this value.

Suggested implementation:

```typescript
    this.total_params_count = null
    this.watchdog_last_count = 0
    this.parameter_table.reset()
    this.reset_timestamp = performance.now()
    // Configurable window (ms) to ignore messages after reset, to accommodate system latency
    this.resetIgnoreWindowMs = 500
  }

```

```typescript
      // Ignore messages received after reset for configurable window (default: 500ms)
      // This helps avoid processing stale messages after a reset, and can be tuned for system latency.
      const message_age = performance.now() - this.reset_timestamp
      if (this.reset_timestamp > 0) {
        if (message_age < this.resetIgnoreWindowMs) {
          return

```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@nicoschmdt nicoschmdt force-pushed the trigger-frontend-to-re-download-parameters branch from 080b435 to 74a3d6d Compare October 30, 2025 19:12
@patrickelectric patrickelectric merged commit 06c9a4b into bluerobotics:master Nov 4, 2025
7 checks passed
@joaoantoniocardoso
Copy link
Member

Should we backport it? The issue was from Jan 2024

@patrickelectric
Copy link
Member

Should we backport it? The issue was from Jan 2024

yes

@joaoantoniocardoso joaoantoniocardoso added the move-to-stable Needs to be cherry-picked and move to stable label Nov 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

move-to-stable Needs to be cherry-picked and move to stable

Projects

None yet

Development

Successfully merging this pull request may close these issues.

changing boards and firmware should trigger frontend to re-download parameters

3 participants