Repository navigation
fix(desktop): restore remote Harness routing across RPC layouts and reconnects - #706
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Native RPC 契约发现与安装 packages/desktop-control/src/renderer-native-rpc-contracts.ts, packages/desktop-control/src/renderer-native-rpc-discovery.ts, packages/desktop-control/src/renderer-native-rpc-install.ts, packages/desktop-control/src/renderer-cdp-control-session.ts, packages/desktop-control/test/renderer-native-rpc.test.ts, packages/desktop-control/test/renderer-native-rpc-install.test.ts, docs/architecture/official-traffic-ownership.md |
新增 Native RPC 类型契约和结构式组件发现逻辑。安装入口在符合条件的 Desktop RPC 布局中发现并接入远程控制。 |
连接代次与 Host 路由 packages/desktop-control/src/renderer-connection-generation.ts, packages/desktop-control/src/renderer-host-routing.ts, packages/desktop-control/src/renderer-host-rpc-routing.ts, packages/desktop-control/src/renderer-draft-prewarm-policy.ts, packages/desktop-control/test/renderer-connection-generation.test.ts, packages/desktop-control/test/renderer-host-routing.test.ts, packages/desktop-control/test/renderer-host-rpc-routing.test.ts, docs/operations/codex-desktop-upgrade-diagnosis-playbook.md, docs/architecture/official-traffic-ownership.md |
Remote Control 路由按连接 owner 和 revision 判断有效性。RPC 路由重新解析 Host 和客户端,并可在原生管理器可用后切换到原生路由。 |
原生桥接与交互转发 packages/desktop-control/src/renderer-native-remote-manager.ts, packages/desktop-control/src/renderer-native-rpc-channel.ts, packages/desktop-control/src/renderer-native-rpc-interactions.ts, packages/desktop-control/src/renderer-draft-prewarm-runtime.ts, packages/desktop-control/test/renderer-native-remote-manager.test.ts, packages/desktop-control/test/renderer-native-rpc-interactions.test.ts, packages/desktop-control/test/renderer-draft-prewarm-policy.test.ts |
新增原生管理器、双向 RPC 通道和交互事件保留逻辑。桥接进程控制请求可通过独立发送函数传输。 |
原生服务适配与连接生命周期 packages/desktop-control/src/renderer-native-rpc-service.ts, packages/desktop-control/src/renderer-native-rpc-runtime.ts, packages/desktop-control/test/renderer-native-rpc.test.ts, docs/platforms/remote/remote-control-host.md, docs/platforms/remote/remote-control-host.zh-CN.md, docs/architecture/official-traffic-ownership.md |
服务适配器根据 Host、平台路径和连接状态发布原生管理器或远程桥接。连接断开、重连和订阅释放时清理对应资源。 |
JSON-RPC 错误码兼容
| Layer / File(s) | Summary |
|---|---|
错误码回退与 Thread 所有权测试 packages/renderer-extension/src/renderer-request-sender.ts, packages/renderer-extension/test/renderer-native-thread-ownership.test.ts |
当错误对象没有 code 属性时,请求发送器读取 jsonRpcCode。测试增加通过该属性表示的不支持错误和普通错误样例。 |
Estimated code review effort: 4 (Complex) | ~60 minutes
Change: Bug fix
Sequence Diagram(s)
sequenceDiagram
participant NativeRpcManager
participant NativeRpcService
participant NativeRemoteManager
participant NativeRpcInteractions
NativeRpcManager->>NativeRpcService: 订阅主机服务
NativeRpcService->>NativeRpcManager: 查询 Codex home 与连接状态
NativeRpcService->>NativeRemoteManager: 为符合条件的主机创建桥接
NativeRemoteManager->>NativeRpcInteractions: 订阅并恢复待处理交互
NativeRpcInteractions-->>NativeRemoteManager: 返回订阅就绪状态
NativeRemoteManager-->>NativeRpcService: 返回管理器与路由
NativeRpcService-->>NativeRpcManager: 发布 RPC 与路由状态
Possibly related issues
- BytePioneer-AI/codex-host#591:该问题报告 Desktop 更新后 Renderer Host 请求管理器不可用;本次变更增加不同 Desktop 管理器布局下的发现和路由接管。
- BytePioneer-AI/codex-host#691:安装流程依赖 loaded-module catalog 发现 Native RPC 合约;本次变更未修改 catalog 的发布逻辑。
Possibly related PRs
- BytePioneer-AI/codex-host#660:该 PR 建立 Desktop 主进程 Manager 的 Renderer RPC 发现与路由;本次变更在此基础上发现并复用原生 RPC 合约。
- BytePioneer-AI/codex-host#663:该 PR 涉及 Renderer Manager 与主进程 RPC 路由;本次变更扩展连接代次、原生 Manager 发现和路由接管。
- BytePioneer-AI/codex-host#630:该 PR 建立 Desktop 外部 Harness 草稿预热和创建路由;本次变更扩展同一预热策略中的控制帧发送与 Manager 接管。
Suggested reviewers: bytepioneer-ai
Merge Risk: 
Minimal · up to a2240
-
The supplied evidence identifies no remaining issue that should block merging. Complete the normal checks before release.
Pre-merge checks: 
4
-
Full details: Title check
-
Explanation
标题“fix(desktop): restore remote Harness routing across RPC layouts and reconnects”与变更集的主要内容相符。变更包括:在 RPC 与 Renderer 两种 Desktop 布局下恢复外部 Harness 远程控制路由、处理断连重连后的桥接失效,并新增原生 Manager 发现与交互转交。标题聚焦于主要变更,表述具体,没有使用模糊词汇。
-
Finishing Touches
-
Generate docstrings
-
- Commit to this branch
- Create a new PR
Generate unit tests (beta)
-
- Commit to this branch
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
|
@codex review |
|
Codex Review: Didn't find any major issues. Can't wait for the next one! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
🛡️ Codex Security Review · Automatically triggeredSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
Summary
Restore external Harness Remote Control across both Desktop manager layouts, while preserving native Codex over SSH and Remote Control. Based on
main/ v0.17.0 (b3094d5a).Trigger conditions and resulting behavior
Remote Control disconnects, but Desktop reuses its manager object. Object identity previously kept a bridge whose process handle belonged to the old connection. Routing now observes the native connection owner/revision and retires stale policies, including a reconnect that happens between reads. Recovery does not replay submitted turns.
A stock SSH app-server rejects a codexhost method through the newer RPC error wrapper. Desktop puts the protocol error in
jsonRpcCode. Normalize that field so the existing native-thread fallback recognizes-32600/-32601; authentication, transport and other errors remain errors.The initial page exposes RPC routing before a native Composer mounts. Prefer usable native managers per Host when they appear, while retaining ready RPC fallback for other Hosts. An empty legacy registry does not suppress v0.17's valid RPC fallback. Managers without a Host getter use the request-client Host identity; an unavailable getter preserves the existing RPC route.
Desktop keeps all managers in the main process. Forwarding
codexhost/harness/inspectto the stock Remote Control endpoint producesunknown variant codexhost/harness/inspect. Discover Desktop's already-loaded native manager factory, RPC session and UI controller by structural contracts and factory-call relationships. Reuse them to connect actual creation, history, subscriptions, queued follow-ups and approvals to the Windows Harness bridge. Replacing only the published connection signal is insufficient for native UI actions.Implementation details
Keep tunnel
process/spawn,process/writeStdinand cleanup on the retained original RPC transport, outside the logical request queue. Otherwise concurrent metadata/history requests can occupy the queue needed to deliver their own responses.Wait for native interaction subscriptions before publishing the adapted route. Main-process managers consume approval, user-input and MCP elicitation requests before normal window broadcasting, so subscribe to their native events and read the authoritative pending request from the native conversation. Recover outstanding interactions once at connection setup; deduplicate requests and reject stale snapshots after resolution or retirement.
Accept native preload notifications with a null source, while rejecting foreign windows and mismatched non-opaque origins.
Release per-connection managers, subscriptions and process bridges on retirement. Keep the upstream RPC handle until final control requests settle. Preserve thread IDs, Harness ownership and native session history.
Treat failure of the initial optional RPC discovery evaluation as an unavailable capability, so native Codex/SSH installation can continue. Regression tests cover both routing discovery exceptions and a destroyed CDP context.
Require verified own properties when identifying scope handles and services; callable RPC proxies must not pass structural guards. Discovery is limited to the current document's loaded module catalog, rejects ambiguous contracts and releases its CDP object group. Unavailable discovery has at most three attempts per catalog/local RPC owner, with 5s/10s cooldowns; owner replacement resets the budget and stale completions cannot overwrite newer attempts. No renamed-symbol/hash pinning, copied Desktop implementation, signed-app patching or polling for optional Harnesses.
Enable this external bridge only for controlled Windows Hosts. POSIX Remote Control and ordinary Hosts retain the native service. A missing/failed contract falls back to native Codex availability rather than publishing a partially initialized manager.
Evidence
Before: five focused regression cases fail against pristine v0.17.0: reused-manager reconnect, a reconnect between route reads, late Composer handoff, and the two RPC unsupported-method error codes. The live pure-RPC Mac also rejected Pi inspection; text-only probes missed a native approval that remained invisible while the server waited for a decision.
After: 144 focused tests across ten files pass. Type checking, formatting, ESLint of the changed files, dependency-boundary checks and the Controller/Renderer builds pass. New tests cover fake RPC proxies, symbol renaming/ambiguity, independent control traffic, connection/subscription races, POSIX passthrough, preload events, interaction deduplication and late resolved/retired snapshots.
Packaged runtime checks: official v0.17.0 npm payloads plus the two built Controller/Renderer overlays; all installed files compared with the official archives (92 Windows files, 91 on each Unix platform).
Live deployment verification passed on all three machines:
| Path | Verification |
| --- | --- |
| Windows, macOS, Ubuntu gateway | Managed startup and native Codex first turn, resume and contextful follow-up |
| Windows → Mac / gateway SSH | Native Codex two-turn history and ownership |
| Windows → gateway Remote Control | Native Codex, actual disconnect/reconnect, resume and exactly two replies |
| Mac → Windows Remote Control | Native Codex and Pi, actual disconnect/reconnect, preserved Pi ownership and exactly two replies |
| Mac native UI → Windows Pi | Actual project/Agent selection, new conversation creation, unsubscribe/resume and UI follow-up |
| Mac native UI → Windows Codex | Ask-mode approval displayed automatically; allow-once executes only the marker command, deny completes without executing it |
The packaged runtime matrix above was exercised on candidate
.3at2e294966. The follow-up discovery guards were additionally checked with the full focused suite and isolated fixture execution in the running Windows and macOS Chromium renderers; this review update does not replace the installed candidates.The packaged Mac UI checks run after a clean Desktop restart without prototype protocol hooks. Test conversations are archived. Pi does not expose a selectable native permission mode; the approval checks above use native Codex, not a claimed Pi approval mode. Gateway has no external Harness installed, so its Remote Control result covers native Codex only.
Merge Danger
Door: two-way. Revert the commits or switch back to the previous launcher candidate; no account-state migration is introduced.
Blast Radius: Desktop.
This touches private Desktop binding and Remote Control lifecycle boundaries. Unsupported or ambiguous native contracts preserve the official route, and failed interaction setup disposes the candidate manager before falling back. Harness-specific protocols remain in their adapters; no credentials, runtime state, proprietary assets or deployment scripts are included in this PR.