Skip to content

fix(exec-harness): reject negative and non-finite numeric durations - #528

Open
mohamedAtoui wants to merge 1 commit into
CodSpeedHQ:mainfrom
mohamedAtoui:fix/reject-negative-durations
Open

fix(exec-harness): reject negative and non-finite numeric durations#528
mohamedAtoui wants to merge 1 commit into
CodSpeedHQ:mainfrom
mohamedAtoui:fix/reject-negative-durations

Conversation

@mohamedAtoui

@mohamedAtoui mohamedAtoui commented Sep 5, 2026

Copy link
Copy Markdown

Fixes #364.

Bare numeric walltime durations were parsed with f64::from_str and converted with a saturating as u64 cast. That silently turned -1, -0.5 and NaN into 0, and inf into u64::MAX. Since a max_time of 0 means "unlimited", --max-time -1 ran the warmup phase and only failed afterwards with Unable to determine number of rounds to perform.

The numeric branch now builds a Duration with Duration::try_from_secs_f64, which already rejects negative, NaN and infinite values, and both branches share the single nanosecond conversion at the end. The error surfaces during argument validation, with the standard library explaining the cause:

Error: Invalid max_time

Caused by:
    0: Invalid duration: '-1'. Expected a finite, non-negative number of seconds
    1: cannot convert float seconds to Duration: value is negative

Humantime inputs such as -1s were already rejected by humantime::parse_duration, so that branch is unchanged.

Note for reviewers: -0 parses as -0.0, which try_from_secs_f64 accepts, so it stays valid and yields 0. That is intentional, 0 is the documented way to disable warmup, and it is covered by a test.

Adds unit tests for the rejected values, for 0/-0 remaining valid, and one covering the reported --max-time -1 path end to end.

@greptile-apps

greptile-apps Bot commented Sep 5, 2026

Copy link
Copy Markdown

Greptile Summary

This PR tightens wall-time duration validation before converting numeric seconds to nanoseconds.

  • Rejects negative, NaN, and infinite bare numeric durations.
  • Preserves documented 0 and intentional -0 behavior.
  • Adds direct parser tests and coverage of negative max_time through the production argument-conversion path.

Confidence Score: 5/5

The PR appears safe to merge; the new validation rejects the targeted invalid inputs while preserving documented zero-duration semantics.

No actionable failures remain: the guard runs before the saturating cast, the production argument-conversion path propagates the validation error, and tests cover rejected values plus 0 and -0.

Important Files Changed

Filename Overview
crates/exec-harness/src/walltime/config.rs Adds correct finite/non-negative validation and focused regression tests without changing valid duration behavior.

Reviews (1): Last reviewed commit: "fix(exec-harness): reject negative and n..." | Re-trigger Greptile

@mohamedAtoui
mohamedAtoui force-pushed the fix/reject-negative-durations branch from 491f788 to 0e511c3 Compare September 5, 2026 13:11
Bare numeric durations were parsed as f64 and converted with a saturating
`as u64` cast, so `-1` and `NaN` became 0 and `inf` became u64::MAX. A
`--max-time -1` therefore ran warmup and only failed later with "Unable to
determine number of rounds to perform".

Build the duration with `Duration::try_from_secs_f64`, which rejects those
values, and share the nanosecond conversion with the humantime branch.
Humantime inputs such as `-1s` were already rejected. `0` stays valid since
it is how warmup is disabled.

Fixes CodSpeedHQ#364
@mohamedAtoui
mohamedAtoui force-pushed the fix/reject-negative-durations branch from 0e511c3 to d08edb0 Compare September 5, 2026 13:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Negative numeric walltime durations are accepted

1 participant