Skip to content

Windows 파일 열기 CLI: HIDE_OPEN_COMMAND를 job object로 소유합니다 - #333

Merged
yansfil merged 5 commits into
mainfrom
platform/win-opener
Oct 3, 2026
Merged

yansfil merged 5 commits into
mainfrom
platform/win-opener

Conversation

@yansfil

@yansfil yansfil commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Refs with-hide/hide-private#103

Summary

Windows는 지금까지 HIDE_OPEN_COMMAND(명시적 파일 열기 CLI)를 부팅 때 거절했습니다. Unix는 데몬이 죽어도 그 CLI의 프로세스 트리가 끝나도록 supervisor와 owner 소켓 쌍을 두는데, Windows에는 그 대응이 없었기 때문입니다.
이제 Windows에서는 그 CLI를 OwnedChild로만 실행합니다. job object(KILL_ON_JOB_CLOSE)가 stop, 10초 timeout, Drop, 그리고 hided가 소멸자 없이 죽는 경우까지 트리 전체를 끝냅니다.
두 시스템이 OwnedOpener 하나와 handler의 실행 경로 하나를 같이 씁니다.
opener lifecycle 테스트는 테스트 바이너리 자신을 가짜 CLI로 씁니다(sh 또는 .cmd 두 줄 스크립트). 그래서 같은 테스트가 세 OS에서 돕니다. 이 테스트와 opener가 필요한 handshake 테스트를 windows check가 실행합니다.
#332(경로 모델)와 #334(필수 windows check) 위로 rebase했습니다. opener는 이제 CLI에 경로를 wire 철자를 거쳐 넘깁니다. Windows에서 데몬이 canonicalize한 \\?\C:\x가 아니라 C:\x를 받습니다. code.cmd 같은 명령줄 프로그램은 \\?\ 접두사를 읽지 못하기 때문입니다.

Review

  • 판단해 주세요: Unix는 supervisor를 유지합니다(원칙 2를 따르지 못한 이유).
    • 어떤 Unix도 소유자가 죽을 때 프로세스 그룹 전체를 끝내 주지 않습니다. Linux PR_SET_PDEATHSIG는 직계 자식 하나만, 그것도 스레드 기준으로 보고, macOS에는 아예 없습니다.
    • 그래서 한 모델로는 owner-death 보장을 지킬 수 없습니다.
  • 판단해 주세요: Windows에서 CLI가 직접 띄운 프로세스는 job 안에 남아 CLI가 끝날 때 같이 끝납니다.
    • 예: 편집기가 떠 있지 않을 때 code.cmd가 띄운 편집기도 같이 끝납니다.
    • 셸이나 이미 떠 있는 앱이 연 것은 job 밖이라 남습니다.
    • Unix에서 setsid로 빠지는 경우와 다릅니다. job을 CLI 종료 때 끝낼지, timeout·종료·데몬 사망 때만 끝낼지 정해 주세요. 지금은 Unix의 "CLI가 끝나면 그룹을 끝낸다"에 맞췄습니다.
  • 조심해서 볼 파일:
    • hide-platform/src/process.rs: 콘솔이 없는 소유자(분리된 데몬)일 때만 Windows OwnedChild에 CREATE_NO_WINDOW를 더합니다. 그렇지 않으면 콘솔 프로그램(.cmd 포함)마다 보이는 창이 뜹니다. 콘솔이 있는 소유자는 예전처럼 자식과 콘솔을 나눕니다. 모든 자식에 더했더니 자식마다 conhost가 생겨 measure_tree 계약이 바뀌었고, os contract (windows)가 그것을 잡았습니다.
    • hided/src/env.rs: Windows는 .exe/.com/.bat/.cmd만 받습니다. 그 밖의 파일은 부팅 때 거절합니다.
    • hided/src/spawn.rs: failure path라서 봐야 합니다. kill이 실패하면 기다리지 않고, job의 마지막 handle이 닫힐 때 끝납니다.
    • hided/src/opener.rs: program_spelling이 to_wire 뒤 from_wire로 프로그램에 줄 철자를 만듭니다. wire 철자가 없는 경로(UTF-8이 아닌 이름 등)는 받은 그대로 넘깁니다. 거절하지 않은 이유는 그 경로가 이미 boundary를 통과한 이 기계의 경로이기 때문입니다.
  • 원칙: 1(Windows 거절 분기, cfg 울타리, 낡은 문서를 지움), 2(한 타입, 한 실행 경로), 4(실행할 수 없는 CLI는 부팅 때 거절), 7(새 장치 없이 OwnedChild 재사용), 8(소유 모델을 플랫폼 계층에 둠), 12(lifecycle 테스트 하나를 세 OS가 공유하고, supervisor 고유 테스트만 Unix).

