Skip to content

feat(runner): enable Windows task runtimes and isolated SSH - #882

Open
AaronWangCong wants to merge 4 commits into
Tencent:mainfrom
AaronWangCong:codex/windows-runner-runtime
Open

AaronWangCong wants to merge 4 commits into
Tencent:mainfrom
AaronWangCong:codex/windows-runner-runtime

Conversation

@AaronWangCong

@AaronWangCong AaronWangCong commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

What changed

Enables Windows Runner task execution with native CLI discovery, Git Bash shell nodes, managed asset snapshots, Windows-safe paths and approval hooks. Personal SSH keys stay in memory through an isolated Git-for-Windows transport; Linux Docker tasks get a separate short-lived in-container SSH agent for each command.

Part 2 of the Windows execution-machine work from #875. Depends on #881. The temporary comparison against main includes that foundation; after it merges this PR will be rebased so only the runtime changes remain. Installer/download delivery and full lifecycle CI stay in #875.

Windows disables automatic in-process Runner replacement even when explicitly requested; installer updates own that lifecycle. Active Docker commands also use a Runner-owned heartbeat lease, so cancellation and forced Runner exit reap their owned process tree. Successful script services remain available to subsequent nodes in the reused sandbox.

Scope

  • Platform core / API / runner
  • Shared behavior contract
  • Installer / CLI

Compatibility

Unix transports, symlink bindings and process-group behavior remain behind their existing platform adapters. Native Windows tasks own their complete process tree and stop remaining descendants when the root exits. With local authentication selected, Codex and Claude Code use the Runner account's existing CLI login; provider credential modes follow the task's selection. Linux images used from Windows need Python 3 at /usr/bin/python3 or /usr/local/bin/python3; personal container Git SSH also needs the OpenSSH client tools. The web interactive PTY continues to require a Unix execution machine.

Windows SSH transport

The full transport source uses Git for Windows' MSYS loopback protocol:

  • A random 128-bit cookie, checked in constant time, authorizes the connection. Client PID/UID/GID values are self-reported compatibility fields and are not an authorization identity.
  • A protected, inheritable DACL for the Runner's Windows SID is applied before the listener or cookie file is created. Earlier session files contain public configuration, known-host keys and public keys.
  • Each incomplete handshake has a five-second read/write deadline; shutdown closes the pending connection. A sustained local connection flood can still deny availability.
  • The session directory's parent must be trusted and private to the Runner account, as with the default per-user workspace/TEMP locations. An ancestor writable by another user permits namespace replacement and is outside this transport's trust boundary.

Validation

  • Windows and Linux runtime test-package compilation on this exact commit; native Windows Runner/Gate builds. Windows ARM64 and Darwin ARM64 Runner/Gate cross-builds passed and artifact headers confirm their architectures.

  • Focused Windows process, procwatch, Git SSH, runtime, Runner, preview and CLI tests.

  • Final runtime/Runner source: 896 Linux tests/subtests passed, including the unchanged default supervisor and actual Codex/Claude gateways; selected vet and public checks passed. The complete integration baseline also passed 4,906 Linux tests/subtests and full vet.

  • Latest compiled Windows Runner: all six live Docker acceptance groups passed in 204.92s, covering real Chromium, Gate/Codex tasks, SSH push and isolation, cancellation, normal services, failure cleanup and reconnect.

  • Forced Runner termination: actual script and pinned Codex tasks both reap their exact parent/child/grandchild identities with no delayed writes; completed unrelated services remain alive. The generic OpenCode provider path with OwnProcessGroup=false and byte-exact JSON stdin also passed.

  • Native Windows process, SSH, runtime and approval acceptance passed, including all nine actual pinned Codex policy cases in the delivery integration.

  • Standalone Windows runtime CI builds Runner/Gate, builds the embedded chatbot assets required by Runner test imports, then tests CLI, process/SSH, runtime, Runner and filesystem identity contracts and runs vet. Its build/test/vet commands also passed locally.

  • Public-content check, git diff --check and Gitleaks 8.30.1 pass on the runtime candidate.

  • Review the 72 runtime-only files in the stacked comparison. The temporary comparison against main contains 99 files including the foundation.

All 18 official checks passed on 176ac5d, including the independent Windows runtime job.

Safety

  • No credentials, internal endpoints, production data or private deployment files included.
  • User files and unrelated changes preserved.
  • No Classic generated bundles or copied third-party content involved.

@AaronWangCong
AaronWangCong force-pushed the codex/windows-runner-runtime branch from 6a3d63b to 176ac5d Compare November 15, 2026 05:37

