Skip to content

feat: serve external clients from headless remote hosts - #788

Merged
BytePioneer-AI merged 1 commit into
BytePioneer-AI:mainfrom
ump45nose:codex/upstream-remote-host-mcp
Nov 10, 2026
Merged

BytePioneer-AI merged 1 commit into
BytePioneer-AI:mainfrom
ump45nose:codex/upstream-remote-host-mcp

Conversation

@ump45nose

@ump45nose ump45nose commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Managed Remote Hosts currently skip the existing external-client listener, so an authenticated MCP client cannot delegate work without a local Desktop runtime. Start the same listener for local, shared, and managed remote runtimes, preserving token authentication, loopback binding, CODEXHOST_EXTERNAL_CLIENT_PORT=off, and best-effort handling of occupied ports.

Initialize the independent official connection before a headless client's first native thread/start. Without this, a first delegation using the default model can fail before any model-catalog call has initialized the protocol. Add a regression fixture that rejects requests made before initialization, and document the Remote Host data directory and headless behavior.

Validation: TypeScript build and typecheck; 70 focused tests across headless delegation, native projection, MCP, runtime, and local shared Host; ESLint and Prettier on changed files. A stable-version backport was also exercised on a Linux x64 NAS using an actual native Codex delegation, completion event, result read, and private Tailscale HTTPS endpoint.

CI: Linux x64, Linux ARM64, and Windows passed. macOS failed in the unchanged Web relay test closes a phone stalled after ClientHello at the 10-second TLS deadline (packages/web-server/test/relay-http.test.ts:242, lower-bound timing assertion). Re-running that upstream job requires repository administrator access.

Related: #785 provides optional remote-access policies and webhooks; this change reuses the existing external-client service and is independently applicable.

@coderabbitai

coderabbitai Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • 新功能
    • 受管远程 Host 现可支持外部客户端监听与发现,并通过共享执行会话委派任务。
    • 无界面共享执行会话首次进行原生 Codex 委派时会先协商官方协议;使用默认模型无需先查询模型目录或打开 Desktop。
  • 文档
    • 补充了远程 Host 的委派方式、数据存储位置及运行客户端时的数据目录要求。

Host Runtime 现在始终尝试启动外部客户端服务,包括受管 Remote Host。原生 Codex 委派通过官方请求封装启动线程,并由新增测试验证首次委派的协议初始化顺序。

Changes: 受管 Remote Host 客户端委派

Layer / File(s) Summary
外部客户端服务启动
packages/host-runtime/src/run-host-runtime.ts、packages/host-runtime/src/shared-host-service.ts、docs/architecture/external-clients.md
移除控制外部客户端服务启动的 externalClients 选项。Host Runtime 现在始终尝试启动服务;未配置端口时仍不启动,启动失败时仍记录错误并继续创建 Host。文档说明受管 Remote Host 的监听、数据目录要求及首次委派的协议协商。
原生 Codex 委派协议
packages/host-runtime/src/app-server-host.ts、packages/host-runtime/test/app-server-host.headless-delegation.test.ts
thread/start 改用 #requestOfficial。新增测试验证首次委派仅调用一次 initialize,然后启动线程和回合,并返回线程 ID、回合 ID及 running 状态。

Estimated code review effort: 2 (Simple) | ~12 minutes

Change: Feature

Possibly related issues

  • BytePioneer-AI/codex-host 第 722 号 issue:本 PR 在受管 Remote Host 上启动现有外部客户端监听,涉及该 issue 的远程 Host 访问目标;但没有实现 issue 提到的 tailnet、公网策略或 webhook。

Suggested labels: 类型:功能新增

Suggested reviewers: bytepioneer-ai

Merge Risk: Minimal · up to 48bfc

The headless delegation test covers the reported first-request failure, and no unresolved merge-blocking issue is established.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed 标题准确概括了主要变更:让无头远程 Host 提供外部客户端服务。
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.
Description check Passed PR 描述与变更相关,说明了远程 Host 外部客户端监听、无头委派初始化、回归测试和文档更新。
Finishing Touches

Generate unit tests (beta)

  • 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

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 85a72c1 and 48bfc87.

Files selected for processing: 5

  • docs/architecture/external-clients.md
  • packages/host-runtime/src/app-server-host.ts
  • packages/host-runtime/src/run-host-runtime.ts
  • packages/host-runtime/src/shared-host-service.ts
  • packages/host-runtime/test/app-server-host.headless-delegation.test.ts
Files with no reviewable changes: 1

  • packages/host-runtime/src/shared-host-service.ts

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

Recent review details

Context from checks skipped due to timeout: 4

  • GitHub Check: CodeRabbit
  • GitHub Check: Check windows-latest
  • GitHub Check: Check macos-26
  • GitHub Check: Check ubuntu-22.04
Additional context used

Code guidelines: 2

AGENTS.md — auto-discovered
CLAUDE.md — auto-discovered
Path-based instructions: 3

Source excerpt: Host Runtime loads installed plugins through public contracts, not direct imports of concrete Adapter packages.

CodeRabbit inference engine (AGENTS.md)

Files:

  • packages/host-runtime/src/app-server-host.ts
  • packages/host-runtime/src/run-host-runtime.ts
  • packages/host-runtime/test/app-server-host.headless-delegation.test.ts
Source excerpt: Keep changes narrowly scoped.

CodeRabbit inference engine (CLAUDE.md)

Files:

  • packages/host-runtime/src/app-server-host.ts
  • docs/architecture/external-clients.md
  • packages/host-runtime/src/run-host-runtime.ts
  • packages/host-runtime/test/app-server-host.headless-delegation.test.ts
Source excerpt: Use package public exports for cross-package dependencies.

CodeRabbit inference engine (CLAUDE.md)

Files:

  • packages/host-runtime/src/app-server-host.ts
  • packages/host-runtime/src/run-host-runtime.ts
  • packages/host-runtime/test/app-server-host.headless-delegation.test.ts
Additional comments: 4

packages/host-runtime/src/run-host-runtime.ts: 1

197-207: 外部客户端监听现在在所有 prepareDelegationRuntime 调用方中无条件启动。请确认这是预期行为。

本地 Desktop、共享 Host 和受管 Remote Host 都会尝试绑定 127.0.0.1:4398。同一用户下有多个 Host Runtime 进程时,后启动的进程会遇到 EADDRINUSE。startExternalClientServer 会返回 undefined 并写诊断,Host 继续运行,这个行为是安全的。

两点需要确认:

  • 同一数据目录下的 cli-credentials.json 和 external-client-endpoint.json 只由成功绑定端口的进程写入。绑定失败的进程不会覆盖它们。
  • 非 EADDRINUSE 的监听错误会被 .then 的拒绝处理捕获并记录,不会终止 Host。

当前代码满足这两点,无需修改。如需在启动时显式区分“已关闭”和“端口被占用”的日志,可在后续补充。

docs/architecture/external-clients.md: 1

23-25: LGTM!

packages/host-runtime/src/app-server-host.ts: 1

2201-2201: LGTM!

packages/host-runtime/test/app-server-host.headless-delegation.test.ts: 1

14-107: LGTM!

@BytePioneer-AI
BytePioneer-AI merged commit 4d6ee40 into BytePioneer-AI:main Nov 10, 2026
4 of 5 checks passed
ump45nose added a commit to ump45nose/codex-host that referenced this pull request Nov 10, 2026
Keep local preview wiring from this branch and always start external
clients, matching main after BytePioneer-AI#788, instead of gating them to the local
runtime only.
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