Skip to content

fix(host-runtime): handle prefetched output read rejections - #1215

Merged
iruriQ merged 2 commits into
BytePioneer-AI:mainfrom
Tim0085:fix/host-output-close
Nov 26, 2026
Merged

iruriQ merged 2 commits into
BytePioneer-AI:mainfrom
Tim0085:fix/host-output-close

Conversation

@Tim0085

@Tim0085 Tim0085 commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Summary

Windows x64 上的 CodexHost v0.26.0 和 v0.27.0 均出现过相同的 Host Runtime 退出。日志先记录官方 Codex 不可用并安排 1000 ms 后重启,随后记录 FATAL unhandledRejection: Error [ERR_STREAM_PREMATURE_CLOSE]: Premature close,Host 以退出码 1 结束。首次断连的触发源仍待定位。

CodexRuntime 在等待当前通知转发完成前,会调用 frames.next() 预读下一帧。输出流在这段时间提前关闭时,预读 Promise 可能在 await following 前拒绝,触发进程级未处理拒绝,打断已安排的恢复。

在发起预读时立即附加拒绝处理,随后仍等待原 Promise,让读失败进入已有的消费错误处理。回归测试使用内存流暂停通知转发,再关闭官方输出,验证关闭通知仍会送达且预读拒绝不会逃逸到进程。

Related issues

N/A

UI Demo

N/A

Test plan

  • 在 Windows x64、Node.js v24.14.0 上运行 node node_modules/vitest/vitest.mjs run --config tests/vitest.config.js --maxWorkers=1 packages/host-runtime/test/codex-runtime-lifecycle.test.ts。
  • 加入回归测试后、修复前,新测试捕捉到一次 Premature close 未处理拒绝并失败。修复后,该文件 5 个测试全部通过。
  • 两个改动文件通过 Prettier 检查,git diff --check 通过。
  • 验证范围为合成流与 Runtime 生命周期,真实 Codex Desktop 断连恢复未实测。

@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • 修复
    • 修复通知转发期间输出提前关闭时可能产生未处理错误的问题;关闭错误现在会正常传递,并且不会重复报告。

CodexRuntime 在等待 onOutput 时,立即为预取的 frames.next() Promise 附加拒绝处理器。之后仍会等待原 Promise,拒绝仍由现有错误流程处理。新增生命周期测试覆盖通知期间 stdout 关闭的情况。

Changes: Codex runtime 生命周期

Layer / File(s) Summary
预取读取的拒绝处理
packages/host-runtime/src/codex-runtime/codex-runtime.ts, packages/host-runtime/test/codex-runtime-lifecycle.test.ts
#consume 立即观察预取读取的拒绝,同时保留后续对原 Promise 的等待。测试验证通知回调待处理时 stdout 关闭后,onClosed 仅收到一次错误,且没有未处理的 Promise rejection。

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

Change: Bug fix

Suggested reviewers: bytepioneer-ai

Merge Risk: Minimal · up to c3c7a

The change prevents the host runtime from exiting on an unhandled stream premature-close rejection after a disconnect. It is small, covered by a regression test, and ready to merge.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed 标题“fix(host-runtime): handle prefetched output read rejections”准确描述了主要改动:在 CodexRuntime 预读输出帧时为 frames.next() 的拒绝附加处理。标题指向 host-runtime 包,并说明修复类型。改动内容与标题一致,检查通过。
Description check Passed 描述与改动直接相关。它说明了 Windows 上 CodexHost 断连后出现的 ERR_STREAM_PREMATURE_CLOSE 未处理拒绝,解释了 CodexRuntime 预读 frames.next() 的原因,并说明了修复方式和回归测试。测试计划也与改动文件一致。检查通过。
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.
Finishing Touches

Generate unit tests (beta)

  • Create a new PR
Fix failing CI checks

  • 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 14e57f3 and c3c7a0d.

Files selected for processing: 1

  • packages/host-runtime/test/codex-runtime-lifecycle.test.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: 8

  • GitHub Check: CodeRabbit
  • GitHub Check: Check Linux ARM64
  • GitHub Check: Static checks
  • GitHub Check: Vitest
  • GitHub Check: Check macos-26
  • GitHub Check: Check ubuntu-22.04
  • GitHub Check: Check windows-latest
  • GitHub Check: Web Host tests
Additional context used

Code guidelines: 2

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

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

CodeRabbit inference engine (CLAUDE.md)

Files:

  • packages/host-runtime/test/codex-runtime-lifecycle.test.ts
Source excerpt: Use package public exports for cross-package dependencies.

CodeRabbit inference engine (AGENTS.md)

Files:

  • packages/host-runtime/test/codex-runtime-lifecycle.test.ts

@iruriQ
iruriQ merged commit 38a1a73 into BytePioneer-AI:main Nov 26, 2026
7 of 8 checks passed
@iruriQ

iruriQ commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator

感谢贡献!3 行精准修复了官方输出流提前关闭时的 unhandledRejection 崩溃竞态,回归单测扎实。已核实 Check windows-latest 失败仅为无关用例抖动(broker-lifecycle 与 certificates 超时),现已合并。

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