Reviewer · Documentation
Keep comments synced with behavior
When code changes, immediately audit the surrounding comments and docstrings so they describe what the code actually does now, not what it used to do. This covers several recurring failure modes:
When code changes, immediately audit the surrounding comments and docstrings so they describe what the code actually does now, not what it used to do. This covers several recurring failure modes:
-
Orphaned section comments: when entries under a comment header are moved or deleted, remove or update the header too. For example, a
# System shutdown / rebootcomment left above an unrelated# Privilege escalationblock after its four entries were relocated elsewhere is actively misleading to the next reader. -
Undocumented limitations/scope: if a parameter or flag (e.g.
strict=True) only guarantees behavior for a subset of cases (own attributes and nested mixin objects, but not arbitrary third-partyto_dict()results), spell that scope out explicitly in the docstring’sArgs/Returnssection rather than letting the name imply a broader guarantee. -
Undocumented side effects: if a method mutates caller-owned state in a way that persists beyond the call (e.g. permanently rewriting
agent.system_promptinstead of restoring it), document this clearly on the class/method docstring so callers know not to pass shared instances, or fix the side effect instead of only documenting it. -
Rationale for non-obvious code: if a method appears unused by production code but is intentionally retained (e.g., a write-only audit-log accessor kept for future/manual use), add a short docstring note explaining why it exists, so it isn’t mistakenly deleted as dead code by a future contributor or linter-driven cleanup.
As a rule: every code change that alters behavior, removes functionality, or introduces a persistent side effect should be accompanied by a corresponding update to the nearest comment or docstring, and any comment that no longer matches the code it sits above/describes must be deleted or rewritten in the same change.</description> </invoke>