Repository navigation
feat(browser): add isolated Chrome lifecycle - #28
Conversation
Wire isolated Chrome sessions through the built CLI and MCP surfaces while preserving retryable process cleanup on partial startup failures.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: fe5a9c649f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| await fs.promises.mkdir(layout.profileDir, { recursive: true }); | ||
| await fs.promises.mkdir(layout.xdgConfigHome, { recursive: true }); | ||
| await fs.promises.mkdir(layout.xdgCacheHome, { recursive: true }); | ||
| await fs.promises.mkdir(layout.xdgDataHome, { recursive: true }); | ||
| await fs.promises.mkdir(layout.xdgStateHome, { recursive: true }); | ||
| await fs.promises.mkdir(layout.tmpDir, { recursive: true }); |
There was a problem hiding this comment.
Make browser runtime directories private
On shared Linux hosts with the usual 022 umask, these mkdir calls create the Chrome profile, HOME/XDG parents, and tmp dir as traversable/readable by other local users until destroy. Since the new browser session can contain history, cache, cookies, downloads, and other page data during a run, the isolation guarantee should not depend on the caller's umask; create/chmod the session/profile/home/tmp tree to 0700 similarly to XDG_RUNTIME_DIR.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 368607e. Browser session, profile, HOME, XDG, and tmp directories are explicitly chmod 0700; a zero-umask regression asserts every mode.
| if (port !== undefined) { | ||
| return { ok: true, port }; |
There was a problem hiding this comment.
Re-check Chrome is alive before accepting the port
If Chrome writes DevToolsActivePort and then immediately crashes, this returns success as soon as the stale file is visible, without verifying that the browser process or CDP endpoint is still alive. In that startup-crash window the supervisor can still be alive briefly, so createBrowserSession may record a running session with a dead/unusable CDP port instead of failing and cleaning it up.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 368607e. Startup now requires the recorded identity to remain live and a direct loopback 200 from /json/version, with abort and crash-after-port regressions.
| const base = path.resolve(sessionDir); | ||
| const resolved = path.resolve(profileDir); | ||
| return ( | ||
| resolved === path.join(base, "profile") || | ||
| resolved.startsWith(base + path.sep) |
There was a problem hiding this comment.
Resolve symlinks before trusting profile confinement
Because this guard is purely lexical, a recorded profileDir such as <session>/link/cache passes even when <session>/link is a symlink to a directory outside the session tree. destroyBrowserSession then passes that path to fs.rm, which follows the intermediate symlink and can delete data outside PickLab's session directory; since this is the tamper guard, it needs realpath/lstat protection or should only accept the exact real profile directory.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 368607e. Cleanup now uses async lstat/realpath confinement, rejects symlinked ancestry, and leaves the external target untouched in regression coverage.
| await fs.promises.rm(sessionDir, { recursive: true, force: true }).catch( | ||
| () => {}, | ||
| ); |
There was a problem hiding this comment.
Preserve records when profile removal fails
When reaping a dead browser session, any failure to remove the session/profile directory is swallowed and the function still returns success, so reapDeadRunningSessions deletes the session record. On EPERM/EBUSY/NFS or other partial filesystem failures, profile data can be left behind with no errored record for retry or inspection, unlike destroyBrowserSession which aggregates cleanup failures.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 368607e. Reaper cleanup failures persist an errored retryable record; a transient failure regression proves the next reap completes removal.
Protect private runtime data, validate CDP readiness, and preserve retryable records when teardown cannot finish.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 368607e03a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const probeSignal = | ||
| signal === undefined | ||
| ? timeoutSignal | ||
| : AbortSignal.any([signal, timeoutSignal]); |
There was a problem hiding this comment.
Avoid AbortSignal.any for advertised Node 20.0
AbortSignal.any was only added in Node 20.3, while these packages still advertise node >=20. When a signal is provided (for example MCP passes extra.signal into browser creation), Node 20.0–20.2 throws here; the surrounding catch then hides the TypeError and the DevTools probe returns false until startup times out even though Chrome is ready. Either raise the engine floor or compose the timeout/client signals without AbortSignal.any.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 25c5a74. Probe cancellation now composes caller abort and timeout with a local AbortController plus explicit listener/timer cleanup, compatible with the advertised Node 20 floor.
Compose probe cancellation without APIs introduced after the advertised runtime floor.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 25c5a74495
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const daemon = await startDaemon(supervised.command, supervised.args, { | ||
| logDir, | ||
| name: "chrome", | ||
| env: childEnv, | ||
| cleanEnv: true, |
There was a problem hiding this comment.
Avoid persisting DevTools websocket URLs in chrome.log
When real Chrome starts with --remote-debugging-port, it writes the full ws://127.0.0.1:.../devtools/browser/<GUID> endpoint to stderr; this launch sends Chrome/supervisor stderr to the persistent chrome.log via startDaemon with name: "chrome". That means every live browser session records the capability URL the rest of this change carefully avoids storing in the session record, and callers with access to diagnostics/logDir can recover it. Suppress or scrub this line before persisting the Chrome log.
Useful? React with 👍 / 👎.
| : { | ||
| status: "error", | ||
| ...(desktop === undefined ? {} : { desktop }), | ||
| ...(browser === undefined ? {} : { browser }), | ||
| }, |
There was a problem hiding this comment.
Mark incomplete startup cleanup for retry
When startup fails after spawning Chrome/Xvfb and this cleanup is incomplete (for example the group is still unverified or profile removal failed), this branch preserves the pids/profile in an error record but does not set the reaperCleanupPending marker that reapDeadRunningSessions requires before retrying error-state cleanup. A later session create therefore skips the orphaned browser/Xvfb/profile even if it has become cleanable, leaving users to discover and destroy a failed id that create never returned; set the cleanup-pending metadata when cleanupComplete is false.
Useful? React with 👍 / 👎.
| xvfbAlive, | ||
| displayAlive, | ||
| browserAlive, | ||
| alive: xvfbAlive && browserAlive, |
There was a problem hiding this comment.
Treat a missing browser display as dead
If the Xvfb socket disappears while the recorded Xvfb pid is still alive (for example after /tmp/.X11-unix/X* is removed), displayAlive is false but alive stays true here, so CLI/MCP status keeps reporting the browser session as running even though screenshot/input tools cannot connect to its display. Include displayAlive in this liveness result so unusable browser displays are surfaced as dead.
Useful? React with 👍 / 👎.
Redact CDP capabilities and make partial browser, display, and runtime cleanup identity-safe and retryable.
Retry failed teardown, verify display identities, escalate surviving groups, and honor cancellation through session commit.
Keep no-identity desktop records live without signaling bare PIDs and make malformed display records non-throwing.
Propagate cancellation into Xvfb launch and verify teardown before returning an abort.
Persist incomplete Xvfb ownership for retry and make browser readiness polling cancellation-aware.
Durably record browser and display identities before polling, and retain retryable teardown state on partial failures.
Co-Authored-By: Claude <[email protected]>
Co-Authored-By: Claude <[email protected]>
Co-Authored-By: Claude <[email protected]>
|
Current-head CI follow-up pushed in Run 29233501902 exposed two test races, not product failures:
Validation after the fix:
Waiting for required CI on the new HEAD. |
Changed
0andDevToolsActivePortwithout persisting capability URLs.This completes PR 5 of #17. Defensive pre-identity cleanup hardening is tracked in #29.
Validated
bun run typecheckbun run buildchrome.logcontained nows://or/devtools/browser/capability URLNot tested
Risk
Chrome runs under the invoking UID. Loopback CDP is not isolation from other same-UID local processes; use a VM or throwaway account for hostile pages.
Closes #18
Refs #17
Refs #29