Skip to content

OS 경계 1: 로컬 IPC를 hide-platform으로 옮기고 Herdr 클라이언트를 세 OS에서 돌립니다 - #307

Merged
yansfil merged 11 commits into
mainfrom
platform/ipc
Oct 2, 2026
Merged

yansfil merged 11 commits into
mainfrom
platform/ipc

Conversation

@yansfil

@yansfil yansfil commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Refs with-hide/hide-private#103

Summary

Herdr 클라이언트가 Unix 소켓에 묶여 있어서 Windows에서는 컴파일조차 되지 않았습니다. OS에 따라 달라지는 로컬 IPC를 새 leaf crate hide-platform의 ipc 모듈로 모으고, hide-herdr-client가 그 위에서 돌게 했습니다. #293의 slice 1입니다.

  • hide-platform::ipc: LocalListener::bind, LocalStream::connect, 읽기/쓰기 timeout, 다른 스레드에서 막힌 읽기를 푸는 ShutdownHandle, OS가 답하는 곳의 peer_pid(아니면 Unsupported). macOS와 Linux는 Unix 소켓, Windows는 현재 사용자만 접근하는 DACL의 named pipe이며 interprocess 위에 있습니다.
  • hide-herdr-client의 UnixSocketConnector는 LocalSocketConnector가 됐고 Unix 전용 코드는 지웠습니다. wire와 API 타입은 그대로입니다.
  • 계약 테스트 21개(hide-platform/tests/ipc.rs)를 세 OS에서 같은 파일로 돌립니다. 새 os contract job(Linux, Windows)이 돌고, macOS는 기존 desktop-e2e job 안의 step으로 돌아 macOS job이 늘지 않습니다. verify의 needs에 넣었습니다.
  • 고정한 Herdr v0.9.1의 Windows asset을 contracts/herdr-bundle.json에 추가했습니다(scripts/bump-herdr.sh가 기록하고, check-herdr-pin-single-source.sh가 새 파생 파일 2개까지 확인). Windows runner가 그 zip을 받아 named pipe로 실제 요청 하나와 events.subscribe 스트림을 확인합니다.
  • trash crate의 coinit_apartmentthreaded feature를 한 줄로 켜서 Windows 컴파일 막힘을 풀었습니다(별도 커밋).

Review

  • 판단해 주세요: Windows named pipe에는 I/O timeout이 없습니다. 읽기 timeout은 PeekNamedPipe 폴링(1ms에서 4ms까지)이고, 쓰기 timeout은 Unsupported입니다. 클라이언트는 그 한 가지 답을 "timeout 없음"으로 받습니다(요청은 버퍼에 들어가는 한 줄). 쓰기 timeout이 Windows에서도 필요한 호출자가 생기면 다시 정해야 합니다.
  • 판단해 주세요: Windows 읽기 timeout 중에는 최대 4ms 간격의 폴링이 돕니다. timeout이 없는 읽기(구독 스트림)는 폴링 없이 블로킹입니다.
  • 조심해서 볼 파일: hide-platform/src/ipc.rs - unsafe는 Windows sys 모듈의 PeekNamedPipe, CancelIoEx, DACL 확인에만 있고 unsafe_op_in_unsafe_fn을 deny합니다. ShutdownHandle은 cancelled 플래그와 blocked 카운터로 CancelIoEx를 재시도합니다(최대 200회, 1ms 간격).
  • 조심해서 볼 파일: hide-herdr-client/src/lib.rs - subscribe 스트림의 줄 읽기(high-frequency path). Unix에서는 이전과 같은 블로킹 read이고, timeout 읽기만 바이트마다 set_read_timeout(남은 시간)을 겁니다.
  • 조심해서 볼 파일: LocalListener::bind의 clear_leftover - 소켓(Unix)이나 marker 파일(Windows)만 지웁니다. 다른 파일이나 폴더가 있으면 AlreadyExists로 실패하고 지우지 않습니다.
  • 조심해서 볼 파일: scripts/bump-herdr.sh, contracts/herdr-bundle.json - 핀은 manifest 한 곳에만 있어야 하고 Windows zip의 sha256도 거기 있습니다.
  • 알려진 한계: Windows에서 LocalListener에 연결해 곧바로 끊는 클라이언트를 빠르게 반복하면(50회 실험에서 33번째) 다음 연결이 timeout 됐습니다. interprocess의 listener는 인스턴스를 하나만 두고 accept가 교체하기 때문입니다(문서에 적힌 동작). 지금 Windows의 LocalListener 사용처는 테스트뿐이고 hided의 소켓은 아직 옮기지 않았습니다. 이후 slice가 서버 쪽을 옮길 때 다시 봐야 합니다.

