Skip to content

fix(gateway): deterministic thread eviction preserves newest entries (salvage #13639)#20285

Merged
teknium1 merged 2 commits into
mainfrom
salvage/pr-13639
May 5, 2026
Merged

fix(gateway): deterministic thread eviction preserves newest entries (salvage #13639)#20285
teknium1 merged 2 commits into
mainfrom
salvage/pr-13639

Conversation

@teknium1
Copy link
Copy Markdown
Contributor

@teknium1 teknium1 commented May 5, 2026

Salvages @hharry11's PR #13639 onto current main.

What it does

ThreadParticipationTracker stored threads in a set and relied on list(set) ordering for capacity eviction. Since Python sets are unordered, a newly mark()-ed thread could be evicted by the next capacity trim while older entries survived — non-deterministic, and specifically bad on Discord where a recently-joined thread might disappear from the participation cache.

Switch to a dict[str, None] which preserves insertion order; the newest mark()-ed thread is always at the end and survives [-max_tracked:] trimming.

Changes

  • gateway/platforms/helpers.py_threads is now a dict keyed by thread id. _load returns an ordered list. Save still uses main's atomic_json_write.
  • tests/gateway/test_discord_thread_persistence.py — assertion on evicted-set ordering + new test for the newest-survives case.
  • scripts/release.py — AUTHOR_MAP entry for hharry11.

Validation

tests/gateway/test_discord_thread_persistence.py — 8 passed locally.

Closes #13639 via salvage.

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/gateway Gateway runner, session dispatch, delivery platform/discord Discord bot adapter labels May 5, 2026
@teknium1 teknium1 force-pushed the salvage/pr-13639 branch from 86dd835 to d3f0481 Compare May 5, 2026 17:13
@teknium1 teknium1 merged commit d9f0875 into main May 5, 2026
9 of 10 checks passed
@teknium1 teknium1 deleted the salvage/pr-13639 branch May 5, 2026 17:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists platform/discord Discord bot adapter type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants