Skip to content

[feat](bot):Add mode config, add debug mode, add /remember cmd#757

Open
yeshion23333 wants to merge 7 commits intomainfrom
feature/bot_debuge_mode
Open

[feat](bot):Add mode config, add debug mode, add /remember cmd#757
yeshion23333 wants to merge 7 commits intomainfrom
feature/bot_debuge_mode

Conversation

@yeshion23333
Copy link
Collaborator

@yeshion23333 yeshion23333 commented Mar 19, 2026

Description

Fix

  • 修复Error时发送的消息,meta信息缺失导致的报错;

Add

  • 新增mode配置,替换之前的readonly。现在支持三种模式
    • normal:正常的模式,开启ov add resource tool,所有user都可以提交agent memory
    • readonly:只读,关闭上传资源功能,agent memory仅配置的白名单用户可更新
    • debug:调试模式,不进行任何的消息处理,只收集消息到session中
  • 新增指令:/remember,提交对话到Viking
  • cmd权限控制:非normal模式,仅channel内配置的allow form可执行指令

Opt

  • 调整ov hook,将消息过滤逻辑上移置调用处,如loop循环时;
  • 调整feishu channel 消息机器人判断逻辑,改为使用 name。兼容 open id获取不到的情况

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

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Potential AttributeError

The condition for checking channels_config uses 'and' which will attempt to call get_all_channels() even if channels_config is None, causing an AttributeError.

if not config.channels_config and not config.channels_config.get_all_channels():
Possible Missing Attribute Check

Accessing channel_config.allow_from without checking if the attribute exists may cause AttributeError for channel configs that don't define allow_from.

if not channel_config or msg.sender_id not in channel_config.allow_from:
Redundant Config Load

Loading config again with load_config() is redundant since self.config is already available in the AgentLoop instance.

config = load_config()

@github-actions
Copy link

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
Possible issue
Fix invalid condition check in memory consolidation

Fix the invalid condition check that could cause an AttributeError. The current code
attempts to call get_all_channels() even when config.channels_config is falsy. Also,
use the existing self.config attribute instead of reloading the config.

bot/vikingbot/agent/loop.py [596-606]

-config = load_config()
-if config.mode == BotMode.READONLY:
-    if not config.channels_config and not config.channels_config.get_all_channels():
+if self.config.mode == BotMode.READONLY:
+    if not self.config.channels_config or not self.config.channels_config.get_all_channels():
         return
-    allow_from = [config.ov_server.admin_user_id]
-    for channel_config in config.channels_config.get_all_channels():
+    allow_from = [self.config.ov_server.admin_user_id]
+    for channel_config in self.config.channels_config.get_all_channels():
         if channel_config and channel_config.type.value == session.key.type:
             if hasattr(channel_config, "allow_from"):
                 allow_from.extend(channel_config.allow_from)
     messages = [msg for msg in session.messages if msg.get("sender_id") in allow_from]
     session.messages = messages
Suggestion importance[1-10]: 7

__

Why: The suggestion fixes a potential AttributeError by using or instead of and in the condition check, and avoids reloading the config by using self.config, improving efficiency and correctness.

Medium

Copy link
Collaborator

@qin-ctx qin-ctx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review 完成,发现 2 个需要修复的 bug 和若干建议。详见 inline comments。

@qin-ctx qin-ctx removed the request for review from MaojiaSheng March 19, 2026 03:36
@chenjw
Copy link
Collaborator

chenjw commented Mar 19, 2026

/remember和/new的区别是? 这块既然改了,我觉得要不我们和openclaw的 /new /compact /reset的定义和命名完全对齐?

Copy link
Contributor

@qin-ptr qin-ptr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review 完成,发现 6 个必须修复的问题和若干建议。

核心问题总结

  1. 逻辑错误: loop.py:598 条件判断使用 and 应该用 or
  2. 多余调用: loop.py:477 重复调用 get_or_create
  3. 设计问题: loop.py:606 直接修改 session.messages 导致本地记忆受影响
  4. 权限不一致: loop.py:726 未包含 admin_user_id
  5. 破坏性变更: schema.py:114 将 open_id 改为 bot_name 缺少迁移路径
  6. 检测逻辑不完整: feishu.py:757 删除了 open_id 检查可能导致检测失败

详见 inline comments。

🤖 I am a bot owned by @qin-ctx.

@yeshion23333
Copy link
Collaborator Author

/remember和/new的区别是? 这块既然改了,我觉得要不我们和openclaw的 /new /compact /reset的定义和命名完全对齐?

调整成/compact了:和/new的区别是只提交一次当前对话到 Openviking,不清空 session

@yeshion23333
Copy link
Collaborator Author

Review 完成,发现 2 个需要修复的 bug 和若干建议。详见 inline comments。

已修复

@yeshion23333 yeshion23333 requested a review from qin-ctx March 19, 2026 06:29
@yeshion23333 yeshion23333 changed the title [feat](bot):Add mode config, add debug mode, add /remember cmd [feat](bot):Add mode config, add debug mode, add /compact cmd Mar 19, 2026
@yeshion23333 yeshion23333 changed the title [feat](bot):Add mode config, add debug mode, add /compact cmd [feat](bot):Add mode config, add debug mode, add /remember cmd Mar 19, 2026
@yeshion23333 yeshion23333 requested a review from qin-ptr March 19, 2026 06:41
Copy link
Collaborator

@qin-ctx qin-ctx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

存在 1 个需要修复的问题,详见 inline comment。

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.

4 participants