Skip to content

feat: 拆分环境后端,新增环境内退出通道与流式增量渲染(审查第三批,v0.26.2) - #25

Merged
WhiteNightShadow merged 11 commits into
mainfrom
feat/batch3-round1
Oct 25, 2026
Merged

WhiteNightShadow merged 11 commits into
mainfrom
feat/batch3-round1

Conversation

@WhiteNightShadow

@WhiteNightShadow WhiteNightShadow commented Oct 24, 2026 •

Copy link
Copy Markdown
Owner

背景

架构审查第三批。范围按10月23日定的:只改本项目,不动pabox;内容沙箱保持关闭(这是浏览器的核心能力);继续留在nightly锁定基线,不迁esr。

改动(按提交)

  • refactor(agent) 工具特性写进声明:每个T(...)声明都写明特性(READ_ONLY,或confirm / repeatExempt / progress的组合)。需确认名单、免重复检查集合和“算作进展”的判断都由声明派生,不再单独维护;失效的net_intercept去掉。js_trace(run模式)和wasm_probe会在宿主node进程里执行页面代码,改为和run_node一样需要确认。删掉还在打包的旧副本EnvironmentBackendCurrent.sys.mjs,EnvironmentPane不再回退到它。新增dev/selftest-tool-metadata.mjs,保证readme工具表、系统提示词、skill文档、工具描述和声明一致。
  • build(windows) windows默认关闭内容沙箱,和macos、linux一致:windows会把security.sandbox.content.level抬到至少6,pref里的0不起作用,引擎层的jsvmp / webapi trace写不出ndjson。apply-phase-b.py现在总是在windows的main()开头注入MOZ_DISABLE_CONTENT_SANDBOX=1;以前只在FRX_ALLOW_UNSANDBOXED_TRACE=1时注入,否则还会删掉已有的注入。注入的代码没变,已经打过的树会跳过。
  • refactor(environment) 按职责拆分环境后端:EnvironmentBackend.sys.mjs(3638行)只保留公开接口和编排(锁、生命周期、运行状态),实现拆到EnvironmentStore(目录、manifest/env.json、按键加锁)、EnvironmentProcess(启动、marionette、pid身份、信号)、EnvironmentFingerprint(生成、校验、采集、导入)、EnvironmentPrefs(指纹/代理写user.js、主profile托管块)、EnvironmentCurrentProcess(主浏览器自己的配置)和EnvironmentCommon(共享常量和工具)。代码按行原样搬移;固定随机数和时间做新旧对照,346项结果和文件全部一致。自测和scripts/verify-native-fingerprint.mjs用到的下划线入口保留为转发。
  • feat(environment) 环境内退出通道:外部mcp/webdriver占着环境的marionette会话时,关闭只能退回发信号;macos上的firefox不处理sigterm,等于强杀,刚写入的cookie、localStorage可能丢失。现在环境浏览器通过agent-sidebar.manifest里新的browser-first-window-ready分类开始监听,写出control/quit-channel.json,取走control/quit-request.json后像Marionette:Quit一样退出。取走和撤回是对同一个文件的删除,只有一方能成功。close()依次尝试通道、marionette、信号,并记录runtime.closedBy。
  • perf(sidebar) 流式markdown增量渲染:以前每次轮询都把整段实时内容重新解析,开销随长度平方增长。现在在不影响前文解析的空行处切块,已完成的块缓存起来,只重新解析最后一块;拿不准的地方就停止切分。流式输出与整段渲染逐字节一致。会话快照带rev,版本没变就跳过这次轮询。
  • fix(environment) 修复windows上的进程核对和结束(这次在真windows上验证时发现;第二批引入,尚未发布):windows的环境变量名是Path,上游Subprocess.pathSearch只认environment.PATH,所以tasklist.exe、powershell.exe、taskkill.exe永远找不到。凡是不是当前后端实例亲手拉起的环境(比如主浏览器重启之后),进程核对一律返回unknown:环境已经退出仍显示运行中,open()拒绝重新打开,close()既确认不了退出也发不了信号。现在系统工具直接从系统目录取(SysD,powershell.exe在WindowsPowerShell\v1.0下),回退查找时显式传入PATH;温和的taskkill被拒绝时(没有窗口的进程不接受不带/F的结束)直接强制结束,调用前已经核对过身份。

