Repository navigation
fix: keep the Gateway responsive while starting a managed browser - #200503
Merged
Merged
Conversation
Move lifecycle sidecar locking, guarded profile decoration and output-directory admission to browser filesystem workers. Use asynchronous Node filesystem operations for profile mkdir, singleton cleanup and bootstrap checks while preserving Preferences-before-Local-State ordering and filesystem error codes. Release-note context: managed browser launch no longer creates profile preparation files synchronously on the Gateway thread under filesystem pressure.
Contributor
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review in progressClawSweeper is reviewing this revision. This supersedes any previous blocked status. |
Contributor
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
steipete
enabled auto-merge (squash)
November 17, 2026 08:40
Contributor
Author
|
Merged via squash auto-merge.
|
github-actions Bot
pushed a commit
to Desicool/openclaw
that referenced
this pull request
Nov 18, 2026
…aw#200503) Move lifecycle sidecar locking, guarded profile decoration and output-directory admission to browser filesystem workers. Use asynchronous Node filesystem operations for profile mkdir, singleton cleanup and bootstrap checks while preserving Preferences-before-Local-State ordering and filesystem error codes. Release-note context: managed browser launch no longer creates profile preparation files synchronously on the Gateway thread under filesystem pressure.
maplel
pushed a commit
to maplel/openclaw
that referenced
this pull request
Nov 24, 2026
…8901) (cherry picked from commit 1f088d2) Release adaptation: carry only 4 MiB ps cap and focused native capture regression. Unknown process ownership remains a refusal. Companions: later profile threading openclaw#200503, Linux temp path openclaw#196778, jemalloc openclaw#195331, and retired allocation cleanup openclaw#197656 are not prerequisites of this macOS capture bound; no PR-number follow-ups. Validation: diff check passed; focused test setup lacks @solidjs/vite-plugin in provided shared dependencies (lock differs), not a product verdict. Co-authored-by: RomneyDa <[email protected]> (cherry picked from commit f8f4d9f4c90a68c0e805b916918c4c1d35d23b0d) (cherry picked from commit d77e84457d8a53075e55507c7053344a22fe08ff)
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.
Related: #200370
What Problem This Solves
Starting a managed browser can freeze every Gateway WebSocket client and RPC while the filesystem is busy. In the November 17 production incident on Linux/btrfs at
a117ca50, the Gateway main thread spent 6.3 seconds in D-state inopenat2(O_CREAT), relative to the browser profiles root, behind an unrelated 8.1-second btrfs commit. The event-loop stall was 6,323 ms during an agent turn; the managed browser reported starting afterward. No JavaScript CPU profile was captured because the thread was inside the syscall.User Impact
Managed browser startup prepares its profile without filesystem creates, renames or fsyncs on the Gateway calling thread. Profile contents, lock retry/stale-owner policy, bootstrap, and launch ordering stay the same. There are no dependency or configuration changes.
Why This Change Was Made
The matching create is the lifecycle sidecar, rather than a decoration JSON temp file. The incident release contains the same lifecycle-lock path as this branch. On the original base,
launchOpenClawChrome(extensions/browser/src/browser/chrome.ts:617) enterswithChromeProfileLifecycleLock(chrome.profile-lifecycle-lock.ts:17,22), targeting a lifecycle sidecar directly under the browser profiles root. SDKwithFileLock(src/plugin-sdk/file-lock.ts:284) callsacquireFileLock(:166). In installed fs-safe 0.27.1,dist/sidecar-lock-acquire.js:297callscreateNativeExclusiveFile;dist/native-operations.js:40-49opens the parent synchronously and directly callsbinding.openBeneath(parentFd, basename, O_WRONLY | O_CREAT | O_EXCL | O_NOFOLLOW). Its binding signature indist/native-binding.d.ts:296returns synchronously. That is a calling-thread create with exactly the observed parent directory. It is followed by synchronousfchmodSyncandwriteSync, both observed by the regression. Source inspection establishes the matching call; the incident capture did not record the leaf filename.The initial decoration hypothesis is disproven for this package version:
chrome.profile-decoration.ts:83,105→ SDKjson-store.ts:15→infra/json-files.ts→ fs-safedist/json.js:299→dist/text-atomic.js:7→dist/replace-file.js→dist/replace-file-descriptor.js:135→AtomicIo.open(dist/atomic-io.js:85-88) uses Node's asynchronous open. It does not callopenBeneathto create its JSON temp. It still contains synchronous metadata work, so the complete decoration operation moves off-thread too.Reuse the existing
WorkerTaskPool/serveWorkerTasksowner and its host-conversation protocol in the browser plugin. A worker holds the existing SDK filesystem lock while the host performs the browser lifecycle operation; a separate preparation pool avoids borrowing all lock slots and then waiting on those same slots for decoration. Nested lifecycle awaits borrow the already-held profile lock. Worker replies retain filesystem error codes and lock paths, and join lock release before returning the host's original result/error. Profile directories, singleton readlink/removal, and bootstrap existence checks use Node's async filesystem APIs. Download-directory admission, mock-keychain JSON inspection, and decoration retain their existing implementations inside the worker. The worker entry is registered in the existing runtime manifest and package inventory; generated runtime assets were regenerated withpnpm runtime:scripts:gen.Safety stays with the existing filesystem owners: native beneath/no-follow sidecar acquisition and its definite-stale recovery are unchanged, as are guarded atomic JSON replacement, modes, file/directory durability and output-directory symlink checks. Plain Node async operations replace only existing Node sync operations on the managed profile. Preferences, including the network-prediction guard, still finish before cosmetic Local State; headed bootstrap and the final spawn retain their existing order. No fs-safe patch, override, vendoring, cache or time-based skip is needed.
Audit only: other request-path callers
These are identified source paths, not a runtime census. They remain unchanged. The first group reaches the same synchronous native exclusive sidecar create (
native-operations.js:49):src/config/write-lock.ts:197,301,341(viasrc/config/mutate.ts:207)src/agents/auth-profiles/oauth-profile-lock.ts:16, called fromprofiles.ts:457(Gateway auth removal) andoauth-manager.ts:125,513,695(refresh when hosted in this process)src/agents/sandbox/registry.ts:201, called frombackend.ts:262src/hooks/bundled/session-memory/handler.ts:338extensions/memory-wiki/src/mutation-coordinator.ts:75(extensions/memory-wiki/index.ts:187,191)src/plugins/provider-auth-persistence.ts:255(also reached fromsrc/system-agent/setup-inference-credentials.ts:165)Direct Root mutations also retain synchronous native root/parent opens, including
dist/native-parent-admission.js:134and the Root mkdir admission indist/root-mkdir-native.js:163,179; their staged content create may itself be asynchronous (dist/native-staged-file.js:291). Identified request callers:src/gateway/server-methods/workspace-fs.ts:287,349src/gateway/server-methods/agents-files.ts:123,449,464src/gateway/server-methods/users-personal-file.ts:258src/auto-reply/reply/commands-export-session.ts:46,234src/hooks/bundled/session-memory/handler.ts:352extensions/browser/src/browser/output-directories.ts:40, reached byoutput-files.ts:19,routes/agent.act.download.ts:61,routes/output-paths.ts:16src/media/store.ts:275,549Read-only RPC siblings also use synchronous guarded Node opens, rather than this addon's native O_CREAT:
agents-files.ts:157,192,334,users-personal-file.ts:205,skills-files.ts:61, andmcp-app-onboarding.ts:46. The installed contract explicitly documents that Root reads use guarded Node opens (dist/root-file.js:80→dist/pinned-open.js:51); these should not be mislabeled as nativeopenBeneathcreates.Evidence
launchOpenClawChrome, real lifecycle locking, real preparation workers and real JSON files; only child/CDP I/O is synthetic. On original base96763b979, 1 failed / 6 passed, with main-threadfchmodSync,writeSync,mkdirSync. With the fix: 8 passed, zero observed calling-thread mutations, one final spawn, expected Preferences/Local State contents, and original filesystem error codes when the browser root cannot be used. This proves routing, not the Linux btrfs stall duration.OPENCLAW_VITEST_RUNTIME=node node scripts/run-vitest.mjs extensions/browser/src/browser/chrome.headless-launch.test.ts --maxWorkers=1. The final five-file run passed 135 tests / 1 platform skip; the launch file passed 8 tests. Existing cleanup tests prove real worker-held exclusion and nested reset/stop ownership without a cross-process retry-policy mock. Fake-clock process tests now mock the preparation transport instead of the moved private implementation.git diff --checkpassed. Fullpnpm buildpassed, including declarations, worker/package outputs, runtime/lazy-import checks and Control UI. Initial build found stale generated runtime assets; regeneration fixes it. Production and full-tree unused-file scans both passed with 0 entries. Build output retains advisory existing Control UI size/dependency bundler warnings.96763b979, through P2: scoped-clean with no accepted findings. A second complete review after the singleton-helper/test-fixture extraction also finished scoped-clean through P2. The extraction satisfies the existing line-cap ratchet. Exact-head CI run 44047276410 completed successfully fora52990f4521631e9ccdbf2c5f6f5f4634d66ab9d;node scripts/watch-pr-ci.mjsfinished GREEN (12 superseded check results, no pending active checks). Native auto-merge landed the reviewed head as51452add9d790cd8ec1f1796ed07af4024fd955c. No CI reruns or inherited-failure exception were needed.Standalone atomic writers such as
src/gateway/github-publication-base-refresh.ts:450andsrc/config/sessions/skill-prompt-blobs.ts:124follow the same asynchronous create path as decoration, with synchronous metadata checks; they are not the matching native O_CREAT. The scoped audit also excluded skill-resource locks used by the execution worker and tool-install locks only reached by the TUI.No STOP decision: the fix fits existing OpenClaw worker contracts without changing fs-safe.