Skip to content

drive ppm vulnerability display off the session repositories, not env vars - #17822

Merged
kevinushey merged 2 commits into
mainfrom
bugfix/ppm-vulnerability-enablement
Jun 2, 2026
Merged

kevinushey merged 2 commits into
mainfrom
bugfix/ppm-vulnerability-enablement

Conversation

@kevinushey

Copy link
Copy Markdown
Collaborator

Intent

Fixes a regression introduced by #17808. That PR moved the PPM vulnerability download off the R main thread (addressing the startup delay in #17807), but in the rewrite it reintroduced an isPpmIntegrationEnabled() gate on the vulnerability path -- in both refreshVulnerabilitiesAsync() (C++) and getVulnerabilityRequestPlan() (R).

isPpmIntegrationEnabled() is satisfied only by the Workbench-injected PWB_PPM_* environment variables. So any session that points options(repos) at a Posit Package Manager instance by hand -- without Workbench PPM integration configured -- stopped showing vulnerability badges in the Packages pane entirely.

Vulnerability display is intentionally not opt-in. This was made an explicit decision in 88778df845 ("always try to provide vuln info if available"), which removed an env-var gate that had been applied incidentally when the metadata column landed. The user-facing documentation also describes vulnerabilities as appearing "when the R session has been configured to use Posit Package Manager" (including the public P3M instance), not as a Workbench-gated feature. The env-var gate is meant only for the Workbench-only metadata column.

Changes

  • SessionPPM.cpp: remove the isPpmIntegrationEnabled() early-return in refreshVulnerabilitiesAsync().
  • SessionPPM.R: remove the isIntegrationEnabled() gate at the top of getVulnerabilityRequestPlan(); enablement is again driven by detecting a PPM URL in getOption("repos") (the per-repo fromRepositoryUrl check already in the loop). A cheap PPM-URL pre-filter is added so installed.packages() is still skipped for non-PPM sessions.
  • Both call sites carry comments recording the motivation (and the 88778df845 reference) so this isn't re-broken.
  • test-ppm.R: replace the now-obsolete "returns nothing when integration is disabled" test with a regression guard ("ignores the integration-enabled flag") that builds a plan for a PPM repo even when integration reports disabled; drop the now-dead isIntegrationEnabled()=TRUE mocks from the other plan tests.

The metadata column remains gated by isPpmMetadataColumnEnabled() exactly as before.

Testing

  • cmake --build . --target rsession -- compiles and links cleanly.
  • rstudio-tests --scope r --filter ppm -- [ FAIL 0 | WARN 0 | SKIP 0 | PASS 69 ].
  • rstudio-tests --scope rsession --filter ppm -- 231 passed, 0 failed.

