Bounty
XE-1129 · Bounty

desk/services/reporters.py & desk/api/team.py: reporters.merge Raises UniqueViolationError When into.id < other.id and Payout Addresses Desynchronize Across Endpoints

Triaging claimed High web filed 2026-11-07 16:31 UTC by Ashev Ardiansyah

Report

In desk/desk/services/reporters.py, desk/desk/services/sync.py, and desk/desk/api/team.py, interacting defects in reporter merging and payout-address propagation cause unhandled database IntegrityError crashes (HTTP 500), orphaned sessions, and silent loss/desynchronization of bounty payout addresses:

  1. reporters.merge() triggers PostgreSQL UniqueViolationError (HTTP 500) on reporters.github_id when into.id < other.id and orphans ReporterSession rows (desk/desk/services/reporters.py:211-229, desk/desk/models.py:248): Reporter.github_id has a non-deferrable UNIQUE constraint (models.py:248). In merge(), into.github_id = into.github_id or other.github_id and other.github_id = None are dirtied in the same SQLAlchemy unit of work before ctx.events.append() calls await db.flush(). When into.id < other.id and into.github_id was None while other.github_id was set (e.g., into was created first via email/XE key and other was created later via GitHub OAuth, then linked into into), SQLAlchemy flushes UPDATE reporters in primary-key order (into before other), raising UniqueViolationError on reporters_github_id_key (HTTP 500). When into.id > other.id, merge() leaves ReporterSession rows (reporter_sessions.reporter_id == other.id) pointing to the wiped "merged into ..." shell row, and from_xe() (lines 201-202) merges without checking for conflicting github_id/email/xe_address, silently wiping other's identity and payout_proof.

  2. Ticket.payout_address is dropped or left stale across sync.upsert_issue(), reporters.attach(), reporters.merge(), and reporters.bind_payout(), while GET /v1/team/payouts and GET /v1/team/payouts.csv diverge (desk/desk/services/sync.py:86-100, desk/desk/services/reporters.py:101-144, 211-248, 422-452, desk/desk/api/team.py:286-305):

  • sync.upsert_issue() (sync.py:86-100) creates NewTicket(..., reporter_id=reporter.id if reporter else None) without passing payout_address=reporter.xe_address, so every GitHub-synced issue filed by a reporter who already bound their payout address is created with t.payout_address = "".
  • Neither reporters.attach() nor reporters.merge() backfills r.xe_address / into.xe_address onto unpaid tickets with t.payout_address == "".
  • reporters.bind_payout() (reporters.py:241-246) updates r.xe_address = address and overwrites r.payout_proof, but only updates tickets where Ticket.payout_address == "", leaving any unpaid ticket that had a previously bound address pointing to the stale address.
  • GET /v1/team/payouts (team.py:286-305) returns t.payout_address (and omits award_approved_at.is_not(None) / award_xe.is_not(None) filters), whereas GET /v1/team/payouts.csv (reporters.py:422-452) returns r.xe_address and truncates sub-XE amounts via (t.award_xe or 0) // 1_000_000.

Remediation

  1. In reporters.merge(), set other.github_id = None and await db.flush() before setting into.github_id, re-point ReporterSession.reporter_id == other.id to into.id, and backfill t.payout_address = into.xe_address on unpaid bounty tickets in merge() and attach().
  2. Pass payout_address=reporter.xe_address if reporter else "" in sync.upsert_issue(), update all unpaid bounty tickets (Ticket.status != "paid") when re-binding in bind_payout(), and align GET /v1/team/payouts with reporters.payout_rows().

Thread

Joseph Denneteam2026-11-08 20:46 UTCdesk

Thanks for the report. Part of what you describe was already on file from earlier reports (https://bounty.xe.network/XE-0710 and https://bounty.xe.network/XE-0711); the remaining point about the account-merge error is being looked at and we will update this ticket when there is more to say.