Evidence

  • 확인한 것: os contract 실행 36893520366(이 PR의 마지막 코드와 트리가 같고 임시 push 트리거만 다릅니다). Linux와 Windows 모두 hide-platform과 hide-herdr-client 테스트, clippy(-D warnings), 고정한 Herdr에 대한 real_herdr(ping, session.snapshot, events.subscribe로 workspace.created 수신, 종료가 막힌 읽기를 푸는 것)를 통과했습니다. Windows에서는 v0.9.1 Windows zip의 herdr.exe가 named pipe로 답했습니다.
  • 확인한 것: macOS 로컬에서 계약 테스트 21개, hide-herdr-client 테스트, cargo clippy -D warnings, fmt, scripts/tests 32개, 핀 단일 출처 검사(파생 파일 10개)를 통과했습니다.
  • 확인한 것: macOS 성능을 옛 UnixStream과 새 LocalStream으로 번갈아 5회(대기는 3회) 쟀습니다. 부하 평균이 35였던 기기라 잡음이 큽니다.
    • 몰아서 읽기(약 250바이트 줄 30만 개): 옛 구현 0.271.28 M lines/s, 새 구현 0.791.25 M lines/s. 평균은 비슷하고 어느 쪽도 일관되게 빠르지 않았습니다.
    • 500us 간격 지연: p50이 옛 구현 8.516.8us, 새 구현 8.615.5us. p99는 두 쪽 모두 부하 때문에 30us~3.7ms로 흔들렸습니다.
    • 대기(트래픽 없이 10초): 옛 구현 2633us CPU, 새 구현 3158us CPU. Unix에는 폴링이 없습니다.
  • 확인한 것: 이 PR의 verify 실행 36894030377이 전부 초록입니다(os contract Linux와 Windows, desktop e2e 안의 macOS leg, rust workspace, web e2e Linux 8개와 macOS, windows check).
  • 확인한 것: windows check(비필수)는 이제 hide-herdr-client와 trash를 지나 hide-agent-hooks에서 처음 멈춥니다(std::os::unix::fs와 Permissions::from_mode, mode() 오류 12개). 그 위층(hide-kit, hide-host, herdr-core, hided)은 아직 컴파일 검사가 닿지 못했습니다. web 셸 typecheck와 단위 테스트, desktop typecheck는 계속 통과입니다.
  • 확인하지 못한 것: Windows 부하/지연 측정, Windows에서 herdr terminal session control, Windows 쓰기 timeout(Unsupported)을 필요로 하는 호출자, hided 소켓과 나머지 로컬 소켓(이후 slice).

@yansfil
yansfil merged commit 6c378c1 into main Oct 2, 2026
21 checks passed
@yansfil
yansfil deleted the platform/ipc branch October 2, 2026 01:49
yansfil added a commit that referenced this pull request Oct 29, 2026
Closes with-hide/hide-private#37
Closes with-hide/hide-private#38
Closes with-hide/hide-private#307

## Summary

A resting Codex CLI was hard to wake and to write to.

- **#37, stray `9;5u` before the resume line.** Sleep pressed Ctrl+C
twice. Codex CLI quits on the first, so the second reached the shell.
Sleep now presses again only when the agent asks for it.
- **#307, letter stuck pending.** A bell whose reservation failed typed
nothing, yet waited for the pane to move. It now retries on the timer,
at most three bells.
- **#38, 429 read as failure.** A Codex CLI turn never answered, whose
conversation's newest retry is a 429, reads `not measured`. A check that
failed on its own beside that turn stays a failure.

스크린샷 없음: 화면을 바꾸지 않는 변경입니다 (셸 입력, 편지 재시도, journey 판정).

## Review

- **판단해 주세요**: the wake clears nothing from the shell's line before it
types. Two cases can still leave text there:
- a quit key the agent never read before the node ended it; only after
`agent_sleep.exit_keys_unanswered`, and no measured run reached it;
- a terminal's answer to the agent's query arriving after it exited;
never seen in a run.
- **판단해 주세요**: after a node end, Herdr keeps the agent's terminal modes
for the shell; filed as with-hide/hide-private#320 (Herdr upstream
report needed).
- **판단해 주세요**: Windows has no real-Herdr sleep-and-wake test (cell in
`docs/INSTALL.md`).
- Codex CLI 0.165.0 never turns the keyboard protocol on there: its
crossterm fork (`openai-oss-forks/crossterm` at `ed1cdab3`) answers
`PushKeyboardEnhancementFlags` with an unsupported error on a Windows
console.
- So a quit press reaches PowerShell as Ctrl+C, never as `ESC[99;5u`.
The press decision is the same code, with unit tests in the Windows
lane.
- **fish 4.9.3 `agent_pane_busy`, a fixture fault**:
- fish 4 runs its man-page completion generator (bash, Python) in its
own foreground group for about 3 s after its first prompt, unless
`~/.cache/fish/generated_completions` exists; fish 3 checked
`~/.local/share/fish`.
- The test sent its first `agent.start` without the shell wait every
product start has, and Herdr refused. It now starts through
`start_within`, and the fixture makes both folders.
- A product start waits on that state for up to 30 s (`SHELL_WAIT`). The
generator runs only on a user's first fish start; how long it takes over
a full set of man pages is not measured.
- **조심해서 볼 파일**:
- `herdr-core/src/agent_sleep_herdr.rs` - failure path: quit presses
follow the screen and the foreground group.
- `herdr-core/src/delivery/doorbell.rs` - failure path: only a failure
before `agent.prompt` retries on the timer.
- `scripts/agent_journey/cells.py`, `journey.py` - only a `NO_ANSWER`
verdict asks the provider log, and a start prefers any other failure.
- `herdr-core/src/agent_start/real_herdr_tests.rs` - the stand-in's
release (`Release`, `Watched`).
- **비용 검토**: sleep reads the screen every 100 ms while quitting, inside
its 5 s grace.

