Skip to content

Report supervised daemon topology accurately#370

Merged
laulpogan merged 2 commits into
mainfrom
fix/doctor-supervisor-topology
Jul 18, 2026
Merged

Report supervised daemon topology accurately#370
laulpogan merged 2 commits into
mainfrom
fix/doctor-supervisor-topology

Conversation

@laulpogan

@laulpogan laulpogan commented Jul 18, 2026

Copy link
Copy Markdown
Collaborator

Fixes final live-audit false positives in wire doctor. Worker fan-out now counts exact wire daemon roles instead of reused stale pid numbers, scopes unsupervised homes correctly, and treats a healthy all-session supervisor as owner of retired per-session pidfiles while still failing on unmanaged daemons.\n\nVerification:\n- 27 doctor unit tests\n- 655-stale-home restart regression\n- cargo fmt and clippy -D warnings\n- live candidate doctor: 11 workers under cap, no unmanaged daemons, zero FAIL\n- test-env/run.sh (final source; 11/11 integrations)\n- GitNexus detect_changes: HIGH diagnostic-path rating; no service/relay/send/pair mutation in exact diff

Summary by CodeRabbit

  • Bug Fixes
    • Improved wire doctor accuracy for supervisor and daemon health checks.
    • Prevented false failures caused by stale pidfiles or reused process IDs.
    • Correctly distinguishes supervisor-managed workers from unmanaged daemon processes.
    • Retired session pidfiles no longer trigger incorrect orphan or consistency warnings when the supervisor is healthy.
  • Tests
    • Added coverage for supervisor topology, worker counting, unmanaged processes, and stale pidfile scenarios.

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying wireup-landing with  Cloudflare Pages  Cloudflare Pages

Latest commit: e3ce055
Status: ✅  Deploy successful!
Preview URL: https://be8cbdc8.wireup-landing.pages.dev
Branch Preview URL: https://fix-doctor-supervisor-topolo.wireup-landing.pages.dev

View logs

@coderabbitai

coderabbitai Bot commented Jul 18, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

wire doctor now evaluates daemon health, fanout, and pid consistency from the active supervisor topology, excluding the supervisor and unmanaged processes from worker counts. Tests cover stale pidfiles and unmanaged daemons, and the session log records the audit correction.

Changes

Supervisor topology diagnostics

Layer / File(s) Summary
Runtime topology and doctor verdicts
src/cli/status.rs
Supervisor-aware topology derivation now feeds daemon health, pid consistency, and fanout checks, while preserving the prior fallback paths when no active supervisor applies.
Topology regressions and audit record
src/cli/status.rs, SESSION_LOG_2026_07_18.md
Unit tests cover supervisor-owned, stale-pidfile, and unmanaged-daemon scenarios; the session log documents the corrected findings and validation results.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant WireDoctor
  participant ProcessDiscovery
  participant SupervisorPidfile
  participant SessionPidfiles
  WireDoctor->>ProcessDiscovery: discover live daemon role PIDs
  WireDoctor->>SupervisorPidfile: read supervisor PID
  WireDoctor->>SessionPidfiles: read known session daemon PIDs
  WireDoctor->>WireDoctor: derive owned workers and unmanaged daemons
  WireDoctor-->>WireDoctor: emit daemon and fanout verdicts
Loading
🚥 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 is concise and clearly reflects the main change: more accurate reporting of supervised daemon topology.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/doctor-supervisor-topology

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.

Actionable comments posted: 1

