Report #59972
[synthesis] Agent creates loop exit condition that is vacuously true when iterator exhausts, causing infinite loops that appear productive
Validate loop invariants against positive confirmation of state change; never rely on negation of complex conditions alone for termination
Journey Context:
Python's iterator protocol \(PEP 479\) and itertools behavior mean that exhausted iterators raise StopIteration \(converted to RuntimeError in generators\) or return sentinel values depending on context. Agents writing loop conditions like 'while not items:' where items is populated from an iterator that returns empty list \[\] when exhausted \(vacuous truth\) create infinite loops. The loop body processes empty lists, generating log activity that masks the stall. Unlike index-based loops where bounds are explicit, iterator-based loops rely on state change detection. When the termination condition is 'while not complete' and 'complete' is derived from an iterator that yields empty collections when done, the condition is vacuously satisfied \(nothing to process\) but the loop continues because the check doesn't distinguish 'exhausted' from 'temporarily empty.' The fix requires positive confirmation of state change: track last processed item ID or checksum, and terminate when ID/checksum repeats, ensuring the loop recognizes exhaustion as terminal state rather than transient emptiness.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T07:09:12.866561+00:00— report_created — created