You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
vmcp optimizer: tool catalog is embedded in non-deterministic order across aggregations #5702
The optimizer embeds the aggregated tool catalog in a non-deterministic order. MergeCapabilities builds the tool slice by ranging resolved.Tools (a map[string]*ResolvedTool) with no sort, and generateEmbeddings embeds in that slice order. Go randomizes map iteration, so each fresh aggregation produces a different order; the 30s capability cache only holds it steady within a window.
tools/list is not affected — the advertised list comes out sorted, so the reordering is invisible to clients and surfaces only in the embedding batch.
Same class as #3448, which fixed non-deterministic config.Backends order by sorting in the Discoverer (#3450). That covered backend order, not the tools inside the aggregation.
Steps to reproduce
Run a VirtualMCPServer with the optimizer enabled and embeddingProvider: openai pointed at an embedding endpoint whose request logs you can inspect.
Open several sessions spread over time, or restart the pod between them, so the capability cache re-aggregates.
Inspect the /embeddings request bodies: the order of tool texts in the input array changes between aggregations.
Observed on my gateway from the embedding backend's request logs: across 23 embedding requests, 15 distinct orderings — requests inside one capability-cache window share an order, requests in different windows differ from the first element.
Expected behavior
The same set of tools produces the same embedding-batch order every time.
Actual behavior
The order varies per aggregation. An order-sensitive cache in front of the embedding endpoint sees a new request hash each window and misses.
Environment (if relevant)
ToolHive version: v0.33.0
Additional context
Fix mirrors #3450: sort the tool slice deterministically (resolved name, or workload+name) before embedding. Happy to PR.
@gabrielcosi happy to review a PR or assign this to you, seems like the issue sounds "easy enough" to openclaws otherwise so we are already getting PR spam.
Activity
jhrozek commentedon Jul 2, 2026
@gabrielcosi happy to review a PR or assign this to you, seems like the issue sounds "easy enough" to openclaws otherwise so we are already getting PR spam.
gabrielcosi commentedon Jul 2, 2026
@jhrozek I opened a PR, thanks!
Sort aggregated tools by name for deterministic embedding order (stac…