Skip to content

fix(zulip): 增加内容检测fallback解决Generic bot收不到mention flag问题#484

Merged
pancacake merged 1 commit into
HKUDS:devfrom
wedone:fix/zulip-upload-and-send
May 29, 2026
Merged

fix(zulip): 增加内容检测fallback解决Generic bot收不到mention flag问题#484
pancacake merged 1 commit into
HKUDS:devfrom
wedone:fix/zulip-upload-and-send

Conversation

@wedone

@wedone wedone commented May 14, 2026

Copy link
Copy Markdown
Contributor

Description

背景说明:

PR #480 中声称实现了 Zulip channel 响应 @mention 的功能。该 PR 通过 _is_mentioned() 检查 flags 中的 mention 标志来判断 bot 是否被 @。

然而实际部署测试发现,该实现未能正常工作——在频道中 @bot 无响应。根因如下:

Zulip 官方文档说明:

An outgoing webhook bot can read direct messages where the bot is a participant, and channel messages where the bot is mentioned. When the bot is DM'd or mentioned, it POSTs the message content to a URL of your choice.

这意味着要响应频道中的 @mention,官方推荐的方式是使用 Outgoing webhook bot,并且需要搭配 Zulip Botserver来接收 POST 请求。

而 DeepTutor 的 Zulip channel 使用的是 Generic bot + Event Queue API 架构。实际测试发现:使用 Generic bot 时,Zulip 服务端返回的事件 flags 字段为空数组,导致 _is_mentioned() 方法无法检测到 @mention。

修复方案:

_is_mentioned() 方法中增加内容检测 fallback 机制:

  1. 首先检查 flags 中的 mention 标志(mentionedwildcard_mentionedstream_wildcard_mentionedtopic_wildcard_mentioned
  2. 如果 flags 中没有 mention 标志,则扫描消息内容是否包含 @**机器人全名** 模式
  3. 如果匹配到 @mention 模式,则认为 bot 被提及

优势:

  • 无需引入 Outgoing webhook bot 和 Zulip Botserver
  • 仅需修改少量代码即可实现 Generic bot 响应频道 @mention 的功能

Related Issues

  • Closes #...
  • Related to #...

Module(s) Affected

  • agents
  • api
  • config
  • core
  • knowledge
  • logging
  • services (tutorbot channels)
  • tools
  • utils
  • web (Frontend)
  • docs (Documentation)
  • scripts
  • tests

Checklist

  • I have read and followed the contribution guidelines.
  • My code follows the project's coding standards.
  • I have run pre-commit run --all-files and fixed any issues.
  • I have added relevant tests for my changes.
  • I have updated the documentation (if necessary).
  • My changes do not introduce any new security vulnerabilities.

Additional Notes

测试验证:

已通过容器部署验证:

DEBUG   Zulip _is_mentioned: detected via content match, pattern=@**test**
INFO    Processing message from zulip:...: **[频道名 > 主题]** @**test** 测试

Bot 成功响应频道中的 @mention 并回复消息。

新增测试用例:

  • test_content_mention_fallback: 验证内容检测 fallback 基本功能
  • test_content_mention_not_at_start: 验证 @mention 不在消息开头时也能检测
  • test_content_mention_no_match_partial: 验证部分名称匹配不会误触发
  • test_content_mention_empty_full_name: 验证 bot 全名为空时跳过检测
  • test_flags_take_precedence_over_content: 验证 flags 检测优先级高于内容检测

@wedone
wedone force-pushed the fix/zulip-upload-and-send branch from f52778d to 69bf9f6 Compare May 17, 2026 01:24
@pancacake
pancacake merged commit e5846fe into HKUDS:dev May 29, 2026
8 of 18 checks passed
@pancacake

Copy link
Copy Markdown
Collaborator

Thanks for your contribution!

pancacake added a commit that referenced this pull request Jun 11, 2026
#493 (sqlite): route _initialize() through the _connect() contextmanager
(the one remaining raw sqlite3.connect FD leak); document the auto-commit
contract so the redundant explicit commits are understood.

#529 (book):
- _strip_thinking_preamble: guard `{ not in text` before rindex() so plain
  prose (refusals/errors) no longer raises ValueError -> ERROR block;
  hoist json import to module top.
- llm_json: honor caller max_tokens as max(max_tokens, 2600) instead of
  discarding it; bump default to 2600; fix stale 'minimal' docstring -> 'low'.
- engine.compile_page: rebuild OVERVIEW pages deterministically via
  _materialize_overview_page on force, instead of running the generic LLM
  compiler over hand-built intro/concept-graph/index blocks.
- kb_health.scan_log_health: key repeated-failure detection on the op, not
  the free-text message, removing false positives/negatives + dead block_error.
- services/__init__: drop orphaned notebook_manager lazy-import + __all__ entry.
- PageReader.tsx: restore t() i18n on regenerate buttons; add 'Regenerating…'.
- remove PATCHES.md (developer-local scratch notes).

#484 (zulip): also match the disambiguated @**Name|user_id** mention form;
make the docstring truthful; add coverage.

#500: remove stray PR_DESCRIPTION.md committed to repo root.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
vaskoyudha added a commit to vaskoyudha/deeptutor-for-programmer-fork that referenced this pull request Jul 25, 2026
…back

Generic bot + Event Queue API returns an empty flags array, so flag-only
mention detection never fires. Add a content fallback that scans the message
body for the rendered @**Bot Full Name** syntax, backed by a _bot_full_name
captured from the bot profile. Resolved against dev's MENTION_FLAGS constant
and structured logging; added content-fallback test coverage.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
vaskoyudha added a commit to vaskoyudha/deeptutor-for-programmer-fork that referenced this pull request Jul 25, 2026
…#529/HKUDS#484

HKUDS#493 (sqlite): route _initialize() through the _connect() contextmanager
(the one remaining raw sqlite3.connect FD leak); document the auto-commit
contract so the redundant explicit commits are understood.

HKUDS#529 (book):
- _strip_thinking_preamble: guard `{ not in text` before rindex() so plain
  prose (refusals/errors) no longer raises ValueError -> ERROR block;
  hoist json import to module top.
- llm_json: honor caller max_tokens as max(max_tokens, 2600) instead of
  discarding it; bump default to 2600; fix stale 'minimal' docstring -> 'low'.
- engine.compile_page: rebuild OVERVIEW pages deterministically via
  _materialize_overview_page on force, instead of running the generic LLM
  compiler over hand-built intro/concept-graph/index blocks.
- kb_health.scan_log_health: key repeated-failure detection on the op, not
  the free-text message, removing false positives/negatives + dead block_error.
- services/__init__: drop orphaned notebook_manager lazy-import + __all__ entry.
- PageReader.tsx: restore t() i18n on regenerate buttons; add 'Regenerating…'.
- remove PATCHES.md (developer-local scratch notes).

HKUDS#484 (zulip): also match the disambiguated @**Name|user_id** mention form;
make the docstring truthful; add coverage.

HKUDS#500: remove stray PR_DESCRIPTION.md committed to repo root.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants