fix: skip hedge dispatch when primary finishes during admission
Address branch review findings 1-4 on feature/1.3.7-hedged-requests: - src/polygateway/middleware/retry.py: recheck primary.done() after hedge admission in _attempt_hedged; release the hedge permit via settle_and_release(permit, 0) (release_probe for probe entries) and adjudicate the primary directly instead of firing a billable HTTP request that would be cancelled immediately - src/polygateway/config.py: check_hedge_assembly raises a hedge-located ValueError for empty sources instead of a bare min() error - tests/unit/test_hedge.py: pin that an injected FakeClock jump of 10^6 seconds does not trigger hedging (design section 8); pin pick(exclude) counting no gate_rejections and leaving reasons untouched; pin silent hedge abandonment when the candidate circuit is open; deterministic regression for the admission-window race (BlockingLimiter harness) - tests/unit/test_config.py: assert the empty-sources guard message locates the hedge key Red-to-green evidence in tests/outputs/137/review-fixes/
This commit is contained in:
@@ -1166,6 +1166,31 @@ class TestHedgeConfig:
|
||||
with pytest.raises(ValueError, match=r"GatewayClient\(hedge_after_s"):
|
||||
_client(hedge_after_s=0)
|
||||
|
||||
def test_hedge_guard_empty_sources_raises_with_hedge_location(self):
|
||||
"""直传路空 sources + 设阈值: ValueError 且消息定位到 hedge(不是裸 min() 报错)。"""
|
||||
from polygateway.config import check_hedge_assembly
|
||||
|
||||
with pytest.raises(ValueError, match="sources") as ei:
|
||||
check_hedge_assembly(
|
||||
hedge_after_s=8,
|
||||
hedge_max_extra=1,
|
||||
sources=[],
|
||||
call_deadline_s=None,
|
||||
origin="GatewayClient(hedge_after_s=8)",
|
||||
)
|
||||
assert "hedge_after_s" in str(ei.value) # 定位得到是哪个键
|
||||
# 未启用对冲(None)时空 sources 直接放行: 交叉守卫没有可校验的对象
|
||||
assert (
|
||||
check_hedge_assembly(
|
||||
hedge_after_s=None,
|
||||
hedge_max_extra=1,
|
||||
sources=[],
|
||||
call_deadline_s=None,
|
||||
origin="test",
|
||||
)
|
||||
is None
|
||||
)
|
||||
|
||||
def test_hedge_guard_below_min_timeout_raises(self):
|
||||
"""阈值 ≥ 最小源 timeout_s = 对冲永不可能触发,装配期炸掉(ValueError)。"""
|
||||
env = self._two_source_env(**{"LLM__HEDGE__AFTER_S": "90"}) # min(timeout)=90
|
||||
|
||||
Reference in New Issue
Block a user