Evidence

  • 확인한 것:
    • macOS에서 verify-cargo.sh lint와 test 전체 통과.
    • opener_lifecycle 10개 통과(가짜 CLI와 자식이 stop, timeout, 종료 알림, 소유 프로세스 kill 뒤에 남지 않음).
    • 새 테스트 a_helper_is_handed_the_plain_spelling_of_a_canonical_path: fs::canonicalize한 경로로 열면 가짜 CLI가 identity::canonical 철자를 받습니다. Windows에서는 \\?\가 빠진 것을 확인합니다.
    • rebase 뒤 macOS verify-cargo.sh lint/test 전체(56 suites)와 Windows 대상 clippy를 다시 통과했습니다.
    • Windows 대상 clippy --workspace --all-targets -D warnings 통과.
    • 독립 리뷰의 Fix now 3건을 고쳤습니다: 콘솔 창, Windows에서 실행 불가 파일 허용, 낡은 문서 한 줄.
  • 확인하지 못한 것:
    • Windows 실행은 이 PR의 CI가 처음입니다.
    • 탐색기와 COM 핸드오프가 job 밖에서 앱을 띄우는 경우는 실기기로 보지 않았습니다.
    • opener를 부르는 신뢰된 전송은 아직 없습니다(open_external은 브라우저 소켓에서 거절). 실제 제품 경로는 이 PR로 열리지 않습니다.

An explicit HIDE_OPEN_COMMAND helper now runs on Windows as an
OwnedChild and nothing else: the job object it is placed in ends the
helper and everything it started when hided stops it, when the
ten-second timeout passes, and when hided dies without running a
destructor, because the system ends the job when its last handle
closes. Windows therefore accepts the variable at boot.

Unix keeps the supervisor and its owner socket: no Unix system ends a
whole process group when its owner dies, so one model cannot keep that
guarantee there. Both systems share one OwnedOpener and one launch path
in the handler.

The opener lifecycle tests use this test binary as the fake helper
through a two-line script, so the same tests run on all three systems;
only the supervisor's own tests stay Unix. The Windows job runs them and
the handshake test that refuses a browser's open.
…opener Windows cannot run

A console program an OwnedChild starts on Windows now gets a console
without a window: a detached hided has no console of its own, so a
`.cmd` opener (which runs through cmd.exe) or any console helper would
otherwise open a visible window for its whole life.

HIDE_OPEN_COMMAND on Windows must name an executable or a batch file,
so a script Windows cannot start fails at boot rather than on every
open. The Windows opener's stop no longer waits on a helper whose kill
failed, and `--open-helper` on Windows is refused instead of starting a
daemon. The handshake test's marker uses the temporary folder's own
spelling, and the architecture notes say what a Windows helper's job
ends and how a batch helper receives its path.
Every console child started without a window gets a console host of its
own, which `measure_tree` counts as a descendant, so hiding the window
for every child changed what the process contract measures under an
owner that has a console (the os contract leg). Only an owner with no
console of its own (a detached daemon) would have Windows open a visible
window, so only then is the child's console hidden; an owner with a
console shares it with its children as before.
A CI runner's process has a console without a window, so asking for the
console's window read it as having none and hid every child's console,
which gave each child a console host of its own. The owner's console
code page is 0 only when it has no console.
A path the daemon canonicalized carries Windows' \\?\ prefix, which
command-line programs such as code.cmd do not read. The opener now hands
its program the path through the wire spelling, so on Windows it gets
C:\x without the prefix and elsewhere the path as it is.
@yansfil
yansfil force-pushed the platform/win-opener branch from 5e5f39a to 77bfec4 Compare October 3, 2026 10:53
@yansfil
yansfil merged commit e43bd07 into main Oct 3, 2026
21 checks passed
@yansfil
yansfil deleted the platform/win-opener branch October 3, 2026 11:04
yansfil added a commit that referenced this pull request Oct 3, 2026
…335)

