Skip to content

Discord: add PluralKit sender identity resolver#5838

Merged
thewilloftheshadow merged 2 commits intomainfrom
shadow/pluralkit
Feb 1, 2026
Merged

Discord: add PluralKit sender identity resolver#5838
thewilloftheshadow merged 2 commits intomainfrom
shadow/pluralkit

Conversation

@thewilloftheshadow
Copy link
Member

@thewilloftheshadow thewilloftheshadow commented Feb 1, 2026

Summary

  • add PluralKit API support and sender identity resolution for Discord
  • propagate PK-aware identity to allowlists, history, and reply context
  • document PK config/allowlist usage and lookup limits

Testing

  • not run (not requested)

Greptile Overview

Greptile Summary

This PR adds PluralKit integration for Discord by introducing a PK message lookup (src/discord/pluralkit.ts) and a unified sender identity model (src/discord/monitor/sender-identity.ts). The Discord message preflight path now optionally queries PK and uses the resolved sender identity for allowlist checks and history sender labels, and config/docs are extended to support channels.discord.pluralkit.{enabled,token}.

Main issue found: the new PK-aware identity isn’t fully propagated into the inbound context consumed downstream. processDiscordMessage still populates SenderId/SenderTag from the original Discord author, so per-sender behavior and any downstream logic will still “see” the proxy identity rather than the PK member.

Also flagged: the self-message guard now depends on author.bot, which could weaken loop prevention if that flag is ever missing/false; and reply-context generation currently has no path to resolve PK identity for referenced messages despite the stated goal to make reply context PK-aware.

Confidence Score: 3/5

  • This PR is reasonably safe to merge, but has a correctness gap where PK identity is not consistently propagated.
  • Core changes are additive and well-scoped (new PK fetch helper, new sender identity helper, config/schema updates, and tests). However, processDiscordMessage still uses the original Discord author for SenderId/SenderTag, which undermines the stated feature goal and can affect downstream behavior. There is also a potential robustness regression in the self-message loop guard depending on author.bot.
  • src/discord/monitor/message-handler.process.ts; src/discord/monitor/message-handler.preflight.ts; src/discord/monitor/reply-context.ts

@openclaw-barnacle openclaw-barnacle bot added docs Improvements or additions to documentation channel: discord Channel integration: discord labels Feb 1, 2026
@thewilloftheshadow thewilloftheshadow self-assigned this Feb 1, 2026
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

4 files reviewed, 4 comments

Edit Code Review Agent Settings | Greptile

