Skip to content

feat: add flapping service detection and visual styling - #176

Merged
hrzlgnm merged 2 commits into
mainfrom
feat/render-flapping-services
Feb 12, 2026
Merged

hrzlgnm merged 2 commits into
mainfrom
feat/render-flapping-services

Conversation

@hrzlgnm

@hrzlgnm hrzlgnm commented Feb 12, 2026

Copy link
Copy Markdown
Owner

Summary

  • Add flapping service detection based on session history (3+ short sessions < 10s)
  • Implement color-blind friendly visual styling in service list (darker background + underline)
  • Add flapping status to details view with combined status line (e.g., "Online, Flapping")
  • Include is_flapping field in JSON state export for debugging/analysis
  • Add comprehensive tests for flapping detection and styling

Summary by CodeRabbit

  • New Features
    • Added visual detection and display of flapping services (those frequently transitioning between online and offline states)
    • Flapping services are highlighted with distinct styling including color and underlining for quick identification
    • Styling is color-blind friendly

- Add is_flapping field to ServiceEntry for tracking unstable services
- Implement flapping detection based on session history (3+ short sessions)
- Add color-blind friendly visual styling in list view (darker background + underline)
- Add flapping status to details view with combined status line (Online/Offline, Flapping)
- Include is_flapping in JSON state export for debugging/analysis
- Add comprehensive tests for flapping detection and styling
@hrzlgnm

hrzlgnm commented Feb 12, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@github-actions github-actions Bot added the enhancement New feature or request label Feb 12, 2026
@coderabbitai

coderabbitai Bot commented Feb 12, 2026

Copy link
Copy Markdown
Contributor
✅ Actions performed

Review triggered.

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 commented Feb 12, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

This PR introduces flapping detection for services—a feature that identifies when a service is rapidly cycling between online and offline states. The change adds flapping status tracking to service entries, implements detection logic based on session history, and updates rendering to visually highlight flapping services with distinct colors and underline styling.

Changes

Cohort / File(s) Summary
Flapping Status Foundation
src/tui_app.rs
Added is_flapping: bool field to ServiceEntry and SerializableServiceEntry structs. Introduced three color constants (FLAPPING_COLOR_SELECTED, FLAPPING_COLOR_NORMAL, FLAPPING_FOREGROUND_COLOR) for visual distinction. Implemented is_flapping_service() detection logic that identifies flapping based on multiple short completed sessions, and update_flapping_status() for caching the result.
Service Lifecycle Integration
src/tui_app.rs
Wired flapping status updates into service state transitions: go_offline_at(), go_online_at(), and add_or_update_service(). Updated From<ResolvedService> and From<&ServiceEntry> trait implementations to initialize and serialize the is_flapping field.
Rendering & UI Updates
src/tui_app.rs
Modified service list item styling to apply FLAPPING_COLOR_SELECTED or FLAPPING_COLOR_NORMAL with underline when flapping. Extended service details display to show "Flapping" label in online/offline sections when applicable.
Testing
src/tui_app.rs
Added unit tests verifying flapping detection under various session histories, styling outcomes for selected/non-selected states, and edge cases (ongoing sessions, long sessions, mixed histories).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

Suggested labels

enhancement

Poem

🚨 A service flaps, it lives, it dies,
Up and down before your eyes,
Now we'll paint it underlined,
So you never miss the sign—
Chaos caught in colors bright! ✨


Look, I gotta be straight with you here: this is a solid feature addition. The flapping detection logic is doing real work—analyzing session history to identify problematic services that keep cycling. The integration into the service lifecycle is thorough, hitting all the right state transitions. Tests are there. The rendering changes are clean and purpose-built.

The only thing I'd double-check in review is whether the flapping detection threshold (what counts as "multiple short completed sessions") is actually tuned right for real-world mDNS behavior. You don't want false positives on services that legitimately restart. But the implementation itself? It's solid. No fires here.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely describes the primary changes: adding flapping service detection and visual styling to the TUI application.
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into main

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/render-flapping-services

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 and usage tips.

@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: 1

🤖 Fix all issues with AI agents
In `@src/tui_app.rs`:
- Around line 247-275: The flapping math in is_flapping_service misclassifies
because integer division and low completed session counts let 1-of-3 or 0-of-1
pass; update the logic to (1) require a minimum number of completed sessions
(e.g., add const MIN_COMPLETED_SESSIONS = 3 and check completed_sessions >=
MIN_COMPLETED_SESSIONS) and (2) compute the "half" correctly using either
short_sessions * 2 >= completed_sessions or short_sessions >=
(completed_sessions + 1) / 2 so you don't undercount due to truncation; keep
counting only sessions with end_time present as you already do and return
flapping only when both the min completed threshold and the corrected half
condition are met in is_flapping_service.

Comment thread src/tui_app.rs
- Require minimum 3 completed sessions before checking flapping
- Use multiplication instead of division to correctly compute half
- Update test to match new requirements
@hrzlgnm
hrzlgnm merged commit 5843189 into main Feb 12, 2026
23 checks passed
@hrzlgnm
hrzlgnm deleted the feat/render-flapping-services branch February 12, 2026 20:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant