Repository navigation
fix(python-performance-regression): detect repo state instead of hardcoding uv sync --frozen - #173
Conversation
|
Warning Review limit reached
More reviews will be available in 28 minutes and 57 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
This PR updates the reusable python-performance-regression.yml workflow to detect repository state (missing pyproject.toml, Poetry, uv with uv.lock, uv without uv.lock) instead of hardcoding uv sync --frozen, so callers without a lockfile or without a Python project can be handled gracefully.
Changes:
- Added a
Detect repo statestep to classify callers asskip,poetry-not-supported,uv-locked, oruv-no-lock. - Split dependency installation into state-specific
uv syncsteps, and added gating so most benchmark steps only run for uv-managed repos. - Added an extras-flag resolver step to keep install commands single-line while supporting multiple extras.
| run: | | ||
| FLAGS="" | ||
| if [ -n "$EXTRA_DEPENDENCIES" ]; then | ||
| EXTRA_ARGS=() | ||
| while IFS= read -r dep; do | ||
| [[ -n "$dep" ]] && EXTRA_ARGS+=("--extra" "$dep") | ||
| [[ -n "$dep" ]] && FLAGS="$FLAGS --extra $dep" | ||
| done < <(echo "$EXTRA_DEPENDENCIES" | tr ' ' '\n') | ||
| uv sync "${EXTRA_ARGS[@]}" --frozen $NO_BUILD_FLAG | ||
| else | ||
| uv sync --frozen $NO_BUILD_FLAG | ||
| fi | ||
| # Trim leading whitespace; emit single-line for safe word-splitting downstream. | ||
| FLAGS="${FLAGS# }" | ||
| echo "flags=$FLAGS" >> $GITHUB_OUTPUT | ||
| echo "Resolved extras: ${FLAGS:-<none>}" |
| # Baseline-on-main install path. After `git checkout origin/main` the worktree is on | ||
| # main's tree, so uv.lock presence has to be re-checked. We branch on detect.state | ||
| # for the install path (matches the PR-branch install above), then the downstream | ||
| # uv run lines can use literal --frozen with Pattern B (preceding-line NOSONAR). | ||
| - name: Install dependencies on main (uv with lockfile) | ||
| if: steps.baseline_source.outputs.source == 'generated' && steps.detect.outputs.state == 'uv-locked' | ||
| env: | ||
| EXTRA_FLAGS: ${{ steps.extras.outputs.flags }} | ||
| run: uv sync $EXTRA_FLAGS --frozen $NO_BUILD_FLAG # NOSONAR(S8541): --no-build is opt-out via `no-build` workflow input | ||
| shell: bash | ||
|
|
||
| - name: Install dependencies on main (uv without lockfile) | ||
| if: steps.baseline_source.outputs.source == 'generated' && steps.detect.outputs.state == 'uv-no-lock' | ||
| env: | ||
| EXTRA_FLAGS: ${{ steps.extras.outputs.flags }} | ||
| run: uv sync $EXTRA_FLAGS $NO_BUILD_FLAG # NOSONAR(S8541,S8544): --no-build opt-out via `no-build` input; no uv.lock by design on this path (uv sync creates one) | ||
| shell: bash |
|
|
||
| - name: Post PR Comment | ||
| if: inputs.comment-on-pr && github.event_name == 'pull_request' | ||
| if: inputs.comment-on-pr && github.event_name == 'pull_request' && (steps.detect.outputs.state == 'uv-locked' || steps.detect.outputs.state == 'uv-no-lock') |
| fi | ||
| echo "✅ Benchmark script found: $BENCHMARK_SCRIPT" | ||
|
|
PR ReviewIndependent review by Claude on top of Copilot and CodeRabbit. All CI checks green; SonarCloud gate passed. Branch is BEHIND main, rebase needed before merge. Critical (must fix before merge)
Important (should fix)
Two Suggested and one Informational finding omitted from this comment for brevity (see review session for the full report). All CLAUDE.md compliance checks pass (no em-dashes, no emoji in new echoes, CodeRabbit review completed (no inline comments surfaced via API). Copilot's four comments are incorporated above, with one technical correction on the injection framing. Generated with Claude Code |
PR #170 strengthened the NOSONAR rule based on Wave 1C (PR #166), which found that comma-separated NOSONAR and inline-trailing NOSONAR inside run: | blocks are not honored. The strengthened rule was framed as "any NOSONAR inside run: | is unreliable; treat Pattern B as a lucky non-failure." Subsequent Waves 2B (PR #172, python-mutation) and 2C (PR #173, python- performance-regression) re-validated Pattern B with passing SonarCloud gates. Both PRs kept multi-line run: | blocks with literal --frozen on every uv line and preceding-line single-rule # NOSONAR(S8541). Both achieved gate=OK with 0 vulns on first push. The evidence supports a more nuanced rule: Pattern B is reliable when three conditions hold simultaneously. 1. Every uv invocation in the run: | block uses literal --frozen (not dynamic $FROZEN_FLAG). 2. NOSONAR is single-rule S8541 only, not comma-separated. 3. NOSONAR is on the preceding line, not inline-trailing. Updates to docs/sonarcloud-nosonar-patterns.md: - TL;DR table: split the prior "Preceding-line with literal --frozen" row into two rows that distinguish the working condition (single-rule S8541) from the failure modes (comma-separated or inline-trailing). - TL;DR Rule of thumb: replace "single-line run: only" framing with "two predictable shapes" framing, listing both Pattern A and the conditioned Pattern B. - Recommended Patterns: replace "Pattern B (fragile)" framing with "Pattern B (acceptable under specific conditions)" plus an explicit three-condition reliability list. Note 3-for-3 empirical track record when conditions hold. - Date line: add "nuanced 2026-05-26" with PR pointer. The earlier strengthened rule was over-pessimistic. This nuance does not contradict it; both PRs #166 and #170 documented failure modes correctly, and PRs #172 and #173 demonstrated the working conditions. Future Phase 2 or 3 implementers should default to Pattern A but may use Pattern B when the three conditions hold. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Addresses PR #174 review findings: Critical - Anti-patterns heading at line 145 narrowed from "any NOSONAR inside run: | blocks" to "unreliable NOSONAR forms inside run: | blocks", since the body of the same PR now endorses Pattern B (preceding-line single-rule NOSONAR with literal --frozen) inside run: | blocks. - Hypothesis section (lines 88-107) rewritten: the absolute Wave 1C claim that "no NOSONAR placement inside a run: | block scalar is reliable" was the surviving prior framing that contradicted the new Pattern B framing. Reframed as historical Wave 1C conclusion now superseded by Wave 2B/2C re-validation. Important - "3-for-3" reliability claim qualified: PR #173 is open at time of writing with a passing pre-merge gate; reframed as "2 merged applications plus 1 pre-merge gate pass" so readers do not treat all three legs as production-validated. Suggested - Pattern B uv-line count corrected from "11 uv lines across 4 blocks" to "11 uv lines across 5 blocks" (actual count of run: | blocks added in PR #173). - TL;DR rule-of-thumb sentence deduplicated against the identical sentence in the Pattern B detail section, now references the Verification protocol section instead. Informational - "Lucky non-failure" jargon at line 141 rewritten to be self-contained for first-time readers. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ce (#174) * docs(sonarcloud): nuance Pattern B reliability with Wave 2B/2C evidence PR #170 strengthened the NOSONAR rule based on Wave 1C (PR #166), which found that comma-separated NOSONAR and inline-trailing NOSONAR inside run: | blocks are not honored. The strengthened rule was framed as "any NOSONAR inside run: | is unreliable; treat Pattern B as a lucky non-failure." Subsequent Waves 2B (PR #172, python-mutation) and 2C (PR #173, python- performance-regression) re-validated Pattern B with passing SonarCloud gates. Both PRs kept multi-line run: | blocks with literal --frozen on every uv line and preceding-line single-rule # NOSONAR(S8541). Both achieved gate=OK with 0 vulns on first push. The evidence supports a more nuanced rule: Pattern B is reliable when three conditions hold simultaneously. 1. Every uv invocation in the run: | block uses literal --frozen (not dynamic $FROZEN_FLAG). 2. NOSONAR is single-rule S8541 only, not comma-separated. 3. NOSONAR is on the preceding line, not inline-trailing. Updates to docs/sonarcloud-nosonar-patterns.md: - TL;DR table: split the prior "Preceding-line with literal --frozen" row into two rows that distinguish the working condition (single-rule S8541) from the failure modes (comma-separated or inline-trailing). - TL;DR Rule of thumb: replace "single-line run: only" framing with "two predictable shapes" framing, listing both Pattern A and the conditioned Pattern B. - Recommended Patterns: replace "Pattern B (fragile)" framing with "Pattern B (acceptable under specific conditions)" plus an explicit three-condition reliability list. Note 3-for-3 empirical track record when conditions hold. - Date line: add "nuanced 2026-05-26" with PR pointer. The earlier strengthened rule was over-pessimistic. This nuance does not contradict it; both PRs #166 and #170 documented failure modes correctly, and PRs #172 and #173 demonstrated the working conditions. Future Phase 2 or 3 implementers should default to Pattern A but may use Pattern B when the three conditions hold. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * docs(sonarcloud): resolve internal contradictions in Pattern B framing Addresses PR #174 review findings: Critical - Anti-patterns heading at line 145 narrowed from "any NOSONAR inside run: | blocks" to "unreliable NOSONAR forms inside run: | blocks", since the body of the same PR now endorses Pattern B (preceding-line single-rule NOSONAR with literal --frozen) inside run: | blocks. - Hypothesis section (lines 88-107) rewritten: the absolute Wave 1C claim that "no NOSONAR placement inside a run: | block scalar is reliable" was the surviving prior framing that contradicted the new Pattern B framing. Reframed as historical Wave 1C conclusion now superseded by Wave 2B/2C re-validation. Important - "3-for-3" reliability claim qualified: PR #173 is open at time of writing with a passing pre-merge gate; reframed as "2 merged applications plus 1 pre-merge gate pass" so readers do not treat all three legs as production-validated. Suggested - Pattern B uv-line count corrected from "11 uv lines across 4 blocks" to "11 uv lines across 5 blocks" (actual count of run: | blocks added in PR #173). - TL;DR rule-of-thumb sentence deduplicated against the identical sentence in the Pattern B detail section, now references the Verification protocol section instead. Informational - "Lucky non-failure" jargon at line 141 rewritten to be self-contained for first-time readers. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
…coding uv sync/run --frozen Apply established NOSONAR detect-state pattern (see python-mutation.yml:159-169) to the largest reusable workflow in the org (642 lines, 17 unguarded uv invocations across 8 install/run steps). Changes: - Add `Detect repo state` step that branches on pyproject.toml + lockfile presence: skip when no pyproject, fail fast on poetry repos with actionable error, install with --frozen on uv-locked repos, install without --frozen on uv-no-lock repos (uv sync creates the lockfile on that path). - Add `Resolve extra dependency flags` helper step (Option 3 from PR #166) that builds a flat "--extra dev --extra ml" string output, so the per-state install steps can be single-line Pattern A NOSONAR placement. - Split the two install steps (PR-branch and main-branch) into uv-locked / uv-no-lock variants each, four total. Pattern A inline NOSONAR(S8541) on uv-locked (literal --frozen visible); NOSONAR(S8541,S8544) on uv-no-lock where --frozen is structurally absent by design. - Apply Pattern B (preceding-line NOSONAR(S8541) inside `run: |`) to the three multi-line shell blocks (Run PR Benchmarks, Run Baseline Benchmarks, Compare Performance). Every uv invocation in these blocks carries literal --frozen, so only S8541 needs suppression. Per docs/sonarcloud-nosonar- patterns.md strengthened 2026-05-26, Pattern B is acceptable when literal --frozen is structurally present and only S8541 fires. The blocks are genuinely multi-line (capability detection branching with three argv variants, Python heredoc) so collapsing to single-line is not feasible without significant readability loss. - Add `Skip notice` step for the no-pyproject path so downstream callers see a clear summary entry instead of a silent green. - Guard all downstream benchmark / summary / PR-comment / fail steps with `if: steps.detect.outputs.state == 'uv-locked' || == 'uv-no-lock'` so the workflow exits cleanly when no pyproject is present. S8541 suppression rationale: `$NO_BUILD_FLAG` (from inputs.no-build, default 'true' -> '--no-build') is dynamic by design so consumers with PEP 517 build backends like hatchling can pass `no-build: false`. SonarCloud cannot resolve the env var. The lockfile-based `uv sync --frozen` (uv-locked path) constrains installable versions to the consumer's audited uv.lock, bounding residual setup-script risk. Wave 2C of CI Repair Sprint Phase 2. Largest single-file change in the sprint.
…n PR #173 Resolves four issues raised in Copilot's review and one related design smell surfaced by the /pr-review pass. Critical: - Install-on-main now re-detects uv.lock presence inline via [ -f uv.lock ] rather than trusting steps.detect.outputs.state. The original gating used the PR-branch detection after `git checkout origin/main`, which misclassifies main when the PR adds or removes uv.lock. Collapses the two install-on-main steps into one with a shell-level branch. - Validate Benchmark Script now carries the same detect-state guard as adjacent steps, so the skip path (no pyproject.toml) actually skips instead of failing on a missing benchmark script. Important: - Compare Performance no longer calls sys.exit(1) on regression. The dedicated `Fail on Regression` step at the end of the job is now the single source of failure-on-regression behavior. Post PR Comment and Performance Summary now run on regression, which is the case where they matter most. Removes the unused `import sys` and the redundant FAIL_ON_REGRESSION env var on the Compare step. - Resolve extra dependency flags validates each extra against the PEP 508 allowlist (^[A-Za-z0-9._-]+\$) before emitting it; caller-controlled bytes can no longer reach the downstream `uv sync \$EXTRA_FLAGS` expansion. Whitespace separators (space, tab, or newlines from YAML block scalars) are normalized via `tr -s`. Verification: - actionlint -shellcheck= passes - yamllint passes (existing line-length warnings unchanged) - pre-commit run --files passes (no-em-dash hook included)
1f732ea to
fda25ca
Compare
PR Fix SummaryAll findings from the Critical fixes (2/2)
Important fixes (3/3)
Suggested fixes (1/2)
Skipped / deferred
Verification (local)
Remote CI will re-trigger on the force-push. Watch-and-refix loop active.
Generated with Claude Code |
… for SonarCloud
SonarCloud quality gate failed on the previous push with 11 new S8541
(and one S8544) issues because the workflow's prior Pattern B (preceding-
line `# NOSONAR(...)` inside `run: |`) is not recognized by SonarCloud's
standard NOSONAR mechanism, which is documented as same-line only.
Conversion:
- Single-line invocations get NOSONAR appended at end of line (Generate
Synthetic Test Data, Install dependencies on main x2, Compare
Performance heredoc opener).
- Multi-line capability checks (`uv run ... --help | grep ...`) get
NOSONAR appended at end of the existing single line.
- Multi-line benchmark execution branches in Run PR Benchmarks and Run
Baseline Benchmarks have their `uv run` argv collapsed onto one line
(no more `\`-continuations) so a same-line NOSONAR can sit on the same
line as the `uv run --frozen $NO_BUILD_FLAG` invocation. The `|| {
... }` fallback brace groups stay multi-line for readability.
Stale comments about "Pattern B (preceding-line NOSONAR inside run: |)
is acceptable here because..." removed; replaced with brief notes
explaining the same-line NOSONAR rationale.
Verification:
- actionlint -shellcheck= passes
- yamllint passes (8 new line-length warnings from collapsed `uv run`
lines; warnings only, not errors)
- pre-commit run --files passes
…n-main, revert Pattern A churn Revert commit 46e462b. Per docs/sonarcloud-nosonar-patterns.md (nuanced in PR #174, merged 2026-05-25), inline-trailing NOSONAR inside `run: |` block scalars is NOT honored by SonarCloud's githubactions rule set, and the preceding-line Pattern B form IS reliable when three conditions hold: literal --frozen on every uv line, single-rule S8541 only, no dynamic $FROZEN_FLAG. The collapse-to-single-line approach in 46e462b violated condition #3 (inline-trailing) and triggered 21 new MAJOR vulnerabilities on the SonarCloud gate, up from 11. This revert restores Pattern B at all original locations. Restructure the `Install dependencies on main` step (still incorrect even at the fda25ca state) to satisfy SonarCloud: - Replace the `run: |` block + `[ -f uv.lock ]` shell check (which used comma-separated NOSONAR(S8541,S8544) for the uv-no-lock branch, violating Pattern B condition #2) with two single-line `run:` steps. - Gate each step with `hashFiles('uv.lock')` instead of the stale `steps.detect.outputs.state`. hashFiles() re-evaluates per step against the current worktree, so after `Checkout Main Branch` it correctly reflects main's tree (the original Copilot finding). - Each single-line step uses Pattern A (inline NOSONAR), which IS the most reliable form per the docs and accepts comma-separated rule lists (the uv-no-lock branch carries NOSONAR(S8541,S8544)). This combines the correctness fix for the Copilot install-on-main finding with the SonarCloud-compatible suppression shape, replacing the previous flawed attempt.
|
PR Fix: All GreenAll 20/20 CI checks now pass on What changed in cycle 2Cycle 1 ( Cycle 2 (one wasted iteration, Cycle 3 (
Net effect: same correctness as cycle 1's intent, but with the SonarCloud-compatible shape. Final state
Test plan items 2 and 3 in the PR description are now verifiably true and can be checked off; item 4 still requires post-merge validation. Generated with Claude Code |



Summary
python-performance-regression.yml(largest reusable workflow in the org, 642 lines, 17 unguarded uv invocations)..github/workflows/python-mutation.yml:159-169(Wave 2B / PR fix(python-mutation): apply detect-state pattern with single-line install #172).Pattern application
run:# NOSONAR(S8541)extrasemits flat--extrastring so install is single-linerun:# NOSONAR(S8541,S8544)--frozenabsent by design (uv sync creates the lockfile)run:# NOSONAR(S8541)git checkout origin/mainrun:# NOSONAR(S8541,S8544)run: |# NOSONAR(S8541)--frozenpresentrun: |# NOSONAR(S8541)per uv runrun: |# NOSONAR(S8541)per uv runrun: |# NOSONAR(S8541)Pattern B is acceptable per strengthened guidance (2026-05-26): every uv invocation inside these
run: |blocks carries literal--frozen, so only S8541 (dynamic$NO_BUILD_FLAG) needs suppression. S8544 does not fire structurally. SonarCloud gate verification per PR is the empirical check.Skip / fail-fast handling
state=skip; downstream steps gated;Skip noticestep writes a clear summary entry.state=poetry-not-supported; immediate failure with actionable error.skiprun exits green.S8541 rationale (cite in every detect-state PR)
$NO_BUILD_FLAG(frominputs.no-build, defaulttrue->--no-build) is dynamic by design so consumers with PEP 517 build backends like hatchling can passno-build: false. SonarCloud's static analyzer cannot resolve the env var. The lockfile-baseduv sync --frozen(uv-locked path) constrains installable versions to the consumer's auditeduv.lock.Test plan
-shellcheck=to skip pre-existing SC2086 noise on unrelated lines)