Principle:2aronS Duel Agents Connectivity Verification
| Knowledge Sources | |
|---|---|
| Domains | Networking, Configuration |
| Last Updated | 2026-10-27 14:00 GMT |
Overview
Technique for verifying that a credential is accepted by a remote API by probing a sequence of read-only endpoints, classifying the outcome into distinct status categories, and never throwing — translating all failures into a structured result.
Description
After installing a credential, the user needs to know whether it actually works. A simple "ping" is insufficient because different failure modes require different user actions:
- Invalid key format — the key is malformed locally; the user needs to re-enter it
- Unauthorized (401/403) — the key is well-formed but rejected by the server; the user needs to renew or check the dashboard
- Unreachable — network issue, wrong proxy URL, or server down; the user should retry later
Connectivity verification addresses this by probing multiple read-only endpoints (e.g., `/models`, `/health`, root `HEAD`) in sequence. Each attempt carries the credential in an `Authorization` header and has a bounded timeout. The first definitive result — a 2xx (ok) or a 401/403 (unauthorized) — short-circuits the loop. Network errors and non-definitive HTTP statuses fall through to the next attempt. If no attempt succeeds, the result is "unreachable" with the last error message.
The key design property is that the function never throws: all exceptions are caught and folded into the result. This makes it safe to call in a CLI `doctor` command where an unhandled exception would produce a confusing stack trace.
Usage
Use this principle when:
- Building a "doctor" or "diagnostics" command that verifies post-install health
- You need to distinguish "bad key" from "bad network" to give the user actionable guidance
- A single endpoint may not always be available, so you need fallback probes
- You want a probe that is safe to run repeatedly (read-only, bounded timeout)
Theoretical Basis
The verification is a fold over a list of endpoint attempts, short-circuiting on definitive results:
# Abstract algorithm (NOT real implementation)
def check_connectivity(key: str, base_url: str) -> ConnectivityResult:
if not validate_format(key):
return Result(ok=False, status="invalid_key", ...)
attempts = [("/models", "GET"), ("/health", "GET"), ("", "HEAD")]
last_error = ""
for path, method in attempts:
try:
res = fetch(base_url + path, method=method, headers={...}, timeout=15s)
if res.status in (401, 403):
return Result(ok=False, status="unauthorized", httpStatus=res.status)
if res.ok:
return Result(ok=True, status="ok", httpStatus=res.status)
last_error = f"HTTP {res.status}"
except Exception as e:
last_error = str(e)
return Result(ok=False, status="unreachable", message=last_error)
The result type is a tagged union:
Failed to parse (syntax error): {\displaystyle \text{ConnectivityResult} = \{ \text{ok}: \text{bool},\ \text{status}: \{\text{ok}, \text{unauthorized}, \text{unreachable}, \text{invalid\_key}\},\ \text{message}: \text{str},\ \text{httpStatus?}: \text{int} \} }