Skip to content

Automation bridge: prefSet/prefGet/prefClear silently fail for prefs not yet registered #17724

Closed

Description

@kevinushey

Summary

The window.rstudioCallbacks automation bridge exposes prefGet(name), prefSet(name, value), and prefClear(name) for the --automation-agent test harness (see ApplicationAutomation.java). For most preferences these callbacks return without doing anything -- no JS-side exception, no log line, no effect on the preference value.

Reproduction

Launch RStudio with --automation-agent and from JS:

const cb = window.rstudioCallbacks;
cb.prefSet('default_project_location', '/tmp/foo');
console.log(cb.prefGet('default_project_location'));  // null

Expected: returns '/tmp/foo'. Actual: null (or whatever the underlying default is once the pref is eventually registered).

The Playwright suite hits this in tests/projects/ignorefiles.test.ts -- the test sets default_project_location via the bridge so the New Project wizard creates a project under the sandbox, but the wizard reads the unchanged value, falls back to ~, and the project is created in the wrong directory.

Root cause

All three callbacks dispatch through setPref(name, value) / userPrefs_.getPrefValue(name):

Prefs.PrefValue<?> pref = userPrefs_.getPrefValue(name);
if (pref == null)
   throw new RuntimeException(\"Unknown user preference: \" + name);

Prefs.getPrefValue(name) reads from Prefs.values_, which is populated lazily -- only when the corresponding factory method (e.g. UserPrefsAccessor.defaultProjectLocation()) has been invoked at least once. Most preferences are never accessed at startup, so they're not in values_ when the bridge call lands. pref == null, the RuntimeException fires.

The exception doesn't propagate to JS because GWT's \$entry wrapper installs the uncaught-exception handler and swallows it (logged to GWT console, but the JSNI callback returns normally). From the JS side it looks like the call succeeded -- silent failure.

Suggested fix

Call userPrefs_.allPrefs() once during ApplicationAutomation.initializeAgent(). allPrefs() runs every factory method (defaultProjectLocation(), saveWorkspace(), ...), and each factory registers its PrefValue in values_ as a side effect. After that, all preferences are addressable by name.

A similar warm-up call may be appropriate for UserState callbacks if any are added later.

Why this matters

  • Playwright tests that drive prefs via the bridge can't be trusted: a passing test may have run with the wrong pref value entirely (no error to alert on).
  • Any downstream consumer of --automation-agent (extensions, scripts) hits the same trap.

Activity

  1. added
    new
    on May 21, 2026
  2. added this to the Blue Plumbago milestone on May 21, 2026
  3. added theissue type on May 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugdevelopernew

    Type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions