Skip to content

fix: respect LLM wake prefix for empty mentions - #9890

Open
wcqqq1214 wants to merge 2 commits into
AstrBotDevs:masterfrom
wcqqq1214:fix/9884
Open

fix: respect LLM wake prefix for empty mentions#9890
wcqqq1214 wants to merge 2 commits into
AstrBotDevs:masterfrom
wcqqq1214:fix/9884

Conversation

@wcqqq1214

@wcqqq1214 wcqqq1214 commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Fixes #9884

An empty mention currently causes the built-in handler to yield an explicit ProviderRequest for its immediate courtesy reply. Explicit provider requests bypass the normal provider_settings.wake_prefix check, so the LLM is invoked even when the user did not supply the configured additional LLM wake prefix.

Modifications / 改动点

  • Normalize provider_settings.wake_prefix against the configured bot wake prefixes using the same behavior as the normal agent request path.

  • Skip only the immediate LLM-generated empty-mention reply when an additional LLM wake prefix remains required.

  • Preserve the existing 60-second empty-mention waiter behavior; this PR does not change session waiter scoping or address [Bug] 群聊中空提及等待器会截获其他成员的消息(session_waiter 未绑定发送者) #9377.

  • Add parameterized regression coverage for empty mentions, wake-prefix-only messages, normalized prefixes, and the existing no-extra-prefix behavior.

  • This is NOT a breaking change. / 这不是一个破坏性变更。

Screenshots or Test Results / 运行截图或测试结果

Verification steps:

uv run pytest -q tests/unit/test_empty_mention_wake_prefix.py \
  tests/unit/test_waking_check_api_key_admin.py \
  tests/unit/test_group_chat_context_wiring.py \
  tests/unit/test_astr_main_agent.py::TestBuildMainAgent::test_build_main_agent_with_wake_prefix \
  tests/unit/test_astr_main_agent.py::TestBuildMainAgent::test_build_main_agent_no_wake_prefix
uv run pytest -q tests/unit
uv run ruff format .
uv run ruff check .

Results:

20 passed, 1 warning
912 passed, 22 warnings
All checks passed!

The new regression test failed in the three prefix-bypass cases before the production change and passes after the fix.


Checklist / 检查清单

  • 😊 If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
    / 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。

  • 👀 My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
    / 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”

  • 🤓 I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in requirements.txt and pyproject.toml.
    / 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到 requirements.txtpyproject.toml 文件相应位置。

  • 😮 My changes do not introduce malicious code.
    / 我的更改没有引入恶意代码。

Summary by Sourcery

Ensure empty-mention handling honors the provider’s configured LLM wake prefix before issuing an immediate reply.

Bug Fixes:

  • Respect the configured additional LLM wake prefix when handling empty mentions, preventing immediate LLM replies unless the required prefix is satisfied.

Enhancements:

  • Normalize provider wake prefixes against bot wake prefixes consistently with the regular agent request path while preserving the existing empty-mention waiting behavior.

Tests:

  • Add parameterized regression coverage for empty mentions, wake-prefix-only messages, normalized prefixes, and configurations without an additional prefix.

@wcqqq1214

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-08-31T18:49:55.018763Z c3526ca Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@wcqqq1214
wcqqq1214 marked this pull request as ready for review August 31, 2026 18:40

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 03f0a53310

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

messages,
should_request_llm,
):
"""Only request an immediate LLM reply when no extra prefix is required."""

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Badge Document the parameterized test in Google format

Expand this one-line docstring with a Google-style Args: section describing monkeypatch, provider_wake_prefix, messages, and should_request_llm; the repository requires all newly introduced docstrings to strictly follow that format.

AGENTS.md reference: AGENTS.md:L75-L77

Useful? React with 👍 / 👎.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hey - I've reviewed your changes and they look great!

Sourcery assessment

Approved.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@wcqqq1214

Copy link
Copy Markdown
Contributor Author

@codex review

@wcqqq1214

Copy link
Copy Markdown
Contributor Author

@sourcery-ai review

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hey - I've reviewed your changes and they look great!

Sourcery assessment

Approved.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@chatgpt-codex-connector

Copy link
Copy Markdown
Contributor

Codex Review: Didn't find any major issues. Swish!

Reviewed commit: c3526ca2a6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

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.

[Bug] “platform_settings.empty_mention_waiting”开启导致的LLM唤醒词设置无效

1 participant