<!-- XE-13209 · desk: Discord mirror re-sends the closed line on every 5s pass when the thread edit fails — send-before-edit ordering, state never marked · testnet -->
*Markdown view of <https://bounty.xe.network/XE-13209>. The page is the record; this is the same page for reading.*

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

Verdict
:   Duplicate

Tier
:   —

Claimed
:   Minor

Area
:   Other

Duplicate of
:   —

Tracked
:   —

Updated
:   2026-11-20 19:45 UTC

Told
:   2026-11-20 19:45 UTC

### Patches

None linked.

### History

- [626144](https://bounty.xe.network/log/626144) 2026-11-20 19:45 UTC proposal.adopted
- [626143](https://bounty.xe.network/log/626143) 2026-11-20 19:45 UTC reply.sent
- [626142](https://bounty.xe.network/log/626142) 2026-11-20 19:45 UTC ticket.status new → closed
- [621798](https://bounty.xe.network/log/621798) 2026-11-20 19:44 UTC proposal.adopted
- [621795](https://bounty.xe.network/log/621795) 2026-11-20 19:44 UTC proposal.adopted
- [621794](https://bounty.xe.network/log/621794) 2026-11-20 19:44 UTC ticket.facts
- [621792](https://bounty.xe.network/log/621792) 2026-11-20 19:44 UTC proposal.adopted
- [621791](https://bounty.xe.network/log/621791) 2026-11-20 19:44 UTC ticket.facts
- [612938](https://bounty.xe.network/log/612938) 2026-11-20 15:29 UTC note.added
- [612937](https://bounty.xe.network/log/612937) 2026-11-20 15:29 UTC proposal.created
- [612936](https://bounty.xe.network/log/612936) 2026-11-20 15:29 UTC proposal.created
- [612935](https://bounty.xe.network/log/612935) 2026-11-20 15:29 UTC proposal.created

[Full history](https://bounty.xe.network/log?ref=XE-13209) · [JSON](https://bounty.xe.network/v1/tickets/XE-13209) · [markdown](https://bounty.xe.network/XE-13209.md)

### 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 Denne**team2026-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.
