mirror of
https://github.com/microsoft/SkillOpt.git
synced 2026-07-03 14:02:58 +08:00
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.
|
||||
# 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(
|
||||
|
||||
Reference in New Issue
Block a user