Skip to content

feat(discord): allow DM access groups from channel audiences - #75813

Merged
steipete merged 2 commits into
mainfrom
codex/discord-dm-access-groups
May 1, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/discord-dm-access-groups

Conversation

@steipete

@steipete steipete commented May 1, 2026

Copy link
Copy Markdown
Contributor

Summary

  • add top-level accessGroups config with Discord channelAudience groups
  • allow Discord DM allowlists to reference accessGroup:<name> and authorize by effective ViewChannel permission
  • document DM access group examples and fail-closed/member-intent behavior

Verification

  • pnpm exec vitest run extensions/discord/src/monitor/dm-command-auth.test.ts extensions/discord/src/send.sends-basic-channel-messages.test.ts src/config/config-misc.test.ts
  • pnpm tsgo:prod
  • pnpm check
  • pnpm build
  • pnpm check:docs
  • pnpm test:unit
  • pnpm exec oxfmt --check --threads=1 docs/channels/discord.md extensions/discord/src/monitor/agent-components-dm-auth.ts extensions/discord/src/monitor/access-groups.ts extensions/discord/src/monitor/dm-command-auth.test.ts extensions/discord/src/monitor/dm-command-auth.ts extensions/discord/src/monitor/message-handler.dm-preflight.ts extensions/discord/src/monitor/native-command-auth.ts extensions/discord/src/monitor/native-command.ts extensions/discord/src/send.permissions.ts extensions/discord/src/send.sends-basic-channel-messages.test.ts extensions/discord/src/send.ts src/config/config-misc.test.ts src/config/types.access-groups.ts src/config/types.openclaw.ts src/config/types.ts src/config/zod-schema.ts

Note: full repo pnpm format:check currently reports pre-existing formatter drift in unrelated Feishu/Line/gateway/test files on latest main, so this PR verified formatting on its touched files.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation channel: discord Channel integration: discord size: L maintainer Maintainer-authored PR labels May 1, 2026
@clawsweeper

clawsweeper Bot commented May 1, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes:

This PR adds top-level accessGroups config, generic message-sender access-group expansion helpers, Discord discord.channelAudience DM authorization, cross-channel integrations for sender groups, docs, config/API baselines, tests, and a changelog entry.

Required change before merge:

A narrow automated repair is available: make the PR's Discord channel-audience permission helper owner-aware and add focused coverage. Because the source branch is not maintainer-modifiable, the repair lane may need a replacement branch.

Security review:

Security review cleared: The diff touches access-control runtime and config surfaces, but I found no concrete supply-chain, CI, dependency, secret-handling, or unauthorized-access regression; the remaining defect is a false block for guild owners.

Review findings:

  • [P2] Honor guild owners in channel audience checks — extensions/discord/src/send.permissions.ts:87
Review details

Best possible solution:

Keep the feature in review, add owner-aware Discord channel permission resolution using the guild owner field before role/admin/overwrite evaluation, add focused owner coverage, and rerun the targeted Discord/config/SDK checks plus the changed gate before merge.

Do we have a high-confidence way to reproduce the issue?

Yes. A focused test can mock a guild channel that denies ViewChannel to @everyone, a guild whose owner field matches the sender, and a member with no granting roles; the current PR helper has no owner branch, so it would return false even though Discord treats the owner as having all permissions.

Is this the best way to solve the issue?

No. The feature direction is maintainable, but the current implementation is not the best fix until the Discord permission helper matches owner/admin/overwrite semantics; the narrow safer repair is an owner short circuit before role and overwrite calculations.

Full review comments:

  • [P2] Honor guild owners in channel audience checks — extensions/discord/src/send.permissions.ts:87
    Discord treats the guild owner as having all permissions before role, administrator, and overwrite calculations. This helper only receives guild id and roles, so a server owner without a granting role can be rejected from accessGroup:<name> DMs even though Discord allows ViewChannel. Include the guild owner field in the calculation and add owner-path coverage.
    Confidence: 0.9

Overall correctness: patch is incorrect
Overall confidence: 0.9

