Skip to content

Suppress Windows console windows for console-subsystem children (#9430) - #9435

Open
LIHUA919 wants to merge 6 commits into
loopx-project:mainfrom
LIHUA919:codex/win-console-no-window-9430
Open

LIHUA919 wants to merge 6 commits into
loopx-project:mainfrom
LIHUA919:codex/win-console-no-window-9430

Conversation

@LIHUA919

@LIHUA919 LIHUA919 commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #9430

Problem

On Windows, loopx flashes black console windows while running, and the detached usage observer intermittently fails with error 2147942632 (0x800700E8) (Win32 232, ERROR_NO_DATA, "The pipe is being closed") when launching python.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. The 0x800700E8 failure 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:

Site Child Change
loopx/control_plane/runtime/node_probe.py probe_node node CREATE_NO_WINDOW via shared helper
loopx/control_plane/effect_runtime.py _start_runtime Popen node (long-lived runtime host) CREATE_NO_WINDOW via shared helper
loopx/usage_ping.py control() node CREATE_NO_WINDOW via shared helper
loopx/usage_ping.py _detach() node / loopx.usage_goal Flags already correct (DETACHED_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:

Site Child Change
loopx/registry.py run_git (todo/status readback probes) git 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) git CREATE_NO_WINDOW
loopx/control_plane/todos/completion_validation.py _git_workspace_is_clean git CREATE_NO_WINDOW
loopx/control_plane/goals/planning_batch.py CliPlanningBatchBackend._call loopx CLI CREATE_NO_WINDOW
loopx/control_plane/status/goal_source.py _run declared source command / ssh CREATE_NO_WINDOW
loopx/control_plane/runtime/validation_command.py _direct_validation caller-declared validator CREATE_NO_WINDOW (the supervised POSIX flock path is POSIX-only by design and untouched)
loopx/control_plane/quota/scheduler_ack.py _run_native_followup node (heartbeat follow-up) CREATE_NO_WINDOW
loopx/entrypoint.py Windows native follow-up re-exec node CREATE_NO_WINDOW (Windows-only branch)
loopx/control_plane/heartbeat/installed_prompt_update.py prompt sync loopx CLI CREATE_NO_WINDOW
loopx/control_plane/turn_driver/host_process_transport.py bridge Popen node CREATE_NO_WINDOW
loopx/control_plane/turn_driver/codex_stdio.py StdioNativeGoalTransport.spawn host process CREATE_NO_WINDOW
loopx/control_plane/turn_driver/command_validation.py turn validator validator command CREATE_NO_WINDOW
loopx/control_plane/turn_driver/codex_execution_preparation.py _default_runner launcher CREATE_NO_WINDOW
loopx/control_plane/state_recovery_io.py _audit_owners node recovery worker CREATE_NO_WINDOW

TypeScript hosts that spawn console children and were missing the existing windowsHide precedent (host_process.ts, zcode_goal_mode/*, effect_runtime_snapshot.ts already had it):

Site Child Change
loopx/pi_goal_mode/loopx-goal.ts (2 execFile sites) loopx CLI windowsHide: true
loopx/control_plane/coordination/shadow_drain_files.ts python shadow-lock host windowsHide: true
loopx/control_plane/capabilities/explore_research_terminal.ts python snapshot host windowsHide: true
loopx/control_plane/coordination/nokv_jsonl_transport.ts default factory NoKV helper windowsHide: true

Implementation

  • One shared helper no_console_creationflags() in loopx/extensions/process_runtime.py: returns subprocess.CREATE_NO_WINDOW only 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 returns 0 (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.
  • Console query: the parent counts as attached when either GetConsoleCP() or GetConsoleWindow() 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.
  • The helper is imported lazily at each call site (in-function or via the existing _PROCESS_RUNTIME_EXPORTS lazy reexport in validation_command.py) so the repo's cold-import contracts (tests/test_process_runtime_loading.py: loopx.contract, loopx.doctor_git, validation_command, host_bridge_transport must not load the process transport at import) keep holding.
  • _detach() keeps DETACHED_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. This one change is not Windows-only: on POSIX the same early child exit previously surfaced as BrokenPipeError from the write-and-close; it now returns normally (verified with real child processes on macOS: normal reads pass before and after; an early-closing child raised on the previous behavior and returns cleanly now).
  • DETACHED_PROCESS and CREATE_NO_WINDOW are mutually exclusive creation flags; no site combines them.

Windows-only default-behavior disclosure

The console-suppression change is Windows-only, and on Windows it is confined to a console-less parent (apart from the _detach() write-and-close behavior above, which applies everywhere): 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 loopx in PowerShell or cmd) and all other platforms pass creationflags=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), and stdio_transport.py (POSIX-only by design).

Test evidence (all on macOS)

  • New tests/test_child_console_suppression.py (30 tests): each site's spawn options (creationflags equals the helper value on POSIX; equals CREATE_NO_WINDOW under an emulated Windows os.name on a console-less parent, via a module-scoped proxy that also answers the console query), the registry's composed CREATE_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_attached truth table (both queries failing → not attached, either succeeding → attached); the reported site with an attached parent passing creationflags == 0 and redirecting nothing, and with a console-less parent passing the flag; a redirected receipt on a console-less host still arriving through capture_output=True.
  • tests/extensions/test_process_runtime.py: helper computation (0 off Windows, 0x08000000 emulated on a console-less parent, 0 without the constant, 0 on an attached parent, 0 and no exception when the console query is unanswerable).
  • Touched-module suites: 1143 passed / 0 failed across usage_ping/usage_goal, registry, effect_runtime node probe, scheduler_ack, completion validation (4 files + MCP), planning batch, goal source, execution preparation, workspace guard, state recovery, leased host process, host launch authority, process runtime (4 files), entrypoint and core distribution contract tests.
  • TypeScript: npm run typecheck:control-plane clean; node test suites for the touched TS modules (nokv transport, shadow drain, explore research execution): 421 passed. loopx/pi_goal_mode/loopx-goal.ts is 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 check on all touched files: clean.
  • After merging current main 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 (two test_effect_runtime_equivalence.py cases first failed only because this worktree's local origin/main ref was eight days stale — they load origin/main:…effect_runtime.py as their baseline and pass 10/10 once the ref is refreshed; _uses_stdio_runtime comes 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.
  • Pre-existing failures unrelated to this change: tests/control_plane/test_native_user_completion_update.py (12 parametrizations, HTTP 404s) fail identically on pristine main at the merge base (verified in a throwaway worktree).

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 <1017343802@qq.com>

@loopx-agent loopx-agent 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.

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.

Comment thread loopx/entrypoint.py
return subprocess.call(native_argv)

from .extensions.process_runtime import no_console_creationflags
return subprocess.call(native_argv, creationflags=no_console_creationflags())

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.

[P2] 用户在附有控制台的 Windows PowerShell 或 cmd 中直接执行生成的 scheduler-ack-current 或 scheduler-fail-current。这个启动点无条件应用 CREATE_NO_WINDOW,也没有转发 stdout。Win32 由此去掉子进程继承的控制台,调度器写入 stdout 的回执可能从终端消失,父进程仍只接收退出码。保留前台调度分支的控制台继承,仅在无控制台宿主使用抑制参数,或显式转发可读的 stdout/stderr。补一项 Windows 前台回执和无控制台重定向回执对照。 Win32 进程创建语义

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

@LIHUA919

Copy link
Copy Markdown
Contributor Author

@/tmp/ci-attribution.md

@BigDataDZ BigDataDZ left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

独立复核(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_v0 JSON,退出码 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 上有完整结果之前,我不给批准。

@mergify

mergify Bot commented Nov 27, 2026

Copy link
Copy Markdown

This pull request has merge conflicts with main and cannot be merged
until they are resolved. Please rebase or merge the base branch, @LIHUA919.

Choose the remote for the base repository, not an out-of-date fork.
For a fork clone, first inspect git remote -v; upstream must point
to https://github.com/loopx-project/loopx.git. If it is absent, add it
with git remote add upstream https://github.com/loopx-project/loopx.git.
Then run:

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 HEAD

For a same-repository clone whose origin points to
https://github.com/loopx-project/loopx.git, use origin instead of
upstream for fetch/rebase. If you prefer merging the base, use
git merge <base-remote>/main and push normally.

Keep the DCO Signed-off-by trailer on every commit when you rebase.
https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

@mergify mergify Bot added the needs-rebase Mergify: the pull request has merge conflicts with its base branch label Nov 27, 2026
@loopx-agent

Copy link
Copy Markdown
Collaborator

@LIHUA919 Thanks for taking this on, and thanks @BigDataDZ for the native Windows readback. I checked the current GitHub refs: a local git merge-tree --write-tree of main at 63c7c487 and the PR head at 83bbed02 completed cleanly, with the Pi change carried into the relocated loopx/hosts/pi/loopx-goal.ts. GitHub still reports a conflict. Merging the current upstream main into your PR branch looks like a viable way to refresh it while preserving your commits. Please confirm GitHub's status on the updated head.

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 _handle. These are the concrete follow-ups to the Windows 10 results. If the updated head leaves the detached-observer pipe case or Windows Terminal/ConPTY untested, please call that out in the PR.

Bring the branch up to date before the review fix; all six files touched by both sides merged cleanly.

Signed-off-by: Lihua <1017343802@qq.com>
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 <1017343802@qq.com>
@mergify mergify Bot removed the needs-rebase Mergify: the pull request has merge conflicts with its base branch label Nov 28, 2026
@LIHUA919

Copy link
Copy Markdown
Contributor Author

Addressed on b35624d7b (one DCO-signed commit on top of 74a33c350, a signed merge of current main 811c1a1f6; the six files touched by both sides merged cleanly, so the stale CONFLICTING label is gone).

Thank you for running this on real Windows — the measurement settles the question, and the P2 is confirmed: the foreground follow-up at entrypoint.py:155 lost its receipt on an attached parent.

What changed

no_console_creationflags() now returns CREATE_NO_WINDOW only when the parent has no console. Your measurement gives the rule: Windows allocates a new console for a child only in that case. A child of an attached process inherits its console and opens no window, and there the helper returns 0 — so the child keeps the console its receipt is read on. This is done in the helper rather than at the single site: on an attached parent every Python site is now exactly on its previous behavior, and the PR's behavior change is confined to the console-less host the issue reports. A future site that forgets to redirect its streams is safe the same way.

  • Console query: attached when either GetConsoleCP() or GetConsoleWindow() 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.
  • Unanswerable query: if the query itself cannot run (ctypes unavailable), the host counts as attached and the helper returns 0. The query only refines the options and must never break a spawn. The existing helper tests caught this: under an emulated Windows name with no console query provided, the first version raised instead of returning.
  • TypeScript sites: all five talk to their child through pipes (stdio: "pipe" / execFile capture), consistent with your finding that entrypoint.py:155 is the only site that does not redirect.

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 CREATE_NO_WINDOW row (no console).

What I did not verify

I 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 134217728

and your own loopx.entrypoint.main call for scheduler-ack-current in PowerShell should print the nine loopx_scheduler_host_followup_error_v0 lines again.

Tests (host-agnostic, macOS)

  • Helper, three hosts parameterized: POSIX → 0; Windows console-less → CREATE_NO_WINDOW; Windows attached → 0.
  • _console_attached truth table: both queries failing → not attached; either succeeding → attached.
  • The reported site: attached parent → the entrypoint.py:155 call passes creationflags == 0 and redirects nothing; console-less parent → CREATE_NO_WINDOW.
  • Redirected receipt on a console-less host: usage_ping.control() passes the flag and capture_output=True, so the pipe still carries the reply.
  • Unanswerable console query (ctypes unavailable) → 0, no exception.
  • tests/test_child_console_suppression.py + tests/extensions/test_process_runtime.py: 95 passed / 1 skipped (96 collected).
  • Touched-module suites after the main merge (51 files): 1355 passed / 0 failed / 8 skipped. Two test_effect_runtime_equivalence.py cases first failed only because this worktree's local origin/main ref was eight days stale — they load origin/main:…effect_runtime.py as their baseline — and pass 10/10 once the ref is refreshed.
  • loopx canary premerge --from-git-diff --git-diff-base 811c1a1f6: 18 checks passed, 0 failures.

Correction to my earlier CI note

My 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 83bbed022 the six Python test-shard jobs were red too. Their logs show no failing assertion: shard 1 ended 3758 passed, 189 skipped … in 3253.12s against a session_deadline of 3251.7s, i.e. a budget overrun of about a second with every case finished. It is not caused by this change: on Linux the helper returns 0 before any console query, and main's own last three Python Tests runs are red the same way and worse (shard 1 on main run 46099466649: 4 failed, 4449 passed, interrupted at the deadline with 4632 of 7308 cases finished). I still cannot rerun jobs (fork PR, admin needed).

@loopx-agent loopx-agent 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.

Reviewer: model_agent · gpt-6.2-sol · OpenAI · runtime_reported · xhigh

动机 / Motivation

无控制台的 Windows 宿主启动大量短命子进程时会闪现控制台窗口。附着在控制台的用户仍要在前台收到 scheduler follow-up 的 JSON 和退出码。前一提交的真机结果已确认,在附着父进程上强加 CREATE_NO_WINDOW 会静默丢失回执。此轮核对修复是否保留这条回执,以及此前失败的 Windows bridge 测试是否已修好。原问题 · 上次 Windows 10 实测 · 仓库真实入口验证规则

改动思路 / Approach

把是否添加 CREATE_NO_WINDOW 留在 Python 共同的进程适配器。附着或无法回答的父进程传零,确认无控制台才启用该标志。Node 的管道调用点使用 windowsHide,保留原 stdio 配置。既有 Windows Job 仍负责把 bridge 纳入监管,测试夹具也需要保留这个独立边界。Win32 进程创建标志 · Windows 控制台句柄

具体改动 / Changes

关键代码讲解

验收项包括 WIN-CONSOLE-LESS、WIN-ATTACHED-RECEIPT、WIN-BRIDGE-TEST。

  • no_console_creationflags 通过 GetConsoleCP 和 GetConsoleWindow 判断是否附着,entrypoint.main 等待 Node 并返回状态。macOS 在基线与当前提交都经实际入口返回相同的 invalid_scheduler_host_facts JSON 和退出码 1。两种 Windows 参数分支由单测覆盖,当前提交的真实 Windows 回执和无控制台启动待复验。
  • run_host_process 在 Windows 会先把子进程加入 Job,再发送请求。以桩提供成功的 Win32 内核调用,在 macOS 执行当前测试的 Windows 分支,复现 BridgeProcess 缺少 _handle。实际失败发生在 Python 尝试读取句柄时,尚未调用 Win32 的 AssignProcessToJobObject。
  • usage_ping._detach 将早退的写入或关闭失败降为 best effort。我在 macOS 用实际子进程复验,正常读取前后均成功,提前关闭时基线抛 BrokenPipeError,当前提交正常返回。这个变化也适用于 POSIX,建议同步修正 PR 正文的 Windows-only 说明。

对主干的风险 / Risks

P2 先前的 Windows bridge 测试失败仍可复现。 当前夹具替换了 Popen,但未处理 WindowsHostJob.assign 所需的真实进程句柄。应在这项 spawn-options 单测里替换 Job I/O 边界并断言 assign 调用,或使用真实子进程。保留生产 Job 监管,再在当前提交的 Windows 上运行该用例与两种父进程形态的真实 CLI,核对 JSON 和退出码。触发点见测试夹具和实际 Job 分配。

语义与 CI 对齐

127 个目标 Python 测试通过、1 个跳过,429 个 Node 测试通过,Git diff 检查通过。上述 Win32 桩只复现当前夹具的失败,真机表现仍待核对。Windows Terminal / ConPTY 与实际 Win32 232 的断管路径也未验证。项目设置使用本地检查,远端 CI 留待仓库流程。

我的整体评价 / Verdict

保留变更请求。附着控制台的参数修正与已知真机结果吻合。当前提交仍保留原来会在 Windows 失败的夹具,且新提交还需要两种启动形态的真机读回。

English verdict: REQUEST_CHANGES at b35624d. The Windows bridge test still supplies a process without the required handle. Fix the fixture and verify both console modes through the native CLI on Windows.

… fixture

The spawn-options test only exercised the POSIX launch branch; on the
Windows branch run_host_process assigns the spawned process to a Host Job
before writing any request, and assign reads the Popen handle the stub
process never carried. Add a companion test that takes the real Windows
branch on any host: the Job boundary is replaced (its module cannot load
off Windows), the fixture process carries the handle assign reads, and
the test asserts the assignment happened for this process alongside the
console-less creation flags.

Signed-off-by: Lihua <1017343802@qq.com>
@LIHUA919

Copy link
Copy Markdown
Contributor Author

Addressed on d0ceb5536 (one DCO-signed commit on top of b35624d7b).

WIN-BRIDGE-TEST — the fixture now runs the real Windows branch. Your reproduction was right: the old stub replaced Popen but carried no _handle, so on the Windows branch WindowsHostJob.assign would fail reading it before any Win32 call. The new companion test takes the production Windows branch on any host: sys.platform is patched to win32 (the if sys.platform == "win32": launch guard in run_host_process is what selects it), the Job boundary is replaced with a recording stand-in injected into sys.modules — the real module cannot even load off Windows, its module-level ctypes.WinDLL is the first thing to raise — and the fixture process now carries the handle assign reads. The test asserts the assignment happened for this process and that the console-less CREATE_NO_WINDOW reached the spawn options. Red-green: against the old fixture the assign assertion fails on the missing handle; the production Job containment is untouched. Both files: 96 passed / 1 skipped.

Disclosure corrected in the PR body — thank you for catching that _detach()'s best-effort write-and-close is not Windows-only: on POSIX the early child exit previously raised BrokenPipeError and now returns normally. The body now says this explicitly (and matches your macOS re-verification with real children) instead of claiming the whole diff is Windows-only.

WIN-ATTACHED-RECEIPT / WIN-CONSOLE-LESS — I cannot run these. I have no Windows host, so the two real-machine readbacks remain with whoever has one; the two-line check for both parent-console branches from my previous comment still stands, and your entrypoint.main scheduler-followup invocation in PowerShell is exactly the attached-receipt oracle. What I can attest on this host: the attached-parent parameterization keeps entrypoint.py:155 at creationflags == 0 with no stream redirection, the console-less host passes the flag, and the helper never lets an unanswerable console query break a spawn.

loopx canary premerge --from-git-diff against 811c1a1f6: 18 checks passed, 0 failures.

@LIHUA919

Copy link
Copy Markdown
Contributor Author

Correction to my CI note above — please read this one instead. My statement that the shards showed "no failing assertion" and finished "every case" was wrong; I had read only shard 1's summary line. The full picture on 83bbed022:

  • Five of the six Python test-shard jobs were interrupted at the session deadline with most of their cases never executed — each shard was assigned ~7082 cases and finished between 3852 and 6897 (LOOPX_PYTEST_DEADLINE, exit 2). Only shard 4 ran to completion.
  • Across the six shards there were 11 failing assertions in total, and I have attributed every one of them below. None traces to this PR's diff:
    • test_runtime_subprocess_utf8 (shard 4): flags planning_batch.py:706 — that call already lacked encoding="utf-8" on this PR's base (b34f0e615, line 704); the PR's two added lines only moved the line number. Current main has since fixed it in that file and introduced a new violation of its own (hosts/agy/__init__.py:581), which is why the guard is red on pristine 811c1a1f6 locally as well.
    • test_stride_comparison_followthrough_cli, test_connected_adapter_status_vocabulary_owner, test_research_execution_loop, test_long_chain_projected_closeout: fail identically on pristine main — reproduced locally on both main and this branch with the same outcomes, and visible in main's own CI runs (e.g. run 46099466649).
    • test_native_accounts_install (shard 5): CI log shows AssertionError: Source-checkout validation requires uv — the runner's PATH lacks uv; environmental. Passes locally.
    • test_integration_branch (shard 5): the fixture's own git commit in a temp repo exits 128 on the runner — it never goes through any LoopX spawn site. Passes locally on both trees.
    • test_dashboard_command (shard 4): passes locally on the merged head.
  • The deadline interruption itself is not PR-specific either: main's own latest Python Tests runs are red the same way and worse (latest: all six shards interrupted, 4 failing assertions, e.g. 4632/7308 cases finished in shard 1). This looks like a main-side CI-budget regression worth its own issue — I will file one separately.

Practical consequence I want to state plainly: CI has not executed the majority of Python cases for this PR on either head, so local validation is the primary Python evidence: the two console-suppression files (96 passed / 1 skipped), the 51 touched-module test files (1355 passed / 0 failed / 8 skipped), the tests/architecture static-guard suite (running now, will report), and canary premerge 18/18.

@loopx-agent loopx-agent 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.

Reviewer: model_agent · gpt-6.2-sol · OpenAI · runtime_reported · xhigh

动机 / Motivation

无控制台的 Windows 宿主需要抑制子进程闪窗,附着到终端的用户仍需看到调度回执。上一轮确认现有 bridge 测试替换了真实子进程,却未提供 Windows Job 要读取的句柄。当前提交增加了模拟 Windows 分支的正向用例。旧用例仍会随测试集运行,并保留原来的失败。前次评审 · 旧头 Windows 10 观察

改动思路 / Approach

保留已有的根据父进程控制台状态选择创建标志。新测试在 Windows Job I/O 边界使用可观察的替身,确认 Job 收到被启动的 bridge。这个覆盖可以保留,原通用测试也需要在原生 Windows 走相同的可替换边界。

具体改动 / Changes

前一头 b35624d7b332760a588f20737a5d49992aaea5be 到现头只增加一个测试。相对基线 811c1a1f66652d3fc3b9830d467e14b45b7423c1,24 文件 +841/-9。核对 WIN-BRIDGE-TEST、WIN-ATTACHED-RECEIPT 和 WIN-CONSOLE-LESS。仓库真实入口验证规则

关键代码讲解

  • no_console_creationflags 在确认 Windows 父进程没有控制台时传标志,在已附着或查询不可用时传零。macOS 上现头的真实调度入口与基线同样输出 invalid_scheduler_host_facts JSON,并退出 1,隔离测试目录无写入。
  • 新的 test_run_host_process_bridge_windows_branch_assigns_job_and_passes_flag 给测试进程提供 _handle,同时替换 Job I/O,观察一次分配以及 console-less 启动参数。此测试通过。
  • 原来的 test_run_host_process_bridge_passes_no_console_creationflags 继续替换 Popen,并照常在 Windows 进入真实 WindowsHostJob.assign。该夹具没有句柄,也无 Windows 跳过条件或 Job 替换。

对主干的风险 / Risks

P2 原 bridge 测试继续产生同一 Windows 失败。 我对现头执行原用例,仅让其选择 Windows 平台分支,并用成功的 Win32 内核桩替换系统调用。代码在 Python 读取 BridgeProcess._handle 时抛出 AttributeError,还未调用 AssignProcessToJobObject。请统一两个 fixture 的 Job 隔离,或把旧用例明确限制在 POSIX,保留新的 Windows 分支用例。真实 Windows 上一次性复验这两个用例和两种启动形态。仍在执行的旧用例 · 新用例

语义与 CI 对齐

128 个目标 Python 测试通过、1 个跳过,429 个 Node 测试及 Git 差异检查通过。POSIX 早退断管现在正常返回,PR 正文已披露该跨平台变化。上次真实 Windows 测量对应旧提交,当前提交附着与无控制台入口的真机观察仍待完成。Windows Terminal / ConPTY 和 Win32 232 的实际断管也未验证。远端 CI 留待仓库流程。

我的整体评价 / Verdict

保留变更请求。新增测试验证了预期的 Job 分配和子进程参数。原用例依旧在 Windows 分支失败,需要修正原夹具并读回当前提交的真实控制台回执。

English verdict: REQUEST_CHANGES at d0ceb55. The new Windows companion test passes, but the original bridge test still supplies no process handle to WindowsHostJob.assign.

The original spawn-options test was left without a process handle or a
Job boundary, so on a real Windows host running the suite it would enter
WindowsHostJob.assign and fail reading the stub's missing handle — the
companion test covered that branch, but only for itself. Unify the two
fixtures: a shared handle-carrying bridge process and a shared recording
Job stand-in (the real module cannot load off Windows). The original test
installs the stand-in alongside its POSIX assertions — dormant wherever
the Windows branch is not selected — and the companion test selects the
Windows branch and asserts the assignment through the same boundary.

Signed-off-by: Lihua <1017343802@qq.com>
@LIHUA919

Copy link
Copy Markdown
Contributor Author

Addressed on 89b2ee479 (one DCO-signed commit on top of d0ceb5536).

The two fixtures are unified — you were right that adding the companion left the original test failing on a real Windows host. Both bridge tests now share one fixture: a handle-carrying bridge process (the _handle assign reads) and one recording Job stand-in injected into sys.modules (the real module cannot load off Windows).

  • The original test installs the stand-in alongside its existing POSIX assertions. Wherever the Windows branch is not selected the stand-in stays dormant and the test is unchanged in what it proves; on a real Windows host the launch now assigns through the recording boundary instead of crashing on the missing handle.
  • The companion test is the same fixture plus sys.platform = "win32" — it is now literally the original test forced onto the Windows branch, which is how you reproduced the failure, and it asserts the assignment happened for this process alongside the console-less flag.

So the suite is correct on any host: on POSIX both tests exercise the launch path they can reach; on Windows both route the Job assignment through the observable boundary, and neither stub process lacks the handle. Both files: 96 passed / 1 skipped on this host.

WIN-ATTACHED-RECEIPT / WIN-CONSOLE-LESS remain with a Windows host — unchanged from my previous reply: I have none, the two-line both-branches check and the PowerShell scheduler-ack-current receipt oracle are there for whoever runs it, and I state plainly that the current head's real-console behavior has not been observed by me.

loopx canary premerge --from-git-diff against 811c1a1f6: 18 checks passed, 0 failures.

@loopx-agent loopx-agent 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.

Reviewer: model_agent · gpt-6.2-sol · OpenAI · runtime_reported · xhigh

动机 / Motivation

在 Windows 上,从没有控制台的宿主启动 LoopX Goal 的用户会遇到子进程闪窗。此前的真实 Windows 评审还观察到,无条件使用进程创建标志会让已附着终端的用户丢失调度回执。当前头的原 bridge 用例在模拟 Windows 分支上已向 Job 分配一次有效句柄,原测试夹具问题已修复。当前头的原生 Windows 双形态和实际错误 232 仍待实测,本轮覆盖 macOS 实际调度与 Windows 测试分支。 上一轮精确提交评审

改动思路 / Approach

保留共享进程创建标志以及现有 Windows Job 和 Node 子进程代码,避免每个调用点维护自己的控制台识别规则。Python 调用方复用 Win32 控制台判定,TypeScript 调用方复用 Node 的 windowsHide,观测器的 stdin 竞态留在原有尽力而为的观测边界。 Python 进程适配器判定控制台和创建标志;Windows Job 保留进程监管;TypeScript 管道调用点使用 Node 的 windowsHide;调度入口仍读取真实子进程退出码。
先前 Windows 10 上观察到附着父进程无条件加 CREATE_NO_WINDOW 时漏掉前台回执;上一头的旧 BridgeProcess 缺 _handle,在 Win32 成功桩中尚未分配就失败。 当前头只改两项 bridge 测试的共享夹具。原测试强制进入 Win32 分支,可验证同一个带 _handle 的进程被分配到 Job 一次;原生附着与无控制台两条路径等待当前头读回。

具体改动 / Changes

复核的提交是 89b2ee47948c7e2ec325092edcdeb8a034a08492,目标基线是 811c1a1f66652d3fc3b9830d467e14b45b7423c1。24 个文件,增加 845 行,删除 9 行。

  • WIN-BRIDGE-TEST 已实现。原用例和显式 Windows 用例使用同一夹具。
  • WIN-ATTACHED-RECEIPT 待验证。真实附着终端需记录 JSON 和退出码。
  • WIN-CONSOLE-LESS 待验证。真实无控制台宿主需观察是否抑制了子进程闪窗。 本仓库真实入口规则

关键代码讲解

  • main。 Windows 保留 Node 子进程的前台标准流和退出码传播,POSIX 仍由 execv 替换进程。 源码
  • no_console_creationflags。 仅在确定 Windows 父进程无控制台时选 CREATE_NO_WINDOW,附着或查询不可用保持默认。 源码
  • run_host_process。 在写入 bridge 请求前,将新子进程关联到既有的 Windows Job。 源码
  • install_windows_job_stand_in。 两项 bridge 测试使用共同带句柄的进程和可检查的 Job 分配边界。 源码
  • _detach。 保持分离进程创建配置,将已经启动的观测器关闭 stdin 所致写入失败隔离在观测路径。 源码

对主干的风险 / Risks

[P2] 当前头待验证两种 Windows 控制台的实际调度回执。 旧头原用例在成功 Win32 API 桩下缺 _handle,当前头的独立原用例模拟已通过。真实无控制台不闪窗和附着终端保留 JSON、退出码的验收仍缺,模拟 Job 或 CLI 单测不能观察它们。 请在当前头用 Windows 原生 Python 和 Node 分别从附着终端及无控制台父进程执行实际 scheduler-ack-current。记录 JSON 与退出码、子进程控制台状态,以及两条 bridge 用例的结果。 用 uv run --extra test python -m pytest -q tests/test_child_console_suppression.py 重跑 bridge 用例。另外,分离观测器吞掉已启动子进程关闭 stdin 导致的写入错误,在 POSIX 也生效。启动失败仍会报错。
173 项 Python 通过、1 项跳过,Ruff 和 Git diff 检查通过。原 bridge 的独立 Win32 分支模拟已回读一次 Job 分配。 本地 macOS 和模拟 Windows 分支已有证据。当前提交缺 Windows 实机的附着终端、无控制台宿主及 Win32 ERROR_NO_DATA 验证。没有查询远端 CI。

语义与 CI 对齐

与上一头相比 22 个生产文件逐字节不变。基线和上一头的真实 macOS Node 调度入口均发出 invalid_scheduler_host_facts JSON、退出码 1,隔离目录没有状态写入。当前头完整目标套件继续验证 POSIX 参数路径。 相关默认值和失败路径已纳入本地验证矩阵。远端 CI 未查询。

我的整体评价 / Verdict

长程效果方面,Goal 启动过程能否避免一连串闪窗仍取决于原生路径读回。用户体验方面,已消除测试夹具障碍,但前台回执本身仍需要在当前头上验证。 当前头只改两项 bridge 测试的共享夹具。原测试强制进入 Win32 分支,可验证同一个带 _handle 的进程被分配到 Job 一次;原生附着与无控制台两条路径等待当前头读回。 保留共享进程创建标志以及现有 Windows Job 和 Node 子进程代码,避免每个调用点维护自己的控制台识别规则。
REQUEST_CHANGES,原夹具发现已关闭,补齐当前提交的原生观测后即可针对剩余事项复审。

English verdict: REQUEST_CHANGES at 89b2ee4. the bridge fixture is fixed and its simulated Windows branch passes. Verify both attached-terminal receipts and console-less child startup on native Windows for this head.

@LIHUA919

Copy link
Copy Markdown
Contributor Author

Acknowledged on 89b2ee479 — thank you for confirming the bridge fixture finding closed and for running the suite yourself (173 passed / 1 skipped on your side as well).

On the one remaining item, I have to state a hard limit: I have no Windows host. WIN-ATTACHED-RECEIPT and WIN-CONSOLE-LESS for this head cannot be observed from this machine, and as your review notes, simulated Job or CLI unit tests cannot stand in for them. Everything that can be prepared without the hardware is prepared:

  • The two-line both-branches check (from my earlier reply), repeated here for the current head:
    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 134217728
  • The attached-receipt oracle is your own first-round method: run loopx.entrypoint.main for quota scheduler-ack-current in PowerShell on this head and read the nine loopx_scheduler_host_followup_error_v0 JSON lines plus the exit code.
  • The bridge pair re-run command you specified: uv run --extra test python -m pytest -q tests/test_child_console_suppression.py — passes 30/30 here (96/1 across both files); your environment is the one that matters for the Windows branch of the original test.

Your round-1 review measured the previous head on real Windows 10, so the hardware is on your side: I'm asking you to run these on 89b2ee479 as the re-measurement — the fixture work your review called for is done, the POSIX _detach behavior is disclosed in the PR body as you required, and per your verdict the native observation is the only gate left. If anything reads back wrong on the real machine, I will take it back and fix it.

@BigDataDZ BigDataDZ left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

原生 Windows 复测(head 89b2ee479)——未批准

环境:Windows 10(19045),Python 3.12.10,Node 24.20.0。对照基线:main 811c1a1f6。

上一轮的两项(前台回执丢失、bridge 测试在 Windows 上失败)都已解决,ERROR_NO_DATA 的处理也验证了。剩一个小项(第 5 节)和未跑完的 CI,所以我仍不给批准。

1. 前台回执(WIN-ATTACHED-RECEIPT):通过

调用真实的 loopx.entrypoint.main,参数为 quota scheduler-ack-current --scheduler-host-facts-chunk … --turn-instance-id …:

父进程 辅助函数 _parent_has_console() / 返回的标志 传给 node 的标志 退出码 回执
有控制台,stdout 就是控制台 True / 0 0 1 9 行 JSON 出现在控制台上
有控制台,stdout 重定向到管道 True / 0 0 1 JSON 经管道完整到达
无控制台 False / 134217728 134217728 1 父进程没有 stdout

回执内容是 loopx_scheduler_host_followup_error_v0(scheduler_followup_binding_missing)。上一轮的 head 83bbed022 在第一行是终端上没有任何输出。第一行是在为探针新建的隐藏控制台里测的(stdout 即该控制台),不是 PowerShell 窗口。

2. 无控制台宿主(WIN-CONSOLE-LESS):通过

  • 第 1 节第三行的运行期间,约每 10 ms 枚举一次类名为 ConsoleWindowClass 的可见顶层窗口(1156 ms 内 31 次):没有出现。
  • 探测器的阳性对照:一个带新控制台的辅助进程(创建时隐藏,窗口移到屏幕外之后才显示)被检出,附着父进程和无控制台父进程里各验证一次。
  • 把入口那条启动语句换成能自述的替身子进程:它的 GetConsoleWindow() 为 NULL,没有窗口。

一个测量上的说明:CREATE_NO_WINDOW 的子进程仍然会带起一个 conhost.exe(实测它的父进程分别是 node.exe 和 python.exe),只是没有窗口。所以"出现 conhost"不能当作闪窗的证据。

3. bridge 测试对:通过

tests/test_child_console_suppression.py + tests/extensions/test_process_runtime.py → 69 passed / 0 failed / 28 skipped。跳过的是 27 个 POSIX 进程组用例和 1 个 "host is Windows" 用例。test_run_host_process_bridge_passes_no_console_creationflags 与 test_run_host_process_bridge_windows_branch_assigns_job_and_passes_flag 均通过。上一轮是 55 passed / 1 failed / 28 skipped。

4. ERROR_NO_DATA:通过

竞态本身是间歇性的,我用注入的方式让它确定发生:让 Popen 返回前延迟 400 ms,各跑 30 次。

OSError 逃出 _detach 的次数 正常返回
main 811c1a1f6 4([Errno 22] Invalid argument) 26
89b2ee479 0 30

另对已退出子进程的 stdin 管道直接调用 WriteFile,30 次全部返回 Win32 错误 232,即 HRESULT 0x800700E8,与 #9430 报告的错误码一致。

5. 一个新的小发现:本 PR 新增了 1 个 mypy 错误

loopx/extensions/process_runtime.py:37: error: Module has no attribute "WinDLL"  [attr-defined]

本机按仓库配置加 --platform linux 运行:main 是 3834 个错误,本 head 是 3835 个(与 CI 一致);忽略行号后只多这一条。原因是 typeshed 只在 sys.platform == "win32" 下声明 ctypes.WinDLL,而新函数判断的是 os.name,mypy 不会据此收窄。在取 WinDLL 之前加 sys.platform 判断,或改用 getattr,应该就能消除。落在改动文件上的其余 148 个 mypy 错误与 main 逐条相同。

CI

该 head 上 kernel-contracts 失败,Python 分片和 windows-powershell 都被跳过,没有完整的 Python 套件结果。

未验证

  • 真实的闪窗我没有观察,用的是"是否出现可见控制台窗口"和"子进程是否有控制台窗口"作为判据。
  • 只测了调度入口这一条路径;Goal 启动流程里其余调用点在无控制台宿主上的表现没有逐个测。
  • Windows Terminal / ConPTY。
  • POSIX 运行。

在第 5 项处理完、且套件在该 head 上有完整结果之前,我不给批准。

@BigDataDZ

Copy link
Copy Markdown
Contributor

补充测量(head 89b2ee479):Goal 启动流程与 detached 观察器路径

上一条评审覆盖了调度入口与 bridge 测试。这两条补的是评审与机器人回复里都点名的剩余面:无控制台宿主上的真实 Goal 启动流程(#9430 报告的场景),以及错误 232 的来源路径。全部在本机 Windows 10 上完成,每个轮次的窗口探测器都先通过阳性对照(屏幕外显示的隐藏控制台窗口被抓到)才采数。

流程一:Goal 启动序列(继承路径)

真实 file 权威夹具上,从无控制台父进程依次运行真实 CLI:quota should-run --codex-app → todo add --execute → refresh-state → 第二次 quota should-run(即 #9430 列举的 bootstrap → todo 写入 → quota 守卫序列)。两种模式的顶层 CLI 都被调用方(我的探针)用 CREATE_NO_WINDOW 启动——这是恒量,被测变量只有 loopx 自己的启动点。

可见控制台窗口 命令结果 出现的 conhost 会话
main 811c1a1f6 0(对照外) 4/4 exit 0 45
89b2ee479 0(对照外) 4/4 exit 0 44

为什么 main 在这条路径上也不闪:顶层的 CREATE_NO_WINDOW 给它一个无窗口的控制台会话,之后所有子孙继承该会话——加不加标志都不会有窗口。45 个 conhost 就是这些无窗口会话。所以「逐点加标志」在继承路径上本来就不改变行为;闪窗不出在这里。

流程二:detached 观察器路径(这才是 #9430 的闪窗面)

DETACHED_PROCESS 的进程没有任何控制台可继承。它调用 usage_ping.control() 启动 node 时,每个子进程都会分配带可见窗口的新控制台——正是 issue 报告的机制,也是错误 232 的同一进程族。每模式 5 次调用:

可见闪窗(剔除对照) 调用结果 conhost 会话
main 811c1a1f6 5 / 5 5×ok:false(状态应答,node 均实际运行) 6
89b2ee479 0 / 5 同上 6

两个方向合起来的结论:本 PR 修复的正是 detached 路径;继承路径则无论是否合并都不闪。#9430 报告的"启动一个 Goal 连续闪窗"与两者都相容——顶层 loopx 被不带标志启动时自身闪一次,其 detached 观察器的 node 子进程再各闪一次。

测量方式说明:闪窗判据为运行期间新出现的、类名 ConsoleWindowClass 的可见顶层窗口,约每 10 ms 枚举一次;每轮先做阳性对照(隐藏创建、屏幕外显示的辅助控制台窗口被检出)。没有用肉眼观察闪窗;窗口属主图像名在采样结束时解析,闪窗的 node 进程此时多已退出,故记为 <exited>。

此前评审的结论不变:前台回执、bridge 测试对、ERROR_NO_DATA 三项在 89b2ee479 上通过;ctypes.WinDLL 的 mypy 小项待处理;该 head 上 Python 套件仍无完整结果,所以我仍不给批准。

The console query reads ctypes.WinDLL, which typeshed declares only under
sys.platform == "win32". The helper selected Windows by os.name, which mypy
does not narrow on, so the new function added one attr-defined error to a
type-check that was otherwise identical to main (3835 against 3834), and
the kernel-contracts job went red on it, skipping the Python shards.

The query now returns "attached" before the import unless sys.platform is
win32, which is where typeshed's declaration applies. Reachable behavior is
unchanged: the helper already returned 0 off Windows, and on Windows the
function proceeds to the same query. AttributeError leaves the except
clause because WinDLL exists wherever the import is now reached.

The unanswerable-query test emulates both platform markers so it still
reaches the failing import, and a companion test proves the Win32 query is
never entered off Windows.

Signed-off-by: Lihua <1017343802@qq.com>
@LIHUA919

Copy link
Copy Markdown
Contributor Author

Thank you both — @BigDataDZ's native re-verification on 89b2ee479 and the Goal-start measurement are exactly the readbacks I could not produce, and they settle the four acceptance items (attached receipt, console-less start, bridge test pair, ERROR_NO_DATA). The finding that the detached observer path is the real flash surface (5/5 visible flashes on main → 0/5 here) while the inherited path never flashes either way is a sharper picture of the issue than the report itself gave.

Item 5 (the one new mypy error) — fixed on 7844d66b5. You were right about the cause: typeshed declares ctypes.WinDLL only under sys.platform == "win32", and mypy does not narrow on the os.name check the helper used. I took your first option: _parent_has_console now returns "attached" before the import unless sys.platform is win32. Reachable behavior is unchanged — off Windows the helper already returned 0 without reaching the query, and on Windows the same query runs. AttributeError left the except clause because WinDLL exists wherever the import is now reached; the unanswerable-query test now emulates both platform markers so it still reaches the failing import, and a companion test proves the Win32 query is never entered off Windows.

Verified the way you measured it — full python -m mypy --platform linux --no-incremental, line numbers ignored, PR tree against a pristine 811c1a1f6:

  • before the fix (89b2ee479): the only delta in either direction was loopx/extensions/process_runtime.py: error: Module has no attribute "WinDLL";
  • after (7844d66b5): 3834 = 3834, empty diff both directions.

On "the suite has a complete result on this head" — one thing I cannot deliver from CI, and it is not this PR's doing. kernel-contracts is red on main itself: run 46210676811 on 811c1a1f6 ends Found 3834 errors in 395 files … exit code 1, which is the same count I get locally on pristine main. Because test-shard and windows-powershell list that job under needs, a pull request on current main gets its Python shards skipped (that is why this PR's shards did not run), and no change to this PR can turn them green. The last kernel-contracts success I can find is the 2026-11-25 run on base b34f0e615. I recorded this with the evidence on #9567. What this PR can truthfully claim is the narrower thing: it adds no mypy error relative to main, which the comparison above shows.

So the complete result for 7844d66b5 is local, on macOS, and I am stating it as such rather than as a CI pass:

  • tests/test_child_console_suppression.py + tests/extensions/test_process_runtime.py: 97 passed / 1 skipped;
  • tests/architecture (the static-guard suite): 1919 passed / 0 failed;
  • the 51 test files of every touched module, serial: 1355 passed / 0 failed / 8 skipped. One earlier pass of this set ran alongside the architecture suite and had a single TimeoutExpired on test_cancelling_real_startup_reaps_probe_and_releases_lock (its real start-and-cancel child exceeded its own 10 s limit under that load); that test then passed 23/23 here and 20/20 on pristine main when rerun alone, and the clean serial run above is all green;
  • loopx canary premerge --from-git-diff --git-diff-base 811c1a1f6: 18 checks passed, 0 failures.

Of the items you listed as unverified, the ones that remain are yours or the owner's to call: Windows Terminal / ConPTY, the remaining Goal-start call sites on a console-less host, and POSIX, where the only behavior change is the _detach write-and-close that the PR body now discloses.

@BigDataDZ BigDataDZ left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

原生 Windows 复核(修复头 7844d66b5)——APPROVE

上一轮的第 5 项(ctypes.WinDLL 的 mypy 错误)已按第一种建议修复,本机用同一方法复核,并确认修复头的 Windows 行为与已验证的 89b2ee479 完全一致。

mypy 平价(本机复跑,非沿用作者数据)

python -m mypy --platform linux --no-incremental,行号归一后双向对比:main 811c1a1f6 = 3834 条,本 head = 3834 条,双向差异均为空。之前多出的 WinDLL 一条已消失。

Windows 行为平价(真实探测)

  • 附着上下文:_parent_has_console() → True,标志 0;bridge 测试对 + process_runtime → 70 passed / 28 skipped / 0 failed(比上轮多 1 个通过 = 新增的非 Windows 早退伴随测试)。
  • 真正的无控制台上下的(DETACHED 阶段进程,GetConsoleWindow() 为 NULL):helper → False / 134217728;真实 loopx.entrypoint.main 传给 node 的正是该标志,运行期间无可见控制台窗口。
  • 一个测量教训,记录备查:我第一次复核时误用了会走 CREATE_NEW_CONSOLE 的探针模式,阶段进程自带隐藏控制台,helper 如实报了 True——那是正确行为,是我的探针用错了模式;换真正 detached 的模式后数值正确。

关于"该 head 上无完整套件结果"

我此前一直以此为由不给批准。经与作者核实并本机查证:main 自身的 kernel-contracts 就是红的(Python Tests run 46210676811 on 811c1a1f6,3834 个仓库级 mypy 错误),而工作流把 test-shard 与 windows-powershell 门控在它后面——当前 main 上的任何 PR 都不可能拿到完整的 Python 套件结果。这是仓库级状态,不是本 PR 的属性;在此条件下该条件无法满足,继续扣批准不增加任何安全性。本 PR 在本机可验证的一切(四项验收读数、Goal 流程、观察器路径、mypy 平价、修复头行为一致性)均已通过。

APPROVE。

This branch has not been deployed

No deployments
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.

Windows: black console windows flash during goal start (console children launched without CREATE_NO_WINDOW)

3 participants