Skip to content

fix(workflows): reject bool max_iterations in engine re-eval guard#3470

Open
Noor-ul-ain001 wants to merge 1 commit into
github:mainfrom
Noor-ul-ain001:fix/engine-max-iterations-bool-guard
Open

fix(workflows): reject bool max_iterations in engine re-eval guard#3470
Noor-ul-ain001 wants to merge 1 commit into
github:mainfrom
Noor-ul-ain001:fix/engine-max-iterations-bool-guard

Conversation

@Noor-ul-ain001

Copy link
Copy Markdown
Contributor

Summary

The while / do-while step validators already reject max_iterations: true as a type error — bool is a subclass of int, so a boolean passes a bare isinstance(..., int) check, and since True - 1 == 0 it would silently cap the loop at a single iteration (0 re-iterations).

The engine's re-evaluation guard in WorkflowEngine, however, still used the older shape:

if not isinstance(max_iters, int) or max_iters < 1:
    max_iters = 10

On an unvalidated run (executing a definition without first calling the validators), a boolean max_iterations slipped through this guard and ran the loop body just once instead of falling back to the safe default of 10.

Fix

Add the explicit isinstance(max_iters, bool) rejection so the engine guard matches WhileStep.validate() / DoWhileStep.validate(). An unvalidated run now degrades to the default of 10 rather than silently under-running the loop.

Testing

  • Added test_while_loop_bool_max_iterations_falls_back_to_default, which runs a while step with max_iterations: true through the engine and asserts the body executes 10 times (not 1).
  • Verified the test fails without the engine change and passes with it (test-the-test via git stash).
  • Full while/do-while/loop suite: 16 passed.

🤖 Generated with Claude Code

The While/DoWhile step validators already reject `max_iterations: true`
as a type error (bool is an int subclass, so it would otherwise pass the
`isinstance(..., int)` check and, since `True - 1 == 0`, silently cap the
loop at a single iteration). The engine's re-evaluation guard used the
older `not isinstance(max_iters, int) or max_iters < 1` shape, so on an
unvalidated run a boolean slipped through and ran the loop body just once
instead of falling back to the safe default of 10.

Add the explicit `isinstance(max_iters, bool)` rejection so the engine
guard matches the step validators and an unvalidated run degrades to the
default rather than silently under-running the loop.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@Noor-ul-ain001 Noor-ul-ain001 requested a review from mnriem as a code owner July 11, 2026 13:11
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.

1 participant