Discord: add PluralKit sender identity resolver#5838
Discord: add PluralKit sender identity resolver#5838thewilloftheshadow merged 2 commits intomainfrom
Conversation
| 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({ |
There was a problem hiding this 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.
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.| 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, | ||
| }); |
There was a problem hiding this 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.
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.
Additional Comments (2)
This shows up in Prompt To Fix With AIThis 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.
The self-reply guard is now gated by Previously the code returned early on Prompt To Fix With AIThis 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. |
3b26618 to
a1cf76e
Compare
|
The formal models extracted constants ( This check is informational (not blocking merges yet). If this change is intentional, follow up by updating the formal models repo or regenerating the extracted artifacts there. |
|
Landed via temp rebase onto main.
Thanks @thewilloftheshadow! |
|
@thewilloftheshadow Might be a small bug in this or I pulled wrong |
|
Yep got a fix being pushed shortly once I finish checking |
* Discord: add PluralKit sender identity resolver * fix: resolve PluralKit sender identities (openclaw#5838) (thanks @thewilloftheshadow)
…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)
* Discord: add PluralKit sender identity resolver * fix: resolve PluralKit sender identities (openclaw#5838) (thanks @thewilloftheshadow)
* Discord: add PluralKit sender identity resolver * fix: resolve PluralKit sender identities (openclaw#5838) (thanks @thewilloftheshadow)
* Discord: add PluralKit sender identity resolver * fix: resolve PluralKit sender identities (openclaw#5838) (thanks @thewilloftheshadow)
* Discord: add PluralKit sender identity resolver * fix: resolve PluralKit sender identities (openclaw#5838) (thanks @thewilloftheshadow)
* Discord: add PluralKit sender identity resolver * fix: resolve PluralKit sender identities (openclaw#5838) (thanks @thewilloftheshadow)
* 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
* Discord: add PluralKit sender identity resolver * fix: resolve PluralKit sender identities (openclaw#5838) (thanks @thewilloftheshadow)
* Discord: add PluralKit sender identity resolver * fix: resolve PluralKit sender identities (openclaw#5838) (thanks @thewilloftheshadow)
* Discord: add PluralKit sender identity resolver * fix: resolve PluralKit sender identities (openclaw#5838) (thanks @thewilloftheshadow)

Summary
Testing
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 supportchannels.discord.pluralkit.{enabled,token}.Main issue found: the new PK-aware identity isn’t fully propagated into the inbound context consumed downstream.
processDiscordMessagestill populatesSenderId/SenderTagfrom 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
processDiscordMessagestill uses the original Discord author forSenderId/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 onauthor.bot.