Skip to content

detect package-library mutations by resolving call namespaces - #18095

Merged
kevinushey merged 1 commit into
mainfrom
bugfix/17758-package-mutation-detection
Jul 1, 2026
Merged

kevinushey merged 1 commit into
mainfrom
bugfix/17758-package-mutation-detection

Conversation

@kevinushey

Copy link
Copy Markdown
Collaborator

Summary

The Packages pane refresh was triggered whenever console input merely contained a keyword like remove or update. The detection was a substring/keyword regex, so it fired on comments, strings, and identifiers such as str_remove_all(), as well as base R's remove() (object removal) and update() (model refit). Each false positive kicked off a full installed-package scan, which on a large library served over NFS could hang the console for minutes (the session entering uninterruptible D state) -- see #17758.

Approach

Replace the keyword regex with a two-stage check:

  1. C++ pre-filter (containsCallSyntax) -- a deliberately dumb regex that only asks "does this input contain a function call?". It carries no package knowledge, so there is no keyword list to keep in sync.
  2. Precise R check (.rs.isPackageManagementCall) -- parses the input and, for each call, resolves its namespace against a strict per-namespace registry of library-mutating functions (utils, renv, pak, pacman, remotes, devtools, BiocManager). Namespace-qualified calls (renv::update()) use the literal namespace; bare calls resolve via a search-path walk.

The bare-call resolver never reads the binding's value (no get(), no mode matching) -- it only tests for the binding's presence and uses the providing environment's name. That keeps it from forcing a promise (delayedAssign) or re-invoking an active binding as a side effect, and it never scans the package library.

As a result, base::remove() / stats::update() are ignored because of what they resolve to, while genuine package operations (install.packages(), remove.packages(), renv::update(), ...) still refresh the pane.

Testing

  • C++ gtests (SessionPackagesTest) updated to cover the pre-filter; pass.
  • New src/cpp/tests/testthat/test-packages.R covers qualified/unqualified resolution, base-R disambiguation, comments/strings, multi-statement and nested calls, unparseable input, and the active-binding / promise side-effect-safety guarantees (45 expectations, all passing).

Fixes #17758.

The Packages pane refresh was triggered whenever console input contained a
keyword like "remove" or "update" -- a regex that fired on comments, strings,
and identifiers such as str_remove_all(), as well as base R's remove()/update().
On a large library (especially over NFS) the resulting library scan could hang
the console for minutes (#17758).

Replace the keyword regex with a two-stage check: a cheap C++ pre-filter
(containsCallSyntax) that just asks whether the input contains a call, gating a
precise R check (.rs.isPackageManagementCall) that parses the input and resolves
each call's namespace against a strict registry of library-mutating functions.
Qualified calls use the literal namespace; bare calls resolve via a search-path
walk that never reads the binding value, so it cannot force a promise or
re-invoke an active binding.

Addresses #17758.
@kevinushey kevinushey added this to the 2026.07 (Pacific Dogwood) milestone Jun 30, 2026
@github-actions

Copy link
Copy Markdown

🍎 macOS Desktop E2E · ARM64

✅ All tests passed!

████████████████████ 100% pass rate

✅ Passed ❌ Failed ⚠️ Skipped 🔁 Flaky
407 0 16 0
📥 Download Playwright report

⬇️ playwright-report.zip — extract and open index.html

Includes screenshots, traces, and step-by-step details for every test. Expires in 15 days.


2 shards · macos-26 ARM64 · commit a9f0612b8e6deded490225595272e171bedaea17 · Run #30

@github-actions

Copy link
Copy Markdown

🐧 Linux Server E2E · Ubuntu 24

❌ 1 test(s) failed

███████████████████░ 99% pass rate

✅ Passed ❌ Failed ⚠️ Skipped 🔁 Flaky
393 1 20 4
📥 Download Playwright report

⬇️ playwright-report.zip — extract and open index.html

Includes screenshots, traces, and step-by-step details for every test. Expires in 15 days.


2 shards · ubuntu-24.04 · commit a9f0612b8e6deded490225595272e171bedaea17 · Run #30

@github-actions

Copy link
Copy Markdown

🐧 Linux Desktop E2E · Ubuntu 24

✅ All tests passed!

████████████████████ 100% pass rate

✅ Passed ❌ Failed ⚠️ Skipped 🔁 Flaky
414 0 8 1
📥 Download Playwright report

⬇️ playwright-report.zip — extract and open index.html

Includes screenshots, traces, and step-by-step details for every test. Expires in 15 days.


2 shards · ubuntu-24.04 · commit a9f0612b8e6deded490225595272e171bedaea17 · Run #30

@github-actions

Copy link
Copy Markdown

🪟 Windows Desktop E2E · Server 2025 x64

✅ All tests passed!

████████████████████ 100% pass rate

✅ Passed ❌ Failed ⚠️ Skipped 🔁 Flaky
415 0 10 0
📥 Download Playwright report

⬇️ playwright-report.zip — extract and open index.html

Includes screenshots, traces, and step-by-step details for every test. Expires in 15 days.


2 shards · Windows Server 2025 x64 · commit a9f0612b8e6deded490225595272e171bedaea17 · Run #30

@kevinushey
kevinushey merged commit 7ab0b89 into main Jul 1, 2026
21 of 23 checks passed
@kevinushey
kevinushey deleted the bugfix/17758-package-mutation-detection branch July 1, 2026 04:56
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.

Rstudio slow to index large site-library on NFS

1 participant