## Evidence

- **확인한 것**:
- Real Herdr 0.9.5: a stand-in Codex CLI (kitty keyboard on, quits on
the first Ctrl+C) is slept and woken by Hide.
- It hands its terminal back only when the test releases it: after the
sleep's screen read shows it quitting, or after a second press is
answered. No timer orders the steps.
- It reads its input a byte at a time up to the first whole Ctrl+C, so a
second press queued with the first stays for the shell.
- Old sleep: 10 of 10 fail (5 runs, zsh and bash), the wake running
`9;5ucodex resume slept-session`; also 10 of 10 when both presses are
queued before the stand-in reads (a local-only hold).
- New sleep: 15 of 15 pass (5 runs, zsh, bash and fish 4.9.3); Linux CI
runs zsh, bash and fish.
- Unit tests: a second press only on the agent's hint or an emptied
draft; an agent quitting on its first press gets one press.
- Unit test: a failed reservation rings again on the timer (0 bells
typed before the fix).
- Provider log: cursor boundary in the same second, another thread, a
later non-429 retry.
- Start composition: an emitter failure beside an unanswered turn and a
429 stays a failure (read `not measured` before the fix).
- Fake-model journey at 698b118, `codex` row alone (codex-cli
0.163.0): 12 of 12 cells; sleep ended Codex CLI by its own key (no
`exit_keys_unanswered`).
- **확인하지 못한 것**:
  - No real-Herdr sleep and wake on Windows (see Review).
- #307's original evidence was deleted; the cause was read from the
issue's log lines, not replayed.
  - No signed-in journey on Codex CLI 0.165.0 here, and no live 429.

<details><summary>Verification record</summary>

- base 047d094, head 2397a4e.
- CI run 40860922492 at 2397a4e, attempt 1: green, 41 pass, 3 skipping
(full run, `pr.yml` changed); `windows check` step "Agent sleep ends the
agent's process tree" 4 of 4, the three quit press tests included.
- CI run 40853614406 at f837d75, attempt 1: green, 21 pass, 10
skipping; `rust workspace` 5560 of 5560, real-Herdr shell step 10 of 10
(sleep and wake on zsh, bash and fish).
- CI run 40844861122 at 391c939: attempt 1 failed only `web e2e
windows`, in setup before any test (`spawnSync powershell.exe
ETIMEDOUT`); attempt 2 green, 21 pass, 10 skipping; `rust workspace`
5560 of 5560, real-Herdr shell step 10 of 10 (sleep and wake on zsh,
bash and fish).
- CI run 40839420249 at 698b118, attempt 1: green; `rust workspace`
5560 of 5560 tests, real-Herdr shell step 10 of 10.
- Local full `nextest -p herdr-core -p hide-agent-adapter`: not run
since 923c430 (3461 of 3461); the build at 698b118 hit a full disk,
and CI covers it.
- Python at 698b118: `test_agent_journey_provider_limit` and
`test_agent_journey_cells` 36 OK; `test_agent_live_protection` 53 OK
alone (it timed out in a full run while the disk filled).
- `fmt-check`, `clippy -p herdr-core --all-targets -D warnings` at
391c939: clean.
- Sleep and wake on real Herdr at f837d75: base sleep code 10 of 10
fail (zsh, bash, 5 runs each), and 10 of 10 with both presses queued
before the stand-in's first read; head 15 of 15 pass (zsh, bash, fish
4.9.3, 5 runs each). With that hold and 391c939's one-call read, the
base sleep passed 4 of 4, the hole the byte read closes.
- Sleep and wake on real Herdr at 391c939: base sleep code 10 of 10
fail (zsh, bash, 5 runs each); head 15 of 15 pass (zsh, bash, fish
4.9.3, 5 runs each); fish also passes with fish 4's marker folder
removed (7.4 s, the start waiting out the generator).
- Local fake-model journey, `codex` row, at 698b118: 12 of 12 pass.
- Review: letter-16881 addressed in 923c430 and ca3db1c;
letter-16914 in aed2c51 and 698b118; letter-16977 and letter-16979
in 391c939; letter-17055 in f837d75; the Windows lane runs the quit
press tests from 2397a4e.

</details>
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