discord-bridge: check the gateway echo before retrying ambiguous webhook sends #67

Merged
jared merged 1 commits from discord-bridge-echo-check into main 2026-11-15 21:46:31 -05:00
Owner

On 2026-11-15 21:34 a 20 KB image from Lonely was dropped with read tcp …: connection reset by peer. Patch 0001 (#65) deliberately doesn't retry failures after the request was sent, because a webhook post has no dedupe. No copy of it came back into the Matrix room, which confirms Discord never posted it.

Patch 0002

  • While a relay send is in flight, the bridge registers a waiter for its channel (or thread). The gateway MESSAGE_CREATE handler offers every webhook message to the waiters. A match needs the same webhook ID, the same text (trimmed) and the same attachment count, created no earlier than 2 s before the send started.
  • On an ambiguous failure (reset, EOF, broken pipe, timeout waiting for the reply, Discord 5xx), it waits up to 6 s for the echo:
    • echo seen: the send is treated as successful and its Discord ID recorded, so there's no resend, no warning, and no copy back into Matrix (the portal later drops the queued MESSAGE_CREATE as a duplicate);
    • no echo: it retries with the 0001 backoff, and checks again without waiting before each resend in case a late echo arrived during the backoff.
  • User-session sends are unchanged (they still retry pre-send errors only). Discord 4xx is never retried.
  • 7 new tests, including the waiter's matching rules. build-patched.sh now runs them with -race.

Already deployed

Clean build via build-patched.sh (both patches applied in order, tests pass with -race), deployed to LXC 151 at 21:41 (sha256 7b396eb2…7111). Reconnected to Discord immediately. The previous build is kept as /opt/mautrix-discord/mautrix-discord.bak-20261115-patch0001.

🤖 Generated with Claude Code

https://claude.ai/code/session_01PPmy3tPq869XDW4njjVaKA

On 2026-11-15 21:34 a 20 KB image from Lonely was dropped with `read tcp …: connection reset by peer`. Patch 0001 (#65) deliberately doesn't retry failures after the request was sent, because a webhook post has no dedupe. No copy of it came back into the Matrix room, which confirms Discord never posted it. ## Patch 0002 - While a relay send is in flight, the bridge registers a waiter for its channel (or thread). The gateway MESSAGE_CREATE handler offers every webhook message to the waiters. A match needs the same webhook ID, the same text (trimmed) and the same attachment count, created no earlier than 2 s before the send started. - On an ambiguous failure (reset, EOF, broken pipe, timeout waiting for the reply, Discord 5xx), it waits up to 6 s for the echo: - **echo seen**: the send is treated as successful and its Discord ID recorded, so there's no resend, no warning, and no copy back into Matrix (the portal later drops the queued MESSAGE_CREATE as a duplicate); - **no echo**: it retries with the 0001 backoff, and checks again without waiting before each resend in case a late echo arrived during the backoff. - User-session sends are unchanged (they still retry pre-send errors only). Discord 4xx is never retried. - 7 new tests, including the waiter's matching rules. `build-patched.sh` now runs them with `-race`. ## Already deployed Clean build via `build-patched.sh` (both patches applied in order, tests pass with `-race`), deployed to LXC 151 at 21:41 (sha256 `7b396eb2…7111`). Reconnected to Discord immediately. The previous build is kept as `/opt/mautrix-discord/mautrix-discord.bak-20261115-patch0001`. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01PPmy3tPq869XDW4njjVaKA
jared added 1 commit 2026-11-15 21:43:12 -05:00
discord-bridge: check the gateway echo before retrying ambiguous webhook sends
Lint / Shell (shellcheck) (push) Successful in 29s
Lint / JS (eslint) (push) Successful in 27s
Lint / No Hookshot webhook IDs in README (push) Successful in 12s
Lint / No secrets in webhook configs (push) Successful in 8s
Lint / Landing page is rendered (matrix (push) Successful in 5s
Lint / Python (ruff) (push) Successful in 6s
Lint / Secret scan (gitleaks) (push) Successful in 7s
Lint / Shell (shellcheck) (pull_request) Successful in 7s
Lint / JS (eslint) (pull_request) Successful in 17s
Lint / No Hookshot webhook IDs in README (pull_request) Successful in 9s
Lint / No secrets in webhook configs (pull_request) Successful in 19s
Lint / Python deps (pip-audit) (push) Successful in 1m18s
Lint / Landing page is rendered (matrix (pull_request) Successful in 11s
Lint / Python (ruff) (pull_request) Successful in 22s
Lint / Secret scan (gitleaks) (pull_request) Successful in 7s
Lint / Python deps (pip-audit) (pull_request) Successful in 34s
d8c2acc461
On 2026-11-15 21:34 an image relay failed with "read: connection reset by
peer" after the request was sent. Patch 0001 deliberately doesn't retry
those (a webhook post has no dedupe), so the image was dropped.

Patch 0002: while a relay send is in flight the bridge watches the
Discord gateway for its own post (same webhook, text and attachment
count, created after the send started). On an ambiguous failure (reset,
EOF, timeout waiting for the reply, Discord 5xx) it waits up to 6 s for
that echo: if it shows up the send counts as delivered and is recorded
(no resend, no copy back into Matrix); otherwise it retries with the
0001 backoff, checking again before each resend.

build-patched.sh runs the new tests with -race.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PPmy3tPq869XDW4njjVaKA
jared scheduled this pull request to auto merge when all checks succeed 2026-11-15 21:46:30 -05:00
jared merged commit b3fec4af2a into main 2026-11-15 21:46:31 -05:00
jared deleted branch discord-bridge-echo-check 2026-11-15 21:46:31 -05:00
Sign in to join this conversation.