Skip to content

perf(wifi): one status fetch per monitor tick instead of three - #411

Merged
ChuckBuilds merged 2 commits into
mainfrom
perf/wifi-monitor-dedup
Jul 14, 2026
Merged

perf(wifi): one status fetch per monitor tick instead of three#411
ChuckBuilds merged 2 commits into
mainfrom
perf/wifi-monitor-dedup

Conversation

@ChuckBuilds

@ChuckBuilds ChuckBuilds commented Jul 13, 2026

Copy link
Copy Markdown
Owner

Summary

PR 7 of the performance series. Each 30s wifi-monitor tick spawned ~10–15 nmcli subprocesses on a healthy link: the daemon pre-fetched status+ethernet (results never used — dead code), check_and_manage_ap_mode() re-fetched internally, and the daemon fetched a third time for its state logging.

  • Decision logic extracted to _manage_ap_mode(status, ethernet, ap_active); new check_and_manage_ap_mode_with_state() performs the single fetch battery — keeping the retrying _get_wifi_status_with_retry the AP-enable decision depends on — and returns (changed, status, ethernet, ap_active_after). Post-state is derivable (state only flips via one enable or one disable per call).
  • The original bool-returning method delegates unchanged — the internal caller and any third-party users are untouched.
  • Daemon: dead pre-fetch deleted; post-check reads use the returned state. The escalating NetworkManager-restart recovery and its gating are unchanged.

Verification

6 new tests (single fetch per call, observed-state passthrough, ap_after inversion on both enable and disable, bool wrapper back-compat, exception path never raises); full wifi suites 14/14 green. AP failover behavior is logic-identical by construction (same decision function, same inputs); a physical unplug test on real hardware is the remaining spot check since the devpi is reached over the network being tested.

🤖 Generated with Claude Code

https://claude.ai/code/session_01FqzC1nzTWL4kaqgMaQZFam

Summary by CodeRabbit

  • Bug Fixes

    • Improved Wi‑Fi and access point state detection during connectivity monitoring.
    • Refined recovery behavior when internet access is unavailable despite an active Wi‑Fi connection.
    • Improved handling of monitoring errors without interrupting the daemon.
  • Tests

    • Added coverage for access point enable/disable transitions, connectivity reporting, compatibility behavior, and error handling.

The wifi monitor daemon fetched WiFi status + ethernet state before its
AP-mode check, the check internally fetched the same state again (with
retry), and the daemon fetched a third time afterwards — each fetch is
several nmcli subprocess forks, every 30s, forever, even on a perfectly
healthy link.

check_and_manage_ap_mode's decision logic is extracted to
_manage_ap_mode(status, ethernet, ap_active); the new
check_and_manage_ap_mode_with_state() runs the single (retrying) fetch
battery and returns (changed, status, ethernet, ap_active_after) — the
post-state is derivable because state only ever flips via one enable or
one disable. The original bool-returning method delegates, so existing
callers are untouched. The daemon's dead pre-fetch is removed and its
post-check reads use the returned state; the AP-enable retry semantics
(_get_wifi_status_with_retry) are preserved exactly. ~10-15 forks/30s
drops to ~4-6.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FqzC1nzTWL4kaqgMaQZFam
@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@ChuckBuilds, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 15 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b7313d05-204b-4647-b672-217bc1a85b1c

📥 Commits

Reviewing files that changed from the base of the PR and between 2416e8b and a26b777.

📒 Files selected for processing (2)
  • src/wifi_manager.py
  • test/test_wifi_check_state.py
📝 Walkthrough

Walkthrough

WiFiManager now performs one combined WiFi, Ethernet, and AP-state check, returns the resulting state, and retains a boolean compatibility wrapper. The monitoring daemon uses the returned AP state for snapshots, logging, and recovery decisions. New tests cover state handling and exceptions.

Changes

WiFi/AP state coordination

Layer / File(s) Summary
Unified AP-management state API
src/wifi_manager.py, test/test_wifi_check_state.py
WiFiManager fetches connectivity state once, manages AP mode from that snapshot, returns the post-check AP state, preserves the boolean wrapper, and adds tests for state transitions and exception handling.
Daemon state and recovery integration
scripts/utils/wifi_monitor_daemon.py
The daemon consumes the combined result for current-state snapshots, AP logging, periodic diagnostics, and NetworkManager recovery escalation.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant wifi_monitor_daemon
  participant WiFiManager
  participant NetworkState
  wifi_monitor_daemon->>WiFiManager: check_and_manage_ap_mode_with_state()
  WiFiManager->>NetworkState: Fetch WiFi, Ethernet, and AP state
  NetworkState-->>WiFiManager: Return connectivity snapshot
  WiFiManager->>WiFiManager: Manage AP mode from snapshot
  WiFiManager-->>wifi_monitor_daemon: Return changed, status, Ethernet, and AP state
  wifi_monitor_daemon->>wifi_monitor_daemon: Update logs and recovery conditions
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: reducing Wi-Fi monitor status fetches from three per tick to one.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch perf/wifi-monitor-dedup

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.

@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 9 complexity · 0 duplication

Metric Results
Complexity 9
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@ChuckBuilds

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 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.

Inline comments:
In `@src/wifi_manager.py`:
- Around line 2570-2578: Update check_and_manage_ap_mode_with_state to add an
explicit return type hint describing its four-value return tuple: state-changed
status, WiFiStatus, Ethernet connection status, and post-check AP activity.
- Around line 2593-2594: Add type annotations to the parameters of
_manage_ap_mode, while preserving its existing bool return annotation and
behavior. Use the appropriate project-consistent types for status,
ethernet_connected, and ap_active.

In `@test/test_wifi_check_state.py`:
- Line 64: In test/test_wifi_check_state.py, update the unpacking assignments
from check_and_manage_ap_mode_with_state: rename status and ethernet to _status
and _ethernet at lines 64 and 73, and rename ethernet and ap_after to _ethernet
and _ap_after at line 86; leave the used variables unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 03881246-c341-4c50-8977-ebca451f77ee

📥 Commits

Reviewing files that changed from the base of the PR and between 6edd80d and 2416e8b.

📒 Files selected for processing (3)
  • scripts/utils/wifi_monitor_daemon.py
  • src/wifi_manager.py
  • test/test_wifi_check_state.py

Comment thread src/wifi_manager.py Outdated
Comment thread src/wifi_manager.py Outdated
Comment thread test/test_wifi_check_state.py Outdated
…d-var lint in tests

- check_and_manage_ap_mode_with_state now declares its
  Tuple[bool, WiFiStatus, bool, bool] return type instead of being untyped.
- _manage_ap_mode's status/ethernet_connected/ap_active parameters are now
  typed (WiFiStatus, bool, bool), matching its existing -> bool return hint.
- test_wifi_check_state.py: rename unused unpacked variables (status/
  ethernet/ap_after) to underscore-prefixed names at the three call sites
  that don't use them, leaving the used ones untouched.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KEZK1P1Q1fu5pcuVrkrCFZ
@ChuckBuilds
ChuckBuilds merged commit 14a59c8 into main Jul 14, 2026
8 checks passed
@ChuckBuilds
ChuckBuilds deleted the perf/wifi-monitor-dedup branch July 14, 2026 15:22
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