fix(im): return partial mget results in messages search instead of all-or-nothing#1366
fix(im): return partial mget results in messages search instead of all-or-nothing#1366nguyenngothuong wants to merge 1 commit into
Conversation
…l-or-nothing Previously batchMGetMessages in +messages-search returned an error when any single batch failed, causing the entire result set to be discarded and replaced with a bare message_id list. Change to best-effort: continue on batch failure so successfully fetched batches are still returned. When all batches fail, the existing fallback (message_id list) still applies. This matches the pattern already used by batchQueryChatContexts and the contact resolution functions.
📝 WalkthroughWalkthroughMessage enrichment now treats mget API calls as best-effort. Failed batch requests are skipped rather than aborting the entire step, and the Step 2 caller uses empty message item results to detect the fallback path. A new test validates transient mget failures are retried and partial results are produced. ChangesBest-effort IM message enrichment
🎯 2 (Simple) | ⏱️ ~10 minutes
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
shortcuts/im/im_messages_search_execute_test.go (1)
305-306: ⚡ Quick winCheck errors for consistency with other tests in this file.
Lines 107-113 and 200-206 use
t.Fatalfto checkio.ReadAllandjson.Unmarshalerrors. Follow that pattern here for robustness and consistency.♻️ Proposed fix
case strings.Contains(req.URL.Path, "/open-apis/im/v1/chats/batch_query"): var body struct { ChatIDs []string `json:"chat_ids"` } - rawBody, _ := io.ReadAll(req.Body) - json.Unmarshal(rawBody, &body) + rawBody, err := io.ReadAll(req.Body) + if err != nil { + t.Fatalf("ReadAll() error = %v", err) + } + if err := json.Unmarshal(rawBody, &body); err != nil { + t.Fatalf("json.Unmarshal() error = %v", err) + } return shortcutJSONResponse(200, map[string]interface{}{🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@shortcuts/im/im_messages_search_execute_test.go` around lines 305 - 306, Replace the unchecked error handling for io.ReadAll and json.Unmarshal with the same t.Fatalf pattern used elsewhere in this test file: capture the error returned by io.ReadAll(req.Body) into a variable and call t.Fatalf(...) if err != nil, and likewise check the error returned by json.Unmarshal(rawBody, &body) and call t.Fatalf(...) on error; reference the existing variables rawBody, req.Body and the json.Unmarshal call so the change matches the style of the other checks in this file.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@shortcuts/im/im_messages_search_execute_test.go`:
- Around line 305-306: Replace the unchecked error handling for io.ReadAll and
json.Unmarshal with the same t.Fatalf pattern used elsewhere in this test file:
capture the error returned by io.ReadAll(req.Body) into a variable and call
t.Fatalf(...) if err != nil, and likewise check the error returned by
json.Unmarshal(rawBody, &body) and call t.Fatalf(...) on error; reference the
existing variables rawBody, req.Body and the json.Unmarshal call so the change
matches the style of the other checks in this file.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 724a586e-e5db-4501-9d6d-51081abba3c8
📒 Files selected for processing (2)
shortcuts/im/im_messages_search.goshortcuts/im/im_messages_search_execute_test.go
Problem
In
+messages-search, when the batch mget step fails for any single chunk, all message details are discarded and replaced with a baremessage_idslist. AI agents lose all message content, sender names, and timestamps.Root Cause
batchMGetMessages()inshortcuts/im/im_messages_search.goreturnsnil, erron the first batch failure, and the caller falls back to ID-only output.With 55 search results split into 2 mget batches (50 + 5), a transient failure on batch 1 loses all 55 messages even though batch 2 would succeed.
Fix
Change
batchMGetMessagesto best-effort:continueon batch failure instead ofreturn nil, errAlso simplified the function signature from
([]interface{}, error)to[]interface{since errors are no longer propagated.Testing
TestImMessagesSearchMgetPartialResults— 55 IDs in 2 batches, first fails, second succeeds, verifies 5 partial results returnedgo vetcleangofmtcleanSummary by CodeRabbit