From 552ddefd74f2a6fdf57d4cd40681f2be5236fb34 Mon Sep 17 00:00:00 2001 From: carpedkm Date: Sat, 20 Jun 2026 13:32:43 +0000 Subject: [PATCH] fix: narrow CLI error markers to avoid false positives MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Address codex review: "API key" was too generic — a model response about configuring API keys would trigger a false auth warning. Now: - Use specific phrases ("Invalid API key", "Unauthorized: invalid x-api-key") - Only check short stdout (<300 chars) to skip real model responses - Still check stderr unconditionally Co-Authored-By: Claude Fable 5 --- skillopt_sleep/backend.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/skillopt_sleep/backend.py b/skillopt_sleep/backend.py index 3640fdd..f472da7 100644 --- a/skillopt_sleep/backend.py +++ b/skillopt_sleep/backend.py @@ -556,19 +556,26 @@ class ClaudeCliBackend(CliBackend): # Known CLI error prefixes that indicate auth or config failures. # When detected, we log a warning so the user doesn't mistake a # broken auth for "nothing to optimize" (issue #68). + # Keep these specific to avoid false positives on normal model output. _CLI_ERROR_MARKERS = ( "Not logged in", "Please run /login", "Authentication required", - "API key", - "Unauthorized", - "Invalid API", + "Invalid API key", + "Unauthorized: invalid x-api-key", ) def _detect_cli_error(self, stdout: str, stderr: str) -> None: - """Log a warning if CLI output looks like an auth/config error.""" + """Log a warning if CLI output looks like an auth/config error. + + Only checks stderr and short stdout (< 300 chars) to avoid + false-positives on legitimate model responses that mention + auth-related terms. + """ import logging - combined = stdout + "\n" + stderr + # Long stdout is almost certainly a real model response, not an error. + check_stdout = stdout if len(stdout) < 300 else "" + combined = check_stdout + "\n" + stderr for marker in self._CLI_ERROR_MARKERS: if marker in combined: logging.getLogger("skillopt_sleep").warning(