fix(discord): prevent wildcard component registration collisions#31213
fix(discord): prevent wildcard component registration collisions#31213
Conversation
Assign distinct sentinel registration ids to Discord wildcard handlers while preserving wildcard parser keys, so select/menu/modal handlers no longer get dropped on runtimes that dedupe by raw customId.
PR SummaryMedium Risk Overview Updates the Carbon Written by Cursor Bugbot for commit c35cb2f. This will update automatically on new commits. Configure here. |
|
Landed via clean rebase replacement for #29459.
Thanks @Sid-Qin. |
Greptile SummaryThis PR fixes a component registration collision bug in the Discord integration where all wildcard handlers shared the same raw Changes:
Confidence Score: 5/5
Last reviewed commit: c35cb2f |
|
|
||
| for (const component of components) { | ||
| expect(component.customIdParser(component.customId).key).toBe("*"); | ||
| if (component.customId.includes("_modal_")) { |
There was a problem hiding this comment.
Fragile modal detection via includes("_modal_")
The test distinguishes modal components from non-modal ones using component.customId.includes("_modal_"). This implicitly couples the test logic to the naming convention of the sentinel IDs. If the modal sentinel were ever renamed (e.g., to __openclaw_discord_component_dialog_wildcard__) this check would silently fail to invoke the modal-branch assertion, potentially masking a regression.
Consider asserting on the exact sentinel strings instead:
| if (component.customId.includes("_modal_")) { | |
| if (component.customIdParser === parseDiscordModalCustomIdForCarbon || component.customId === "__openclaw_discord_component_modal_wildcard__") { |
Or, alternatively, export a constant for the modal sentinel ID and reference it directly in the test.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/discord/monitor/agent-components.wildcard.test.ts
Line: 51
Comment:
**Fragile modal detection via `includes("_modal_")`**
The test distinguishes modal components from non-modal ones using `component.customId.includes("_modal_")`. This implicitly couples the test logic to the naming convention of the sentinel IDs. If the modal sentinel were ever renamed (e.g., to `__openclaw_discord_component_dialog_wildcard__`) this check would silently fail to invoke the modal-branch assertion, potentially masking a regression.
Consider asserting on the exact sentinel strings instead:
```suggestion
if (component.customIdParser === parseDiscordModalCustomIdForCarbon || component.customId === "__openclaw_discord_component_modal_wildcard__") {
```
Or, alternatively, export a constant for the modal sentinel ID and reference it directly in the test.
How can I resolve this? If you propose a fix, please make it concise.
Summary
*both resolve to wildcard key.Why
Discord wildcard handlers that shared raw
customId="*"could be dropped in dedupe-by-customId runtimes, causing select/user/role/channel/mentionable/modal interactions to fail with Unknown component.Validation (limited gate)
pnpm vitest run src/discord/monitor/agent-components.wildcard.test.ts src/discord/components.test.ts src/discord/monitor/provider.test.tsLinks