Skip to content

fix(desktop): restore remote Harness routing across RPC layouts and reconnects - #706

Merged
BytePioneer-AI merged 8 commits into
mainfrom
fix/0170-retain-remote-fixes
Nov 3, 2026
Merged

BytePioneer-AI merged 8 commits into
mainfrom
fix/0170-retain-remote-fixes

Conversation

@mouzhi

@mouzhi mouzhi commented Nov 2, 2026 •

Copy link
Copy Markdown
Collaborator

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).


Desktop with Renderer managers

  physical connection revision changes -> retire old bridge -> fresh process handle



Desktop with main-process RPC managers

  loaded native contracts -> native UI controller + per-Host service

    Windows Remote Control -> native Renderer manager -> Harness process bridge

    other Hosts            -> original native RPC manager

  native interaction event -> authoritative pending request -> native approval UI

Trigger conditions and resulting behavior

  1. 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.

  2. 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.

  3. 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.

  4. Desktop keeps all managers in the main process. Forwarding codexhost/harness/inspect to the stock Remote Control endpoint produces unknown 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/writeStdin and 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 .3 at 2e294966. 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.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-02T15:03:40.094841Z a224051 Manual request
🔒 Security Review ✅ Completed 2026-11-02T15:04:35.350005Z a224051 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between b753f8a and a224051.

Files selected for processing: 8
  • docs/architecture/official-traffic-ownership.md
  • packages/desktop-control/src/renderer-draft-prewarm-policy.ts
  • packages/desktop-control/src/renderer-host-routing.ts
  • packages/desktop-control/src/renderer-host-rpc-routing.ts
  • packages/desktop-control/src/renderer-native-rpc-install.ts
  • packages/desktop-control/test/renderer-host-routing.test.ts
  • packages/desktop-control/test/renderer-host-rpc-routing.test.ts
  • packages/desktop-control/test/renderer-native-rpc-install.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

Recent review details
Context from checks skipped due to timeout: 4
  • GitHub Check: Check macos-15
  • GitHub Check: Check Linux ARM64
  • GitHub Check: Check ubuntu-22.04
  • GitHub Check: Check windows-latest
Additional context used
Code guidelines: 1
AGENTS.md — auto-discovered
Path-based instructions: 1
Source excerpt: `codexhost` runs external Agent Harnesses as independent Threads inside Codex Desktop, preserving the official shell and native Codex path.

CodeRabbit inference engine (AGENTS.md)

Files:

  • packages/desktop-control/test/renderer-native-rpc-install.test.ts
  • packages/desktop-control/src/renderer-native-rpc-install.ts
  • packages/desktop-control/src/renderer-host-routing.ts
  • packages/desktop-control/src/renderer-draft-prewarm-policy.ts
  • packages/desktop-control/test/renderer-host-routing.test.ts
  • packages/desktop-control/test/renderer-host-rpc-routing.test.ts
  • packages/desktop-control/src/renderer-host-rpc-routing.ts
  • docs/architecture/official-traffic-ownership.md
Learnings: 1
Common learnings
Learnt from: CR
Repo: BytePioneer-AI/codex-host PR: 0
File: .agents/skills/codexhost-pre-push-checks/SKILL.md:0-0
Timestamp: 2026-10-31T06:53:01.023Z
Learning: Applicability reference:
AGENTS.md: # Repository Guidelines
## Repository Skills
| Task | Skill |
| --- | --- |
| Selecting local checks before pushing or claiming checks pass | [codexhost-pre-push-checks](.agents/skills/codexhost-pre-push-checks/SKILL.md) |

Source excerpt:
# codexhost 推送前检查

## 按改动面选择

规则:每个行为改动至少有一个“回归时会失败”的测试或检查;没有现成的就补一个或说明缺口。不要因为即将提交就重复跑刚通过的检查。
Learnt from: CR
Repo: BytePioneer-AI/codex-host PR: 0
File: .agents/skills/codexhost-code-review/SKILL.md:0-0
Timestamp: 2026-10-17T15:17:42.370Z
Learning: Applicability reference:
AGENTS.md: # Repository Guidelines
## Repository Skills
| Task | Skill |
| --- | --- |
| Reviewing a PR or local diff for correctness and boundaries | [codexhost-code-review](.agents/skills/codexhost-code-review/SKILL.md) |