验证

  • 6个提交的代码树各自跑bash scripts/selftest-agent-tools.sh,全部通过(34/34/34/35/37/37步)。新增用例在旧代码上都会失败。
  • 编译机上用apply-patches.sh打到锁定基线(沙箱注入恰好一处),编出mac-arm64和win-x64(BuildID 20261024061226)。两个包里37个侧栏模块与提交逐字节一致(PageAccessibility.sys.mjs由构建生成),启动分类已登记。
  • mac包实测(临时profile):外部webdriver占着环境的marionette时,关闭走退出通道,0.6–0.7秒,cookie和localStorage都在;流式渲染的实时内容与最终消息一致;原生指纹验证213项通过。
  • windows包实测(windows server 2022):外部webdriver占着环境的marionette时,关闭同样走退出通道,cookie和localStorage都在;原生指纹验证196项通过;进程核对方面,新的后端实例能认出并关闭真实环境,pid被主控浏览器或node占用时判为不是本环境,一个信号都不发;主浏览器重启后,已经退出的环境显示已停止,可以重新打开。
  • 流式渲染性能(同一个二进制上新旧js交替,各两轮):侧栏渲染js占主线程采样24%→6%,主线程最大延迟56–71ms→17–18ms,超过50ms的卡顿3–5次→0;进程总cpu基本不变。

发布准备(v0.26.2正式版)

  • chore(release) 版本号改为0.26.2:包里的extensions.firefox-reverse.version必须等于release tag(verify-windows-package.py会核对),六个发布包都从这个提交(adeb510)编出。
  • 三个docs提交:把@QIWEB在关于会话导入导出优化建议+多组Base URL API Key Token+模型组合配置by qiweb3 #7、@leihualiang和@odtu945在#18里公开发的原话整理成docs/community/下的记录,作者分别设为本人,提交者是维护者。github的contributors只统计提交作者,Co-authored-by不算(qiweb之前就是这样没进列表)。
  • docs发布说明:changelog、readme的v0.26.2一节、#18启动说明的验收结果,以及docs/verification/release-v0.26.2/summary.json。
  • 五目标六包验证:SourceStamp adeb5100a6d43382bd0e26e9ab8461dcadbdbd79,BuildID 20261024082441。
平台 指纹回归 页面/agent 提示词场景/合成请求
macos arm64(本机macos 26.7.1) 213 33 8/11
macos intel(原生runner) 197 33 8/11
windows x86_64 212 33 8/11
linux x86_64 182 33 8/11
linux arm64 182 33 8/11

