Skip to content

fix(discord): ignore invalid poll payloads#388

Open
deanfluencebot wants to merge 2 commits intospacedriveapp:mainfrom
deanfluencebot:codex/fix-discord-invalid-poll
Open

fix(discord): ignore invalid poll payloads#388
deanfluencebot wants to merge 2 commits intospacedriveapp:mainfrom
deanfluencebot:codex/fix-discord-invalid-poll

Conversation

@deanfluencebot
Copy link
Contributor

@deanfluencebot deanfluencebot commented Mar 10, 2026

Summary

  • ignore invalid Discord poll payloads in rich replies
  • keep plain text replies working even when a malformed optional poll object is present
  • add a unit test covering empty and incomplete poll payloads

Why

Some reply payloads can include an empty poll stub even when the intent is just a normal text reply. Discord rejects those malformed polls, which causes the whole rich message send to fail.

This change validates poll payloads before attaching them to Discord messages. Invalid polls are skipped instead of breaking delivery.

Testing

  • added unit test coverage for invalid and valid poll payloads

Note

This PR adds poll validation to the Discord adapter. A new is_valid_poll() function checks that polls have a non-empty question and at least 2 answers, filtering them at the point of attachment in two locations. Invalid polls are silently skipped with a debug log. The unit test covers empty, single-answer, and valid poll payloads.

Written by Tembo for commit badfb61. This will update automatically on new commits.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 10, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d9a38eba-15ba-4fe1-90eb-029a9de2f9a6

📥 Commits

Reviewing files that changed from the base of the PR and between badfb61 and c42dae2.

📒 Files selected for processing (1)
  • src/messaging/discord.rs

Walkthrough

Introduces poll validation and normalization in Discord messaging: adds is_valid_poll and normalized_poll_answers, gates poll creation with the validity check, replaces prior answer cap logic, and adds unit tests covering invalid, trimmed, sparse, and limit-edge poll cases.

Changes

Cohort / File(s) Summary
Discord poll logic & tests
src/messaging/discord.rs
Added is_valid_poll(poll) and normalized_poll_answers(poll); replaced direct poll usage with `poll.as_ref().filter(

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 28.57% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: adding validation to ignore invalid Discord poll payloads, which is the primary objective of the changeset.
Description check ✅ Passed The description is well-related to the changeset, explaining the problem, solution, and testing approach for handling invalid Discord poll payloads.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/messaging/discord.rs`:
- Around line 1179-1197: The validation currently counts non-empty answers
across the whole vector but build_poll only serializes the first 10 raw answers,
so edge cases like ["Yes", "", "No"] or a second non-empty answer past index 9
slip through; update validation to use the same normalized/trimming/filtering
logic as build_poll by adding or using a helper normalized_poll_answers(poll:
&crate::Poll) -> Vec<String> that trims and filters out empty answers and then
validate against that normalized list (and only consider the first 10 answers
exactly as build_poll will), change is_valid_poll to call that helper, update
build_poll to also call the same helper, and add a regression test asserting
that polls with empty strings and answers beyond the 10th are handled
consistently (rich reply accepted only when normalized answers >= 2 and
serialization uses the first 10 normalized answers).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1d7bbd5d-8db8-4894-ac12-bd8ff4dce17a

📥 Commits

Reviewing files that changed from the base of the PR and between 0a97964 and badfb61.

📒 Files selected for processing (1)
  • src/messaging/discord.rs


fn is_valid_poll(poll: &crate::Poll) -> bool {
let question = poll.question.trim();
let answer_count = poll
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice. One edge case: build_poll only sends the first 10 answers, but is_valid_poll counts across all of them; that can accept a poll that still gets truncated to <2 usable answers.

Suggested change
let answer_count = poll
let answer_count = poll
.answers
.iter()
.take(10)
.filter(|answer| !answer.trim().is_empty())
.count();

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed in c42dae2. The validation now uses the same normalized answer set as serialization via normalized_poll_answers, so we no longer count answers that would be dropped or skipped before sending to Discord.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant