4b6817381b
CI (OpenClaw E2E) / openclaw test (push) Has been cancelled
CI / coverage-report (push) Has been cancelled
CI / test-kubernetes (push) Has been cancelled
CI / should-run-thorough (push) Has been cancelled
CI / test-thorough (cloudwatch-demo) (push) Has been cancelled
CI / test-thorough (flink-ecs) (push) Has been cancelled
CI / test-thorough (upstream-lambda) (push) Has been cancelled
CI / test-thorough (prefect-ecs-fargate) (push) Has been cancelled
Release / build-binaries (zip, opensre.exe, onefile, windows-latest, windows-x64) (push) Has been cancelled
Benchmark image — build + push to ECR (any adapter) / build + push (push) Has been cancelled
CI / quality (ubuntu-latest) (push) Has been cancelled
CI / test (tools-runtime) (push) Has been cancelled
CI / test (e2e-general) (push) Has been cancelled
CI / test (cli-runtime) (push) Has been cancelled
CI / test (e2e-provider-and-openclaw) (push) Has been cancelled
CI / test (integrations-and-misc) (push) Has been cancelled
Release / verify (push) Has been cancelled
Release / build-python-dist (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, macos-15-intel, darwin-x64) (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, macos-latest, darwin-arm64) (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04, linux-x64) (push) Has been cancelled
Release / publish-release (push) Has been cancelled
Release / publish-main-release (push) Has been cancelled
Interactive Shell Live (PR + post-merge) / turn-checks (no-LLM) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled
Interactive Shell Live (PR + post-merge) / turn-live shard ${{ matrix.shard_index }} (push) Has been cancelled
Release / prepare (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04-arm, linux-arm64) (push) Has been cancelled
Synthetic Deterministic Tests / Synthetic offline (deterministic) (push) Has been cancelled
83 lines
2.5 KiB
Python
83 lines
2.5 KiB
Python
"""Shared failure explanation for all LLM CLI adapters.
|
|
|
|
Adapters call :func:`explain_cli_failure` from ``explain_failure`` so generic
|
|
quota/auth/context/network handling lives in one place. The runner must not
|
|
re-classify or override adapter messages.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from collections.abc import Sequence
|
|
|
|
from core.llm.failure_classification import (
|
|
classify_cli_failure_category_hint,
|
|
classify_cli_failure_hint,
|
|
is_context_length_overflow,
|
|
)
|
|
|
|
__all__ = [
|
|
"classify_cli_failure_category_hint",
|
|
"classify_cli_failure_hint",
|
|
"explain_cli_failure",
|
|
"is_context_length_overflow",
|
|
]
|
|
|
|
|
|
def explain_cli_failure(
|
|
*,
|
|
exit_label: str,
|
|
stdout: str,
|
|
stderr: str,
|
|
returncode: int,
|
|
extra_messages: Sequence[str] = (),
|
|
always_include_output_snippet: bool = False,
|
|
) -> str:
|
|
"""Build a human-readable failure string for a non-zero CLI exit.
|
|
|
|
Args:
|
|
exit_label: Command label shown to users (e.g. ``codex exec``).
|
|
stdout: Process stdout (ANSI-stripped).
|
|
stderr: Process stderr (ANSI-stripped).
|
|
returncode: Subprocess exit code.
|
|
extra_messages: Provider-specific messages inserted before generic hints.
|
|
always_include_output_snippet: When True, append stderr/stdout after
|
|
``extra_messages`` (used by adapters that surface raw CLI output
|
|
alongside tailored guidance).
|
|
"""
|
|
err = (stderr or "").strip()
|
|
out = (stdout or "").strip()
|
|
bits: list[str] = [f"{exit_label} exited with code {returncode}"]
|
|
bits.extend(msg for msg in extra_messages if msg)
|
|
has_extra = len(bits) > 1
|
|
|
|
if has_extra:
|
|
if always_include_output_snippet:
|
|
if err:
|
|
bits.append(err[:2000])
|
|
elif out:
|
|
bits.append(out[:2000])
|
|
return ". ".join(bits)
|
|
|
|
if always_include_output_snippet:
|
|
if err:
|
|
bits.append(err[:2000])
|
|
elif out:
|
|
bits.append(out[:2000])
|
|
else:
|
|
hint = classify_cli_failure_hint(stdout, stderr, returncode)
|
|
if hint:
|
|
bits.append(hint)
|
|
return ". ".join(bits)
|
|
|
|
category = classify_cli_failure_category_hint(stdout, stderr, returncode)
|
|
if err:
|
|
bits.append(category if category else err[:2000])
|
|
elif out:
|
|
bits.append(category if category else out[:2000])
|
|
else:
|
|
hint = classify_cli_failure_hint(stdout, stderr, returncode)
|
|
if hint:
|
|
bits.append(hint)
|
|
|
|
return ". ".join(bits)
|