|
| 1 | +Code Review Procedures |
| 2 | +====================== |
| 3 | + |
| 4 | +### Why do we code review? |
| 5 | + |
| 6 | +Code review is a process where someone other than the author of a patch |
| 7 | +examines the proposed changes and approves or critiques them. The main |
| 8 | +benefits are to: |
| 9 | + |
| 10 | +- Encourage submitters to ensure that their changes are well thought out, |
| 11 | + tested, and documented so that their intent and wisdom will be clear to |
| 12 | + others. |
| 13 | +- Directly find shortcomings in or suggest improvements to the proposed |
| 14 | + changes, and ensure that the changes are consistent with the project's best |
| 15 | + practices. |
| 16 | +- Minimize the amount of the code base that has only been seen or is only |
| 17 | + understood by one person. |
| 18 | +- Improve security and robustness of the code base by assuring that at least |
| 19 | + two people (submitter and reviewer) agree that every patch is reasonable and |
| 20 | + safe. |
| 21 | + |
| 22 | +### Reviewer guidelines -- what you should be looking for |
| 23 | + |
| 24 | +Code review is not difficult, and it doesn't require you to be a senior |
| 25 | +developer or a domain expert. Even if you don't particularly understand that |
| 26 | +region of the code and are not a domain expert in the feature being changed, |
| 27 | +you can still provide a helpful second pair of eyes to look for obvious red |
| 28 | +flags and give an adequate review: |
| 29 | + |
| 30 | +- This may seem too obvious to say explicitly, but a big part of review is |
| 31 | + just looking at the PR and seeing that it doesn't appear to deface, |
| 32 | + purposely/obviously break, or introduce malware into the project. |
| 33 | +- Does the explanation of the PR make logical sense and appear to match (as |
| 34 | + near as you can tell) the changes in the code? Does it seem sensible, even |
| 35 | + if you don't understand all the details? |
| 36 | +- Does the test pass all of our existing CI tests? (If it does, at least we |
| 37 | + are reasonably sure it doesn't break commonly used features.) |
| 38 | +- Is there any evidence that the changes have been tested? Ideally, something |
| 39 | + already in, or added to the testsuite by this PR, exercises the new or |
| 40 | + altered code. (Though sometimes a patch addresses an edge case that's very |
| 41 | + hard to reproduce in the testsuite, and you have to rely on the submitter's |
| 42 | + word and the sensibility of their explanation.) |
| 43 | +- Not required, but nice if we can get it: You're an expert in the part of |
| 44 | + the code being changed, and you agree that this is the best way to achieve |
| 45 | + an improvement. |
| 46 | +- Any objections should be explained in detail and invite counter-arguments |
| 47 | + from the author or other onlookers. A reviewer should never close a PR |
| 48 | + unless it fails to conform to even the basic requirements of any submitted |
| 49 | + PR, or if enough time has passed that it's clear that the PR has been |
| 50 | + abandoned by its author. It's ok to ultimately say "no" to a PR that can't |
| 51 | + be salvaged, but that should be the result of a dialogue. |
| 52 | + |
| 53 | +Obviously, you also want any review comments you give to be constructive and |
| 54 | +helpful. If you don't understand something, ask for clarification. If you |
| 55 | +think something is wrong, suggest a fix if you know how to fix it. If you |
| 56 | +think something is missing, suggest what you think should be added. Follow the |
| 57 | +expected kind and constructive tone of the project's community. |
| 58 | + |
| 59 | +### Submitter guidelines -- how to encourage good reviews and timely merges |
| 60 | + |
| 61 | +A few tips for submitters to help ensure that your PRs get reviewed and merged |
| 62 | +in a timely manner and are respectful of the reviewers' time and effort: |
| 63 | + |
| 64 | +- Aim for small PRs that do a specific thing in a clear way. It is better to |
| 65 | + implement a large change with a series of PRs that each take a small, |
| 66 | + obvious step forward, than to have one huge PR that makes changes so |
| 67 | + extensive that nobody quite knows how to evaluate it. |
| 68 | +- Make sure your PR commit summary message clearly explains the why and how of |
| 69 | + your changes. You want someone to read that and judge whether it's a |
| 70 | + sensible approach, know what to look for in the code, and have their |
| 71 | + examination of the code make them say "yes, I see, of course, great, just as |
| 72 | + I expected!" |
| 73 | +- Make sure your PR includes a test (if not covered by existing tests). |
| 74 | +- Make sure your PR fully passes our CI tests. |
| 75 | +- Make sure your PR modifies the documentation as necessary if it adds new |
| 76 | + features, changes any public APIs, or alters behavior of existing features. |
| 77 | +- If your PR alters the C++ API, make sure that the changes are also reflected |
| 78 | + in the Python bindings and any other language bindings we support. |
| 79 | +- If your PR adds to or alters any ImageBufAlgo function, make sure you have |
| 80 | + exposed those changes with appropriate `oiiotool` commands as well. |
| 81 | + |
| 82 | +### Code review procedures -- in the ideal case |
| 83 | + |
| 84 | +In the best of circumstances, the code review process should be as follows for |
| 85 | +**EVERY** pull request: |
| 86 | + |
| 87 | +- At least one reviewer critiques and eventually (possibly after changes are |
| 88 | + made) approves the pull request. Reviewers, by definition, are not the same |
| 89 | + person as the author. |
| 90 | +- Reviewers should indicate their approval by clicking the "Approve" button in |
| 91 | + GitHub, or by adding a comment that says "LGTM" (looks good to me). |
| 92 | +- If possible, reviewers should have some familiarity with the code being |
| 93 | + changed (though for a large code base, this is not always possible). |
| 94 | +- At least a few work days should elapse between posting the PR and merging |
| 95 | + it, even if an approving review is received immediately. This is to allow |
| 96 | + additional reviewers or dissenting voices to get a chance to weigh in. |
| 97 | +- If the reviewer has suggestions for improvement, it's the original author |
| 98 | + who should make the changes and push them to the PR, or at the very least, |
| 99 | + the author should okay any changes made by the reviewer before a merge |
| 100 | + occurs (if at all practical). |
| 101 | + |
| 102 | +Not all patches need the highest level of scrutiny. Reviews can be cursory and |
| 103 | +quick, and merges performed without additional delay, in some common low-risk |
| 104 | +circumstances: |
| 105 | + |
| 106 | +- The patch fixes broken CI, taking the project from a verifiably broken state |
| 107 | + to passing all of our CI builds and tests. |
| 108 | +- The changes are only to documentation, comments, or other non-code files, |
| 109 | + and so cannot break the build or introduce new bugs. |
| 110 | +- The code changes are trivial and are obviously correct. (This is a judgment |
| 111 | + call, but if the author or reviewer or both are among the project's senior |
| 112 | + developers, they don't need to performatively pretend that they aren't sure |
| 113 | + it's a good patch.) |
| 114 | +- The changes are to *localized* and *low risk* code, that even if wrong, |
| 115 | + would only have the potential to break individual non-critical features or |
| 116 | + rarely-used code paths. |
| 117 | + |
| 118 | +Conversely, some patches are so important or risky that if possible, they |
| 119 | +should be reviewed by multiple people, preferably from different stakeholder |
| 120 | +institutions than the author, and ensure that the approval is made with a |
| 121 | +detailed understanding of the issues. In these cases, it may also be worth |
| 122 | +bringing up the issue up at a TSC meeting to ensure the attention of many |
| 123 | +stakeholders. These include: |
| 124 | + |
| 125 | +- *New directions*: Addition of major new features, new strategic initiatives, |
| 126 | + or changes to APIs that introduce new idioms or usage patterns should give |
| 127 | + ample time for all stakeholders to provide feedback. In such cases, it may |
| 128 | + be worth having the PR open for comments for weeks, not just days. |
| 129 | +- *Risky changes*: Changes to core classes or code that could subtly break |
| 130 | + many things if not done right, or introduce performance regressions to |
| 131 | + critical cases. |
| 132 | +- *Compatibility breaks*: changes that propose to break backward API |
| 133 | + compatibility with existing code or data files, or that change the required |
| 134 | + toolchain or depeendencies needed to build the project. |
| 135 | +- *Security*: Changes that could introduce security vulnerabilities, or that |
| 136 | + fix tricky security issues where the best fix is not obvious. |
| 137 | + |
| 138 | +### Code review compromises -- because things are rarely ideal |
| 139 | + |
| 140 | +We would love to have many senior reviewers constantly watching for PRs, doing |
| 141 | +thorough reviews immediately, and following the above guidelines without |
| 142 | +exception. Wouldn't that be great! But in reality, we have to compromise, |
| 143 | +hurry, or cut corners, or nothing would ever get done. Some of these |
| 144 | +compromises are understandable and acceptable if they aren't happening too |
| 145 | +often. |
| 146 | + |
| 147 | +- Lack of reviews: If no reviews are forthcoming after a couple days, a "are |
| 148 | + there any objections?" comment may be added to the PR, and if no objections |
| 149 | + are raised within another few days, the PR may be merged by the author if |
| 150 | + they are a senior developer on the project. This is a fact of life, but |
| 151 | + should be minimized (with a rigor proportional to where the patch falls on |
| 152 | + the "low risk / high risk" scale described above). If this is done, you |
| 153 | + should leave an additional comment explaining why it was merged without |
| 154 | + review and inviting people to submit post-merge comments if they |
| 155 | + subsequently spot something that can be improved. |
| 156 | +- Time-critical patches: urgent security fixes, broken CI or builds, critical |
| 157 | + bugs affecting major stakeholders who are waiting for a repaired release, |
| 158 | + fixes that are blocking other work or preventing other PRs from advancing. |
| 159 | + In such cases, it is understandable for senior developers to try to speed up |
| 160 | + the process of getting the changes integrated (though the very nature of |
| 161 | + their criticality also indicates that it's worth getting a review if at all |
| 162 | + possible). |
| 163 | +- Failing tests: Sometimes a PR must be merged despite failing CI tests. |
| 164 | + Usually this is for one of two reasons: (1) spurious CI failures are known |
| 165 | + to be occurring at that time and are unrelated to the PR; (2) the PR is part |
| 166 | + of a series of patches that are only expected to fully pass CI when the last |
| 167 | + piece is completed. |
| 168 | + |
| 169 | +These changes are understandable, but we still are striving to reduce their |
| 170 | +frequency. It is the responsibility of the senior developers, TSC members, and |
| 171 | +major stakeholders to be monitoring the incoming PRs and helping with reviews |
| 172 | +as much as possible, to ensure that review exceptions are rare. |
| 173 | + |
| 174 | +### Code review pathologies -- things to avoid |
| 175 | + |
| 176 | +These are anti-patterns that generally are indications of an unhealthy open |
| 177 | +source project: |
| 178 | + |
| 179 | +* An author merging their own PR without any review comments that indicate |
| 180 | + meaningful scrutiny or approval from another party, and without giving |
| 181 | + adequate warning that a merge will occur if no reviews are received. |
| 182 | +* PRs languishing for weeks or months without any review or merge. |
| 183 | +* PRs that don't adequately test their changes (basically crossing your |
| 184 | + fingers and hoping it works). |
| 185 | +* PRs that are merged despite failing CI that might be related or, if |
| 186 | + unrelated, that might be masking problems with the PR being evaluated. |
| 187 | + |
| 188 | +Again, sometimes these things happen out of necessity to keep the project |
| 189 | +moving forward under constrained development resources. But we strive as much |
| 190 | +as possible to ensure that they are rare exceptions. |
0 commit comments