Acceptance criteria:

  • pnpm test extensions/discord/src/send.sends-basic-channel-messages.test.ts extensions/discord/src/monitor/dm-command-auth.test.ts src/config/config-misc.test.ts src/plugin-sdk/command-auth.test.ts src/plugin-sdk/direct-dm.test.ts
  • pnpm exec oxfmt --check --threads=1 extensions/discord/src/send.permissions.ts extensions/discord/src/send.sends-basic-channel-messages.test.ts
  • pnpm check:changed in Testbox

What I checked:

  • Protected open PR state: GitHub API shows this PR is open and unmerged at head a90e8ceb4315fdf944ecf7a445eedd9fc3ec2ecd, with maintainer label, maintainer_can_modify=false, and mergeable_state=unstable. (a90e8ceb4315)
  • Current main lacks requested config surface: On current main, rg found no top-level accessGroups, accessGroup:, discord.channelAudience, or message.senders implementation beyond an existing Discord config-log label; Discord docs still describe only static channels.discord.allowFrom DM allowlists. Public docs: docs/channels/discord.md. (docs/channels/discord.md:425, 8043923910e9)
  • PR implements the requested surface: The PR head adds src/plugin-sdk/access-groups.ts with ACCESS_GROUP_ALLOW_FROM_PREFIX, access-group matching, and expansion helpers, and the PR file list shows config schema/types, Discord docs, channel integrations, tests, and generated baselines changed. (src/plugin-sdk/access-groups.ts:5, a90e8ceb4315)
  • Owner permission gap remains: resolveMemberChannelPermissionBits receives guild: Pick<APIGuild, "id" | "roles"> and computes role/admin/overwrite permissions without checking whether userId is the guild owner, so canViewDiscordGuildChannel can return false for a guild owner with no granting role. (extensions/discord/src/send.permissions.ts:87, a90e8ceb4315)
  • Upstream permission contract: discord.js GuildChannel.memberPermissions returns all permissions when member.id === this.guild.ownerId before role, administrator, and overwrite calculations, which confirms the missing owner branch is real Discord behavior.
  • Coverage gap: The PR head covers arbitrary member visibility, conflicting role overwrites, and guild mismatch, but there is no owner-path test where owner_id matches the sender and roles do not grant ViewChannel. (extensions/discord/src/send.sends-basic-channel-messages.test.ts:701, a90e8ceb4315)

Likely related people:

  • steipete: Current-main git log and blame show Peter Steinberger introduced or recently maintained the central Discord permission helper, Discord DM auth helper, and plugin SDK command-auth surface that this PR extends. (role: recent maintainer and Discord/plugin SDK auth owner; confidence: high; commits: 35a9785753aa, 33b043b92074, 8043923910e9; files: extensions/discord/src/send.permissions.ts, extensions/discord/src/monitor/dm-command-auth.ts, src/plugin-sdk/command-auth.ts)
  • scoootscooob: The prior ClawSweeper review context identifies this handle in the history for the Discord permission helper migration into the bundled plugin boundary, which is adjacent to the PR's Discord permission work. (role: Discord extension migration owner; confidence: medium; commits: 5682ec37fada; files: extensions/discord/src/send.permissions.ts)
  • hxy91819: The prior ClawSweeper review context identifies recent command-status and command-auth SDK surface work near the generic SDK helper boundary expanded by this PR. (role: adjacent plugin SDK surface contributor; confidence: medium; commits: aa15de8fdc8b, ba636d120668; files: src/plugin-sdk/command-auth.ts)

Remaining risk / open question:

  • Current head has failing CI checks, so merge should wait for logs or a rerun after the permission fix.
  • The source branch is not maintainer-modifiable according to the GitHub API, so an automated repair may need a replacement branch rather than direct edits to the PR branch.

Codex review notes: model gpt-5.5, reasoning high; reviewed against 8043923910e9.

@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: 503d254614

ℹ️ 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".

Comment on lines +109 to +112
if (params.member.roles?.includes(overwrite.id)) {
permissions = removePermissionBits(permissions, overwrite.deny ?? "0");
permissions = addPermissionBits(permissions, overwrite.allow ?? "0");
}

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 Aggregate role overwrites before applying channel permissions

