feat(ci): xdist per-worker isolation infrastructure#110775
Merged
mchen-sentry merged 4 commits intomasterfrom Mar 16, 2026
Merged
feat(ci): xdist per-worker isolation infrastructure#110775mchen-sentry merged 4 commits intomasterfrom
mchen-sentry merged 4 commits intomasterfrom
Conversation
Contributor
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix prepared a fix for the issue found in the latest run.
- ✅ Fixed: Falsy-zero check masks xdist worker 0 identity
- Changed 'xdist._worker_num or 0' to 'xdist._worker_num if xdist._worker_num is not None else 0' in relay.py to properly distinguish worker 0 from non-xdist case, matching the pattern used throughout the codebase.
Or push these changes by commenting:
@cursor push 99ad560e14
Preview (99ad560e14)
diff --git a/src/sentry/testutils/pytest/relay.py b/src/sentry/testutils/pytest/relay.py
--- a/src/sentry/testutils/pytest/relay.py
+++ b/src/sentry/testutils/pytest/relay.py
@@ -68,7 +68,7 @@
template_path = _get_template_dir()
sources = ["config.yml", "credentials.json"]
- worker_num = xdist._worker_num or 0
+ worker_num = xdist._worker_num if xdist._worker_num is not None else 0
relay_port = ephemeral_port_reserve.reserve(ip="127.0.0.1", port=33331 + worker_num * 100)
redis_db = xdist.get_redis_db()This Bugbot Autofix run was free. To enable autofix for future PRs, go to the Cursor dashboard.
91a5699 to
e4a26bb
Compare
Give each xdist worker its own Redis DB, Kafka topic names, Snuba instance, Relay container, and snowflake ID range. All gated on xdist env vars — no-ops without them. - New xdist.py module with get_redis_db(), get_kafka_topic(), get_snuba_url() - Per-worker Relay container names and port offsets - Deterministic region name seeding across workers - Per-worker snowflake IDs to avoid IntegrityError collisions - Disable pytest-rerunfailures crash recovery (broken under xdist due to Sentry's global socket timeout)
The Span NamedTuple dropped end_timestamp in e40ec24 but this test callsite was missed, causing mypy to fail.
e4a26bb to
290270e
Compare
…t workers Redis defaults to 16 databases (0-15). With a base DB of 9, we can support at most 7 workers before hitting an out-of-range error. Fail fast with a clear message instead of a cryptic Redis error.
joshuarli
reviewed
Mar 16, 2026
joshuarli
approved these changes
Mar 16, 2026
JonasBa
pushed a commit
that referenced
this pull request
Mar 16, 2026
3 tasks
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.


When pytest-xdist spawns multiple workers inside a single CI shard, all workers share ci infrasturcture (Redis, Kafka, Snuba, and Relay). Without isolation, workers corrupt each other (e.g.
reset_snuba/flushdb(), Kafka events pollute, identical snowflake IDs).This PR gives each worker its own isolated resources. Everything is gated on xdist env vars, so this change will be a no-op on master as is.
Changes
xdist.py- resolves worker ID at module level, provides helpers (e.g.get_redis_db())pytest-rerunfailuresas this is broken under xdist due to Sentry's globalsocket.setdefaulttimeout(5), normal--rerunsunaffected