|
9 | 9 | from dataclasses import dataclass, field |
10 | 10 | from typing import Any, Callable, Dict, Iterable |
11 | 11 |
|
| 12 | +_SCORE_EPS = 0.001 |
| 13 | + |
| 14 | + |
| 15 | +def _clamp_score(value: object) -> float: |
| 16 | + """Ensure a score is strictly inside (0, 1) for validator compliance.""" |
| 17 | + try: |
| 18 | + v = float(value) # type: ignore[arg-type] |
| 19 | + except (TypeError, ValueError): |
| 20 | + v = 0.5 |
| 21 | + return round(max(_SCORE_EPS, min(v, 1.0 - _SCORE_EPS)), 3) |
| 22 | + |
12 | 23 | from openai import OpenAI |
13 | 24 | from openenv.core.utils import run_async_safely |
14 | 25 |
|
@@ -473,15 +484,15 @@ def _execute_episode( |
473 | 484 | "step": observation.step_number, |
474 | 485 | "tool_name": action.tool_call.tool_name, |
475 | 486 | "success": None if observation.last_tool_result is None else observation.last_tool_result.success, |
476 | | - "score": round(float(observation.reward or 0.0), 3), |
| 487 | + "score": _clamp_score(observation.reward), |
477 | 488 | "done": observation.done, |
478 | 489 | "terminal_outcome": observation.metadata.get("terminal_outcome", "in_progress"), |
479 | 490 | }, |
480 | 491 | verbose, |
481 | 492 | ) |
482 | 493 |
|
483 | 494 | outcome = observation.metadata.get("terminal_outcome", "unknown") |
484 | | - score = round(float(observation.metadata.get("episode_score", observation.reward or 0.0)), 3) |
| 495 | + score = _clamp_score(observation.metadata.get("episode_score", observation.reward)) |
485 | 496 | total_points = round(float(observation.metadata.get("debug_total_points", 0.0)), 2) |
486 | 497 | _emit( |
487 | 498 | "END", |
|
0 commit comments