GLM-5.3 Flash · Heavy

span-buffer-multiprocess-enhancement-with-health-monitoring-sentry

Sentry · Python · M · 100–299 lines · 4 files

The generalist plus 9 specialist lens agents in parallel, then the same verify and dedup steps. Judge: Claude Opus 5.5.

Gold bugs found
2 of 4
Comments published
8
Comments matching a bug
2
Comments not matching
6
Cost of this PR
$0.181

Published comments (8)

mediumperformancesrc/sentry/spans/consumers/process/flusher.py:299-301

submit() queries cluster memory info once per buffer, duplicating blocking Redis INFO calls — The blocking cluster-wide Redis INFO round-trip in `buffer.get_memory_info()` runs once per buffer on the consumer loop, so duplicated I/O grows with process count while the resulting ratio is unchanged. Every buffer shares the same Redis cluster, so query it once and reuse the result.

mediumperformancesrc/sentry/spans/consumers/process/flusher.py:269-270

record_stored_segments runs one sequential Redis pipeline per buffer in submit — A batch submit that previously took one Redis round trip now takes one sequential pipeline per buffer, so latency grows with process count. Aggregate the zcard sampling into a single pipeline over all assigned shards instead of calling `record_stored_segments()` per buffer.

mediumbugsrc/sentry/spans/consumers/process/flusher.py:59-66

N flusher processes each use the full max-flush-segments budget — Each buffer computes `max_segments_per_shard` from its own shard subset, so total flush work reaches N times `max-flush-segments` and Redis backpressure only trips at N times the intended backlog. Divide the global budget across processes, deriving the per-shard page size from the total shard count.

mediumbugsrc/sentry/spans/consumers/process/flusher.py:47-51

`max_processes or ...` treats explicit 0 as missing, silently maximizing parallelism — Passing `--flusher-processes 0` silently spawns one process per shard, the opposite of the requested limit, because the truthiness test swallows 0. Use an `is not None` check and validate a minimum of 1 on the option.

mediumbugtests/sentry/spans/consumers/process/test_consumer.py:60-62

Patched-out sleep makes flusher wait a no-op — This wait never happens because the test replaces `time.sleep` with a no-op earlier, so the race the comment targets stays unfixed. Poll until `messages` is non-empty instead of sleeping.

mediumbugtests/sentry/spans/consumers/process/test_consumer.py:119-121

Test only checks total shard count, not distribution across processes — If the mapping ever assigned all four shards to a single process, `total_shards` would still equal 4 and every assertion would pass. Assert the distribution itself, for example that each of the two processes received shards in `process_to_shards_map`.

mediumbugsrc/sentry/spans/consumers/process/flusher.py:253-259

Hung thread-based flusher is duplicated on restart instead of being stopped — Threads cannot be killed, so skipping `kill()` still leaves the hung thread polling its shards while `_create_process_for_shards` starts a second one, and both produce duplicate segment payloads. Stop or disable the old thread first, or skip the restart and surface the failure.

mediumbugsrc/sentry/spans/consumers/process/flusher.py:199

Metric tag key `shards` inconsistent with `shard` used elsewhere — Dashboards or alerts querying one emit site will miss or split the data because the other flusher metrics tag the same value as `shard`. Use `shard` here too so all four emit sites agree.

Gold bugs found (2)

mediumsubmit() queries cluster-wide Redis memory once per flusher buffer, repeating identical INFO calls per process on every submit.
medium_ensure_processes_alive only kills the old flusher when isinstance(process, multiprocessing.Process), but it always starts a replacement. A hung thread-based flusher, and even a spawn-context process (SpawnProcess is not a multiprocessing.Process subclass), keeps running beside the new one, so both flush and produce the same shards' segments and duplicate output.

Gold bugs missed (2)

highThe restart path only kills a hung flusher if it is a multiprocessing.Process, but spawn-context workers are SpawnProcess, so hung processes are never killed and a duplicate flusher is started for the same shards.
mediumjoin() breaks out of the per-process loop when the shared deadline expires, skipping termination of the remaining flusher processes and leaving them running after shutdown.