Skip to content

fix(runtime): isolate Electron Node mode from user commands - #4835

Draft
sunheyi6 wants to merge 1 commit into
apache:mainfrom
sunheyi6:codex/fix-user-command-electron-env
Draft

fix(runtime): isolate Electron Node mode from user commands#4835
sunheyi6 wants to merge 1 commit into
apache:mainfrom
sunheyi6:codex/fix-user-command-electron-env

Conversation

@sunheyi6

@sunheyi6 sunheyi6 commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Summary

Prevent Maka's internal Electron Node-mode environment from leaking into user commands. This is a general runtime correctness fix, not a Computer Use test workaround.

When the Runtime Host has ELECTRON_RUN_AS_NODE=1, its user-command children can inherit it. An Electron project that launches normally with bun run dev from a regular terminal can then run in Node mode when launched through Maka, losing Electron APIs such as BrowserWindow.

Build a fresh child environment at the foreground shell, direct-argv, background pipe, and PTY boundaries, removing this one variable while preserving other entries and leaving the parent environment untouched. Fixing the shared boundary avoids requiring every Electron project or generated command to know about Maka's internal launch mode.

Refs #2142. Discovered while validating #4668, but deliberately independent of that Computer Use integration and its foreground/background interaction policy.

Compatibility and scope

  • Applies to commands launched through the modified runtime helpers, not every subprocess in the application. Internal Runtime Host/Worker launch code is unchanged.
  • Removes the key case-insensitively on Windows and only the exact uppercase key on POSIX.
  • Also removes this variable from an explicitly supplied env object. Callers intentionally relying on passing Node mode through that object will observe a behavior change. A command may still explicitly set the variable inside its shell/script before launching its own child; this is environment hygiene, not a sandbox or a prohibition on Electron Node mode.
  • Does not rewrite commands or working directories, install dependencies, or repair PATH, ports, project configuration, application code, or unrelated Electron startup errors. Existing shell-planning behavior remains in place.
  • Does not relax permissions, sandbox admission, Computer Use focus/input restrictions, or verification semantics. No local executables, artifact pins, test profiles, or logs are included.
  • This does not establish full Windows support or packaged/clean-machine release readiness.

Verification

Prior local validation of this patch on Windows (before cherry-picking it onto the separate current-main branch):

  • Incremental compilation passed.
  • Four new focused test cases reported passing, covering environment copying/case handling, foreground shell and direct argv, and background pipes/argv/PTY. Probes observed the variable absent in children, unrelated values retained, and the parent's value unchanged; the foreground probe also checked explicit reassignment inside the command.
  • The focused test process did not exit cleanly. Passing assertions are not an overall successful test-run exit.
  • The full shell suite reported 53 pass / 17 fail / 10 skip, including Windows shell/PTY and cleanup failures. These failures are not resolved here; this is not an all-green or baseline-equivalence claim.
  • A real SunCode Electron development project launched successfully through Maka's shell-run manager after the fix. The previously reported manual-terminal versus Maka launch discrepancy was resolved in that local scenario; this is not a cross-platform or packaged-app certification.
  • At PR preparation, the separate branch was clean, its remote head matched 05895cd7a1e446b9906bc77e972300498f15fc57, and git diff --check passed. Compilation and runtime tests were not rerun on this cherry-picked branch. macOS/Linux, clean-machine, and packaged release validation remain unverified.

Before marking ready

  • Obtain exact-head CI/build and affected-suite results; investigate test-runner non-exit and failing shell tests rather than treating passing assertions as a green suite.
  • Confirm cross-platform behavior and the intentional explicit-env compatibility boundary during review.
  • Add/retain the repository-required Generated-by attribution in the affected commit history/final squash commit before merge (the currently published commit lacks that trailer).

AI use

  • No generative tool made a substantive contribution
  • Generative tooling made a substantive contribution

Tool(s) and scope: OpenAI Codex, including Luna (gpt-5.6-luna, high reasoning), assisted with implementation and tests; Codex assisted with review, local validation, commit preparation, and this PR description.

Checklist

  • Tests cover the change and fail without it (regression tests added; a fresh exact-head before/after run is still outstanding)
  • Lint, format, typecheck and the affected suites pass locally

Does this PR entail a change in behavior?

  • Yes — described under Summary and Compatibility and scope
  • No
中文翻译

概要

防止 Maka 内部用于 Electron Node 模式的环境变量泄漏到用户命令。这是通用运行时正确性修复,不是 Computer Use 测试专用绕过。

Runtime Host 带有 ELECTRON_RUN_AS_NODE=1 时,用户命令的子进程可能继承该值。因此,在普通终端执行 bun run dev 正常的 Electron 项目,通过 Maka 启动时可能变成 Node 模式,失去 BrowserWindow 等 Electron API。

