Skip to content

Fix Posit Assistant failing to start in a second RStudio instance on Windows - #18790

Merged
gtritchie merged 4 commits into
rel-autumn-hawkbitfrom
bugfix/18787-pai-lock-owner-id-windows-hawkbit
Sep 12, 2026
Merged

gtritchie merged 4 commits into
rel-autumn-hawkbitfrom
bugfix/18787-pai-lock-owner-id-windows-hawkbit

Conversation

@gtritchie

@gtritchie gtritchie commented Sep 11, 2026 •

Copy link
Copy Markdown
Member

Intent

Fixes #18787. Replaces #18788, which targeted main; this is the same change based on rel-autumn-hawkbit for the 2026.09.1 patch.

On Windows, every RStudio session named its Posit Assistant "in use" lock file pai/locks/sessions/.lock, so a second instance collided with the first and Posit Assistant refused to start with "A Posit Assistant update is in progress".

The owner id that names the file is a function-local static const std::string initialized by a conditional expression. MSVC 19.51 in C++20 mode (which the Windows build uses) initializes that static to an empty string; the same code is correct in C++17 mode, as a non-static local, or when the initializer is wrapped in a lambda. The static was introduced by #18573, which is why 2026.08 is unaffected.

Upstream: this is a regression in MSVC 19.51 / Build Tools v14.51 (VS 2026 18.6+), which the Windows CI image uses via its VS 2026 18.7.3 pin; MSVC 19.29 through 19.50 compile the same code correctly. Microsoft tracks it as Developer Community ticket 11093947, fixed in the v14.52 preview (July 2026 preview notes). No GA toolset carries the fix as of 2026-09-11, so the source-level workaround is required. Details in the issue.

Approach

  • Compute the owner id inside an immediately-invoked lambda with plain locals.
  • InstallLock::acquireInUse refuses an empty owner id with a real error, so a regression surfaces as "Unable to verify the Posit Assistant installation state" instead of silently sharing one file and reporting an update in progress.
  • Expose InstallLock::ownerId() as a test seam.

Automated Tests

The lock tests were entirely #ifndef _WIN32, so nothing exercised owner-path naming on Windows. This PR moves the tests' common includes out of the POSIX-only block and adds three tests that compile everywhere:

  • the session lock file is named <owner>.lock
  • an empty owner id is refused without creating .lock
  • the production accessor's owner id is non-empty (fails on the previous initializer under MSVC, passes with the fix)

QA Notes

Verified on Windows 11 with the local dev build; QA notes added to the issue.

Documentation

None; no user-facing behavior beyond the bug fix. NEWS entry added to version/news/os/NEWS-2026.09.1-autumn-hawkbit.md.

Checklist

  • If this PR adds a new feature, or fixes a bug in a previously released version, it includes an entry in NEWS.md
  • If this PR adds or changes UI, the updated UI meets accessibility standards
  • A reviewer is assigned to this PR (if unsure who to assign, check Area Owners list)
  • This PR passes all local unit tests

MSVC in C++20 mode initializes a function-local static std::string whose
initializer is a conditional expression to an empty string, so every
Windows session named its in-use lock file `sessions/.lock` and a second
RStudio instance refused to start Posit Assistant with "A Posit Assistant
update is in progress". Compute the id in a lambda instead, expose it for
tests, and move the lock tests' common includes out of the POSIX-only
block so owner-path tests compile on Windows.

Addresses #18787
An empty owner id names the session lock file `.lock`, which every
session with the same defect shares, and the resulting contention reads
as an update in progress. Fail the acquisition with a real error instead
so a regression surfaces instead of silently sharing one file.

Addresses #18787
@gtritchie gtritchie added this to the Patch 2026.09.1 milestone Sep 11, 2026
@github-actions

github-actions Bot commented Sep 11, 2026 •

Copy link
Copy Markdown

RStudio E2E - all platforms

1 test(s) failed

###################- 99% pass rate

Passed Failed Skipped Flaky
2585 1 184 9
Platform ✅ Passed ❌ Failed ⚠️ Skipped 🔁 Flaky
✅ auth-teardown 2 0 10 0
✅ desktop-linux 649 0 38 3
✅ desktop-macos 656 0 33 2
✅ desktop-windows 655 0 39 2
❌ server-linux 595 1 44 2
✅ setup 28 0 20 0
View / download the full report

View report online -- opens in the browser, no download needed. Available for 14 days.

Download playwright-report.zip -- extract and open index.html

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


All platforms - commit 31936b42f6ac2bf8e1b89cc86740986cfac8fa65 - Run #972

@kevinushey kevinushey left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix looks good to me, and the MSVC write-up in the issue is great. A few suggestions, none blocking; the inline ones are small and I'd be happy with them in this PR or a follow-up.

One thing outside the diff: the new ChatInstallLockProduction.OwnerIdIsNotEmpty test compiles into rsession.exe, but nothing runs it on Windows. Jenkinsfile.windows only runs rstudio-tests.bat --scope core, and the PR workflows run the C++ tests on Linux only. Since this is a Windows-only miscompile, a regression would still ship green. rstudio-tests.bat already accepts --scope core,rsession, so a follow-up PR that switches the Windows Tests stage over (and watches a few runs for timing/flakes) would make the guard real.