Refs #293

## Summary

원격 데몬을 위해 기기에서 도는 pane bootstrap 도우미(`hide-host-helper
workspace-bridge`)는 `UnixListener` 위에서 비차단 accept를 폴링했고, 그 기기의 `hide`는
Windows에서 브리지를 찾지 않았습니다(`Ok(None)`).
이제 브리지는 slice 5의 pane bootstrap과 같은 방식으로
`hide_platform::ipc::LocalListener`/`ListenerCloser` 위에 섭니다.
macOS/Linux에서는 Unix 소켓, Windows에서는 named pipe와 그 marker 파일입니다.
accept는 자기 스레드에서 막혀 기다리고, exec 채널의 입력이 끝나면 closer가 그것을 닫습니다.
클라이언트(`bootstrap_remote`)는 `LocalStream`으로 연결합니다.
그래서 Windows 기기도 원격 데몬의 브리지를 둘 수 있습니다. 원격 OS probe와 원격 kit 설치는 이 PR의 범위가
아닙니다.
#332(경로 모델), #334(필수 `windows check`), #333(Windows opener) 위로
rebase했습니다. 브리지의 줄이 기기의 경로를 wire 철자로 싣습니다.
  - 데몬의 첫 줄의 `bridge_dir`는 브리지가 `from_wire`로 읽습니다.
- 브리지가 답하는 endpoint(Windows에서는 marker 파일)와 reference는 `to_wire`로 씁니다.
기기의 `hide`는 reference를 `from_wire`로 읽습니다.
  - hided 자신의 pane bootstrap도 같은 reader를 지나므로 reference를 wire 철자로 답합니다.

## Review

- **판단해 주세요**: 리뷰가 찾은 Windows 보안 구멍을 `hide_platform::ipc`에서 한 번에 막았습니다.
- Windows pipe 이름은 전역이라, marker가 있는 비공개 폴더가 다른 계정이 그 이름의 pipe를 먼저 만드는 것을
막지 못합니다.
- 이제 Windows의 모든 `LocalStream::connect`가 연결한 pipe의 소유자가 이 계정인지 확인하고, 아니면
`PermissionDenied`로 거절합니다.
  - slice 5에서 들어온 hided 자신의 pane bootstrap도 같은 구멍이 있었고, 같이 막힙니다.
