Detect incomplete Holmes tool investigations
This commit is contained in:
parent
518c0964bf
commit
9bcb44802e
|
|
@ -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`
|
||||
|
|
|
|||
|
|
@ -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'
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in New Issue