Skip to content

refactor(bot)!: remove gateway sharding - #199

Merged
TheMeinerLP merged 3 commits into
mainfrom
refactor/remove-gateway-sharding
Nov 8, 2026
Merged

TheMeinerLP merged 3 commits into
mainfrom
refactor/remove-gateway-sharding

Conversation

@TheMeinerLP

@TheMeinerLP TheMeinerLP commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Sturnus is installed for one guild, but the bot was still built for many. It opened several gateway connections (shards) and kept per-shard state for them. From the operator's side that showed up in three places:

  • /readyz waited for "every shard this process is supposed to hold", a rule that only means something for a bot in thousands of guilds. The probe body reported shard numbers that were the same for every installation.
  • on_ready no longer ran the way discord.py code expects. The reconcile had moved into a per-shard hook, so the usual place to look for it was empty.
  • Log lines carried a shard_id that is 0 on every line, and docs/operations.md section 3.6 explained a mechanism nobody could use.

Discord only asks for sharding from 2,500 guilds on (gateway docs). One guild is far below that, so the decision is to hold one gateway connection, let /readyz report that one connection, and remove STURNUS_SHARD_COUNT.

The failure this prevents is a readiness probe that can go red for a state that cannot occur, and a pod that crash-loops over a leftover variable. A deployment that still sets STURNUS_SHARD_COUNT starts normally and logs once that the variable is ignored. Unset it after upgrading.

This is the first part of the OpenSpec change remove-multi-guild-machinery. The removal of per-guild OAuth sign-in and its migration ship in a separate PR. The change as a whole needs single-guild-instance deployed first, as its proposal states.

Checks

pytest 2724 passed · ruff check and ruff format --check clean · mypy no issues in 293 files · helm template charts/sturnus renders

BEGIN_COMMIT_OVERRIDE
refactor(bot)!: remove gateway sharding

BREAKING CHANGE: STURNUS_SHARD_COUNT is gone. The bot holds a single gateway connection, and /readyz reports that one connection.
END_COMMIT_OVERRIDE

Sturnus serves one guild per installation, so the bot holds one Discord
gateway connection. The sharded client, per-shard readiness and the
shard_id log field were built for many guilds and only made /readyz wait
for shards that never exist.

- SturnusClient is a commands.Bot again. on_ready reconciles every guild.
- on_disconnect clears the single gateway flag and logs one WARNING
  (bot.disconnected); on_resumed sets the flag and logs INFO (bot.resumed).
- ReadinessState is one gateway flag plus the database flag.
- STURNUS_SHARD_COUNT is removed from settings, chart and docs. A leftover
  value is ignored and logged once at startup.
- application/sharding.py and its tests are deleted.

BREAKING CHANGE: STURNUS_SHARD_COUNT is gone; the bot holds a single gateway
 connection and /readyz reports that one connection.
@TheMeinerLP
TheMeinerLP force-pushed the refactor/remove-gateway-sharding branch from 86a80b7 to 2cc3a4f Compare November 8, 2026 12:19
@TheMeinerLP
TheMeinerLP merged commit 758f289 into main Nov 8, 2026
12 checks passed
@TheMeinerLP
TheMeinerLP deleted the refactor/remove-gateway-sharding branch November 8, 2026 12:49
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