Skip to content

fix(ui): avoid tmp dir fs.constants access at import time#48202

Closed
7inspire wants to merge 1 commit intoopenclaw:mainfrom
7inspire:codex/fix-48062-ui-fs-constants-import-clean
Closed

fix(ui): avoid tmp dir fs.constants access at import time#48202
7inspire wants to merge 1 commit intoopenclaw:mainfrom
7inspire:codex/fix-48062-ui-fs-constants-import-clean

Conversation

@7inspire
Copy link
Copy Markdown

Summary

  • make temp-dir access mode resolution lazy in tmp-openclaw-dir
  • avoid reading fs.constants at module scope

Why

Issue #48062 reports that the Control UI can render a blank screen because:

  • src/infra/tmp-openclaw-dir.ts reads fs.constants.W_OK / X_OK at module scope
  • that module is pulled into the browser bundle through a transitive import chain
  • in the browser build, node:fs is externalized, so evaluating fs.constants at import time crashes before the UI mounts

Changes

  • src/infra/tmp-openclaw-dir.ts
    • replace the top-level TMP_DIR_ACCESS_MODE constant with a lazy getTmpDirAccessMode() helper
    • use the helper at the two accessSync(...) call sites

This keeps Node runtime behavior the same while preventing browser-side import-time evaluation from crashing the bundle.

Validation

  • pnpm exec vitest run src/infra/tmp-openclaw-dir.test.ts
  • pnpm exec oxfmt --check src/infra/tmp-openclaw-dir.ts

Closes #48062

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Mar 16, 2026

Greptile Summary

This PR fixes a browser-side blank-screen crash (issue #48062) caused by src/infra/tmp-openclaw-dir.ts reading fs.constants.W_OK | fs.constants.X_OK at module scope, which would fail when node:fs is externalized in the browser bundle. The fix wraps that evaluation in a lazy getTmpDirAccessMode() helper that is only invoked inside resolvePreferredOpenClawTmpDir() — a function that runs exclusively in Node.js — so the browser bundle can import the module without crashing.

  • Change is minimal and targeted: only the evaluation timing of two fs.constants accesses changes; all runtime behavior in Node.js remains identical.
  • No logic regressions: both accessSync(...) call sites receive the same bitmask (W_OK | X_OK) as before.
  • No issues found: the helper is unexported, called only within the function, and fs.constants values are stable integer literals so repeated calls are inconsequential.

Confidence Score: 5/5

  • This PR is safe to merge — it is a one-file, surgical fix with no logic changes and a clear, well-described root cause.
  • The diff is small (4 lines added, 1 removed) and changes only evaluation timing, not runtime behavior. The fix correctly defers fs.constants access to call time, which is the minimal correct solution for the reported import-time crash in the browser bundle. No new control flow, no new exports, and no impact on the Node.js code path.
  • No files require special attention.

Last reviewed commit: 3a54b1a

@altaywtf
Copy link
Copy Markdown
Member

merged in 412811e, author credited in changelog.

@altaywtf altaywtf closed this Mar 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Control UI blank screen — fs.constants.W_OK accessed at module scope breaks browser bundle

2 participants