@Yanami-2K Yanami-2K left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已核对可见部分:CI(含 Windows runtime contracts 和 Windows platform adapter contracts)全绿、无冲突;cmd/agentflow-runner 在 Windows 上强制关闭自动更新、restart_windows.go 在重启时 fail closed,符合描述;gitwork.StartSSHWithAgentFactory 保留了 StrictHostKeyChecking yes/IdentitiesOnly yes,会拒绝含换行或 NUL 的 socket,ssh_factory_test.go 断言私钥不会落到文件或环境变量。以下原因让我无法在本轮给出批准结论,需要维护者判断:

  1. 堆叠 PR 的审查时机:当前对比 main 的 99 个文件里有 28 个来自 #881(本轮已单独批准)。描述写了 #881 合入后会 rebase,建议先合 #881,等本 PR rebase 到只剩 72 个运行时文件后再做正式审查和批准,避免两个 PR 对同一批文件的修改出现偏差。
  2. 安全敏感的代码未能看全:工具未返回 internal/runtime/git_ssh_agent_windows.go(+231)、docker_process_lease.go(+171)、conversation_approval_windows.go(+137)、materialize_binding_windows.go(+172)、runner/daemon.go、runner/exec.go、sandbox_docker.go、sandbox_script_docker.go 等约 70 个文件的 patch,gitwork/ssh.go 和 ssh_transport_windows.go 也被截断。容器内 SSH agent、审批 hook、进程租约都涉及凭据和越权风险,建议由人逐行审。
  3. internal/gitwork/ssh_transport_windows.go 的 MSYS AF_LOCAL 模拟:agent 实际监听在 127.0.0.1 的 TCP 端口,本机所有用户都能连接,安全性完全依赖 socket 文件里的 16 字节 cookie 和目录 DACL。请在描述或注释里说明:(a) 握手阶段是否校验了 MSYS 协议中的对端 pid/uid/gid,或有意不校验;(b) cookie 文件在 SetNamedSecurityInfo 收紧目录权限之前是否可能被其他用户读到;(c) 握手未完成的连接(pending)有没有超时,防止本地进程占满连接。
  4. 行为变化需要确认:原生 Windows 任务在 root 退出后会杀掉整个 Job 里的后台进程,而 Docker 侧「成功的脚本服务对后续节点保持可用」,两套语义不同。引入自动化 SOP 时这是否可以接受、是否需要写进用户文档,需要维护者确认。

@Yanami-2K Yanami-2K left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

跟进上一轮的审查意见。这次仍然只留评论,不批准。

已确认的部分

  • 描述里新增的「Windows SSH transport」一节回答了上一轮的三个问题,和可见代码一致:
    • internal/gitwork/ssh_transport_windows.go 的 listenSSHAgent 先用 SetNamedSecurityInfo 给会话目录加上只允许 Runner 账号 SID 访问的受保护 DACL(D:P(A;OICI;FA;;;<SID>)),之后才监听 127.0.0.1:0 并写入 cookie 文件。
    • cookie 有 128 位,由 crypto/rand 生成;客户端的 PID/UID/GID 只是兼容字段,不作为身份凭据。
    • 握手有 5 秒读写超时,本地连接洪泛只影响可用性。描述里也写明了:会话目录的父目录必须是 Runner 私有目录,这是信任边界的前提。
  • StartSSHWithAgentFactory 校验了 factory 返回的 socket(拒绝空值、\r\n\x00、nil cleanup),失败时会清理目录。ssh_factory_test.go 断言了以下几点:私钥不会落盘、不会进入环境变量;身份去重;cleanup 幂等;配置保留 StrictHostKeyChecking yes 和 IdentitiesOnly yes。
  • 18 项 CI 全绿,包括 Windows runtime contracts 和 Windows platform adapter contracts。

仍未能核对、需要人工审查的部分

  1. 工具没有返回 diff 的文件约 70 个,这次仍然没看到,其中包括安全或并发敏感的实现:internal/runtime/git_ssh_agent_windows.go(+231,容器内 SSH agent)、conversation_approval_windows.go(+137,审批 hook)、docker_process_lease.go(+171,心跳租约和强制退出时回收进程)、materialize_binding_windows.go(+172)、internal/runner/daemon.go 和 exec.go。请维护者按描述里给的 stacked comparison 逐个过一遍这些文件,尤其要确认 agent 私钥只存在内存里,以及租约过期时只回收自己拥有的进程树。
  2. 和 main 对比,当前 diff 仍然包含 #881 的全部 28 个文件。按作者的计划,应先合入 #881,再把本 PR rebase 到只剩 runtime 改动,然后正式批准,避免同一批基础改动在两个 PR 里被分别审查。
  3. 可见部分有一处非阻塞建议:internal/processgroup/process_windows.go 的 Start 在根进程退出后立即调用 Kill(pid) 回收整个 Job。这和描述里的「Native Windows tasks ... stop remaining descendants when the root exits」一致,但和 Unix 行为不同:Unix 上后台子进程可以存活。建议在用户文档(Runner 的 Windows 说明)里明确写出这一点,避免脚本节点里 nohup/start 启动的服务被意外结束。

@Robert0622

Copy link
Copy Markdown
Collaborator

LoopForge PR Review Bot — reviewed commit 176ac5d144b5ff51d32454e446017faa4e19c314

Verdict: PASS ✅

What I checked

  • Diff: 99 files, +4501/-285 — Windows runner enablement (part 2 of feat(runner): deliver Windows execution machine lifecycle #875, depends on refactor(runtime): isolate process and filesystem platform adapters #881 which already passes).
  • go build -v ./internal/... ./cmd/... (linux/amd64) — OK
  • go vet ./internal/runtime/... — OK (no output)
  • Targeted tests covering this change — all PASS: TestHostBrowserEndpointPreservesWorkspace, TestOrphanBrowserProcessHelper, TestHookObservation, TestTerminalPoolScopes, plus the new workspace_lock_test.go / workspace_identity_test.go cases.
  • Also read through the two new cross-platform packages directly: internal/processgroup/{process_unix,process_windows}.go (Job-Object-based process-tree kill-on-close for Windows, Setpgid-based group kill for Unix) and internal/procwatch/{procwatch,group_unix,group_windows}.go (watchdog/stall/timeout wrapper used for long-running commands). The mutex-guarded job tracking, sync.Once cleanup, cmd.Cancel wiring and "reap job before cmd.Wait" ordering (so pipe readers see EOF) look correct — no race or leak found.
  • Cross-compile check for the touched code: GOOS=windows GOARCH=amd64 go vet ./internal/runtime/... ./internal/processgroup/... ./internal/procwatch/... — all clean.
  • GitHub checks: 18/18 green. mergeable_state: clean.

Note: this is static review + cross-compile vet for the Windows-only paths (sandbox here is Linux-only), not an execution test on a real Windows host. Flagging as informational only — no blocking defect found.

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.

4 participants