Skip to content

Operator rewrites MCPServer status on every reconcile when externalAuthConfigRef is healthy (ExternalAuthConfigValidated lastTransitionTime flaps) #7161

Done

Description

@im-jari-niskala

Bug description

For every MCPServer that references a healthy MCPExternalAuthConfig through spec.externalAuthConfigRef, the operator writes the MCPServer's status on every reconcile, and each write triggers the next reconcile. The only field that changes is lastTransitionTime of the ExternalAuthConfigValidated condition, which stays True / ExternalAuthConfigValid throughout.

Cause

mirrorInvalidOnMCPServer in cmd/thv-operator/controllers/external_auth_mirror.go runs on every reconcile from handleExternalAuthConfig. When the referenced MCPExternalAuthConfig is healthy (mirroredExternalAuthConfigInvalid returns nil), it removes the consumer's ExternalAuthConfigValidated condition unless ownedByLocalValidation is true, and that function only recognises the reasons InvalidConfig and InvalidCABundle:

if mirrored == nil {
    if !ownedByLocalValidation(m.Status.Conditions, mcpv1beta1.ConditionTypeExternalAuthConfigValidated) {
        meta.RemoveStatusCondition(&m.Status.Conditions, mcpv1beta1.ConditionTypeExternalAuthConfigValidated)
    }
    return false, nil
}

The healthy condition (True, ExternalAuthConfigValid) is therefore removed too. A few lines later setMCPServerExternalAuthConfigValidCondition sets it again. Because the condition is absent at that point, meta.SetStatusCondition stamps a new LastTransitionTime. updateMCPServerStatus then persists the status, the object's resourceVersion changes, and the For(&MCPServer{}) watch enqueues the MCPServer again. Controllers that watch MCPServers, such as the MCPGroup controller, are triggered by every write too.

mirrorInvalidOnRemoteProxy has the same code for MCPRemoteProxy and ConditionTypeMCPRemoteProxyExternalAuthConfigValidated. The single-upstream check (MultiUpstreamNotSupported, a False condition written after the mirror runs) flaps the same way, because ownedByLocalValidation does not recognise it either.

VirtualMCPServer is not affected: it calls mirroredExternalAuthConfigInvalid only to build errors, and its status collector keeps one entry per condition type, so a remove followed by a set collapses into a set.

The code is unchanged from v0.57.0 through v0.66.0 and on main.

Steps to reproduce

  1. Create an MCPExternalAuthConfig of any type that validates (for example type: unauthenticated).
  2. Create an MCPServer with spec.externalAuthConfigRef pointing at it, and let it become Ready.
  3. Read metadata.resourceVersion and the ExternalAuthConfigValidated condition twice, 30 seconds apart:
    kubectl get mcpserver <name> -o jsonpath='{.metadata.resourceVersion} {.status.conditions[?(@.type=="ExternalAuthConfigValidated")].lastTransitionTime}{"\n"}'

Expected behavior

Once the MCPServer is Ready and nothing changes, its resourceVersion and the condition's lastTransitionTime stay the same.

Actual behavior

Both change every few seconds. In one namespace with 14 MCPServers that all reference healthy configs (v0.57.0):

  • all 14 MCPServers changed resourceVersion within 30 seconds, and a diff of two snapshots showed only ExternalAuthConfigValidated.lastTransitionTime changing;
  • the operator logged about 1,600–2,000 lines a minute, almost all Reconciling MCPGroup / Successfully reconciled MCPGroup;
  • the operator used 300–550m CPU against a 10m request.

On that cluster the churn ran continuously for about 20 hours, from the operator's start after an upgrade until it was replaced. On a second cluster with the same setup, an operator that was restarted with nothing else changing stayed quiet for over two hours, so there may be a further condition that keeps the cycle going which we have not identified. The condition rewrite itself is visible in the code above and is covered by the unit tests in the linked PR.

Environment

  • ToolHive operator v0.57.0 (the code path is identical in v0.63.0, v0.66.0 and main)
  • Namespace-scoped install via the toolhive-operator Helm chart, GKE

Additional context

A fix with regression tests is in #7162.

Activity

  1. added
    needs-triage
    on Nov 17, 2026
  2. removed
    needs-triage
    on Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions