Skip to content

fix(bot): Limit grep\glob\search tool's user scope, grep use one pattern, Optimize client initialization.#2240

Open
yeshion23333 wants to merge 4 commits into
mainfrom
fix_bot
Open

fix(bot): Limit grep\glob\search tool's user scope, grep use one pattern, Optimize client initialization.#2240
yeshion23333 wants to merge 4 commits into
mainfrom
fix_bot

Conversation

@yeshion23333
Copy link
Copy Markdown
Collaborator

@yeshion23333 yeshion23333 commented May 26, 2026

Description

  1. grep、glob、search tool,使用当前admin User 进行ov检索;
  2. 优化 Openviking client的初始化逻辑;
  3. 去除grep的多pattern 并发检索逻辑,一次只查询一个;
  4. 优化 工具提示词

Related Issue

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional changes)
  • Performance improvement
  • Test update

Changes Made

Testing

  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have tested this on the following platforms:
    • Linux
    • macOS
    • Windows

Checklist

  • My code follows the project's coding style
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

Screenshots (if applicable)

Additional Notes

@github-actions
Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🏅 Score: 85
🧪 No relevant tests
🔒 No security concerns identified
✅ No TODO sections
🔀 Multiple PR themes

Sub-PR theme: Optimize OpenViking client initialization and add user-scoped clients

Relevant files:

  • bot/vikingbot/openviking_mount/ov_server.py

Sub-PR theme: Limit grep/glob/search tools to admin user scope

Relevant files:

  • bot/vikingbot/agent/tools/ov_file.py

⚡ Recommended focus areas for review

Missing Memory Type Filtering

The openviking_search tool no longer filters results to only include "memory" type items when using tool_context.memory_user_ids. This may return non-memory resources in results, changing previous behavior.

if not target_uri and tool_context.memory_user_ids:
    user_uri = client._memory_target_uri(admin_user_id)
    results = await client.search(
        query,
        target_uri=user_uri,
        limit=20,
        user_id=admin_user_id,
    )

    if not results:
        return f"No results found for query: {query}"

    grouped_items = self._filter_search_items(results, min_score=min_score)
    total = sum(len(items) for items in grouped_items.values())
    if total == 0:
        return f"No results found for query: {query}"
    return self._format_search_items_json(grouped_items, min_score=min_score)

@github-actions
Copy link
Copy Markdown

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
Possible issue
Restore memory search filtering logic

Restore the memory-type filtering and extraction of search items that was present in
the original code, and add back the user key mode check. This ensures only memory
items are included when searching user memories, which matches the original
behavior.

bot/vikingbot/agent/tools/ov_file.py [253-267]

 admin_user_id = client.admin_user_id
 
 if not target_uri and tool_context.memory_user_ids:
-    user_uri = client._memory_target_uri(admin_user_id)
+    if client._is_user_key_mode():
+        user_uri = client._memory_target_uri(None)
+        user_id = None
+    else:
+        user_uri = client._memory_target_uri(admin_user_id)
+        user_id = admin_user_id
+    
+    logger.info(f"openviking_search: searching {user_uri} for query: {query}")
     results = await client.search(
         query,
         target_uri=user_uri,
         limit=20,
-        user_id=admin_user_id,
+        user_id=user_id,
     )
 
     if not results:
         return f"No results found for query: {query}"
 
-    grouped_items = self._filter_search_items(results, min_score=min_score)
+    extracted_items = self._extract_search_items(results)
+    memories = [
+        item
+        for item in extracted_items
+        if item.get("type") == "memory"
+    ]
+    grouped_items = self._filter_search_items(memories, min_score=min_score)
Suggestion importance[1-10]: 7

__

Why: The suggestion correctly restores original behavior: memory-type filtering via _extract_search_items, user key mode check, and logging, which were removed in the PR. This addresses a potential functional regression in user memory search results.

Medium

@yeshion23333 yeshion23333 changed the title fix(bot): Limit grep\glob\search tool's user scope, Optimize client initialization. fix(bot): Limit grep\glob\search tool's user scope, grep use one pattern, Optimize client initialization. May 26, 2026
@yeshion23333 yeshion23333 requested review from chenjw and qin-ctx May 26, 2026 09:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

1 participant