Skip to content

Conversation

@joaomariolago
Copy link
Collaborator

@joaomariolago joaomariolago commented Nov 6, 2025

  • Make sure _execute_route use settings as source of the interface object to avoid fetching from system and overriding existing settings

This could be the fix for root cause of static IPs being lost on PI5 due to fact that NetworkManager take more time to apply configuration and during cable guy startup sequence _execute_route method could be some times being called prior to IP addresses been actually configured properly.

Summary by Sourcery

Ensure cable_guy route execution uses saved interface settings as the authoritative source and skips invalid or forbidden interfaces when applying route changes.

Bug Fixes:

  • Prevent route execution from overriding existing interface settings by relying on saved configuration instead of live system state.
  • Avoid applying route actions to invalid or forbidden interfaces, reducing unintended side effects on disallowed network devices.

@sourcery-ai
Copy link

sourcery-ai bot commented Nov 6, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adjusts the Cable Guy manager’s _execute_route method to operate strictly on saved interface settings, adds validation for interface existence and type, and updates stored routes without re-fetching the interface from the system to avoid overwriting static configuration.

Sequence diagram for updated _execute_route flow in CableGuyManager

sequenceDiagram
    participant Caller
    participant CableGuyManager
    participant SettingsStore
    participant KernelRouting

    Caller->>CableGuyManager: _execute_route(action, interface_name, route)
    CableGuyManager->>CableGuyManager: is_valid_interface_name(interface_name, filter_wifi=true)
    alt invalid_or_forbidden_interface
        CableGuyManager-->>Caller: return (route action ignored)
    else valid_interface
        CableGuyManager->>SettingsStore: get_saved_interface_by_name(interface_name)
        alt interface_not_found
            CableGuyManager-->>Caller: raise ValueError
        else interface_found
            CableGuyManager->>CableGuyManager: _get_interface_index(interface_name)
            CableGuyManager->>KernelRouting: apply route(action, interface_index, route)
            alt routing_error
                CableGuyManager-->>Caller: raise exception
            else routing_ok
                CableGuyManager->>CableGuyManager: get_routes(interface_name, ignore_unmanaged=false)
                CableGuyManager->>SettingsStore: update current_interface.routes
                CableGuyManager->>SettingsStore: sync managed flag on matching route
                CableGuyManager-->>Caller: return
            end
        end
    end
Loading

Updated class diagram for CableGuyManager _execute_route and related types

classDiagram
    class CableGuyManager {
        +remove_route(interface_name: str, route: Route) void
        -_execute_route(action: str, interface_name: str, route: Route) void
        +is_valid_interface_name(interface_name: str, filter_wifi: bool) bool
        +get_saved_interface_by_name(interface_name: str) Interface
        +_get_interface_index(interface_name: str) int
        +get_routes(interface_name: str, ignore_unmanaged: bool) list~Route~
    }

    class Interface {
        +name: str
        +routes: list~Route~
    }

    class Route {
        +destination_parsed: str
        +next_hop_parsed: str
        +gateway: str
        +next_hop_parsed: str
        +managed: bool
    }

    CableGuyManager --> Interface : manages_saved_interfaces
    CableGuyManager --> Route : configures_routes
    Interface --> Route : has_routes
Loading

File-Level Changes

Change Details Files
Validate interface before executing route actions and skip forbidden or unknown interfaces.
  • Add an early check using is_valid_interface_name with filter_wifi=True to ignore route actions for disallowed interfaces.
  • Log a debug message and return early when a forbidden interface is encountered.
  • Retrieve the interface from saved settings and raise ValueError if the interface is not found.
core/services/cable_guy/api/manager.py
Update route settings using the existing saved interface object instead of refetching from the system.
  • Remove call to get_interface_by_name when updating settings after applying a route change.
  • Populate current_interface.routes by querying get_routes with ignore_unmanaged=False.
  • Preserve and update managed flag on the matching route while operating on the saved interface object, preventing system-derived state from overwriting configuration.
core/services/cable_guy/api/manager.py

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

* Make sure _execute_route use settings as source of the interface
  object to avoid fetching from system and overriding existing settings
@joaomariolago joaomariolago marked this pull request as ready for review November 27, 2025 19:12
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:

  • Now that _execute_route raises a ValueError when get_saved_interface_by_name returns None, double-check that all callers either handle this exception or that it is acceptable for the caller path to fail hard rather than logging and continuing.
  • The new early return when is_valid_interface_name(..., filter_wifi=True) fails changes behavior for Wi-Fi interfaces; confirm that this aligns with how higher-level code expects route ops for Wi-Fi to behave (e.g., if they previously relied on an error or different handling).
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Now that `_execute_route` raises a `ValueError` when `get_saved_interface_by_name` returns `None`, double-check that all callers either handle this exception or that it is acceptable for the caller path to fail hard rather than logging and continuing.
- The new early return when `is_valid_interface_name(..., filter_wifi=True)` fails changes behavior for Wi-Fi interfaces; confirm that this aligns with how higher-level code expects route ops for Wi-Fi to behave (e.g., if they previously relied on an error or different handling).

## Individual Comments

### Comment 1
<location> `core/services/cable_guy/api/manager.py:638-639` </location>
<code_context>
         self._execute_route("del", interface_name, route)

     def _execute_route(self, action: str, interface_name: str, route: Route) -> None:
+        if not self.is_valid_interface_name(interface_name, filter_wifi=True):
+            logger.debug(f"Ignoring route action '{action}' for forbidden interface '{interface_name}'.")
+            return
+
</code_context>

<issue_to_address>
**question (bug_risk):** Consider whether silently ignoring route actions for filtered interfaces is the right contract here.

This early return changes `_execute_route` from "attempt and likely fail" to "no-op with a debug log" for some interfaces. If callers depended on an exception or other failure signal for invalid/forbidden interfaces, this could hide misconfigurations and upstream logic bugs. Please confirm that callers expect a no-op here; otherwise consider raising a clear exception or performing this check explicitly at call sites instead.
</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.

@patrickelectric patrickelectric merged commit 1e7e9ac into bluerobotics:master Dec 4, 2025
7 checks passed
@patrickelectric patrickelectric added move-to-stable Needs to be cherry-picked and move to stable and removed move-to-stable Needs to be cherry-picked and move to stable labels Dec 5, 2025
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.

2 participants