{"id":"XE-13355","kind":"bounty","visibility":"public","source":"github","source_repo":"xeprotocol/xe","source_ref":"500","source_url":"https://github.com/xeprotocol/xe/issues/500","reporter_id":2,"title":"[DAO] sessions._submitted leaves Anchor rows unwritten until worker.job_sessions, causing false anchor_overdue health degradation and unbounded rescans","area":"dao-harness","claimed_tier":null,"assessed_tier":null,"verdict":"duplicate","duplicate_of":null,"tracked":false,"internal_ref":"","internal_url":"","status":"closed","closed_reason":"duplicate","github_state":"closed","disclosed_at":null,"award_xe":null,"award_approved":false,"paid_ref":"","created_at":"2026-11-14T20:42:10.492869+00:00","updated_at":"2026-11-15T10:28:28.817891+00:00","source_created_at":"2026-11-12T05:49:29+00:00","told_at":"2026-11-15T10:27:41+00:00","status_changed_at":"2026-11-15T10:27:34.334810+00:00","url":"https://bounty.xe.network/XE-13355","body":"### Summary\n\nIn `dao/services/sessions.py`, `_ended` (`L502-506`) deletes an `Anchor` row inside the same transaction whenever an anchor session ends `failed` or `cancelled`. By contrast, `_submitted` (`L394-401`) — the single helper called by `submit` (`L426`), `_refused` (`L448`), `rebuild` (`L295`), and `cancel` (`L494`) whenever a session's block has landed on the state chain — sets `SigningSession.status = \"submitted\"`, `submitted_index`, and `submitted_hash` without updating `Anchor.statechain_index` or `Anchor.statechain_hash`.\n\nThis produces two concrete defects:\n\n1. **False `anchor_overdue` health degradation and stale public anchor surfaces after API submission**:\n   - Every member API path that lands an anchor block (`POST /v1/members/sessions/{sid}/sign`, `/rebuild`, `/cancel`) commits `SigningSession.status = \"submitted\"` while leaving `Anchor.statechain_index = None` and `Anchor.statechain_hash = \"\"`.\n   - In `dao/worker.py:289-303` (`Worker.scheduler`), `\"health\"` is ordered **before** `\"sessions\"` in `job_table`. On any scheduler pass where both `job_health` and `job_sessions` are due after an overdue anchor has just been signed and submitted via the API (or when `GET /v1/health` / `dao health` runs before the next 120-second `job_sessions` tick, or while the worker is not yet caught up), `records.health` (`dao/services/records.py:282`) queries `latest_anchor(db, written=True)` (`Anchor.statechain_index.isnot(None)`), misses the already-landed anchor, sets `anchor_overdue = True` and `ok = False`, degrades 30-day uptime (`HealthCheck(ok=False)`), and appends a public `health.degraded` event to `EventLog`.\n   - Over the same window, `GET /v1/legal/anchors`, `GET /v1/log/head`, and `/records` report `statechain_index: null` (`pending`) while `/members` already shows the anchor session `Written at state-chain #N`.\n2. **Unbounded full-history anchor scan every 120 seconds in `worker.job_sessions`**:\n   - To compensate for `_submitted` not updating `Anchor`, `dao/worker.py:195-197` runs `select(SigningSession).where(SigningSession.status == \"submitted\", SigningSession.kind == \"anchor\")` on every two-minute `job_sessions` pass with no `Anchor.statechain_index.is_(None)` filter, reloading every submitted anchor session since genesis and issuing `SELECT ... FROM anchors` + ORM updates for each one.\n\n### Impact\n\nSubmitting an overdue anchor via the member API still triggers false `anchor_overdue` health failure, permanent `health.degraded` log entries, 30-day uptime loss when `job_health` runs ahead of `job_sessions`, temporary disagreement between `/members` and `/records` + `/v1/legal/anchors` + `/v1/log/head`, and an `O(total historical anchors)` database scan every 120 seconds.","patch_refs":[],"thread":[{"id":3134,"source":"github","source_ref":"6815842735","author":"Khanhtnq","team":false,"body":"Fix proposed in xeprotocol/dao#4.","created_at":"2026-11-12T05:49:31+00:00"},{"id":5407,"source":"github","source_ref":"6892976869","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-13355 and says what differs; it is read like any other.","created_at":"2026-11-15T10:27:41+00:00"}]}