- **조심해서 볼 파일**:
- `hide-host/src/workspace_bridge.rs`: failure path라서 봐야 합니다. accept나
sweep이 스스로 멈추면 이제 `failed` 프레임을 쓰고 끝납니다. 예전에는 아무 말 없이 멈춰 route가 ready로
남았습니다. 데몬(`remote_bridge.rs`)은 그 이유를 기록하고 route를 끝냅니다.
- `hide-platform/src/ipc.rs`: 모든 Windows 클라이언트 연결(Herdr 클라이언트 포함)에 소유자
확인이 하나 늘었습니다. Herdr는 같은 계정으로 돌기 때문에 통과합니다.
- `hided/src/workspace_cli.rs`: Unix의 `is_socket` 확인이 "디렉터리·링크가 아님 + 이
계정 소유"로 바뀌었습니다. 살아 있는 listener인지는 connect가 판단합니다.
- **판단해 주세요**: 첫 줄의 `herdr_socket`은 wire 철자로 바꾸지 않았습니다. 기기의 Herdr가 보고한
값을 그 Herdr에게 되돌려 주는 것이라, #332의 `wire.rs`가 Herdr에게 Herdr의 철자로 보내는 것과 같은
규칙입니다. 데몬이 Mac에서 Windows 기기의 철자를 바꾸지 않는 것은 ARCHITECTURE의 "Not spelled
yet"에 그대로 남아 있습니다.
- **조심해서 볼 파일 (rebase 후)**: `hided/src/pane_auth.rs`: failure path라서 봐야
합니다. wire 철자가 없는 reference(UTF-8이 아닌 상태 경로)는 `reference_unavailable`로
거절하고, 전달하지 못한 reference처럼 회수합니다. macOS/Linux에서는 바이트 동일합니다.
- **판단해 주세요**: 첫 CI(run 37118299146)의 rust workspace를 실패시킨 잠금 테스트를
고쳤습니다(`hide-platform/tests/fs.rs`, `src/fs/lock.rs` 문서).
- 원인: Unix의 `flock`은 서술자가 아니라 열린 파일에 붙습니다. 같은 테스트 바이너리의 다른
테스트(`hold_in_another_process`, `mkfifo`)가 자식을 띄우면, 그 자식은 exec 전까지 잠금
서술자의 복사본을 쥡니다. 그 사이에 `drop(held)`가 일어나면 잠금은 자식이 exec할 때 풀립니다. 테스트는 drop
직후 `Duration::ZERO` 한 번만 시도했습니다.
- 확인: fork 뒤 exec 전에 멈추는 자식을 둔 작은 프로그램에서, drop 직후 재잠금이 실패하고 자식이 exec한
뒤에는 성공했습니다.
- 고침: drop 뒤 다시 잡는 세 곳만 최대 10초 기다립니다. 같은 파일의 다른 프로세스 잠금 테스트가 이미 쓰는
방식입니다. "drop하면 풀린다"와 "잡고 있는 동안 다른 잠금은 못 잡는다"는 그대로 단언합니다. 경로 공유는
없었습니다(테스트마다 자기 tempdir).
- **원칙**: 1(fd 수준 peer pid 도우미와 브리지 복사본을 지움), 2·7(새 장치 없이 slice 5의 패턴과
`ipc` 재사용), 4·10(브리지가 멈춘 이유를 채널 위로 올림), 13(pipe 소유자 확인을 호출자가 아니라
`ipc`에서).

## Evidence

- **확인한 것**:
  - macOS에서 `verify-cargo.sh lint`와 `test` 전체 통과(55 suites).
  - Windows 대상 `clippy --workspace --all-targets -D warnings` 통과.
- rebase 뒤 macOS `verify-cargo.sh lint`/`test` 전체와 Windows 대상 clippy를 다시
돌렸습니다.
- 새 테스트 `a_remote_bridge_answers_this_device_and_ends_with_its_channel`가
세 OS에서 실제 브리지와 클라이언트를 맞붙입니다.
- 브리지가 호출자의 pid를 보고, Herdr가 없는 소켓에서 `pane_unavailable`로 멈춥니다. pid를 못 봤다면
`caller_unavailable`가 먼저 나옵니다.
    - 채널이 끝나면 10초 안에 끝나고 endpoint가 사라집니다.
- 첫 줄을 wire 철자로 보내고, `ready`의 endpoint가 `from_wire`로 읽혀 그 폴더 아래에 있는지
봅니다. Windows에서는 네이티브 철자였다면 `from_wire`가 거절합니다.
    - `windows check`가 이 테스트와 브리지 단위 테스트를 돌립니다.
- 독립 리뷰의 Fix now 2건을 고쳤습니다(멈춘 브리지의 침묵, Windows pipe 선점). accept 큐 제한과
sweep 기아도 같이 고쳤습니다.
- **확인하지 못한 것**:
- 첫 CI의 web e2e linux 1/6 `checkout-owner.spec.ts:162` 실패는 원인을 확인하지 못해
재실행하지 않고 #288에 run id와 함께 남겼습니다. Herdr는 탭 둘(`w2:t1`, `w2:t2`)을 만들었는데
화면에는 하나만 올라왔습니다. 이 PR은 탭 생성과 projection 경로를 바꾸지 않습니다.
  - 다른 계정이 pipe를 선점하는 경우는 CI에서 재현할 수 없습니다. 같은 계정의 연결이 모두 통과하는 것만 확인됩니다.
