Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion meta_harness/failure_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import hashlib
import json
import re
from dataclasses import dataclass, field
from typing import Any, Mapping

Expand Down Expand Up @@ -189,7 +190,14 @@ def classify_failure(
return code
if "cuda out of memory" in text or "cublas_status_alloc_failed" in text:
return "cuda_oom"
if "401" in text or "403" in text or "authentication" in text or "gated repo" in text:
# A duration, package name, or model identifier can contain these digits
# without being an HTTP status. Misreading one disables ordinary recovery
# and asks for credentials that cannot fix the underlying failure.
if (
re.search(r"(?<![\w.])(?:401|403)(?!\w|\.\w)", text)
or "authentication" in text
or "gated repo" in text
):
return "authentication_required"
if "dataset" in text and any(token in text for token in ("not found", "unavailable", "404")):
return "dataset_unavailable"
Expand Down
44 changes: 44 additions & 0 deletions tests/test_failure_status_boundaries.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"""Unrelated numeric text must not send retryable failures to auth recovery."""

import pytest

from meta_harness.failure_policy import FailureContext, classify_failure, decide_recovery


@pytest.mark.parametrize(
("message", "expected"),
[
("model download timeout after 1.403 seconds", "model_download_timeout"),
("model download timeout after 403.5 seconds", "model_download_timeout"),
("connection reset for model-401b", "network_transient"),
("timed out after 1403 milliseconds", "network_transient"),
("No module named 'package401'", "dependency_missing"),
],
)
def test_numeric_substrings_preserve_the_actual_failure(message, expected):
reason = classify_failure(message=message, returncode=1)
assert reason == expected
decision = decide_recovery(
FailureContext(reason, message, "code", "environment", 3600),
fingerprint_seen=False,
)
assert decision.reason_code == expected
if expected in {"model_download_timeout", "network_transient"}:
assert decision.retryable


@pytest.mark.parametrize(
"message",
[
"HTTP Error 401: Unauthorized",
"Client error '403 Forbidden' for url https://example.test/model",
"status_code=401",
"request failed with HTTP status 403.",
"HTTP status 401. Credentials are required.",
"403",
"authentication required",
"gated repo access denied",
],
)
def test_actual_authentication_failures_still_require_credentials(message):
assert classify_failure(message=message, returncode=1) == "authentication_required"
Loading