Repository navigation
Conversation
Windows allocates a visible conhost window for every console-subsystem child of a parent without a console, so the node, python and git helpers spawned throughout a goal start flash black windows on console-less hosts, and the detached usage observer intermittently surfaces ERROR_NO_DATA (0x800700E8) when its child exits before reading stdin. Add a shared no_console_creationflags() helper (CREATE_NO_WINDOW on Windows, 0 elsewhere) and apply it at the launch sites the CLI, goal/turn, quota and validation paths execute. Keep the detached observer's DETACHED_PROCESS | CREATE_NEW_PROCESS_GROUP flags and make its pipe-closed stdin write race non-fatal. TypeScript hosts that spawn python or loopx CLI children set windowsHide: true, matching the existing host_process and zcode_goal_mode precedent. Non-Windows behavior is byte-for-byte unchanged; the helper is imported lazily so cold import contracts stay cold. Fixes loopx-project#9430 Signed-off-by: Lihua <[email protected]>
loopx-agent
left a comment
There was a problem hiding this comment.
Reviewer: model_agent · gpt-6.2-sol · OpenAI · runtime_reported · xhigh
动机 / Motivation
Windows 无控制台宿主启动 Goal 时,短命的 Node、Python 和 Git 子进程会弹出控制台。Console-less startup 的验收包括回执。适用于已有 Windows CLI、Git 探测、Node 宿主、验证器、Python detached observer、Pi、NoKV 和 Research snapshot 子进程。
用户在附有控制台的 Windows PowerShell 或 cmd 中直接执行生成的 scheduler-ack-current 或 scheduler-fail-current。这个启动点无条件应用 CREATE_NO_WINDOW,也没有转发 stdout。Win32 由此去掉子进程继承的控制台,调度器写入 stdout 的回执可能从终端消失,父进程仍只接收退出码。
真实 macOS 子进程读取了完整 UTF-8 请求。子进程提前退出时,基线出现 BrokenPipeError,当前头安静返回。缺失程序在两侧均报告 FileNotFoundError,真实 Node 探测及 Usage Status 可用。 Windows 分支隔离夹具只证实了进程参数发生变化。Windows 控制台读回与闪窗实际表现仍需在 Windows 上执行。 问题 #9430
改动思路 / Approach
共享进程 transport 提供 Windows 创建标志。Node 侧使用现有 windowsHide 选项。Telemetry observer 保留脱离进程和 pipe 传输,单独处理提前关闭的 pipe。调度状态、校验、写入和持久回执由 TypeScript scheduler owner 处理。Python 与 Node 只改变创建子进程的 transport。
loopx.entrypoint.main → _native_scheduler_followup_argv → subprocess.call → heartbeat_followup_cli.ts。保留前台调度分支的控制台继承,仅在无控制台宿主使用抑制参数,或显式转发可读的 stdout/stderr。补一项 Windows 前台回执和无控制台重定向回执对照。
具体改动 / Changes
精确 head 83bbed0221d5722ab6344371cb1f4b5a36b2a5d3,分叉基线 b34f0e6157968251dedbd88552ccad34c4fdeef9。24 个文件,+601 / −9。生产改动复用按平台的创建参数并调用现有 transport。新增 482 行 Python 参数断言。
关键代码讲解
no_console_creationflags。Python 复用进程平台适配器,macOS 返回默认的 0。 源码entrypoint.main。原生调度入口等待子进程退出,发布回执依赖子进程的 stdout。 源码heartbeat_followup_cli.main。类型化调度结果和拒绝原因写入 stdout。 源码usage_ping._detach。保留现有进程分离和重定向,清理已断开的遥测输入。 源码NoKVJsonLinesTransport。默认 spawn 已使用显式 stdio pipe,现传入 windowsHide。 源码
对主干的风险 / Risks
[P2] 保留 Windows 前台调度命令的回执输出
用户在附有控制台的 Windows PowerShell 或 cmd 中直接执行生成的 scheduler-ack-current 或 scheduler-fail-current。当前入口用 subprocess.call(..., creationflags=CREATE_NO_WINDOW) 无条件启动 Node,既有 stdout 回执由 Node 直接写出。父进程只返回退出码。根据 Win32 创建标志和 CPython 的标准句柄设置规则,这会改变前台控制台继承,可能丢掉终端里的成功回执和拒绝原因。保留前台调度分支的控制台继承,仅在无控制台宿主使用抑制参数,或显式转发可读的 stdout/stderr。补一项 Windows 前台回执和无控制台重定向回执对照。 入口 · Win32 创建标志 · STARTUPINFO · CPython
语义与本地验证
Python 测试 600 项通过、8 项跳过,包含 56 项单独复跑的聚焦用例。TypeScript 测试 468 项通过。真实 CLI 在基线和当前 macOS 头均返回 invalid_scheduler_host_facts 和退出码 1。Windows emulation 仅记录到旧头无额外参数,当前头只有 CREATE_NO_WINDOW。 标准本地 premerge 的 18 项 smoke 有 1 项安装超时。该项在同一精确提交单独复跑通过,差异检查与编译也通过。 断管吞错分支在 macOS 同样生效,建议同步修正 PR 的平台影响说明。
我的整体评价 / Verdict
REQUEST_CHANGES。 建议保留后台节点抑制与遥测断管修复,补齐前台和无控制台两类 Windows 调度回执的 readback。
English verdict: REQUEST_CHANGES. Preserve the existing scheduler receipt on console-attached Windows launches while suppressing new consoles for the background launch path.
| return subprocess.call(native_argv) | ||
|
|
||
| from .extensions.process_runtime import no_console_creationflags | ||
| return subprocess.call(native_argv, creationflags=no_console_creationflags()) |
There was a problem hiding this comment.
[P2] 用户在附有控制台的 Windows PowerShell 或 cmd 中直接执行生成的 scheduler-ack-current 或 scheduler-fail-current。这个启动点无条件应用 CREATE_NO_WINDOW,也没有转发 stdout。Win32 由此去掉子进程继承的控制台,调度器写入 stdout 的回执可能从终端消失,父进程仍只接收退出码。保留前台调度分支的控制台继承,仅在无控制台宿主使用抑制参数,或显式转发可读的 stdout/stderr。补一项 Windows 前台回执和无控制台重定向回执对照。 Win32 进程创建语义
There was a problem hiding this comment.
Addressed on b35624d7b. The flag is no longer passed to an attached parent: no_console_creationflags() returns CREATE_NO_WINDOW only when the parent has no console, so the entrypoint.py:155 call keeps creationflags == 0 there and the scheduler child inherits the console its receipt is printed on. The fix, the host-agnostic tests, the unrun-on-Windows disclosure and a two-line check for both branches are in my comment above.
|
@/tmp/ci-attribution.md |
BigDataDZ
left a comment
There was a problem hiding this comment.
独立复核(native Windows 10,Python 3.12,Node 24.20)——未批准
精确核对 head:83bbed022,合并基点 b34f0e615。评审里"Windows 控制台读回与闪窗实际表现仍需在 Windows 上执行"这一项,我在真机上做了。
1. 抑制机制在真 Windows 上有效
父进程无控制台(GetConsoleWindow() 为 NULL,stdout 句柄为 NULL)时:
| 子进程启动方式 | 子进程是否拿到控制台 |
|---|---|
| 不加标志 | 拿到自己的新控制台(独立 HWND) |
CREATE_NO_WINDOW |
没有控制台 |
2. 前台回执丢失已实测确认,且是静默的(对应评审的 P2)
父进程附着在控制台上(即用户在 PowerShell / cmd 里执行)时,用 subprocess.call(argv) 与 subprocess.call(argv, creationflags=CREATE_NO_WINDOW) 各启动 Python 和 Node 子进程,不重定向标准流,然后读回控制台屏幕缓冲区:
| 子进程 / 启动方式 | 输出是否出现在控制台 | 子进程侧 |
|---|---|---|
| Python / 基线 | 是 | 写入成功 |
Python / CREATE_NO_WINDOW |
否(整个屏幕缓冲区里都没有,光标不动) | sys.stdout 非 None,print 与 os.write(1, …) 均返回成功 |
| Node / 基线 | 是 | 写入成功 |
Node / CREATE_NO_WINDOW |
否 | process.stdout.isTTY === true,console.log 与 fs.writeSync(1, …) 均返回成功 |
并在本 head 上直接调用真实的 loopx.entrypoint.main(quota scheduler-ack-current --scheduler-host-facts-chunk … --turn-instance-id …;基线通过让 no_console_creationflags 返回 0 来还原,与 main 的 subprocess.call(native_argv) 等价):
- 基线:终端上出现 9 行
loopx_scheduler_host_followup_error_v0JSON,退出码 1。 - 当前 head:终端上没有任何输出,只有退出码 1。
entrypoint.py:155 是本 PR 中唯一不重定向标准流的调用点(scheduler_ack.py 那处有 capture_output=True,不受影响)。复现只需在 PowerShell 里运行:
import subprocess, sys
child = "print('RECEIPT')"
subprocess.call([sys.executable, "-c", child]) # 打印 RECEIPT
subprocess.call([sys.executable, "-c", child], creationflags=subprocess.CREATE_NO_WINDOW) # 不打印任何内容修复方向:新控制台只在父进程没有控制台时才会被分配,所以这一处可以只在父进程无控制台时才加该标志;或者显式转发子进程的 stdout / stderr。实测数据支持前者:父进程有控制台且不加标志时,子进程共用父进程的控制台(同一 HWND),不产生新窗口,输出正常。我没有对打了补丁的变体做测试。
3. 本 PR 新增的测试在 native Windows 上失败
tests/test_child_console_suppression.py + tests/extensions/test_process_runtime.py → 55 passed / 28 skipped / 1 failed。失败的是 test_run_host_process_bridge_passes_no_console_creationflags:run_host_process 在 Windows 上会执行 WindowsHostJob.assign(proc)(读取 process._handle),而测试里的假 BridgeProcess 没有这个属性:
loopx\control_plane\turn_driver\windows_host_job.py:111: AttributeError: 'BridgeProcess' object has no attribute '_handle'
28 个 skipped 都是 POSIX 专用的进程组用例。
4. CI
6 个 test-shard 都不是干净的结论,需要分开看:
- 分片 1、2、3、5、6 撞到了 pytest 会话时限(
LOOPX_PYTEST_DEADLINE,约 3250 秒,exit 2),属未跑完。我没有确定时限超标是否与本 PR 有关。 - 在已跑完的用例里共有 11 个失败。其中
test_runtime_subprocess_utf8.py::test_shipped_runtime_pins_utf8_for_every_text_mode_subprocess_call我核实过:它在合并基点b34f0e615上就是红的(planning_batch._call当时没有encoding),main 已由 #9400 修好,rebase 后会消失,不是本 PR 引入。其余 10 个我没有归因。 - PR 下 11-25 12:28 的那条评论正文只有字面量
@/tmp/ci-attribution.md,看起来 CI 归因的文本没有被展开,没有发出来。
未验证
usage_ping._detach对0x800700E8断管竞态的处理。- 闪窗本身:我用"子进程是否获得控制台 / 窗口是否可见"作为可测的替代指标,并在实验中把窗口隐藏,没有观察真实的闪窗。
- 实验用的是经典 conhost 控制台(隐藏窗口,通过屏幕缓冲区读回);没有在 Windows Terminal / ConPTY 下验证。
- 没有 POSIX 运行。
在 2 和 3 处理完、且套件在该 head 上有完整结果之前,我不给批准。
|
This pull request has merge conflicts with Choose the remote for the base repository, not an out-of-date fork. git fetch upstream
git rebase upstream/main
# Resolve each conflict, git add the resolved files, then git rebase --continue.
git push --force-with-lease origin HEADFor a same-repository clone whose Keep the DCO |
|
@LIHUA919 Thanks for taking this on, and thanks @BigDataDZ for the native Windows readback. I checked the current GitHub refs: a local Could you include the foreground follow-up fix and the Windows bridge test fix in that update? The next native Windows pass should cover both launch modes: a parent without a console starts its child without a new window, and an attached terminal still receives the scheduler follow-up JSON and the child's exit status. Please also rerun the bridge test that failed when its test double lacked |
Bring the branch up to date before the review fix; all six files touched by both sides merged cleanly. Signed-off-by: Lihua <[email protected]>
The foreground follow-up (`loopx quota scheduler-ack-current`) launches the scheduler without redirecting its streams, so the scheduler's receipt is printed on the console the user is reading. On a parent attached to a console, CREATE_NO_WINDOW detaches the child from that console: the review measured the nine receipt lines vanish from PowerShell while every child write still reported success. Windows allocates a new console for a child only when the parent has none, so that is now the only case in which the flag is returned. A child of an attached process inherits its console and opens no window, and the helper reports 0, which leaves every spawn site exactly on its previous behavior. A host that cannot answer the console query counts as attached: the query only refines the options and must never break a spawn. Both outcomes now land on cells the review measured on Windows: attached without the flag keeps the receipt, console-less with the flag opens no window. Signed-off-by: Lihua <[email protected]>
|
Addressed on Thank you for running this on real Windows — the measurement settles the question, and the P2 is confirmed: the foreground follow-up at What changed
Both outcomes now land on cells you already measured: attached without the flag is your baseline (the child shares the parent's console HWND, no new window, output printed); console-less with the flag is your What I did not verifyI have not run this fix on Windows — I have no Windows host. The reasoning above rests on your two measured cells; the fix itself is untested on a real console. If you still have the Windows 10 machine, this checks both branches from one PowerShell prompt (the second line starts a detached child, i.e. a console-less parent): import subprocess, sys, loopx.extensions.process_runtime as pr
print("attached:", pr._parent_has_console(), pr.no_console_creationflags()) # expect True 0
code = ("import loopx.extensions.process_runtime as pr; "
"print('console-less:', pr._parent_has_console(), pr.no_console_creationflags())")
print(subprocess.run([sys.executable, "-c", code], capture_output=True, text=True,
creationflags=subprocess.DETACHED_PROCESS | 0x200).stdout.strip()) # expect False 134217728and your own Tests (host-agnostic, macOS)
Correction to my earlier CI noteMy previous comment attributed the red CI to two browser flakes only. That was incomplete — I had read the first lines of the check list. On |
Fixes #9430
Problem
On Windows,
loopxflashes black console windows while running, and the detached usage observer intermittently fails witherror 2147942632 (0x800700E8)(Win32 232,ERROR_NO_DATA, "The pipe is being closed") when launchingpython.exe -P -m loopx.usage_goal.Windows allocates a visible conhost window for every console-subsystem child (
node.exe,python.exe,git.exe) whose parent has no console. A single goal start from a console-less host (bootstrap, agent registration, requirement/todo writes, quota guards) runs dozens of such children. The0x800700E8failure is the detached-observer pipe race: a child that exits before reading (for example a suppressed observer) closes its stdin pipe first, and the parent's write then fails with ERROR_NO_DATA.Affected sites enumerated on current main
Reporter's v2.4.1 list, verified against this main:
loopx/control_plane/runtime/node_probe.pyprobe_nodeCREATE_NO_WINDOWvia shared helperloopx/control_plane/effect_runtime.py_start_runtimePopenCREATE_NO_WINDOWvia shared helperloopx/usage_ping.pycontrol()CREATE_NO_WINDOWvia shared helperloopx/usage_ping.py_detach()loopx.usage_goalDETACHED_PROCESS | CREATE_NEW_PROCESS_GROUP, no console); the stdin write/close is now tolerant of the child-closed pipe (the 0x800700E8 race)Cross-check additions in the same goal-start/turn/quota flow on current main:
loopx/registry.pyrun_git(todo/status readback probes)CREATE_NEW_PROCESS_GROUP | CREATE_NO_WINDOW(group flag kept for tree termination)loopx/control_plane/agents/workspace_guard.py(2 git probes, agent registration)CREATE_NO_WINDOWloopx/control_plane/todos/completion_validation.py_git_workspace_is_cleanCREATE_NO_WINDOWloopx/control_plane/goals/planning_batch.pyCliPlanningBatchBackend._callCREATE_NO_WINDOWloopx/control_plane/status/goal_source.py_runCREATE_NO_WINDOWloopx/control_plane/runtime/validation_command.py_direct_validationCREATE_NO_WINDOW(the supervised POSIX flock path is POSIX-only by design and untouched)loopx/control_plane/quota/scheduler_ack.py_run_native_followupCREATE_NO_WINDOWloopx/entrypoint.pyWindows native follow-up re-execCREATE_NO_WINDOW(Windows-only branch)loopx/control_plane/heartbeat/installed_prompt_update.pyprompt syncCREATE_NO_WINDOWloopx/control_plane/turn_driver/host_process_transport.pybridge PopenCREATE_NO_WINDOWloopx/control_plane/turn_driver/codex_stdio.pyStdioNativeGoalTransport.spawnCREATE_NO_WINDOWloopx/control_plane/turn_driver/command_validation.pyturn validatorCREATE_NO_WINDOWloopx/control_plane/turn_driver/codex_execution_preparation.py_default_runnerCREATE_NO_WINDOWloopx/control_plane/state_recovery_io.py_audit_ownersCREATE_NO_WINDOWTypeScript hosts that spawn console children and were missing the existing
windowsHideprecedent (host_process.ts,zcode_goal_mode/*,effect_runtime_snapshot.tsalready had it):loopx/pi_goal_mode/loopx-goal.ts(2execFilesites)windowsHide: trueloopx/control_plane/coordination/shadow_drain_files.tswindowsHide: trueloopx/control_plane/capabilities/explore_research_terminal.tswindowsHide: trueloopx/control_plane/coordination/nokv_jsonl_transport.tsdefault factorywindowsHide: trueImplementation
no_console_creationflags()inloopx/extensions/process_runtime.py: returnssubprocess.CREATE_NO_WINDOWonly on Windows and only when the parent has no console, which is the one case in which Windows allocates a new console for a child. It returns0(subprocess's default) for an attached parent, on every other platform, and when the console query cannot be answered. A child of an attached parent inherits its console and opens no window, so every site keeps exactly its previous behavior there; passing the flag to an attached parent would instead detach the child from the console its output is read on. Non-Windows behavior is byte-for-byte unchanged.GetConsoleCP()orGetConsoleWindow()succeeds (a console-less process fails both). Any success counting as attached is the safe direction — the only cost of a wrong "attached" is an unsuppressed window, never a lost receipt._PROCESS_RUNTIME_EXPORTSlazy reexport invalidation_command.py) so the repo's cold-import contracts (tests/test_process_runtime_loading.py:loopx.contract,loopx.doctor_git,validation_command,host_bridge_transportmust not load the process transport at import) keep holding._detach()keepsDETACHED_PROCESS | CREATE_NEW_PROCESS_GROUP(the observer is deliberately console-free) with fully redirected stdio (PIPE/DEVNULL/DEVNULL); the fix makes the parent's write-and-close non-fatal when the child wins the race, matching the documented best-effort telemetry contract.DETACHED_PROCESSandCREATE_NO_WINDOWare mutually exclusive creation flags; no site combines them.Windows-only default-behavior disclosure
The behavioral change is Windows-only, and on Windows it is confined to a console-less parent: children spawned by the listed sites no longer allocate a console host window there, and the detached observer's early-exit race no longer surfaces as an error. A parent attached to a console (a user running
loopxin PowerShell or cmd) and all other platforms passcreationflags=0/ omit the option, which is identical to the previous behavior.Windows verification status: the reviewer ran the previous head on a real Windows 10 host and measured that the suppression works (the child gets no console) and that the flag, applied unconditionally, silently removed the foreground receipt of the one site that does not redirect its streams (
loopx/entrypoint.py:155). That finding is what the attached-parent rule above fixes. The fix itself has not been run on Windows — I have no Windows host. It rests on the reviewer's two measured cells (attached without the flag keeps the receipt; console-less with the flag opens no window); a two-line check for both branches is in the review reply. The visible window and pipe behavior is otherwise owned by CI's Windows lanes; the host-agnostic tests below prove the flags are computed and passed on the spawn-option objects.Out of scope (follow-up candidates using the same helper)
Dev/CI tooling (
loopx/canary/**,loopx/control_plane/testing/**,benchmark_toolkit,experiments), capability adapters wrapping interactive external CLIs, MCP/collaboration daemon spawns (operation_wake,collaboration_mcp,remote_authority_gateway,delegation_preview_transport), SSH lifecycle transports, self-update/installer flows (already detached where relevant), andstdio_transport.py(POSIX-only by design).Test evidence (all on macOS)
tests/test_child_console_suppression.py(30 tests): each site's spawn options (creationflags equals the helper value on POSIX; equalsCREATE_NO_WINDOWunder an emulated Windowsos.nameon a console-less parent, via a module-scoped proxy that also answers the console query), the registry's composedCREATE_NEW_PROCESS_GROUP | CREATE_NO_WINDOW, the detached observer's Windows flags, and the pipe-closed write race staying non-fatal. Added for the attached-parent rule: the helper across three hosts (POSIX → 0, Windows console-less →CREATE_NO_WINDOW, Windows attached → 0); the_console_attachedtruth table (both queries failing → not attached, either succeeding → attached); the reported site with an attached parent passingcreationflags == 0and redirecting nothing, and with a console-less parent passing the flag; a redirected receipt on a console-less host still arriving throughcapture_output=True.tests/extensions/test_process_runtime.py: helper computation (0 off Windows,0x08000000emulated on a console-less parent, 0 without the constant, 0 on an attached parent, 0 and no exception when the console query is unanswerable).npm run typecheck:control-planeclean; node test suites for the touched TS modules (nokv transport, shadow drain, explore research execution): 421 passed.loopx/pi_goal_mode/loopx-goal.tsis outside the repo's tsconfig (host-provided dependencies); a direct tsc comparison shows the identical pre-existing error set before/after, i.e. no new type errors.ruff checkon all touched files: clean.811c1a1f6(74a33c350; all six files touched by both sides merged cleanly): the two test files above 95 passed / 1 skipped; the 51 test files of every touched module 1355 passed / 0 failed / 8 skipped (twotest_effect_runtime_equivalence.pycases first failed only because this worktree's localorigin/mainref was eight days stale — they loadorigin/main:…effect_runtime.pyas their baseline and pass 10/10 once the ref is refreshed;_uses_stdio_runtimecomes from main's feat(control-plane): allow the CLI Effect runtime to use stdio in restricted hosts #9140, not from this PR).uv run --extra test loopx canary premerge --from-git-diff --git-diff-base 811c1a1f6: 18 checks passed, 0 failures.tests/control_plane/test_native_user_completion_update.py(12 parametrizations, HTTP 404s) fail identically on pristinemainat the merge base (verified in a throwaway worktree).