Skip to content

fix/RR-1023-duplicate-discussion-sync - #1027

Merged
anandray merged 1 commit into
developfrom
fix/RR-1023-duplicate-discussion-sync
Jun 1, 2026
Merged

anandray merged 1 commit into
developfrom
fix/RR-1023-duplicate-discussion-sync

Conversation

@EdwardLien0426

@EdwardLien0426 EdwardLien0426 commented May 28, 2026 •

Copy link
Copy Markdown
Contributor

Closes #1023

Root cause

POST used the raw DISCORD_DISCUSSIONS_WEBHOOK_URL; PATCH rebuilt the URL via awk -F'/' over the same secret. Any deviation from https://discord.com/api/webhooks/{id}/{token} — trailing slash, ?thread_id=..., alternate host — silently breaks the PATCH target while POST keeps working.

Cascade

Malformed PATCH → Discord 404 → handler treats it as "message deleted" → deletes the marker comment → falls through to POST → posts a fresh message + writes a new marker → next edit hits the same broken PATCH again. Repost on every update.

(Local repro with a trailing-slash webhook returns 405 rather than 404; in that shape the job would exit 1 instead of reposting. Whichever shape prod actually sees, the URL is malformed and this PR eliminates both failure modes.)

Fix

  • Normalize the secret once into $BASE (strip query string + trailing slash). Reuse $BASE for the marker-hit PATCH, the create POST, and the race-guard DELETE + PATCH.
  • Add --no-retry-5xx -X POST to the create call per the discord-helper contract. Without it a transient Discord 5xx could create a duplicate message on retry — a second, independent duplicate source fixed in the same PR.

Verification

Local-only; final acceptance needs a develop merge + a real discussion edit.

  • ${URL%%\?*} + ${BASE%/} tested against canonical, trailing-slash, ?thread_id=, combined, and discordapp.com shapes — all produce a clean base.
  • Local e2e against a throwaway Discord webhook:
    • POST: 200
    • PATCH via $BASE: 200 (message edited in place, no duplicate)
    • PATCH via old awk-split: 405 (broken path confirmed)
  • bash -n on the inline script passes.

Acceptance criteria

  • Editing a discussion with an existing marker returns PATCH 200; original Discord message is edited in place, no duplicate is posted.
  • POST is at-most-once on transient 5xx.

Summary by CodeRabbit

  • Bug Fixes

    • Improved error handling for Discord API requests with optimized retry behavior.
  • Chores

    • Enhanced Discord webhook integration efficiency through streamlined URL handling and endpoint routing.

Review Change Stack

@EdwardLien0426
EdwardLien0426 requested a review from kwit75 as a code owner May 28, 2026 21:23
@github-actions github-actions Bot added the ci/cd CI/CD and build system label May 28, 2026
@coderabbitai

coderabbitai Bot commented May 28, 2026 •

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 19a8351d-4939-458c-9183-481a930bea91

📥 Commits

Reviewing files that changed from the base of the PR and between 04858d0 and d398670.

📒 Files selected for processing (1)
  • .github/workflows/discord-discussions.yml

📝 Walkthrough

Walkthrough

The PR fixes a critical bug in the Discord discussions workflow where edited discussions post new messages instead of updating existing ones. The fix normalizes the webhook URL into a reusable BASE variable, updates all webhook endpoints to use it consistently, and adds --no-retry-5xx to prevent duplicate posts on transient errors.

Changes

Discord webhook URL normalization

Layer / File(s) Summary
Base URL normalization and PATCH endpoint
.github/workflows/discord-discussions.yml
Introduces BASE variable that strips query strings and trailing slashes from the webhook URL. Updates the PATCH request to use $BASE/messages/$DISCORD_MSG_ID instead of reconstructing the endpoint from awk-split WEBHOOK_ID and WEBHOOK_TOKEN.
POST endpoint update with retry flag
.github/workflows/discord-discussions.yml
Updates the POST call to use the normalized $BASE?wait=true endpoint and adds --no-retry-5xx flag to prevent duplicate messages on transient 5xx errors.
Race-guard duplicate-detection endpoints
.github/workflows/discord-discussions.yml
Updates DELETE and PATCH operations in the duplicate-message race-guard path to use $BASE/messages/<id> format instead of fully expanded webhook URLs.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested labels

ci/cd

Suggested reviewers

  • kwit75
  • joshuadarron

Poem

🐰 A webhook once split and frayed,
Now normalized without dismay,
With BASE so clean and POST so sound,
No duplicate Discord posts around!
Retry flags keep chaos at bay. 🎯

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title is partially related to the changeset but not the main point. While it references the issue ID (#1023) and the domain (duplicate-discussion-sync), it uses a generic 'fix/' prefix and the title format (branch name) lacks clarity about the actual technical changes implemented. Consider using a more descriptive title like 'Normalize Discord webhook URL to fix duplicate messages on edit' that clearly conveys the primary technical fix without relying on issue reference.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed The PR fully implements all coding objectives from issue #1023: normalizes webhook URL (stripping query and trailing slash) for unified POST/PATCH use, updates PATCH/DELETE operations to use the normalized base, adds --no-retry-5xx flag to POST, and ensures consistent webhook URL handling across all Discord API calls.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing the identified webhook URL normalization issue and making POST resilient to transient 5xx errors. No unrelated modifications or scope creep detected; changes are confined to the Discord workflow file.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/RR-1023-duplicate-discussion-sync

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.

@github-actions

Copy link
Copy Markdown
Contributor

No description provided.

@coderabbitai

coderabbitai Bot commented May 28, 2026

Copy link
Copy Markdown
Contributor

Actionable comments posted: 0

@anandray anandray 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.

LGTM — textbook implementation of #1023's prescribed fix.

BASE="${DISCORD_WEBHOOK_URL%%\?*}" + BASE="${BASE%/}" correctly normalizes against both query strings (?thread_id=...) and trailing slashes. All four URL-construction sites consistently use $BASE (PATCH on marker hit, POST create, DELETE race-guard, PATCH race-guard re-apply), and the old WEBHOOK_ID/WEBHOOK_TOKEN awk-split is fully retired. --no-retry-5xx on POST is the right at-most-once posture given the discord-helper contract (only 429 is replay-safe).

In-file comments accurately document the cascade. CI green, no CR threads. Local-against-throwaway-webhook verification covers the 5 URL shapes that would have triggered the bug.

@anandray
anandray merged commit a8a5754 into develop Jun 1, 2026
22 checks passed
@anandray
anandray deleted the fix/RR-1023-duplicate-discussion-sync branch June 1, 2026 15:24
AviNormie pushed a commit to AviNormie/rocketride-server that referenced this pull request Nov 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci/cd CI/CD and build system

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(ci): discord-discussions reposts on every edit due to fragile PATCH URL reconstruction

2 participants