From 934869275f2769155430ea8e226dee5291719e25 Mon Sep 17 00:00:00 2001 From: Prekshi Vyas Date: Mon, 13 Jul 2026 12:17:54 -0700 Subject: [PATCH 1/6] feat(pr-advisor): add purpose-driven adversarial reasoning to correctness stage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Teach the correctness stage to derive bypass paths from the PR's stated guarantee rather than applying a generic checklist. When a PR claims a fail-closed property, the advisor now enumerates alternate branches, combined input states, and external-spec assumptions that could silently violate it — the same reasoning pattern that caught three successive blockers in #6771 that CI and prior review missed. Signed-off-by: Prekshi Vyas Co-Authored-By: Claude Sonnet 4.6 --- tools/pr-review-advisor/analyze.mts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/pr-review-advisor/analyze.mts b/tools/pr-review-advisor/analyze.mts index efd4d93ecd5..2ee77cf921b 100755 --- a/tools/pr-review-advisor/analyze.mts +++ b/tools/pr-review-advisor/analyze.mts @@ -1740,6 +1740,8 @@ Do not produce final JSON or update the finding ledger in this turn. Reply with Use the PR diff already fetched by the scope/risk stage as shared conversation evidence, and call read-only repository tools when a citation needs confirmation. First classify linked issue text as binding acceptance or non-binding context using the system rubric, then map only binding clauses to code evidence. Review caller/callee contracts, state transitions, negative and error paths, behavior drift, documentation or migration gaps, and any fallback, recovery, tolerant parsing, monkeypatch, workaround, or compatibility behavior against the source-of-truth questions in the system rubric. Apply the simplification ladder only where it preserves correctness and trust boundaries. Leave detailed security and test-depth review to their dedicated turns. +When the PR's summary states a correctness guarantee (fail-closed check, locality invariant, ordering constraint, capacity gate), identify the guarantee and enumerate the specific ways it could be silently bypassed: alternate code branches (e.g. cache-hit paths that skip the check), combined input states (e.g. multiple env vars set simultaneously with documented precedence that differs from implementation), and external system contract assumptions (e.g. what "unix://" actually proves about daemon locality). For each bypass path, verify against the diff whether it is closed, explicitly opted out, or unaddressed. When the implementation makes assumptions about an external system's behavior (env var precedence, API semantics, filesystem guarantees), verify the assumption against upstream documentation using read-only tools, not just internal code consistency. + Do not produce final JSON or update the finding ledger in this turn. Reply with at most 8 concise, evidence-backed stage-analysis bullets; if this domain is not applicable, include that limitation in one bullet. `, }, From f540ec3532b3b310bb84660024b222da5f0fad3a Mon Sep 17 00:00:00 2001 From: Prekshi Vyas Date: Mon, 13 Jul 2026 16:35:28 -0700 Subject: [PATCH 2/6] fix(pr-advisor): require authorized contract before accepting opt-out in bypass analysis --- tools/pr-review-advisor/analyze.mts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/pr-review-advisor/analyze.mts b/tools/pr-review-advisor/analyze.mts index b5643ecf085..1100a6061fe 100755 --- a/tools/pr-review-advisor/analyze.mts +++ b/tools/pr-review-advisor/analyze.mts @@ -1840,7 +1840,7 @@ Do not produce final JSON or update the finding ledger in this turn. Reply with Use the PR diff already fetched by the scope/risk stage as shared conversation evidence, and call read-only repository tools when a citation needs confirmation. First classify linked issue text as binding acceptance or non-binding context using the system rubric, then map only binding clauses to code evidence. Review caller/callee contracts, state transitions, negative and error paths, behavior drift, documentation or migration gaps, and any fallback, recovery, tolerant parsing, monkeypatch, workaround, or compatibility behavior against the source-of-truth questions in the system rubric. Apply the simplification ladder only where it preserves correctness and trust boundaries. Leave detailed security and test-depth review to their dedicated turns. -When the PR's summary states a correctness guarantee (fail-closed check, locality invariant, ordering constraint, capacity gate), identify the guarantee and enumerate the specific ways it could be silently bypassed: alternate code branches (e.g. cache-hit paths that skip the check), combined input states (e.g. multiple env vars set simultaneously with documented precedence that differs from implementation), and external system contract assumptions (e.g. what "unix://" actually proves about daemon locality). For each bypass path, verify against the diff whether it is closed, explicitly opted out, or unaddressed. When the implementation makes assumptions about an external system's behavior (env var precedence, API semantics, filesystem guarantees), verify the assumption against upstream documentation using read-only tools, not just internal code consistency. +When the PR's summary states a correctness guarantee (fail-closed check, locality invariant, ordering constraint, capacity gate), identify the guarantee and enumerate the specific ways it could be silently bypassed: alternate code branches (e.g. cache-hit paths that skip the check), combined input states (e.g. multiple env vars set simultaneously with documented precedence that differs from implementation), and external system contract assumptions (e.g. what "unix://" actually proves about daemon locality). For each bypass path, verify against the diff whether it is closed, explicitly opted out under an authorized contract/non-goal, or unaddressed; unauthorized opt-outs remain unaddressed. When the implementation makes assumptions about an external system's behavior (env var precedence, API semantics, filesystem guarantees), verify the assumption against upstream documentation using read-only tools, not just internal code consistency. Do not produce final JSON or update the finding ledger in this turn. Reply with at most 8 concise, evidence-backed stage-analysis bullets; if this domain is not applicable, include that limitation in one bullet. `, From e77c0867e5267ff3cf6c084b26bf702071c4013c Mon Sep 17 00:00:00 2001 From: Prekshi Vyas Date: Mon, 13 Jul 2026 16:43:34 -0700 Subject: [PATCH 3/6] fix(pr-advisor): broaden bypass trigger, expand guarantees, add doc-unavailable fallback --- tools/pr-review-advisor/analyze.mts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/pr-review-advisor/analyze.mts b/tools/pr-review-advisor/analyze.mts index 1100a6061fe..b6ba5e6d806 100755 --- a/tools/pr-review-advisor/analyze.mts +++ b/tools/pr-review-advisor/analyze.mts @@ -1840,7 +1840,7 @@ Do not produce final JSON or update the finding ledger in this turn. Reply with Use the PR diff already fetched by the scope/risk stage as shared conversation evidence, and call read-only repository tools when a citation needs confirmation. First classify linked issue text as binding acceptance or non-binding context using the system rubric, then map only binding clauses to code evidence. Review caller/callee contracts, state transitions, negative and error paths, behavior drift, documentation or migration gaps, and any fallback, recovery, tolerant parsing, monkeypatch, workaround, or compatibility behavior against the source-of-truth questions in the system rubric. Apply the simplification ladder only where it preserves correctness and trust boundaries. Leave detailed security and test-depth review to their dedicated turns. -When the PR's summary states a correctness guarantee (fail-closed check, locality invariant, ordering constraint, capacity gate), identify the guarantee and enumerate the specific ways it could be silently bypassed: alternate code branches (e.g. cache-hit paths that skip the check), combined input states (e.g. multiple env vars set simultaneously with documented precedence that differs from implementation), and external system contract assumptions (e.g. what "unix://" actually proves about daemon locality). For each bypass path, verify against the diff whether it is closed, explicitly opted out under an authorized contract/non-goal, or unaddressed; unauthorized opt-outs remain unaddressed. When the implementation makes assumptions about an external system's behavior (env var precedence, API semantics, filesystem guarantees), verify the assumption against upstream documentation using read-only tools, not just internal code consistency. +When the diff introduces or modifies a correctness-critical path — whether or not the PR summary labels it — identify any correctness guarantee the change makes or depends on (fail-closed check, locality invariant, ordering constraint, capacity gate, idempotency guarantee, atomicity or rollback boundary, rate or auth gate) and enumerate the specific ways it could be silently bypassed: alternate code branches (e.g. cache-hit paths that skip the check), combined input states (e.g. multiple env vars set simultaneously with documented precedence that differs from implementation), and external system contract assumptions (e.g. what "unix://" actually proves about daemon locality). For each bypass path, verify against the diff whether it is closed, explicitly opted out under an authorized contract/non-goal, or unaddressed; unauthorized opt-outs remain unaddressed. When the implementation makes assumptions about an external system's behavior (env var precedence, API semantics, filesystem guarantees), verify the assumption against upstream documentation using read-only tools, not just internal code consistency; if upstream documentation is unavailable or ambiguous, flag the assumption as unverified rather than treating it as confirmed. Do not produce final JSON or update the finding ledger in this turn. Reply with at most 8 concise, evidence-backed stage-analysis bullets; if this domain is not applicable, include that limitation in one bullet. `, From ea6f7b8a02834417111aaae707433664bcfbfd0d Mon Sep 17 00:00:00 2001 From: Prekshi Vyas Date: Mon, 13 Jul 2026 16:46:06 -0700 Subject: [PATCH 4/6] fix(pr-advisor): sharpen bypass trigger, cover deletions, add error-path/TOCTOU/default gaps --- tools/pr-review-advisor/analyze.mts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/pr-review-advisor/analyze.mts b/tools/pr-review-advisor/analyze.mts index b6ba5e6d806..e6fdebaaffc 100755 --- a/tools/pr-review-advisor/analyze.mts +++ b/tools/pr-review-advisor/analyze.mts @@ -1840,7 +1840,7 @@ Do not produce final JSON or update the finding ledger in this turn. Reply with Use the PR diff already fetched by the scope/risk stage as shared conversation evidence, and call read-only repository tools when a citation needs confirmation. First classify linked issue text as binding acceptance or non-binding context using the system rubric, then map only binding clauses to code evidence. Review caller/callee contracts, state transitions, negative and error paths, behavior drift, documentation or migration gaps, and any fallback, recovery, tolerant parsing, monkeypatch, workaround, or compatibility behavior against the source-of-truth questions in the system rubric. Apply the simplification ladder only where it preserves correctness and trust boundaries. Leave detailed security and test-depth review to their dedicated turns. -When the diff introduces or modifies a correctness-critical path — whether or not the PR summary labels it — identify any correctness guarantee the change makes or depends on (fail-closed check, locality invariant, ordering constraint, capacity gate, idempotency guarantee, atomicity or rollback boundary, rate or auth gate) and enumerate the specific ways it could be silently bypassed: alternate code branches (e.g. cache-hit paths that skip the check), combined input states (e.g. multiple env vars set simultaneously with documented precedence that differs from implementation), and external system contract assumptions (e.g. what "unix://" actually proves about daemon locality). For each bypass path, verify against the diff whether it is closed, explicitly opted out under an authorized contract/non-goal, or unaddressed; unauthorized opt-outs remain unaddressed. When the implementation makes assumptions about an external system's behavior (env var precedence, API semantics, filesystem guarantees), verify the assumption against upstream documentation using read-only tools, not just internal code consistency; if upstream documentation is unavailable or ambiguous, flag the assumption as unverified rather than treating it as confirmed. +When the diff adds, modifies, or removes a conditional that gates an operation, a function whose comments or tests describe an invariant, or a guard that prior code or issues treat as required — whether or not the PR summary labels it as a correctness guarantee — identify any guarantee the change makes or depends on (fail-closed check, locality invariant, ordering constraint, capacity gate, idempotency guarantee, atomicity or rollback boundary, rate or auth gate) and enumerate the specific ways it could be silently bypassed: alternate code branches (e.g. cache-hit paths that skip the check), combined input states (e.g. multiple env vars set simultaneously with documented precedence that differs from implementation), external system contract assumptions (e.g. what "unix://" actually proves about daemon locality), error path bypasses (e.g. an upstream call throws and the guard is skipped entirely), TOCTOU windows (e.g. state changes between the check and the operation it guards), and default or absent value assumptions (e.g. null vs empty vs absent behaving differently at a boundary). For each bypass path, verify against the diff whether it is closed, explicitly opted out under an authorized contract/non-goal, or unaddressed; unauthorized opt-outs remain unaddressed. When the implementation makes assumptions about an external system's behavior (env var precedence, API semantics, filesystem guarantees), verify the assumption against upstream documentation using read-only tools, not just internal code consistency; if upstream documentation is unavailable or ambiguous, flag the assumption as unverified rather than treating it as confirmed. Do not produce final JSON or update the finding ledger in this turn. Reply with at most 8 concise, evidence-backed stage-analysis bullets; if this domain is not applicable, include that limitation in one bullet. `, From 68d8c9c0fcf1c1a3a91efb08d89b06f7c3145148 Mon Sep 17 00:00:00 2001 From: Prekshi Vyas Date: Mon, 13 Jul 2026 16:47:05 -0700 Subject: [PATCH 5/6] fix(pr-advisor): cap bypass analysis at 2-3 bullets to preserve correctness stage budget --- tools/pr-review-advisor/analyze.mts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/pr-review-advisor/analyze.mts b/tools/pr-review-advisor/analyze.mts index e6fdebaaffc..3044d848434 100755 --- a/tools/pr-review-advisor/analyze.mts +++ b/tools/pr-review-advisor/analyze.mts @@ -1842,7 +1842,7 @@ Use the PR diff already fetched by the scope/risk stage as shared conversation e When the diff adds, modifies, or removes a conditional that gates an operation, a function whose comments or tests describe an invariant, or a guard that prior code or issues treat as required — whether or not the PR summary labels it as a correctness guarantee — identify any guarantee the change makes or depends on (fail-closed check, locality invariant, ordering constraint, capacity gate, idempotency guarantee, atomicity or rollback boundary, rate or auth gate) and enumerate the specific ways it could be silently bypassed: alternate code branches (e.g. cache-hit paths that skip the check), combined input states (e.g. multiple env vars set simultaneously with documented precedence that differs from implementation), external system contract assumptions (e.g. what "unix://" actually proves about daemon locality), error path bypasses (e.g. an upstream call throws and the guard is skipped entirely), TOCTOU windows (e.g. state changes between the check and the operation it guards), and default or absent value assumptions (e.g. null vs empty vs absent behaving differently at a boundary). For each bypass path, verify against the diff whether it is closed, explicitly opted out under an authorized contract/non-goal, or unaddressed; unauthorized opt-outs remain unaddressed. When the implementation makes assumptions about an external system's behavior (env var precedence, API semantics, filesystem guarantees), verify the assumption against upstream documentation using read-only tools, not just internal code consistency; if upstream documentation is unavailable or ambiguous, flag the assumption as unverified rather than treating it as confirmed. -Do not produce final JSON or update the finding ledger in this turn. Reply with at most 8 concise, evidence-backed stage-analysis bullets; if this domain is not applicable, include that limitation in one bullet. +Do not produce final JSON or update the finding ledger in this turn. Reply with at most 8 concise, evidence-backed stage-analysis bullets; if this domain is not applicable, include that limitation in one bullet. Bypass analysis (from the paragraph above) must fit within 2–3 of those bullets — consolidate multiple bypass paths under one bullet per guarantee rather than one bullet per path, so the remaining budget covers caller/callee contracts, state transitions, behavior drift, and other correctness checks. `, }, { From eed9fb30371147ba074cc5daee83599aec14c6b0 Mon Sep 17 00:00:00 2001 From: Prekshi Vyas Date: Mon, 13 Jul 2026 16:52:38 -0700 Subject: [PATCH 6/6] fix(pr-advisor): drop issues as trigger signal; anchor opt-out to author_association --- tools/pr-review-advisor/analyze.mts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/pr-review-advisor/analyze.mts b/tools/pr-review-advisor/analyze.mts index 3044d848434..94857768db7 100755 --- a/tools/pr-review-advisor/analyze.mts +++ b/tools/pr-review-advisor/analyze.mts @@ -1840,7 +1840,7 @@ Do not produce final JSON or update the finding ledger in this turn. Reply with Use the PR diff already fetched by the scope/risk stage as shared conversation evidence, and call read-only repository tools when a citation needs confirmation. First classify linked issue text as binding acceptance or non-binding context using the system rubric, then map only binding clauses to code evidence. Review caller/callee contracts, state transitions, negative and error paths, behavior drift, documentation or migration gaps, and any fallback, recovery, tolerant parsing, monkeypatch, workaround, or compatibility behavior against the source-of-truth questions in the system rubric. Apply the simplification ladder only where it preserves correctness and trust boundaries. Leave detailed security and test-depth review to their dedicated turns. -When the diff adds, modifies, or removes a conditional that gates an operation, a function whose comments or tests describe an invariant, or a guard that prior code or issues treat as required — whether or not the PR summary labels it as a correctness guarantee — identify any guarantee the change makes or depends on (fail-closed check, locality invariant, ordering constraint, capacity gate, idempotency guarantee, atomicity or rollback boundary, rate or auth gate) and enumerate the specific ways it could be silently bypassed: alternate code branches (e.g. cache-hit paths that skip the check), combined input states (e.g. multiple env vars set simultaneously with documented precedence that differs from implementation), external system contract assumptions (e.g. what "unix://" actually proves about daemon locality), error path bypasses (e.g. an upstream call throws and the guard is skipped entirely), TOCTOU windows (e.g. state changes between the check and the operation it guards), and default or absent value assumptions (e.g. null vs empty vs absent behaving differently at a boundary). For each bypass path, verify against the diff whether it is closed, explicitly opted out under an authorized contract/non-goal, or unaddressed; unauthorized opt-outs remain unaddressed. When the implementation makes assumptions about an external system's behavior (env var precedence, API semantics, filesystem guarantees), verify the assumption against upstream documentation using read-only tools, not just internal code consistency; if upstream documentation is unavailable or ambiguous, flag the assumption as unverified rather than treating it as confirmed. +When the diff adds, modifies, or removes a conditional that gates an operation, a function whose comments or tests describe an invariant, or a guard that prior code or checked-in tests treat as required — whether or not the PR summary labels it as a correctness guarantee — identify any guarantee the change makes or depends on (fail-closed check, locality invariant, ordering constraint, capacity gate, idempotency guarantee, atomicity or rollback boundary, rate or auth gate) and enumerate the specific ways it could be silently bypassed: alternate code branches (e.g. cache-hit paths that skip the check), combined input states (e.g. multiple env vars set simultaneously with documented precedence that differs from implementation), external system contract assumptions (e.g. what "unix://" actually proves about daemon locality), error path bypasses (e.g. an upstream call throws and the guard is skipped entirely), TOCTOU windows (e.g. state changes between the check and the operation it guards), and default or absent value assumptions (e.g. null vs empty vs absent behaving differently at a boundary). For each bypass path, verify against the diff whether it is closed, explicitly opted out under a maintainer decision (author_association OWNER/MEMBER/COLLABORATOR) or documented non-goal, or unaddressed; unauthorized opt-outs remain unaddressed. When the implementation makes assumptions about an external system's behavior (env var precedence, API semantics, filesystem guarantees), verify the assumption against upstream documentation using read-only tools, not just internal code consistency; if upstream documentation is unavailable or ambiguous, flag the assumption as unverified rather than treating it as confirmed. Do not produce final JSON or update the finding ledger in this turn. Reply with at most 8 concise, evidence-backed stage-analysis bullets; if this domain is not applicable, include that limitation in one bullet. Bypass analysis (from the paragraph above) must fit within 2–3 of those bullets — consolidate multiple bypass paths under one bullet per guarantee rather than one bullet per path, so the remaining budget covers caller/callee contracts, state transitions, behavior drift, and other correctness checks. `,