Skip to content

fix grey-screen dead-end when set_user_state fails during bootstrap - #18031

Merged
kevinushey merged 3 commits into
mainfrom
bugfix/18019-bootstrap-grey-screen
Jun 22, 2026
Merged

kevinushey merged 3 commits into
mainfrom
bugfix/18019-bootstrap-grey-screen

Conversation

@kevinushey

Copy link
Copy Markdown
Collaborator

Summary

On RStudio Desktop, a transient set_user_state RPC failure during workbench bootstrap could leave the user with an unrecoverable grey screen (title/menu bars present, empty grey content), with no retry or error UI. See #18019 for the full analysis.

The bootstrap in Application.java chains initializeWorkbench() behind UserState.writeState() and then UserPrefs.writeUserPrefs(). UserState.writeState's onError only logged the error and never invoked the completion continuation, unlike the analogous UserPrefs.writeUserPrefs. So when set_user_state failed at the TCP level (ERR_CONNECTION_FAILED):

  • the continuation never ran, so initializeWorkbench() never built or painted the IDE (permanent grey screen); and
  • writeUserPrefs() never ran, so its leading updatePrefs(getPrefs()) never refreshed the pref layers, leaving them in the incomplete "loaded without sessionInfo" state. That in turn caused a secondary Cannot read properties of undefined (reading 'values') TypeError on quit, when index-based pref accessors dereferenced a not-yet-populated layer.

Changes

  • UserState.writeState: invoke onCompleted.execute(false) in onError, mirroring UserPrefs.writeUserPrefs, so bootstrap continues (and the pref layers get refreshed) even when the RPC fails.
  • Prefs.java (defense-in-depth): route the index-based accessors (getGlobalValue, getProjectValue, setGlobalValue, removeGlobalValue, hasProjectValue, setProjectValue, removeProjectValue) through a new layerValues() helper that returns null for an absent layer, so reading a pref before the layers are fully populated falls back to the default instead of throwing.
  • Tests: added PrefsTests covering the incomplete-layers accessor behavior.

Testing

  • ant javac and ant unittest pass (507 tests).
  • The primary grey-screen scenario is timing-dependent (a transient connection blip during startup) and requires manual verification; the added unit tests cover the defense-in-depth accessor path.

Addresses #18019

The workbench bootstrap in Application.java chains initializeWorkbench()
behind UserState.writeState() and UserPrefs.writeUserPrefs(). UserState's
onError only logged the error and never invoked the completion continuation,
so a transient set_user_state RPC failure (e.g. ERR_CONNECTION_FAILED during
startup) silently dead-ended bootstrap: initializeWorkbench() never ran and
the user was left with an unrecoverable grey screen, and the prefs layers
stayed in the incomplete "loaded without sessionInfo" state.

Make UserState.writeState's onError invoke onCompleted.execute(false),
matching UserPrefs.writeUserPrefs, so the chain continues and the workbench
is built (and the prefs layers refreshed) even when the RPC fails.

As defense-in-depth, also guard the index-based pref accessors in Prefs.java
(getGlobalValue, getProjectValue, setGlobalValue, etc.) against not-yet-
populated layers via a layerValues() helper, so reading a pref before the
layers are fully populated falls back to the default instead of throwing a
TypeError on an undefined layer.

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

github-actions Bot commented Jun 20, 2026 •

Copy link
Copy Markdown

🍎 macOS Desktop E2E · ARM64

❌ 1 test(s) failed

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

✅ Passed ❌ Failed ⚠️ Skipped 🔁 Flaky
398 1 19 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 d31075bbd14ad752adc3c710742075df7b7efdf9 · Run #131

@github-actions

github-actions Bot commented Jun 20, 2026 •

Copy link
Copy Markdown

🪟 Windows Desktop E2E · Server 2025 x64

✅ All tests passed!

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

✅ Passed ❌ Failed ⚠️ Skipped 🔁 Flaky
403 0 16 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 · Windows Server 2025 x64 · commit d31075bbd14ad752adc3c710742075df7b7efdf9 · Run #131

@gtritchie

Copy link
Copy Markdown
Member

Code review findings

Actionable items from an automated multi-agent review. Strengths, dismissed findings, and ratings are omitted.

Important

  1. src/gwt/src/org/rstudio/studio/client/workbench/prefs/model/Prefs.java:434 — getUserLayer()
    still does layers_.get(userLayer()).getValues() with no guard, contradicting the new comment's
    claim that "callers that index directly into layers_ must tolerate a missing layer." It's the
    one positional deref left unhardened. Sole caller is PreferencesDialog.java:135 (off the
    bootstrap/quit path), so not a live crash. Fix: route through layerValues(), or narrow the
    comment (finding 3).

  2. src/gwt/src/org/rstudio/studio/client/workbench/prefs/model/Prefs.java:182 and :227 —
    setGlobalValue/setProjectValue early-return and silently discard the write when the target
    layer is absent. A dropped write is data loss with no log; in a non-bootstrap path this loses a
    user's setting invisibly. Fix: Debug.logWarning naming name_ and the missing layer index in
    the values == null branch before returning.

  3. src/gwt/src/org/rstudio/studio/client/workbench/prefs/model/Prefs.java:447-451 — the
    layerValues comment ("callers that index directly into layers_") overclaims: getValue(),
    hasValue(), and setValue(String,...) iterate via JsUtil.asReverseIterable and are safe by
    construction. Fix: scope the comment to fixed-index positional access
    (layers_.get(userLayer()/projectLayer())).

