You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Posit Assistant's R code checks stay off for the session after a hooked function fails to restore #19806
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, with fs installed in a user library rather than in .Library:
loadNamespace("fs")
libs<- .libPaths()
outside<- tempfile(tmpdir= dirname(tempdir()))
dir.create(outside)
# 1. code run by Posit Assistant unloads fs, and fs can't be loaded again
.rs.chat.safeEval(quote({ unloadNamespace("fs"); .libPaths(.Library) }))
.libPaths(libs)
# 2. later code run by Posit Assistant writes outside the allowed locations
.rs.chat.safeEval(quote(writeLines("x", file.path(outside, "file.txt"))))
file.exists(file.path(outside, "file.txt"))
Describe the problem in detail
Step 1 warns failed to restore binding 'file_create' in 'fs': Failed to load namespace for package 'fs' once for each hooked fs function. Step 2 then writes the file, and file.exists() returns TRUE. Before step 1, the same write is refused.
chat.restoreBindings() leaves chat.bindingsInjected set to TRUE when any binding fails to restore. chat.injectBindings() returns early whenever that flag is TRUE, which is meant as a guard against reentrant calls. The base and utils functions were restored, so every later evaluation runs with none of the checks for the rest of the session.
A restore fails when .rs.replaceBinding() errors. Here, its requireNamespace() can't load a package that was unloaded during the evaluation.
Describe the behavior you expected
A failed restore doesn't turn off the checks for later evaluations: the next evaluation hooks whatever isn't hooked. Functions in a namespace that was unloaded during the evaluation don't need restoring.
Activity
keep the chat guardrails on after a binding fails to restore (#19807)