Skip to content

Improve bot performance, moderation reliability, and runtime lifecycle - #219

Merged
SlimShadyIAm merged 29 commits into
mainfrom
codex/architecture-performance-review
Nov 6, 2026
Merged

SlimShadyIAm merged 29 commits into
mainfrom
codex/architecture-performance-review

Conversation

@SlimShadyIAm

@SlimShadyIAm SlimShadyIAm commented Oct 17, 2026 •

Copy link
Copy Markdown
Member

The bot performs synchronous database and SDK work in Discord event handlers, accumulates image/logging work during bursts, and can record failed moderation actions as successful. This modernization batch isolates blocking persistence throughout the bot and fixes scheduler and moderation correctness issues while retaining the existing stack.

Changes

  • Make every bot-facing user/guild service operation awaitable using a bounded database pool. Offload document saves, GridFS reads/writes and metadata, report/history queries, autocomplete queries, and cache misses. Materialize birthday queries in workers, prefetch case-page profiles, and remove import-time database access.
  • Move APScheduler polling and persistent job mutations to a dedicated thread. Dispatch Discord callbacks onto the bot loop, preserve stored callback references, and drain/cancel work during shutdown. Support namespaced and legacy giveaway cancellation.
  • Award XP atomically; remove redundant database reads and isolate synchronous Spotify calls.
  • Reuse managed HTTP connections; bound image and webhook-log queues; prioritize inexpensive abuse checks and measure runtime lag, memory, and backlog.
  • Allocate case numbers atomically, share moderation execution, and record bans/kicks only after Discord accepts them. Prevent old expiry jobs or report dismissals from clearing newer timeouts.
  • Keep secrets out of Docker images, make setup/profile creation idempotent, and preserve historical case dates.
  • Add regression tests, an all-extension startup/shutdown smoke test, and real-MongoDB CI coverage.

Review

Changes remain in separate commits against main. The latest additions are:

  • 979ae2c: MongoEngine service and GridFS isolation across handlers.
  • ed422c4: persistent scheduler storage on a dedicated thread.
  • 06f3b1a: rollout documentation and import-without-database smoke coverage.

The preceding anti-raid enhancements are already merged in #218 and are not duplicated here. The jailbreak-chart URL and Instagram-link changes from main are retained.

docs/modernization.md lists the commit history, operational behavior changes, rollout checks, and remaining migrations.

Validation

  • 47 tests discovered: 44 passed, 3 real-MongoDB concurrency tests skipped locally.
  • Tests verify loop responsiveness during slow database/job-store operations, scheduler callback loop affinity and shutdown cancellation, GridFS operations, materialized birthday queries, and awaited service calls.
  • All configured extensions load and resources close using example configuration without live services. Module imports succeed before a database connection exists.
  • Python compilation, whitespace checks, and dependency consistency checks passed.
  • Local validation used Python 3.9 with pinned runtime dependencies; CI uses Python 3.10 and a real MongoDB service. CI results for the new head have not been verified.
  • Production image build and real-MongoDB tests were not run locally because the Docker daemon was unavailable.

Rollout considerations

  • MongoEngine is still synchronous internally, but its I/O is isolated from the Discord event loop. Production latency/throughput gains remain to be measured; slow queries still need query/index analysis.
  • Image overload skips excess scans; scheduler rollback requires reconciling namespaced jobs.
  • Database failure after a successful Discord action still needs durable reconciliation. Persistent report restoration, immutable persistence snapshots, schema migration, and dependency/runtime upgrades remain follow-up work.
  • No production deployment or database migration has been performed.

@SlimShadyIAm
SlimShadyIAm changed the base branch from feature/antiraid-hidden-invites-scam-images to main October 17, 2026 21:12
@SlimShadyIAm
SlimShadyIAm force-pushed the codex/architecture-performance-review branch from 472d654 to a51a111 Compare October 17, 2026 21:14
@SlimShadyIAm
SlimShadyIAm force-pushed the codex/architecture-performance-review branch from 06f3b1a to f078588 Compare October 25, 2026 09:35
@SlimShadyIAm
SlimShadyIAm force-pushed the codex/architecture-performance-review branch from f078588 to eef3813 Compare November 6, 2026 19:28
@SlimShadyIAm
SlimShadyIAm merged commit de3b507 into main Nov 6, 2026
4 checks passed
@SlimShadyIAm
SlimShadyIAm deleted the codex/architecture-performance-review branch November 6, 2026 21:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant