From 9bcb44802e2fd417ca2f6c74b21c4eeb7e34bf30 Mon Sep 17 00:00:00 2001 From: "juvenal.diaz" Date: Sat, 14 Nov 2026 11:15:59 -0600 Subject: [PATCH] Detect incomplete Holmes tool investigations --- docs/doctor-overview.md | 3 +++ scripts/doctor-focus | 11 +++++++++-- tests/jeannie/test_doctor_focus.py | 24 +++++++++++++++++++++++- 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/docs/doctor-overview.md b/docs/doctor-overview.md index 7be91b6..72c22b1 100644 --- a/docs/doctor-overview.md +++ b/docs/doctor-overview.md @@ -79,6 +79,9 @@ directory, then independently checks the selected application's Argo CD health and sync. A failed or unavailable check returns a failure; Healthy and Synced does not establish end-to-end health or confirm the root cause. This mode is unavailable through the remote API and does not accept JSON output. +If Holmes records no tool calls, Doctor marks the investigation incomplete even +when the model prints what looks like a tool request as ordinary text. A tool +call record alone does not prove that a repair was made or succeeded. Repair mode defaults to 30 model steps, a 900-second timeout and a 2048 MiB per-tool memory limit; `LAB_HOLMES_REPAIR_MAX_STEPS`, `LAB_HOLMES_REPAIR_TIMEOUT_SECONDS` and `LAB_HOLMES_REPAIR_TOOL_MEMORY_MB` diff --git a/scripts/doctor-focus b/scripts/doctor-focus index 01b8836..6091f42 100644 --- a/scripts/doctor-focus +++ b/scripts/doctor-focus @@ -107,7 +107,7 @@ doctor_focus_holmes() { } doctor_focus_holmes_fix() { - local item="$1" base artifact bin config model fast key snapshot validation_row status=0 validation=unknown + local item="$1" base artifact bin config model fast key snapshot validation_row status=0 validation=unknown tool_status=unknown local tools_env="${LAB_AI_STACK_TOOLS_ENV_FILE:-/data/homelab-ai-stack/ai-tools.env}" local AI_STACK_AGENT_SMART_MODEL="${AI_STACK_AGENT_SMART_MODEL:-}" AI_STACK_AGENT_FAST_MODEL="${AI_STACK_AGENT_FAST_MODEL:-}" local OPENAI_BASE_URL="${OPENAI_BASE_URL:-}" OPENAI_API_KEY="${OPENAI_API_KEY:-}" @@ -146,6 +146,12 @@ doctor_focus_holmes_fix() { >"${artifact}/holmes-output.txt" 2>"${artifact}/holmes-error.txt"; then status=1 fi + if python3 -c 'import json,sys; d=json.load(open(sys.argv[1])); sys.exit(0 if isinstance(d.get("tool_calls"),list) and len(d["tool_calls"]) > 0 else 1)' "${artifact}/conversation.json" 2>/dev/null; then + tool_status=observed + else + tool_status=not-observed + status=1 + fi { printf '$ kubectl --kubeconfig %q --request-timeout=10s -n argocd get application %q --ignore-not-found -o json | python3 %q --report\n' "${KUBECONFIG_PATH}" "${item}" "${REPO_ROOT}/scripts/doctor-application.py" if cluster_context_require && snapshot="$(doctor_focus_application_fetch "${item}")" && [[ -n "${snapshot}" ]] && validation_row="$(printf '%s' "${snapshot}" | python3 "${REPO_ROOT}/scripts/doctor-application.py" --report)"; then @@ -164,7 +170,8 @@ doctor_focus_holmes_fix() { printf 'Holmes investigation, five whys and attempted mitigation (model-generated; verify claims):\n' cat "${artifact}/holmes-output.txt" printf '\nHolmes execution: ' - if ((status)); then echo 'failed or timed out; changes may already have occurred'; else echo 'completed'; fi + if ((status)); then echo 'incomplete, failed or timed out; changes may already have occurred'; else echo 'completed'; fi + if [[ "${tool_status}" != observed ]]; then echo 'No completed Holmes tool calls were recorded; no tool-based investigation is confirmed.'; fi printf '\nIndependent post-repair Argo CD check: %s\n' "${validation}" cat "${artifact}/validation.txt" printf 'This checks Argo CD health and sync only; it does not prove end-to-end functionality or the root cause.\n' diff --git a/tests/jeannie/test_doctor_focus.py b/tests/jeannie/test_doctor_focus.py index 41eb1c9..85bd846 100644 --- a/tests/jeannie/test_doctor_focus.py +++ b/tests/jeannie/test_doctor_focus.py @@ -28,7 +28,7 @@ class DoctorFocusTests(unittest.TestCase): root = Path(directory) binary = root / "jeannie-holmes" binary.write_text("#!/bin/sh\n[ \"${TOOL_MEMORY_LIMIT_MB:-}\" = 2048 ] || exit 4\ncase \" $* \" in *' --max-steps 30 '*' --interactive '*' --bash-always-allow '*) ;; *) exit 3;; esac\n" - "while [ $# -gt 0 ]; do if [ \"$1\" = --json-output-file ]; then shift; printf '{}' > \"$1\"; break; fi; shift; done\n" + "while [ $# -gt 0 ]; do if [ \"$1\" = --json-output-file ]; then shift; printf '%s' '{\"tool_calls\":[{}]}' > \"$1\"; break; fi; shift; done\n" "echo 'attempted repair'\nread -r line\n[ \"$line\" = /exit ]\n") binary.chmod(0o755) rows = root / "rows" @@ -52,6 +52,28 @@ doctor_focus_holmes_fix n8n''' self.assertIn("Distinguish I/O errors from permissions", (artifact / "holmes-prompt.txt").read_text()) self.assertIn("does not prove end-to-end", (artifact / "report.txt").read_text()) + def test_holmes_repair_rejects_text_only_tool_request(self): + with tempfile.TemporaryDirectory() as directory: + root = Path(directory) + binary = root / "jeannie-holmes" + binary.write_text("#!/bin/sh\nwhile [ $# -gt 0 ]; do if [ \"$1\" = --json-output-file ]; then shift; printf '%s' '{\"tool_calls\":[]}' > \"$1\"; break; fi; shift; done\necho TodoWrite\nread -r line\n") + binary.chmod(0o755) + rows = root / "rows" + rows.write_text("warn\tKubernetes apps\tn8n\tUnavailable\n") + env = os.environ.copy() + env.update(PATH=f"{root}:{env.get('PATH', '')}", REPO_ROOT=str(ROOT), HOME=str(root), + REPORT_UI_ROWS_FILE=str(rows), KUBECONFIG_PATH="/tmp/test-kubeconfig", + LAB_AI_STACK_TOOLS_ENV_FILE=str(root / "missing"), LAB_HOLMES_CONFIG_FILE=str(root / "missing-config"), + LAB_DOCTOR_K8S_ARTIFACT_DIR=str(root / "artifacts")) + code = '''source "$1" +cluster_context_require() { :; } +record_change_journal() { :; } +doctor_focus_application_fetch() { printf '%s' '{"metadata":{"name":"n8n"},"status":{"health":{"status":"Healthy"},"sync":{"status":"Synced"}}}'; } +doctor_focus_holmes_fix n8n''' + result = subprocess.run(["bash", "-c", code, "test", str(DOCTOR)], env=env, capture_output=True, text=True) + self.assertNotEqual(result.returncode, 0) + self.assertIn("No completed Holmes tool calls were recorded", result.stdout) + def test_holmes_repair_does_not_claim_success_when_validation_fails(self): with tempfile.TemporaryDirectory() as directory: root = Path(directory)