🤖 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/cli/status.rs`:
- Around line 1042-1069: Update supervisor_worker_count to restrict its fanout
set to known_session_pids even when supervisor_pid is present, excluding
unmanaged daemon PIDs such as 12 when only 11 is known. In
supervisor_daemon_health_verdict, calculate the total daemon count separately
for health evaluation rather than reusing the restricted fanout count, and add
coverage for the specified PID case.
🪄 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: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 54719b1a-06e6-4167-aa79-5088d9e05e39

📥 Commits

Reviewing files that changed from the base of the PR and between 80b271e and e3ce055.

📒 Files selected for processing (2)
  • SESSION_LOG_2026_07_18.md
  • src/cli/status.rs

Comment thread src/cli/status.rs
Comment on lines +1042 to +1069
fn supervisor_worker_count(
supervisor_pid: Option<u32>,
daemon_pids: &[u32],
known_session_pids: &[u32],
) -> usize {
let known: std::collections::HashSet<u32> = known_session_pids.iter().copied().collect();
daemon_pids
.iter()
.copied()
.filter(|pid| match supervisor_pid {
Some(supervisor) => *pid != supervisor,
None => known.contains(pid),
})
.collect::<std::collections::HashSet<_>>()
.len()
}

fn supervisor_daemon_health_verdict(
supervisor_pid: Option<u32>,
supervisor_alive: bool,
daemon_pids: &[u32],
unmanaged_pids: &[u32],
) -> Option<DoctorCheck> {
let supervisor_pid =
supervisor_pid.filter(|pid| supervisor_alive && daemon_pids.contains(pid))?;
let workers = supervisor_worker_count(Some(supervisor_pid), daemon_pids, &[]);
if !unmanaged_pids.is_empty() {
let managed_workers = workers.saturating_sub(unmanaged_pids.len());

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Exclude unmanaged daemon PIDs from the fanout count.

When a supervisor exists, Lines 1051-1053 count every daemon except the supervisor and ignore known_session_pids. An unmanaged daemon therefore inflates supervisor_fanout and may incorrectly classify it as a wire_defect.

Keep fanout restricted to known session PIDs, and calculate the health verdict’s total daemon count separately.

Proposed fix
     daemon_pids
         .iter()
         .copied()
-        .filter(|pid| match supervisor_pid {
-            Some(supervisor) => *pid != supervisor,
-            None => known.contains(pid),
-        })
+        .filter(|pid| Some(*pid) != supervisor_pid && known.contains(pid))
         .collect::<std::collections::HashSet<_>>()
         .len()
 }
 
 fn supervisor_daemon_health_verdict(
@@
-    let workers = supervisor_worker_count(Some(supervisor_pid), daemon_pids, &[]);
+    let workers = daemon_pids
+        .iter()
+        .copied()
+        .filter(|pid| *pid != supervisor_pid)
+        .collect::<std::collections::HashSet<_>>()
+        .len();

Also add a case asserting that PID 12 is excluded when only PID 11 is known.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
fn supervisor_worker_count(
supervisor_pid: Option<u32>,
daemon_pids: &[u32],
known_session_pids: &[u32],
) -> usize {
let known: std::collections::HashSet<u32> = known_session_pids.iter().copied().collect();
daemon_pids
.iter()
.copied()
.filter(|pid| match supervisor_pid {
Some(supervisor) => *pid != supervisor,
None => known.contains(pid),
})
.collect::<std::collections::HashSet<_>>()
.len()
}
fn supervisor_daemon_health_verdict(
supervisor_pid: Option<u32>,
supervisor_alive: bool,
daemon_pids: &[u32],
unmanaged_pids: &[u32],
) -> Option<DoctorCheck> {
let supervisor_pid =
supervisor_pid.filter(|pid| supervisor_alive && daemon_pids.contains(pid))?;
let workers = supervisor_worker_count(Some(supervisor_pid), daemon_pids, &[]);
if !unmanaged_pids.is_empty() {
let managed_workers = workers.saturating_sub(unmanaged_pids.len());
fn supervisor_worker_count(
supervisor_pid: Option<u32>,
daemon_pids: &[u32],
known_session_pids: &[u32],
) -> usize {
let known: std::collections::HashSet<u32> = known_session_pids.iter().copied().collect();
daemon_pids
.iter()
.copied()
.filter(|pid| Some(*pid) != supervisor_pid && known.contains(pid))
.collect::<std::collections::HashSet<_>>()
.len()
}
fn supervisor_daemon_health_verdict(
supervisor_pid: Option<u32>,
supervisor_alive: bool,
daemon_pids: &[u32],
unmanaged_pids: &[u32],
) -> Option<DoctorCheck> {
let supervisor_pid =
supervisor_pid.filter(|pid| supervisor_alive && daemon_pids.contains(pid))?;
let workers = daemon_pids
.iter()
.copied()
.filter(|pid| *pid != supervisor_pid)
.collect::<std::collections::HashSet<_>>()
.len();
if !unmanaged_pids.is_empty() {
let managed_workers = workers.saturating_sub(unmanaged_pids.len());
🤖 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/cli/status.rs` around lines 1042 - 1069, Update supervisor_worker_count
to restrict its fanout set to known_session_pids even when supervisor_pid is
present, excluding unmanaged daemon PIDs such as 12 when only 11 is known. In
supervisor_daemon_health_verdict, calculate the total daemon count separately
for health evaluation rather than reusing the restricted fanout count, and add
coverage for the specified PID case.

@laulpogan
laulpogan merged commit b6a6d49 into main Jul 18, 2026
14 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