fix(core): Cohere and Voyage rerankers bypass non-positive limit check on NaN topN and send invalid null payload
Maintainer antworten meist innerhalb von 1 Tag
Bewertung
Dieses Issue wurde noch nicht bewertet.
Beschreibung
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
- Vorherrschende Sprache
- TypeScript
- Sterne
- 13
- Forks
- 7
- Ø Merge
- 3 Std. 14 Min.
- Gemergte PRs (30 T.)
- 332
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus codercops/chatcops
-
Ingest: a crawl source for sites without a sitemapEvtl. vergeben @bhushan4work hat das vor 2 Tagen übernommen. Offenenhancement
codercops/chatcops#586 · 1 Kommentar · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 1 Tag
-
Widget: a code block tagged `c++`, `c#` or `objective-c` shows part of the tag as codeEvtl. vergeben @prakashNalla hat das vor 4 Tagen übernommen. Offenbug widget
codercops/chatcops#578 · 2 Kommentare · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 1 Tag
-
Docs: Astro, Nuxt and SvelteKit guides for the serverEvtl. vergeben @anurag2787 hat das vor 4 Tagen übernommen. Offendocumentation
codercops/chatcops#575 · 2 Kommentare · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 1 Tag
-
Server: chatcopsNext(), one catch-all route for Next.jsEvtl. vergeben @Saifjafri212213 hat das vor 4 Tagen übernommen. Offenenhancement server
codercops/chatcops#574 · 2 Kommentare · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 1 Tag
-
@chatcops/react: a <ChatCops> component and useChatCops() hookEvtl. vergeben @Saifjafri212213 hat das vor 4 Tagen übernommen. Offenenhancement widget
codercops/chatcops#573 · 2 Kommentare · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in codercops/chatcops
Ähnliche Issues
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
Yeraze/meshmonitor#6239 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
better-auth/better-auth#12292 · 1 Reaktion ·
Maintainer antworten meist innerhalb von 1 Tag
-
The sample email preview's ResizeObserver is never disconnected and keeps raising errors after leaving SettingsEvtl. vergeben Ein verknüpfter Pull Request ist offen oder bereits gemergt. Offenbug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
Maintainer antworten meist innerhalb von 1 Tag
-
area:ui bug effort:S priority:P2
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
Maintainer antworten meist innerhalb von 1 Tag
-
Typo in WSL project description on Projects pageEvtl. vergeben @akhil9tiet hat das heute übernommen. Offen
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 75/100
microsoft/opensource.microsoft.com#1066 · 1 Kommentar ·