fix(whp): helper 防孤兒——Job Object + stdin-EOF 自我了結#126
Merged
Conversation
與 macOS vz 實機發現的同款問題(vz 修法在 claude/inspiring-chaum-208d84 分支 待合併):whp.rs spawn chefer-whp-helper 只 pipe stdout,runtime 的 Ctrl+C 處理 仰賴 helper 同 console 收到同一事件——對 runtime 單殺(taskkill /PID,非 console Ctrl+C)時 helper 收不到任何訊號,micro-VM 推測會殘留繼續執行(程式碼層面確認 無任何防護;無 Windows 實機,尚未實際重現)。 雙保險修法(DESIGN §6 whp 新增「Helper 生命週期」契約段): 1. Job Object:spawn 後把 helper 掛進 JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE 的 job 並故意洩漏 handle——runtime 無論怎麼死(taskkill /F、當機、正常結束) OS 都會關閉 handle → job 關閉 → helper 連同 VM 被系統終結。掛入失敗僅 警告,由 2. 後援。 2. stdin liveness(與 vz 同契約):runtime 以 piped stdin spawn 並 mem::forget 寫端讓 fd 隨行程存亡;helper boot 模式以專屬執行緒讀 stdin,EOF 即自我了結。 WHP guest console 無輸入路徑(serial 僅 TX),資料直接丟棄、無 vz 的 terminal stdin 泵送;--preflight/--gui-selftest(.output() 驅動、stdin 立即 EOF)不安裝監看。 測試:whp.rs 新增 KILL_ON_JOB_CLOSE 語意測試(dummy child,CI Windows runner 執行);whp-helper 新增 drain_until_eof 純邏輯測試(跨平台)。真 WHP VM 的 端到端孤兒化重現與修復驗證待實機(AGENTS.md Follow-ups)。 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…-d0486b # Conflicts: # AGENTS.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
問題
與 macOS vz 實機發現的同款孤兒化問題(vz 修法在
claude/inspiring-chaum-208d84分支待合併):whp.rsspawnchefer-whp-helper時只 pipe stdout,無 Job Object、無 stdin liveness。runtime 的 Ctrl+C 處理仰賴「helper 與 runtime 同 console、console 事件同時送達」,因此對 runtime 單殺(taskkill /PID <runtime>,非 console Ctrl+C)時 helper 收不到任何訊號,micro-VM 會殘留繼續執行。誠實標註:程式碼層面確認原本無任何防護;但手邊無 Windows 實機,孤兒化尚未實際重現,本修復是依 vz 實機重現過的同款機制推定。
修法(雙保險,DESIGN §6 whp 新增「Helper 生命週期」契約段)
whp.rs):spawn 後立刻把 helper 掛進JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE的 job 並故意洩漏 handle——runtime 無論怎麼死(taskkill /F、當機、正常結束)OS 都會關閉 handle → job 關閉 → helper 連同 VM 被系統終結。Windows 8+ 支援巢狀 job(runtime 已在別的 job 如 CI runner 也掛得進);掛入失敗僅警告,由 2. 後援。whp.rs+whp-helper/src/main.rs):runtime 以 piped stdin spawn 並mem::forget寫端讓 fd 隨行程存亡;helper boot 模式以專屬執行緒讀 stdin,EOF 即自我了結(VM 在行程內,exit 即拆)。與 vz 的差異:WHP guest console 無輸入路徑(serial 模擬僅 TX),讀到的資料直接丟棄、無 terminal stdin 泵送;--preflight/--gui-selftest由.output()驅動(stdin 立即 EOF),不安裝監看以免誤殺。兩機制皆不觸發 vdb data 回寫(M3 既有限制:僅 guest 乾淨關機回寫),與被 kill 的行為一致。
測試
whp.rs:kill_on_close_job_terminates_child_when_handle_closes——以長命 dummy child 鎖住 KILL_ON_JOB_CLOSE 語意(CI 的 Windows runner 執行,不需 WHP)。whp-helper:drain_until_eof_*兩則純邏輯測試(跨平台)鎖住「Interrupted 重試、資料丟棄、EOF/讀錯即返回」。cargo test全 workspace 通過;cargo check/clippy --target x86_64-pc-windows-msvc -p vmm-backend -p whp-helper --tests乾淨(Windows-only 程式碼含測試皆過編譯與 lint)。實機待驗項(無 Windows 實機,標註於 AGENTS.md Follow-ups)
CHEFER_BACKEND=whp跑 bundle →taskkill /F /PID <runtime>→ 確認chefer-whp-helper數秒內消失、無殘留。合併注意
vz 分支(
claude/inspiring-chaum-208d84)AGENTS.md 的「Windows whp-helper 疑有同款孤兒化問題」follow-up 由本 PR 解決,兩邊都合併時請刪除該項(AGENTS.md 的## Follow-ups區塊兩分支都有新增,預期有一個小衝突)。🤖 Generated with Claude Code