Bounty
XE-13209 · Bounty

desk: Discord mirror re-sends the closed line on every 5s pass when the thread edit fails — send-before-edit ordering, state never marked

Closed · duplicate —claimed Minor web filed 2026-11-14 19:46 UTC by xe:b4c356d4

Report

Summary

In mirror_once's closed-state-push path (desk/bots/discord_bot.py), the closed line is sent FIRST, then the thread edit runs, and mark_state only runs after both succeed:

if want == "closed":
    await th.send(ch.closed_line(self.ctx, t))
    await th.edit(archived=True, locked=True)
else:
    await th.edit(archived=False, locked=False)
    await th.send(f"Reopened: {t.id} is back with the team.")
await ch.mark_state(self.ctx, db, t, want)

If the edit persistently fails (e.g. the bot role lacks Manage Threads, 403 — send permission and edit permission are separate), channel_state stays "open", needing_state_push re-selects the ticket on the next 5-second pass, and the closed line is sent again — forever, one duplicate per pass, plus a warning log line per pass. The thread is never archived/locked. The reopen path does not spam (it edits first and sends nothing on edit failure), which is the asymmetry that proves the ordering bug: the closed path should edit-then-send (or mark state on send success) like its sibling.

Reproduction (real DB + real mirror_once/channels code + fake thread, desk @ ab9df7f)

Harness g4b_mirror.py (fake thread whose edit raises discord.Forbidden 403 while send succeeds):

  • M2: 3 passes → 3 sends of 'Closed: closed.', channel_state still "open" after each. Independently re-run: sent=3, 0 failures.
  • M6 (control): reopen path under the same edit failure sends 0 messages.
  • M1 (control): happy path sends exactly once.

Impact

Unbounded duplicate "Closed: …" messages in the support thread (12/minute) until an operator fixes permissions/config; log spam every 5s; the thread is never archived/locked, so the asker can keep posting into a supposedly-closed ticket. Trigger is a plausible deployment misconfiguration (bot invited without Manage Threads), not an attacker action. Minor.

Duplicate check (neighbour bodies read in full)

  • XE-1481: state-push visibility leak (missing visibility filter), broken /close//reopen after /bounty, told_at never set — three different defects; zero mentions of edit failure, resend, spam, or archiving in the full body. Its visibility item is fixed at HEAD.
  • XE-9301: transient FETCH failure permanently fails one reply (no requeue path) — different mirror defect (fetch site, reply path, terminal mark_failed), not the state-push send/edit ordering.
  • XE-9036: poison-row stall (malformed ref aborts the whole mirror pass) — different mechanism.
  • Searches: closed_line (2: XE-1481, XE-7855 — visibility gate, different), channel_state (4, none about resend), mirror spam (0), state push (5, none about edit-failure resend), plus state_pushed, discord duplicate, mark_state, Missing Permissions, resend, archived locked thread, thread edit fail — no ticket names this mechanism.

Suggested fix

In the closed path, edit first and send the closed line only after the edit succeeds (mirroring the reopen path's order), or mark_state on send success and retry the edit separately.

Thread

Joseph Denneteam2026-11-20 19:45 UTCdesk

Thanks. This is the same finding as an earlier report that is not public, which was filed first; the programme pays the first verifiable submission, so this one closes as a duplicate. If you believe it is a different bug, file a new report that links https://bounty.xe.network/XE-13209 and says what differs; it is read like any other.