bug(mcp): handle malformed and partial reranker responses safely

Aperta Adatta ai principianti
#301 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 4 giorni

@KamilEjaz890 ci sta già lavorando.

Dal 18/11/2026.

  • #302 di @KamilEjaz890 — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
85/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python
Ambito
backend

Direzione di ricerca

Inizia da docs-agent-mcp/mcp-server/reranker_client.py e segui il modo in cui analizza le risposte del reranker e combina i punteggi con i risultati della ricerca. Controlla gli scenari simulati con JSON non valido e risposte parziali descritti nell’issue. Il lavoro è terminato quando gli errori preservano i risultati originali, i risultati validi con punteggio vengono ordinati per punteggio, i risultati senza punteggio mantengono il loro ordine relativo e i dizionari dei risultati non vengono modificati.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Area

mcp

What happened

The MCP reranker client does not safely handle all responses from the TEI reranking service.

There are two issues:

  1. Malformed JSON response

The response.json() call can raise a ValueError when the reranking service returns invalid JSON, such as an HTML error page.

This exception can escape the reranking function instead of gracefully falling back to the original search results.

  1. Partial reranker response

When the reranker returns scores for only some of the search hits, the current implementation combines cross-encoder scores with the original retrieval distances and sorts them together.

These values can use different score scales, such as BM25 distances and cross-encoder scores. Comparing and sorting them together can produce an incorrect ranking.

Expected behavior
  • Invalid JSON and request failures should preserve the original search results.
  • Invalid reranker entries should be ignored safely.
  • Valid scored hits should be sorted by cross-encoder score in descending order.
  • Unscored hits should retain their original relative order.
  • Original hit dictionaries should not be mutated.
  • If no valid scores are returned, the original result order should be preserved.
Reproduction

Environment

  • Repository: kubeflow/docs-agent
  • Component: MCP reranker client
  • Environment: Local development
  • Python: 3.11.9
  • Kubernetes cluster: Not required for reproducing these client-side cases.

Reproduction scenarios

Scenario 1: Malformed JSON

  1. Configure or mock the reranking HTTP request.
  2. Make the mocked reranker response contain invalid JSON, such as an HTML error page.
  3. Call the reranking function.
  4. Observe whether JSON decoding raises an exception instead of preserving the original hits.

Scenario 2: Partial reranker response

  1. Prepare multiple search hits with their original retrieval distances.
  2. Mock a reranker response that returns valid scores for only some of those hits.
  3. Call the reranking function.
  4. Observe whether scored and unscored hits are sorted together using incompatible score scales.

No live TEI service or Kubernetes cluster is required for these mocked reproduction scenarios.

Note: The issue was investigated through local code analysis. The reported test results below are from the proposed local fix; a live TEI integration reproduction has not been performed.

Suspected files

docs-agent-mcp/mcp-server/reranker_client.py

Lingua principale
Python
Stelle
49
Fork
122
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di kubeflow/docs-agent

Tutte le issue di kubeflow/docs-agent

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.