Repository navigation
fix(runtime): fence node-pty writes at PTY exit - #3016
Conversation
Astro-Han
left a comment
There was a problem hiding this comment.
Thanks — this fixes the race at the correct ownership boundary. Fencing queued writes inside node-pty’s CustomWriteStream is substantially cleaner than adding retries or defensive behavior in Runtime or SQLite consumers. I found no P0–P2 issues, so I’m approving.
Before merging, please rebase onto the current main, resolve the patches/README.md conflict, and confirm the new head is green. I consider this merge hygiene rather than a blocker to approval.
One non-blocking test note: after reversing the dependency patch, the regression failed consistently in one environment but survived repeated runs in another. The underlying fd-reuse race and the production fix are sound, but the fixture still appears sensitive to scheduling and fd allocation. It may be worth either forcing reuse of the exact retired fd or describing this as a stress regression rather than a deterministic one.
中文对照
感谢修复。这个改动在正确的职责边界上解决了竞态:在 node-pty 的 CustomWriteStream 内终止过期写入,比在 Runtime 或 SQLite 使用方增加重试和防御逻辑干净得多。没有发现 P0–P2 问题,因此 Approve。
合并前请 rebase 到当前 main,解决 patches/README.md 的冲突,并确认新 head 的 CI 全绿。这属于合并状态处理,不阻塞本次 Approve。
有一个非阻塞的测试建议:反向移除依赖补丁后,该回归测试在一个环境中能稳定失败,但在另一个环境中多次通过。底层 fd 重用竞态和生产修复本身是成立的,不过测试夹具仍会受到调度和 fd 分配的影响。后续可以考虑强制重用准确的已退役 fd,或者将其称为压力回归测试,而不是确定性测试。
AI-assisted review disclosure: Codex assisted with source inspection and focused validation. I reviewed the evidence and own the conclusions and approval.
node-pty can leave async raw-fd writes queued after a Unix PTY exits, allowing descriptor reuse to redirect terminal input into unrelated files. Patch the dependency at its write-lifecycle boundary and add a deterministic exact-fd-reuse regression that fails against the unpatched package. Generated-by: Codex
00ca32f to
388910c
Compare
|
Addressed both points: the branch is rebased onto current All affected checks are green. The remaining unrelated Desktop E2E failure is tracked in #3044 and has a separate fix underway. We have decided to merge. |
Summary
Patch the node-pty Unix writer so queued PTY input cannot outlive its raw file descriptor and corrupt a subsequently opened file after fd reuse. Writes now use the already nonblocking descriptor synchronously, verify descriptor identity before retries, and stop at every exit or close fence.
Add an isolated deterministic regression that blocks the sole libuv worker, reopens a sentinel at the exact retired PTY fd, and proves that the unpatched queued write reaches that sentinel.
Fixes #2978
Verification
npm ci— patch-package reapplies[email protected]npm run build:testnpm run typechecknpm --workspace @maka/runtime test— 2,836 tests, 0 failuresnpm run lintnpm run format:checkReview focus
This is a temporary dependency patch for an upstream Unix lifecycle defect. Remove it when node-pty publishes an equivalent fix. This PR intentionally does not upgrade to beta.15 because that release does not modify the Unix write path.
Checklist
Does this PR entail a change in behavior?
AI disclosure: Codex prepared this draft with direction from M4n5ter; M4n5ter is the contributor of record and will review the result.