Repository navigation
refactor(runtime): isolate process and filesystem platform adapters - #881
AaronWangCong wants to merge 2 commits into
Conversation
Yanami-2K
left a comment
There was a problem hiding this comment.
Unix 侧核对过是等价重构:procwatch 的 Setpgid/Cancel 与 ErrWaitDelay 忽略整体移入 group_unix.go,flock、Nlink、Stat_t.Uid 的判断和错误路径都未变,EWOULDBLOCK 改用 errors.Is 也等价。问题集中在新增的 Windows 逻辑:
-
Windows 代码在 CI 中既不编译也不测试。本 PR 的目标是「让 Runner 能在 Windows 上编译」,但当前所有检查都跑在 ubuntu/macos 上,
internal/processgroup/process_windows.go、internal/procwatch/group_windows.go、internal/preview/archive_links_windows.go、internal/runtime/workspace_lock_windows.go、internal/httpapi/assistant_native_lock_windows.go以及对应的*_windows_test.go全部没有被 CI 编译或执行,只有描述里的本地结果。合入后任何人改动 Unix 签名都可能静默打碎 Windows 构建。建议至少在.github/workflows/platform.yml加一个windows-latest作业,跑go build ./cmd/...(Runner/Gate)和go test ./internal/processgroup ./internal/procwatch ./internal/preview ./internal/runtime -run 'Windows|Lock|Hardlink';不方便加 Windows runner 的话,最低要求是在 Linux 上跑GOOS=windows go vet和GOOS=windows go test -c覆盖这些包。 -
测试依赖「关闭句柄立即释放 LockFileEx」,在 Windows 上有间歇失败风险。
internal/runtime/workspace_lock_test.go末尾second.Close()后立刻断言workspaceInUse为 false,internal/httpapi/assistant_native_lock_test.go的second.Close()后立刻让子进程期望available。Windows 文档明确说关闭句柄时由系统解除锁,但时机取决于系统资源,不保证同步。建议测试里先显式unlock再Close,或者对「只关闭句柄」的断言加上有限重试;生产代码unlockFile已经是先解锁再关闭,不受影响。 -
与 #882 / 草稿 #875 的关系:三个 PR 含有同一套底层适配代码。保留本 PR 作为底层先合入是合理的,请在描述里写明合入后 #882 和 #875 会 rebase 去掉重复部分,避免三处各自修改同一段代码。
说明:internal/processgroup/process_windows.go(resumeInitialThread/Kill/Alive 部分)、process_windows_test.go、procwatch_windows_test.go 的 patch 被工具截断,这几段没有看全。
Yanami-2K
left a comment
There was a problem hiding this comment.
逐个核对了 Unix 侧是否「行为不变」:workspace_lock_unix.go/assistant_native_lock_unix.go 仍是 Flock(LOCK_EX|LOCK_NB),繁忙判断从 == 改为 errors.Is 等价,openAssistantNativeSession 失败时仍先 Close 再返回 errAssistantNativeBusy;procwatch/group_unix.go 仍设 Setpgid 和对进程组的 SIGKILL Cancel,并把原来在 Run 里对 exec.ErrWaitDelay 的忽略原样保留;preview 硬链接检查和 gitIndexLockHeldUnder 的 UID 读取只是搬到平台文件,判断条件不变。Windows 侧用 kill-on-close Job + 挂起启动后再入 Job,避免子进程逃逸;cleanup 先关 Job 再等 root 退出,不会死等;硬链接元数据读取失败时 fail closed,且有原生 Windows 测试(进程树取消、未托管进程不被误杀、长路径、元数据缺失),CI 含 Windows 作业全绿。作为 #882/#875 的前置抽象,动机成立,建议先合入。
非阻塞建议:
internal/runtime/git_index_lock_windows.go返回ok=false后,gitIndexLockHeldUnder报的是「index lock ... is not a regular file」,在 Windows 上文案会误导排查,建议对「平台无法确认属主」单独给出错误信息。.github/workflows/platform-adapters-windows.yml用正则从sandbox_process.go抽取声明、拷贝源文件到临时包里测试,源文件一旦重排就会失败。请在 #882 合入后尽快换成直接测试真实包。
|
LoopForge PR Review — head Verdict: ✅ Pass
|
What changed
Extracts process ownership, file locking, Git index ownership and preview hard-link checks into platform adapters, preserving Unix callers and providing the process, lock and file primitives used by the Windows Runner port in #882. Unix adapters keep the existing process-group, flock, inode and symlink behavior. Windows adapters use kill-on-close Job objects, LockFileEx and native file identity checks.
Part 1 of the Windows execution-machine work from #875. This foundation merges first. After it merges, #882 and #875 will rebase onto the official main branch to remove these shared changes from their comparisons. After #882 merges, #875 will rebase again to the delivery-only changes. Changes to the shared foundation land here and flow to the followers by rebase.
Scope
Compatibility
No database or deployment changes. Unix process execution and locking retain their current implementations. Windows Jobs own descendants until the root command exits. Windows runtime/Runner callers and their complete Windows builds follow in #882.
Validation
Linux amd64 and Darwin arm64 Runner/Gate builds; Linux runtime test-package compilation.
Native Windows process-group, procwatch, preview and lock regression tests.
On this exact commit, local Linux parity verification passed 208 tests/subtests across procwatch, Git SSH, previews, runtime locks/identity/index cancellation and HTTP native-file locks. Focused Linux vet checks passed.
python scripts/check-public.py,git diff --checkand Gitleaks 8.30.1 pass on this exact foundation.Windows CI runs the standalone process/procwatch/preview adapter packages and real lock/index source tests with minimal caller declarations. This isolates the foundation while the Windows runtime callers are introduced in feat(runner): enable Windows task runtimes and isolated SSH #882.
Both lock tests explicitly unlock before closing handles; repeated Windows and Linux checks verify contention and reacquisition.
Official CI also covers the existing platform, browser, coverage and E2E suites.
Safety