Skip to content

fix: keep the Gateway responsive while starting a managed browser - #200503

Merged
steipete merged 1 commit into
mainfrom
codex/browser-launch-offmain-fs
Nov 17, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/browser-launch-offmain-fs

Conversation

@steipete

@steipete steipete commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

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 in openat2(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) enters withChromeProfileLifecycleLock (chrome.profile-lifecycle-lock.ts:17,22), targeting a lifecycle sidecar directly under the browser profiles root. SDK withFileLock (src/plugin-sdk/file-lock.ts:284) calls acquireFileLock (:166). In installed fs-safe 0.27.1, dist/sidecar-lock-acquire.js:297 calls createNativeExclusiveFile; dist/native-operations.js:40-49 opens the parent synchronously and directly calls binding.openBeneath(parentFd, basename, O_WRONLY | O_CREAT | O_EXCL | O_NOFOLLOW). Its binding signature in dist/native-binding.d.ts:296 returns synchronously. That is a calling-thread create with exactly the observed parent directory. It is followed by synchronous fchmodSync and writeSync, 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 → SDK json-store.ts:15 → infra/json-files.ts → fs-safe dist/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 call openBeneath to create its JSON temp. It still contains synchronous metadata work, so the complete decoration operation moves off-thread too.

Reuse the existing WorkerTaskPool / serveWorkerTasks owner 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 with pnpm 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):

Gateway request path File and line
Config set/apply/patch → config mutation/source locks src/config/write-lock.ts:197,301,341 (via src/config/mutate.ts:207)
OAuth credential removal and refresh src/agents/auth-profiles/oauth-profile-lock.ts:16, called from profiles.ts:457 (Gateway auth removal) and oauth-manager.ts:125,513,695 (refresh when hosted in this process)
Agent sandbox preparation / provider operations src/agents/sandbox/registry.ts:201, called from backend.ts:262
Session-memory capture on command lifecycle src/hooks/bundled/session-memory/handler.ts:338
Memory wiki tool mutations extensions/memory-wiki/src/mutation-coordinator.ts:75 (extensions/memory-wiki/index.ts:187,191)
Provider auth persistence during setup/sign-in src/plugins/provider-auth-persistence.ts:255 (also reached from src/system-agent/setup-inference-credentials.ts:165)

Direct Root mutations also retain synchronous native root/parent opens, including dist/native-parent-admission.js:134 and the Root mkdir admission in dist/root-mkdir-native.js:163,179; their staged content create may itself be asynchronous (dist/native-staged-file.js:291). Identified request callers:

Gateway request path File and line
Workspace text/binary saves src/gateway/server-methods/workspace-fs.ts:287,349
Agent bootstrap/document saves and conditional creates src/gateway/server-methods/agents-files.ts:123,449,464
Personal USER.md editing src/gateway/server-methods/users-personal-file.ts:258
Session HTML export command src/auto-reply/reply/commands-export-session.ts:46,234
Session-memory artifact creation src/hooks/bundled/session-memory/handler.ts:352
Browser output admission outside managed launch extensions/browser/src/browser/output-directories.ts:40, reached by output-files.ts:19, routes/agent.act.download.ts:61, routes/output-paths.ts:16
Incoming/downloaded media publication src/media/store.ts:275,549

Read-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, and mcp-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 native openBeneath creates.

Evidence

  • Owning-boundary regression through launchOpenClawChrome, real lifecycle locking, real preparation workers and real JSON files; only child/CDP I/O is synthetic. On original base 96763b979, 1 failed / 6 passed, with main-thread fchmodSync, 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.
  • Regression command: 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.
  • Core/extension production typechecks, focused browser test typecheck, targeted oxlint, format checks and git diff --check passed. Full pnpm build passed, 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.
  • One new main-thread regression plus one error-contract case; net test growth 46 lines. New production machinery is the plugin worker transport needed to retain cross-process locking while moving filesystem preparation, with no parallel lock implementation or weakened atomic writer.
  • Codex autoreview of the complete local snapshot against 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 for a52990f4521631e9ccdbf2c5f6f5f4634d66ab9d; node scripts/watch-pr-ci.mjs finished GREEN (12 superseded check results, no pending active checks). Native auto-merge landed the reviewed head as 51452add9d790cd8ec1f1796ed07af4024fd955c. No CI reruns or inherited-failure exception were needed.

Standalone atomic writers such as src/gateway/github-publication-base-refresh.ts:450 and src/config/sessions/skill-prompt-blobs.ts:124 follow 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.

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.
@clawsweeper

clawsweeper Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review in progress

ClawSweeper is reviewing this revision. This supersedes any previous blocked status.

View the workflow run.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-17T08:33:33.888737Z a52990f PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation extensions: browser size: L labels Nov 17, 2026
@steipete
steipete enabled auto-merge (squash) November 17, 2026 08:40
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 17, 2026
@steipete
steipete merged commit 51452ad into main Nov 17, 2026
137 of 139 checks passed
@steipete
steipete deleted the codex/browser-launch-offmain-fs branch November 17, 2026 08:42
@steipete

Copy link
Copy Markdown
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. docs Improvements or additions to documentation extensions: browser size: L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant