fix(core): Cohere and Voyage rerankers bypass non-positive limit check on NaN topN and send invalid null payload
Les mainteneurs répondent en général sous 1 jour
Évaluation
Cette issue n'a pas encore été évaluée.
Description
Which part?
@chatcops/core
Package version
No response
What happened?
Problem
In both cohereReranker and voyageReranker, candidate reranking enforces the requested limit using:
const limit = Math.floor(topN);
if (chunks.length === 0 || limit <= 0) return [];
If topN evaluates to NaN (such as when parsing unvalidated query/input parameters into retrieval plans), Math.floor(NaN) evaluates to NaN. In JavaScript /
IEEE 754 arithmetic, relational comparisons with NaN (NaN <= 0) always evaluate to false.
Consequently, the early return check is bypassed:
- Math.min(limit, chunks.length) calculates Math.min(NaN, chunks.length), which returns NaN.
- When serialized for outbound HTTP calls, JSON.stringify converts NaN to null:
• Cohere receives: {"top_n": null}
• Voyage receives: {"top_k": null} - Both Cohere and Voyage AI endpoints reject null values with HTTP 400 Bad Request (e.g. invalid request: top_n must be a positive integer), triggering an
unhandled provider error in postWithRetries that aborts the chat/retrieval turn.
By contrast, workersAiReranker correctly protects against this:
const requestedLimit = Number.isFinite(topN) && topN > 0 ? Math.floor(topN) : 0;
if (!requestedLimit || !chunks.length) return [];
Actual Behavior
• Actual Behavior: Calling rerank(query, chunks, NaN) bypasses the non-positive limit guard, triggers an outbound HTTP request with top_n: null or top_k:
null, and fails with HTTP 400 Bad Request.
Impact
• Any unvalidated or non-numeric topK / topN value passed directly to rerankers or computed via plan() results in an unnecessary outbound API call that fails
with an unhandled HTTP 400 error.
• Causes behavioral inconsistency across @chatcops/core rerankers (workersAiReranker returns [], while cohereReranker and voyageReranker fail with provider
errors).
Acceptance Criteria
• cohereReranker and voyageReranker validate that topN is a positive finite number (e.g., using Number.isFinite(topN) && topN > 0) before making outbound
requests.
• Invoking rerank with NaN or non-finite topN returns [] immediately without sending network requests.
• Test suites in cohere-reranker.test.ts and voyage-reranker.test.ts include assertions for non-finite topN values.
What did you expect?
• Expected Behavior: Calling rerank(query, chunks, NaN) should recognize non-finite / invalid counts, return [] immediately, and avoid making unnecessary
outbound API calls.
How can we reproduce it?
1. Initialize a reranker instance:
const reranker = cohereReranker({ apiKey: 'dummy-key', fetch: mockFetch });
2. Call rerank with non-empty chunks and NaN:
await reranker.rerank('query', [{ id: '1', text: 'chunk' }], NaN);
3. Inspect mockFetch: instead of returning [] without dispatching a network call (like topN = 0 does), a request is dispatched with body:
{ "model": "rerank-v5.0-pro", "query": "query", "documents": ["chunk"], "top_n": null }
Environment
No response
- Langage dominant
- TypeScript
- Étoiles
- 13
- Forks
- 7
- Merge moyen
- 3 h 14 min
- PR mergées (30 j)
- 332
Préparer son environnement
- Aucun Dockerfile ni fichier Docker Compose
- Propose un modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de codercops/chatcops
-
Ingest: a crawl source for sites without a sitemapPeut-être pris @bhushan4work l’a pris il y a 2 jours. Ouverteenhancement
codercops/chatcops#586 · 1 commentaire · 1 personne assignée ·
Les mainteneurs répondent en général sous 1 jour
-
Widget: a code block tagged `c++`, `c#` or `objective-c` shows part of the tag as codePeut-être pris @prakashNalla l’a pris il y a 4 jours. Ouvertebug widget
codercops/chatcops#578 · 2 commentaires · 1 personne assignée ·
Les mainteneurs répondent en général sous 1 jour
-
Docs: Astro, Nuxt and SvelteKit guides for the serverPeut-être pris @anurag2787 l’a pris il y a 4 jours. Ouvertedocumentation
codercops/chatcops#575 · 2 commentaires · 1 personne assignée ·
Les mainteneurs répondent en général sous 1 jour
-
Server: chatcopsNext(), one catch-all route for Next.jsPeut-être pris @Saifjafri212213 l’a pris il y a 4 jours. Ouverteenhancement server
codercops/chatcops#574 · 2 commentaires · 1 personne assignée ·
Les mainteneurs répondent en général sous 1 jour
-
@chatcops/react: a <ChatCops> component and useChatCops() hookPeut-être pris @Saifjafri212213 l’a pris il y a 4 jours. Ouverteenhancement widget
codercops/chatcops#573 · 2 commentaires · 1 personne assignée ·
Les mainteneurs répondent en général sous 1 jour
Toutes les issues de codercops/chatcops
Issues similaires
-
The sample email preview's ResizeObserver is never disconnected and keeps raising errors after leaving SettingsPeut-être pris Une pull request liée à cette issue est ouverte ou déjà fusionnée. Ouvertebug
Difficulté 2/5 1-3 heures Accessibilité débutants 82/100
Les mainteneurs répondent en général sous 1 jour
-
area:ui bug effort:S priority:P2
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
Les mainteneurs répondent en général sous 1 jour
-
Typo in WSL project description on Projects pagePeut-être pris @akhil9tiet l’a pris aujourd’hui. Ouverte
Difficulté 1/5 Moins d'une heure Accessibilité débutants 75/100
microsoft/opensource.microsoft.com#1066 · 1 commentaire ·
-
ArcGIS Maps SDK for JavaScript c-carousel calcite-design-tokens enhancement impact - p3 - not time sensitive needs triage
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
Esri/calcite-design-system#15565 ·
Les mainteneurs répondent en général sous 1 jour
-
bug
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
linkwarden/linkwarden#1891 ·
Les mainteneurs répondent en général sous 1 jour