Skip to content

fix(compatibility): support delegated worktree shell environment pattern - #52

Open
ken861222 wants to merge 1 commit into
RyensX:mainfrom
ken861222:fix/worktree-shell-environment-pattern
Open

ken861222 wants to merge 1 commit into
RyensX:mainfrom
ken861222:fix/worktree-shell-environment-pattern

Conversation

@ken861222

Copy link
Copy Markdown

问题描述 (Problem Description)

在官方 Codex / ChatGPT Desktop 最新运行时版本(如 26.908.40834 (build 8881))中,main.js"worktree-shell-environment-config" 的定义由内联的 async({cwd, hostId}) => { ... } 重构为直接委托给实例方法:

"worktree-shell-environment-config":({cwd:e,hostId:t})=>this.readWorktreeShellEnvironment(e,t??`local`),

原有的 WORKTREE_SHELL_ENVIRONMENT_PATTERN 正则仅匹配旧版内联 async 函数形式,导致:

  1. 优化器未能识别并补丁该 handler(recognizedCount: 0 < markerCount: 1),在 Manifest 中被标记为 "worktreeShellEnvironment": "unsupported-layout"
  2. /api/health 检查失败并显示健康状态异常(compatibility.status: "degraded"static.cache.main.worktree-shell-environmentCached locator did not resolve)。
  3. 浏览器端启动时调用 /worktree-shell-environment-config,由于缺少限流合并与 2 秒 fallback 超时保护,耗时过长(10s~20s+),导致 Web 界面卡在启动加载(Loading)状态。

修复方案 (Solution)

  1. 更新 OfficialRuntimeOptimizer.ts 中的 WORKTREE_SHELL_ENVIRONMENT_PATTERN,同时兼容旧版内联 async 块以及新版委托给 this.readWorktreeShellEnvironment 的方法调用形式。
  2. 保持箭头函数词法作用域中的 this 绑定,确保包装后的 cache handler 正确执行。
  3. 增加单元测试,覆盖新版委托语法的优化与合并调用行为。

测试验证 (Testing)

  • node --test gateway/test/official-desktop-compat.test.cjs 相关单元测试通过。
  • 在本地实际解包的最新官方 bundle(26.908.40834 / build 8881)上验证,补丁成功应用,/api/health 返回 ok: truecompatibility.status: "ok",Web 端正常加载。

@RyensX

RyensX commented Sep 13, 2026

Copy link
Copy Markdown
Owner

感谢PR!其实这个问题今天我在测试Windows上时也发现了,不过不确定是否只有Windows有问题所以没有吧修复带上去。这里你做了我就不做了,等测完review会进行合并

@yorkane

yorkane commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

Tested on Linux (headless gateway, no Launcher) and it fixes the point as described.

  • Official runtime: ChatGPT Desktop for Linux 26.908.40834 (build 318576267-1789148373000), codex-cli 0.154.0-alpha.6.2
  • Base: 2.1.0 (f6fd79c) + this PR (b5c61e2)

Before (plain 2.1.0):

/api/health  ok:false   checks.compatibility:false
unsupportedFiles: ["main-DaMR-wdT.js:worktree-shell-environment"]
runtimeOptimizations.worktreeShellEnvironment: "unsupported-layout"
abnormalPoints: [{ id: "static.cache.main.worktree-shell-environment",
                   reason: "Expected 1 candidates but found 0" }]

After (2.1.0 + #52, bundle cache rebuilt so the optimizer re-patches main-*.js):

/api/health  ok:true    all 7 checks true
unsupportedFiles: []
runtimeOptimizations.worktreeShellEnvironment: "gateway-coalesced"
compatibility: 103 points / degraded 0 / unavailable 0

The patched main bundle now contains the cache wrapper (__opencodexWorktreeShellEnvironmentCache).

Test run: gateway/test/official-desktop-compat.test.cjs = 44/44 pass, including the new case.
Heads-up for anyone running the suite: the tests consume gateway/dist, so a plain node --test gateway/test/...
against a stale dist fails the new case until pnpm run build:gateway (i.e. pretest) has been run.

Note: unrelated to this PR, we are also tracking a chronic app-host / AppView RPC staleness problem in #53.

Environment: Linux x86_64, gateway started with pnpm run web:dev, desktop shell from the official Linux .deb.

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.

3 participants