Comment thread src/cpp/session/modules/SessionChat.cpp Outdated
// the static's initializer: MSVC in C++20 mode initializes
// `static const std::string x = cond ? f() : g() + f();` to an empty
// string, which named every session's lock file ".lock" (#18787).
static const std::string ownerId = []() {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional: since ownerId feeds exactly one consumer (the static InstallLock instance right below, whose own one-time init already gives single evaluation), you could drop the second static entirely and pass a helper call straight to the constructor:

static install_lock::InstallLock instance(
   xdg::userDataDir().completePath(chat_constants::kPositAiLocksDirName),
   makeInstallLockOwnerId());

That removes the static const std::string MSVC hazard structurally rather than documenting around it, so the comment can shrink to a line.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 31936b4: the owner id now comes from a makeInstallLockOwnerId() helper in the anonymous namespace and is passed straight to the constructor; the second static is gone and the comment is down to the one-line MSVC note.

// every other session with the same defect shares, and the resulting
// contention would read as an update in progress (#18787). Refuse
// instead so the defect surfaces as a real error.
if (ownerId_.empty())

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This guard only covers acquireInUse, but tryBeginMutation also derives its own-file skip from ownerId_ (via ownSessionLockPath(), line ~317). With an empty id, a mutator would treat a foreign sessions/.lock as its own, skip probing it, and update/uninstall under a live backend. Neither performInstall nor uninstall passes through acquireInUse. Validating once in the constructor (or a shared check called from both entry points) closes both paths.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed: with an empty id ownSessionLockPath() resolves to sessions/.lock, so the own-file skip would match a foreign .lock and the mutator would proceed. Fixed in 31936b4 with a private checkOwnerId() called from both acquireInUse and tryBeginMutation (the latter surfaces it as "Unable to verify the Posit Assistant installation state"). The constructor cannot return an Error, so a shared check was the closer fit. Added ChatInstallLockOwner.EmptyOwnerIdRefusesMutation, which also asserts that install.lock is never created.

// per-process uuid. MSVC in C++20 mode initialized the previous form of
// that static (a conditional expression) to an empty string, so every
// Windows session locked "sessions/.lock" and the second instance refused
// to start (#18787). Constructing the singleton touches no files.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pins the #18787 symptom (non-empty) but not the #18571 contract the lambda implements (uuid suffix always present, session-id prefix kept). Cheap to strengthen with the accessor this PR adds:

const std::string& id = installLock().ownerId();
EXPECT_NE(id, module_context::activeSession().id());
EXPECT_TRUE(boost::algorithm::ends_with(id, ...)); // 32 hex chars, generateUuid(false) has no dashes

Otherwise a later simplification to sessionId.empty() ? uuid : sessionId would pass this test and quietly reintroduce #18571.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strengthened in 31936b4: the test is now OwnerIdIsSessionIdPlusPerProcessUuid. It asserts the id differs from the bare session id, ends in 32 hex characters (generateUuid(false)), and that the prefix is exactly <sessionId>- (or empty when the session id is empty). A simplification to sessionId.empty() ? uuid : sessionId fails the first and third checks.

@gtritchie

Copy link
Copy Markdown
Member Author

One thing outside the diff: the new ChatInstallLockProduction.OwnerIdIsNotEmpty test compiles into rsession.exe, but nothing runs it on Windows. Jenkinsfile.windows only runs rstudio-tests.bat --scope core, and the PR workflows run the C++ tests on Linux only. Since this is a Windows-only miscompile, a regression would still ship green. rstudio-tests.bat already accepts --scope core,rsession, so a follow-up PR that switches the Windows Tests stage over (and watches a few runs for timing/flakes) would make the guard real.

#17825 tracks this long-standing issue (not all unit tests run on Windows builds).

Review follow-ups for #18790:

- InstallLock::tryBeginMutation now refuses an empty owner id via the same
  checkOwnerId() used by acquireInUse. With an empty id the own-file
  exclusion matched a foreign "sessions/.lock", so a mutator would skip
  probing it and update or uninstall under a live backend.
- Pass the owner id straight to the InstallLock constructor from a named
  helper instead of holding it in a second static, removing the MSVC
  static-initializer hazard structurally.
- Strengthen the production owner-id test to check the "<sessionId>-<uuid>"
  contract from #18571, not just non-emptiness.
- Add a test that an empty owner id refuses tryBeginMutation without
  creating install.lock.

Addresses #18787
@gtritchie
gtritchie merged commit 75bc526 into rel-autumn-hawkbit Sep 12, 2026
33 of 34 checks passed
@gtritchie
gtritchie deleted the bugfix/18787-pai-lock-owner-id-windows-hawkbit branch September 12, 2026 19:42

This branch was previously deployed

1 inactive deployment
e2e-playwright — 31936b42 Deployed Sep 12, 2026 by gtritchie via windows / e2e-desktop-windows (6) #972
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