{"id":"XE-13429","kind":"bounty","visibility":"public","source":"web","source_repo":"","source_ref":"","source_url":"","reporter_id":2235,"title":"Missing state event for pre-closed imports in desk allows the push worker to reopen a reporter's closed GitHub issue","area":"other","claimed_tier":"medium","assessed_tier":null,"verdict":null,"duplicate_of":null,"tracked":false,"internal_ref":"","internal_url":null,"status":"triaging","closed_reason":null,"github_state":"","disclosed_at":null,"award_xe":null,"award_approved":false,"paid_ref":"","created_at":"2026-11-14T22:14:52.093865+00:00","updated_at":"2026-11-20T19:46:45.190032+00:00","source_created_at":null,"told_at":"2026-11-20T19:45:52.259948+00:00","status_changed_at":"2026-11-20T19:45:46.462325+00:00","url":"https://bounty.xe.network/XE-13429","body":"CVSS: 5.3 (AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:L/A:N)\r\n\r\n## Summary\r\nThe 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.\r\n\r\nDownstream, 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.\r\n\r\nThe 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).\r\n\r\n## Steps to reproduce\r\n1. On GitHub, open an issue on `xeprotocol/xe`, then close it.\r\n2. Trigger a desk import of that issue (poll, webhook, or CLI import — all go through `upsert_issue`).\r\n3. `GET /v1/tickets/<id>` → `github_state: \"closed\"`, `status: \"new\"`.\r\n4. `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.\r\n5. 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.\r\n\r\n## Live instance: XE-13253\r\nPublic, 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).\r\n\r\n## Impact\r\nIntegrity: 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.\r\n\r\n## Mitigation\r\nIn 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.\r\n\r\n## Dup-check\r\nLive 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.","patch_refs":[],"thread":[{"id":15265,"source":"desk","source_ref":"reply:13156","author":"Joseph Denne","team":true,"body":"Thanks for the report. It has been read against the current code and is being handled. The assessment and any award follow the fix.","created_at":"2026-11-20T19:45:52.242483+00:00"}]}