Repository navigation
fix(desktop-gpui): Cap opens on clean Windows installs and never exits silently - #4256
Open
richiemcilroy wants to merge 18 commits into
Open
richiemcilroy wants to merge 18 commits into
richiemcilroy wants to merge 18 commits into
Conversation
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
richiemcilroy
marked this pull request as ready for review
November 14, 2026 14:37
|
Sandchest reviewed Sandchest reviews every change for vulnerabilities an attacker could use · 14 credits · Review details |
Member
Author
|
hey @greptileai, please re-review the PR |
Member
Author
|
hey @greptileai, please re-review the PR |
Member
Author
|
hey @greptileai, please re-review the PR |
…rs after the prompt
Member
Author
|
hey @greptileai, please re-review the PR |
Two launches recovering the same frozen copy could both stop with "could not be reached": each opened the instance mutex to check on the copy, so whichever launch ended it found the mutex kept alive by the other launch with no process behind it. Launches of a profile now take turns through an owned Local\CapGpuiLaunch mutex, held until the pidfile and endpoint are published, so only the holder ever opens the instance mutex and the next launch hands off to the copy it started. A holder that dies leaves the lock abandoned, which counts as free. Also expect the Linux launch lock file in the first-launch profile test.
Member
Author
|
hey @greptileai, please re-review the PR |
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Cap on Windows could fail to open at all, most often after the move to the GPUI app, and reinstalling never helped. Four separate causes, each reproduced on a clean Windows 11 24H2 VM with no GPU (WARP only) and fixed here. A user reported Cap "isn't opening" even after deleting everything and reinstalling; others hit "file in use" errors from background
cap-cliprocesses during updates, or got stuck at onboarding.flowchart TD A[Cap.exe launched] --> B{VC++ runtime present?} B -- "no (clean Win11)" --> X1["MSVCP140.dll was not found<br/>(reinstall cannot fix)"] B -- yes --> C{Instance mutex held?} C -- "yes, owner hung" --> X2[exit 0, nothing on screen] C -- no --> D{Early init error?} D -- yes --> X3[exit 1, nothing on screen] D -- no --> E{store parses?} E -- "no (NUL-filled)" --> X4["onboarding: Could not save<br/>onboarding progress, forever"]Root causes
Cap.exeimportsMSVCP140.dll,VCRUNTIME140.dllandVCRUNTIME140_1.dll.cap-cli.exe,cap-muxer.exe,onnxruntime.dll,dxcompiler.dllanddxil.dllimport them too (read from the PE import tables of the shipped 0.6.3). A clean Windows 11 24H2 has none of them in System32, and the installer doesn't ship them. 0.5.x was built bytauri build, which links the runtime statically (STATIC_VCRUNTIME). The GPUI app is built with plaincargo buildand links it dynamically, so this started with the GPUI release.ERROR_ALREADY_EXISTSon theLocal\CapGpui-*mutex and sends a reopen request that times out (os error 10060in the log). It then callsSetForegroundWindowon a frozen window andexit(0). Linux has the same pattern (forward_linux_reopenerror, thenexit(0)). Stalecap-gpui.pid/cap-gpui.ipcfiles alone are harmless on Windows: the mutex decides, and a launch with a pidfile pointing at a reused pid (explorer.exe) starts normally.exit(1)/cx.quit()with only a log line. That line was often lost too, becauseprocess::exitskips the non-blocking log writer's guard. A panic while gpui starts (for examplefailed to initialize Windows platform) only reached the crash file.store(what NTFS can leave after a power loss) fails to parse. fix(desktop-gpui): recover onboarding from an empty settings store #3778 only covers empty and whitespace files. Every write then refuses, so Get Started shows "Could not save onboarding progress" on every press.Cap.exeand then stopped on DLLs held bycap-cli. Any runningcap-cli.exe(for examplecap record start --detach) statically loads the FFmpeg DLLs. NSIS writesCap.exefirst, then hitsError opening file for writing: avcodec-61.dllwith Abort/Retry/Ignore. Abort leavesCap.exefrom the new version,cap-cli.exefrom the old one, and the registry still on the old version. A silent install (cap update) skips the locked files without telling anyone.The #3594 reporter's missing
logsfolder is a location mix-up, not an early crash: Windows logs go to%LOCALAPPDATA%\so.cap.desktop\logs, not Roaming.What changed
scripts/setup.js: copiesmsvcp140.dll,msvcp140_1.dll,vcruntime140.dllandvcruntime140_1.dllfrom the Visual Studio that links the build (VC/Redist/MSVC/<Microsoft.VCRedistVersion.default.txt>/<arch>/Microsoft.VC14*.CRT) intotarget/native-deps/vcruntime.scripts/bundle-gpui.mjsinstalls them next toCap.exe(app-local deployment, so they are never older than the toolset that linked the binaries).desktop-release.ymlnow requires them in the installer.packaging/windows/installer-hooks.nsh: newWaitForCapCommandLineToolsin the pre-install and pre-uninstall hooks, after the MCP servers are ended. A fastFindProcessCurrentUserprobe means PowerShell only starts when acap-cli.exe/cap-muxer.exeexists. The check waits up to 10 s for any running from$INSTDIR, then asks Retry/Cancel. Cancel, or a silent install, aborts before any file is written.src/startup.rs(new):startup::beginlogsCap starting version= pid= executable=as the first line and owns the log guard.startup::exitflushes the log beforeprocess::exit.startup::faillogs, writes the crash file synchronously, shows a native error ("Cap couldn't start", the reason, and the logs folder), then exits. A main-thread panic before the main window opens shows the same dialog from the panic hook.src/single_instance.rs:WM_NULLwithin 5 s (the threshold Windows uses for "Not Responding"; the listener acknowledges from its own thread, so a frozen UI thread would otherwise still swallow the launch). The launch then asks "Cap is already running but isn't responding. Quit that copy and open Cap again?". After OK it re-takes the mutex and repeats the hand-off, and only ends the same pid the user confirmed if that copy is still stuck, so a copy that recovered or exited during the prompt is never touched. The pid comes only from this profile'scap-gpui.pid, or the pid in itscap-gpui.ipcwhen the pidfile is missing, never from other processes in the session. If neither identifies the owner, the launch shows an error instead of exiting silently. A Cap whose window still answers is activated as before. Launches take turns through an ownedLocal\CapGpuiLaunch-<profile>mutex, held until the pidfile and endpoint are published, and only the holder opens the instance mutex. Otherwise a launch still checking on the frozen copy kept that mutex alive after another launch ended the copy, and both stopped with "could not be reached". A launch that dies holding the lock leaves it abandoned, which counts as free.flockoncap-gpui.lock, held until the pidfile and activation socket are published, so two launches can never both end the same hung copy and both carry on: the second waits, then hands off to the copy the first one started. After OK the launch repeats the hand-off and only ends the confirmed copy if it still doesn't answer, the sametakeover_steprule as Windows. A pidfd is opened before the prompt and SIGTERM, then SIGKILL after 3 s, go through it, so a pid reused while the prompt is open can never be signalled.exit(1)now goes throughstartup::fail.src/store.rs: only the two onboarding flags (set_has_completed_startup/set_has_completed_onboarding) set an unparseable store aside asstore.unreadable-<ms>(bytes kept) and save to a fresh store. Every other writer still refuses an unparseable store, as before. While the store doesn't parse, its auth and presets are already invisible, so onboarding loses nothing more.src/main.rs: a main window that fails to open shows the error instead of quitting silently.dialog.startup.*strings in all seven locales.Callers checked
single_instance::acquire: onlymain. The macOS acquire path is unchanged apart from its error exits. A failed forward there still activates the app, which macOS shows (beachball, Force Quit), andlive_legacy_instance_survives_failed_forwarding_without_metadata_changeskeeps pinning that.set_has_completed_*: onlyonboarding_window.rs:489and:512.platform::confirm_dialogis unchanged. On Windows it renders OK/Cancel, the same as every other Cap confirmation there.crash_capture's panic hook still records first. The dialog is shown only on the main thread and only beforestartup::finished().What could regress, and why it doesn't
WM_NULLis activated. Proven on the VM: a normal second launch hands off with no prompt, and with the pidfile deleted the healthy copy is brought forward, not quit.Tests
single_instance::windows_takeover_tests(Windows CI): a pidfile naming a non-Cap, dead or garbage pid identifies no instance; the endpoint file identifies an instance whose pidfile is missing; a held lock with no identifiable instance is reported within 5 s; an instance that never acks reopen is reported, not activated; an instance with no endpoint or window is reported; an acking instance is handed off; ending aCap.exewaits for its exit; a process not named Cap is never ended; a second launch waits for the launch lock until the first releases it; a launch that died holding it does not block the next; another profile never waits.single_instance::linux_takeover_tests: SIGTERM ends a hung instance; one ignoring SIGTERM is killed after 3 s; a process that exits during the prompt is never signalled again (ESRCH through its pidfd); an already-exited instance starts a new one without asking; a responsive one is handed off without asking; Cancel leaves the hung copy running; OK ends it and this launch starts; a copy that answers again by the time OK is pressed is kept and handed off; a second launch waits on the lock, then hands off to the copy the first one started instead of starting another. Run 3 times in a row on Linux, 28/28 each.single_instance::takeover_step_tests: only the confirmed pid is ended, and only once.store::tests::onboarding_progress_sets_aside_an_unparseable_store(NUL-filled, truncated,null,[]; other writers still refuse; bytes kept) andonboarding_progress_leaves_an_unreadable_store_alone.scripts/bundle-gpui.test.mjs: VC runtime resources, and the hook order, path match, silent default and stack balance.i18n::dialogs_surface_testscovers the new strings.Proof (Windows 11 24H2, Azure D4s_v4, no GPU, no VC++ runtime installed)
Fixed build: release installer built from this branch's head. Before: the shipped 0.6.3 (and 0.6.2 for the update).
store, Get Started/P /R /UPDATE) withcap record --detachrunningcap record stopand Retry, every binary is the new build, Cap relaunches, and the recording is intact/S, thecap updatepath) with a recording running: exit code 2 in 15 s, every file unchanged, recording still running.cap-cli versionruns on the clean VM from the new install.Cap starting ... pid=6052andCap GPUI is already running; bringing it forward pid=5012. Before this change, neither line reached disk.macOS and Linux: CI builds and runs the full GPUI test suite on both. Neither shares the VC runtime or installer causes. Linux shared the hung-instance silent exit (fixed). macOS already activates the running app visibly.


Confidence Score: 5/5
The PR appears safe to merge; no new actionable issue was established.Summary
This PR improves desktop startup and Windows updates.
The supplied previous threads have no comment numbers, so
previousFindingsis empty. Their original causes were checked against the current code: regular Windows reopen now checks the window, profile-wide process searches are gone, Linux holds a process reference and retries handoff after confirmation, and both platforms serialize recovery launches.Reviews (14) · Last reviewed commit: "Merge remote-tracking branch 'origin/mai..." · Reviewed by Greptile