fix(ai): replace raw require(node:fs) with loadNodeBuiltinModule in getProcEnv#102947
Conversation
aae01c1 to
310867d
Compare
|
Codex review: needs real behavior proof before merge. Reviewed July 9, 2026, 11:37 AM ET / 15:37 UTC. Summary PR surface: Source +3. Total +3 across 1 file. Reproducibility: yes. source-reproducible: current main still contains the exact Review metrics: none identified. Root-cause cluster Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Proof guidance:
Risk before merge
Maintainer options:
Next step before merge
Security Review detailsBest possible solution: Land one narrow, proof-backed PR that removes the remaining static Do we have a high-confidence way to reproduce the issue? Yes, source-reproducible: current main still contains the exact Is this the best way to solve the issue? Yes for the code shape: reusing AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 3c048ef05297. Label changesLabel changes:
Label justifications:
Evidence reviewedPR surface: Source +3. Total +3 across 1 file. View PR surface stats
What I checked:
Likely related people:
What the crustacean ranks mean
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics. How this review workflow works
|
310867d to
62485c2
Compare
|
Maintainer fixup and land-ready proof for exact head
Known proof gap: the Testbox image has no Bun executable, so a direct Bun Best-fix verdict: best. A top-level import breaks the package's browser contract, another helper duplicates policy, and deleting or async-converting the fallback would regress the tracked Bun sandbox workaround. |
|
Merged via squash.
|
…etProcEnv (openclaw#102947) * fix(ai): replace raw require(node:fs) with loadNodeBuiltinModule in getProcEnv * test(ai): cover browser-safe env key bundle --------- Co-authored-by: Peter Steinberger <[email protected]>
What Problem This Solves
Fixes #102934 —
getProcEnvused a rawrequire("node:fs")string literal on line 92, which static bundlers such as Vite scan and attempt to resolve even when guarded bytry/catch. The same file already has a safeloadNodeBuiltinModulewrapper (line 17) used byloadNodeHelpersSync(line 32) for the same purpose —getProcEnvwas the only remaining raw require.Why This Change Was Made
The file header explicitly states:
// NEVER convert to top-level imports - breaks browser/Vite builds. UsingloadNodeBuiltinModuleandNODE_FS_SPECIFIER(both already defined in the file) eliminates the staticrequire("node:fs")literal without changing runtime behavior.User Impact
No user-visible impact. Fixes a static analysis / bundler compatibility gap for packages consuming
@openclaw/aiin browser contexts.Evidence
Before —
packages/ai/src/env-api-keys.ts:92(raw staticrequireliteral):After — same behavior via
loadNodeBuiltinModule:loadNodeBuiltinModuleis runtime-equivalent —packages/ai/src/env-api-keys.ts:17-28:The wrapper first tries
process.getBuiltinModule(Node 22+), then falls back torequire(specifier). The key difference for bundlers:requireis called with a variable (specifier) rather than a string literal ("node:fs"), so static analyzers cannot trace the dependency. The addednullguard is also stricter —getProcEnvnow returnsundefinedwhenfsis unavailable, where previously it would have thrown.