fix(task): reject boolean max_steps values during task validation - #183
Merged
Conversation
Contributor
Author
|
@jeqcho follow up pr |
jeqcho
approved these changes
Jul 29, 2026
jeqcho
left a comment
Collaborator
There was a problem hiding this comment.
Thanks for the quick follow-up on the #161 review note — this closes the bool-as-int loophole cleanly, and the scope is exactly what was asked for.
What I checked:
- Correctness (
src/inspect_robots/task.py:78):isinstance(self.max_steps, bool) or self.max_steps < 1is right.True(previously accepted as a silent 1-step horizon) is now rejected, andFalse— which the old< 1check already caught — still raises the same error. Putting theisinstancecheck first also mirrors the structure of themax_secondsguard directly below it (task.py:80-84), so the two horizon validations now read the same way. - Error message: reusing the existing
"max_steps must be >= 1, got True"message rather than inventing a new one keeps things consistent and avoids churn in anything matching on it. (Strictly speakingTrue >= 1is numerically true, but the siblingmax_secondsmessage has the same quirk forTrue, so this is the established convention here.) - Tests (
tests/test_types_spaces.py:147-158): the parameterization[True, 0, -1]covers the new bool branch plus both sides of the numeric boundary, and the test mirrors the style oftest_task_rejects_invalid_seconds_horizonright next to it (local imports,pytest.raises(..., match=...)). Nice symmetry. - CHANGELOG: entry is accurate and correctly placed under
## [Unreleased]/### Fixed. - Verification: full CI matrix is green; tests in
tests/test_types_spaces.pyalso pass locally (30 passed).
Two optional nits, neither blocking:
src/inspect_robots/task.py:78sits at 99 characters against the 100-char limit. Wrapping the condition across lines like themax_secondscheck below it would make the two guards visually parallel, but ruff is satisfied as-is.- Not for this PR, but the same
bool-is-inthole still exists inEpochs.__post_init__(task.py:31-33):Task(epochs=True)currently validates as a 1-epoch spec. Might be worth a tiny follow-up issue for the same strictness there.
Approving — thanks for the contribution!
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Follow-up to #161 as requested by @jeqcho in #161 (comment).
Because
boolis a subclass ofintin Python (isinstance(True, int) == True),Task(max_steps=True)previously bypassed validation and was silently treated as a 1-step horizon (max_steps=1).This PR explicitly checks
isinstance(self.max_steps, bool)inTask.__post_init__and raisesConfigError.Changes
inspect_robots.task.Task: Reject booleanmax_stepsvalues during__post_init__validation.tests/test_types_spaces.py: Added parameterized testtest_task_rejects_invalid_steps_horizontesting[True, 0, -1].CHANGELOG.md: Added entry under## [Unreleased] -> ### Fixed.Checklist
pre-commit run --all-filespassesruff check .andruff format --check .passmypypassesCHANGELOG.mdupdated under "Unreleased"Related
Follow-up to #161 (comment) / #160