Skip to content

Fix VectorScoreSliceCmd to handle RESP2 flat array responses#3767

Merged
ndyakov merged 3 commits intomasterfrom
copilot/fix-vector-set-resp2-responses
Apr 9, 2026
Merged

Fix VectorScoreSliceCmd to handle RESP2 flat array responses#3767
ndyakov merged 3 commits intomasterfrom
copilot/fix-vector-set-resp2-responses

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 7, 2026

VectorScoreSliceCmd.readReply called rd.ReadMapLen() unconditionally, making VSimWithScores, VSimWithArgsWithScores, and VLinksWithScores broken on RESP2 connections, which return flat arrays instead of maps.

Changes

  • command.goVectorScoreSliceCmd.readReply: Add PeekReplyType() check before parsing. RESP3 maps use existing path; RESP2 flat arrays ([name, score, ...]) read via ReadArrayLen(), validate even length, then parse pairs sequentially — consistent with how ZSliceCmd and XStreamSliceCmd handle dual-protocol responses.

  • command.go — new constructor: Add NewVectorScoreSliceCmd as the canonical constructor; NewVectorInfoSliceCmd becomes a backwards-compatible alias.

  • vectorset_commands_test.go: Unit tests for readReply covering RESP2 array, RESP3 map, empty responses, and odd-length array error.

// RESP3 (map): %2\r\n+elem1\r\n,0.9\r\n+elem2\r\n,0.8\r\n  ✅ already worked
// RESP2 (flat array): *4\r\n$5\r\nelem1\r\n$3\r\n0.9\r\n... ✅ now works

Note

Medium Risk
Touches Redis reply parsing for vector-with-scores commands; incorrect type detection or length handling could break decoding for some server/protocol combinations, though coverage is added via targeted unit tests.

Overview
Fixes VectorScoreSliceCmd.readReply to correctly decode both RESP3 map responses and RESP2 flat array responses ([name, score, ...]), including validation for odd-length RESP2 arrays.

Introduces NewVectorScoreSliceCmd as the canonical constructor and keeps NewVectorInfoSliceCmd as a backwards-compatible alias, and adds unit tests that exercise RESP2/RESP3, empty replies, and error cases.

Reviewed by Cursor Bugbot for commit 4491630. Bugbot is set up for automated code reviews on this repo. Configure here.

Copilot AI linked an issue Apr 7, 2026 that may be closed by this pull request
@jit-ci
Copy link
Copy Markdown

jit-ci Bot commented Apr 7, 2026

🛡️ Jit Security Scan Results

CRITICAL HIGH MEDIUM

✅ No security findings were detected in this PR


Security scan by Jit

Copilot AI changed the title [WIP] Fix Vector Set commands to handle RESP2 responses Fix VectorScoreSliceCmd to handle RESP2 flat array responses Apr 7, 2026
Copilot AI requested a review from ndyakov April 7, 2026 07:50
@ndyakov ndyakov marked this pull request as ready for review April 8, 2026 12:19
@ndyakov ndyakov added the bug label Apr 9, 2026
@ndyakov ndyakov merged commit a6741de into master Apr 9, 2026
56 of 57 checks passed
@ndyakov ndyakov deleted the copilot/fix-vector-set-resp2-responses branch April 9, 2026 12:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Vector Set commands don't handle RESP2 responses.

3 participants