Kimi K3.1 Pro · 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 Haiku 5.5.

Gold bugs found
2 of 2
Comments published
9
Comments matching a bug
2
Comments not matching
7
Cost of this PR
$1.927

Published comments (9)

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

Memory backpressure repeats cluster-wide scans for every shard buffer — `SpansBuffer.get_memory_info()` ignores `assigned_shards` and scans every master, so this loop repeats the cluster-wide fan-out once per flusher process during every `submit` on the consumer thread. Fetch memory info once and compute the totals from that shared result.

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

Per-process metrics polling causes N sequential Redis round trips — `record_stored_segments()` runs a blocking Redis pipeline for each flusher process on every `submit`, replacing one all-shards poll with N sequential round trips on the consumer thread. Keep one all-shards buffer for this poll or batch every queue-size `ZCARD` into one pipeline.

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

Produce metrics use inconsistent shard tag keys — A common shard filter or aggregation cannot match all produce-phase metrics because `spans.buffer.flusher.wait_produce` tags `shard_tag` as `shards`, while the other two metrics use `shard`. Use `shard` consistently across all three metrics.

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

max_processes=0 is silently treated as an unset value — Passing `max_processes=0` through `--flusher-processes` unexpectedly enables one process per shard because the truthiness fallback treats it like `None`. Default only when `max_processes is None`, reject nonpositive counts, and constrain the CLI option with `click.IntRange(min=1)`.

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

Shard count assertion does not verify distribution across processes — The summed count still passes if process 0 owns every shard and process 1 owns none, so broken distribution can go undetected. Assert `flusher.process_to_shards_map` equals the expected per-process mapping, such as `{0: [0, 2], 1: [1, 3]}`.

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

Hang recovery skips killing spawn-based flusher processes — On Linux, the spawn context creates a `SpawnProcess`, so the `multiprocessing.Process` guard skips `kill()` and `_create_process_for_shards` can start a replacement while the hung worker keeps flushing the same shards. Guard with `multiprocessing.process.BaseProcess` or the spawn context's process type.

mediumbugsrc/sentry/spans/consumers/process/flusher.py:337-347

Expired join deadline skips termination of remaining flusher workers — Because `next_step.join(timeout)` can consume the whole deadline, the timeout `break` can exit before any `terminate()` and skip every later worker, leaving hung daemons flushing after shutdown. Attempt termination for every process even after the deadline, bounding only the graceful waits.

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

Negative max_processes causes a KeyError during flusher startup — A negative `max_processes` leaves `process_to_shards_map` empty, so startup raises `KeyError` on `self.process_to_shards_map[process_index]`. Reject values below 1 before computing `num_processes`, and restrict `--flusher-processes` with `click.IntRange(min=1)`.

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

Intended flusher delay is a no-op under the sleep monkeypatch — The test's `time.sleep` monkeypatch makes `time.sleep(0.1)` return immediately, providing no processing delay before the test reaches `join()`. Use real waiting or synchronization instead of the no-op sleep.

Gold bugs found (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.

Gold bugs missed (0)

None.