Skip to content

[Intern] Expand hanzo doctor diagnostics (kubeconfig, port collisions, stale VM sockets) #111

Done

Description

@zeekay

Track: Pod A — Runtime & CLI (Task #3)
Onboarding Guide: https://docs.hanzo.ai/docs/contributing/oss-onboarding
Bounty Program: https://hanzo.ai/bounty

Objective

Add self-checks to hanzo doctor detecting malformed/stale ~/.kube/hanzo.yaml, local port conflicts (8080, 9090, 1234, 8000), and orphaned VM/daemon sockets, printing exact one-line fix commands.

Getting Started

git clone https://github.com/hanzoai/cli.git && cd cli

Quick build / test command: cargo test --locked

Acceptance Criteria (Definition of Done)

  • Implement checks for kubeconfig validity, default local port collisions, and stale runtime sockets.
  • Add deterministic unit tests (no live cluster required) covering healthy and unhealthy states.
  • cargo test --locked and clippy pass cleanly.
  • Paste reproducible build/test output in your PR description and reference this issue (Closes #<number>).
  • If you hit any broken setup step or unclear docs along the way, include a quick fix in README.md or open a companion PR on hanzoai/docs.

Activity

  1. added
    bounty
    intern
    on Nov 27, 2026
  2. linear commented on Nov 27, 2026

    @linear
  3. Jonesc2321601 commented on Nov 29, 2026

    @Jonesc2321601

    Implemented in #127.

    Three read-only self-checks are now part of hanzo doctor, each printing a one-line fix command:

    • kubeconfig — missing ~/.kube/hanzo.yaml, invalid YAML, absent �piVersion/clusters, or a 127.0.0.1: API endpoint that is not listening → suggests hanzo up / hanzo k8s restart
    • local ports — 8080, 9090, 1234, 8000 already bound → prints the lsof/
      etstat line that names the holder
    • runtime sockets — orphaned *.sock / *.pid under ~/.hanzo (pid gone, or socket untouched for >24h) → prints
      m -f

    The analysis is a pure function over a snapshot (kubeconfig body, busy ports, socket states), so the deterministic tests need neither a live cluster nor a real runtime directory: cargo test --locked --bin hanzo doctor:: → 9 passed, and cargo clippy --locked --bin hanzo reports no new lints. No new dependencies.

  4. hoangvietdevstudio-bit commented on Nov 29, 2026

    @hoangvietdevstudio-bit

    For hanzo doctor, I'd add three independent checks: one that parses and validates kubeconfig (current context, reachable cluster, expired credentials), one that probes the CLI's default ports and names the process holding each one, and one that finds VM socket files whose owning process no longer exists and offers safe cleanup. I've attached a short working prototype (hanzo_doctor_checks.py) that runs all three and prints PASS/WARN/FAIL results with a suggested fix for each. Each check is a small standalone function, so it should map easily onto your existing doctor command structure. Should stale-socket cleanup happen automatically behind a --fix flag, or should doctor only report and leave removal to the user?

    Preview from the working prototype (hanzo_doctor_checks.py) I built for your project:

    #!/usr/bin/env python3
    """hanzo doctor checks: kubeconfig validity, TCP port collisions, stale VM sockets."""
    import glob, os, re, socket, sys
    from pathlib import Path
    COMMON_PORTS = {80: "http", 443: "https", 2375: "docker", 3000: "dev-server",
    5432: "postgres", 6379: "redis", 6443: "k8s-api", 8080: "http-alt"}
    SOCKET_GLOBS = ["/.hanzo/vm/*.sock", "/.lima//.sock", "~/.colima//.sock", "/tmp/hanz

    I can share the complete runnable sample immediately and tailor it to your exact environment today. Could you let me know if you have any specific hosting or integration preferences?

    Reference Implementation (hanzo_doctor_checks.py)

    #!/usr/bin/env python3
    """hanzo doctor checks: kubeconfig validity, TCP port collisions, stale VM sockets."""
    import glob, os, re, socket, sys
    from pathlib import Path
    
    COMMON_PORTS = {80: "http", 443: "https", 2375: "docker", 3000: "dev-server",
                    5432: "postgres", 6379: "redis", 6443: "k8s-api", 8080: "http-alt"}
    SOCKET_GLOBS = ["~/.hanzo/vm/*.sock", "~/.lima/*/*.sock", "~/.colima/*/*.sock", "/tmp/hanzo-*.sock"]
    results = []  # (status, check, message, hint)
    
    def report(status, check, msg, hint=""):
        results.append((status, check, msg, hint))
    
    def check_kubeconfig():
        paths = [Path(p).expanduser() for p in os.environ.get("KUBECONFIG", "~/.kube/config").split(os.pathsep) if p]
        found = [p for p in paths if p.is_file()]
        if not found:
            return report("FAIL", "kubeconfig", f"No kubeconfig found at {', '.join(map(str, paths))}",
                          "Run your cluster login command or set KUBECONFIG to a valid file.")
        for path in found:
            try:
                text = path.read_text(encoding="utf-8")
            except (PermissionError, OSError) as exc:
                return report("FAIL", "kubeconfig", f"Cannot read {path}: {exc.strerror or exc}",
                              f"Fix permissions, e.g. chmod 600 {path}")
            try:
                import yaml  # optional dependency for strict parsing
                data = yaml.safe_load(text) or {}
                current = data.get("current-context")
                names = {c.get("name") for c in data.get("contexts") or [] if isinstance(c, dict)}
            except ImportError:
                m = re.search(r"^current-context:\s*['\"]?([^'\"\n]+)", text, re.M)
                current = m.group(1).strip() if m else None
                names = set(re.findall(r"^\s*name:\s*['\"]?([^'\"\n]+)", text, re.M))
            except Exception as exc:
                return report("FAIL", "kubeconfig", f"{path} is not valid YAML: {exc}",
                              "Restore a backup or regenerate the kubeconfig.")
            if not current:
                return report("WARN", "kubeconfig", f"{path} has no current-context set",
                              "Run: kubectl config use-context <name>")
            if current not in names:
                return report("FAIL", "kubeconfig", f"current-context '{current}' is not defined",
                              "Run: kubectl config get-contexts, then use-context with a valid name.")
            return report("PASS", "kubeconfig", f"{path} OK, current-context '{current}'")
    
    def check_ports():
        busy = []
        for port, name in COMMON_PORTS.items():
            with socket.socket(socket.AF_INET, socket.SOCK_STR
  5. linhsama commented on Nov 29, 2026

    @linhsama

    Hi, I can help you implement these diagnostics by updating src/commands/doctor.rs to catch kubeconfig issues, port collisions, and stale sockets with clear fix commands. I will verify the changes with isolated unit tests and a clean cargo test --locked run. Please confirm assignment to me on this issue before I open a pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bountyintern

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions