fix: narrow CLI error markers to avoid false positives
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 <noreply@anthropic.com>
This commit is contained in:
@@ -556,19 +556,26 @@ class ClaudeCliBackend(CliBackend):
|
|||||||
# Known CLI error prefixes that indicate auth or config failures.
|
# Known CLI error prefixes that indicate auth or config failures.
|
||||||
# When detected, we log a warning so the user doesn't mistake a
|
# When detected, we log a warning so the user doesn't mistake a
|
||||||
# broken auth for "nothing to optimize" (issue #68).
|
# broken auth for "nothing to optimize" (issue #68).
|
||||||
|
# Keep these specific to avoid false positives on normal model output.
|
||||||
_CLI_ERROR_MARKERS = (
|
_CLI_ERROR_MARKERS = (
|
||||||
"Not logged in",
|
"Not logged in",
|
||||||
"Please run /login",
|
"Please run /login",
|
||||||
"Authentication required",
|
"Authentication required",
|
||||||
"API key",
|
"Invalid API key",
|
||||||
"Unauthorized",
|
"Unauthorized: invalid x-api-key",
|
||||||
"Invalid API",
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def _detect_cli_error(self, stdout: str, stderr: str) -> None:
|
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
|
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:
|
for marker in self._CLI_ERROR_MARKERS:
|
||||||
if marker in combined:
|
if marker in combined:
|
||||||
logging.getLogger("skillopt_sleep").warning(
|
logging.getLogger("skillopt_sleep").warning(
|
||||||
|
|||||||
Reference in New Issue
Block a user