Source excerpt:
# codexhost 代码审查

## 阻断项

2. **官方流量归属**:Host 只截获自身流量,其余原样转发。检查新增拦截是否有归属依据,参见 [official-traffic-ownership](../../../docs/architecture/official-traffic-ownership.md)。
Additional comments: 8
packages/desktop-control/src/renderer-native-rpc-install.ts: 1

16-16: LGTM!

Also applies to: 22-22, 27-28, 31-39, 74-77

packages/desktop-control/test/renderer-native-rpc-install.test.ts: 1

4-97: LGTM!

docs/architecture/official-traffic-ownership.md: 1

22-22: LGTM!

Also applies to: 24-24, 26-26, 28-28

packages/desktop-control/src/renderer-draft-prewarm-policy.ts: 1

48-48: LGTM!

Also applies to: 56-56, 70-72, 74-74, 79-80, 83-84

packages/desktop-control/src/renderer-host-routing.ts: 1

71-76: LGTM!

Also applies to: 118-125, 261-265

packages/desktop-control/src/renderer-host-rpc-routing.ts: 1

12-12: LGTM!

Also applies to: 30-31, 49-58, 61-61, 64-65, 71-94, 196-196, 204-224, 314-324, 328-329, 332-333, 348-349, 356-363, 379-379, 383-384, 388-388, 395-396

packages/desktop-control/test/renderer-host-routing.test.ts: 1

121-143: LGTM!

packages/desktop-control/test/renderer-host-rpc-routing.test.ts: 1

124-135: LGTM!

Also applies to: 167-342, 357-358, 362-362, 388-390, 393-393, 595-597, 600-600

Summary

Summary by CodeRabbit

  • 新功能
    • 符合条件的 Windows Desktop Remote Control 会话可使用外部 Harness;不支持或无法确认的环境继续使用原生路由。
    • Renderer 与 RPC 管理布局均可按 Host 使用可用路由;原生管理器就绪后可接管,其他 Host 的 RPC 路由保持可用。
    • 断连后旧桥接失效,重连时建立新桥接,且不会重放已提交的消息。
    • 可恢复进行中的审批与交互请求,并避免重复处理;隧道控制请求不受逻辑请求队列阻塞。
  • 文档
    • 补充 Desktop 兼容性、路由切换、重连行为及相关诊断说明。

此变更为 Desktop 增加 Native RPC 远程控制接入,包含契约发现、连接代次路由、桥接生命周期和交互转发。请求发送器还新增 jsonRpcCode 错误码回退,并更新相关测试与文档。

Changes: Native RPC 远程控制接入

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 与路由状态
Loading

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: Passed 4
Check name Status Explanation
Title check Passed 标题“fix(desktop): restore remote Harness routing across RPC layouts and reconnects”与变更集的主要内容相符。变更包括:在 RPC 与 Renderer 两种 Desktop 布局下恢复外部 Harness 远程控制路由、处理断连重连后的桥接失效,并新增原生 Manager 发现与交互转交。标题聚焦于主要变更,表述具体,…
Description check Passed 描述与变更集高度相关。描述说明了目标(在两种 Desktop Manager 布局下恢复外部 Harness Remote Control,同时保留 SSH 和 Remote Control 上的原生 Codex)、触发条件、实现细节(契约发现、交互订阅、生命周期释放、Windows 限定)、验证证据及合并风险。描述内容具体,与摘要中列出的文件变更一致。
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
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.

Share

@coderabbitai coderabbitai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Fix comments: Fix CodeRabbit comments on this PR

@coderabbitai coderabbitai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Fix comments: Fix CodeRabbit comments on this PR

mouzhi commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: a224051441

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

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".

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: a224051441

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

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.

2 participants