Repository navigation
Conversation
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
RStudio E2E - all platforms1 test(s) failed
View / download the full reportView report online -- opens in the browser, no download needed. Available for 14 days. Download playwright-report.zip -- extract and open
All platforms - commit |
kevinushey
left a comment
There was a problem hiding this comment.
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.
| // 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 = []() { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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()) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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 dashesOtherwise a later simplification to sessionId.empty() ? uuid : sessionId would pass this test and quietly reintroduce #18571.
There was a problem hiding this comment.
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.
…18787-pai-lock-owner-id-windows-hawkbit
#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
Intent
Fixes #18787. Replaces #18788, which targeted
main; this is the same change based onrel-autumn-hawkbitfor 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::stringinitialized 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
InstallLock::acquireInUserefuses 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.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:<owner>.lock.lockQA 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
NEWS.md