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): give a Source an identity that never reverts after a credential change (#2628)

Call White8efe42a6eb27
diff --git a/config/v2_config.py b/config/v2_config.py
index 1161f4d21..bdee63684 100644
--- a/config/v2_config.py
+++ b/config/v2_config.py
@@ -2341,6 +2341,16 @@ class ModelHubSourceConfig:
account_label: Optional[str] = None
masked_credential: Optional[str] = None
verification_pending: Optional[str] = None
+ # The verification marker minted at the latest credential or endpoint change, kept when verification clears the
+ # marker: the Source's identity follows it, so an identity never returns to one an earlier credential had, even
+ # when OAuth reauthentication keeps the credential's handle. Absent until the first such change.
+ credential_generation: Optional[str] = None
+
+ def __post_init__(self) -> None:
+ if self.credential_generation is None and self.verification_pending:
+ # A release before the generation left a pending Source with only its marker, which named the change that
+ # minted it: that marker is the change's generation, so the identity stays what it was.
+ self.credential_generation = self.verification_pending
@classmethod
def from_payload(cls, payload: dict, *, repairing: bool = False) -> "ModelHubSourceConfig":
@@ -2365,6 +2375,7 @@ class ModelHubSourceConfig:
"account_label",
"masked_credential",
"verification_pending",
+ "credential_generation",
}
if set(payload) - allowed_fields:
raise ValueError("Config 'model_hub.sources' contains unknown fields")
@@ -2420,6 +2431,12 @@ class ModelHubSourceConfig:
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")
+ credential_generation = payload.get("credential_generation")
+ if credential_generation is not None and (
+ not isinstance(credential_generation, str)
+ or re.fullmatch(r"vp_[0-9a-f]{32}", credential_generation) is None
+ ):
+ raise ValueError("Config 'model_hub.sources.credential_generation' must be a verification marker")
created_at = payload.get("created_at")
client_nonce = (
validate_model_hub_source_client_nonce(payload.get("client_nonce"))
@@ -2474,6 +2491,7 @@ class ModelHubSourceConfig:
account_label=account_label,
masked_credential=masked_credential,
verification_pending=verification_pending,
+ credential_generation=credential_generation,
)
def to_payload(self) -> dict:
@@ -2498,6 +2516,8 @@ class ModelHubSourceConfig:
payload["client_nonce"] = self.client_nonce
if self.verification_pending:
payload["verification_pending"] = self.verification_pending
+ if self.credential_generation:
+ payload["credential_generation"] = self.credential_generation
if self.usage is not None:
payload["usage"] = self.usage.to_payload()
return payload
diff --git a/core/handlers/model_hub/hosted_probe.py b/core/handlers/model_hub/hosted_probe.py
index 9e31edb9d..3bdb0acd5 100644
--- a/core/handlers/model_hub/hosted_probe.py
+++ b/core/handlers/model_hub/hosted_probe.py
@@ -256,12 +256,10 @@ REPLAY_MIN_SECONDS: Final = 60.0
MAX_PROBE_REQUESTS = 2
class CallResult(Protocol):
- """How one pinned call settled: the Source it ran on, its outcome, and whether it retired that Source's own
- pending verification marker (``ModelHubService._user_test_call``)."""
+ """How one pinned call settled: the Source it ran on and its outcome (``ModelHubService._user_test_call``)."""
source: ModelHubSourceConfig
outcome: RawCallOutcome
- retired_own_marker: bool
# Model Hub's one pinned call for a request body: it opens the call on the probed Source, hands it to the reader,
@@ -276,8 +274,6 @@ class ProbeCall:
body: dict[str, Any]
source: ModelHubSourceConfig
outcome: RawCallOutcome
- # Proof that this call's own success retired the Source's pending verification.
- retired_own_marker: bool = False
class _CallStream(httpx.AsyncByteStream):
@@ -364,7 +360,7 @@ class PinnedCallTransport(httpx.AsyncBaseTransport):
async def run() -> None:
settled = await self._call(body, read)
- self._slots[slot] = ProbeCall(body, settled.source, settled.outcome, settled.retired_own_marker)
+ self._slots[slot] = ProbeCall(body, settled.source, settled.outcome)
task = asyncio.create_task(run())
self._tasks.append(task)
diff --git a/core/handlers/model_hub/retry.py b/core/handlers/model_hub/retry.py
index 6dd589a91..9b28b2614 100644
--- a/core/handlers/model_hub/retry.py
+++ b/core/handlers/model_hub/retry.py
@@ -30,11 +30,18 @@ RETRY_DELAYS = {
def source_identity(source: ModelHubSourceConfig) -> tuple:
- """Configuration identity, independent of mutable health and inventory."""
+ """Configuration identity, independent of mutable health, inventory and verification.
+
+ Every credential or endpoint change mints a new ``credential_generation``, which verification keeps, so the
+ identity changes once per change and never reverts: not when the change is verified, and not when OAuth
+ reauthentication keeps the credential's handle. Released Sources keep their digests: a verified one has no
+ generation where its identity held a ``None`` marker, and a pending one's marker becomes its generation
+ (``ModelHubSourceConfig``).
+ """
return (
source.kind, source.vendor, source.protocol, source.supply_channel,
- source.base_url, source.credential_ref, source.verification_pending,
+ source.base_url, source.credential_ref, source.credential_generation,
)
@@ -292,16 +299,6 @@ class RecoveryPolicy:
self.notify()
return True
- def verification_retired(self, source_id: str, previous: tuple, current: tuple) -> None:
- """Retiring a verification marker does not replace the credential."""
-
- state = self._sources.get(source_id)
- if state is not None and state.identity == previous:
- state.identity = current
- retired = self._retired_cooldowns.get(source_id)
- if retired is not None and retired[0] == previous:
- self._retired_cooldowns[source_id] = (current, *retired[1:])
-
async def wait(self, delay: float, changed: asyncio.Event) -> None:
"""Wait without owning the configuration lock or a transport."""
diff --git a/core/handlers/model_hub/service.py b/core/handlers/model_hub/service.py
index 5e51e7032..7531f8df2 100644
--- a/core/handlers/model_hub/service.py
+++ b/core/handlers/model_hub/service.py
@@ -820,8 +820,6 @@ class UserTestCall(NamedTuple):
source: ModelHubSourceConfig
outcome: RawCallOutcome
elapsed_ms: int
- # Whether this call's own success retired the pending verification it was made under.
- retired_own_marker: bool
def _call_usage(outcome: RawCallOutcome | None, observed: ProtocolSSEState | None) -> ProtocolUsageReport | None:
@@ -2596,6 +2594,8 @@ class ModelHubService:
previous = self.store.load()
config = self._clone_config(previous)
source = self._source(config, source_id)
+ # The material behind the ref may be the new grant's: the Source no longer has the earlier one's identity.
+ self._mark_source_unverified(source)
source.models = [
model
for model in source.models
@@ -7715,7 +7715,7 @@ class ModelHubService:
async for _chunk in handle.stream:
pass
- source, outcome, elapsed_ms, _retired = await self._user_test_call(
+ source, outcome, elapsed_ms = await self._user_test_call(
source_id,
model_id,
selected,
@@ -7928,24 +7928,16 @@ class ModelHubService:
) -> str | None:
"""Record what a probe showed for the Source as it reads now; the identity recorded for, or None.
- Only ``verified`` and ``unsupported`` are evidence. The one change a probe
- may see is its own: its call's success retired the pending verification it
- was made under, which settlement proves. Any other change during the probe
- (a new credential, endpoint, protocol, or a marker another grant's call
- retired) means the probe vouches for nothing there. ``identity``, when
- given, is the one the probe's earlier aspect was recorded for: both
- records then describe the same Source.
+ Only ``verified`` and ``unsupported`` are evidence. A Source whose identity
+ changed during the probe (a new credential, endpoint or protocol) is one the
+ probe vouches for nothing on; verifying the credential it ran on is no such
+ change. ``identity``, when given, is the one the probe's earlier aspect was
+ recorded for: both records then describe the same Source.
"""
current = await asyncio.to_thread(self.store.load)
live = next((item for item in current.sources if item.id == last.source.id), None)
- if live is None or not (
- identity_digest(live) == identity_digest(last.source)
- or (
- last.retired_own_marker
- and identity_digest(replace(last.source, verification_pending=None)) == identity_digest(live)
- )
- ):
+ if live is None or identity_digest(live) != identity_digest(last.source):
return None
digest = identity_digest(live)
if identity is not None and digest != identity:
@@ -8036,7 +8028,6 @@ class ModelHubService:
admitted_at = None
attempt_generation = PRE_ATTEMPT_SETTLEMENT_GENERATION
cancelled_observed: ProtocolSSEState | None = None
- retired_own_marker = False
async def invoke_selected() -> None:
nonlocal source, handle, outcome, admitted_at, attempt_generation, cancelled_observed
@@ -8097,7 +8088,6 @@ class ModelHubService:
outcome = await self._engine_call(handle.outcome())
async def settle_attempt() -> None:
- nonlocal retired_own_marker
try:
if source is not None and outcome is not None:
# The explicit test is the retry a cooldown waits for.
@@ -8105,7 +8095,7 @@ class ModelHubService:
await self._record_recovery_success(
source.id, attempt_generation, backend="system", model_id=model_id,
)
- retired_own_marker = await self._verify_successful_source(
+ await self._verify_successful_source(
source.id, source.credential_ref, source.verification_pending, outcome,
)
finally:
@@ -8148,7 +8138,7 @@ class ModelHubService:
pass
raise cancelled
assert source is not None and outcome is not None
- return UserTestCall(source, outcome, elapsed_ms, retired_own_marker)
+ return UserTestCall(source, outcome, elapsed_ms)
@staticmethod
def _probe_failure(
@@ -9459,8 +9449,11 @@ class ModelHubService:
@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}"
+ # Persist identity with the credential, including same-handle reauth: the marker clears once a call verifies
+ # the credential, and the generation keeps it, so the Source's identity never reverts to an earlier one.
+ marker = f"vp_{uuid.uuid4().hex}"
+ source.verification_pending = marker
+ source.credential_generation = marker
async def _verify_successful_source(
self,
@@ -9468,14 +9461,16 @@ class ModelHubService:
credential_ref: str | None,
verification_pending: str | None,
outcome: RawCallOutcome,
- ) -> bool:
- """Retire pending verification only for the current credential's call; whether this call retired it."""
+ ) -> None:
+ """Retire pending verification only for the current credential's call.
+
+ The Source's identity does not include the marker, so retiring it changes no identity: health, retry state
+ and evidence all carry over.
+ """
if outcome.kind is not RawOutcomeKind.SUCCESS or verification_pending is None:
- return False
- retired_identity: tuple[tuple, tuple] | None = None
+ return
def clear_current(config: ModelHubConfig) -> bool:
- nonlocal retired_identity
current = next((item for item in config.sources if item.id == source_id), None)
if (
current is None
@@ -9483,20 +9478,13 @@ class ModelHubService:
or current.verification_pending != verification_pending
):
return False
- previous_identity = source_identity(current)
current.verification_pending = None
- retired_identity = (previous_identity, source_identity(current))
return True
try:
async with self._mutation_lock:
self.store.mutate(clear_current)
- if retired_identity is not None:
- previous_identity, current_identity = retired_identity
- self.recovery.verification_retired(source_id, previous_identity, current_identity)
- if self._source_attempt_identities.get(source_id) == previous_identity:
- self._source_attempt_identities[source_id] = current_identity
- return retired_identity is not None
+ return
except ValueError as exc:
if "recovery warnings" not in str(exc):
raise
@@ -9505,7 +9493,6 @@ class ModelHubService:
# 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")
- return False
async def settle_handle_outcome(
self,
diff --git a/docs/plans/agent-core-contracts/model-hub-consumer.md b/docs/plans/agent-core-contracts/model-hub-consumer.md
index 8187a81e0..2c96e8219 100644
--- a/docs/plans/agent-core-contracts/model-hub-consumer.md
+++ b/docs/plans/agent-core-contracts/model-hub-consumer.md
@@ -87,7 +87,7 @@ consumer's requirements, and the Model Hub lane lands the change in both places.
- every replayed hosted item outside the in-flight response needs its tool to run on the hop, and `replay`
evidence. A generated image never has it.
- **One identity per turn and Source.** Native content goes to a Source only under one identity (credential,
- base URL, protocol, vendor, kind, verification) per turn. The turn's first pinned request admitted to the
+ base URL, protocol, vendor, kind, credential generation) per turn. The turn's first pinned request admitted to the
Source binds it, atomically with that request's final admission, and every later one must match it. After a
mid-turn change, such as a rotated key or an edited relay URL, every pinned request to that Source is
`pin_unavailable` for the rest of the turn, even with evidence taken anew, including one overlapping the
diff --git a/docs/plans/model-hub-capability-model.md b/docs/plans/model-hub-capability-model.md
index 93d38bf8d..b8768b775 100644
--- a/docs/plans/model-hub-capability-model.md
+++ b/docs/plans/model-hub-capability-model.md
@@ -76,9 +76,13 @@ is its JSON Schema. The store is `core/handlers/model_hub/capability_evidence.py
`observed` evidence is always `unsupported`.
Records live in the Model Hub state directory (`model_hub_capability_evidence.json`). They follow Source identity:
-`retry.source_identity` covers kind, vendor, protocol, channel, base URL, credential and verification marker.
+`retry.source_identity` covers kind, vendor, protocol, channel, base URL, credential and credential generation.
Changing any of those drops the Source's evidence: a record whose stored digest no longer matches reads as unknown
-and is pruned at the next write.
+and is pruned at the next write. The credential generation is the verification marker the latest credential or
+endpoint change minted, kept after verification clears the marker. So verifying a credential changes no identity,
+and a later change never returns the Source to an earlier identity, even when OAuth reauthentication keeps the
+credential's handle. Released Sources keep their digests: a verified one has no generation, where the identity held
+no marker, and a pending one's marker becomes its generation.
### 3.2 Learning from real errors (negative evidence)
diff --git a/docs/plans/model-hub-contracts/source.schema.json b/docs/plans/model-hub-contracts/source.schema.json
index 087d93c81..5344c7cbc 100644
--- a/docs/plans/model-hub-contracts/source.schema.json
+++ b/docs/plans/model-hub-contracts/source.schema.json
@@ -24,6 +24,11 @@
"pattern": "^vp_[0-9a-f]{32}$",
"description": "Opaque, non-secret pending-verification identity, replaced whenever Hub credential material or endpoint is stored without an add-time observation that authenticated it, same-handle OAuth reauthentication included. Presence means nothing upstream has accepted this credential yet, 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."
},
+ "credential_generation": {
+ "type": ["string", "null"],
+ "pattern": "^vp_[0-9a-f]{32}$",
+ "description": "Opaque, non-secret identity of the Source's latest credential or endpoint change: the verification marker that change minted, kept after verification clears verification_pending. The Source identity that evidence, retry state, a turn's native-content pin and opaque-payload binding follow includes it instead of verification_pending, so verification changes no identity and an identity never returns to one an earlier credential had, even when OAuth reauthentication keeps the credential's handle. Absent on a verified Source no such change has touched since the field existed; a Source still pending from before the field takes its verification_pending as its generation. Either way a released Source's identity is unchanged."
+ },
"id": {
"type": "string",
"pattern": "^src_[a-z0-9]{8,}$"
diff --git a/tests/scenarios/model_hub/catalog.yaml b/tests/scenarios/model_hub/catalog.yaml
index cf8f2cece..5f4877e9a 100644
--- a/tests/scenarios/model_hub/catalog.yaml
+++ b/tests/scenarios/model_hub/catalog.yaml
@@ -194,6 +194,8 @@ scenarios:
related_tests:
- tests/test_model_hub_capability_evidence.py::test_a_changed_source_identity_reads_as_unknown_and_is_pruned
- tests/test_model_hub_capability_evidence.py::test_hosted_evidence_is_stamped_with_the_engines_hosted_wire
+ - tests/test_model_hub_capability_evidence.py::test_a_released_sources_identity_digest_is_unchanged
+ - tests/test_model_hub_unverified.py::test_a_verified_reauthentication_never_returns_the_source_to_its_earlier_identity
- tests/test_model_hub_capability_evidence.py::test_persisted_records_match_the_schema_and_unreadable_ones_are_unknown
- id: MH-HOSTED-004
name: The Tools API reads every tool's candidates and evidence and writes one toggle without touching other Model Hub state
@@ -330,12 +332,11 @@ scenarios:
- tests/test_model_hub_hosted_probe.py::test_each_candidate_states_what_probing_it_would_cost
- tests/test_model_hub_hosted_probe.py::test_each_request_the_adapter_sends_is_its_own_pinned_call
- tests/test_model_hub_hosted_probe.py::test_a_probe_that_verifies_its_source_records_evidence_for_the_source_as_it_now_is
- - tests/test_model_hub_hosted_probe.py::test_a_probe_records_no_evidence_for_a_grant_that_replaced_its_own_mid_probe
+ - tests/test_model_hub_hosted_probe.py::test_a_probe_records_no_evidence_for_a_source_reauthenticated_mid_probe
- tests/test_model_hub_hosted_probe.py::test_the_probe_reads_its_calls_in_the_order_the_adapter_sent_them
- tests/test_model_hub_hosted_probe.py::test_the_probe_asks_for_no_more_output_than_a_turn_on_its_hop_would
- tests/test_model_hub_hosted_probe.py::test_an_api_key_source_is_probed_on_a_passthrough_model_it_does_not_list
- tests/test_model_hub_hosted_probe.py::test_a_probe_that_times_out_before_its_handle_is_still_metered
- - tests/test_model_hub_hosted_probe.py::test_a_probe_attributes_nothing_when_another_grant_retired_the_marker
- tests/test_model_hub_hosted_probe.py::test_a_deadline_mid_stream_ends_the_probe_as_transient
- tests/test_model_hub_hosted_probe.py::test_a_probe_settles_when_the_adapter_is_done_even_if_the_body_stays_open
- tests/test_model_hub_hosted_probe.py::test_an_image_probe_verifies_only_an_image_vibey_could_keep
diff --git a/tests/test_model_hub_api.py b/tests/test_model_hub_api.py
index 8723cb8b0..1575141da 100644
--- a/tests/test_model_hub_api.py
+++ b/tests/test_model_hub_api.py
@@ -8613,6 +8613,8 @@ def test_failed_same_handle_hub_reauth_requires_user_action(
assert exc_info.value.code == ("discovery_failed" if failure == "discovery" else "engine_down")
persisted = store.config.sources[0]
assert persisted.credential_ref == "cred_hub_reused"
+ # The material behind the reused ref may be the new grant's, so the Source leaves the earlier grant's identity.
+ assert persisted.credential_generation is not None and persisted.verification_pending == persisted.credential_generation
assert persisted.models == []
assert persisted.state.status == "needs_action"
assert persisted.state.detail_key == "models.source.needs_action.oauth_expired"
diff --git a/tests/test_model_hub_background_discovery.py b/tests/test_model_hub_background_discovery.py
index f5d90bb3a..d7948aaa2 100644
--- a/tests/test_model_hub_background_discovery.py
+++ b/tests/test_model_hub_background_discovery.py
@@ -12,7 +12,7 @@ import pytest
from config.v2_config import ModelHubModelConfig, ModelHubSourceStateConfig
from core.handlers.model_hub.errors import ModelDiscoveryError
from core.handlers.model_hub.rpc import dispatch_model_hub_rpc
-from core.handlers.model_hub.service import UnavailableEngineAdapter
+from core.handlers.model_hub.service import ModelHubService, UnavailableEngineAdapter
from tests.test_model_hub_resolution import FakeAdapter, _config, _service, _source
from tests.test_model_hub_retry_policy import Clock
@@ -236,7 +236,7 @@ def _switch_protocol(source):
def _await_verification(source):
- source.verification_pending = "vp_" + "0" * 32
+ ModelHubService._mark_source_unverified(source)
def _land_manual_refresh(source):
diff --git a/tests/test_model_hub_capability_evidence.py b/tests/test_model_hub_capability_evidence.py
index 8944e621d..f6bd5d1e9 100644
--- a/tests/test_model_hub_capability_evidence.py
+++ b/tests/test_model_hub_capability_evidence.py
@@ -124,6 +124,25 @@ def test_hosted_evidence_is_stamped_with_the_engines_hosted_wire(tmp_path, monke
assert engine_stamp() == stamp
+ "marker,digest",
+ [
+ (None, "sha256:b682a96ef48e2f2834ed22ba2d42cdae568e5768f3fc3a1334a24728ffdb7166"),
+ ("vp_" + "7" * 32, "sha256:d0b054e8827133cbeb6b4427af5ea696e2d29ab8f08de21d079336155bed8333"),
+ ],
+ ids=["verified", "pending"],
+)
+def test_a_released_sources_identity_digest_is_unchanged(marker, digest):
+ """MH-HOSTED-003: evidence a released build recorded still follows the Source it loads. The digests are the ones
+ released builds computed, whose identity held the verification marker; a pending Source's marker seeds its
+ generation, so a reauthentication it was pending on never collides with the identity before it."""
+ released = _source().to_payload()
+ if marker is not None:
+ released["verification_pending"] = marker
+ assert "credential_generation" not in released
+ assert identity_digest(ModelHubSourceConfig.from_payload(released)) == digest
+
+
def test_a_changed_source_identity_reads_as_unknown_and_is_pruned(tmp_path):
store = CapabilityEvidenceStore(tmp_path / "model_hub_capability_evidence.json")
keep, rekeyed = _source("src_keep0001"), _source("src_swap0001")
diff --git a/tests/test_model_hub_config.py b/tests/test_model_hub_config.py
index e9d5f8db3..6553b7ea0 100644
--- a/tests/test_model_hub_config.py
+++ b/tests/test_model_hub_config.py
@@ -1403,6 +1403,7 @@ def test_model_hub_config_round_trip_and_serializer_completeness(monkeypatch, tm
"credential_ref": "cred_serializer_test",
"client_nonce": "scn_01j5w8z7p4n6q2rt",
"verification_pending": "vp_0123456789abcdef0123456789abcdef",
+ "credential_generation": "vp_0123456789abcdef0123456789abcdef",
}
hub_payload = {
"sources": [source_example],
diff --git a/tests/test_model_hub_hosted_probe.py b/tests/test_model_hub_hosted_probe.py
index 5edf52299..5ab960132 100644
--- a/tests/test_model_hub_hosted_probe.py
+++ b/tests/test_model_hub_hosted_probe.py
@@ -378,9 +378,10 @@ async def test_each_request_the_adapter_sends_is_its_own_pinned_call(tmp_path, m
@pytest.mark.asyncio
async def test_a_probe_that_verifies_its_source_records_evidence_for_the_source_as_it_now_is(tmp_path):
- """MH-HOSTED-007: a new Source's first successful call retires its pending verification, which changes the
- identity evidence follows; the probe's record follows the Source as it reads after that call."""
- pending = replace(XAI, verification_pending="vp_" + "0" * 32)
+ """MH-HOSTED-007: a new Source's first successful call retires its pending verification, which changes no
+ identity; the probe's record follows the Source as it reads after that call."""
+ marker = "vp_" + "0" * 32
+ pending = replace(XAI, verification_pending=marker, credential_generation=marker)
service, _clock, _models = configured_service(tmp_path, sources=[pending])
async def respond(_request):
@@ -399,23 +400,32 @@ async def test_a_probe_that_verifies_its_source_records_evidence_for_the_source_
@pytest.mark.asyncio
-async def test_a_probe_records_no_evidence_for_a_grant_that_replaced_its_own_mid_probe(tmp_path):
- """MH-HOSTED-007: only the probe's own settlement may change the identity it vouches for. A reauthentication that
- lands mid-probe (same credential ref, a new pending marker) leaves the old grant's result without a record."""
- first, second = "vp_" + "1" * 32, "vp_" + "2" * 32
- service, _clock, _models = configured_service(tmp_path, sources=[replace(XAI, verification_pending=first)])
[email protected]("verified_after", [False, True], ids=["pending", "then-verified-by-another-call"])
+async def test_a_probe_records_no_evidence_for_a_source_reauthenticated_mid_probe(tmp_path, verified_after):
+ """MH-HOSTED-007: a reauthentication that lands mid-probe (same credential ref, a new credential generation)
+ leaves the old grant's result without a record, also once another call has verified the new grant."""
+ from core.handlers.model_hub.service import ModelHubService
+
+ first = "vp_" + "1" * 32
+ service, _clock, _models = configured_service(
+ tmp_path, sources=[replace(XAI, verification_pending=first, credential_generation=first)],
+ )
async def respond(_request):
config = service.store.load()
- config.sources[0].verification_pending = second
+ ModelHubService._mark_source_unverified(config.sources[0])
service.store.save(config)
+ if verified_after:
+ config = service.store.load()
+ config.sources[0].verification_pending = None
+ service.store.save(config)
return web.Response(body=_responses(SEARCH, ANSWER).encode(), content_type="text/event-stream")
async with loopback_engine(tmp_path, service, respond):
result = await service.probe_hosted_tool("web_search", {"source_id": XAI.id, "model_id": "grok-4.6"})
assert result["probe"]["call"]["outcome"] == "verified"
- assert service.store.load().sources[0].verification_pending == second
+ assert service.store.load().sources[0].credential_generation not in (None, first)
assert service.capability_evidence.records() == []
@@ -441,7 +451,7 @@ async def test_the_probe_reads_its_calls_in_the_order_the_adapter_sent_them():
first_may_settle.set()
status = 400 if body["n"] == 1 else 503
outcome = RawCallOutcome(RawOutcomeKind.HTTP_ERROR, status, None, None, False, "grok-4.6", XAI.id)
- return UserTestCall(XAI, outcome, 0, False)
+ return UserTestCall(XAI, outcome, 0)
transport = PinnedCallTransport(call)
async with httpx.AsyncClient(transport=transport) as client:
@@ -536,30 +546,6 @@ async def test_a_probe_that_times_out_before_its_handle_is_still_metered(tmp_pat
assert _usage_of(service, XAI.id)
-async def test_a_probe_attributes_nothing_when_another_grant_retired_the_marker(tmp_path):
- """MH-HOSTED-007: only proof that the probe's own call retired its marker lets the record follow the Source. A
- reauth mid-probe whose new marker another call then retires reads the same, and gets no record."""
- first, second = "vp_" + "3" * 32, "vp_" + "4" * 32
- service, _clock, _models = configured_service(tmp_path, sources=[replace(XAI, verification_pending=first)])
-
- async def respond(_request):
- config = service.store.load()
- config.sources[0].verification_pending = second
- service.store.save(config)
- config = service.store.load()
- config.sources[0].verification_pending = None
- service.store.save(config)
- return web.Response(body=_responses(SEARCH, ANSWER).encode(), content_type="text/event-stream")
-
- async with loopback_engine(tmp_path, service, respond):
- result = await service.probe_hosted_tool("web_search", {"source_id": XAI.id, "model_id": "grok-4.6"})
-
- assert result["probe"]["call"]["outcome"] == "verified"
- assert service.store.load().sources[0].verification_pending is None
- assert service.capability_evidence.records() == []
-
-
@pytest.mark.asyncio
async def test_a_deadline_mid_stream_ends_the_probe_as_transient(tmp_path, monkeypatch):
"""MH-HOSTED-007: only the call's own task reads its stream, so a deadline that fires while the adapter waits
diff --git a/tests/test_model_hub_retry_lifecycle.py b/tests/test_model_hub_retry_lifecycle.py
index 6db987df3..7c19a9798 100644
--- a/tests/test_model_hub_retry_lifecycle.py
+++ b/tests/test_model_hub_retry_lifecycle.py
@@ -18,7 +18,7 @@ import pytest
from config.v2_config import ModelHubConfig, ModelHubRouteConfig, ModelHubRouteHopConfig, ModelHubSourceStateConfig
from core.handlers.model_hub.adapter import RawOutcomeKind
from core.handlers.model_hub.retry import RECOVERY_EXHAUSTED_CODE, RECOVERY_EXHAUSTED_MESSAGE
-from core.handlers.model_hub.service import ModelHubError
+from core.handlers.model_hub.service import ModelHubError, ModelHubService
from core.handlers.model_hub.stream_wire import ProtocolSSEState
from core.handlers.model_hub import turn_gateway
from core.handlers.model_hub.turn_gateway import ModelHubTurnGateway
@@ -305,7 +305,7 @@ def test_recovered_disk_observation_is_exact_and_never_masks_new_authority(tmp_p
elif change == "credential":
current.credential_ref = "cred_replaced"
elif change == "verification":
- current.verification_pending = "vp_" + "1" * 32
+ ModelHubService._mark_source_unverified(current)
elif change == "endpoint":
current.base_url = "https://replacement.invalid"
elif change == "deleted":
diff --git a/tests/test_model_hub_unverified.py b/tests/test_model_hub_unverified.py
index 0f90dda4d..638d477cc 100644
--- a/tests/test_model_hub_unverified.py
+++ b/tests/test_model_hub_unverified.py
@@ -149,6 +149,37 @@ def test_only_current_successful_invocation_retires_verification(tmp_path, kind,
asyncio.run(scenario())
+def test_a_verified_reauthentication_never_returns_the_source_to_its_earlier_identity(tmp_path):
+ """MH-HOSTED-003: OAuth reauthentication can keep the credential's handle. Once a call verifies the new grant, the
+ Source still reads as a new identity, so the earlier grant's evidence, retry state and opaque payloads never
+ follow it; verifying a credential changes no identity."""
+ from core.handlers.model_hub.capability_evidence import identity_digest
+
+ service, store, _adapter = _service(tmp_path)
+
+ async def verify() -> None:
+ current = store.config.sources[0]
+ outcome = RawCallOutcome(
+ kind=RawOutcomeKind.SUCCESS, http_status=200, error_code=None, redacted_message=None,
+ stream_started=False, source_id=current.id, model_id="test-model",
+ )
+ await service._verify_successful_source(current.id, current.credential_ref, current.verification_pending, outcome)
+
+ async def scenario():
+ source = (await service.create_source(_draft()))["source"]
+ pending = identity_digest(store.config.sources[0])
+ await verify()
+ earlier = identity_digest(store.config.sources[0])
+ service._mark_source_unverified(store.config.sources[0])
+ reauthenticated = identity_digest(store.config.sources[0])
+ await verify()
+ current = store.config.sources[0]
+ assert (current.verification_pending, current.credential_ref) == (None, source["credential_ref"])
+ assert identity_digest(current) == reauthenticated != earlier == pending
+
+ asyncio.run(scenario())
+
+
@pytest.mark.parametrize("path", ["resolve", "probe", "stream"])
def test_model_call_consumers_retire_pending_verification(tmp_path, path):
service, store, adapter = _service(tmp_path)
diff --git a/ui/src/components/settings/models/SettingsModelsPage.tsx b/ui/src/components/settings/models/SettingsModelsPage.tsx
index 9fa369015..d1d9093ef 100644
--- a/ui/src/components/settings/models/SettingsModelsPage.tsx
+++ b/ui/src/components/settings/models/SettingsModelsPage.tsx
@@ -1251,7 +1251,7 @@ export const SettingsModelsPage: React.FC = () => {
const selectedSourceIdentity = selectedSource
? JSON.stringify([
selectedSource.id, selectedSource.kind, selectedSource.vendor, selectedSource.protocol, selectedSource.supply_channel,
- selectedSource.base_url ?? null, selectedSource.credential_ref ?? null, selectedSource.verification_pending ?? null,
+ selectedSource.base_url ?? null, selectedSource.credential_ref ?? null, selectedSource.credential_generation ?? null,
])
: null;
const hostedTools = useHostedTools(tab === 'tools' || selectedSource !== null, selectedSourceIdentity);
diff --git a/ui/src/components/settings/models/SourceTestDialog.test.tsx b/ui/src/components/settings/models/SourceTestDialog.test.tsx
index 81055621a..ecc8d66cc 100644
--- a/ui/src/components/settings/models/SourceTestDialog.test.tsx
+++ b/ui/src/components/settings/models/SourceTestDialog.test.tsx
@@ -19,7 +19,8 @@ const source: Source = {
id: 'src_test0001', kind: 'api_key', vendor: 'custom', display_name: 'My relay',
protocol: 'openai_chat', base_url: 'https://relay.example/v1', supply_channel: 'hub',
billing: 'metered', state: { status: 'standby', retry_at: null, detail_key: null },
- credential_ref: 'cred_test001', verification_pending: 'vp_original', last_discovered_at: null,
+ credential_ref: 'cred_test001', verification_pending: 'vp_original', credential_generation: 'vp_original',
+ last_discovered_at: null,
models: ['first-model', 'gpt-5.6-luna', 'manual-model'].map((id) => ({
id, display_name: null, origin: 'discovered', reasoning_efforts: [], reasoning_efforts_source: null,
})),
@@ -91,12 +92,15 @@ describe('SourceTestDialog', () => {
expect(screen.getByText(/responded successfully/)).toBeTruthy();
});
- it('cannot show a late success for a replacement credential', async () => {
+ it.each([
+ ['a replacement credential', { credential_ref: 'cred_new', verification_pending: 'vp_new', credential_generation: 'vp_new' }],
+ ['a verified same-handle reauthentication', { verification_pending: null, credential_generation: 'vp_new' }],
+ ])('cannot show a late success for %s', async (_name, replacement) => {
let resolve!: (result: SourceProbeResult) => void;
vi.spyOn(modelsApi, 'probeSource').mockReturnValue(new Promise((done) => { resolve = done; }));
const rendered = render(view());
await userEvent.click(screen.getByRole('button', { name: 'Run test' }));
- rendered.rerender(view({ ...source, credential_ref: 'cred_new', verification_pending: 'vp_new' }));
+ rendered.rerender(view({ ...source, ...replacement }));
resolve(answer());
await waitFor(() => expect(screen.getByRole('button', { name: 'Run test' }).hasAttribute('disabled')).toBe(false));
expect(screen.queryByText(/responded successfully/)).toBeNull();
@@ -136,11 +140,13 @@ describe('SourceTestDialog', () => {
expect(probe).toHaveBeenCalledTimes(1);
});
- it.each(['unread', 'superseded', 'deleted', 'credential', 'marker', 'base_url', 'protocol', 'model'])('requires a current matching Source after reconciliation: %s', async (change) => {
+ it.each(['unread', 'superseded', 'deleted', 'credential', 'reauth', 'verified-reauth', 'base_url', 'protocol', 'model'])('requires a current matching Source after reconciliation: %s', async (change) => {
vi.spyOn(modelsApi, 'probeSource').mockResolvedValue(answer());
const current = { ...source };
if (change === 'credential') current.credential_ref = 'cred_replacement';
- if (change === 'marker') current.verification_pending = 'vp_replacement';
+ // A same-handle reauthentication keeps the ref and mints a new generation, which verification keeps.
+ if (change === 'reauth') Object.assign(current, { verification_pending: 'vp_replacement', credential_generation: 'vp_replacement' });
+ if (change === 'verified-reauth') Object.assign(current, { verification_pending: null, credential_generation: 'vp_replacement' });
if (change === 'base_url') current.base_url = 'https://other.example/v1';
if (change === 'protocol') current.protocol = 'anthropic';
if (change === 'model') current.models = [];
@@ -174,7 +180,7 @@ describe('SourceTestDialog', () => {
const rendered = render(view());
await userEvent.click(screen.getByRole('button', { name: 'Run test' }));
await waitFor(() => expect(settlement.unread).toHaveBeenCalledTimes(1));
- rendered.rerender(view({ ...source, credential_ref: 'cred_new', verification_pending: 'vp_new' }));
+ rendered.rerender(view({ ...source, credential_ref: 'cred_new', verification_pending: 'vp_new', credential_generation: 'vp_new' }));
resolve(landing());
await waitFor(() => expect(screen.getByRole('button', { name: 'Run test' }).hasAttribute('disabled')).toBe(false));
expect(screen.queryByRole('status')).toBeNull();
diff --git a/ui/src/components/settings/models/SourceTestDialog.tsx b/ui/src/components/settings/models/SourceTestDialog.tsx
index 076b3b4d6..7d7a0beb6 100644
--- a/ui/src/components/settings/models/SourceTestDialog.tsx
+++ b/ui/src/components/settings/models/SourceTestDialog.tsx
@@ -27,19 +27,14 @@ export const SourceTestDialog: React.FC<{
const [status, setStatus] = React.useState<TestStatus>(null);
const [continuation] = React.useState(createContinuationSettlement);
const running = React.useRef(false);
- const identity = `${source.id}/${source.credential_ref}/${source.base_url}/${source.protocol}`;
+ // Every credential change, a same-handle reauthentication included, mints a new generation that verification keeps.
+ const identity = `${source.id}/${source.credential_ref}/${source.credential_generation ?? ''}/${source.base_url}/${source.protocol}`;
const selected = selectTestModel(source.models, selection);
React.useEffect(() => {
continuation.invalidate();
setStatus(null);
return () => { continuation.invalidate(); };
}, [continuation, identity, selected]);
- React.useEffect(() => {
- if (source.verification_pending) {
- continuation.invalidate();
- setStatus(null);
- }
- }, [continuation, source.verification_pending]);
const options = source.models.filter((model) => !model.retired).map((model) => ({
value: model.id, label: model.id,
}));
@@ -72,7 +67,8 @@ export const SourceTestDialog: React.FC<{
});
const matches = current && current.credential_ref === latest.credential_ref
&& current.base_url === latest.base_url && current.protocol === latest.protocol
- && (!current.verification_pending || current.verification_pending === latest.verification_pending)
+ // Every credential change mints a new generation, which verification keeps.
+ && (current.credential_generation ?? null) === (latest.credential_generation ?? null)
&& current.models.some((model) => model.id === selected && !model.retired);
// Only a verified reply lifts a cooldown, so the reconciled state, not
// `reachable`, says whether this test restored the provider.
diff --git a/ui/src/components/settings/models/types.ts b/ui/src/components/settings/models/types.ts
index 20224f752..4a3abadba 100644
--- a/ui/src/components/settings/models/types.ts
+++ b/ui/src/components/settings/models/types.ts
@@ -147,6 +147,8 @@ export type Source = {
state: SourceState;
/** Opaque pending-verification identity; presence means no successful model call yet. */
verification_pending?: string | null;
+ /** Opaque identity of the latest credential or endpoint change; kept after verification. Not for display. */
+ credential_generation?: string | null;
usage?: SourceUsage;
/** Subscription identity for the row's mono sub-line (e.g. "[email protected]").
* Never secret material; may be null. */