Suggestions

  1. src/gwt/src/org/rstudio/studio/client/application/Application.java:276-287 — the bootstrap
    continuation never inspects boolArg/boolArg1, so a failed set_user_state/set_user_prefs
    proceeds identically to success with no user-facing signal (only a console Debug.logError).
    Proceeding-on-failure is the right availability call. Fix: branch on the boolean and queue a
    deferred non-blocking notification once the workbench is up, or add a comment documenting the
    deliberate silent-proceed choice.

  2. src/gwt/test/org/rstudio/studio/client/workbench/prefs/model/PrefsTests.java — coverage gaps:
    the empty-array fixture only exercises the index >= layers_.length() branch of layerValues();
    the layer == null branch (Prefs.java:458) is never hit — a partially-populated fixture would
    cover it and better model the real bug. The primary fix (UserState.writeState.onError) and the
    removeGlobalValue/removeProjectValue guards are also untested.

  3. src/gwt/test/org/rstudio/studio/client/workbench/prefs/model/PrefsTests.java:46-58 — reference
    UserPrefsAccessor.LAYER_USER/LAYER_PROJECT instead of hardcoded 3/4 so the fixture is
    self-documenting and refactor-proof.

  4. src/gwt/src/org/rstudio/studio/client/workbench/model/SessionInfo.java:144 (pre-existing, out
    of this PR's scope) — getUserStateLayer() clamps with getPrefs().length() but indexes into
    getUserState(); cloned from getUserPrefLayer() (line 133) and should be
    getUserState().length(). Normally masked, but in the incomplete-layers scenario this PR targets
    it could index out of bounds and throw on .getValues(). Worth a separate follow-up.

@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.

See feedback

- Prefs.java: log a warning instead of silently dropping setGlobalValue/
  setProjectValue writes when the target layer is absent; narrow the
  layerValues() comment to the fixed-index positional accessors it covers
- Application.java: document the deliberate proceed-on-RPC-failure during
  workbench bootstrap
- SessionInfo.java: getUserStateLayer() now measures and indexes the same
  array (user_state, not user_prefs); clamp all three layer accessors to
  the last valid index so an incomplete layer array falls back to the last
  layer instead of indexing past the end and throwing
- PrefsTests.java: cover the missing-layer (null slot) branch and the
  remove* accessors; reference UserPrefsAccessor.LAYER_* instead of 3/4
@kevinushey

Copy link
Copy Markdown
Collaborator Author

Thanks for the thorough review. Addressed in d31075b (also merged latest main):

1 / 3 (layerValues comment + getUserLayer) -- narrowed the comment to the fixed-index positional accessors that actually route through layerValues(), and noted that the name-iterating accessors (getValue/hasValue/setValue) are safe by construction. Left getUserLayer() unguarded on purpose and documented why: its only caller is the preferences-dialog save path (PreferencesDialog.doSaveChanges -> setUserPrefs), which runs after the layers are fully populated and needs a real layer.

2 (silent dropped writes) -- setGlobalValue/setProjectValue now Debug.logWarning (naming the pref and the missing layer index) before returning.

4 (bootstrap ignores the completion boolean) -- added a comment documenting the deliberate proceed-on-failure: a transient persistence failure must not dead-end startup, and the RPC error is already logged. Kept it silent rather than adding a user-facing notification (separate UX call).

5 / 6 (test coverage + magic numbers) -- added a partially-populated fixture (null user/project slots) that exercises the layer == null branch, plus removeGlobalValue/removeProjectValue tests, and switched the fixture to UserPrefsAccessor.LAYER_USER/LAYER_PROJECT. The UserState.writeState.onError path needs a server mock to unit-test, so it remains covered by the manual-verification note.

7 (getUserStateLayer) -- fixed here rather than as a follow-up. It had two defects: it measured getPrefs().length() while indexing getUserState() (the cross-array bug), and the Math.min(length, LAYER_USER) clamp still indexes one past the end when length <= LAYER_USER -- the very incomplete-layers case -- so the array-only fix alone wouldn't have stopped the throw. Changed all three sibling accessors (getUserPrefs, getUserPrefLayer, getUserStateLayer) to Math.min(length - 1, LAYER_USER). That's identical to indexing LAYER_USER for any fully-populated array (length >= LAYER_USER + 1), so normal behavior is unchanged; it only affects the degenerate case, turning an out-of-bounds throw into a fallback to the last available layer. Two of the three are on the bootstrap path, so leaving the others would have kept a parallel crash route open.

ant javac clean; ant unittest -> OK (513 tests).

@kevinushey
kevinushey merged commit 72ea5bb into main Jun 22, 2026
14 of 15 checks passed
@kevinushey
kevinushey deleted the bugfix/18019-bootstrap-grey-screen branch June 22, 2026 03:55
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