Repository navigation
Description
System details
RStudio Edition : Desktop and Server
RStudio Version : main
OS Version : any (seen on macOS 27)
R Version : any (seen with R 4.6)
Steps to reproduce the problem
Run this in the Console:
src <- file.path(tempdir(), "importer")
dir.create(file.path(src, "R"), recursive = TRUE)
writeLines(
c(
"Package: importer",
"Version: 0.0.1",
"Title: Imports a Hooked Function",
"Description: Imports a hooked function.",
"License: MIT"
),
file.path(src, "DESCRIPTION")
)
writeLines(c("importFrom(utils, write.table)", "export(save_table)"), file.path(src, "NAMESPACE"))
writeLines("save_table <- function(x, file) write.table(x, file)", file.path(src, "R", "save_table.R"))
lib <- file.path(tempdir(), "lib")
dir.create(lib)
install.packages(src, lib = lib, repos = NULL, type = "source", quiet = TRUE)
outside <- tempfile(tmpdir = dirname(tempdir()))
dir.create(outside)
# 1. code run by Posit Assistant loads the package for the first time
.rs.chat.safeEval(quote(loadNamespace("importer", lib.loc = lib)))
# 2. later, the user calls the package from the Console
importer::save_table(mtcars, file.path(outside, "mtcars.txt"))Describe the problem in detail
Step 2 fails with "One or more agent file operations were blocked.", although Posit Assistant is not running anything. utils::write.table() called directly works. The package keeps failing this way until it is unloaded and loaded again, or the session restarts.
Loading a namespace copies the current values of its imports into its imports environment. A package loaded while the checks are installed gets the hooked functions. chat.restoreBindings() puts the originals back in the source namespace and in package:<pkg> only, and the hooks validate paths whether or not Posit Assistant is running code. This affects packages that import utils::download.file(), utils::write.table(), or one of the hooked fs functions, including those that import all of utils.
Describe the behavior you expected
Once Posit Assistant's code has finished, the checks don't apply to the user's own calls, including calls through a package that was loaded while they were installed.
Found by gtritchie while reviewing #19807.
- I have read the guide for submitting good bug reports.
- I have installed the latest version of RStudio, and confirmed that the issue still persists.
- If I am reporting an RStudio crash, I have included a diagnostics report.
- I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
Activity