Awesome Reviewers

Reviewer · Null Handling

Guard nullable values

Treat every value that can legitimately be `None` (or missing) as nullable end-to-end: annotate it correctly, guard it before use, and give it an explicit fallback before handing it to code that requires a real value.

Instruction

Treat every value that can legitimately be None (or missing) as nullable end-to-end: annotate it correctly, guard it before use, and give it an explicit fallback before handing it to code that requires a real value.

Apply these rules:

  1. Annotate what the default actually is. If a parameter or attribute defaults to None, its type hint must say so (Optional[Dict[str, Any]] = None, not Dict[str, Any] = None). A class-level annotation with no assignment is not initialization — assign the attribute in __init__ (or give it a real default) so static checkers don’t flag it as uninitialized.

  2. Don’t assume an attribute or key exists just because the “normal” case has it. When a value might come from a dict instead of an object (e.g. parsed tool calls), or might come from an object whose nested attribute is optional (self.director.llm, self.knowledge_generator.agent), use getattr(obj, "attr", default) or an explicit isinstance/.get() check instead of direct access. Prefer degrading gracefully (return defaults/zeros) over raising from a property or helper that’s called in a finally or hot path.

  3. Bind an Optional attribute to a local before narrowing. Re-reading self.attr across multiple statements does not preserve a prior is not None check (and is unsafe if another thread can swap it). Bind once:
    path = self.memory_md_path
    if path and os.path.exists(path):
     size = os.path.getsize(path)
    
  4. Supply an explicit fallback when passing an Optional value to an API that requires a concrete one, e.g. agent.agent_name or "Worker", current_agent.agent_name or "". Don’t let a None silently propagate into a role, key, or label.

  5. Distinguish “missing” from “falsy-but-present”. dict.setdefault("summary", reason) only fires when the key is absent; if the field is commonly initialized to "" or None, check truthiness instead (if not subtask.get("summary"): ...) so a real fallback value isn’t skipped.

  6. Validate types before arithmetic/logic on externally-sourced values. Don’t assume a field from an external provider or mock is numeric/non-null; coerce or skip (if isinstance(value, (int, float))) rather than letting a TypeError surface from deep inside a shared helper.

  7. Avoid relying on an implicit None as a hidden state flag (e.g. transcript is None meaning “first iteration”). If that’s the intent, make it explicit (loop_count == 1) or document the invariant clearly, so future edits don’t silently break the branch.</description>

</invoke>