Skip to content

fix(guards): raise ValueError for values too large for float conversion - #740

Closed
ompatil1906 wants to merge 1 commit into
Hebbian-Robotics:mainfrom
ompatil1906:fix/overflow-in-numeric-guards
Closed

ompatil1906 wants to merge 1 commit into
Hebbian-Robotics:mainfrom
ompatil1906:fix/overflow-in-numeric-guards

Conversation

@ompatil1906

@ompatil1906 ompatil1906 commented Oct 28, 2026 •

Copy link
Copy Markdown

Summary

math.isfinite() raises an unlabelled OverflowError when given integers or Fractions that cannot be converted to float (e.g. 10**400). Public entry points such as TransformConfig(gop_seconds=...) and plan_batches(..., stagger_interval_s=...) therefore leak OverflowError instead of the field-named ValueError used for every other invalid numeric input.

Root cause

In require_finite_float and require_non_negative_real, the call to math.isfinite is not protected against overflow during the float conversion that CPython performs internally.

Fix

Catch OverflowError around math.isfinite and re-raise a ValueError that names the field, matching the existing error style. No change to accepted value sets or to the behaviour of values that fit in a float.

Verification

  • Manual reproduction before/after: TransformConfig(gop_seconds=10**400) and plan_batches({'item': 1}, batch_count=1, stagger_interval_s=Fraction(10**400, 1)) now raise ValueError containing the field name.
  • New unit tests in tests/test_field_guards.py cover large int for the float guards and both large int/Fraction for the Real guard.
  • Extended parametrized cases in tests/test_batching.py and tests/test_transform.py.
  • PYTHONPATH=src python -m pytest tests/test_field_guards.py -q → 9 passed.
  • Full suite could not be run in this environment (uv dependency resolution hits an exclude-newer / private-index interaction for duckdb); the change is isolated to pure-Python guards and the added tests do not require the rest of the package.

Fixes #739


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

math.isfinite() raises OverflowError for ints/Fractions that cannot
convert to float. Catch that and raise a field-named ValueError so
callers of TransformConfig and plan_batches get a consistent error
instead of an unlabelled OverflowError.

Add regression coverage in field_guards, batching, and transform tests.

Fixes Hebbian-Robotics#739
@github-actions

Copy link
Copy Markdown

👋 Hi @ompatil1906 — thank you so much for your first contribution to HFlow!

A maintainer will review your pull request as soon as possible. In the meantime:

💡 Tip: one open pull request per contributor at a time. Before starting an issue, check its sidebar for an assignee or a linked pull request. Either one means somebody is already on it; everything else is fair game.

We are excited to have you here and appreciate your help making the project better! 🙌

@greptile-apps

greptile-apps Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 4/5

[Medium impact] The PR changes error reporting across shared numeric validation paths.

The PR appears safe to merge, with a non-blocking gap in error messages for extremely large values.

Findings

  1. P2 Larger values hide the field ▶

Summary

The PR turns float-conversion overflow into field-named errors.

  • Oversized numeric settings now raise a field-named ValueError.

Reviews (1) · Last reviewed commit: "fix(guards): raise ValueError for values..." · Reviewed by Greptile

try:
finite = math.isfinite(number)
except OverflowError:
raise ValueError(f"{name} must be finite, got {number}") from None

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Larger values hide the field

Both new overflow handlers format the rejected number before raising the field-named error. On Python 3.11 with the default digit limit, 10**5000 and Fraction(10**5000, 1) make that formatting raise its own ValueError, which does not name the bad setting. This leaves the fix incomplete for larger inputs. Avoid formatting the full value in both handlers, and add tests beyond the digit limit.

@kstonekuan

Copy link
Copy Markdown
Contributor

Thanks for the contribution. #739 is already assigned to @yoveneim, so I’m keeping it reserved for them. You’re welcome to pick an unassigned good first issue.

@kstonekuan kstonekuan closed this Oct 28, 2026
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.

Numeric guards leak OverflowError for very large inputs

2 participants