原生ci:run 40084257624。mac arm64另通过15个数据目录场景(含#18两类情况)、环境退出通道和从v0.26.1原位升级检查;windows另在真机上通过退出通道、进程身份核对和重启后状态恢复;安装程序核心载荷与zip一致。草稿release v0.26.2已上传六个包,合并后发布。

已知问题(本pr未处理)

  • windows上直连访问不到mozilla的服务时,环境浏览器退出常要15–60秒以上,后端等15秒后强杀。原因是环境profile不套用marionette推荐设置(remote.prefs.recommended=false),firefox自带的nimbus实验加载器在quit-application阶段等远程设置同步。v0.26.1同样存在。
  • windows上trace实际落盘还没在真机上测过。
  • WorkspaceBackend查找node等程序也用Subprocess.pathSearch,在windows上同样找不到,目前靠兜底路径。

🤖 Generated with Claude Code

WhiteNightShadow and others added 11 commits October 23, 2026 23:40
…nvironment backend copy

- Every T(...) declaration now states its traits (READ_ONLY, or a subset of
  confirm / repeatExempt / progress). The confirm list, the repeat-exempt set
  and the "counts as progress" regex are derived from the declarations instead
  of being kept separately; the stale net_intercept entry is gone.
- js_trace (run mode) and wasm_probe execute page code in the host Node
  process, so they now require confirmation like run_node.
- Remove modules/EnvironmentBackendCurrent.sys.mjs, an outdated copy of the
  environment backend that was still packaged; EnvironmentPane no longer
  falls back to it.
- New dev/selftest-tool-metadata.mjs keeps the README tool table, the system
  prompt, the skill doc and the tool descriptions consistent with the
  declarations.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…d Linux

Windows raises security.sandbox.content.level to at least 6, so the pref that
disables the content sandbox on macOS and Linux has no effect there and the
engine-level JSVMP / WebAPI trace could not write its NDJSON. apply-phase-b.py
now always injects MOZ_DISABLE_CONTENT_SANDBOX=1 at the start of main() on
Windows; before, it did so only with FRX_ALLOW_UNSANDBOXED_TRACE=1 and
stripped an existing injection otherwise. The injected code is unchanged, so
trees that already carry it are skipped.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
EnvironmentBackend.sys.mjs (3638 lines) keeps the public API and the
orchestration: locks, lifecycle and runtime state. The implementation moves to
- EnvironmentStore: directory layout, manifest/env.json, per-key locks
- EnvironmentProcess: launch, Marionette, pid identity, signals
- EnvironmentFingerprint: generation, validation, capture and import
- EnvironmentPrefs: fingerprint/proxy to user.js, main-profile managed block
- EnvironmentCurrentProcess: the main browser's own fingerprint/proxy config
- EnvironmentCommon: shared constants and helpers

Code was moved line by line. An old/new comparison with fixed randomness and
time gave identical results and files (346 checks). The underscore entry points
used by the selftests and scripts/verify-native-fingerprint.mjs remain as
delegates; the unused _pidAlive is removed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
When an external MCP/WebDriver client holds an environment's Marionette
session, closing it fell back to signals. macOS Firefox does not handle
SIGTERM, so the environment was killed and recently written cookies or
localStorage could be lost.

- EnvironmentControl.sys.mjs: environment browsers, started through the new
  browser-first-window-ready category in agent-sidebar.manifest, announce
  control/quit-channel.json and quit like Marionette:Quit when they take
  control/quit-request.json. Taking and withdrawing a request are the same
  unlink, so only one side can win.
- close() tries the channel first, then Marionette, then signals, and records
  runtime.closedBy. A failed request write falls back instead of leaving the
  environment in "closing"; the Linux Subprocess SIGKILL now comes after the
  backend's own wait, and a failed force kill re-checks whether the process
  is already gone.
- Tests for both sides, manifest registration checks in selftest-mozbuild,
  and a package check in prepare-native-candidate.py.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
While a reply streams, the live segment was re-parsed as a whole on every
poll, so the cost grew with the square of its length.

- MarkdownContent's streaming mode splits the text at blank lines that cannot
  change how earlier blocks parse, memoizes the finished blocks and re-parses
  only the last one. Anything it cannot judge line by line stops further
  splitting. The streamed output is byte-identical to rendering the whole text.
- AgentSession snapshots carry a rev; the panel skips polls whose rev has not
  changed. Clearing the live area invalidates it, so the steps and the confirm
  bar come back when the running thread is reopened.
- dev/selftest-markdown-streaming.mjs compares every prefix of a corpus in
  both modes; dev/selftest-panel-live.mjs covers the live polling in jsdom.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
On real Windows the environment variable is named "Path", and
Subprocess.pathSearch only reads environment.PATH, so tasklist.exe,
powershell.exe and taskkill.exe were never found. Every process check for an
environment the current backend did not launch itself (for example after the
main browser restarted) came back "unknown": the status stayed "running"
after the environment had exited, open() refused to start it again, and
close() could neither confirm the exit nor send a signal.

- resolveSystemCommand takes Windows system tools from the system directory
  (SysD, plus WindowsPowerShell\v1.0 for powershell.exe) instead of a PATH
  search, as unixCommand already does with /bin and /usr/bin; the fallback
  search passes PATH explicitly.
- terminatePid escalates to a forced kill when the gentle signal is refused:
  taskkill without /F fails for windowless (headless or exiting) processes,
  and close() has already verified the identity.
- Selftests reproduce the real pathSearch behaviour and the refused taskkill.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The packaged extensions.firefox-reverse.version has to match the release tag
(verify-windows-package.py checks it), so the v0.26.2 packages are built from
this commit.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Record the five-target package verification (native CI run 40084257624 and
the local macOS ARM64 and Windows checks), mark the issue #18 app-data fix as
released, and credit the issue #7 and #18 contributors.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@WhiteNightShadow WhiteNightShadow changed the title feat: 拆分环境后端,新增环境内退出通道与流式增量渲染(审查第三批) feat: 拆分环境后端,新增环境内退出通道与流式增量渲染(审查第三批,v0.26.2) Oct 24, 2026
@WhiteNightShadow
WhiteNightShadow merged commit 27f1268 into main Oct 25, 2026
2 checks passed
@WhiteNightShadow
WhiteNightShadow deleted the feat/batch3-round1 branch October 25, 2026 02:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants