# PR #25710 完整报告

- 仓库：`sgl-project/sglang`
- 标题：Remove the dead hasattr fallback around the test-only crash counter
- 合并时间：2026-05-19 09:17
- 原文链接：http://prhub.com.cn/sgl-project/sglang/pull/25710

---

# 执行摘要

- 一句话：移除测试崩溃计数器的冗余 hasattr 保护
- 推荐动作：简单清理，可安全合并。

# 功能与动机

消除死代码，简化测试辅助逻辑。__init__已确保属性存在，hasattr 检查不再必要。

# 实现拆解

在 `_trigger_crash_for_tests` 方法中删除两行：
 - `if not hasattr(self, "_test_stream_output_count"):`
 - `self._test_stream_output_count = 0`
 由于 `__init__` 已设置为 0，该赋值不再需要。

关键文件：
- `python/sglang/srt/managers/scheduler_components/output_streamer.py`（模块 调度器；类别 source；类型 core-logic；符号 _trigger_crash_for_tests）: 删除 _trigger_crash_for_tests 中的 hasattr fallback，简化测试崩溃计数器逻辑。

关键符号：_trigger_crash_for_tests

## 关键源码片段

### `python/sglang/srt/managers/scheduler_components/output_streamer.py`

删除 _trigger_crash_for_tests 中的 hasattr fallback，简化测试崩溃计数器逻辑。

```python
# python/sglang/srt/managers/scheduler_components/output_streamer.py
# __init__ 已经设置了 self._test_stream_output_count = 0，因此 hasattr 检查是冗余的。
def _trigger_crash_for_tests(self, crash_threshold: int):
    # Crash trigger: crash after stream_output is called N times
    # This is used for testing purposes.
    self._test_stream_output_count += 1
    if self._test_stream_output_count >= crash_threshold:
        raise RuntimeError(
            f"Test crash after stream_output called {self._test_stream_output_count} times"
        )

```

# 评论区精华

无讨论。

- 暂无高价值评论线程

# 风险与影响

- 风险：风险极低：属性已在 __init__中初始化，删除 hasattr 不会改变行为。
- 影响：仅影响测试崩溃触发逻辑，无用户可见影响。
- 风险标记：低风险

# 关联脉络

- PR #25712 Pack scattered request logprob state into a dedicated container: 同样重构了 SchedulerOutputStreamer 相关的数据结构，属于同一重构链条。