Skip to content

feat(cli): upgrade doctor to state-aware diagnostic engine - #47

Merged
JacksonFergusonDev merged 13 commits into
mainfrom
smarter-doctor
Feb 20, 2026
Merged

feat(cli): upgrade doctor to state-aware diagnostic engine#47
JacksonFergusonDev merged 13 commits into
mainfrom
smarter-doctor

Conversation

@JacksonFergusonDev

Copy link
Copy Markdown
Owner

Description

This PR significantly upgrades git pulsar doctor from a static log parser into a state-aware diagnostic engine. It addresses the inherent issue of event-based monitoring in self-healing distributed systems by correlating historical log events with current repository state, suppressing alert fatigue from naturally resolved transient anomalies.

Additionally, it introduces environmental and topological checks to preemptively identify pipeline blockers and remote state drift.

Key Changes

  • State vs. Event Correlation: run_doctor now evaluates active repository health before parsing logs. It utilizes a dynamic lookback window calculated as a multiple of the daemon's configured push_interval. If the system state is healthy, active log errors within that window are downgraded to suppressed informational notices.
  • Execution Environment Sanity: Implemented _check_systemd_linger to verify systemd user linger status on Linux, preventing silent daemon termination upon SSH disconnect.
  • Remote Session Drift (Roaming Radar): Implemented _check_remote_drift to perform lightweight fetches of the wip/pulsar namespace. It warns users if a remote machine has pushed a newer backup stream for the current branch, prompting a sync.
  • Git Hook Interference Warning: Added _check_git_hooks to scan .git/hooks/ for executable pre-push or pre-commit scripts lacking explicit bypass logic, warning users of potential background pipeline hangs.

Testing

  • Added test_cli.py coverage for all new helper functions using pytest and mocker.
  • Refactored run_doctor tests to utilize tmp_path fixtures instead of directly mocking read-only PosixPath attributes, ensuring robust filesystem simulation.
  • Verified deterministic state/event correlation logic via mocked configuration lookback windows.

Documentation

  • Updated README.md to reflect the "Roaming Radar" completion and new diagnostic capabilities.
  • Updated src/README.md with the 5th architectural invariant: "State Over Events".
  • Expanded tests/README.md to detail the CLI interaction and diagnostic mocking strategy.

Transitions `_analyze_logs` to accept a `seconds` parameter instead of `hours`. This allows for higher-resolution, dynamic lookback windows based on daemon configuration intervals.
Calculates the log analysis lookback window dynamically as a multiple of the daemon's configured `push_interval` (defaulting to 3 cycles). This adapts diagnostic sensitivity directly to the expected operational frequency of the system.
Reorders diagnostic checks in `run_doctor` to evaluate repository health before log events. If all repositories are healthy (no stalled backups), recent log errors are downgraded to a suppressed informational message, preventing alert fatigue from naturally resolved transient anomalies.
Introduces a diagnostic check to verify if the user account has systemd 'Linger' enabled. This prevents the daemon from being silently killed when the user's SSH or TTY session terminates.
Implements a topological check to scan the remote `wip/pulsar` namespace for backup streams originating from other machine IDs. Warns the user if a remote stream has a newer timestamp than the local working directory, prompting a synchronization.
Scans the local `.git/hooks/` directory for executable `pre-push` or `pre-commit` scripts. Alerts the user that strict hooks may intercept and hang the background daemon's automated subprocess calls.
Introduces tests for the `_check_systemd_linger` helper function. Verifies correct behavior across different platforms (ignoring macOS/Windows) and handles simulated `loginctl` outputs for enabled and disabled states.
Introduces tests for the `_check_remote_drift` helper. Validates the topological scanning logic by mocking remote ref fetches and timestamp comparisons to ensure divergence risks are properly flagged.
Introduces tests for the `_check_git_hooks` helper. Verifies the file system scanning logic to ensure executable pre-push and pre-commit hooks lacking bypass logic are correctly flagged as potential blockers.
Updates CLI tests to cover the dynamic lookback window and state/event correlation in `run_doctor`. Verifies that transient log errors are suppressed when the system state is healthy, and printed loudly when failures correlate.
Updates the testing documentation to include the verification strategy for `test_cli.py`. Outlines the approach for testing state/event correlation, execution environment sanity (systemd linger), topological drift detection, and git hook interference scanning.
Expands the module map documentation for `cli.py` to include its new role as the state-aware diagnostic engine. Adds a 5th architectural invariant detailing the priority of system state over transient event logs during health evaluations.
… detection

Updates the main `README.md` to highlight the new capabilities of the `doctor` command. Adds a "State-Aware Diagnostics" feature bullet, expands the command reference, and marks the "Roaming Radar" roadmap item as completed since drift detection is now integrated into the health checks.
@JacksonFergusonDev
JacksonFergusonDev merged commit e21626e into main Feb 20, 2026
4 checks passed
@JacksonFergusonDev
JacksonFergusonDev deleted the smarter-doctor branch February 20, 2026 01:18
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