This repository was archived by the owner on Nov 13, 2026. It is now read-only.
Repository navigation
feat: deploy behind a gateway proxy instead of reconnecting shards - #133
Merged
Merged
Conversation
Production can now run Gelbpunkt's gateway-proxy, which holds the shard connections and replays READY/GUILD_CREATE from its cache when the bot connects. A deploy restarts only the bot and sends no IDENTIFY. - DISCORD_GATEWAY_URL points discord.py at the proxy and skips the 5-second IDENTIFY spacing; SHARD_COUNT is required and checked against the proxy's /shard-count at startup. - The proxy is a compose service behind the gateway-proxy profile, pinned by digest; `just deploy` never touches it, `just deploy-proxy` recreates it. - MIGRATE_ON_START=false skips the boot-time migration in production. - Remove the bot-side RESUME machinery (SessionPersister, launch_shard override, session save on close, IDENTIFY lock): a fresh process that RESUMEs gets no READY or GUILD_CREATE and starts with an empty cache. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`just deploy` now checks out the latest v* release tag (prereleases excluded), or the tag or branch passed to it, instead of resetting to origin/main. Restores the explicit SHARD_COUNT requirement behind the gateway proxy. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Restarting a bot with many guilds re-IDENTIFIES every shard, and Discord allows one IDENTIFY per 5 seconds (~2 min for 31k guilds). Any deploy, even a one-line change in
args/orhelpers/, paid that cost.The existing bot-side RESUME path (
BOT_MODE=clusteredonly) could not fix this: after a RESUME Discord sends noREADYorGUILD_CREATE, so a fresh process starts withbot.user = Noneand an empty guild cache.What
READY+GUILD_CREATEs from its cache. It runs as thegateway-proxycompose profile, using the upstreamznver3image pinned by digest, with its config ingateway-proxy.jsonand the token fromTOKEN.DISCORD_GATEWAY_URLpoints discord.py's default gateway at the proxy, so re-identifies after an invalidated session also stay behind it. In that mode:SHARD_COUNTis required, and the bot refuses to start if it differs from the proxy's/shard-count;zlib-stream, which is the only compression the proxy produces.just deploychecks out the latest release tag (orjust deploy <tag|branch>, e.g.mainfor beta) instead oforigin/main, then builds and restarts only the default services (db lavalink redis bot), so it never touches the proxy. The newjust deploy-proxyrecreates the proxy; use it only for proxy upgrades and shard count changes.MIGRATE_ON_START=falseskips thealembic upgrade headrun on boot, becausejust deployalready migrates. The default (true) keeps self-hosting unchanged.SessionPersister/RedisSessionPersister, thelaunch_shardRESUME override, the session save and close code 4000 inclose(), and the IDENTIFY lock..env.example, aGLOSSARY.mddecision, and theAGENTS.mdmodule index.Notes for review
cache.usersis on. The proxy drops cached members whose user isn't cached, and without itguild.mewould be missing after a replay.intentsingateway-proxy.json(53608447) isdiscord.Intents.all(). The proxy identifies with its own intents, so the two must be kept in sync by hand.SHARD_COUNTcompose default. It's now empty instead of64, so the bot can tell whether it was set.ClusterConfigstill falls back to 64.Test plan
ruff format --check,ruff check,ty check,pytest(424 passed)guild.meand the caches are populatedjust deploywhile running; measure the gap, and confirm in the proxy logs that no shard reconnectsjust deploy-proxy; confirm the bot reconnects on its own🤖 Generated with Claude Code