fix(core): Cohere and Voyage rerankers bypass non-positive limit check on NaN topN and send invalid null payload
Maintainer thường phản hồi trong vòng 1 ngày
@bhushan4work đang làm issue này rồi.
Từ ngày 3/11/2026.
Đánh giá
Issue này chưa được đánh giá.
Mô tả
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
- Ngôn ngữ chính
- TypeScript
- Star
- 13
- Fork
- 7
- Merge trung bình
- 3 giờ 11 phút
- Pull request đã merge (30 ngày)
- 330
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của codercops/chatcops
-
Ingest: a crawl source for sites without a sitemapCó thể đã có người làm @bhushan4work đã nhận hôm nay. Đang mởenhancement
codercops/chatcops#586 · 1 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Widget: a code block tagged `c++`, `c#` or `objective-c` shows part of the tag as codeCó thể đã có người làm @prakashNalla đã nhận 2 ngày trước. Đang mởbug widget
codercops/chatcops#578 · 2 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Docs: Astro, Nuxt and SvelteKit guides for the serverCó thể đã có người làm @anurag2787 đã nhận 2 ngày trước. Đang mởdocumentation
codercops/chatcops#575 · 2 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Server: chatcopsNext(), one catch-all route for Next.jsCó thể đã có người làm @Saifjafri212213 đã nhận 2 ngày trước. Đang mởenhancement server
codercops/chatcops#574 · 2 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
@chatcops/react: a <ChatCops> component and useChatCops() hookCó thể đã có người làm @Saifjafri212213 đã nhận 2 ngày trước. Đang mởenhancement widget
codercops/chatcops#573 · 2 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của codercops/chatcops
Issue tương tự
-
needs-area-label
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
Maintainer thường phản hồi trong vòng 2 ngày
-
Website: the hero tip's video play() has no catch, so a refused play is an unhandled rejectionĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
liberation-data/drivine#615 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
backend bug ready-for-agent
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
geolens-io/geolens#3639 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
radius-project/ai-extensions#1196 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
good first issue
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 88/100