- Windows를 실제 원격 기기로 붙이는 흐름은 아직 없습니다. OS probe(`uname`), POSIX 셸 명령, kit
설치가 Unix를 가정합니다(#293).
yansfil added a commit that referenced this pull request Oct 30, 2026
…s and a Windows Node warm-up (#1863)

Closes with-hide/hide-private#331
Closes with-hide/hide-private#332
Closes with-hide/hide-private#333
Closes with-hide/hide-private#338
Closes with-hide/hide-private#329

## Summary

Six flaky tests in five crates came from three causes, and each is fixed
once for its class.
- Tests read through a product time budget they are not about: Memory
reads were cut at the hook's 100 ms and returned no cards, and the usage
store's 250 ms step cut a 40,000-row prune.
A Memory read now has no deadline of its own (the 100 ms stays in the
hook alone), and the usage store's tests hold its clock still.
- Fixture `git` read the account's settings, so a commit failed whenever
the commit-signing agent did not answer; the fixtures now read no global
or system git file.
- The Windows Node test warmed Node with `--version`, which skips most
of Node's start, so the guarded run still paid the slow first start; the
warm-up now runs the same script.

Per issue:

| Issue | Handling |
| --- | --- |
| #331 usage store prune | Cause fixed: store budgets measured on an
injected clock; store tests open it on a still one |
| #332 herdr-core memory tests | Cause fixed: `MemoryStore::retrieve`
has no deadline; memory_hook tests use `answer_until` with a still clock
|
| #338 hide-memory store tests | Same cause as #332, same fix; the store
and hook tests in its latest comments read through
`retrieve_with_expiry`, which no longer adds a wall clock of its own |
| #333 hide-host fixture commit | Cause fixed:
`GIT_CONFIG_GLOBAL=/dev/null`, `GIT_CONFIG_NOSYSTEM=1`; four other
fixtures with the same inheritance too |
| #329 hide-kit Windows Node | Cause fixed: the first start runs the
guarded script, not `--version` |
| #334 omp observed false | Stays open by the lead's decision: the
helper's 1.2 s send budget is in another process; the failure now prints
the time, the recorded cause and the stand-in's calls |

The Windows process end (with-hide/hide-private#327) was in this pull
request and moved to a pull request of its own; its commits here are
taken back out, so `hide-platform`, `hide-ai`'s omp test and its
documentation are as on main.

스크린샷 없음: no screen changes.

## Review

- **조심해서 볼 파일**:
- `hide-memory/src/store.rs`, `hide-memory/src/hook.rs` -
`RetrievalQuery.deadline` is removed. The product's only Memory reader
is the hook (`hook::context_for` and `herdr_core::memory_hook::answer`,
both through `hide_memory::hook::within_hook_budget`, which adds the 100
ms); every `retrieve` call left is in a test.
- `herdr-core/src/usage_ledger/store.rs` - `Store` carries `clock: fn()
-> Instant`; `open` passes `Instant::now`, so product timing is
unchanged.
- `hide-host/src/worktrees.rs` and four test fixtures - git runs with no
global or system configuration file.
- **질문**: #329's readying pays Node's first full start before the 30 s
guard; the test is about the environment the kit hands Node (it aborts
without `SystemRoot`), not its start time. If a cold first start is ever
the operator's own concern, that is a separate product issue.

## Evidence

- **확인한 것**:
- Local macOS at load 30 to 84: `hide-memory --lib` 205/205 four times
(the parallel run that failed in #338), `hide-host --lib` 154/154,
`herdr-core --lib` usage_ledger, memory_hook, project_memory,
memory_analysis and real_agent_trust 135/135, `hide-agent-hooks`
adapter_contract and codex_binary 6/6.
- Windows CI on 7af7724 and 6fe4f39: every Rust suite of `windows
check` passed, including the hide-kit Node test (#329).
- `clippy --all-targets -D warnings` clean for hide-memory, herdr-core,
hide-host, hide-kit, hide-agent-hooks, hide-ai on macOS.
- **확인하지 못한 것**:
  - Windows tests run only on PR CI; this Mac cannot run them.
  - #334 is not fixed; it fails less silently.
- `windows check` failures seen on this branch were outside its diff:
two web unit tests timing out at 5 s together (open
with-hide/hide-private#354, commented there) and a web unit suite that
could not rename a fixture program another worker built (filed as
with-hide/hide-private#371).
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.

1 participant