<!-- XE-1129 · desk/services/reporters.py & desk/api/team.py: reporters.merge Raises UniqueViolationError When into.id < other.id and Payout Addresses Desynchronize Across Endpoints · testnet -->
*Markdown view of <https://bounty.xe.network/XE-1129>. The page is the record; this is the same page for reading.*

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

Verdict
:   published when the fix ships

Tier
:   published when the fix ships

Claimed
:   High

Area
:   Other

Duplicate of
:   —

Tracked
:   —

Updated
:   2026-11-08 20:46 UTC

Told
:   2026-11-08 20:46 UTC

### Patches

None linked.

### History

- [45400](https://bounty.xe.network/log/45400) 2026-11-08 20:46 UTC reply.sent
- [45399](https://bounty.xe.network/log/45399) 2026-11-08 20:46 UTC proposal.adopted
- [45398](https://bounty.xe.network/log/45398) 2026-11-08 20:46 UTC proposal.adopted
- [45397](https://bounty.xe.network/log/45397) 2026-11-08 20:46 UTC ticket.status new → triaging
- [45396](https://bounty.xe.network/log/45396) 2026-11-08 20:46 UTC proposal.adopted
- [45395](https://bounty.xe.network/log/45395) 2026-11-08 20:46 UTC ticket.award
- [45394](https://bounty.xe.network/log/45394) 2026-11-08 20:46 UTC proposal.adopted
- [45393](https://bounty.xe.network/log/45393) 2026-11-08 20:46 UTC ticket.facts
- [45392](https://bounty.xe.network/log/45392) 2026-11-08 20:46 UTC proposal.adopted
- [45391](https://bounty.xe.network/log/45391) 2026-11-08 20:46 UTC ticket.facts
- [45390](https://bounty.xe.network/log/45390) 2026-11-08 20:46 UTC proposal.adopted
- [45389](https://bounty.xe.network/log/45389) 2026-11-08 20:46 UTC ticket.facts

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

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