You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Intern] Expand hanzo doctor diagnostics (kubeconfig, port collisions, stale VM sockets) #111
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.
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.
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."""importglob, os, re, socket, sysfrompathlibimportPathCOMMON_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)defreport(status, check, msg, hint=""):
results.append((status, check, msg, hint))
defcheck_kubeconfig():
paths= [Path(p).expanduser() forpinos.environ.get("KUBECONFIG", "~/.kube/config").split(os.pathsep) ifp]
found= [pforpinpathsifp.is_file()]
ifnotfound:
returnreport("FAIL", "kubeconfig", f"No kubeconfig found at {', '.join(map(str, paths))}",
"Run your cluster login command or set KUBECONFIG to a valid file.")
forpathinfound:
try:
text=path.read_text(encoding="utf-8")
except (PermissionError, OSError) asexc:
returnreport("FAIL", "kubeconfig", f"Cannot read {path}: {exc.strerrororexc}",
f"Fix permissions, e.g. chmod 600 {path}")
try:
importyaml# optional dependency for strict parsingdata=yaml.safe_load(text) or {}
current=data.get("current-context")
names= {c.get("name") forcindata.get("contexts") or [] ifisinstance(c, dict)}
exceptImportError:
m=re.search(r"^current-context:\s*['\"]?([^'\"\n]+)", text, re.M)
current=m.group(1).strip() ifmelseNonenames=set(re.findall(r"^\s*name:\s*['\"]?([^'\"\n]+)", text, re.M))
exceptExceptionasexc:
returnreport("FAIL", "kubeconfig", f"{path} is not valid YAML: {exc}",
"Restore a backup or regenerate the kubeconfig.")
ifnotcurrent:
returnreport("WARN", "kubeconfig", f"{path} has no current-context set",
"Run: kubectl config use-context <name>")
ifcurrentnotinnames:
returnreport("FAIL", "kubeconfig", f"current-context '{current}' is not defined",
"Run: kubectl config get-contexts, then use-context with a valid name.")
returnreport("PASS", "kubeconfig", f"{path} OK, current-context '{current}'")
defcheck_ports():
busy= []
forport, nameinCOMMON_PORTS.items():
withsocket.socket(socket.AF_INET, socket.SOCK_STR
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.
Activity
linear commentedon Nov 27, 2026
HAI-544
Jonesc2321601 commentedon Nov 29, 2026
Implemented in #127.
Three read-only self-checks are now part of hanzo doctor, each printing a one-line fix command:
etstat line that names the holder
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.
hoangvietdevstudio-bit commentedon Nov 29, 2026
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--fixflag, 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/hanzI 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)linhsama commentedon Nov 29, 2026
Hi, I can help you implement these diagnostics by updating
src/commands/doctor.rsto catch kubeconfig issues, port collisions, and stale sockets with clear fix commands. I will verify the changes with isolated unit tests and a cleancargo test --lockedrun. Please confirm assignment to me on this issue before I open a pull request.