Skip to content

Feature/yuanbao group bot owner command - #29077

Open
295367131 wants to merge 3 commits into
NousResearch:mainfrom
YuanbaoTeam:feature/yuanbao-group-bot-owner-command
Open

Feature/yuanbao group bot owner command#29077
295367131 wants to merge 3 commits into
NousResearch:mainfrom
YuanbaoTeam:feature/yuanbao-group-bot-owner-command

Conversation

@295367131

Copy link
Copy Markdown

Summary

Adds stricter owner-command handling for Yuanbao group chats.

What changed

  • Added QueryBotInfoReq/QueryBotInfoRsp protocol support in gateway/platforms/yuanbao_proto.py
  • Query and cache bot owner information after WS auth-bind succeeds
  • Added cached bot_info accessor on YuanbaoAdapter
  • Refactored OwnerCommandMiddleware command parsing and owner validation flow
  • Added stricter owner-only command gating for group chats
  • Added dedicated GROUP_ALLOWLIST handling for group-chat slash commands
  • Reject non-owner attempts for privileged slash commands
  • Prevent slash-command execution and responses in group chats unless:
    • sender is the bot owner
    • command is explicitly allowlisted
    • or bot is explicitly @mentioned
  • Normalize mention metadata before forwarding commands to Hermes Agent
  • Allow owner commands to bypass group queue serialization for concurrent dispatch
  • Added normalization support for full-width slash (/command)

This improves safety and predictability for privileged commands such as /approve, /deny, /stop, and /reset in Yuanbao group chats while preserving normal mention-based interaction behavior.

Testing

Tested manually with Yuanbao WebSocket integration.

Verified:

  1. Bot owner commands in group chats require explicit @Bot mention
  2. Mention metadata is normalized before forwarding commands to Hermes Agent
  3. Non-owner users are rejected for privileged commands
  4. Non-allowlisted commands are blocked in group chats
  5. Private chat command flow still works normally
  6. Group messages without @Bot no longer trigger slash-command responses unexpectedly
  7. Cached bot owner info is refreshed after reconnect
  8. Concurrent owner command dispatch works correctly

Platforms Tested

  • Linux

Related

Closes #29065

@alt-glitch alt-glitch added type/feature New feature or request P3 Low — cosmetic, nice to have comp/gateway Gateway runner, session dispatch, delivery labels May 20, 2026
@loongfay

Copy link
Copy Markdown
Contributor

The author is a developer from the Yuanbao team. This PR performs strict permission verification on custom slash commands, enhancing security. @alt-glitch @kovyrin @jbarket @valda

295367131 added 3 commits May 21, 2026 19:57
… gating

- Add QueryBotInfoReq/Rsp encode/decode in yuanbao_proto.py
- Query and cache bot owner info via QueryBotInfoReq after WS auth-bind
- Refactor OwnerCommandMiddleware: stricter owner validation, GROUP_ALLOWLIST
- Allow owner commands to bypass group queue for concurrent dispatch
- Reject non-owner slash commands and non-allowlisted commands in group chat
- Require @bot mention for slash commands in group chat
@295367131
295367131 force-pushed the feature/yuanbao-group-bot-owner-command branch from aba6880 to e34239d Compare May 21, 2026 12:00

@teknium1 teknium1 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.

Thanks for the Yuanbao security hardening work. I verified that the underlying gap still exists on current main: Yuanbao owner commands still depend on push.bot_owner_id at gateway/platforms/yuanbao.py:2041, and current main has no QueryBotInfo support.

Problems

  • gateway/platforms/yuanbao.py:1953 in this PR duplicates the same is_gateway_known_command and group @bot checks already added at gateway/platforms/yuanbao.py:1944-1950.
  • gateway/platforms/yuanbao.py:1930 prefers cached adapter.bot_info whenever present; if the cached owner_id is empty, it skips the existing push.bot_owner_id fallback and valid owner commands can fail.
  • gateway/platforms/yuanbao.py:2889 calls _query_bot_info() only during initial open(). I did not find a reconnect-path refresh, despite the PR body saying cached owner info refreshes after reconnect.
  • gateway/platforms/yuanbao.py:4604 says _bot_info resets on disconnect and is re-fetched on every reconnect, but the PR head search only found initialization, _query_bot_info(), and the accessor.
  • No tests were added for the new owner-command branches or QueryBotInfoRsp decoding.

Suggested changes

  • Remove the duplicate gate block.
  • Fall back to push.bot_owner_id when cached bot info is missing an owner id.
  • Clear/refresh _bot_info on reconnect/disconnect, or adjust the lifecycle comments.
  • Add targeted tests for the new group command gate and protocol decoder.

This is an automated hermes-sweeper review.

def _is_owner(adapter, push: dict, from_account: str) -> bool:
"""Check whether from_account is the bot owner."""
bot_info = adapter.bot_info if adapter else None
owner_id = (

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.

If adapter.bot_info exists but its owner_id is empty, this skips the existing push.bot_owner_id fallback and can reject the real owner. Consider falling back whenever the cached owner id is blank.

await next_fn()
return

from hermes_cli.commands import is_gateway_known_command

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.

This repeats the same is_gateway_known_command import/check and group @bot gate from the block just above; one copy should be removed.


YuanbaoAdapter.set_active(adapter)

await self._query_bot_info()

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.

This refreshes bot info on initial connect only. The reconnect path also needs the refresh if the cache is meant to survive connection churn safely.


# Bot info cache: populated once after WS connect by _query_bot_info().
# Contains {"bot_id": str, "owner_id": str} from QueryBotInfoRsp.
# Reset to None on disconnect; re-fetched on every reconnect.

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.

The comment says _bot_info is reset on disconnect and re-fetched on every reconnect, but this patch does not implement that lifecycle. Either add the reset/refresh or narrow the comment.

@teknium1 teknium1 added sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages sweeper:risk-security-boundary Sweeper risk: may affect sandboxing, auth, credentials, or sensitive data sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform labels Jul 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/gateway Gateway runner, session dispatch, delivery P3 Low — cosmetic, nice to have sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages sweeper:risk-security-boundary Sweeper risk: may affect sandboxing, auth, credentials, or sensitive data sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state type/feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Support session control commands in Yuanbao group chats

4 participants