Skip to content

armgit / avibe

Public Imported from GitHub
0

Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.

fix(model-hub): avoid model scheduling during provider detection (#1920)

Call Whitea3cc88d32f99
diff --git a/config/v2_config.py b/config/v2_config.py
index 387daac04..44ffbf440 100644
--- a/config/v2_config.py
+++ b/config/v2_config.py
@@ -2829,6 +2829,7 @@ class ModelHubSourceConfig:
credential_ref: Optional[str] = None
account_label: Optional[str] = None
masked_credential: Optional[str] = None
+ verification_pending: Optional[str] = None
@classmethod
def from_payload(cls, payload: dict, *, repairing: bool = False) -> "ModelHubSourceConfig":
@@ -2852,6 +2853,7 @@ class ModelHubSourceConfig:
"credential_ref",
"account_label",
"masked_credential",
+ "verification_pending",
}
if set(payload) - allowed_fields:
raise ValueError("Config 'model_hub.sources' contains unknown fields")
@@ -2899,6 +2901,12 @@ class ModelHubSourceConfig:
credential_ref = payload.get("credential_ref")
account_label = payload.get("account_label")
masked_credential = payload.get("masked_credential")
+ verification_pending = payload.get("verification_pending")
+ if verification_pending is not None and (
+ not isinstance(verification_pending, str)
+ or re.fullmatch(r"vp_[0-9a-f]{32}", verification_pending) is None
+ ):
+ raise ValueError("Config 'model_hub.sources.verification_pending' must be a verification marker")
created_at = payload.get("created_at")
client_nonce = (
validate_model_hub_source_client_nonce(payload.get("client_nonce"))
@@ -2952,6 +2960,7 @@ class ModelHubSourceConfig:
credential_ref=credential_ref,
account_label=account_label,
masked_credential=masked_credential,
+ verification_pending=verification_pending,
)
def to_payload(self) -> dict:
@@ -2974,6 +2983,8 @@ class ModelHubSourceConfig:
}
if self.client_nonce is not None:
payload["client_nonce"] = self.client_nonce
+ if self.verification_pending:
+ payload["verification_pending"] = self.verification_pending
if self.usage is not None:
payload["usage"] = self.usage.to_payload()
return payload
diff --git a/core/handlers/model_hub/adapter.py b/core/handlers/model_hub/adapter.py
index a2dea1ce0..4979d0157 100644
--- a/core/handlers/model_hub/adapter.py
+++ b/core/handlers/model_hub/adapter.py
@@ -510,11 +510,14 @@ class EngineAdapter(Protocol):
``protocol_order`` either enumerates Auto-detect probes or names one
owner-constrained protocol. A returned protocol may be established by
a protocol-shaped upstream response, by a shipped API-key vendor pin,
- or by a concrete `custom` declaration. The latter two require a
- response from that exact path plus the September 4, 2026 auth ladder:
- 401/403 reject, while 2xx and request-error 400/404/422 accept even
- if the response shape itself stays generic. `custom` Auto detect still
+ or by a concrete `custom` declaration. Schema-validation errors,
+ altered-credential controls and public inventory cannot establish
+ authentication. A shaped success can; a bare status cannot. Auto still
requires response-backed proof; order alone never proves a protocol.
+ Explicit unverified API-key saving and completed Hub OAuth admission
+ belong to Source creation, not this non-persisting evidence result.
+ They retain a fixed protocol owner with verification pending and do
+ not turn an unknown/rejected observation into authentication proof.
"""
...
diff --git a/core/handlers/model_hub/migration.py b/core/handlers/model_hub/migration.py
index 7d93be26d..7d90cf82c 100644
--- a/core/handlers/model_hub/migration.py
+++ b/core/handlers/model_hub/migration.py
@@ -67,6 +67,9 @@ class MigrationHost(Protocol):
@staticmethod
def _clone_config(config: ModelHubConfig) -> ModelHubConfig: ...
+ @staticmethod
+ def _mark_source_unverified(source: ModelHubSourceConfig) -> None: ...
+
async def _engine_call(self, awaitable: Awaitable[Any]) -> Any: ...
async def _commit_synced(
@@ -824,6 +827,8 @@ async def apply_native_migration(
)
except (TypeError, ValueError):
raise MigrationConflictError from None
+ if source.supply_channel == "hub":
+ host._mark_source_unverified(source)
updated.sources.append(source)
host._apply_source_placement(updated, source)
diff --git a/core/handlers/model_hub/service.py b/core/handlers/model_hub/service.py
index fdc19dc5f..04f99c030 100644
--- a/core/handlers/model_hub/service.py
+++ b/core/handlers/model_hub/service.py
@@ -269,6 +269,8 @@ class ModelHubConfigStore(Protocol):
def save(self, config: ModelHubConfig) -> None: ...
+ def mutate(self, mutator: Callable[[ModelHubConfig], bool]) -> None: ...
+
class V2ModelHubConfigStore:
def load(self) -> ModelHubConfig:
@@ -292,6 +294,14 @@ class V2ModelHubConfigStore:
update_config_fields(lambda cfg: setattr(cfg, "model_hub", model_hub))
+ def mutate(self, mutator: Callable[[ModelHubConfig], bool]) -> None:
+ from config.v2_config import config_file_lock
+
+ with config_file_lock():
+ config = V2Config.load()
+ if mutator(config.model_hub):
+ config.save()
+
class UnavailableEngineAdapter:
"""Explicit fail-closed adapter for isolated callers and tests."""
@@ -396,6 +406,7 @@ class ResolvedInvocation:
supply_channel: Literal["native_cli", "hub"] = "hub"
credential_ref: Optional[str] = None
settlement_generation: Optional[int] = None
+ verification_pending: Optional[str] = None
@dataclass(frozen=True)
@@ -2041,16 +2052,19 @@ class ModelHubService:
discovered: list[DiscoveredModel] | None
if channel == "hub":
rollback_credential_ref = cast(str, flow.credential_ref)
- observation = await self._require_proven_observation(
+ observation = await self._observe_provisioned_credential(
vendor,
None,
rollback_credential_ref,
SOURCE_PROTOCOLS,
)
- protocol = cast(
- Literal["anthropic", "openai_responses", "openai_chat"],
- observation.protocol,
+ # Completed consent supplies credential custody, not proof
+ # that a model call works. Its vendor fixes the interface.
+ protocol = observation.protocol or _FIXED_BACKEND_PROTOCOLS.get(
+ _NATIVE_VENDOR_BACKENDS.get(vendor, vendor),
)
+ if protocol is None:
+ raise ModelHubError("discovery_failed")
if observation.discovery is ObservationDiscovery.SUCCEEDED:
discovered = list(observation.models)
elif observation.discovery is ObservationDiscovery.FAILED:
@@ -2060,7 +2074,12 @@ class ModelHubService:
detail_key="models.source.error.unclassified",
)
else:
- raise ModelHubError("discovery_failed", status=502)
+ discovered = None
+ if observation.authenticated is False:
+ state = ModelHubSourceStateConfig(
+ status="needs_action",
+ detail_key="models.source.needs_action.oauth_expired",
+ )
else:
backend = _NATIVE_VENDOR_BACKENDS.get(vendor)
protocol = (
@@ -2115,6 +2134,20 @@ class ModelHubService:
source = ModelHubSourceConfig.from_payload(source_payload)
except (TypeError, ValueError):
raise ModelHubError("discovery_failed") from None
+ if channel == "hub":
+ self._mark_source_unverified(source)
+ if (
+ channel == "hub"
+ and observation.outcome is not ObservationOutcome.OBSERVED
+ and observation.authenticated is not False
+ ):
+ try:
+ discovered = await self._discover(source)
+ except ModelHubError as exc:
+ if exc.code != "discovery_failed":
+ raise
+ # Inventory is optional and never verifies the login.
+ discovered = None
if discovered is not None:
self._apply_discovered_models(
source,
@@ -2413,6 +2446,7 @@ class ModelHubService:
if model.provenance == "manual"
]
source.credential_ref = replacement_ref
+ self._mark_source_unverified(source)
discovered = await self._discover(source)
overrides = self._apply_discovered_models(source, manual, discovered)
source.state = ModelHubSourceStateConfig(status="standby")
@@ -2705,6 +2739,7 @@ class ModelHubService:
"protocol",
"client_nonce",
"accept_unavailable_inventory",
+ "save_unverified",
}:
raise ModelHubError("discovery_failed")
forbidden = {
@@ -2791,13 +2826,16 @@ class ModelHubService:
if kind != "api_key" and client_nonce is not None:
raise ModelHubError("discovery_failed")
accept_unavailable_inventory = payload.get("accept_unavailable_inventory", False)
+ save_unverified = payload.get("save_unverified", False)
if (
not isinstance(accept_unavailable_inventory, bool)
+ or not isinstance(save_unverified, bool)
or (
kind != "api_key"
and (
"protocol" in payload
or "accept_unavailable_inventory" in payload
+ or "save_unverified" in payload
)
)
):
@@ -2805,6 +2843,8 @@ class ModelHubService:
protocol_order: tuple[str, ...] | None = None
if kind == "api_key":
protocol_order = self._observation_protocols(vendor, payload)
+ if save_unverified and len(protocol_order) != 1:
+ raise ModelHubError("discovery_failed", detail="modelHub.errors.ambiguous_source")
if oauth_ref:
return self._source_creation_result(
@@ -2866,9 +2906,13 @@ class ModelHubService:
}
if "protocol" in payload:
observation_payload["protocol"] = payload["protocol"]
- observation = await self._require_proven_source_payload(observation_payload)
+ observation = (
+ None if save_unverified
+ else await self._require_proven_source_payload(observation_payload)
+ )
if (
- observation.discovery is ObservationDiscovery.FAILED
+ observation is not None
+ and observation.discovery is ObservationDiscovery.FAILED
and not accept_unavailable_inventory
):
raise ModelHubError(
@@ -2877,18 +2921,20 @@ class ModelHubService:
detail="modelHub.errors.inventory_unavailable",
data={"observation": self._observation_payload(observation)},
)
- source.protocol = cast(
- Literal["anthropic", "openai_responses", "openai_chat"],
- observation.protocol,
- )
- if observation.discovery is ObservationDiscovery.SUCCEEDED:
+ self._mark_source_unverified(source)
+ if observation is not None:
+ source.protocol = cast(
+ Literal["anthropic", "openai_responses", "openai_chat"],
+ observation.protocol,
+ )
+ if observation is not None and observation.discovery is ObservationDiscovery.SUCCEEDED:
self._apply_discovered_models(
source,
manual_models,
list(observation.models),
allow_empty=True,
)
- elif observation.discovery is ObservationDiscovery.FAILED:
+ else:
catalog_efforts_by_model = bundled_catalog_reasoning_efforts_by_model()
for model in source.models:
resolution = resolve_reasoning_tiers(
@@ -2900,10 +2946,11 @@ class ModelHubService:
)
model.reasoning_efforts = list(resolution.efforts)
model.reasoning_efforts_source = resolution.source
- source.state = ModelHubSourceStateConfig(
- status="error",
- detail_key="models.source.error.unclassified",
- )
+ if observation is not None:
+ source.state = ModelHubSourceStateConfig(
+ status="error",
+ detail_key="models.source.error.unclassified",
+ )
# AC-29 requires the canonical Source validator to run before any
# permanent credential is provisioned. The placeholder is never saved.
@@ -3002,6 +3049,7 @@ class ModelHubService:
old_revocation_recorded = False
try:
source.credential_ref = replacement_ref
+ self._mark_source_unverified(source)
source.masked_credential = _mask_credential(key)
discovered = await self._discover(source)
if old_credential_ref != replacement_ref:
@@ -3117,6 +3165,7 @@ class ModelHubService:
old_revocation_recorded = False
try:
source.credential_ref = replacement_ref
+ self._mark_source_unverified(source)
source.base_url = base_url
discovered = await self._discover(source)
self.revocations.add(source.id, old_credential_ref)
@@ -5236,6 +5285,7 @@ class ModelHubService:
},
)
source = self._source(config, candidate_payload["source_id"])
+ verification_pending = source.verification_pending
resolved_model = candidate_payload["model_id"]
if source.supply_channel == "native_cli":
ready = self.native_source_ready(
@@ -5299,6 +5349,10 @@ class ModelHubService:
decision = classify_outcome(outcome, refresh_attempted=True)
elapsed_ms = max(0, round((time.monotonic() - started_at) * 1000))
reachable = decision.action == "return"
+ if reachable:
+ await self._verify_successful_source(
+ source.id, source.credential_ref, verification_pending, outcome,
+ )
error_key: Optional[str] = None
latency_ms: Optional[int] = elapsed_ms
if not reachable:
@@ -6228,6 +6282,44 @@ class ModelHubService:
resolution=resolution,
)
+ @staticmethod
+ def _mark_source_unverified(source: ModelHubSourceConfig) -> None:
+ # Persist identity with the credential, including same-handle reauth.
+ source.verification_pending = f"vp_{uuid.uuid4().hex}"
+
+ async def _verify_successful_source(
+ self,
+ source_id: str,
+ credential_ref: str | None,
+ verification_pending: str | None,
+ outcome: RawCallOutcome,
+ ) -> None:
+ """Retire pending verification only for the current credential's call."""
+ if outcome.kind is not RawOutcomeKind.SUCCESS or verification_pending is None:
+ return
+ def clear_current(config: ModelHubConfig) -> bool:
+ current = next((item for item in config.sources if item.id == source_id), None)
+ if (
+ current is None
+ or current.credential_ref != credential_ref
+ or current.verification_pending != verification_pending
+ ):
+ return False
+ current.verification_pending = None
+ return True
+
+ try:
+ async with self._mutation_lock:
+ self.store.mutate(clear_current)
+ except ValueError as exc:
+ if "recovery warnings" not in str(exc):
+ raise
+ logger.warning("Could not persist Model Hub verification state during config recovery")
+ except OSError:
+ # Advisory bookkeeping must not turn a completed model call into a
+ # failed response. Retain pending verification for the next success.
+ logger.warning("Could not persist Model Hub verification state")
+
async def settle_handle_outcome(
self,
resolved: ResolvedInvocation | None,
@@ -6260,6 +6352,9 @@ class ModelHubService:
)
record_attempt(outcome, decision)
if decision.action == "return":
+ await self._verify_successful_source(
+ resolved.source_id, resolved.credential_ref, resolved.verification_pending, outcome,
+ )
return HandleSettlement(
outcome=outcome,
decision=decision,
@@ -6784,6 +6879,7 @@ class ModelHubService:
target_model = inspection.model_id
if source is None or target_model is None:
raise AssertionError("runnable hop must have an exact identity")
+ verification_pending = source.verification_pending
exact_reasoning_request = self._request_for_exact_reasoning_effort(
request,
source,
@@ -6861,6 +6957,7 @@ class ModelHubService:
outcome=None,
credential_ref=source.credential_ref,
settlement_generation=settlement_generation,
+ verification_pending=verification_pending,
)
decision = await self._classify_source_outcome(source, outcome)
if cancelled is not None:
@@ -6915,6 +7012,7 @@ class ModelHubService:
outcome=None,
credential_ref=source.credential_ref,
settlement_generation=settlement_generation,
+ verification_pending=verification_pending,
)
decision = classify_outcome(outcome, refresh_attempted=True)
if cancelled is not None:
@@ -6941,6 +7039,9 @@ class ModelHubService:
(),
)
if decision.action == "return":
+ await self._verify_successful_source(
+ source.id, source.credential_ref, verification_pending, outcome,
+ )
self._emit_switch(
agent=event_agent,
model_id=model_id,
@@ -6958,6 +7059,7 @@ class ModelHubService:
outcome=outcome,
credential_ref=source.credential_ref,
settlement_generation=settlement_generation,
+ verification_pending=verification_pending,
)
if decision.action == "surface":
source_transition_persisted: bool | None = None
diff --git a/docs/plans/model-hub-contracts/README.md b/docs/plans/model-hub-contracts/README.md
index 6b19c5630..2bf5d69a6 100644
--- a/docs/plans/model-hub-contracts/README.md
+++ b/docs/plans/model-hub-contracts/README.md
@@ -69,10 +69,17 @@ No underlying engine expansion or OAuth alias substitution is part of this chang
api-key vendor catalog pin, a user declaration on `custom`, or a matching
protocol-shaped upstream response. `POST /api/models/sources/observe` is the
non-persisting API-key observation surface; API-key `POST /api/models/sources`
- performs the same observation before its independent committed credential
- provisioning, while subscription OAuth uses its vendor-specific observation flow.
- A typed Base URL never creates a saved protocol value. Catalog pin and declaration
- still require reachability and authentication; they never bypass those failures.
+ normally repeats observation before committed credential provisioning. Explicit
+ `save_unverified: true` permits a catalog pin or declaration without observation;
+ custom Auto still cannot be guessed. Completed Hub OAuth consent can retain its
+ bound credential under the fixed vendor protocol. Every newly stored Hub
+ credential, including observed creates and native-config imports, carries an
+ opaque `verification_pending` identity until an actual matching-credential
+ model call succeeds. Its clearing is a fresh cross-process field mutation;
+ model discovery never clears it. A typed Base URL never
+ supplies protocol ownership. Model-free validation, altered-credential controls
+ and public model lists do not prove authentication. See the 2026-09-07 ruling
+ in `docs/plans/model-hub.md` and the create/Source schemas for the complete policy.
3. Every Source/model reference is canonical and referentially valid at write time.
Unchanged stale Route hops may be retained or reordered, but new or changed pairs
must validate Source existence/eligibility, canonical identifiers and explicit retirement.
diff --git a/docs/plans/model-hub-contracts/adapter-interface.py b/docs/plans/model-hub-contracts/adapter-interface.py
index a2dea1ce0..4979d0157 100644
--- a/docs/plans/model-hub-contracts/adapter-interface.py
+++ b/docs/plans/model-hub-contracts/adapter-interface.py
@@ -510,11 +510,14 @@ class EngineAdapter(Protocol):
``protocol_order`` either enumerates Auto-detect probes or names one
owner-constrained protocol. A returned protocol may be established by
a protocol-shaped upstream response, by a shipped API-key vendor pin,
- or by a concrete `custom` declaration. The latter two require a
- response from that exact path plus the September 4, 2026 auth ladder:
- 401/403 reject, while 2xx and request-error 400/404/422 accept even
- if the response shape itself stays generic. `custom` Auto detect still
+ or by a concrete `custom` declaration. Schema-validation errors,
+ altered-credential controls and public inventory cannot establish
+ authentication. A shaped success can; a bare status cannot. Auto still
requires response-backed proof; order alone never proves a protocol.
+ Explicit unverified API-key saving and completed Hub OAuth admission
+ belong to Source creation, not this non-persisting evidence result.
+ They retain a fixed protocol owner with verification pending and do
+ not turn an unknown/rejected observation into authentication proof.
"""
...
diff --git a/docs/plans/model-hub-contracts/api.md b/docs/plans/model-hub-contracts/api.md
index 8258b3ad8..bb1d01cb3 100644
--- a/docs/plans/model-hub-contracts/api.md
+++ b/docs/plans/model-hub-contracts/api.md
@@ -92,23 +92,44 @@ response. A supplied protocol is established when authentication succeeds and ei
`vendor` has a shipped catalog pin, the client declared that protocol on `custom`, or
a matching protocol-shaped response proves it. The protocol probe is deliberately
schema-invalid and names no synthetic model, so a relay can authenticate and classify it
-without selecting or invoking an upstream model. A bare-origin Base URL uses the
+without selecting or invoking an upstream model. Schema validation does not prove
+authentication. Synthetic altered credentials are not used: unknown token grammars
+and middleware ordering make their rejection inconclusive. Public inventory and
+`accept_unavailable_inventory` never supply authentication proof.
+A bare-origin Base URL uses the
standard `/v1` endpoint paths, while a URL with a path is treated as the complete API
root. The endpoint provisions an unbound engine credential only for this operation,
returns `observation-result.schema.json`, then revokes the transient reference before
settling. A revoke failure remains in the existing pending-revocation journal. The
response never contains that reference or any persisted Source.
-For an API-key `POST /api/models/sources`, the server performs the same
+For an API-key `POST /api/models/sources` without `save_unverified: true`, the server performs the same
server-owned observation internally before its independent committed credential
provisioning. It accepts the create fields and optional protocol constraint, but never
accepts protocol proof or inventory results from the caller. A null protocol
produces no Source. A repeated observation that establishes a protocol owner but ends
with failed inventory discovery produces no Source unless this request explicitly carries
`accept_unavailable_inventory: true`; the accepted Source has `models: []` and the
-existing uncertain health projection. Subscription OAuth creation follows its
-vendor-specific observation flow before commit. Saved Sources use the stored protocol for
-every later operation.
+existing uncertain health projection.
+
+Explicit `save_unverified: true` instead saves the catalog-pinned or user-declared
+interface without upstream observation or discovery. Custom Auto without a declaration
+is rejected before credential provisioning. Manual models remain manual; no inventory
+is invented. The Source carries an opaque `verification_pending` marker, independently of its
+routing health, and may be configured and invoked. List/detail surfaces label it
+unverified, not healthy/in use. Successful inventory discovery never clears this flag.
+Every newly stored Hub credential starts pending, including observed creates and
+native-config imports. A call captures the persisted marker before invocation; any
+successful call using the same current credential and marker clears it through a
+fresh cross-process config transaction. Newer same-credential attempts do not negate
+success. Credential/endpoint replacement generates a new marker, including same-handle
+OAuth reauthentication; old calls and failed calls cannot verify that replacement.
+Existing Sources lacking the optional marker retain their existing state.
+
+Completed Hub OAuth consent can likewise retain its bound credential under the fixed
+vendor protocol with verification pending. An explicit authentication rejection keeps
+the existing needs-action state. Native CLI OAuth is unchanged. Saved Sources use the
+stored protocol for every later operation. No create path performs a model invocation.
`source-create.schema.json` is the complete `SourceCreate` request. Its field table is
authoritative; no Source response field may be inferred backwards into the request:
diff --git a/docs/plans/model-hub-contracts/observation-result.schema.json b/docs/plans/model-hub-contracts/observation-result.schema.json
index c77890e51..b64e1d9b3 100644
--- a/docs/plans/model-hub-contracts/observation-result.schema.json
+++ b/docs/plans/model-hub-contracts/observation-result.schema.json
@@ -2,7 +2,7 @@
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "model-hub/observation-result.schema.json",
"title": "SourceObservation",
- "description": "Response-backed result of the unsaved Source observation. It never contains a credential reference or persisted Source state. Any upstream response proves reachability, but a bare HTTP status proves neither protocol nor authentication. Authentication is accepted only for a shaped success or a shaped request error that occurs after authentication; shaped authentication errors are rejected, while shaped server and rate-limit errors leave authentication unknown and settle as adapter_error rather than observed or ambiguous.",
+ "description": "Response-backed result of the unsaved Source observation. It never contains a credential reference or persisted Source state. Any upstream response proves reachability, but a bare HTTP status proves neither protocol nor authentication. A shaped success can establish authentication; schema errors cannot, because they can precede authentication. No synthetic credential control or public model inventory upgrades that evidence. Shaped authentication errors reject their candidate; unknown sibling candidates in Auto remain unknown. Shaped request, server and rate-limit errors leave authentication unknown and settle as adapter_error rather than observed. Explicit unverified Source creation is separate from this result and never changes its evidence.",
"type": "object",
"required": [
"contract_version",
diff --git a/docs/plans/model-hub-contracts/source-create.schema.json b/docs/plans/model-hub-contracts/source-create.schema.json
index 474866bf1..fbcdbc76f 100644
--- a/docs/plans/model-hub-contracts/source-create.schema.json
+++ b/docs/plans/model-hub-contracts/source-create.schema.json
@@ -2,15 +2,20 @@
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "model-hub/source-create.schema.json",
"title": "SourceCreate",
- "description": "API-key Source creation input. It extends the unsaved observation request with display, reconciliation, and explicit unavailable-inventory consent data; the server still owns Source identity, protocol, discovered inventory, health, usage, custody metadata, and timestamps. Optional protocol restricts observation to one interface; omission selects the shipped vendor pin when one exists, otherwise only custom omission auto-detects across the supported interfaces. A supplied protocol is persisted when observation is authenticated and either vendor has a shipped catalog pin for that protocol, the client declared it on custom, or a matching protocol-shaped upstream response proves it. Auto-detect without a catalog pin still requires matching response proof. When client_nonce is present, the server reserves it atomically in process before observation or credential work; only a successful commit persists Source.client_nonce unchanged. A lost-response client reconciles through the ordinary Source list without a receipt or separate endpoint. Nonce uniqueness covers live-process reservations and live Sources; process restart or Source deletion releases it, and a later same-nonce request after the required list read is a fresh create.",
+ "description": "API-key Source creation input. The default path requires authenticated observation and a protocol established by a shipped catalog pin, a declaration on custom, or matching response proof. Explicit save_unverified consent instead persists configuration with verification pending, without observation or discovery, and requires a catalog pin or a concrete custom declaration. The server owns Source identity, discovered inventory, health, usage, custody metadata and timestamps. Both paths use canonical validation and the same custody, rollback and reconciliation lifecycle. When client_nonce is present, the server reserves it atomically in process before observation or credential work; only a successful commit persists Source.client_nonce unchanged. A lost-response client reconciles through the ordinary Source list without a receipt or separate endpoint. Nonce uniqueness covers live-process reservations and live Sources; process restart or Source deletion releases it, and a later same-nonce request after the required list read is a fresh create.",
"type": "object",
"required": ["vendor", "key"],
"additionalProperties": false,
"properties": {
+ "save_unverified": {
+ "type": "boolean",
+ "default": false,
+ "description": "Explicit consent to save configuration without upstream observation or discovery. Requires a catalog-pinned or explicitly declared protocol; custom Auto cannot be guessed. Canonical input validation, credential custody, rollback and nonce reconciliation are unchanged. Sets Source.verification_pending, preserves manual models and does not claim usability."
+ },
"vendor": {
"type": "string",
"pattern": "^[a-z0-9]+(?:[._-][a-z0-9]+)*$",
- "description": "Vendor id used by the response-backed observation."
+ "description": "Vendor id used for catalog ownership and optional observation."
},
"display_name": {
"type": "string",
@@ -29,7 +34,7 @@
},
"protocol": {
"enum": ["anthropic", "openai_responses", "openai_chat"],
- "description": "Optional user-selected interface. When present, observation probes exactly this protocol. Omission selects the shipped vendor pin when one exists; otherwise on vendor custom it auto-detects across the authoritative protocol vocabulary and still requires matching response proof. Persistence requires authentication plus one of: a shipped vendor catalog pin for this protocol, a declaration on vendor custom, or matching protocol-shaped upstream response proof."
+ "description": "Optional user-selected interface. When present, observation probes exactly this protocol. Omission selects the shipped vendor pin when one exists; otherwise custom Auto requires matching response proof. Explicit unverified saving requires a catalog pin or a concrete custom declaration and never guesses a protocol."
},
"client_nonce": {
"type": "string",
@@ -57,6 +62,13 @@
"key": "<transient plaintext key>",
"protocol": "openai_chat",
"accept_unavailable_inventory": true
+ },
+ {
+ "vendor": "custom",
+ "base_url": "https://relay.example/v1",
+ "key": "<transient plaintext key>",
+ "protocol": "openai_chat",
+ "save_unverified": true
}
]
}
diff --git a/docs/plans/model-hub-contracts/source.schema.json b/docs/plans/model-hub-contracts/source.schema.json
index da7be7ace..13c9e781d 100644
--- a/docs/plans/model-hub-contracts/source.schema.json
+++ b/docs/plans/model-hub-contracts/source.schema.json
@@ -19,6 +19,11 @@
],
"additionalProperties": false,
"properties": {
+ "verification_pending": {
+ "type": ["string", "null"],
+ "pattern": "^vp_[0-9a-f]{32}$",
+ "description": "Opaque, non-secret pending-verification identity, replaced whenever Hub credential material or endpoint is stored, including observed creates and same-handle OAuth reauthentication. Presence means not yet model-call verified, independently of routing health. An invocation captures this marker before admission; any successful call with the same current credential and marker may clear it through a fresh cross-process config mutation. Later same-credential calls do not invalidate proof. Inventory never clears it. Null or omission retains legacy behavior without a retrospective verification claim."
+ },
"id": {
"type": "string",
"pattern": "^src_[a-z0-9]{8,}$"
diff --git a/docs/plans/model-hub-ui-spec.md b/docs/plans/model-hub-ui-spec.md
index d4182e844..dd6398742 100644
--- a/docs/plans/model-hub-ui-spec.md
+++ b/docs/plans/model-hub-ui-spec.md
@@ -3243,6 +3243,21 @@ Stated as the property rather than as three call sites: **an interface this dial
not detect says where it came from, and the row that says it also says what detection
is still for.**
+**2026-09-07 owner-approved unverified-save exit.** An explicit catalog pin or
+concrete custom declaration permits `Save unverified` (`addKey.saveUnverified`)
+from the valid initial form and observation failure/undetermined states. Reuse the
+outline footer action with the Save icon; enter the existing persisting phase with
+`save_unverified: true`. Custom Auto has no such exit until an interface is selected.
+Unknown-write reconciliation retains this consent and the nonce. Draft edits retire
+held evidence as before. The footer wraps on narrow screens. This supersedes the
+observation prerequisite in the earlier state tables, not cancellation, settlement
+or focus ownership. No upstream observation or inventory request occurs on this exit.
+Source list/detail show `sourceDetail.status.unverified` in existing advisory ink;
+error/cooldown states retain visual precedence. Adoption and model discovery cannot
+replace this label with healthy/in-use copy. Only an actual successful model call
+retires verification as defined by the Source contract. Ambiguity copy must not
+claim authentication success.
+
**Element inventory**
| Element | Displays | Data source | Interactive | On activate |
@@ -3262,7 +3277,7 @@ is still for.**
| `WZyA8` selector | the same four interface choices, expanded in place, glyphs on concrete options | selection | yes, Auto detect remains selected until changed | Select one concrete interface; enables 重试 |
| `Nak7y` ④ foot | 取消 / 重试 (dimmed until a concrete interface is picked) | selection | yes | — |
| `d6bFlX` state ⑤ strip | the interface *was* identified, and the model list did not come back | observation result | no | — |
-| `x0Gzg` ⑤ foot | 取消 / 仍要添加 / 重试 — **three** buttons, the only foot in the product with three | — | yes | Dismiss / save the source without an inventory / rerun the entire observation |
+| `x0Gzg` ⑤ foot | 取消 / 仍要添加 / 重试 — three buttons | — | yes | Dismiss / save the source without an inventory / rerun the entire observation |
| `sqZa9` success note | that the dialog closes straight into 06 | static | no | — |
**Metrics** `[frame]`: dialog 560 wide, height auto in all five states — the frame
diff --git a/docs/plans/model-hub-vendor-preset-protocol.md b/docs/plans/model-hub-vendor-preset-protocol.md
index 4c4ab3013..c415fc612 100644
--- a/docs/plans/model-hub-vendor-preset-protocol.md
+++ b/docs/plans/model-hub-vendor-preset-protocol.md
@@ -147,6 +147,54 @@ invariants change.
- G-18 / G-27 rows: probe constraint language is now only the Auto
branch on `custom`.
+## Model-independent observation (2026-09-07)
+
+Protocol observation omits `model` for every interface. A fabricated model can
+enter a relay's scheduler and return capacity or upstream errors before request
+validation, making valid credentials impossible to add. A model-free request
+keeps observation independent of model availability and generation. The shared
+request taxonomy applies to API-key and OAuth observation alike.
+
+The owner's 2026-09-07 ruling separates configuration from verification. The
+protocol owners remain catalog pins, custom declarations and response evidence;
+explicit `save_unverified: true` may save either of the first two without an
+upstream request. Custom Auto cannot invent an owner. Canonical input validation,
+credential custody, nonce reconciliation and rollback remain unchanged.
+
+Schema errors never authenticate: they can precede key lookup. Synthetic controls
+were removed because unknown token grammar/checksums and collisions with another
+valid key make their results inconclusive. A public model list cannot repair
+that proof, and the inventory waiver does not waive authentication. Bare 401/403
+responses remain unknown for every owner; only shaped authentication evidence
+rejects a candidate. An unknown Auto sibling is not eliminated by another
+candidate's rejection. API-key observation remains model-free, non-redirecting
+and bounded by its deadline.
+
+Every newly stored Hub credential carries an opaque `verification_pending` marker
+independently of routing health, including observed creates and native-config imports.
+Inventory refresh never clears it. Any actual successful invocation whose captured
+marker and credential still match the fresh Source clears it inside the shared config
+transaction. Later same-credential attempts do not negate proof. Credential/endpoint
+replacement generates a new marker, including same-handle OAuth reauthentication.
+The Source remains configurable and invokable, but list/detail surfaces do not
+claim healthy/in-use status while verification is pending. The normal verified
+save path still requires response-backed authentication and protocol ownership.
+
+Completed Hub OAuth consent may retain its engine-bound credential under the fixed
+vendor protocol with verification pending. Explicit upstream authentication
+rejection keeps the existing needs-action state. The existing allowlisted
+auth-index transport substitutes the engine-held token; no private-token reader
+or fabricated OAuth control is needed. Native CLI OAuth is unchanged.
+
+`AUTH-SETUP-112` covers every catalog pin and concrete custom protocol against
+isolated HTTP middleware with both authentication/schema orders, public/protected
+inventory and alphanumeric/punctuation-only credentials. Unknown validation cannot
+authenticate, while explicit saving performs no additional upstream requests.
+`AUTH-SETUP-113` covers completed Hub OAuth admission, fixed protocol ownership,
+pending verification and idempotent polling across credential shapes and upstream
+outcomes. `AUTH-SETUP-114` covers Auto policy responses that must remain unknown
+and cannot permit unverified saving without a concrete protocol declaration.
+
## Acceptance
- DeepSeek official URL + valid key, vendor `deepseek`, adds as
diff --git a/docs/plans/model-hub.md b/docs/plans/model-hub.md
index dfa5f4d0c..a33c2ef77 100644
--- a/docs/plans/model-hub.md
+++ b/docs/plans/model-hub.md
@@ -355,10 +355,44 @@ rungs, documented in `docs/plans/model-hub-vendor-preset-protocol.md`:
prove reachability and authentication on that protocol's path. Shape proof
is not required. A wrong declaration fails on a later real call.
+**Owner ruling 2026-09-07: configuration and verification are independent.**
+The three owners above still determine the interface, but explicit API-key
+`save_unverified: true` no longer requires a successful observation. It saves only
+a catalog-pinned or user-declared protocol, with canonical validation, credential
+custody, nonce reconciliation and rollback unchanged. Custom Auto without a
+declaration is refused before credential work. No upstream probe or model discovery
+is performed by this explicit save path; supplied manual models remain manual.
+
+Schema errors may precede authentication and never authenticate a key. There is no
+synthetic credential control: unknown grammar/checksums and other valid credentials
+make both rejection and acceptance of an altered token inconclusive. Bare 401/403
+statuses likewise do not prove credential rejection. The ordinary non-persisting
+observation still reports response-backed evidence without inventing certainty.
+
+Completed Hub OAuth consent may retain its bound credential as an unverified Source
+under the fixed vendor protocol. The engine retains OAuth token custody; optional
+model-free observation uses the existing allowlisted auth-index transport and token
+substitution, not private-token reads. Explicit upstream credential rejection retains
+the existing needs-action state. Native CLI OAuth is unchanged.
+
+`Source.verification_pending` is one optional persisted opaque identity, independent
+of health and routing eligibility. Every newly stored Hub credential gets a marker,
+including observed creates and native-config imports. Source list/detail use the
+existing advisory treatment instead of healthy/in-use copy. Inventory never clears it.
+A call captures the marker before invocation; any successful same-credential call
+with that marker, including the existing backend probe, clears it in a fresh shared
+config transaction. Later same-credential attempts do not invalidate success.
+Credential/endpoint replacement generates a new marker even when OAuth reuses the
+same handle, so old calls cannot verify replacement material across processes.
+Legacy Sources retain their existing
+state without retroactive verification claims. Successful verification of one call
+does not promise that every model or operation is supported.
+
The form exposes a vendor select first (V4 06r / 模型网关 05). Auto detect plus
-the three supported protocols remain on `custom`. A failed observation still
-stores nothing rather than guessing. Unreachable, rejected, timeout, and
-adapter-error paths still cannot save.
+the three supported protocols remain on `custom`. Observation alone never saves
+anything. The explicit unverified-save exit is available after an observation failure
+or directly from a valid declared/pinned draft; it does not turn that failure into
+proof or silently select the first Auto candidate.
Once saved, `protocol` is immutable for that Source. Connectivity retest, model
discovery, refresh, credential replacement, Base URL replacement, and restart all use
diff --git a/tests/scenarios/auth_setup/catalog.yaml b/tests/scenarios/auth_setup/catalog.yaml
index bb25bf646..d5a21af56 100644
--- a/tests/scenarios/auth_setup/catalog.yaml
+++ b/tests/scenarios/auth_setup/catalog.yaml
@@ -113,6 +113,27 @@ scenarios:
layer: scenario
backend: shared
test: tests/scenarios/auth_setup/test_auth_setup_scenarios.py::test_catalog_api_key_setup_observe_then_create_closed_loop
+ - id: AUTH-SETUP-112
+ name: API-key setup keeps validation unverified and explicitly saves without upstream scheduling
+ status: covered
+ kind: happy_path
+ layer: scenario
+ backend: shared
+ test: tests/scenarios/auth_setup/test_auth_setup_scenarios.py::test_api_key_setup_does_not_schedule_a_model
+ - id: AUTH-SETUP-113
+ name: Hub OAuth retains completed credentials as unverified and preserves explicit rejection state
+ status: covered
+ kind: negative_path
+ layer: scenario
+ backend: shared
+ test: tests/scenarios/auth_setup/test_auth_setup_scenarios.py::test_hub_oauth_model_free_observation_closed_loop
+ - id: AUTH-SETUP-114
+ name: Auto policy responses neither reject credentials nor falsely exclude competing protocols
+ status: covered
+ kind: negative_path
+ layer: scenario
+ backend: shared
+ test: tests/scenarios/auth_setup/test_auth_setup_scenarios.py::test_custom_auto_policy_response_cannot_reject_or_exclude_credentials
- id: AUTH-SETUP-201
name: Re-entering setup replaces the active flow
status: covered
diff --git a/tests/scenarios/auth_setup/test_auth_setup_scenarios.py b/tests/scenarios/auth_setup/test_auth_setup_scenarios.py
index 818e7e3bf..50d4ba5ba 100644
--- a/tests/scenarios/auth_setup/test_auth_setup_scenarios.py
+++ b/tests/scenarios/auth_setup/test_auth_setup_scenarios.py
@@ -1,20 +1,23 @@
import asyncio
import json
import os
+import re
import sys
import tempfile
import time
import unittest
import urllib.parse
from concurrent.futures import ThreadPoolExecutor
+from dataclasses import replace
from pathlib import Path
from types import SimpleNamespace
-from unittest.mock import AsyncMock, patch
+from unittest.mock import AsyncMock, Mock, patch
import httpx
import jwt
import pytest
import yaml
+from aiohttp import web
from cryptography.hazmat.primitives.asymmetric import rsa
ROOT = Path(__file__).resolve().parents[3]
@@ -35,6 +38,7 @@ from config.v2_config import (
V2Config,
)
from core.agent_auth_service import AgentAuthService
+from core.handlers.model_hub.adapter import SOURCE_PROTOCOLS
from core.handlers.model_hub.service import ModelHubError
from core.show_pages import ShowPageStore
from modules.agents.codex.agent import CodexAgent
@@ -58,6 +62,8 @@ from vibe.claude_config import (
)
from vibe import remote_access, show_identity, ui_server
from vibe.ui_server import app
+from vibe.model_hub_runtime.api_key_vendors import api_key_vendor_catalog
+from vibe.model_hub_runtime.adapter import _OAUTH_ENDPOINTS
def test_auth_setup_catalog_priorities_reference_live_scenarios():
@@ -2685,5 +2691,346 @@ def test_catalog_api_key_setup_observe_then_create_closed_loop(monkeypatch, tmp_
)
+ ("vendor", "protocol"),
+ [(entry.id, entry.protocol) for entry in api_key_vendor_catalog()]
+ + [("custom", protocol) for protocol in SOURCE_PROTOCOLS],
+)
[email protected]("auth_before_validation", [True, False])
[email protected]("public_inventory", [False, True])
[email protected]("valid_key", ["test-model-free-key", "!@#$%^&*"])
+def test_api_key_setup_does_not_schedule_a_model(
+ monkeypatch, tmp_path, vendor, protocol, auth_before_validation, public_inventory, valid_key,
+):
+ """Scenario: AUTH-SETUP-112"""
+ from tests.test_model_hub_api import _service
+ from vibe.model_hub_runtime.adapter import CLIProxyEngineAdapter
+ from vibe.model_hub_runtime.state import EngineStateStore
+
+ monkeypatch.setenv("AVIBE_HOME", str(tmp_path))
+ state_store = EngineStateStore(tmp_path / "engine-state")
+ transport = CLIProxyEngineAdapter(supervisor=Mock(), state_store=state_store)
+ service, store, adapter = _service(tmp_path)
+ # Keep engine lifecycle simulated; exercise real credential custody, HTTP
+ # observation, inventory discovery, and Source admission together.
+ for method in ("provision_credential", "provision_transient_credential", "revoke_credential", "observe_source"):
+ monkeypatch.setattr(adapter, method, getattr(transport, method))
+
+ async def scenario():
+ requests = []
+ observed_credentials = set()
+ key_syntax = r"[a-z-]+" if valid_key[0].isalpha() else r"[^\w\s]+"
+ paths = {
+ "anthropic": "/v1/messages",
+ "openai_responses": "/v1/responses",
+ "openai_chat": "/v1/chat/completions",
+ }
+
+ async def upstream(request):
+ body = await request.json() if request.method == "POST" else None
+ requests.append((request.method, request.path, body))
+ supplied_key = (
+ request.headers.get("x-api-key")
+ if protocol == "anthropic"
+ else request.headers.get("Authorization", "").removeprefix("Bearer ")
+ )
+ observed_credentials.add(supplied_key)
+ if not re.fullmatch(key_syntax, supplied_key):
+ return web.json_response({"code": "INVALID_API_KEY"}, status=401)
+ if request.method == "POST" and not auth_before_validation and "model" not in body:
+ return web.json_response(
+ {"error": {"type": "invalid_request_error", "message": "model is required"}},
+ status=400,
+ )
+ if supplied_key != valid_key and not (request.method == "GET" and public_inventory):
+ return web.json_response({"code": "INVALID_API_KEY"}, status=401)
+ if request.method == "GET":
+ return web.json_response({"data": [{"id": "relay-model"}]})
+ if "model" in body:
+ return web.json_response(
+ {"error": {"type": "rate_limit_error", "message": "No available model capacity"}},
+ status=429,
+ )
+ return web.json_response(
+ {"error": {"type": "invalid_request_error", "message": "model is required"}},
+ status=400,
+ )
+
+ upstream_app = web.Application()
+ upstream_app.router.add_post(paths[protocol], upstream)
+ upstream_app.router.add_get("/v1/models", upstream)
+ web_runner = web.AppRunner(upstream_app)
+ await web_runner.setup()
+ site = web.TCPSite(web_runner, "127.0.0.1", 0)
+ await site.start()
+ port = site._server.sockets[0].getsockname()[1]
+ draft = {
+ "vendor": vendor,
+ "protocol": protocol,
+ "base_url": f"http://127.0.0.1:{port}",
+ "key": valid_key,
+ }
+ harness = SimpleNamespace()
+ runner = ScenarioRunner(harness)
+ async def observe(h):
+ result = await service.observe_source(draft)
+ observation = result["observation"]
+ assert observation["outcome"] != "observed"
+ assert observation["authenticated"] == "unknown"
+ assert not store.config.sources
+
+ async def confirm(h):
+ with pytest.raises(ModelHubError):
+ await service.create_source({
+ "kind": "api_key", **draft, "accept_unavailable_inventory": True,
+ })
+ before = len(requests)
+ await service.create_source({"kind": "api_key", **draft, "save_unverified": True})
+ assert len(requests) == before
+ assert len(store.config.sources) == 1
+ h.source = store.config.sources[0].to_payload()
+ assert h.source["protocol"] == protocol
+ assert h.source["models"] == []
+ assert h.source["verification_pending"]
+ assert state_store.read_api_key(h.source["credential_ref"]) == valid_key
+
+ async def reject_invalid_key(h):
+ invalid = {**draft, "key": "invalid-test-key" if valid_key[0].isalpha() else "!!??"}
+ result = await service.observe_source(invalid)
+ assert result["observation"]["outcome"] != "observed"
+ assert result["observation"]["authenticated"] != "authenticated"
+ with pytest.raises(ModelHubError):
+ await service.create_source({
+ "kind": "api_key", **invalid, "accept_unavailable_inventory": True,
+ })
+ assert [source.to_payload() for source in store.config.sources] == ([h.source] if h.source else [])
+
+ try:
+ await runner.run(
+ ScenarioStep("observe", observe),
+ ScenarioStep("confirm", confirm),
+ ScenarioStep("reject_invalid_key", reject_invalid_key),
+ )
+ ScenarioExpect.step_history(runner, ["observe", "confirm", "reject_invalid_key"])
+ assert observed_credentials == {
+ valid_key, "invalid-test-key" if valid_key[0].isalpha() else "!!??",
+ }
+ assert all(
+ path == (paths[protocol] if method == "POST" else "/v1/models")
+ for method, path, _ in requests
+ )
+ assert all("model" not in body for _, _, body in requests if body is not None)
+ finally:
+ await web_runner.cleanup()
+
+ asyncio.run(scenario())
+
+
+ ("status", "body"),
+ [
+ (400, {"error": {"type": "invalid_request_error", "param": "model"}}),
+ (401, {"error": {"code": "invalid_api_key"}}),
+ (403, {"message": "Request blocked by regional policy"}),
+ (429, {"error": {"type": "rate_limit_error"}}),
+ (502, {"error": {"type": "upstream_error"}}),
+ (200, {"ok": True}),
+ ],
+)
[email protected]("validation_before_auth", [False, True])
[email protected]("vendor", tuple(_OAUTH_ENDPOINTS))
[email protected]("credential_valid", [True, False])
+def test_hub_oauth_model_free_observation_closed_loop(
+ monkeypatch, tmp_path, caplog, status, body, validation_before_auth, vendor, credential_valid,
+):
+ """Scenario: AUTH-SETUP-113"""
+ from tests.test_model_hub_api import _service
+ from vibe.model_hub_runtime.adapter import CLIProxyEngineAdapter
+ from vibe.model_hub_runtime.state import EngineStateStore
+
+ monkeypatch.setenv("AVIBE_HOME", str(tmp_path))
+ state_store = EngineStateStore(tmp_path / "engine-state")
+ api_calls = []
+ inventory_calls = []
+ rejected = status == 401 or (not credential_valid and not (validation_before_auth and status == 400))
+ is_openai = vendor in {"openai", "codex"}
+ protocol = "openai_responses" if is_openai else "anthropic"
+ if vendor == "anthropic" and "error" in body:
+ body = {"type": "error", **body}
+ signing_key = "test-oauth-signature-key-with-32-bytes"
+ bound_token = (
+ jwt.encode({"sub": "account-test", "exp": time.time() + (3600 if credential_valid else -3600)}, signing_key)
+ if is_openai
+ else "sk-ant-oat01-test-valid" if credential_valid else "sk-ant-oat01-test-expired"
+ )
+ auth_name = "oauth-test.json"
+ state_store._secure_write_json(state_store.auth_dir / auth_name, {"access_token": bound_token})
+
+ def management_request(method, path, *, query=None, payload=None):
+ if path == "/auth-files":
+ return {"files": [{
+ "id": "codex-test", "auth_index": "auth-index-test",
+ "name": auth_name, "provider": "codex" if is_openai else "claude",
+ "id_token": {"chatgpt_account_id": "account-test"},
+ }]}
+ if path == "/api-call":
+ assert method == "POST"
+ assert payload["auth_index"] == "auth-index-test"
+ assert payload["url"] == (
+ "https://chatgpt.com/backend-api/codex/responses" if is_openai
+ else "https://api.anthropic.com/v1/messages?beta=true"
+ )
+ if is_openai:
+ assert payload["header"]["Chatgpt-Account-Id"] == "account-test"
+ assert "model" not in json.loads(payload["data"])
+ api_calls.append(payload)
+ token = payload["header"]["Authorization"].removeprefix("Bearer ").replace("$TOKEN$", bound_token)
+ try:
+ if is_openai:
+ jwt.decode(token, options={"verify_signature": False})
+ elif not re.fullmatch(r"sk-ant-oat01-[a-z-]+", token):
+ raise ValueError("Malformed opaque token")
+ except (jwt.PyJWTError, ValueError):
+ return {"status_code": 401, "body": '{"error":{"code":"invalid_api_key"}}'}
+ if validation_before_auth and status == 400:
+ return {"status_code": status, "body": json.dumps(body)}
+ try:
+ if is_openai:
+ jwt.decode(token, signing_key, algorithms=["HS256"])
+ elif token != "sk-ant-oat01-test-valid":
+ raise ValueError("Invalid opaque token")
+ except (jwt.PyJWTError, ValueError):
+ return {"status_code": 401, "body": '{"error":{"code":"invalid_api_key"}}'}
+ return {"status_code": status, "body": json.dumps(body)}
+ if path == "/auth-files/models":
+ assert query == {"name": auth_name}
+ inventory_calls.append(query)
+ return {"models": [{"id": "gpt-5.6"}]}
+ raise AssertionError((method, path))
+
+ client = Mock()
+ client.management_request.side_effect = management_request
+ supervisor = Mock()
+ supervisor.client.return_value = client
+ transport = CLIProxyEngineAdapter(supervisor=supervisor, state_store=state_store)
+ service, store, adapter = _service(tmp_path)
+ # Simulate consent and engine lifecycle, but run the actual bound-credential
+ # probe, evidence parser, discovery, and terminal Source materialization.
+ monkeypatch.setattr(adapter, "observe_source", transport.observe_source)
+ monkeypatch.setattr(adapter, "discover_models", transport.discover_models)
+ harness = SimpleNamespace()
+ runner = ScenarioRunner(harness)
+
+ async def start_login(h):
+ started = await service.oauth_start({"vendor": vendor, "channel": "hub"})
+ h.flow_id = started["flow"]["flow_id"]
+ assert not store.config.sources
+
+ async def complete_consent(h):
+ flow = adapter.flows[h.flow_id]
+ h.credential_ref = state_store.bind_oauth_credential(flow.source_id, vendor, auth_name)
+ adapter.flows[h.flow_id] = replace(flow, state="success", credential_ref=h.credential_ref)
+
+ async def materialize_source(h):
+ terminal = await service.oauth_status(h.flow_id)
+ source = terminal["source"]
+ assert terminal["flow"]["state"] == "success"
+ assert source["protocol"] == protocol
+ assert source["supply_channel"] == "hub"
+ assert source["credential_ref"] == h.credential_ref
+ assert source["verification_pending"]
+ assert source["state"]["status"] == ("needs_action" if rejected else "standby")
+ assert [model["id"] for model in source["models"]] == ([] if rejected else ["gpt-5.6"])
+ assert service.list_sources() == [source]
+ assert bound_token not in json.dumps(terminal)
+ assert (await service.oauth_status(h.flow_id))["source"] == source
+ assert adapter.revoked == []
+ assert len(api_calls) == 1
+ assert api_calls[0]["header"]["Authorization"] == "Bearer $TOKEN$"
+ assert len(inventory_calls) == int(not rejected)
+ assert json.loads((state_store.auth_dir / auth_name).read_text())["access_token"] == bound_token
+ assert bound_token not in caplog.text
+
+ asyncio.run(runner.run(
+ ScenarioStep("start_login", start_login),
+ ScenarioStep("complete_consent", complete_consent),
+ ScenarioStep("materialize_source", materialize_source),
+ ))
+ ScenarioExpect.step_history(runner, ["start_login", "complete_consent", "materialize_source"])
+
+
[email protected]("status", [401, 403])
[email protected]("policy_body", ["<html>Request blocked</html>", '{"message":"Regional policy"}'])
[email protected]("competing_protocol", [False, True])
+def test_custom_auto_policy_response_cannot_reject_or_exclude_credentials(
+ monkeypatch, tmp_path, status, policy_body, competing_protocol,
+):
+ """Scenario: AUTH-SETUP-114"""
+ from tests.test_model_hub_api import _service
+ from vibe.model_hub_runtime.adapter import CLIProxyEngineAdapter
+ from vibe.model_hub_runtime.state import EngineStateStore
+
+ monkeypatch.setenv("AVIBE_HOME", str(tmp_path))
+ transport = CLIProxyEngineAdapter(
+ supervisor=Mock(), state_store=EngineStateStore(tmp_path / "engine-state"),
+ )
+ service, store, adapter = _service(tmp_path)
+ for method in ("provision_credential", "provision_transient_credential", "revoke_credential", "observe_source"):
+ monkeypatch.setattr(adapter, method, getattr(transport, method))
+
+ async def scenario():
+ paths = []
+
+ async def upstream(request):
+ assert request.method == "POST", "Unknown protocol evidence must not reach model discovery"
+ assert "model" not in await request.json()
+ paths.append(request.path)
+ if competing_protocol and request.path == "/v1/responses":
+ if request.headers.get("Authorization") != "Bearer test-policy-key":
+ return web.Response(status=401, text="Invalid control")
+ return web.json_response(
+ {"error": {"type": "invalid_request_error", "param": "model"}}, status=400,
+ )
+ if competing_protocol and request.path == "/v1/chat/completions":
+ return web.Response(status=404)
+ return web.Response(status=status, text=policy_body)
+
+ upstream_app = web.Application()
+ upstream_app.router.add_route("*", "/{path:.*}", upstream)
+ web_runner = web.AppRunner(upstream_app)
+ await web_runner.setup()
+ site = web.TCPSite(web_runner, "127.0.0.1", 0)
+ await site.start()
+ port = site._server.sockets[0].getsockname()[1]
+ draft = {"vendor": "custom", "base_url": f"http://127.0.0.1:{port}", "key": "test-policy-key"}
+ runner = ScenarioRunner(SimpleNamespace())
+
+ async def observe(h):
+ result = await service.observe_source(draft)
+ observation = result["observation"]
+ assert observation["outcome"] == "ambiguous"
+ assert observation["protocol"] is None
+ assert observation["authenticated"] == "unknown"
+ assert not store.config.sources
+
+ async def confirm(h):
+ with pytest.raises(ModelHubError):
+ await service.create_source({"kind": "api_key", **draft, "accept_unavailable_inventory": True})
+ before = len(paths)
+ with pytest.raises(ModelHubError):
+ await service.create_source({"kind": "api_key", **draft, "save_unverified": True})
+ assert len(paths) == before
+ assert not store.config.sources
+
+ try:
+ await runner.run(ScenarioStep("observe", observe), ScenarioStep("confirm", confirm))
+ ScenarioExpect.step_history(runner, ["observe", "confirm"])
+ assert set(paths) == {"/v1/messages", "/v1/responses", "/v1/chat/completions"}
+ finally:
+ await web_runner.cleanup()
+
+ asyncio.run(scenario())
+
+
if __name__ == "__main__":
unittest.main()
diff --git a/tests/scenarios/model_hub/test_model_hub_migration_scenarios.py b/tests/scenarios/model_hub/test_model_hub_migration_scenarios.py
index e500735c3..8df1b4edb 100644
--- a/tests/scenarios/model_hub/test_model_hub_migration_scenarios.py
+++ b/tests/scenarios/model_hub/test_model_hub_migration_scenarios.py
@@ -965,6 +965,7 @@ def test_scan_skips_invalid_endpoint_without_blocking_valid_items(
assert {item["backend"] for item in scan} == {"opencode"}
result = asyncio.run(service.migration_apply([item["id"] for item in scan]))
assert result["applied"] == 2
+ assert all(source.verification_pending for source in store.config.sources)
assert {source.vendor for source in store.config.sources} == {
"openrouter",
"zhipuai",
diff --git a/tests/test_model_hub_api.py b/tests/test_model_hub_api.py
index 55011a888..2409294e4 100644
--- a/tests/test_model_hub_api.py
+++ b/tests/test_model_hub_api.py
@@ -120,6 +120,11 @@ class MemoryStore:
def save(self, config):
self.config = config
+ def mutate(self, mutator):
+ config = copy.deepcopy(self.config)
+ if mutator(config):
+ self.save(config)
+
def ensure_writable(self):
if self.recovery:
raise ModelHubError("config_recovery", status=409)
@@ -7564,7 +7569,8 @@ def test_completed_hub_oauth_persists_only_a_response_proven_protocol(tmp_path):
assert adapter.revoked == []
-def test_completed_hub_oauth_rejects_unproven_protocol_before_persistence(tmp_path):
[email protected]("observed", [False, True])
+def test_completed_hub_oauth_saves_fixed_protocol_as_unverified(tmp_path, observed):
service, store, adapter = _service(tmp_path)
flow = asyncio.run(service.oauth_start({"vendor": "openai", "channel": "hub"}))["flow"]
adapter.flows[flow["flow_id"]] = OAuthFlowState(
@@ -7575,22 +7581,20 @@ def test_completed_hub_oauth_rejects_unproven_protocol_before_persistence(tmp_pa
}
)
adapter.observation = SourceObservation(
- outcome=ObservationOutcome.AMBIGUOUS,
+ outcome=ObservationOutcome.OBSERVED if observed else ObservationOutcome.AMBIGUOUS,
reachable=True,
authenticated=True,
- protocol=None,
- discovery=ObservationDiscovery.NOT_ATTEMPTED,
+ protocol="openai_responses" if observed else None,
+ discovery=ObservationDiscovery.SUCCEEDED if observed else ObservationDiscovery.NOT_ATTEMPTED,
models=(),
)
- with pytest.raises(ModelHubError) as exc_info:
- asyncio.run(service.oauth_status(flow["flow_id"]))
-
- assert exc_info.value.code == "discovery_failed"
- assert exc_info.value.status == 422
- assert store.config.sources == []
- assert adapter.revoked == ["cred_oauth_unproven"]
- assert service.oauth_flows.binding(flow["flow_id"]) is None
+ result = asyncio.run(service.oauth_status(flow["flow_id"]))
+ assert result["source"]["protocol"] == "openai_responses"
+ assert result["source"]["verification_pending"]
+ assert store.config.sources[0].credential_ref == "cred_oauth_unproven"
+ assert adapter.revoked == []
+ assert asyncio.run(service.oauth_status(flow["flow_id"]))["source"] == result["source"]
def test_concurrent_completed_hub_oauth_flow_has_single_credential_owner(tmp_path):
diff --git a/tests/test_model_hub_config.py b/tests/test_model_hub_config.py
index 64f25d1d0..f21d8a862 100644
--- a/tests/test_model_hub_config.py
+++ b/tests/test_model_hub_config.py
@@ -1462,6 +1462,7 @@ def test_model_hub_config_round_trip_and_serializer_completeness(monkeypatch, tm
"supply_channel": "hub",
"credential_ref": "cred_serializer_test",
"client_nonce": "scn_01j5w8z7p4n6q2rt",
+ "verification_pending": "vp_0123456789abcdef0123456789abcdef",
}
hub_payload = {
"sources": [source_example],
diff --git a/tests/test_model_hub_l3.py b/tests/test_model_hub_l3.py
index 0cdef649b..6cca66d5a 100644
--- a/tests/test_model_hub_l3.py
+++ b/tests/test_model_hub_l3.py
@@ -2,8 +2,10 @@ from __future__ import annotations
import ast
import asyncio
+import copy
import inspect
import json
+import re
import tempfile
import threading
from collections import deque
@@ -16,7 +18,9 @@ from typing import cast
from unittest.mock import AsyncMock, Mock, patch
import aiohttp
+import jwt
import pytest
+import yaml
from aiohttp import web
from jsonschema import Draft7Validator, FormatChecker
from sqlalchemy import create_engine, delete, select
@@ -741,6 +745,11 @@ class MemoryStore:
def requested_model(self, backend: str) -> str:
return self.requested_models.get(backend, "")
+ def mutate(self, mutator):
+ config = copy.deepcopy(self.config)
+ if mutator(config):
+ self.save(config)
+
class _EngineObservation:
"""The adapter-side half of `InvokeHandle` these fakes all answer the same way.
@@ -6675,7 +6684,7 @@ def test_source_observation_accepts_catalog_pin_and_custom_declaration_without_s
assert inventory_probe.await_args.kwargs["protocol"] == "openai_chat"
-def test_qwen_catalog_pin_observation_accepts_wrapperless_authenticated_validation_response(
+def test_qwen_catalog_pin_validation_remains_unverified(
tmp_path: Path,
) -> None:
state_store = EngineStateStore(tmp_path / "engine-state")
@@ -6695,6 +6704,8 @@ def test_qwen_catalog_pin_observation_accepts_wrapperless_authenticated_validati
async def capture_probe(request: web.Request) -> web.Response:
requests.append(request.path)
+ if request.headers.get("Authorization") != "Bearer test-qwen-key":
+ return web.json_response({"code": "INVALID_API_KEY"}, status=401)
if request.path == _PROTOCOL_OBSERVATION_TAXONOMY["openai_chat"].request_path:
return web.json_response(
{
@@ -6732,28 +6743,26 @@ def test_qwen_catalog_pin_observation_accepts_wrapperless_authenticated_validati
credential_ref,
SOURCE_PROTOCOLS,
)
- assert inventory_probe.await_args is not None
- inventory_kwargs = dict(inventory_probe.await_args.kwargs)
+ inventory_probe.assert_not_awaited()
+ inventory_kwargs = {}
finally:
await runner.cleanup()
return requests, observed, inventory_kwargs
requests, observed, inventory_kwargs = asyncio.run(scenario())
- assert observed.outcome.value == "observed"
- assert observed.protocol == "openai_chat"
- assert observed.authenticated is True
- assert observed.model_ids == ("qwen-plus",)
+ assert observed.outcome.value == "ambiguous"
+ assert observed.protocol is None
+ assert observed.authenticated is None
+ assert observed.model_ids == ()
assert requests == [
_PROTOCOL_OBSERVATION_TAXONOMY[protocol].request_path
for protocol in SOURCE_PROTOCOLS
]
- assert inventory_kwargs["vendor"] == "qwen"
- assert inventory_kwargs["protocol"] == "openai_chat"
- assert inventory_kwargs["base_url"] is None
+ assert inventory_kwargs == {}
-def test_openrouter_catalog_pin_observation_accepts_nested_numeric_authenticated_validation_response(
+def test_openrouter_catalog_pin_numeric_validation_remains_unverified(
tmp_path: Path,
) -> None:
state_store = EngineStateStore(tmp_path / "engine-state")
@@ -6773,6 +6782,8 @@ def test_openrouter_catalog_pin_observation_accepts_nested_numeric_authenticated
async def capture_probe(request: web.Request) -> web.Response:
requests.append(request.path)
+ if request.headers.get("Authorization") != "Bearer test-openrouter-key":
+ return web.json_response({"code": "INVALID_API_KEY"}, status=401)
if request.path == _PROTOCOL_OBSERVATION_TAXONOMY["openai_chat"].request_path:
return web.json_response(
{
@@ -6812,25 +6823,23 @@ def test_openrouter_catalog_pin_observation_accepts_nested_numeric_authenticated
credential_ref,
SOURCE_PROTOCOLS,
)
- assert inventory_probe.await_args is not None
- inventory_kwargs = dict(inventory_probe.await_args.kwargs)
+ inventory_probe.assert_not_awaited()
+ inventory_kwargs = {}
finally:
await runner.cleanup()
return requests, observed, inventory_kwargs
requests, observed, inventory_kwargs = asyncio.run(scenario())
- assert observed.outcome.value == "observed"
- assert observed.protocol == "openai_chat"
- assert observed.authenticated is True
- assert observed.model_ids == ("openrouter/auto",)
+ assert observed.outcome.value == "ambiguous"
+ assert observed.protocol is None
+ assert observed.authenticated is None
+ assert observed.model_ids == ()
assert requests == [
_PROTOCOL_OBSERVATION_TAXONOMY[protocol].request_path
for protocol in SOURCE_PROTOCOLS
]
- assert inventory_kwargs["vendor"] == "openrouter"
- assert inventory_kwargs["protocol"] == "openai_chat"
- assert inventory_kwargs["base_url"] is None
+ assert inventory_kwargs == {}
def _catalog_owner_status_body(vendor: str, status: int) -> dict[str, object]:
@@ -6852,7 +6861,7 @@ def _catalog_owner_status_body(vendor: str, status: int) -> dict[str, object]:
return {
"error": {
"code": 400,
- "message": "invalid API key",
+ "message": "messages is required",
}
}
return {
@@ -6888,6 +6897,9 @@ def _run_catalog_pin_observation(
async def capture_probe(request: web.Request) -> web.Response:
requests.append(request.path)
+ supplied = request.headers.get("x-api-key") or request.headers.get("Authorization", "").removeprefix("Bearer ")
+ if supplied != f"test-{vendor}-{status}":
+ return web.json_response({"code": "INVALID_API_KEY"}, status=401)
return web.json_response(body, status=status)
app = web.Application()
@@ -6930,7 +6942,7 @@ def _run_catalog_pin_observation(
@pytest.mark.parametrize(("vendor", "protocol"), CATALOG_API_KEY_VENDOR_PROTOCOL_CASES)
-def test_catalog_pin_observation_accepts_any_nonempty_json_400_response(
+def test_catalog_pin_json_400_does_not_prove_authentication(
tmp_path: Path,
vendor: str,
protocol: str,
@@ -6943,19 +6955,16 @@ def test_catalog_pin_observation_accepts_any_nonempty_json_400_response(
body=_catalog_owner_status_body(vendor, 400),
)
- assert observed.outcome.value == "observed"
- assert observed.protocol == protocol
- assert observed.authenticated is True
- assert observed.model_ids == (f"{vendor}/auto",)
+ assert observed.outcome.value == "ambiguous"
+ assert observed.protocol is None
+ assert observed.authenticated is None
+ assert observed.model_ids == ()
assert requests == [_PROTOCOL_OBSERVATION_TAXONOMY[protocol].request_path]
- assert inventory_kwargs is not None
- assert inventory_kwargs["vendor"] == vendor
- assert inventory_kwargs["protocol"] == protocol
- assert inventory_kwargs["base_url"] is None
+ assert inventory_kwargs is None
@pytest.mark.parametrize(("vendor", "protocol"), CATALOG_API_KEY_VENDOR_PROTOCOL_CASES)
-def test_catalog_pin_observation_rejects_any_json_401_response(
+def test_catalog_pin_unknown_json_401_is_not_credential_rejection(
tmp_path: Path,
vendor: str,
protocol: str,
@@ -6968,9 +6977,9 @@ def test_catalog_pin_observation_rejects_any_json_401_response(
body=_catalog_owner_status_body(vendor, 401),
)
- assert observed.outcome.value == "authentication_failed"
+ assert observed.outcome.value == "ambiguous"
assert observed.protocol is None
- assert observed.authenticated is False
+ assert observed.authenticated is None
assert observed.model_ids == ()
assert requests == [_PROTOCOL_OBSERVATION_TAXONOMY[protocol].request_path]
assert inventory_kwargs is None
@@ -7110,17 +7119,19 @@ def test_source_observation_catalog_pin_and_declaration_still_require_authentica
@pytest.mark.parametrize(
("status", "initial_authentication", "expected_outcome", "expected_authenticated"),
[
- (400, _AuthenticationEvidence.REJECTED, "observed", True),
- (401, _AuthenticationEvidence.ACCEPTED, "authentication_failed", False),
+ (400, _AuthenticationEvidence.REJECTED, "authentication_failed", False),
+ (400, _AuthenticationEvidence.UNKNOWN, "ambiguous", None),
+ (401, _AuthenticationEvidence.REJECTED, "authentication_failed", False),
+ (400, _AuthenticationEvidence.ACCEPTED, "observed", True),
],
- ids=("request_error_accepts", "auth_error_rejects"),
+ ids=("explicit_rejection", "unverified_validation", "auth_error_rejects", "verified_validation"),
)
-def test_custom_declared_observation_uses_owner_status_before_parser_verdict(
+def test_custom_declared_observation_preserves_transport_authentication_verdict(
tmp_path: Path,
status: int,
initial_authentication: _AuthenticationEvidence,
expected_outcome: str,
- expected_authenticated: bool,
+ expected_authenticated: bool | None,
) -> None:
base_url = "https://relay.example/v1"
state_store = EngineStateStore(tmp_path / f"engine-state-custom-declared-{status}")
@@ -7173,13 +7184,48 @@ def test_custom_declared_observation_uses_owner_status_before_parser_verdict(
inventory_probe.assert_not_awaited()
+def test_auth_setup_executable_scenarios_are_registered() -> None:
+ root = Path(__file__).parent / "scenarios/auth_setup"
+ catalog = yaml.safe_load((root / "catalog.yaml").read_text())
+ registered = {entry["id"]: entry for entry in catalog["scenarios"]}
+ tree = ast.parse((root / "test_auth_setup_scenarios.py").read_text())
+ for node in ast.walk(tree):
+ if not isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef)):
+ continue
+ doc = ast.get_docstring(node) or ""
+ match = re.match(r"Scenario:\s+(AUTH-SETUP-\d+)\b", doc)
+ if match:
+ scenario_id = match.group(1)
+ assert scenario_id in registered, (scenario_id, node.name)
+ assert registered[scenario_id]["test"].endswith("::" + node.name)
+
+
[email protected]("protocol", SOURCE_PROTOCOLS)
[email protected]("status", [401, 403])
[email protected]("body", ['{"message":"Regional policy"}', '{"error":{"code":"invalid_api_key"}}'])
+def test_authentication_status_interpretation_preserves_evidence_role(
+ protocol, status, body,
+) -> None:
+ evidence = _parse_protocol_authenticated_evidence(protocol, status, body)
+ expected = (
+ _AuthenticationEvidence.REJECTED
+ if "invalid_api_key" in body
+ else _AuthenticationEvidence.UNKNOWN
+ )
+ assert evidence.authentication is expected
+
+
[email protected]("vendor", ["openai", "codex"])
[email protected]("error_param", ["input", "model", None])
def test_oauth_observation_uses_the_bound_auth_index_and_requires_response_proof(
tmp_path: Path,
+ vendor: str,
+ error_param: str | None,
) -> None:
state_store = EngineStateStore(tmp_path / "engine-state")
credential_ref = state_store.bind_oauth_credential(
"src_oauthproof",
- "openai",
+ vendor,
"codex-test.json",
)
client = Mock()
@@ -7200,6 +7246,7 @@ def test_oauth_observation_uses_the_bound_auth_index_and_requires_response_proof
}
if path == "/api-call":
api_calls.append(payload)
+ assert payload["header"]["Authorization"] == "Bearer $TOKEN$"
return {
"status_code": 400,
"header": {},
@@ -7207,7 +7254,7 @@ def test_oauth_observation_uses_the_bound_auth_index_and_requires_response_proof
{
"error": {
"type": "invalid_request_error",
- "param": "input",
+ "param": error_param,
}
}
),
@@ -7227,16 +7274,17 @@ def test_oauth_observation_uses_the_bound_auth_index_and_requires_response_proof
observed = asyncio.run(
adapter.observe_source(
- "openai",
+ vendor,
None,
credential_ref,
SOURCE_PROTOCOLS,
)
)
- assert observed.outcome.value == "observed"
- assert observed.protocol == "openai_responses"
- assert observed.model_ids == ("gpt-5.6",)
+ assert observed.outcome.value == ("adapter_error" if error_param == "input" else "ambiguous")
+ assert observed.authenticated is None
+ assert observed.protocol is None
+ assert observed.model_ids == ()
assert len(api_calls) == 1
assert api_calls[0]["auth_index"] == "auth-index-test"
assert api_calls[0]["header"]["Chatgpt-Account-Id"] == "account-test"
@@ -7249,22 +7297,27 @@ def test_oauth_observation_uses_the_bound_auth_index_and_requires_response_proof
if path == "/auth-files":
return management_request(method, path, query=query, payload=payload)
if path == "/api-call":
- return {"status_code": 200, "header": {}, "body": '{"ok":true}'}
+ return {"status_code": unknown_status, "header": {}, "body": unknown_body}
raise AssertionError((method, path))
client.management_request.side_effect = ambiguous_management_request
- ambiguous = asyncio.run(
- adapter.observe_source(
- "openai",
- None,
- credential_ref,
- SOURCE_PROTOCOLS,
+ for unknown_status, unknown_body in (
+ (200, '{"ok":true}'),
+ (401, "<html>Request blocked</html>"),
+ (403, '{"message":"Regional policy"}'),
+ ):
+ ambiguous = asyncio.run(
+ adapter.observe_source(
+ vendor,
+ None,
+ credential_ref,
+ SOURCE_PROTOCOLS,
+ )
)
- )
- assert ambiguous.outcome.value == "ambiguous"
- assert ambiguous.protocol is None
- assert ambiguous.authenticated is None
+ assert ambiguous.outcome.value == "ambiguous"
+ assert ambiguous.protocol is None
+ assert ambiguous.authenticated is None
def test_oauth_observation_does_not_use_api_key_catalog_pins_without_shape_proof(
@@ -7410,7 +7463,7 @@ def test_protocol_evidence_parser_requires_candidate_specific_response_shapes(
json.dumps(request_error_body),
) == _ProtocolEvidence(
protocol=_ProtocolProof.PROVEN,
- authentication=_AuthenticationEvidence.ACCEPTED,
+ authentication=_AuthenticationEvidence.UNKNOWN,
)
assert _parse_protocol_authenticated_evidence(
protocol,
@@ -7439,7 +7492,7 @@ def test_protocol_evidence_parser_requires_candidate_specific_response_shapes(
ANTHROPIC_RELAY_REQUEST_ERROR_PAYLOAD,
_ProtocolEvidence(
protocol=_ProtocolProof.UNPROVEN,
- authentication=_AuthenticationEvidence.ACCEPTED,
+ authentication=_AuthenticationEvidence.UNKNOWN,
shape=_ProtocolObservationShape.GENERIC_REQUEST_ERROR,
),
),
@@ -7548,7 +7601,7 @@ def test_protocol_evidence_table_defaults_shaped_non_auth_rows_to_unknown(
),
],
)
-def test_anthropic_protocol_evidence_table_accepts_authenticated_model_errors(
+def test_anthropic_protocol_model_errors_leave_authentication_unknown(
protocol: str,
status: int,
body: dict,
@@ -7559,7 +7612,7 @@ def test_anthropic_protocol_evidence_table_accepts_authenticated_model_errors(
json.dumps(body),
) == _ProtocolEvidence(
protocol=_ProtocolProof.PROVEN,
- authentication=_AuthenticationEvidence.ACCEPTED,
+ authentication=_AuthenticationEvidence.UNKNOWN,
)
@@ -7598,7 +7651,7 @@ def test_anthropic_protocol_evidence_table_accepts_authenticated_model_errors(
),
],
)
-def test_openai_model_errors_without_family_param_record_accepted_but_unproven_evidence(
+def test_openai_model_errors_without_family_param_leave_authentication_unknown(
protocol: str,
status: int,
body: dict,
@@ -7609,13 +7662,13 @@ def test_openai_model_errors_without_family_param_record_accepted_but_unproven_e
json.dumps(body),
) == _ProtocolEvidence(
protocol=_ProtocolProof.UNPROVEN,
- authentication=_AuthenticationEvidence.ACCEPTED,
+ authentication=_AuthenticationEvidence.UNKNOWN,
shape=_ProtocolObservationShape.GENERIC_REQUEST_ERROR,
)
@pytest.mark.parametrize("protocol", ("openai_responses", "openai_chat"))
-def test_openai_request_error_without_family_param_records_accepted_but_unproven_evidence(
+def test_openai_request_error_without_family_param_leaves_authentication_unknown(
protocol: str,
) -> None:
assert _parse_protocol_authenticated_evidence(
@@ -7631,12 +7684,12 @@ def test_openai_request_error_without_family_param_records_accepted_but_unproven
),
) == _ProtocolEvidence(
protocol=_ProtocolProof.UNPROVEN,
- authentication=_AuthenticationEvidence.ACCEPTED,
+ authentication=_AuthenticationEvidence.UNKNOWN,
shape=_ProtocolObservationShape.GENERIC_REQUEST_ERROR,
)
-def test_qwen_wrapperless_invalid_parameter_request_error_counts_as_authenticated_openai_chat() -> None:
+def test_qwen_wrapperless_validation_leaves_authentication_unknown() -> None:
assert _parse_protocol_authenticated_evidence(
"openai_chat",
400,
@@ -7648,7 +7701,7 @@ def test_qwen_wrapperless_invalid_parameter_request_error_counts_as_authenticate
),
) == _ProtocolEvidence(
protocol=_ProtocolProof.UNPROVEN,
- authentication=_AuthenticationEvidence.ACCEPTED,
+ authentication=_AuthenticationEvidence.UNKNOWN,
shape=_ProtocolObservationShape.GENERIC_REQUEST_ERROR,
)
@@ -7837,12 +7890,10 @@ def test_protocol_observation_consumers_cannot_classify_from_status_codes() -> N
assert _PROTOCOL_OBSERVATION_TAXONOMY["openai_responses"].request_path != _PROTOCOL_OBSERVATION_TAXONOMY[
"openai_chat"
].request_path
- assert _PROTOCOL_OBSERVATION_TAXONOMY["openai_responses"].request_body == {
- "model": "__avibe_model_hub_probe__"
- }
- assert _PROTOCOL_OBSERVATION_TAXONOMY["openai_chat"].request_body == {
- "model": "__avibe_model_hub_probe__"
- }
+ assert all(
+ "model" not in taxonomy.request_body
+ for taxonomy in _PROTOCOL_OBSERVATION_TAXONOMY.values()
+ )
consumers = {
node.name: node
for node in ast.walk(tree)
@@ -7882,7 +7933,9 @@ def test_protocol_observation_consumers_cannot_classify_from_status_codes() -> N
node
for node in ast.walk(tree)
if isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef))
- and node.name != "_parse_protocol_authenticated_evidence"
+ and node.name not in {
+ "_parse_protocol_authenticated_evidence",
+ }
):
for branch in (node for node in ast.walk(function) if isinstance(node, (ast.If, ast.IfExp))):
condition = ast.unparse(branch.test)
diff --git a/tests/test_model_hub_resolution.py b/tests/test_model_hub_resolution.py
index 5569c19e5..aada12478 100644
--- a/tests/test_model_hub_resolution.py
+++ b/tests/test_model_hub_resolution.py
@@ -1,6 +1,7 @@
from __future__ import annotations
import asyncio
+import copy
import hashlib
import json
from collections import deque
@@ -91,6 +92,11 @@ class MemoryStore:
def requested_model(self, backend: str) -> str:
return self.requested_models.get(backend, "")
+ def mutate(self, mutator):
+ config = copy.deepcopy(self.config)
+ if mutator(config):
+ self.save(config)
+
def test_source_settlement_authority_never_downgrades_a_decided_error() -> None:
assert source_settlement_allowed("error", "network") is False
@@ -1995,7 +2001,7 @@ def test_credential_cleanup_settlement_has_one_durable_boundary():
assert raw_cleanup_callers == {"_require_credential_cleanup"}
-def test_every_persisting_source_path_requires_response_backed_protocol_evidence():
+def test_source_admission_uses_explicit_owners_and_keeps_verified_paths_proven():
from ast import AsyncFunctionDef, Attribute, Call, Name, parse, walk
from pathlib import Path
@@ -2051,9 +2057,11 @@ def test_every_persisting_source_path_requires_response_backed_protocol_evidence
assert "_require_proven_source_payload" in calls(
migration_functions["apply_native_migration"]
)
- assert "_require_proven_observation" in calls(
- service_functions["_create_oauth_source"]
- )
+ oauth_calls = calls(service_functions["_create_oauth_source"])
+ assert "_observe_provisioned_credential" in oauth_calls
+ assert "_mark_source_unverified" in oauth_calls
+ assert "_mark_source_unverified" in calls(service_functions["create_source"])
+ assert "_mark_source_unverified" in calls(migration_functions["apply_native_migration"])
def test_manual_model_delete_ignores_preexisting_unrelated_gap(tmp_path):
diff --git a/tests/test_model_hub_unverified.py b/tests/test_model_hub_unverified.py
new file mode 100644
index 000000000..13b88adb4
--- /dev/null
+++ b/tests/test_model_hub_unverified.py
@@ -0,0 +1,243 @@
+"""Unverified configuration is persistable, never authentication evidence."""
+
+import asyncio
+import copy
+import multiprocessing
+import os
+from pathlib import Path
+from dataclasses import replace
+from unittest.mock import AsyncMock
+
+import pytest
+
+from config.v2_config import ModelHubSourceConfig, V2Config, config_write_transaction
+from core.handlers.model_hub.adapter import RawCallOutcome, RawOutcomeKind, SOURCE_PROTOCOLS
+from core.handlers.model_hub.service import ModelHubError, V2ModelHubConfigStore
+from tests.test_model_hub_api import _assert_valid, _service
+from vibe.model_hub_runtime.api_key_vendors import api_key_vendor_catalog
+
+
+def _draft(**changes):
+ return {
+ "kind": "api_key",
+ "vendor": "custom",
+ "protocol": "openai_chat",
+ "base_url": "https://relay.example/v1",
+ "key": "unverified-test-key",
+ "client_nonce": "scn_unverified00000001",
+ "save_unverified": True,
+ **changes,
+ }
+
+
+ "owner",
+ [{"vendor": entry.id} for entry in api_key_vendor_catalog()]
+ + [{"vendor": "custom", "protocol": protocol} for protocol in SOURCE_PROTOCOLS],
+)
+def test_unverified_save_uses_declared_owner_without_upstream_work(tmp_path, owner):
+ service, store, adapter = _service(tmp_path)
+ adapter.observe_source = AsyncMock(side_effect=AssertionError("unexpected observation"))
+ adapter.discover_models = AsyncMock(side_effect=AssertionError("unexpected inventory"))
+ draft = _draft(**owner)
+ if owner["vendor"] != "custom":
+ draft.pop("protocol")
+ created = asyncio.run(service.create_source(draft))["source"]
+ _assert_valid("source.schema.json", created)
+ assert created["verification_pending"]
+ assert created["models"] == []
+ assert created["state"]["status"] == "standby"
+ assert created["client_nonce"] == draft["client_nonce"]
+ assert adapter.credential_count == 1
+ assert len(store.config.sources) == 1
+ adapter.observe_source.assert_not_awaited()
+ adapter.discover_models.assert_not_awaited()
+ with pytest.raises(ModelHubError):
+ asyncio.run(service.create_source(draft))
+ assert adapter.credential_count == 1
+
+
[email protected]("invalid", [
+ {"protocol": None}, {"protocol": "unknown"}, {"key": " "},
+ {"base_url": "file:///tmp/credentials"}, {"save_unverified": "true"},
+ {"verification_pending": False}, {"vendor": "openai", "protocol": "anthropic"},
+])
+def test_unverified_consent_cannot_bypass_input_or_owner_validation(tmp_path, invalid):
+ service, store, adapter = _service(tmp_path)
+ draft = _draft(**invalid)
+ if draft.get("protocol") is None:
+ draft.pop("protocol")
+ with pytest.raises(ModelHubError):
+ asyncio.run(service.create_source(draft))
+ assert store.config.sources == []
+ assert adapter.credential_count == 0
+
+
+def test_unverified_create_rolls_back_custody_and_releases_nonce(tmp_path):
+ service, store, adapter = _service(tmp_path)
+ adapter.fail_sync = True
+ with pytest.raises(ModelHubError):
+ asyncio.run(service.create_source(_draft()))
+ assert not store.config.sources
+ assert adapter.revoked == ["cred_test001"]
+ adapter.fail_sync = False
+ created = asyncio.run(service.create_source(_draft()))["source"]
+ assert created["verification_pending"]
+ assert len(store.config.sources) == 1
+
+
+def test_inventory_never_clears_pending_verification(tmp_path):
+ service, store, _adapter = _service(tmp_path)
+ source = asyncio.run(service.create_source(_draft()))["source"]
+ refreshed = asyncio.run(service.refresh_source(source["id"]))["source"]
+ assert refreshed["models"]
+ assert refreshed["verification_pending"] == source["verification_pending"]
+ assert ModelHubSourceConfig.from_payload(store.config.sources[0].to_payload()).verification_pending
+
+
+def test_verification_bookkeeping_io_failure_preserves_success_and_pending_state(tmp_path, monkeypatch):
+ service, store, _adapter = _service(tmp_path)
+
+ async def scenario():
+ source = (await service.create_source(_draft()))["source"]
+ outcome = RawCallOutcome(
+ kind=RawOutcomeKind.SUCCESS, http_status=200, error_code=None,
+ redacted_message=None, stream_started=False, model_id="test-model", source_id=source["id"],
+ )
+ def fail_save(_config):
+ raise OSError("Disk unavailable")
+ monkeypatch.setattr(store, "save", fail_save)
+ await service._verify_successful_source(source["id"], source["credential_ref"], source["verification_pending"], outcome)
+ assert store.config.sources[0].verification_pending == source["verification_pending"]
+
+ asyncio.run(scenario())
+
+
[email protected]("kind", list(RawOutcomeKind))
[email protected]("current", ["same", "replaced", "same_handle_reauth", "newer_attempt", "deleted"])
+def test_only_current_successful_invocation_retires_verification(tmp_path, kind, current):
+ service, store, _adapter = _service(tmp_path)
+
+ async def scenario():
+ source = (await service.create_source(_draft()))["source"]
+ outcome = RawCallOutcome(
+ kind=kind, http_status=200 if kind is RawOutcomeKind.SUCCESS else 400,
+ error_code=None, redacted_message=None, stream_started=False,
+ source_id=source["id"], model_id="test-model",
+ )
+ service._reserve_settlement_generation(source["id"])
+ if current == "replaced":
+ store.config.sources[0].credential_ref = "cred_replacement"
+ elif current == "same_handle_reauth":
+ service._mark_source_unverified(store.config.sources[0])
+ elif current == "newer_attempt":
+ service._reserve_settlement_generation(source["id"])
+ elif current == "deleted":
+ store.config.sources.clear()
+ await service._verify_successful_source(source["id"], source["credential_ref"], source["verification_pending"], outcome)
+ if current != "deleted":
+ verified = current in {"same", "newer_attempt"} and kind is RawOutcomeKind.SUCCESS
+ assert (store.config.sources[0].verification_pending is None) == verified
+
+ asyncio.run(scenario())
+
+
[email protected]("path", ["resolve", "probe", "stream"])
+def test_model_call_consumers_retire_pending_verification(tmp_path, path):
+ service, store, adapter = _service(tmp_path)
+
+ async def scenario():
+ source = (await service.create_source(_draft(vendor="anthropic", protocol="anthropic")))["source"]
+ await service.refresh_source(source["id"])
+ if path == "probe":
+ result = await service.probe_agent("claude", "claude-opus-4-6")
+ assert result["reachable"] is True
+ else:
+ resolved = await service.resolve(backend="claude", model_id="claude-opus-4-6", request={})
+ if path == "stream":
+ # Exercise the downstream-consumed settlement independently of
+ # the resolver's buffered-success path, with the same identity.
+ store.config.sources[0].verification_pending = resolved.verification_pending
+ handle = await adapter.invoke(source["id"], "claude-opus-4-6", {}, False, "claude")
+ outcome = replace(await handle.outcome(), stream_started=True)
+ await service.settle_handle_outcome(
+ resolved, outcome, termination_origin="upstream_terminal", record_attempt=lambda *_args: None,
+ )
+ assert store.config.sources[0].verification_pending is None
+ assert "verification_pending" not in service.list_sources()[0]
+
+ asyncio.run(scenario())
+
+
[email protected]("unverified", [False, True])
+def test_new_api_key_credentials_always_start_pending(tmp_path, unverified):
+ service, _store, _adapter = _service(tmp_path)
+ created = asyncio.run(service.create_source(_draft(save_unverified=unverified)))["source"]
+ _assert_valid("source.schema.json", created)
+ assert created["verification_pending"]
+
+
+def _settle_in_controller(config_home, captured, attempted, done):
+ os.environ["AVIBE_HOME"] = config_home
+
+ class SignallingStore(V2ModelHubConfigStore):
+ def mutate(self, mutator):
+ attempted.set()
+ super().mutate(mutator)
+
+ service, _store, _adapter = _service(Path(config_home) / "controller")
+ service.store = SignallingStore()
+ outcome = RawCallOutcome(
+ kind=RawOutcomeKind.SUCCESS, http_status=200, error_code=None,
+ redacted_message=None, stream_started=False, model_id="test-model", source_id=captured["id"],
+ )
+ asyncio.run(service._verify_successful_source(
+ captured["id"], captured["credential_ref"], captured["verification_pending"], outcome,
+ ))
+ done.set()
+
+
[email protected]("replacement", ["none", "same_handle", "new_handle"])
+def test_controller_verification_preserves_fresh_web_config_and_credential_identity(tmp_path, monkeypatch, replacement):
+ monkeypatch.setenv("AVIBE_HOME", str(tmp_path))
+ service, store, _adapter = _service(tmp_path)
+ captured = asyncio.run(service.create_source(_draft()))["source"]
+ config = V2Config.default()
+ config.model_hub = store.load()
+ config.save()
+ ctx = multiprocessing.get_context("spawn")
+ attempted, done = ctx.Event(), ctx.Event()
+ controller = ctx.Process(target=_settle_in_controller, args=(str(tmp_path), captured, attempted, done))
+ try:
+ with config_write_transaction() as fresh:
+ controller.start()
+ assert attempted.wait(timeout=15), "controller never reached the verification transaction"
+ assert not done.wait(timeout=1), "controller bypassed Web's cross-process lock"
+ current = fresh.model_hub.sources[0]
+ current.display_name = "Edited in Web"
+ if replacement != "none":
+ service._mark_source_unverified(current)
+ if replacement == "new_handle":
+ current.credential_ref = "cred_web_replacement"
+ pending = current.verification_pending
+ peer = copy.deepcopy(current)
+ peer.id = "src_webadded01"
+ peer.client_nonce = None
+ peer.credential_ref = "cred_web_added"
+ fresh.model_hub.sources.append(peer)
+ fresh.model_hub.agents["codex"].sources.order = [peer.id, current.id]
+ fresh.language = "zh"
+ controller.join(timeout=15)
+ assert controller.exitcode == 0
+ assert done.is_set()
+ finally:
+ if controller.is_alive():
+ controller.terminate()
+ controller.join(timeout=5)
+ updated = V2Config.load()
+ current = updated.model_hub.sources[0]
+ assert current.verification_pending == (None if replacement == "none" else pending)
+ assert current.display_name == "Edited in Web"
+ assert updated.model_hub.sources[1].to_payload() == peer.to_payload()
+ assert updated.model_hub.agents["codex"].sources.order == [peer.id, current.id]
+ assert updated.language == "zh"
diff --git a/ui/src/components/settings/models/AddApiKeyDialog.test.tsx b/ui/src/components/settings/models/AddApiKeyDialog.test.tsx
index 9e13992ab..53311ba9e 100644
--- a/ui/src/components/settings/models/AddApiKeyDialog.test.tsx
+++ b/ui/src/components/settings/models/AddApiKeyDialog.test.tsx
@@ -212,6 +212,42 @@ afterEach(() => {
});
describe('AddApiKeyDialog', () => {
+ it('saves only a selected interface as unverified without observing', async () => {
+ const observe = vi.spyOn(modelsApi, 'observeApiKeySource');
+ const create = vi.spyOn(modelsApi, 'createApiKeySource').mockResolvedValue({
+ source: { ...source, verification_pending: 'vp_0123456789abcdef0123456789abcdef' }, added_to: [], adopted_by: [],
+ });
+ const { onAdded } = renderDialog();
+ const user = await fillCredentials();
+ expect(screen.queryByRole('button', { name: 'Save unverified' })).toBeNull();
+ await openManualProtocol(user);
+ await user.click(screen.getByRole('button', { name: 'OpenAI Chat Completions' }));
+ await user.click(screen.getByRole('button', { name: 'Save unverified' }));
+ await waitFor(() => expect(onAdded).toHaveBeenCalledTimes(1));
+ expect(create).toHaveBeenCalledWith(expect.objectContaining({
+ protocol: 'openai_chat', save_unverified: true, key: 'secret-key',
+ }));
+ expect(observe).not.toHaveBeenCalled();
+ });
+
+ it('retains unverified consent and nonce while reconciling an unknown write', async () => {
+ const create = vi.spyOn(modelsApi, 'createApiKeySource')
+ .mockRejectedValueOnce(new Error('Connection interrupted'))
+ .mockResolvedValue({ source: { ...source, verification_pending: 'vp_0123456789abcdef0123456789abcdef' }, added_to: [], adopted_by: [] });
+ vi.spyOn(modelsApi, 'listSources').mockResolvedValue([]);
+ const observe = vi.spyOn(modelsApi, 'observeApiKeySource');
+ const { onAdded } = renderDialog();
+ const user = await fillCredentials();
+ await selectVendor(user, preset('openai_chat').id);
+ await user.click(screen.getByRole('button', { name: 'Save unverified' }));
+ await user.click(await screen.findByRole('button', { name: RETRY }));
+ await waitFor(() => expect(onAdded).toHaveBeenCalledTimes(1));
+ expect(create).toHaveBeenCalledTimes(2);
+ expect(create.mock.calls[1][0]).toEqual(create.mock.calls[0][0]);
+ expect(create.mock.calls[1][0].save_unverified).toBe(true);
+ expect(observe).not.toHaveBeenCalled();
+ });
+
it('detects without persisting, names the protocol, and drops the report when credentials change', async () => {
vi.spyOn(modelsApi, 'observeApiKeySource').mockResolvedValueOnce(observed());
const create = vi.spyOn(modelsApi, 'createApiKeySource');
@@ -353,7 +389,7 @@ describe('AddApiKeyDialog', () => {
await user.click(screen.getByRole('button', { name: /^Retry$|^重试$/i }));
await waitFor(() => expect(observe).toHaveBeenCalledTimes(2));
- expect(await screen.findByText(/cannot tell which interface|无法判断是哪种接口/i)).toBeTruthy();
+ expect(await screen.findByText(i18n.t('settings.models.addKey.undetermined.title'))).toBeTruthy();
expect(screen.queryByRole('button', { name: /Add anyway|仍要添加/i })).toBeNull();
});
@@ -722,7 +758,7 @@ describe('AddApiKeyDialog', () => {
await clickDetect(user);
await clickConfirm(user);
- expect(await screen.findByText(/cannot tell which interface|无法判断是哪种接口/i)).toBeTruthy();
+ expect(await screen.findByText(i18n.t('settings.models.addKey.undetermined.title'))).toBeTruthy();
expect(screen.queryByText(i18n.t('settings.models.addKey.fail.unclassified'))).toBeNull();
});
@@ -1232,7 +1268,7 @@ describe('AddApiKeyDialog · vendor', () => {
const hint = row?.querySelector('.model-hub-add-key-hint');
expect(statement?.textContent).toMatch(/Anthropic Messages/);
expect(statement?.textContent).toMatch(/Built-in catalog/);
- expect(hint?.textContent).toMatch(/no longer has to prove the interface|不再需要靠返回结构证明接口/);
+ expect(hint?.textContent).toBe(i18n.t('settings.models.addKey.protocol.catalogPinned.hint'));
// A sibling of the statement's line, not a child of it.
expect(hint?.parentElement).toBe(row);
expect(statement?.contains(hint ?? null)).toBe(false);
diff --git a/ui/src/components/settings/models/AddApiKeyDialog.tsx b/ui/src/components/settings/models/AddApiKeyDialog.tsx
index 52e72cd0e..084c53c75 100644
--- a/ui/src/components/settings/models/AddApiKeyDialog.tsx
+++ b/ui/src/components/settings/models/AddApiKeyDialog.tsx
@@ -8,6 +8,7 @@ import {
EyeOff,
Info,
LoaderCircle,
+ Save,
TriangleAlert,
X,
} from 'lucide-react';
@@ -66,11 +67,13 @@ type Phase =
messageKey: string | null;
protocol: SourceProtocol | undefined;
acceptUnavailableInventory: boolean;
+ saveUnverified: boolean;
}
| {
kind: 'save_unconfirmed';
protocol: SourceProtocol | undefined;
acceptUnavailableInventory: boolean;
+ saveUnverified: boolean;
};
const INITIAL_PHASE: Phase = { kind: 'form', report: null };
@@ -361,6 +364,7 @@ export const AddApiKeyDialog: React.FC<AddApiKeyDialogProps> = (props) => {
const draft = React.useCallback((
protocol?: SourceProtocol,
acceptUnavailableInventory = false,
+ saveUnverified = false,
): ApiKeySourceCreate => ({
kind: 'api_key',
vendor,
@@ -373,16 +377,18 @@ export const AddApiKeyDialog: React.FC<AddApiKeyDialogProps> = (props) => {
client_nonce: clientNonce.current,
...(protocol ? { protocol } : {}),
...(acceptUnavailableInventory ? { accept_unavailable_inventory: true } : {}),
+ ...(saveUnverified ? { save_unverified: true } : {}),
}), [apiKey, baseUrl, displayName, vendor]);
const persist = React.useCallback(async (
seq: ContinuationTicket,
protocol?: SourceProtocol,
acceptUnavailableInventory = false,
+ saveUnverified = false,
) => {
if (continuation.settle(seq, () => setPhase({ kind: 'working', origin: 'add', stage: 'persist' })) === 'stale') return;
try {
- const created = await modelsApi.createApiKeySource(draft(protocol, acceptUnavailableInventory));
+ const created = await modelsApi.createApiKeySource(draft(protocol, acceptUnavailableInventory, saveUnverified));
createdDelivery.settle(continuation, seq, created);
} catch (error) {
const failure = apiFailure(error);
@@ -409,8 +415,9 @@ export const AddApiKeyDialog: React.FC<AddApiKeyDialogProps> = (props) => {
messageKey: failureMessageKey(failure),
protocol,
acceptUnavailableInventory,
+ saveUnverified,
}
- : { kind: 'save_unconfirmed', protocol, acceptUnavailableInventory });
+ : { kind: 'save_unconfirmed', protocol, acceptUnavailableInventory, saveUnverified });
});
}
}, [continuation, createdDelivery, draft]);
@@ -594,7 +601,7 @@ export const AddApiKeyDialog: React.FC<AddApiKeyDialogProps> = (props) => {
return;
}
if (reconciliation.kind === 'absent') {
- await persist(seq, phase.protocol, phase.acceptUnavailableInventory);
+ await persist(seq, phase.protocol, phase.acceptUnavailableInventory, phase.saveUnverified);
}
return;
}
@@ -603,6 +610,7 @@ export const AddApiKeyDialog: React.FC<AddApiKeyDialogProps> = (props) => {
continuation.begin(),
phase.protocol,
phase.acceptUnavailableInventory,
+ phase.saveUnverified,
);
return;
}
@@ -985,7 +993,7 @@ export const AddApiKeyDialog: React.FC<AddApiKeyDialogProps> = (props) => {
</div>
)}
- <footer className="model-hub-add-key-foot model-hub-fill-05 flex flex-row items-center justify-end border-t border-border">
+ <footer className="model-hub-add-key-foot model-hub-fill-05 flex flex-row flex-wrap items-center justify-end border-t border-border">
{replaceMode ? (
<>
<Button
@@ -1036,6 +1044,18 @@ export const AddApiKeyDialog: React.FC<AddApiKeyDialogProps> = (props) => {
{t('settings.models.addKey.addAnyway')}
</Button>
)}
+ {constrainedProtocol && (phase.kind === 'undetermined' || phase.kind === 'failure' || (phase.kind === 'form' && !phase.report)) && (
+ <Button
+ type="button"
+ variant="outline"
+ className="model-hub-add-key-action"
+ disabled={!canSubmit}
+ onClick={() => void persist(continuation.begin(), constrainedProtocol, false, true)}
+ >
+ <Save className="size-3 shrink-0" />
+ {t('settings.models.addKey.saveUnverified')}
+ </Button>
+ )}
{phase.kind === 'form' && !phase.report && (
<Button
type="button"
diff --git a/ui/src/components/settings/models/SourceDetailPanel.tsx b/ui/src/components/settings/models/SourceDetailPanel.tsx
index cea6a689b..368addbc5 100644
--- a/ui/src/components/settings/models/SourceDetailPanel.tsx
+++ b/ui/src/components/settings/models/SourceDetailPanel.tsx
@@ -893,6 +893,7 @@ export const SourceDetailPanel: React.FC<{
known: adoptedBy !== undefined,
backends: adoptedBackends,
native: source.supply_channel === 'native_cli',
+ verificationPending: Boolean(source.verification_pending),
});
// One authority picks the remedy and another total Record names its concrete
// control. In particular, `retest` points at the existing refetch button; it is
diff --git a/ui/src/components/settings/models/SourceRow.tsx b/ui/src/components/settings/models/SourceRow.tsx
index 2e2c7b5cc..d12ca6778 100644
--- a/ui/src/components/settings/models/SourceRow.tsx
+++ b/ui/src/components/settings/models/SourceRow.tsx
@@ -33,13 +33,14 @@ export const SourceRow: React.FC<{
known: adoptedBy !== undefined,
backends: adoptedBackends,
native: source.supply_channel === 'native_cli',
+ verificationPending: Boolean(source.verification_pending),
});
const kindKey = source.supply_channel === 'native_cli'
? 'nativeCredential'
: source.kind === 'subscription'
? 'subscription'
: 'apiKey';
- const adopted = (source.state.status === 'active' || source.state.status === 'standby') && (adoptedBy?.length ?? 0) > 0;
+ const adopted = !source.verification_pending && (source.state.status === 'active' || source.state.status === 'standby') && (adoptedBy?.length ?? 0) > 0;
return (
<button
type="button"
diff --git a/ui/src/components/settings/models/sourceStatePresentation.test.ts b/ui/src/components/settings/models/sourceStatePresentation.test.ts
index ae8721267..a6a101f0b 100644
--- a/ui/src/components/settings/models/sourceStatePresentation.test.ts
+++ b/ui/src/components/settings/models/sourceStatePresentation.test.ts
@@ -21,6 +21,20 @@ const state = (status: SourceStatus, over: Partial<SourceState> = {}): SourceSta
});
describe('sourceStatePresentation', () => {
+ it.each(['card', 'detail'] as const)('keeps unverified %s sources distinct from adopted healthy sources', (surface) => {
+ for (const status of SOURCE_STATUSES) {
+ const current = state(status);
+ const adoption = { known: true, backends: ['Codex'], native: false };
+ const presentation = sourceStatePresentation(current, surface, 'en', 0, { ...adoption, verificationPending: true });
+ if (status === 'active' || status === 'standby') {
+ expect(presentation.key).toBe('settings.models.sourceDetail.status.unverified');
+ expect(presentation.dotClass).toBe('bg-gold');
+ } else {
+ expect(presentation).toEqual(sourceStatePresentation(current, surface, 'en', 0, adoption));
+ }
+ }
+ });
+
it('omits attribution when the source projection does not carry it', () => {
expect(sourceStatePresentation(state('active'), 'card', 'en', 0).key).toBeNull();
expect(sourceStatePresentation(state('active'), 'detail', 'en', 0).key).toBeNull();
diff --git a/ui/src/components/settings/models/sourceStatePresentation.ts b/ui/src/components/settings/models/sourceStatePresentation.ts
index a4e0cff74..abe275da2 100644
--- a/ui/src/components/settings/models/sourceStatePresentation.ts
+++ b/ui/src/components/settings/models/sourceStatePresentation.ts
@@ -97,8 +97,15 @@ export const sourceStatePresentation = (
surface: SourceStateSurface,
locale: string,
now: number = Date.now(),
- adoption: { known: boolean; backends: string[]; native: boolean } = { known: false, backends: [], native: false },
+ adoption: { known: boolean; backends: string[]; native: boolean; verificationPending?: boolean } = { known: false, backends: [], native: false },
): SourceStatePresentation => {
+ if (adoption.verificationPending && (state.status === 'active' || state.status === 'standby')) {
+ return {
+ key: 'settings.models.sourceDetail.status.unverified',
+ textClass: 'model-hub-ink-gold',
+ dotClass: 'bg-gold',
+ };
+ }
if (state.status === 'active' && !adoption.known) {
return { key: null, textClass: 'text-muted', dotClass: 'bg-muted' };
}
diff --git a/ui/src/components/settings/models/types.ts b/ui/src/components/settings/models/types.ts
index 31d2fd87a..0be405b7d 100644
--- a/ui/src/components/settings/models/types.ts
+++ b/ui/src/components/settings/models/types.ts
@@ -130,6 +130,8 @@ export type Source = {
supply_channel: SupplyChannel;
billing: 'monthly' | 'metered';
state: SourceState;
+ /** Opaque pending-verification identity; presence means no successful model call yet. */
+ verification_pending?: string | null;
usage?: SourceUsage;
/** Subscription identity for the row's mono sub-line (e.g. "[email protected]").
* Never secret material; may be null. */
@@ -851,7 +853,7 @@ export type ApiKeySourceObservation = {
protocol?: SourceProtocol;
};
-/** POST /api/models/sources — api_key create observes again before persisting. */
+/** POST /api/models/sources — observation is bypassed only by explicit consent. */
export type ApiKeySourceCreate = {
kind: 'api_key';
vendor: string;
@@ -864,6 +866,8 @@ export type ApiKeySourceCreate = {
protocol?: SourceProtocol;
/** Explicit consent for a repeated, protocol-proven inventory failure. */
accept_unavailable_inventory?: boolean;
+ /** Save a catalog-pinned or declared interface without calling the upstream. */
+ save_unverified?: boolean;
};
/**
diff --git a/ui/src/i18n/en.json b/ui/src/i18n/en.json
index e33c26e59..22d4862bc 100644
--- a/ui/src/i18n/en.json
+++ b/ui/src/i18n/en.json
@@ -1423,7 +1423,7 @@
},
"addKey": {
"title": "Add API key",
- "subtitle": "Detect the connection and interface first, then confirm to add",
+ "subtitle": "API key and model interface",
"field": {
"vendor": "Vendor",
"vendor.custom": "Custom · compatible endpoint",
@@ -1432,7 +1432,7 @@
"vendor.empty": "No vendor by that name",
"name": "Name (optional)",
"protocol": "Interface type",
- "protocol.hint": "Use Auto detect when unsure; choose a type to declare that interface. If authentication succeeds it can be added, a wrong choice can fail at runtime, and the saved type cannot be changed",
+ "protocol.hint": "A declared interface is not proof of credential validity or model compatibility",
"baseUrl": "Base URL",
"baseUrl.hint": "API root, such as https://api.example.com/v1; a bare host uses the standard /v1 path",
"apiKey": "API key",
@@ -1451,7 +1451,7 @@
"saving": "Saving…",
"saving.detail": "Saving this source",
"fail": {
- "subtitle": "Identifying the interface is a precondition of Add · fix what the line below names, then retry",
+ "subtitle": "Model-call verification is still pending",
"auth": "The upstream rejected this credential",
"auth.detail": "Check the API key, interface type, and the Base URL's API root path",
"address": "Wrong address: 404 Not Found",
@@ -1464,8 +1464,8 @@
},
"retry": "Retry",
"undetermined": {
- "title": "Connected and authenticated — but we cannot tell which interface it speaks",
- "detail": "This response shape matches no interface we know. Choose a concrete type and retry: if authentication succeeds on that path it can be added, but a wrong choice can fail at runtime and the saved type cannot be changed"
+ "title": "Connected, but not fully verified",
+ "detail": "The response does not establish both the interface and credential validity"
},
"protocol": {
"auto": "Auto detect",
@@ -1476,13 +1476,14 @@
"detecting": "Identifying the interface…",
"manual": "Manually specify interface type",
"catalogPinned": "Built-in catalog",
- "catalogPinned.hint": "Detection authenticates the key and fetches models; it no longer has to prove the interface by its response shape",
+ "catalogPinned.hint": "Interface supplied by the built-in catalog; credential verification is separate",
"declared": "Manually specified"
},
"inventory": {
"title": "The interface is identified — but its model list did not come back this time"
},
"addAnyway": "Add anyway",
+ "saveUnverified": "Save unverified",
"success": {
"title": "Done → the dialog closes and you land on Source details · Models",
"detail": "The model list, refetch and reasoning tiers are all maintained there"
@@ -1670,6 +1671,7 @@
"error": "Error",
"standbyHintLabel": "What this status means",
"standbyHint": "This source is healthy. It reads as in use once a backend in Gateway mode serves a route through it.",
+ "unverified": "Not yet verified",
"listUpdated": "· model list updated {{time}}"
},
"summary_one": "{{host}} · {{count}} model",
diff --git a/ui/src/i18n/zh.json b/ui/src/i18n/zh.json
index 188de3abf..7cb718c99 100644
--- a/ui/src/i18n/zh.json
+++ b/ui/src/i18n/zh.json
@@ -1423,7 +1423,7 @@
},
"addKey": {
"title": "添加 API Key",
- "subtitle": "先检测连接与接口,确认后添加",
+ "subtitle": "API Key 与模型接口",
"field": {
"vendor": "服务商",
"vendor.custom": "自定义 · 兼容端点",
@@ -1432,7 +1432,7 @@
"vendor.empty": "没有同名的服务商",
"name": "名称(可选)",
"protocol": "接口类型",
- "protocol.hint": "不确定时用自动探测;已知类型时可直接声明所选接口。该路径鉴权成功即可添加;选错了运行时可能失败,而且保存后不可更改",
+ "protocol.hint": "指定接口不代表凭证有效,也不代表实际模型调用兼容",
"baseUrl": "Base URL",
"baseUrl.hint": "填写 API 根地址,例如 https://api.example.com/v1;只填域名时使用标准 /v1 路径",
"apiKey": "API Key",
@@ -1451,7 +1451,7 @@
"saving": "保存中…",
"saving.detail": "正在保存这个供应商",
"fail": {
- "subtitle": "认出接口是「添加」的前置条件 · 先按下面这条修,再重试",
+ "subtitle": "实际模型调用仍未验证",
"auth": "供应商拒绝了这个凭据",
"auth.detail": "检查 API Key、接口类型和 Base URL 的 API 根路径",
"address": "地址不对:404 Not Found",
@@ -1464,8 +1464,8 @@
},
"retry": "重试",
"undetermined": {
- "title": "连上了、也通过了鉴权 —— 但认不出它说哪种接口",
- "detail": "这次返回结构对不上任何一种已知接口。请选择一个明确类型后重试:只要该路径鉴权成功即可添加;但选错了运行时可能失败,而且保存后不可更改"
+ "title": "已连接,但尚未完成验证",
+ "detail": "这次响应不足以同时确认接口类型和凭证有效性"
},
"protocol": {
"auto": "自动探测",
@@ -1476,13 +1476,14 @@
"detecting": "识别接口中…",
"manual": "手动指定接口类型",
"catalogPinned": "内置目录",
- "catalogPinned.hint": "检测会验证密钥并拉取模型;不再需要靠返回结构证明接口",
+ "catalogPinned.hint": "接口由内置目录指定;凭证是否有效仍需单独验证",
"declared": "手动指定"
},
"inventory": {
"title": "接口已经识别,但这次没有拿到模型清单"
},
"addAnyway": "仍要添加",
+ "saveUnverified": "未验证保存",
"success": {
"title": "添加成功,接下来进入供应商详情",
"detail": "模型列表、重新拉取和推理强度档位都在那里维护"
@@ -1670,6 +1671,7 @@
"error": "异常",
"standbyHintLabel": "这个状态是什么意思",
"standbyHint": "这个供应商当前可用。当模型网关中的某个后端通过它调用模型时,它就会显示为使用中。",
+ "unverified": "尚未验证",
"listUpdated": "· 模型列表更新于 {{time}}"
},
"summary_one": "{{host}} · {{count}} 个模型",
diff --git a/vibe/model_hub_runtime/adapter.py b/vibe/model_hub_runtime/adapter.py
index 0c2090523..99472fdf4 100644
--- a/vibe/model_hub_runtime/adapter.py
+++ b/vibe/model_hub_runtime/adapter.py
@@ -140,9 +140,9 @@ class _ProtocolObservationTaxonomy:
"""One protocol's request shape and response evidence table.
The request path and body are part of the same authority as the response
- taxonomy. OpenAI probes deliberately provide the common ``model`` field
- while omitting the candidate-specific ``input`` or ``messages`` field, so
- each endpoint reaches its own protocol-shaped validation error.
+ taxonomy. Every probe omits ``model`` so observation does not request model
+ scheduling. Schema validation never proves authentication, regardless of
+ whether the interface has a catalog owner or a user declaration.
"""
request_path: str
@@ -253,13 +253,13 @@ def _openai_evidence_rules(
error_identifiers=_REQUEST_ERROR_IDENTIFIERS,
error_params=request_params,
protocol=_ProtocolProof.PROVEN,
- authentication=_AuthenticationEvidence.ACCEPTED,
+ authentication=_AuthenticationEvidence.UNKNOWN,
),
_ProtocolEvidenceRule(
statuses=_REQUEST_ERROR_STATUSES,
error_identifiers=_MODEL_ERROR_IDENTIFIERS,
protocol=_ProtocolProof.UNPROVEN,
- authentication=_AuthenticationEvidence.ACCEPTED,
+ authentication=_AuthenticationEvidence.UNKNOWN,
shape=_ProtocolObservationShape.GENERIC_REQUEST_ERROR,
),
_ProtocolEvidenceRule(
@@ -289,6 +289,8 @@ def _openai_evidence_rules(
)
+# Omit the model so observation stops at request validation, before a relay
+# schedules upstream capacity or applies model-specific availability limits.
_PROTOCOL_OBSERVATION_TAXONOMY = {
"anthropic": _ProtocolObservationTaxonomy(
request_path="/v1/messages",
@@ -314,7 +316,7 @@ _PROTOCOL_OBSERVATION_TAXONOMY = {
top_level_values=frozenset({"error"}),
error_identifiers=_REQUEST_ERROR_IDENTIFIERS | _MODEL_ERROR_IDENTIFIERS,
protocol=_ProtocolProof.PROVEN,
- authentication=_AuthenticationEvidence.ACCEPTED,
+ authentication=_AuthenticationEvidence.UNKNOWN,
),
_ProtocolEvidenceRule(
statuses=_AUTHENTICATION_ERROR_STATUSES,
@@ -344,7 +346,7 @@ _PROTOCOL_OBSERVATION_TAXONOMY = {
),
"openai_responses": _ProtocolObservationTaxonomy(
request_path="/v1/responses",
- request_body={"model": "__avibe_model_hub_probe__"},
+ request_body={},
oauth_path="/backend-api/codex/responses",
evidence_rules=_openai_evidence_rules(
frozenset({"response"}),
@@ -353,7 +355,7 @@ _PROTOCOL_OBSERVATION_TAXONOMY = {
),
"openai_chat": _ProtocolObservationTaxonomy(
request_path="/v1/chat/completions",
- request_body={"model": "__avibe_model_hub_probe__"},
+ request_body={},
oauth_path=None,
evidence_rules=_openai_evidence_rules(
frozenset({"chat.completion", "chat.completion.chunk"}),
@@ -493,13 +495,10 @@ def _parse_protocol_authenticated_evidence(
vendor: str | None = None,
request_root: str | None = None,
) -> _ProtocolEvidence:
- """Classify response-shaped protocol proof and table-driven auth evidence.
+ """Classify protocol shape without treating schema validation as login.
- This parser never upgrades a generic response into a protocol owner on its
- own. ``observe_source()`` may later apply the September 4, 2026 owner-based
- ladder for shipped vendor pins and concrete `custom` declarations after the
- constrained path has responded. `custom` Auto detect still relies on this
- parser's response evidence alone.
+ A missing-model error can precede authentication. Neither a declaration nor
+ a differently rejected credential can upgrade it into authentication proof.
"""
def evidence(
@@ -550,7 +549,7 @@ def _parse_protocol_authenticated_evidence(
if wrapperless == "accepted":
return evidence(
protocol=_ProtocolProof.UNPROVEN,
- authentication=_AuthenticationEvidence.ACCEPTED,
+ authentication=_AuthenticationEvidence.UNKNOWN,
shape=_ProtocolObservationShape.GENERIC_REQUEST_ERROR,
)
if wrapperless == "rejected":
@@ -577,7 +576,7 @@ def _parse_protocol_authenticated_evidence(
if wrapperless == "accepted":
return evidence(
protocol=_ProtocolProof.UNPROVEN,
- authentication=_AuthenticationEvidence.ACCEPTED,
+ authentication=_AuthenticationEvidence.UNKNOWN,
shape=_ProtocolObservationShape.GENERIC_REQUEST_ERROR,
)
if isinstance(error, dict):
@@ -589,7 +588,7 @@ def _parse_protocol_authenticated_evidence(
):
return evidence(
protocol=_ProtocolProof.UNPROVEN,
- authentication=_AuthenticationEvidence.ACCEPTED,
+ authentication=_AuthenticationEvidence.UNKNOWN,
shape=_ProtocolObservationShape.GENERIC_REQUEST_ERROR,
)
if _response_shape_proves_protocol(protocol, payload):
@@ -636,7 +635,7 @@ async def _probe_protocol_response(
"Accept": "application/json",
}
client_timeout = aiohttp.ClientTimeout(total=timeout)
- try:
+ async def observe() -> _ProtocolEvidence:
async with aiohttp.ClientSession(timeout=client_timeout) as session:
async with session.post(
url,
@@ -646,12 +645,11 @@ async def _probe_protocol_response(
) as response:
body = await response.content.read(64 * 1024)
return _parse_protocol_authenticated_evidence(
- protocol,
- response.status,
- body,
- vendor=vendor,
- request_root=root,
+ protocol, response.status, body, vendor=vendor, request_root=root,
)
+
+ try:
+ return await asyncio.wait_for(observe(), timeout=timeout)
except asyncio.TimeoutError:
raise EngineClientError("protocol observation timed out", error_type="timeout") from None
except aiohttp.ClientError:
@@ -816,7 +814,6 @@ def _probe_oauth_protocol_response(
if vendor == "anthropic" and protocol == "anthropic":
url = f"https://api.anthropic.com{taxonomy.oauth_path or taxonomy.request_path}"
headers = {
- "Authorization": "Bearer $TOKEN$",
"Accept": "application/json",
"Content-Type": "application/json",
"Anthropic-Version": "2023-06-01",
@@ -826,7 +823,6 @@ def _probe_oauth_protocol_response(
elif vendor in {"openai", "codex"} and protocol == "openai_responses":
url = f"https://chatgpt.com{taxonomy.oauth_path or taxonomy.request_path}"
headers = {
- "Authorization": "Bearer $TOKEN$",
"Accept": "application/json",
"Content-Type": "application/json",
"Originator": "codex-tui",
@@ -838,30 +834,31 @@ def _probe_oauth_protocol_response(
"OAuth credential does not support this protocol path",
status_code=404,
)
- payload = client.management_request(
- "POST",
- "/api-call",
- payload={
- "auth_index": auth.auth_index,
- "method": "POST",
- "url": url,
- "header": headers,
- "data": json.dumps(taxonomy.request_body, separators=(",", ":")),
- },
- )
- status = payload.get("status_code")
- if not isinstance(status, int) or isinstance(status, bool):
- raise EngineClientError(
- "protocol observation returned an invalid status",
- error_type="invalid_json",
+ headers["Authorization"] = "Bearer $TOKEN$"
+ def request(probe_headers: dict[str, str]) -> _ProtocolEvidence:
+ payload = client.management_request(
+ "POST",
+ "/api-call",
+ payload={
+ "auth_index": auth.auth_index,
+ "method": "POST",
+ "url": url,
+ "header": probe_headers,
+ "data": json.dumps(taxonomy.request_body, separators=(",", ":")),
+ },
)
- body = payload.get("body")
- return _parse_protocol_authenticated_evidence(
- protocol,
- status,
- body if isinstance(body, str) else "",
- vendor=vendor,
- )
+ status = payload.get("status_code")
+ if not isinstance(status, int) or isinstance(status, bool):
+ raise EngineClientError(
+ "protocol observation returned an invalid status",
+ error_type="invalid_json",
+ )
+ body = payload.get("body")
+ return _parse_protocol_authenticated_evidence(
+ protocol, status, body if isinstance(body, str) else "", vendor=vendor,
+ )
+
+ return request(headers)
@dataclass
@@ -1578,12 +1575,11 @@ class CLIProxyEngineAdapter:
``protocol_order`` orders attempts only. A protocol-specific response
with accepted authentication proves the current attempt and terminates
observation. A shipped vendor catalog pin or a concrete `custom`
- declaration also terminates observation once that exact protocol path
- returns an owner-scoped auth status: 401/403 reject, while 2xx and
- request-error 400/404/422 accept even when the response shape stays
- generic. A shaped credential rejection is recorded while later
- candidates continue on Auto detect. Vendor, URL, and order never create
- a conclusion on their own; `custom` Auto still requires response-backed
+ declaration also terminates observation after a shaped success.
+ Schema errors remain unverified; explicit unverified saving belongs to
+ Source creation, not this observation. A shaped rejection is
+ recorded while later candidates continue on Auto detect. Vendor, URL,
+ and order never create a conclusion on their own; `custom` Auto still requires response-backed
proof, and exhausting that path without one remains ambiguous.
"""
@@ -1628,6 +1624,12 @@ class CLIProxyEngineAdapter:
for protocol in protocol_order:
if protocol not in SOURCE_PROTOCOLS:
raise EngineStateError("unsupported source protocol")
+ owner_scoped_protocol = _protocol_is_persistable_without_shape_proof(
+ credential_kind=str(credential_kind),
+ vendor=normalized_vendor,
+ protocol=protocol,
+ protocol_order=protocol_order,
+ )
try:
if credential_kind == "api_key":
evidence = await _probe_protocol_response(
@@ -1648,33 +1650,6 @@ class CLIProxyEngineAdapter:
except EngineClientError as exc:
failures.append(exc)
continue
- owner_scoped_protocol = _protocol_is_persistable_without_shape_proof(
- credential_kind=str(credential_kind),
- vendor=normalized_vendor,
- protocol=protocol,
- protocol_order=protocol_order,
- )
- owner_rejected = (
- owner_scoped_protocol
- and evidence.status in _AUTHENTICATION_ERROR_STATUSES
- )
- owner_accepted = (
- owner_scoped_protocol
- and (
- evidence.status in _SUCCESS_STATUSES
- or evidence.status in _REQUEST_ERROR_STATUSES
- )
- )
- if owner_rejected:
- evidence = replace(
- evidence,
- authentication=_AuthenticationEvidence.REJECTED,
- )
- elif owner_accepted:
- evidence = replace(
- evidence,
- authentication=_AuthenticationEvidence.ACCEPTED,
- )
if evidence.authentication is _AuthenticationEvidence.REJECTED:
received_rejection = True
ruled_out_protocols.add(protocol)
@@ -1777,29 +1752,29 @@ class CLIProxyEngineAdapter:
discovery=ObservationDiscovery.NOT_ATTEMPTED,
models=(),
)
- if received_rejection:
+ if received_proven_unknown:
return make_source_observation(
- outcome=ObservationOutcome.AUTHENTICATION_FAILED,
+ outcome=ObservationOutcome.ADAPTER_ERROR,
reachable=True,
- authenticated=False,
+ authenticated=None,
protocol=None,
discovery=ObservationDiscovery.NOT_ATTEMPTED,
models=(),
)
- if received_proven_unknown:
+ if received_unproven_response and not considered_protocols.issubset(ruled_out_protocols):
return make_source_observation(
- outcome=ObservationOutcome.ADAPTER_ERROR,
+ outcome=ObservationOutcome.AMBIGUOUS,
reachable=True,
authenticated=None,
protocol=None,
discovery=ObservationDiscovery.NOT_ATTEMPTED,
models=(),
)
- if received_unproven_response:
+ if received_rejection:
return make_source_observation(
- outcome=ObservationOutcome.AMBIGUOUS,
+ outcome=ObservationOutcome.AUTHENTICATION_FAILED,
reachable=True,
- authenticated=None,
+ authenticated=False,
protocol=None,
discovery=ObservationDiscovery.NOT_ATTEMPTED,
models=(),