|
| 1 | +--- |
| 2 | +name: audit-review |
| 3 | +description: Perform deep feature audits with transition-matrix and logical fault-injection validation. Use when reviewing complex changes, regressions, state-machine behavior, config interactions, API/protocol flows, and concurrency-sensitive logic. |
| 4 | +--- |
| 5 | + |
| 6 | +# Audit Review |
| 7 | + |
| 8 | +## Purpose |
| 9 | + |
| 10 | +Run a repeatable deep audit for any feature and report confirmed defects with severity. |
| 11 | +Default mode is static reasoning unless runtime execution is explicitly performed. |
| 12 | + |
| 13 | +## Workflow |
| 14 | + |
| 15 | +1. If PR scope is large, partition by functionality/workstream first: |
| 16 | + - define partitions and boundaries, |
| 17 | + - review each partition independently with the full workflow below, |
| 18 | + - track per-partition findings and coverage, |
| 19 | + - deduplicate cross-partition findings by root cause, |
| 20 | + - finish with cross-partition interaction risks. |
| 21 | +2. Build call graph first: |
| 22 | + - user/system entrypoints (API, RPC, CLI, worker, scheduler) |
| 23 | + - dispatch and validation layers |
| 24 | + - state/storage/cache interactions |
| 25 | + - downstream integrations (network, filesystem, service calls) |
| 26 | + - exception and error-propagation paths |
| 27 | +3. Build transition matrix: |
| 28 | + - request/event entry -> processing stages -> state changes -> outputs/side effects |
| 29 | + - define key invariants and annotate where each transition must preserve them |
| 30 | +4. Perform logical testing of all code paths: |
| 31 | + - enumerate all reachable branches in changed logic, |
| 32 | + - record expected branch outcomes (success, handled failure, fail-open/fail-closed, exception), |
| 33 | + - include happy path, malformed input, integration timeout/failure, and concurrency/timing branches. |
| 34 | +5. Define logical fault categories from the code under review: |
| 35 | + - derive categories from actual components, transitions, and dependencies in scope, |
| 36 | + - document category boundary and affected states/transitions, |
| 37 | + - prioritize categories by risk and blast radius. |
| 38 | +6. Run logical fault injection category-by-category: |
| 39 | + - execute one category at a time, |
| 40 | + - for each category cover success/failure/edge/concurrency paths as applicable, |
| 41 | + - record pass/fail-open/fail-closed/exception behavior per injected fault. |
| 42 | + - maintain a category completion matrix with status: |
| 43 | + - Executed / Not Applicable / Deferred, |
| 44 | + - outcome, |
| 45 | + - defects found, |
| 46 | + - justification for Not Applicable or Deferred. |
| 47 | +7. Confirm each finding with code-path evidence. |
| 48 | +8. Produce coverage accounting: |
| 49 | + - reviewed vs unreviewed call-graph nodes, |
| 50 | + - reviewed vs unreviewed transitions, |
| 51 | + - executed vs skipped fault categories (with reasons). |
| 52 | + - mark coverage complete only when every in-scope node/transition/category is reviewed or explicitly skipped with justification. |
| 53 | +9. For multithreaded/shared-state paths, perform interleaving analysis: |
| 54 | + - write several plausible thread interleavings per critical transition, |
| 55 | + - identify race/deadlock/lifetime hazards per interleaving. |
| 56 | +10. For mutation-heavy paths, perform rollback/partial-update analysis: |
| 57 | + - reason about exception/cancellation at intermediate points, |
| 58 | + - verify state invariants still hold. |
| 59 | + |
| 60 | +## C++ Bug-Type Coverage (Required for C++ audits) |
| 61 | + |
| 62 | +- memory lifetime defects (use-after-free/use-after-move/dangling refs) |
| 63 | +- iterator/reference invalidation |
| 64 | +- data races and lock-order/deadlock risks |
| 65 | +- exception-safety and partial-update rollback hazards |
| 66 | +- integer overflow/underflow and signedness conversion bugs |
| 67 | +- ownership/resource leaks (RAII violations) |
| 68 | +- undefined behavior from invalid casts/aliasing/lifetime misuse |
| 69 | + |
| 70 | +## Multithreaded Database Emphasis |
| 71 | + |
| 72 | +For ClickHouse-style multithreaded systems, prioritize these checks before lower-risk issues: |
| 73 | + |
| 74 | +1. Shared mutable state touched by multiple threads without clear synchronization. |
| 75 | +2. Lock hierarchy consistency and potential lock-order inversion/deadlock cycles. |
| 76 | +3. Cross-thread lifetime safety (dangling references/pointers after erase/reload/shutdown). |
| 77 | +4. Concurrent container mutation + iterator/reference use. |
| 78 | +5. Exception/cancellation paths that can leave locks/state inconsistent. |
| 79 | + |
| 80 | +## Output Contract |
| 81 | + |
| 82 | +- Start with confirmed defects only. |
| 83 | +- Group by severity: High, Medium, Low. |
| 84 | +- For each defect include: |
| 85 | + - title, |
| 86 | + - impact, |
| 87 | + - file/function anchor, |
| 88 | + - fault-injection trigger, |
| 89 | + - transition mapping, |
| 90 | + - why it is a defect (not a design preference), |
| 91 | + - smallest logical repro steps, |
| 92 | + - likely fix direction (short, concrete: 2-4 bullets or sentences), |
| 93 | + - regression test direction (short, concrete: 2-4 bullets or sentences), |
| 94 | + - affected subsystem and blast radius, |
| 95 | + - at least one code snippet proving the defect. |
| 96 | +- Separate “not confirmed” or “needs runtime proof” from confirmed defects. |
| 97 | +- Include an **Assumptions & Limits** section for static reasoning. |
| 98 | +- Include an overall **confidence rating** and what additional evidence would raise confidence. |
| 99 | +- If no defects are found, include residual risks and untested paths. |
| 100 | +- For large PRs, include per-partition findings/coverage and final cross-partition risk summary. |
| 101 | +- Include a fault-category completion matrix for every deep audit. |
| 102 | + |
| 103 | +### Canonical report order |
| 104 | + |
| 105 | +1. Scope and partitions (if large PR) |
| 106 | +2. Call graph |
| 107 | +3. Transition matrix |
| 108 | +4. Logical code-path testing summary |
| 109 | +5. Fault categories and category-by-category injection results |
| 110 | +6. Confirmed defects (High/Medium/Low) |
| 111 | +7. Coverage accounting + stop-condition status |
| 112 | +8. Assumptions & Limits |
| 113 | +9. Confidence rating and confidence-raising evidence |
| 114 | +10. Residual risks and untested paths |
| 115 | + |
| 116 | +## Standard Audit Report Template (Default: Pointed PR Style) |
| 117 | + |
| 118 | +Default report style should match concise PR review comments: |
| 119 | +- fail-first and action-oriented, |
| 120 | +- only confirmed defects (no pass-by-pass narrative), |
| 121 | +- one short summary line when there are no confirmed defects. |
| 122 | + |
| 123 | +Use the compact template below by default. Use the full 10-section canonical format only when explicitly requested. |
| 124 | + |
| 125 | +```markdown |
| 126 | +Audit update for PR #<id> (<short title/scope>): |
| 127 | + |
| 128 | +Confirmed defects: |
| 129 | + |
| 130 | +- **<Severity>: <short defect title>** |
| 131 | + - Impact: <concrete user/system impact> |
| 132 | + - Anchor: `<file>` / `<function or code path>` |
| 133 | + - Trigger: <smallest condition that triggers defect> |
| 134 | + - Why defect: <1-2 lines, behavior not preference> |
| 135 | + - Fix direction (short): <2-4 bullets or sentences> |
| 136 | + - Regression test direction (short): <2-4 bullets or sentences including positive and edge/failure cases> |
| 137 | + - Evidence: |
| 138 | + ```start:end:path |
| 139 | + // minimal proving snippet |
| 140 | + ``` |
| 141 | +
|
| 142 | +<repeat per defect, sorted High -> Medium -> Low> |
| 143 | +
|
| 144 | +Coverage summary: |
| 145 | +- Scope reviewed: <partitions or key areas, one line> |
| 146 | +- Categories failed: <count/list> |
| 147 | +- Categories passed: <count only> |
| 148 | +- Assumptions/limits: <one line> |
| 149 | +``` |
| 150 | + |
| 151 | +## Severity Rubric |
| 152 | + |
| 153 | +- High: realistic trigger can cause crash/UB/data corruption/auth bypass/deadlock. |
| 154 | +- Medium: correctness/reliability issue with narrower trigger conditions. |
| 155 | +- Low: diagnostics/consistency issues without direct correctness break. |
| 156 | + |
| 157 | +## Checklist |
| 158 | + |
| 159 | +- Verify call graph is explicitly documented before defect analysis. |
| 160 | +- Verify invariants are explicitly listed and checked against transitions. |
| 161 | +- Verify fail-open vs fail-closed behavior where security-sensitive. |
| 162 | +- Verify logical branch coverage for all changed code paths. |
| 163 | +- Verify fault categories are explicitly defined from the reviewed code before injection starts. |
| 164 | +- Verify category-by-category execution and reporting completeness. |
| 165 | +- Verify full fault-category completion matrix is present and complete. |
| 166 | +- Verify concurrency and cache/state transition paths. |
| 167 | +- Verify multithreaded interleavings are explicitly analyzed for critical shared-state paths. |
| 168 | +- Verify rollback/partial-update safety under exception/cancellation points. |
| 169 | +- Verify major C++ bug classes are explicitly covered (or marked not applicable). |
| 170 | +- Verify race/deadlock/crash class defects are prioritized and explicitly reported. |
| 171 | +- Verify error-contract consistency across equivalent fault paths. |
| 172 | +- Verify performance/resource failure classes were considered. |
| 173 | +- Verify findings are deduplicated by root cause. |
| 174 | +- Verify coverage accounting is present (covered vs skipped with reason). |
| 175 | +- Verify stop-condition criteria for coverage completion are explicitly satisfied. |
| 176 | +- Verify every confirmed defect includes code evidence snippets. |
| 177 | +- Verify parser/config/runtime consistency. |
| 178 | +- Verify protocol/API parity across entrypoints. |
| 179 | +- Verify no sensitive-data leakage in logs/errors. |
0 commit comments