The new DM access-group path calls canViewDiscordGuildChannel, which relies on this role-overwrite loop to decide ViewChannel; however, the code applies each matching role overwrite in sequence, so the final permission depends on the API order of permission_overwrites. Discord’s permission algorithm requires aggregating all matching role denies first and then all allows, so members with conflicting role overwrites can be misclassified (false allow/block), causing accessGroup:<name> DM authorization to be incorrect for real guild setups.

Useful? React with 👍 / 👎.

@steipete
steipete force-pushed the codex/discord-dm-access-groups branch from 503d254 to 47922a4 Compare May 1, 2026 22:21
@openclaw-barnacle openclaw-barnacle Bot added channel: googlechat Channel integration: googlechat channel: whatsapp-web Channel integration: whatsapp-web channel: zalo Channel integration: zalo channel: zalouser Channel integration: zalouser size: XL and removed size: L labels May 1, 2026
@steipete
steipete force-pushed the codex/discord-dm-access-groups branch from 47922a4 to 88902a0 Compare May 1, 2026 22:25
@steipete
steipete force-pushed the codex/discord-dm-access-groups branch from 88902a0 to 180675d Compare May 1, 2026 22:29
@steipete
steipete force-pushed the codex/discord-dm-access-groups branch from 180675d to ff8a482 Compare May 1, 2026 22:36
@openclaw-barnacle openclaw-barnacle Bot added the channel: matrix Channel integration: matrix label May 1, 2026
steipete added a commit that referenced this pull request May 1, 2026
@steipete
steipete force-pushed the codex/discord-dm-access-groups branch from ff8a482 to 6c95613 Compare May 1, 2026 22:41
@openclaw-barnacle openclaw-barnacle Bot removed the channel: matrix Channel integration: matrix label May 1, 2026
@steipete
steipete force-pushed the codex/discord-dm-access-groups branch from 6c95613 to a90e8ce Compare May 1, 2026 22:46
@steipete
steipete force-pushed the codex/discord-dm-access-groups branch from a90e8ce to d4c3fe1 Compare May 1, 2026 22:51
@openclaw-barnacle openclaw-barnacle Bot added the cli CLI command changes label May 1, 2026
@steipete
steipete merged commit 20945b8 into main May 1, 2026
103 of 104 checks passed
@steipete
steipete deleted the codex/discord-dm-access-groups branch May 1, 2026 22:55
@steipete

steipete commented May 1, 2026

Copy link
Copy Markdown
Contributor Author

Landed, thanks @clawsweeper.

Source head: d4c3fe1f77bb4653dc86d6b8fe866b83ec025cb3
Merge commit: 20945b84b44a62d634967073ed1de743f05fe2fe

Verification before merge:

  • GitHub exact-head CI: required shards green on d4c3fe1f77bb4653dc86d6b8fe866b83ec025cb3 (82 success, 20 skipped, 1 neutral; ignored canceled ClawSweeper dispatch).
  • pnpm config:docs:check
  • pnpm plugin-sdk:api:check
  • pnpm lint --threads=8
  • pnpm lint:webhook:no-low-level-body-read && pnpm lint:auth:no-pairing-store-group && pnpm lint:auth:pairing-account-scope && pnpm check:import-cycles
  • pnpm test extensions/whatsapp/src/inbound/access-control.test.ts src/plugin-sdk/command-auth.test.ts src/plugin-sdk/direct-dm.test.ts src/plugins/contracts/plugin-sdk-subpaths.test.ts src/plugins/contracts/plugin-sdk-runtime-api-guardrails.test.ts
  • pnpm test src/cli/plugins-cli.list.test.ts src/cli/plugins-cli.install.test.ts src/cli/plugins-cli.uninstall.test.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: discord Channel integration: discord channel: googlechat Channel integration: googlechat channel: whatsapp-web Channel integration: whatsapp-web channel: zalo Channel integration: zalo channel: zalouser Channel integration: zalouser cli CLI command changes docs Improvements or additions to documentation maintainer Maintainer-authored PR size: XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant