[codex] Support Discord DM agent requests#305
Conversation
|
Warning Review limit reached
Your plan includes 1 review of capacity. Refill in 22 minutes and 38 seconds. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more review capacity refills, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than trial, open-source, and free plans. In all cases, review capacity refills continuously over time. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
This PR adds support for handling natural-language agent requests sent to the Discord bot via direct messages (DMs), while ensuring DM senders are validated as current members of the configured 508 Discord server and that confirmation flows reflect up-to-date membership/roles.
Changes:
- Add DM handling path to the agent message listener, resolving DM senders against the configured guild and using fresh guild-member roles in the backend context.
- Update confirmation-context role behavior to distinguish “guild not resolvable” vs “member no longer present,” clearing roles when the member has left the guild.
- Extend unit tests and update Discord bot documentation to cover DM behavior and guardrails.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| tests/unit/test_agent_cog.py | Adds coverage for DM agent requests, DM denial for non-members, and confirmation-context role clearing when a member leaves the guild. |
| apps/discord_bot/src/five08/discord_bot/cogs/agent.py | Implements DM request handling, guild/member resolution, role refresh semantics in confirmations, and DM-specific response routing/auditing. |
| apps/discord_bot/README.md | Documents DM support for text-based agent requests and the membership validation requirement. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| metadata={"reason": "member_not_in_configured_guild"}, | ||
| ) | ||
| await message.reply( | ||
| "I can only run DM workflows for current members of the " | ||
| "configured 508 server.", |
| configured_guild_id = str(settings.discord_server_id or "").strip() | ||
| if configured_guild_id: | ||
| try: | ||
| return self.bot.get_guild(int(configured_guild_id)) | ||
| except ValueError: | ||
| return None | ||
|
|
||
| guilds = getattr(self.bot, "guilds", []) | ||
| if len(guilds) == 1: | ||
| return guilds[0] | ||
| return None |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ad8db68579
ℹ️ 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".
| member_context = await self._resolve_dm_member_context(message.author.id) | ||
| if member_context is None: |
There was a problem hiding this comment.
Rate-limit DM requests before guild member resolution
Move the DM rate-limit check ahead of _resolve_dm_member_context in _handle_agent_dm: right now every DM from a non-member (or from a member before cache hit) can trigger a guild member lookup/fetch, and those denied requests are not throttled because _mention_rate_limited runs only after successful membership resolution. In a spam scenario this creates an unbounded stream of Discord API lookups and denial replies, which can consume rate budget and degrade legitimate bot traffic.
Useful? React with 👍 / 👎.
ad8db68 to
6569528
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6569528889
ℹ️ 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".
| slash_context = await self._resolve_slash_context(interaction) | ||
| if slash_context is None: |
There was a problem hiding this comment.
Rate-limit DM slash requests before member resolution
The new DM slash flow performs self._resolve_slash_context(interaction) immediately, which for DM users calls _resolve_dm_member_context and can hit guild.fetch_member on every request, but this path has no throttling equivalent to _mention_rate_limited. In practice, a user outside the configured guild (or a cached-miss user) can spam /agent in DMs and force repeated Discord member lookups before denial, consuming API budget and degrading legitimate bot traffic.
Useful? React with 👍 / 👎.
Summary
Validation
uv run pytest tests/unit/test_agent_cog.py./scripts/lint.sh./scripts/mypy.sh./scripts/test.sh