fix(local-cloak): match profile processes on an exact --user-data-dir boundary - #243
Open
Kaushik2003 wants to merge 1 commit into
Open
Conversation
… boundary Background-profile teardown found the Chromium to kill with a bare substring test on the process command line. Because profile ids may share a prefix (`work` / `work-2`, `default` / `default-2`), `--user-data-dir=<dir>` matched sibling profiles too, so closing one background context sent SIGTERM to a healthy concurrent profile's browser. The victim surfaced only the opaque "Target page, context or browser has been closed". The same match had no Cloak-binary check, so a user's own Chrome on a matching profile dir was killed as well. Launch recovery in session-manager.ts already did this correctly. Its process matching moves to profile-processes.ts and is reused by terminateProfile, so both paths agree on which processes belong to a profile. The helpers cannot live in either existing module without an import cycle, since session-manager already imports darwin-background-launch. Teardown on the success path is now best-effort as well, so a ps or kill failure no longer replaces the outcome of browser.close(). The launch-failure path was already guarded this way.
Contributor
🟢 No documentation gap found — medium confidenceThe automated review found no documentation gap in the supplied changes. This review is advisory and does not block merging. |
Author
|
@ngaurav - Tagging you for visibility. Happy to adjust this fix if it doesn't align with the vision for the project. |
adikulkarni006
approved these changes
Aug 9, 2026
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.
Description
On macOS,
terminateProfilepicked the Chromium processes toSIGTERMwith a baresubstring test on the
pscommand line(
darwin-background-launch.ts:42-50). Profiles are siblings under~/.webcmd/cloak/profiles/<id>and ids may contain-and., so--user-data-dir=…/profiles/workmatched…/profiles/work-2as well: tearing downone background profile killed a healthy concurrent one. With no CloakBrowser binary
check, a user's own Chrome on a matching
--user-data-dirwas killed too. Thevictim only ever surfaced
Target page, context or browser has been closed.Lock recovery in
session-manager.tsalready matched profile processes correctly —requiring the flag value to end at an argument boundary, resolving realpath aliases,
and restricting matches to CloakBrowser binaries. This moves that matching into a
new
profile-processes.tsand routes both call sites through it, so there is oneimplementation instead of two that disagree.
The helpers cannot live in either existing module:
session-manager.tsalreadyimports
darwin-background-launch.ts, so either direction would create a cycle.The new module is a straight move — no behavior change on the recovery path.
Teardown on the context-close path is now best-effort like the launch-failure path
beside it, so a
psorkillfailure no longer replaces the outcome ofbrowser.close().Files in the commit:
src/browser/runtime/local-cloak/profile-processes.ts— new; profile processdiscovery and signalling, moved from
session-manager.ts.src/browser/runtime/local-cloak/session-manager.ts— imports the moved helpers.src/browser/runtime/local-cloak/darwin-background-launch.ts—terminateProfileuses the shared matching; teardown made best-effort.
src/browser/runtime/local-cloak/profile-processes.test.ts— new; regressioncoverage.
Related issue: #242
Type of Change
Checklist
npm run typecheck, plus the affectedsrc/browser/runtime/local-cloaksuites (see below)profile-processes.test.ts; nouser-facing surface changed, so no docs or skills update
Adapter Notes
Not an adapter change — this touches the local CloakBrowser runtime only.
CliErrorsubclasses instead of rawErrorScreenshots / Output
The two boundary tests fail against the previous matching and pass with this
change, so they are genuine regression coverage.
Reverting
commandUsesProfileDirto the old substring test reproduces the bug inthose tests:
The neighbouring suites still pass, confirming the move did not change recovery
behaviour:
Note on CI: these tests live under
src/browser/**, which the vitestunitproject excludes — see #231 and PR #238. Until that lands they need a local vitest
config to run; CI will not report them.
Note on #225: distinct root cause (that one is in the CloakBrowser launch
layer), but it produces the same opaque
Target page, context or browser has been closedin concurrent-profile workflows,so it may be a second contributing cause of what #225 describes.