Amazon Ergo 1.0 · 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
- 3 of 4
- Comments published
- 9
- Comments matching a bug
- 3
- Comments not matching
- 6
- Cost of this PR
- $2.593
Published comments (9)
Per-process buffers distort flush budgets and backpressure — With one shard per process, `any_shard_at_limit` may never set `backpressure_since`, disabling `MessageRejected` backpressure while per-process fetch budgets multiply the consumer-wide cap. In `SpansBuffer.flush_segments` (`buffer.py`), derive the fetch budget and backpressure threshold from the consumer's total assigned shard count, not local `assigned_shards`.
submit() fetches cluster-wide memory info once per flusher process — Enabling multiple flusher processes repeats identical cluster-wide Redis `INFO` fan-out on the consumer's main thread, adding latency to every batch. Call `get_memory_info()` on just one buffer and reuse the result for `max_memory_percentage`; the buffers share a cached `RedisCluster` client, and each call reaches `iter_cluster_memory_usage` in `processing/backpressure/memory.py`.
Hung spawn-based flusher processes are never killed before restart — Restarting a hung flusher can leave two processes producing segments for the same shards and leak one process per restart. `self.mp_context` creates `SpawnProcess` objects, not `multiprocessing.Process` instances, making the current check always false; use `if not isinstance(process, threading.Thread):` before `process.kill()`.
Zero `--flusher-processes` silently enables maximum parallelism — An invalid setting can unexpectedly create one process per shard, multiplying resource use instead of failing fast. Replace `max_processes or len(buffer.assigned_shards)` with an explicit `is not None` fallback, and raise `ValueError` when `max_processes < 1` so `--flusher-processes 0` is rejected.
Monkeypatched time.sleep makes the flusher wait a no-op — On a slow machine, the flusher can exit before flushing under the new drift, making this test flaky because the monkeypatched `time.sleep` returns immediately and `step.poll()` never polls the flusher. Poll until `messages` is non-empty using `threading.Event.wait()`, or use the real `from time import sleep` alias from `test_flusher.py`.
Shard assignment test does not verify distribution across processes — A regression could assign all four shards to one process and leave the other idle while this assertion still passes, silently losing the intended parallelism. Assert `sorted(len(shards) for shards in flusher.process_to_shards_map.values()) == [2, 2]` instead of checking only `total_shards`.
Deadline expiry skips termination of remaining flusher processes — Shutdown can leave later flushers running: once `deadline` expires, `break` skips their termination and `join()` returns with hung processes alive. Remove the early `break` so every process reaches `process.terminate()`; the `while` condition already prevents further waiting.
Inconsistent `shard` tag format: comma-joined list vs single shard number — Per-shard queries cannot correlate these metrics because `shard` is a comma-joined list here but a single number in `flusher_unhealthy`. Use `shards` for the list in `spans.buffer.flusher.produce` and `spans.buffer.segment_size_bytes`, or emit one tag per shard.
wait_produce metric uses inconsistent `shards` tag key — Dashboards and queries keyed on `shard` silently omit `spans.buffer.flusher.wait_produce`, because it alone uses `shards` for the same `shard_tag`. Change this timer's tag key to `shard` to match the produce and segment-size metrics.