@@ -2117,7 +2117,7 @@ def _is_token_limit_exceeded(self) -> bool:
21172117 :return: True if a positive token limit is set and ``_total_token_usage >= token_limit``.
21182118 """
21192119 limit : Optional [int ] = getattr (self ._options , "token_limit" , None )
2120- return bool ( limit ) and self ._total_token_usage >= limit
2120+ return limit is not None and limit > 0 and self ._total_token_usage >= limit
21212121
21222122 def _evaluate_response (self , optimize_context : OptimizationContext ) -> bool :
21232123 """
@@ -2282,11 +2282,12 @@ def _apply_duration_gate(
22822282 rationale = "Latency gate passed (no baseline)."
22832283 score = 1.0
22842284 else :
2285+ baseline_dur = self ._baseline_duration_ms or 0.0
22852286 rationale = (
22862287 f"Latency improvement gate failed: { ctx .duration_ms :.0f} ms did not improve "
22872288 f"by { int ((1 - _DURATION_TOLERANCE ) * 100 )} % vs baseline "
2288- f"{ self . _baseline_duration_ms :.0f} ms "
2289- f"(required < { self . _baseline_duration_ms * _DURATION_TOLERANCE :.0f} ms)."
2289+ f"{ baseline_dur :.0f} ms "
2290+ f"(required < { baseline_dur * _DURATION_TOLERANCE :.0f} ms)."
22902291 )
22912292 score = 0.0
22922293 ctx = dataclasses .replace (
@@ -2335,11 +2336,12 @@ def _apply_cost_gate(
23352336 rationale = "Cost gate passed (no baseline)."
23362337 score = 1.0
23372338 else :
2339+ baseline_cost = self ._baseline_cost_usd or 0.0
23382340 rationale = (
23392341 f"Cost improvement gate failed: { ctx .estimated_cost_usd :.6f} did not improve "
23402342 f"by { int ((1 - _COST_TOLERANCE ) * 100 )} % vs baseline "
2341- f"{ self . _baseline_cost_usd :.6f} "
2342- f"(required < { self . _baseline_cost_usd * _COST_TOLERANCE :.6f} )."
2343+ f"{ baseline_cost :.6f} "
2344+ f"(required < { baseline_cost * _COST_TOLERANCE :.6f} )."
23432345 )
23442346 score = 0.0
23452347 ctx = dataclasses .replace (
0 commit comments