fix(learn): let exit code 0 win over a bare Killed line; classify signal kills

A successful command can print a standalone Killed line, so that line now counts as
a failure only when no zero exit status is reported; killed by signal and exited with
signal still override exit code 0. The shared classifier maps signal kills (killed by
signal, a Killed line) to EXIT_CODE, since a shell reports them as status 128+N.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Tejas Chopra
2026-10-09 20:38:21 -07:00
co-authored by Claude Opus 5.5
parent 1d3777c169
commit 507236217f
3 changed files with 18 additions and 8 deletions
+5 -1
View File
@@ -69,7 +69,11 @@ _ERROR_PATTERNS: list[tuple[re.Pattern[str], ErrorCategory]] = [
ErrorCategory.USER_REJECTED,
),
(re.compile(r"[Ss]ibling tool call errored", re.I), ErrorCategory.SIBLING_ERROR),
(re.compile(r"exit code|non-zero|exited with", re.I), ErrorCategory.EXIT_CODE),
# A signal kill is the shell's exit status 128+N, so it shares EXIT_CODE.
(
re.compile(r"exit code|non-zero|exited with|killed by signal|^\s*Killed\s*$", re.I | re.M),
ErrorCategory.EXIT_CODE,
),
(
re.compile(r"BUILD FAILED|compilation error|compile error", re.I),
ErrorCategory.BUILD_FAILURE,
+8 -6
View File
@@ -241,15 +241,15 @@ _ERROR_SIGNALS: tuple[re.Pattern[str], ...] = (
# Agent harnesses (Codex, Grok, opencode, ...) append "exit code 0" to every
# SUCCESSFUL shell command, so an exit code only signals an error when it is
# nonzero (signed codes such as -9 included). A zero code never hides another
# failure signal in the same output: a nonzero code, "non-zero", a signal or
# a "Killed" line. A bare "exited with ..." (no code) still counts.
# failure signal in the same output: a nonzero code, "non-zero" or a signal kill.
# A standalone "Killed" line (the shell's SIGKILL message) counts only when no
# zero exit status is reported, since a successful command can print that word.
# A bare "exited with ..." (no code) still counts.
_EXIT_STATUS_RE = re.compile(
r"\bexit(?:ed)?(?:\s+with)?(?:\s+exit)?\s+(?:code|status)\s*:?\s*([+-]?\d+)", re.I
)
_EXIT_FAILURE_RE = re.compile(
r"non-zero|nonzero|exited with signal|killed by signal|^\s*Killed(?::\s*\d+)?\s*$",
re.I | re.M,
)
_EXIT_FAILURE_RE = re.compile(r"non-zero|nonzero|exited with signal|killed by signal", re.I)
_KILLED_LINE_RE = re.compile(r"^\s*Killed(?::\s*\d+)?\s*$", re.M)
_EXITED_WITH_RE = re.compile(r"exited with", re.I)
@@ -257,6 +257,8 @@ def _exit_status_is_error(snippet: str) -> bool:
codes = _EXIT_STATUS_RE.findall(snippet)
if any(int(code) != 0 for code in codes) or _EXIT_FAILURE_RE.search(snippet):
return True
if _KILLED_LINE_RE.search(snippet) and not codes:
return True
return not codes and bool(_EXITED_WITH_RE.search(snippet))
+5 -1
View File
@@ -74,7 +74,9 @@ class TestErrorClassification:
# A zero wrapper status must not hide a separate failure.
("worker exited with signal 9\nexit code 0", True),
("child exit code 2\nwrapper exit code 0", True),
("python train.py\nKilled\nexit code 0", True),
("python train.py\nKilled\n", True),
# A successful command may print the word; exit code 0 then wins.
("grep result:\nKilled\nexit code 0", False),
("task killed by signal SIGKILL\nexit code 0", True),
# Case-insensitive signals the shared is_error_content would miss.
("zsh: no such file or directory: ./run.sh", True),
@@ -117,6 +119,8 @@ class TestErrorClassification:
("Permission denied: /etc/shadow", "permission_denied"),
("TimeoutError: deadline exceeded after 30s", "timeout"),
("ConnectionError: [Errno 111] Connection refused", "connection_error"),
("task killed by signal SIGKILL", "exit_code"),
("python train.py\nKilled", "exit_code"),
],
)
async def test_error_category_recorded(