fix: guard nil map in web search context to prevent plugin crash - #935
fix: guard nil map in web search context to prevent plugin crash#935crspeller wants to merge 1 commit into
Conversation
Unmarshaling the literal JSON "null" from the web_search_context post prop succeeds and leaves the target map nil. The unconditional writes that followed panicked with "assignment to entry in nil map", crashing the plugin process and taking all AI routes offline. Any authenticated user could trigger this by DMing a bot with props.web_search_context set to "null". Guard against a nil map after unmarshaling and add a table-driven test covering null, empty-object, valid, and invalid inputs. Co-authored-by: Christopher Speller <crspeller@users.noreply.github.com>
📝 WalkthroughWalkthroughThe web search context unmarshaller now initializes nil maps before resetting tracking fields. Table-driven tests cover null, empty, valid, invalid, and non-object JSON inputs. ChangesWeb search context handling
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested labels: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
🤖 LLM Evaluation ResultsOpenAI
❌ Failed EvaluationsShow 6 failuresOPENAI1. TestConversationMentionHandling/[openai]_conversation_from_attribution_long_thread.json
2. TestConversationMentionHandling/[openai]_conversation_from_attribution_long_thread.json
3. TestConversationMentionHandling/[openai]_conversation_from_attribution_long_thread.json
4. TestConversationMentionHandling/[openai]_conversation_from_attribution_long_thread.json
5. TestConversationMentionHandling/[openai]_conversation_from_attribution_long_thread.json
6. TestDirectMessageConversations/[openai]_bot_dm_tool_introspection
Anthropic
❌ Failed EvaluationsShow 7 failuresANTHROPIC1. TestReactEval/[anthropic]_react_cat_message
2. TestConversationMentionHandling/[anthropic]_conversation_from_attribution_long_thread.json
3. TestConversationMentionHandling/[anthropic]_conversation_from_attribution_long_thread.json
4. TestConversationMentionHandling/[anthropic]_conversation_from_attribution_long_thread.json
5. TestConversationMentionHandling/[anthropic]_conversation_from_attribution_long_thread.json
6. TestConversationMentionHandling/[anthropic]_conversation_from_attribution_long_thread.json
7. TestDirectMessageConversations/[anthropic]_bot_dm_tool_introspection
This comment was automatically generated by the eval CI pipeline. |
Summary
Fixes a crash when parsing the
web_search_contextpost prop.In
conversations/web_search_context.go,unmarshalWebSearchContextunmarshals the prop value into amap[string]interface{}. For certain inputsjson.Unmarshalsucceeds but leaves the map nil, and the unconditional writes that follow then panic:Fix: guard against a nil map right after a successful unmarshal (
if params == nil { params = make(map[string]interface{}) }). This is the minimal change that addresses the root cause — the subsequent writes are now always safe regardless of the prop value.Added a table-driven test (
TestUnmarshalWebSearchContext) covering the nil-map case, empty object, a valid context payload, invalid JSON, and non-object JSON.QA / proof:
Before the fix, the parsing path panicked at
web_search_context.go:100(assignment to entry in nil map). After the fix, all cases pass:Full
conversationspackage tests,go vet, andgolangci-lintall pass.Ticket Link
Release Note
Summary by CodeRabbit
Bug Fixes
null.Tests
null, invalid, and non-object context values.