Notes

  • No NEWS.md entry: the regression existed only in 2026.06.0 dailies (reintroduced by move PPM vulnerability download off the R main thread #17808 on 2026-06-01), never in a shipped release.
  • Follow-up (separate rstudio-ide-automation repo): vulnerability badges are delivered asynchronously, so the QA Playwright assertion on the badge should use a generous explicit timeout rather than the Playwright default.

… vars

Vulnerability badges in the Packages pane are intentionally not opt-in: they
should appear whenever the session is using a Posit Package Manager repository
(a PPM URL in getOption("repos")), including open-source / desktop RStudio. This
was made an explicit decision in 88778df "always try to provide vuln info if
available", which removed an env-var gate that had been applied incidentally.

The async rewrite in #17808 reintroduced that gate, adding isPpmIntegrationEnabled()
early-returns to both refreshVulnerabilitiesAsync() (C++) and
getVulnerabilityRequestPlan() (R). isPpmIntegrationEnabled() requires the
Workbench-injected PWB_PPM_* env vars, so any session that points options(repos)
at PPM by hand (without Workbench PPM integration configured) stopped showing
vulnerability badges entirely.

Remove both gates so enablement is once again driven by repository detection,
keeping the env-var gate only for the Workbench-only metadata column. Add a
cheap PPM-URL pre-filter so installed.packages() is still skipped for non-PPM
sessions, and add comments recording the motivation.
@gtritchie

gtritchie commented Jun 2, 2026 •

Copy link
Copy Markdown
Member

Code Review Summary

A focused, well-reasoned regression fix. Core logic is correct and the non-PPM empty-plan / no-network behavior checks out. No critical issues.

Important Issues (1)

1. vapply over getOption("repos") throws on an NA repo entry -- and this PR widens its reach -- SessionPPM.R:108

The real .rs.regexMatches (gregexpr-based, Tools.R:1243) makes .rs.ppm.fromRepositoryUrl(NA_character_) throw invalid substring arguments (reproduced; "" and the default @CRAN@ return cleanly, so the common desktop case is safe).

isPpmRepo <- vapply(repos, function(url) {
   length(.rs.ppm.fromRepositoryUrl(url)) > 0L
}, logical(1))

This isn't introduced here -- the per-repo loop below already had it -- but it previously ran only after the now-removed isIntegrationEnabled() gate, so non-Workbench sessions never reached it. Now the scan runs unconditionally on every refresh for every session. A single NA in repos aborts the plan; the C++ side logs the error (SessionPPM.cpp:397-403) but the empty cached set is never published, so badges silently never appear. Suggested call-site guard:

is.character(url) && !is.na(url) && length(.rs.ppm.fromRepositoryUrl(url)) > 0L

Low-frequency, but the fix is small and belongs with the change that widened the path.

Suggestions (5)

2. Add a mixed PPM + non-PPM repo test -- test-ppm.R -- The pre-filter is a coarse any() gate; the per-repo loop does the real filtering. A test passing c(CRAN = "https://cran.rstudio.com", PPM = .rs.testPpm$repoUrl) and asserting exactly one plan entry would lock in that a non-PPM repo mixed in doesn't suppress the PPM one. The current multi-repo test uses two PPM repos only.

3. Assert the installed.packages() skip -- SessionPPM.R:106-116 -- The pre-filter's stated purpose is to skip the expensive call for non-PPM sessions, but no test verifies it. Mocking .rs.ppm.installedPackageKeys to stop() and expecting list() for a non-PPM repo set would guard the ordering.

4. .rs.ppm.fromRepositoryUrl has no direct tests -- SessionPPM.R:390 -- The whole vuln path now hinges on its URL classification, including the optional binary/platform/snapshot branches. Worth a dedicated test block (relatedly, the NA case from #1).

5. C++ gate removal is untested -- SessionPPM.cpp:455 -- The R guard covers user-visible behavior, but the C++ early-return is exactly the kind of line a refactor re-adds silently (it has been reintroduced once already). Add coverage if the async test infra supports it.

6. Comment slightly overstates the gate's scope -- SessionPPM.R:98-99 -- "The env-var gate is reserved for the Workbench-only metadata column" -- but isPpmIntegrationEnabled() also feeds ppm_integration_enabled in client session info (SessionClientInit.cpp:548, SessionMain.cpp:969). Minor; consider softening "reserved for" / "gates only". The longer C++ comment phrases it more carefully.

Notes

  • The retained isIntegrationEnabled -> FALSE mock at test-ppm.R:357 is correct to keep despite looking dead -- it is precisely what makes the regression guard fire if the R gate is re-added.
  • No NEWS.md entry is correct -- the regression lived only in unreleased 2026.06.0 dailies.

@gtritchie gtritchie left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall LGTM! One small tweak suggested by the AI that seems worth making if correct.

- guard .rs.ppm.fromRepositoryUrl against non-string/NA repo entries so an
  NA in getOption("repos") no longer aborts the now-unconditional vuln plan
- soften the integration-gate comment (the env-var gate also feeds
  ppm_integration_enabled in client session info)
- add tests: mixed PPM/non-PPM repos, installed.packages() skip for non-PPM
  sessions, NA repo tolerance, and direct fromRepositoryUrl coverage
@kevinushey
kevinushey merged commit 45c0ecf into main Jun 2, 2026
7 of 8 checks passed
@kevinushey
kevinushey deleted the bugfix/ppm-vulnerability-enablement branch June 2, 2026 23:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants