{"id":"XE-13209","kind":"bounty","visibility":"public","source":"web","source_repo":"","source_ref":"","source_url":"","reporter_id":2305,"title":"desk: Discord mirror re-sends the closed line on every 5s pass when the thread edit fails — send-before-edit ordering, state never marked","area":"other","claimed_tier":"minor","assessed_tier":null,"verdict":"duplicate","duplicate_of":null,"tracked":false,"internal_ref":"","internal_url":"","status":"closed","closed_reason":"duplicate","github_state":"","disclosed_at":null,"award_xe":null,"award_approved":false,"paid_ref":"","created_at":"2026-11-14T19:46:57.509652+00:00","updated_at":"2026-11-20T19:45:53.373171+00:00","source_created_at":null,"told_at":"2026-11-20T19:45:53.400087+00:00","status_changed_at":"2026-11-20T19:45:53.381980+00:00","url":"https://bounty.xe.network/XE-13209","body":"## Summary\n\nIn `mirror_once`'s closed-state-push path (`desk/bots/discord_bot.py`), the\nclosed line is sent FIRST, then the thread edit runs, and `mark_state` only\nruns after both succeed:\n\n```python\nif want == \"closed\":\n    await th.send(ch.closed_line(self.ctx, t))\n    await th.edit(archived=True, locked=True)\nelse:\n    await th.edit(archived=False, locked=False)\n    await th.send(f\"Reopened: {t.id} is back with the team.\")\nawait ch.mark_state(self.ctx, db, t, want)\n```\n\nIf the edit persistently fails (e.g. the bot role lacks Manage Threads, 403 —\nsend permission and edit permission are separate), `channel_state` stays\n`\"open\"`, `needing_state_push` re-selects the ticket on the next 5-second\npass, and the closed line is sent again — forever, one duplicate per pass,\nplus a warning log line per pass. The thread is never archived/locked. The\nreopen path does not spam (it edits first and sends nothing on edit failure),\nwhich is the asymmetry that proves the ordering bug: the closed path should\nedit-then-send (or mark state on send success) like its sibling.\n\n## Reproduction (real DB + real `mirror_once`/`channels` code + fake thread, desk @ ab9df7f)\n\nHarness `g4b_mirror.py` (fake thread whose `edit` raises `discord.Forbidden`\n403 while `send` succeeds):\n\n- M2: 3 passes → 3 sends of `'Closed: closed.'`, `channel_state` still\n  `\"open\"` after each. Independently re-run: `sent=3`, 0 failures.\n- M6 (control): reopen path under the same edit failure sends 0 messages.\n- M1 (control): happy path sends exactly once.\n\n## Impact\n\nUnbounded duplicate \"Closed: …\" messages in the support thread (12/minute)\nuntil an operator fixes permissions/config; log spam every 5s; the thread is\nnever archived/locked, so the asker can keep posting into a\nsupposedly-closed ticket. Trigger is a plausible deployment misconfiguration\n(bot invited without Manage Threads), not an attacker action. Minor.\n\n## Duplicate check (neighbour bodies read in full)\n\n- XE-1481: state-push visibility leak (missing visibility filter), broken\n  `/close`/`/reopen` after `/bounty`, `told_at` never set — three different\n  defects; zero mentions of edit failure, resend, spam, or archiving in the\n  full body. Its visibility item is fixed at HEAD.\n- XE-9301: transient FETCH failure permanently fails one reply (no requeue\n  path) — different mirror defect (fetch site, reply path, terminal\n  `mark_failed`), not the state-push send/edit ordering.\n- XE-9036: poison-row stall (malformed ref aborts the whole mirror pass) —\n  different mechanism.\n- Searches: `closed_line` (2: XE-1481, XE-7855 — visibility gate, different),\n  `channel_state` (4, none about resend), `mirror spam` (0), `state push` (5,\n  none about edit-failure resend), plus `state_pushed`, `discord duplicate`,\n  `mark_state`, `Missing Permissions`, `resend`, `archived locked thread`,\n  `thread edit fail` — no ticket names this mechanism.\n\n## Suggested fix\n\nIn the closed path, `edit` first and send the closed line only after the edit\nsucceeds (mirroring the reopen path's order), or `mark_state` on send success\nand retry the edit separately.","patch_refs":[],"thread":[{"id":15303,"source":"desk","source_ref":"reply:13194","author":"Joseph Denne","team":true,"body":"Thanks. This is the same finding as an earlier report that is not public, which was filed first; the programme pays the\nfirst verifiable submission, so this one closes as a duplicate. If you believe it is a different\nbug, file a new report that links https://bounty.xe.network/XE-13209 and says what differs; it is read like any other.","created_at":"2026-11-20T19:45:53.373171+00:00"}]}