Repository navigation
fix(explore): reject non-finite replay weights and score floors #7574
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
gcl-coder
wants to merge
2
commits into
loopx-project:main
from
gcl-coder:fix/adaptive-replay-numeric-inputs
+78
−15
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,20 +10,38 @@ | |
| from .trace_runtime import TraceLog, require_nonempty_text | ||
|
|
||
|
|
||
| def _nonnegative(value: float, field_name: str) -> float: | ||
| def _finite_number(value: float, field_name: str, *, allow_zero: bool) -> float: | ||
| """Normalize a public numeric input without admitting NaN or overflow. | ||
|
|
||
| ``float("nan") < 0`` and ``float("nan") <= 0`` are both false, so a | ||
| comparison-only guard admits NaN; a NaN then makes every later floor | ||
| comparison false too, which turns a bound into a pass-through. Booleans are | ||
| refused because ``float(True)`` is silently ``1.0``, and integers too large | ||
| for a float are refused so the raw ``OverflowError`` does not escape | ||
| validation as a non-field-specific error. | ||
| """ | ||
|
|
||
| requirement = "non-negative" if allow_zero else "positive" | ||
| message = f"{field_name} must be a finite {requirement} number" | ||
| if isinstance(value, bool): | ||
| raise ValueError(f"{field_name} must be a finite non-negative number") | ||
| raise ValueError(message) | ||
| try: | ||
| normalized = float(value) | ||
| except (OverflowError, TypeError, ValueError) as exc: | ||
| raise ValueError( | ||
| f"{field_name} must be a finite non-negative number" | ||
| ) from exc | ||
| if not math.isfinite(normalized) or normalized < 0: | ||
| raise ValueError(f"{field_name} must be a finite non-negative number") | ||
| raise ValueError(message) from exc | ||
| if not math.isfinite(normalized) or normalized < 0 or (normalized == 0 and not allow_zero): | ||
| raise ValueError(message) | ||
| return normalized | ||
|
|
||
|
|
||
| def _nonnegative(value: float, field_name: str) -> float: | ||
| return _finite_number(value, field_name, allow_zero=True) | ||
|
|
||
|
|
||
| def _positive(value: float, field_name: str) -> float: | ||
| return _finite_number(value, field_name, allow_zero=False) | ||
|
|
||
|
|
||
| @dataclass(frozen=True) | ||
| class ReplayPositionCost: | ||
| """Public-safe Adapter estimate for one addressable trace boundary.""" | ||
|
|
@@ -94,10 +112,7 @@ def __post_init__(self) -> None: | |
| ) | ||
| if self.minimum_fidelity == ReplayFidelity.NON_REPLAYABLE: | ||
| raise ValueError("failure observations require replayable fidelity") | ||
| normalized_weight = float(self.weight) | ||
| if normalized_weight <= 0: | ||
| raise ValueError("weight must be positive") | ||
| object.__setattr__(self, "weight", normalized_weight) | ||
| object.__setattr__(self, "weight", _positive(self.weight, "weight")) | ||
|
|
||
|
|
||
| @dataclass(frozen=True) | ||
|
|
@@ -167,9 +182,8 @@ def plan_adaptive_replay_points( | |
| for observation in normalized_observations | ||
| ): | ||
| raise TypeError("observations must contain FailureReplayObservation values") | ||
| if int(max_proposals) <= 0: | ||
| raise ValueError("max_proposals must be positive") | ||
| threshold = float(minimum_score_minutes) | ||
| proposal_limit = int(_positive(max_proposals, "max_proposals")) | ||
| threshold = _nonnegative(minimum_score_minutes, "minimum_score_minutes") | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [P2] 对分数下界验证有限性,保留其符号。minimum_score_minutes=-1原来合法:保存1分钟减捕获2分钟的候选score=-1可用于诊断,base会返回;当前_nonnegative直接ValueError。成本非负不等于过滤下界非负,#6094的要求针对cost。请保留有限负下界并补正/零/负对照;不能将此范围收窄称作valid inputs unchanged。 |
||
| for candidate in normalized_candidates: | ||
| _validate_position(trace, candidate) | ||
| for observation in normalized_observations: | ||
|
|
@@ -226,4 +240,4 @@ def plan_adaptive_replay_points( | |
| proposal.after_event_id or "", | ||
| ) | ||
| ) | ||
| return tuple(proposals[: int(max_proposals)]) | ||
| return tuple(proposals[:proposal_limit]) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[P2] 在int转换后验证上限仍为正。相同合法trace/candidates/observations,max_proposals=0.5在不可变base ffc90182中抛ValueError;当前_positive(0.5)通过后int成0,静默返回空tuple,输入错误被伪装成没有候选。请在最终proposal_limit上保留>0检查,并补0.5以及声明要兼容的2.9→2对照。