Awesome Reviewers

Reviewer · Algorithms

Explicit structural conditions

When an algorithm branches or recurses based on structural properties (node type, loop counters, regex alternatives, recursive key matching), make the condition explicit and self-contained rather than relying on incidental behavior that happens to work for today's inputs. Order-dependent matching, type inference from payload instead of an explicit tag, and...

Instruction

When an algorithm branches or recurses based on structural properties (node type, loop counters, regex alternatives, recursive key matching), make the condition explicit and self-contained rather than relying on incidental behavior that happens to work for today’s inputs. Order-dependent matching, type inference from payload instead of an explicit tag, and narrow special-casing are all fragile: they silently break once the data shape, ordering, or guard conditions change.

Concretely:

  • For pattern/alternation matching, don’t depend on evaluation order to disambiguate overlapping alternatives; make the match unambiguous by construction (e.g., sort alternatives by length) instead of relying on backtracking semantics that aren’t guaranteed to stay correct as the pattern grows.
  • For tree/graph traversal, gate behavior on the node’s own explicit type/tag (e.g., node.type == NodeType.SUBGRAPH) rather than inspecting the type of an attached payload, so the dispatch logic stays correct even when payload and node-kind diverge.
  • For recursive data-structure traversal (e.g., removing keys from a nested schema), identify the full, generalized set of structural/container keys (properties, $defs, definitions, patternProperties, etc.) that must be recursed into, instead of special-casing only the one key exercised by current tests:
elif key in ("properties", "$defs", "definitions", "patternProperties") and isinstance(d[key], dict):
    for prop in d[key].values():
        if isinstance(prop, dict):
            _remove_a_key(prop, remove_key)
  • For loop/guard conditions, verify the condition covers every type/value the variable can take (e.g., confirm behavior when max_loops is non-integer like "auto"), not just the common numeric case.

Before merging algorithmic changes, enumerate the edge cases (reordered inputs, alternate type combinations, additional structural keys, non-standard values) and confirm the logic is correct for all of them, not just the cases covered by the existing tests.</description> </invoke>