From d783b94c7f9476d30eeaec891f2cb2f5621bd60c Mon Sep 17 00:00:00 2001 From: "juvenal.diaz" Date: Sat, 14 Nov 2026 10:10:56 -0600 Subject: [PATCH] Allow Holmes repair tools and retain crash error lines --- docs/doctor-overview.md | 4 +++- scripts/doctor-focus | 2 +- scripts/doctor-pod-evidence.py | 4 +++- tests/jeannie/test_doctor_focus.py | 11 ++++++++++- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/docs/doctor-overview.md b/docs/doctor-overview.md index 5713989..7c0433b 100644 --- a/docs/doctor-overview.md +++ b/docs/doctor-overview.md @@ -70,7 +70,9 @@ cluster context, records a change journal entry, enables Holmes tools and automatically allows Bash commands. **Holmes has the Debian user's host-level permissions**, including any passwordless sudo access; this is not a sandbox or an application-scoped permission boundary. Its actions can change the cluster -or host. Holmes is asked for a diagnosis, an evidence-based five whys analysis, +or host. Repair mode sets Holmes's `BASH_TOOL_UNSAFE_ALLOW_ALL` environment +variable in addition to the CLI flag; support depends on the installed Holmes +version. Holmes is asked for a diagnosis, an evidence-based five whys analysis, the repair, validation and recommendations, marking unsupported causes as unknown. Doctor saves its output, errors and a report in a private artifact directory, then independently checks the selected application's Argo CD health diff --git a/scripts/doctor-focus b/scripts/doctor-focus index 718c3f6..e1d090c 100644 --- a/scripts/doctor-focus +++ b/scripts/doctor-focus @@ -135,7 +135,7 @@ doctor_focus_holmes_fix() { } >"${artifact}/holmes-prompt.txt" record_change_journal "doctor-holmes-k8s-repair" "${item}" echo "Holmes is authorized to execute commands to repair ${item}; its Bash tool has host-level access." - if ! timeout "${LAB_HOLMES_TRIAGE_TIMEOUT_SECONDS:-360}" env KUBECONFIG="${KUBECONFIG_PATH}" \ + if ! timeout "${LAB_HOLMES_TRIAGE_TIMEOUT_SECONDS:-360}" env KUBECONFIG="${KUBECONFIG_PATH}" BASH_TOOL_UNSAFE_ALLOW_ALL=true \ OPENAI_BASE_URL="${OPENAI_BASE_URL:-http://127.0.0.1:20128/v1}" \ OPENAI_API_BASE="${OPENAI_BASE_URL:-http://127.0.0.1:20128/v1}" OPENAI_API_KEY="${key}" \ "${bin}" ask --config "${config}" --prompt-file "${artifact}/holmes-prompt.txt" \ diff --git a/scripts/doctor-pod-evidence.py b/scripts/doctor-pod-evidence.py index 4d59bbb..689c35a 100644 --- a/scripts/doctor-pod-evidence.py +++ b/scripts/doctor-pod-evidence.py @@ -17,7 +17,9 @@ def main(): mode = sys.argv[1] if mode == "logs": data = sys.stdin.buffer.read(8193).decode("utf-8", errors="replace") - for line in data.splitlines()[-8:]: + lines = data.splitlines() + selected = lines if len(lines) <= 8 else lines[:4] + lines[-4:] + for line in selected: print("previous log:", clean(line)[:200]) if not data: print("Previous container logs were empty.") diff --git a/tests/jeannie/test_doctor_focus.py b/tests/jeannie/test_doctor_focus.py index 1630ba5..5c013c2 100644 --- a/tests/jeannie/test_doctor_focus.py +++ b/tests/jeannie/test_doctor_focus.py @@ -27,7 +27,7 @@ class DoctorFocusTests(unittest.TestCase): with tempfile.TemporaryDirectory() as directory: root = Path(directory) binary = root / "jeannie-holmes" - binary.write_text("#!/bin/sh\ncase \" $* \" in *' --bash-always-allow '*) echo 'attempted repair';; *) exit 3;; esac\n") + binary.write_text("#!/bin/sh\n[ \"${BASH_TOOL_UNSAFE_ALLOW_ALL:-}\" = true ] || exit 4\ncase \" $* \" in *' --bash-always-allow '*) echo 'attempted repair';; *) exit 3;; esac\n") binary.chmod(0o755) rows = root / "rows" rows.write_text("warn\tKubernetes apps\tn8n\tUnavailable\n") @@ -295,6 +295,15 @@ doctor_runner_report self.assertNotIn("secret123", result.stdout) self.assertNotIn("secret456", result.stdout) + def test_crash_log_preserves_exception_and_stack_tail(self): + script = str(ROOT / "scripts/doctor-pod-evidence.py") + lines = ["Error: read-only filesystem"] + [f"stack line {i}" for i in range(12)] + result = subprocess.run([sys.executable, script, "logs"], input="\n".join(lines), + capture_output=True, text=True, check=True) + self.assertIn("Error: read-only filesystem", result.stdout) + self.assertIn("stack line 11", result.stdout) + self.assertNotIn("stack line 5", result.stdout) + def test_selected_item_does_not_inherit_unrelated_failure(self): code = r''' source "$1"