Skip to content
Merged
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
71 changes: 2 additions & 69 deletions agent/chat_completion_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
from agent.fork_ext.relay_headers import _pool_affinity_headers, _pool_lane, _pool_lane_src
from agent.reasoning_summaries import separate_glued_reasoning_blocks
from agent.stream_single_writer import claim_stream_writer, stream_writer_is_current
from agent.shared_transport_guard import _TAILSCALE_RELAY_PROVIDERS
from tools.terminal_tool import is_persistent_env
from utils import base_url_host_matches, base_url_hostname, env_float, env_int

Expand All @@ -69,7 +68,8 @@
"x-pool-route-id",
"x-pool-unreachable",
)
_POOLED_PROVIDERS = _TAILSCALE_RELAY_PROVIDERS
# Relay-pool providers whose responses carry the x-pool-* attribution headers.
_POOLED_PROVIDERS = frozenset({"claude-apr", "claude-bpr"})
_PINNED_PROVIDER_KEYS = {
"xai-oauth": "supergrok",
"gemini-bridge": "gemini",
Expand Down Expand Up @@ -3008,7 +3008,6 @@ def _side(prov, mdl, eff):
"overloaded": "provider overloaded",
"server_error": "provider error",
"timeout": "connection dropped",
"tailscale_down": "Tailscale down",
"stream_parse": "malformed stream",
"decode_error": "corrupt response",
"ssl_cert_verification": "TLS error",
Expand Down Expand Up @@ -3607,17 +3606,6 @@ def try_activate_fallback(
backoff_count, backoff_seconds, backoff_seconds / 60, backoff_count + 1,
)
if agent._fallback_index >= len(agent._fallback_chain):
try:
from agent.shared_transport_guard import emit_unavailable_summary

emit_unavailable_summary(
agent,
evidence=getattr(
agent, "_shared_transport_evidence", "backend_state=Stopped"
),
)
except Exception:
logger.debug("Could not emit shared-transport fallback summary", exc_info=True)
# Chain exhausted. If we actually walked a non-empty chain and the
# failure was NOT a rate-limit/billing event (those already armed
# their own 60s cooldown above), arm a short cooldown so the next
Expand Down Expand Up @@ -3781,61 +3769,6 @@ def try_activate_fallback(
# not pin api_mode explicitly. An explicit fb.api_mode (even
# "chat_completions") must never be overridden here.
fb_base_url = str(fb_client.base_url)
try:
from agent.shared_transport_guard import (
emit_unavailable_summary,
record_unavailable_route,
route_uses_tailscale,
tailscale_status_down,
)

if route_uses_tailscale(fb_provider, fb_base_url):
tailscale_down, tailscale_evidence = tailscale_status_down()
if tailscale_down is True:
source_uses_tailscale = route_uses_tailscale(
getattr(agent, "provider", ""),
getattr(agent, "base_url", ""),
)
if source_uses_tailscale:
record_unavailable_route(
agent,
getattr(agent, "provider", ""),
getattr(agent, "model", ""),
)
record_unavailable_route(agent, fb_provider, fb_model)
agent._shared_transport_evidence = tailscale_evidence
unavailable.add(fb_key)
try:
fb_client.close()
except Exception:
pass
logger.warning(
"Fallback skip: %s/%s shares unavailable Tailscale "
"transport (%s); suppressing for this session",
fb_provider,
fb_model,
tailscale_evidence,
)
next_reason = (
FailoverReason.tailscale_down
if source_uses_tailscale
or reason == FailoverReason.tailscale_down
else reason
)
return agent._try_activate_fallback(
next_reason, error_context=error_context,
display_reason=display_reason if next_reason == reason else None,
)
emit_unavailable_summary(
agent,
evidence=getattr(
agent, "_shared_transport_evidence", "backend_state=Stopped"
),
)
except Exception:
# Availability detection is an optimization. An unavailable or
# malformed local Tailscale CLI must preserve historical routing.
logger.debug("Shared-transport fallback preflight failed open", exc_info=True)
_fb_is_azure = agent._is_azure_openai_url(fb_base_url)

if not fb_api_mode_explicit and fb_api_mode == "chat_completions":
Expand Down
68 changes: 0 additions & 68 deletions agent/conversation_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -3629,74 +3629,6 @@ def _body_budget_failure(error_message: str) -> Dict[str, Any]:
effective_task_id=effective_task_id,
close_tail=True,
)
# ── Shared host-transport preflight ───────────────────────
# APR/BPR and direct 100.64/10 routes all depend on the local
# Tailscale client. If the host-local CLI explicitly says it is
# stopped, do not issue a request that can only consume the relay's
# full upstream timeout, then walk every route sharing the same
# prerequisite. Unknown/ambiguous CLI state fails open, so a lone
# provider timeout retains the normal retry and reason label.
try:
from agent.shared_transport_guard import (
emit_unavailable_summary,
record_unavailable_route,
route_uses_tailscale,
tailscale_status_down,
)

_route_uses_tailscale = route_uses_tailscale(
getattr(agent, "provider", ""),
getattr(agent, "base_url", ""),
)
_tailscale_down, _tailscale_evidence = (
tailscale_status_down()
if _route_uses_tailscale
else (None, "not_applicable")
)
if _route_uses_tailscale and _tailscale_down is True:
record_unavailable_route(agent, agent.provider, agent.model)
agent._shared_transport_evidence = _tailscale_evidence
if agent._try_activate_fallback(
reason=FailoverReason.tailscale_down
):
active_system_prompt = _sync_failover_system_message(
agent, api_messages, active_system_prompt
)
retry_count = 0
compression_attempts = 0
_retry.primary_recovery_attempted = False
# parity 2026-08-30: break to the restart-with-rebuilt-
# messages handler (not a bare continue) so the pre-API
# preflight re-runs against the fallback context window
# (#84733 restart discipline; upstream guard enforces).
_retry.restart_with_rebuilt_messages = True
break

emit_unavailable_summary(
agent, evidence=_tailscale_evidence
)
# The terminal result below is the single human-facing
# error. Drop the buffered aggregate here rather than send
# the same Tailscale diagnosis twice; route count/session
# detail remains in the WARNING diagnostic.
agent._clear_status_buffer()
_transport_error = "Tailscale down"
agent._persist_session(messages, conversation_history)
return {
"final_response": _transport_error,
"messages": messages,
"completed": False,
"api_calls": api_call_count,
"error": _transport_error,
"partial": True,
"failed": True,
"shared_transport_unavailable": "tailscale",
}
except Exception:
logger.debug(
"Shared-transport request preflight failed open",
exc_info=True,
)
# ── Nous Portal rate limit guard ──────────────────────
# If another session already recorded that Nous is rate-
# limited, skip the API call entirely. Each attempt
Expand Down
4 changes: 0 additions & 4 deletions agent/error_classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,6 @@ class FailoverReason(enum.Enum):

# Transport
timeout = "timeout" # Connection/read timeout β€” rebuild client + retry
# Local Tailscale client is explicitly stopped. This is not inferred from
# an API timeout: the host-local CLI must confirm the shared prerequisite
# is down before fallback routing may use this reason.
tailscale_down = "tailscale_down"
# An HTTP response stream opened successfully but contained malformed
# JSON/SSE data. Retry because another provider box may return valid bytes,
# then fail over with an honest user-facing reason if the fault persists.
Expand Down
202 changes: 0 additions & 202 deletions agent/shared_transport_guard.py

This file was deleted.

Loading
Loading