Comment on lines +22 to 28
const sender = resolveDiscordSenderIdentity({
author: referenced.author,
pluralkitInfo: null,
});
const fromLabel = referenced.author ? buildDirectLabel(referenced.author, sender.tag) : "Unknown";
const body = `${referencedText}\n[discord message id: ${referenced.id} channel: ${referenced.channelId} from: ${sender.tag ?? sender.label} user id:${sender.id}]`;
return formatAgentEnvelope({
Copy link
Contributor

Choose a reason for hiding this comment

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

[P2] Reply context still cannot resolve PK identity

resolveReplyContext always calls resolveDiscordSenderIdentity with pluralkitInfo: null, so replies to PK-proxied messages will continue to attribute the referenced message to the Discord webhook/bot identity (or whatever formatDiscordUserTag produces), not the PK member.

If the intent is “PK-aware reply context” (per PR description), this likely needs the same PK lookup path used in preflightDiscordMessage, or at least to thread the already-resolved sender into reply context construction.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/discord/monitor/reply-context.ts
Line: 22:28

Comment:
[P2] Reply context still cannot resolve PK identity

`resolveReplyContext` always calls `resolveDiscordSenderIdentity` with `pluralkitInfo: null`, so replies to PK-proxied messages will continue to attribute the referenced message to the Discord webhook/bot identity (or whatever `formatDiscordUserTag` produces), not the PK member.

If the intent is “PK-aware reply context” (per PR description), this likely needs the same PK lookup path used in `preflightDiscordMessage`, or at least to thread the already-resolved `sender` into reply context construction.

How can I resolve this? If you propose a fix, please make it concise.

Comment on lines +42 to +48
const headers: Record<string, string> = {};
if (params.config.token?.trim()) {
headers.Authorization = params.config.token.trim();
}
const res = await fetchImpl(`${PLURALKIT_API_BASE}/messages/${params.messageId}`, {
headers,
});
Copy link
Contributor

Choose a reason for hiding this comment

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

[P2] Always sending headers: {} may behave differently than omitting headers

When no token is configured, this still passes an empty headers object to fetch. Some fetch implementations treat headers: {} differently than headers being omitted (e.g., around defaults/normalization).

Not necessarily broken, but if resolveFetch can return non-standard implementations, it may be safer to only include the headers option when there’s actually an Authorization header.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/discord/pluralkit.ts
Line: 42:48

Comment:
[P2] Always sending `headers: {}` may behave differently than omitting headers

When no token is configured, this still passes an empty `headers` object to `fetch`. Some fetch implementations treat `headers: {}` differently than `headers` being omitted (e.g., around defaults/normalization).

Not necessarily broken, but if `resolveFetch` can return non-standard implementations, it may be safer to only include the `headers` option when there’s actually an Authorization header.

How can I resolve this? If you propose a fix, please make it concise.

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 1, 2026

Additional Comments (2)

src/discord/monitor/message-handler.process.ts
[P0] PK sender identity not propagated to inbound context

processDiscordMessage now computes senderLabel = sender.label, but still populates finalizeInboundContext with the original Discord author fields (SenderName, SenderId, SenderTag). This means allowlists/history are PK-aware, but the agent/runtime context and any per-sender logic downstream will still see the Discord bot user (the proxy) rather than the PK member.

This shows up in src/discord/monitor/message-handler.process.ts:271-275 and should likely use the already-computed sender identity (id/name/tag) instead of author/formatDiscordUserTag(author).

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/discord/monitor/message-handler.process.ts
Line: 122:125

Comment:
[P0] PK sender identity not propagated to inbound context

`processDiscordMessage` now computes `senderLabel = sender.label`, but still populates `finalizeInboundContext` with the original Discord author fields (`SenderName`, `SenderId`, `SenderTag`). This means allowlists/history are PK-aware, but the agent/runtime context and any per-sender logic downstream will still see the Discord bot user (the proxy) rather than the PK member.

This shows up in `src/discord/monitor/message-handler.process.ts:271-275` and should likely use the already-computed `sender` identity (id/name/tag) instead of `author`/`formatDiscordUserTag(author)`.

How can I resolve this? If you propose a fix, please make it concise.

src/discord/monitor/message-handler.preflight.ts
[P1] Self-message loop prevention no longer covers non-bot authored messages

The self-reply guard is now gated by author.bot && author.id === botUserId. If the Discord library ever delivers a message from the bot account where author.bot is missing/false (e.g. partial user objects, API changes, or mis-typed fields), this will stop preventing self-reply loops.

Previously the code returned early on author.id === botUserId regardless of author.bot. Consider restoring the author.id === botUserId check without depending on the bot flag.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/discord/monitor/message-handler.preflight.ts
Line: 270:275

Comment:
[P1] Self-message loop prevention no longer covers non-bot authored messages

The self-reply guard is now gated by `author.bot && author.id === botUserId`. If the Discord library ever delivers a message from the bot account where `author.bot` is missing/false (e.g. partial user objects, API changes, or mis-typed fields), this will stop preventing self-reply loops.

Previously the code returned early on `author.id === botUserId` regardless of `author.bot`. Consider restoring the `author.id === botUserId` check without depending on the `bot` flag.

How can I resolve this? If you propose a fix, please make it concise.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 1, 2026

⚠️ Formal models conformance drift detected

The formal models extracted constants (generated/*) do not match this openclaw PR.

This check is informational (not blocking merges yet).
See the formal-models-conformance-drift artifact for the diff.

If this change is intentional, follow up by updating the formal models repo or regenerating the extracted artifacts there.

@thewilloftheshadow thewilloftheshadow merged commit 8e2b17e into main Feb 1, 2026
22 of 42 checks passed
@thewilloftheshadow thewilloftheshadow deleted the shadow/pluralkit branch February 1, 2026 01:50
@thewilloftheshadow
Copy link
Member Author

Landed via temp rebase onto main.

  • Related tests: pnpm vitest run --config vitest.unit.config.ts src/discord/monitor.test.ts src/discord/pluralkit.test.ts
  • Land commit: a1cf76e
  • Merge commit: 8e2b17e

Thanks @thewilloftheshadow!

@orionnelson
Copy link

@thewilloftheshadow Might be a small bug in this or I pulled wrong
image 0.534 A2UI sources missing; keeping prebuilt bundle.
12.32 src/discord/monitor/message-handler.preflight.ts(58,3): error TS2459: Module '"./message-handler.preflight.types.js"' declares 'DiscordSenderIdentity' locally, but it is not exported.
12.39  ELIFECYCLE  Command failed with exit code 1.

@thewilloftheshadow
Copy link
Member Author

Yep got a fix being pushed shortly once I finish checking

lawrence565 pushed a commit to lawrence565/openclaw that referenced this pull request Feb 1, 2026
* Discord: add PluralKit sender identity resolver

* fix: resolve PluralKit sender identities (openclaw#5838) (thanks @thewilloftheshadow)
electricpen added a commit to electricpen/moltbot that referenced this pull request Feb 1, 2026
…uard, context window cap, thread binding)

Notable changes:
- fix: cap context window resolution (openclaw#6187)
- fix: update compaction safeguard to respect context window tokens
- fix: secure chrome extension relay cdp
- fix(security): restrict MEDIA path extraction to prevent LFI (openclaw#4930)
- fix(lobster): block arbitrary exec via lobsterPath/cwd (GHSA-4mhr-g7xj-cg8j)
- feat(routing): add thread parent binding inheritance for Discord (openclaw#3892)
- Discord: add PluralKit sender identity resolver (openclaw#5838)

Conflicts resolved: 3 files (duplicate imports from our custom security patches)
buiilding pushed a commit to buiilding/openclaw that referenced this pull request Feb 2, 2026
* Discord: add PluralKit sender identity resolver

* fix: resolve PluralKit sender identities (openclaw#5838) (thanks @thewilloftheshadow)
HashWarlock pushed a commit to HashWarlock/openclaw that referenced this pull request Feb 4, 2026
* Discord: add PluralKit sender identity resolver

* fix: resolve PluralKit sender identities (openclaw#5838) (thanks @thewilloftheshadow)
uxcu pushed a commit to uxcu/kook-openclaw that referenced this pull request Feb 5, 2026
* Discord: add PluralKit sender identity resolver

* fix: resolve PluralKit sender identities (openclaw#5838) (thanks @thewilloftheshadow)
bestNiu pushed a commit to bestNiu/clawdbot that referenced this pull request Feb 5, 2026
* Discord: add PluralKit sender identity resolver

* fix: resolve PluralKit sender identities (openclaw#5838) (thanks @thewilloftheshadow)
batao9 pushed a commit to batao9/openclaw that referenced this pull request Feb 7, 2026
* Discord: add PluralKit sender identity resolver

* fix: resolve PluralKit sender identities (openclaw#5838) (thanks @thewilloftheshadow)
hughdidit pushed a commit to hughdidit/DAISy-Agency that referenced this pull request Feb 8, 2026
* Discord: add PluralKit sender identity resolver

* fix: resolve PluralKit sender identities (openclaw#5838) (thanks @thewilloftheshadow)

(cherry picked from commit 8e2b17e)

# Conflicts:
#	CHANGELOG.md
#	src/discord/monitor/message-handler.preflight.ts
battman21 pushed a commit to battman21/openclaw that referenced this pull request Feb 12, 2026
* Discord: add PluralKit sender identity resolver

* fix: resolve PluralKit sender identities (openclaw#5838) (thanks @thewilloftheshadow)
battman21 pushed a commit to battman21/openclaw that referenced this pull request Feb 12, 2026
* Discord: add PluralKit sender identity resolver

* fix: resolve PluralKit sender identities (openclaw#5838) (thanks @thewilloftheshadow)
jiulingyun added a commit to jiulingyun/openclaw-cn that referenced this pull request Feb 15, 2026
zooqueen pushed a commit to hanzoai/bot that referenced this pull request Mar 6, 2026
* Discord: add PluralKit sender identity resolver

* fix: resolve PluralKit sender identities (openclaw#5838) (thanks @thewilloftheshadow)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: discord Channel integration: discord docs Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants