Code Reviewing
Function length, nesting, broad types, hardcoded values, repeated resource construction, or
multiple mocks are signals to investigate; they are not defects by themselves.
Contents
Always Review
Requirements and Correctness
- Trace the changed behavior to the user request or user-spec.
- Check happy paths, specified edge cases, failures, and state changes that the change owns.
- Identify behavior that was added accidentally or requested behavior that is missing.
- Separate new regressions from unrelated pre-existing problems.
Scope, Necessity, and Simplicity
- Trace each added behavior, validation, fallback, branch, state, abstraction, dependency, and
configuration option to a current requirement, project contract, or realistic condition in
the present codebase.
- Report unrequested machinery only when it expands behavior or creates concrete maintenance,
correctness, performance, or testing cost. Fewer lines are not automatically simpler; compare
responsibilities, states, branches, dependencies, and concepts the solution introduces.
- Check whether the project already has a direct capability that satisfies the requirement. An
abstraction used once is acceptable when it expresses a real boundary; it is a problem when it
adds indirection or generality without a current use.
- Evaluate the chosen algorithm against realistic input size and project constraints. Report
avoidable complexity only when an existing project capability or direct requirement proves it
unnecessary and the current choice has a demonstrable consequence; do not prescribe a
replacement, speculative optimization, or wholesale redesign.
- Treat handling for extremely unlikely cases as a defect only when no requirement or realistic
path justifies it and the extra handling materially complicates the normal path.
Cross-File Contracts
- Read every touched source file in full and the callers, dependencies, schemas, or interfaces
on which the change relies. For deleted or renamed files, inspect the supplied change status
and diff. For generated, lock, snapshot, or other mechanical artifacts, inspect the supplied
diff, generator, and deterministic validation instead of consuming the whole artifact
without benefit.
- Verify imports, names, argument order, return values, types, lifecycle assumptions, and error
contracts against their definitions.
- Report a mismatch only when it can break behavior, compilation, loading, or a documented
contract.
Review When Applicable
Architecture and Maintainability
Apply when the change alters responsibilities, dependencies, public interfaces, or repeated
logic.
- Prefer established project architecture over generic pattern preferences.
- Check cohesion, dependency direction, circular dependencies, duplicated responsibility, and
abstractions that add indirection without solving a current problem.
- Treat size and nesting as readability signals. Report them only when they hide behavior,
make a branch unsafe to change, or prevent useful testing.
- Treat duplicated knowledge or responsibility as a finding only when the copies must change
together and a demonstrated divergence risk exists.
- Treat a hardcoded value as a problem when its meaning is unclear, it is repeated as policy,
or it should vary by environment; a local obvious value needs no constant ceremony.
Comments and Documentation
- Straightforward code should explain itself through structure and naming.
- A comment is useful when code cannot express why a non-obvious decision exists: a business
rule, safety invariant, external constraint, compatibility workaround, deliberate tradeoff,
or required ordering.
- The comment should explain the reason and what must remain true. A comment that merely
narrates the next statement is noise and should be removed or replaced by clearer code.
- Report a missing comment only when future maintainers could reasonably remove or "simplify"
an important constraint because its reason is not recoverable from code or project docs.
Failure Handling and Observability
Apply when the change introduces a failure boundary, external operation, recovery path, or
operationally important state transition.
- Errors should be handled where the program can recover, translate them into a stable contract,
or add information that is not already available.
- Preserve the original cause when propagating a failure. Do not require a local
try/catch
that only logs and rethrows; that commonly duplicates logs without improving recovery.
- Check empty catches, lost causes, misleading fallbacks, partial writes, and cleanup on failure.
- Follow the project's logging policy. Require a log when its absence creates a real diagnostic
gap, not at every function that calls an API or database.
- Log only the minimum operational context needed. Keep secrets, credentials, sensitive
payloads, emails, phone numbers, and unnecessary user identifiers out of logs.
Types and Data Contracts
Apply to typed code, parsing, serialization, schemas, nullable data, or external input.
- Check that types describe runtime possibilities and that narrowing or assertions are justified.
- Validate untrusted input at the boundary where it enters the trusted system.
- Use parameterized queries and context-appropriate encoding at the destination; generic
"sanitize everything" rules can corrupt valid data without preventing the relevant attack.
- Check migrations, defaults, compatibility, and partial-data behavior when data shape changes.
Security
Apply when authentication, authorization, untrusted input, secrets, sensitive data, file paths,
database queries, rendering, or external requests changed.
- Verify authorization at the operation that needs protection, not only in the UI.
- Check injection, path traversal, XSS, CSRF, SSRF, secret exposure, unsafe deserialization, and
privilege escalation as applicable to the changed boundary.
- Confirm sensitive configuration stays outside source and ignored secret files remain ignored.
Performance and Resources
Apply when the change touches a hot path, loop over unbounded data, rendering frequency, query
shape, concurrency, or a heavy resource.
- Look for N+1 work, unbounded loads, repeated initialization, leaked handles, missing cleanup,
and concurrency that can corrupt state or exceed external limits.
- Multiple resource instances may be correct for tenant, configuration, process, worker, or test
isolation. Report them only when lifecycle and measured cost show harmful duplication.
- Report only the concrete bottleneck or unbounded resource risk.
Dependencies
Apply when a dependency or its version changes.
- Check necessity, existing alternatives, manifest/lockfile consistency, imported API contracts,
bundle or runtime impact, and compatibility with the project.
- Use repository evidence or supplied tool results for vulnerabilities, maintenance status, and
licensing. If external evidence is unavailable, state that it was not verified rather than
guessing.
Tests
Apply when behavior or tests changed.
- Tests should protect the changed behavior at the smallest reliable boundary.
- Look for missing meaningful branches, failures, validation, transformations, and specified
edge cases.
- Do not require tests for freely editable UX copy, presentation-only markup or styles, or
mechanical changes with no observable contract to protect. Content, configuration, markup,
styles, and accessors remain testable when they implement an explicit user, accessibility,
protocol, or project contract.
- A mock is a problem when the test verifies its own setup or replaces all meaningful behavior,
not when an arbitrary count is reached.
- Checking a call is valid when the interaction itself is the observable contract, such as
publishing an event or sending a command with required arguments.
1---2name: code-reviewing-23description: Reviews code against the user request, project conventions, cross-file contracts, and applicable quality risks. Use when: "проверь код", "code review", "ревью кода", "review this code", "check code quality"4---5<!-- Generated by sync-to-codex v1. Do not edit directly. -->67# Code Reviewing89Function length, nesting, broad types, hardcoded values, repeated resource construction, or10multiple mocks are signals to investigate; they are not defects by themselves.1112## Contents1314- [Always Review](#always-review)15- [Review When Applicable](#review-when-applicable)1617## Always Review1819### Requirements and Correctness2021- Trace the changed behavior to the user request or user-spec.22- Check happy paths, specified edge cases, failures, and state changes that the change owns.23- Identify behavior that was added accidentally or requested behavior that is missing.24- Separate new regressions from unrelated pre-existing problems.2526### Scope, Necessity, and Simplicity2728- Trace each added behavior, validation, fallback, branch, state, abstraction, dependency, and29 configuration option to a current requirement, project contract, or realistic condition in30 the present codebase.31- Report unrequested machinery only when it expands behavior or creates concrete maintenance,32 correctness, performance, or testing cost. Fewer lines are not automatically simpler; compare33 responsibilities, states, branches, dependencies, and concepts the solution introduces.34- Check whether the project already has a direct capability that satisfies the requirement. An35 abstraction used once is acceptable when it expresses a real boundary; it is a problem when it36 adds indirection or generality without a current use.37- Evaluate the chosen algorithm against realistic input size and project constraints. Report38 avoidable complexity only when an existing project capability or direct requirement proves it39 unnecessary and the current choice has a demonstrable consequence; do not prescribe a40 replacement, speculative optimization, or wholesale redesign.41- Treat handling for extremely unlikely cases as a defect only when no requirement or realistic42 path justifies it and the extra handling materially complicates the normal path.4344### Cross-File Contracts4546- Read every touched source file in full and the callers, dependencies, schemas, or interfaces47 on which the change relies. For deleted or renamed files, inspect the supplied change status48 and diff. For generated, lock, snapshot, or other mechanical artifacts, inspect the supplied49 diff, generator, and deterministic validation instead of consuming the whole artifact50 without benefit.51- Verify imports, names, argument order, return values, types, lifecycle assumptions, and error52 contracts against their definitions.53- Report a mismatch only when it can break behavior, compilation, loading, or a documented54 contract.5556## Review When Applicable5758### Architecture and Maintainability5960Apply when the change alters responsibilities, dependencies, public interfaces, or repeated61logic.6263- Prefer established project architecture over generic pattern preferences.64- Check cohesion, dependency direction, circular dependencies, duplicated responsibility, and65 abstractions that add indirection without solving a current problem.66- Treat size and nesting as readability signals. Report them only when they hide behavior,67 make a branch unsafe to change, or prevent useful testing.68- Treat duplicated knowledge or responsibility as a finding only when the copies must change69 together and a demonstrated divergence risk exists.70- Treat a hardcoded value as a problem when its meaning is unclear, it is repeated as policy,71 or it should vary by environment; a local obvious value needs no constant ceremony.7273### Comments and Documentation7475- Straightforward code should explain itself through structure and naming.76- A comment is useful when code cannot express why a non-obvious decision exists: a business77 rule, safety invariant, external constraint, compatibility workaround, deliberate tradeoff,78 or required ordering.79- The comment should explain the reason and what must remain true. A comment that merely80 narrates the next statement is noise and should be removed or replaced by clearer code.81- Report a missing comment only when future maintainers could reasonably remove or "simplify"82 an important constraint because its reason is not recoverable from code or project docs.8384### Failure Handling and Observability8586Apply when the change introduces a failure boundary, external operation, recovery path, or87operationally important state transition.8889- Errors should be handled where the program can recover, translate them into a stable contract,90 or add information that is not already available.91- Preserve the original cause when propagating a failure. Do not require a local `try/catch`92 that only logs and rethrows; that commonly duplicates logs without improving recovery.93- Check empty catches, lost causes, misleading fallbacks, partial writes, and cleanup on failure.94- Follow the project's logging policy. Require a log when its absence creates a real diagnostic95 gap, not at every function that calls an API or database.96- Log only the minimum operational context needed. Keep secrets, credentials, sensitive97 payloads, emails, phone numbers, and unnecessary user identifiers out of logs.9899### Types and Data Contracts100101Apply to typed code, parsing, serialization, schemas, nullable data, or external input.102103- Check that types describe runtime possibilities and that narrowing or assertions are justified.104- Validate untrusted input at the boundary where it enters the trusted system.105- Use parameterized queries and context-appropriate encoding at the destination; generic106 "sanitize everything" rules can corrupt valid data without preventing the relevant attack.107- Check migrations, defaults, compatibility, and partial-data behavior when data shape changes.108109### Security110111Apply when authentication, authorization, untrusted input, secrets, sensitive data, file paths,112database queries, rendering, or external requests changed.113114- Verify authorization at the operation that needs protection, not only in the UI.115- Check injection, path traversal, XSS, CSRF, SSRF, secret exposure, unsafe deserialization, and116 privilege escalation as applicable to the changed boundary.117- Confirm sensitive configuration stays outside source and ignored secret files remain ignored.118119### Performance and Resources120121Apply when the change touches a hot path, loop over unbounded data, rendering frequency, query122shape, concurrency, or a heavy resource.123124- Look for N+1 work, unbounded loads, repeated initialization, leaked handles, missing cleanup,125 and concurrency that can corrupt state or exceed external limits.126- Multiple resource instances may be correct for tenant, configuration, process, worker, or test127 isolation. Report them only when lifecycle and measured cost show harmful duplication.128- Report only the concrete bottleneck or unbounded resource risk.129130### Dependencies131132Apply when a dependency or its version changes.133134- Check necessity, existing alternatives, manifest/lockfile consistency, imported API contracts,135 bundle or runtime impact, and compatibility with the project.136- Use repository evidence or supplied tool results for vulnerabilities, maintenance status, and137 licensing. If external evidence is unavailable, state that it was not verified rather than138 guessing.139140### Tests141142Apply when behavior or tests changed.143144- Tests should protect the changed behavior at the smallest reliable boundary.145- Look for missing meaningful branches, failures, validation, transformations, and specified146 edge cases.147- Do not require tests for freely editable UX copy, presentation-only markup or styles, or148 mechanical changes with no observable contract to protect. Content, configuration, markup,149 styles, and accessors remain testable when they implement an explicit user, accessibility,150 protocol, or project contract.151- A mock is a problem when the test verifies its own setup or replaces all meaningful behavior,152 not when an arbitrary count is reached.153- Checking a call is valid when the interaction itself is the observable contract, such as154 publishing an event or sending a command with required arguments.