fix(core): Cohere and Voyage rerankers bypass non-positive limit check on NaN topN and send invalid null payload
维护者通常 1 天内回复
@bhushan4work 已经在做这个了。
开始于 2026年11月3日。
评估
这个 Issue 还没有评估数据。
描述
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
- 主要语言
- TypeScript
- 星标
- 13
- 派生
- 7
- 平均合并
- 3 小时 11 分钟
- 30 天内合并 PR
- 330
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
codercops/chatcops 的其他 Issue
-
Ingest: a crawl source for sites without a sitemap可能已有人在做 @bhushan4work 今天认领。 未关闭enhancement
codercops/chatcops#586 · 1 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
-
Widget: a code block tagged `c++`, `c#` or `objective-c` shows part of the tag as code可能已有人在做 @prakashNalla 于 2 天前认领。 未关闭bug widget
codercops/chatcops#578 · 2 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
-
Docs: Astro, Nuxt and SvelteKit guides for the server可能已有人在做 @anurag2787 于 3 天前认领。 未关闭documentation
codercops/chatcops#575 · 2 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
-
Server: chatcopsNext(), one catch-all route for Next.js可能已有人在做 @Saifjafri212213 于 2 天前认领。 未关闭enhancement server
codercops/chatcops#574 · 2 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
-
@chatcops/react: a <ChatCops> component and useChatCops() hook可能已有人在做 @Saifjafri212213 于 2 天前认领。 未关闭enhancement widget
codercops/chatcops#573 · 2 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
查看 codercops/chatcops 的全部 Issue
相似的 Issue
-
[fullsend] E2E: scorecard — filecheck GitLab entity metrics unavailable due to initialDelay timing未关闭e2e-failure ready-to-code
难度 2/5 1-3 小时 新手友好度 75/100
redhat-developer/rhdh-plugin-export-overlays#4698 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 88/100
devswha/herdr-web-ui#2884 ·
-
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
b:minor bug
难度 2/5 1-3 小时 新手友好度 78/100
software-mansion/argent#1771 ·
维护者通常 1 天内回复
-
Resources: New palettes of Xiamen可能已有人在做 @rmt-svc 今天认领。 未关闭resources
难度 1/5 1-3 小时 新手友好度 74/100
railmapgen/rmg-palette#2491 ·
维护者通常 4 天内回复