<!-- XE-13429 · Missing state event for pre-closed imports in desk allows the push worker to reopen a reporter's closed GitHub issue · testnet -->
*Markdown view of <https://bounty.xe.network/XE-13429>. The page is the record; this is the same page for reading.*

XE-13429 · Bounty

# Missing state event for pre-closed imports in desk allows the push worker to reopen a reporter's closed GitHub issue

Triaging
claimed Medium
web
filed 2026-11-14 22:14 UTC
by xe:b67c2472

Verdict
:   published when the fix ships

Tier
:   published when the fix ships

Claimed
:   Medium

Area
:   Other

Duplicate of
:   —

Tracked
:   —

Updated
:   2026-11-20 19:46 UTC

Told
:   2026-11-20 19:45 UTC

### Patches

None linked.

### History

- [627300](https://bounty.xe.network/log/627300) 2026-11-20 19:46 UTC proposal.adopted
- [627299](https://bounty.xe.network/log/627299) 2026-11-20 19:46 UTC ticket.award
- [626048](https://bounty.xe.network/log/626048) 2026-11-20 19:45 UTC proposal.adopted
- [626047](https://bounty.xe.network/log/626047) 2026-11-20 19:45 UTC reply.sent
- [625681](https://bounty.xe.network/log/625681) 2026-11-20 19:45 UTC proposal.adopted
- [625680](https://bounty.xe.network/log/625680) 2026-11-20 19:45 UTC ticket.status new → triaging
- [624994](https://bounty.xe.network/log/624994) 2026-11-20 19:45 UTC proposal.adopted
- [624993](https://bounty.xe.network/log/624993) 2026-11-20 19:45 UTC ticket.facts area
- [624989](https://bounty.xe.network/log/624989) 2026-11-20 19:45 UTC proposal.adopted
- [624988](https://bounty.xe.network/log/624988) 2026-11-20 19:45 UTC ticket.facts
- [624984](https://bounty.xe.network/log/624984) 2026-11-20 19:45 UTC proposal.adopted
- [624983](https://bounty.xe.network/log/624983) 2026-11-20 19:45 UTC ticket.facts

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

### Report

CVSS: 5.3 (AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:L/A:N)

## Summary

The desk log is the audit trail for a ticket's GitHub state, and the invariant "latest github.state event \=\= API github\_state" holds on the full population — except by construction on the creation path. `upsert_issue` creates a ticket for a GitHub issue with `NewTicket(..., github_state=state)` (`desk/services/sync.py`, creation branch; `tsvc.create` bakes it in at `desk/services/tickets.py:258`) and appends only `ticket.created` — no `github.state` event, and no `github.closed_externally` event either. The refresh path for an existing ticket (`sync.py:154-161`) appends both. So a ticket imported from an issue that was already closed on GitHub carries `github_state="closed"` with zero trace in the log, and the "closed before the desk ruled, mirror as stale" handling is skipped entirely.

Downstream, once the ticket leaves status `new` it enters `tickets_needing_push` (`sync.py:864-870`, status !\= `new`, public, github) and `push_state` (`sync.py:749-770`) computes want \= `"open"` (status not closed/paid) !\= `github_state` (`"closed"`), so it calls `client.set_state(repo, n, "open")` — reopening the author's deliberately closed issue on GitHub — and records only a `github.state_pushed` event. `writes_to_issue` (`sync.py:717-723`: source github \+ repo \+ public) passes for such a ticket.

The reopen is conditional on triage \+ the GitHub token being restored (the token is currently dead per XE-4992/XE-11211, so it cannot fire live today); the log gap is live now and permanent — no code path ever appends a retroactive `github.state` event (contrast `github.labels`, whose creation-path gap self-heals at first `push_labels`, which appends the full list).

## Steps to reproduce

1. On GitHub, open an issue on `xeprotocol/xe`, then close it.
2. Trigger a desk import of that issue (poll, webhook, or CLI import — all go through `upsert_issue`).
3. `GET /v1/tickets/<id>` → `github_state: "closed"`, `status: "new"`.
4. `GET /v1/tickets/<id>/log` → only `ticket.created` (\+ first-touch note); no `github.state`, no `github.closed_externally`. `GET /v1/log?kind=github.state` has no event for the ticket.
5. Once the ticket is triaged (status leaves `new`) and the GitHub client is enabled, the push pass runs `push_state`: want `"open"` !\= `"closed"` → `set_state(..., "open")` reopens the GitHub issue.

## Live instance: XE-13253

Public, bounty, github `xeprotocol/xe#383`, status `new`, created 2026-11-14T20:42:03Z, `source_created_at` 2026-11-11T12:43:36Z. Live GitHub issue #383: state `closed`, `closed_at` 2026-11-11T14:34:45Z — closed by its author \~2h after creation, \~3 days before the desk imported it. Single-ticket API (fetched twice): `github_state: "closed"`, `github_labels: None`. Per-ticket log (fetched twice, `limit=500`): exactly 2 events (`ticket.created`, `note.added`), zero `github.*` events. Global log: `github.state` population still 3 events, none for XE-13253. Full-population compare (2,272 tickets): exactly 1 API-closed-no-event ticket in 2,272; all other legs 0 violations (shapes, alternation, closed\_externally pairing 3/3, reverse, pushed 71/71, latest-vs-API on the 74 event tickets).

## Impact

Integrity: the signed audit log silently omits a material state fact for an imported ticket, and the desk's own push worker is then primed to undo the reporter's deliberate action on GitHub (reopen a closed issue) once the ticket is triaged and the GitHub token is restored. Any GitHub user can trigger it by opening and closing an issue before import; no desk privilege needed; deterministic code path.

## Mitigation

In the `upsert_issue` creation branch, after `tsvc.create`, mirror the refresh path: if `state != "open"`, append `github.state` `{ticket, state}`; and if `state == "closed"` and the ticket status is open/editable, append `github.closed_externally` `{ticket, status}`. (Alternative: create with `github_state="open"` and let the refresh path record the transition — same event trail, no new branch.) No retroactive repair is possible for the event hash chain — XE-13253's missing event cannot be backfilled without breaking log verification; the fix prevents new instances.

## Dup-check

Live queries 2026-11-15: `q=github.state` → XE-0768, XE-0273, XE-12802; `q=github_state` → \+ XE-6996, XE-13131, XE-13133; `q=already closed` → XE-3910, XE-0989, XE-13382; `q=import closed` → 0; `q=closed issue` → XE-0228, XE-0004, XE-6996; `q=state event` → XE-3548. All 11 checked by title \+ single-ticket fetch — none is this finding. Closest prior XE-0273 is the refresh-path title/body rewrite (different field, different path, no cross-system write-back). `/v1/tickets/XE-13253/similar` → XE-12189 (same campaign, different ticket), XE-0668 (unrelated lease finding). Code check at desk HEAD `ab9df7f`: no path appends a retroactive `github.state` event.

### Thread

**Joseph Denne**team2026-11-20 19:45 UTCdesk

Thanks for the report. It has been read against the current code and is being handled. The assessment and any award follow the fix.