在前台 shell、直接 argv、后台管道及 PTY 边界创建新的子进程环境,仅移除这个变量,保留其他条目,不修改父进程环境。在共享边界修复,可避免要求每个 Electron 项目或生成的命令了解 Maka 内部的启动模式。

关联 #2142,但不关闭该 Windows 支持总议题。问题在验证 #4668 时发现,本 PR 刻意独立于 Computer Use 集成及其前后台交互策略。

兼容性与范围

  • 只覆盖经过本次修改的运行时辅助函数启动的命令,不覆盖应用中的所有子进程;内部 Runtime Host/Worker 启动代码不变。
  • Windows 按不区分大小写移除该键;POSIX 仅移除完全匹配的大写键。
  • 显式传入的 env 对象中的同名变量也会被移除。依赖这种传参方式主动启用 Node 模式的调用方会受到行为变化影响。命令仍可在自己的 shell/脚本内部主动设置该变量,再启动自己的子进程;这是环境隔离,不是沙箱,也不是禁止使用 Electron Node 模式。
  • 不改写命令或工作目录,不安装依赖,不修复 PATH、端口、项目配置、应用代码或其他 Electron 启动错误;既有 shell 启动规划行为保持不变。
  • 不放宽权限、沙箱准入、Computer Use 焦点/输入限制或验证语义。不包含本地可执行文件、制品绑定、测试配置或日志。
  • 不代表 Windows 已全面受支持,也不代表打包发行版或干净机器验证完成。

验证

以下为该补丁在 Windows 本地的先前验证,发生在将其摘取到独立的当前 main 分支之前:

  • 增量编译通过。
  • 四个新增专项测试用例报告通过,覆盖环境复制/大小写、前台 shell 和直接 argv,以及后台管道/argv/PTY。探针确认子进程缺少该变量、其他值保留、父进程值不变;前台探针还检查了命令内部显式重新赋值。
  • 专项测试进程没有正常退出。断言通过不等于整个测试运行成功退出。
  • 完整 shell 测试报告 53 通过 / 17 失败 / 10 跳过,包含 Windows shell/PTY 及清理失败。本 PR 未解决这些失败,不宣称全部通过,也未证明与基线等价。
  • 修复后,真实 SunCode Electron 开发项目通过 Maka 的 shell-run manager 成功启动。此前“手动终端正常、Maka 启动失败”的差异在该本地场景中得到解决;这不是跨平台或打包应用认证。
  • 准备 PR 时,独立分支工作区干净,远端提交与 05895cd7a1e446b9906bc77e972300498f15fc57 一致,git diff --check 通过。没有在摘取后的独立分支重新运行编译和运行时测试。macOS/Linux、干净机器及打包发行验证仍未完成。

转为待合并状态前

  • 获取精确提交的 CI/构建及受影响测试结果;调查测试进程不退出及 shell 测试失败,不能将断言通过当作测试全绿。
  • 审查跨平台行为和显式 env 的预期兼容性边界。
  • 合并前在受影响提交历史及最终 squash 提交中补充/保留仓库要求的 Generated-by 署名(当前已发布提交缺少该 trailer)。

AI 使用

  • 生成式工具未作出实质贡献
  • 生成式工具作出了实质贡献

工具及范围:OpenAI Codex,包括 Luna(gpt-5.6-luna,high 思考强度),协助实现及测试;Codex 协助审查、本地验证、提交准备和本 PR 说明。

检查清单

  • 测试覆盖改动,并在没有修复时失败(已新增回归测试,仍需重新执行精确提交的修复前后对照)
  • 本地 lint、格式、类型检查及受影响测试全部通过

本 PR 是否改变行为?

  • 是,已在概要和兼容性与范围中说明

Remove inherited ELECTRON_RUN_AS_NODE at foreground, background, PTY and direct-argv user-command boundaries, preserving the Runtime Host environment and unrelated variables.

Validation: incremental compilation and real SunCode startup passed. Four focused assertions passed, but the Windows runner did not exit cleanly; the full shell suite also has Windows shell/PTY failures. This is not an all-green claim.

Isolate this general runtime fix for a separate PR. No local executables, profiles or artifact pins are included.

<details>
<summary>中文翻译</summary>

在前台、后台、PTY 和直接 argv 用户命令边界移除继承的 ELECTRON_RUN_AS_NODE,保留 Runtime Host 自身环境和其他变量,避免 Maka 启动的 Electron 项目丢失 Electron API。

验证:增量编译和真实 SunCode 启动通过。四项专项断言通过,但 Windows 测试进程未正常退出,完整 shell 测试也有 Windows shell/PTY 失败,不宣称测试全绿。

此通用修复独立提交,便于另开 PR。不包含本地执行器、测试配置或制品绑定。

</details>
@github-actions github-actions Bot added the effort/M Under 500 readable lines label Sep 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

effort/M Under 500 readable lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant