Skip to content

Recover Herdr and delegation lineage after a reboot - #257

Merged
yansfil merged 4 commits into
mainfrom
quick/herdr-restart-recovery
Sep 29, 2026
Merged

yansfil merged 4 commits into
mainfrom
quick/herdr-restart-recovery

Conversation

@yansfil

@yansfil yansfil commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary

재부팅 후 앱이 Herdr 없이 떴습니다.
Herdr 서버를 켜는 곳이 없었고, hided는 남은 herdr.sock에 연결 거부를 반복했습니다.
위임 계보도 사라졌습니다.
Herdr는 서버를 재시작하면 pane 토큰을 복원하지 않습니다.
hcoord는 데몬 시작 때 한 번만 토큰을 다시 썼는데, 그 시점에는 Herdr가 아직 없었습니다.

  • 패키징된 앱이 hide connect 전에 번들 herdr status server --json으로 확인합니다.
    • running:false일 때만 herdr server를 분리 실행하고, 최대 5초 동안 응답을 기다립니다.
    • 재부팅 뒤 남은 소켓도 not_running으로 답합니다.
    • 응답하는 서버는 건드리지 않습니다.
    • 개발 호스트와 HERDR_BIN_PATH를 명시한 실행은 서버를 켜지 않습니다.
    • 앱을 종료해도 서버는 계속 돕니다.
  • hcoord는 계보 복구를 시작할 때 한 번이 아니라 타이머로 합니다.
    • 등록된 자식을 가진 Herdr 서버마다 pane list를 한 번 호출합니다. 이 Mac은 5초, 원격은 60초 간격입니다.
    • 살아 있는 자식 중 토큰을 잃은 pane에만 씁니다.
    • hide는 지금처럼 토큰만 읽습니다.
  • Finder로 연 앱에는 locale이 없습니다. 그래서 앱이 켜는 서버에는 LC_CTYPE=UTF-8을 줍니다. 이 값이 없으면 zsh가 "한글"을 6바이트로 셉니다.

Review

  • 판단해 주세요: 앱이 붙어 있는 동안 죽은 Herdr는 다시 켜지 않습니다. Retry나 Dock 클릭 때만 켭니다. 이 범위가 맞는지.
  • 판단해 주세요: 계보 확인 주기.
    • 이 Mac은 5초라서 분당 herdr pane list 12번입니다.
    • 원격은 60초라서 hcoord 작업 큐 안에서 분당 SSH 1번입니다.
  • 조심해서 볼 파일: desktop/src/main/spawn.ts startDetached.
    • 호스트가 띄우지만 소유하지 않는 유일한 자식입니다(ownership, process practice).
    • 터미널에서 herdr가 띄운 서버처럼, 일부러 앱보다 오래 삽니다.
  • 조심해서 볼 파일: desktop/src/main/host.ts ensureHerdrServer.
    • failure path입니다. 모든 실패는 로그로만 남기고 연결은 그대로 진행합니다.
  • 조심해서 볼 파일: plugins/hcoord/src/hcoord/transport.ts reconcileLineage.
    • 직렬화된 작업 큐 위에서 Herdr를 동기 호출합니다. high-frequency path입니다.
  • 질문: 앱이 켠 서버는 hide.app이 띄운 프로세스입니다. 그래서 pane 안 프로세스의 macOS 개인정보 권한 창에 터미널 대신 hide가 뜰 수 있습니다. 괜찮은지.

Evidence

  • 확인한 것: 패키징 후보를 env -i로 격리해 실행했습니다.
    • 환경은 launchd 같은 PATH에 locale 없음, HOME·소켓·state·profile·hcoord는 모두 격리했습니다.
    • 저장된 세션과 남은 소켓 파일을 미리 둔 상태에서 시작했습니다.
    • 결과:
      • discovery 시작 219ms 뒤 herdr.server_started가 기록됐고, hided가 붙었습니다.
      • 서버 환경에 LC_CTYPE=UTF-8이 있었고, 서버는 자기 프로세스 그룹에서 돌았습니다.
      • 저장된 Claude Code pane이 claude --resume <id>로 resume됐고, 창에 복원된 프로젝트와 에이전트가 보였습니다.
      • 앱을 SIGTERM으로 종료한 뒤에도 서버는 살아 있었습니다.
  • 확인한 것: 격리 서버로 헤드리스 herdr server를 띄워 봤습니다.
    • 클라이언트가 하나도 붙지 않아도 복원된 에이전트가 resume됩니다.
    • 그래서 앱이 서버를 켜기만 해도 충분합니다.
  • 확인한 것: hcoord를 격리된 실제 Herdr 0.9.1에서 돌렸습니다.
    • 데몬이 도는 중에 Herdr를 재시작하면 첫 패스(0초)에 토큰이 돌아왔습니다.
    • Herdr가 꺼진 상태에서 데몬을 시작하면 stderr 1줄만 남고 ledger 이벤트는 0건이었습니다. Herdr가 응답한 지 3초 뒤 토큰이 돌아왔습니다.
  • 확인한 것: hcoord e2e에 테스트를 추가했습니다.
    • 데몬 시작 때 Herdr가 꺼져 있어 지워진 토큰이 복구되는지 봅니다.
    • 이미 맞는 토큰을 다시 쓰지 않는지도 봅니다.
    • 이전 코드에서는 실패합니다.
  • 확인한 것: 같은 격리 실행을 최종 head로 다시 했습니다.
    • 이번에는 pane에서 연 것처럼 HERDR_PANE_ID와 없는 HERDR_BIN_PATH를 넣었습니다.
    • 서버 환경에는 HERDR_SOCKET_PATH와 LC_CTYPE=UTF-8만 남았습니다.
    • 314ms 만에 서버가 떴고, 에이전트가 resume됐고, 앱을 종료한 뒤에도 서버가 살아 있었습니다.
  • 확인한 것: 최종 head에서 bash scripts/verify-web.sh가 통과했습니다. hcoord unit 30, hcoord e2e 27, web 515, desktop 60개입니다.
  • 확인한 것: 게이트 check-no-workstation-identity, check-harness-ignore-anchor, check-agent-asset-committed, check-herdr-pin-single-source, check-no-attribution이 통과했습니다.
  • 확인하지 못한 것: 이 Mac을 실제로 재부팅하고 로그인하는 것.
  • 확인하지 못한 것: pnpm --dir desktop e2e와 pnpm --dir web e2e는 로컬에서 돌리지 않았습니다. CI가 돌립니다.
    • 디스크가 97%였고 다른 worktree들이 빌드 중이었습니다.
    • Rust 변경은 없습니다.
  • 확인하지 못한 것: 원격(mini) Herdr 재시작.
    • 60초 원격 경로는 코드 읽기와 공유 route 코드로만 확인했습니다.
추가 증거

2026-09-29 재부팅 직후 운영 머신에서 본 것:

hided core.jsonl: connect.failed ... herdr.sock: Connection refused (os error 61) × 1,241
hcoord ledger:    lineage.reconciled {scanned: 39, filled: 0, failed: 39} at 05:33:51Z (Herdr 시작 05:36:00Z)
session.json:     pane마다 cwd와 agent_session만 저장; Socket API "Token metadata is not restored after a server restart."
리뷰 처리
  • 코드 리뷰와 요구 충실도 리뷰를 별도로 돌렸습니다.
  • 반영한 것:
    • 서버 시작 순서를 ensureServer로 분리하고 분기마다 테스트했습니다.
    • 서버 환경에서 pane 값(HERDR_BIN_PATH, pane·tab·workspace id, HERDR_ENV)을 뺐습니다.
    • 시작 대기 중 status 호출은 남은 시간만 쓰도록 했습니다.
    • ARCHITECTURE의 CLI 문단에 남아 있던 옛 문장을 고쳤습니다.
    • 세션 없는 자식은 재시작 뒤 다시 잇지 않는다는 점을 문서에 적었습니다.
  • 반영하지 않은 것:
    • "status exit code 미확인": not_running도 exit 0이고, 격리 실행에서 실제로 서버가 켜졌습니다.
  • 후속으로 남긴 것:
    • 부모 pane의 생존 확인. 이전 코드도 하지 않았습니다.
    • 건너뛴 자식을 세는 카운터.
    • 원격 60초 경로와 쓰기 재시도 테스트.

AI tooling: 대부분 AI 도구. 원인은 로그와 격리 실행으로 손으로 대조했습니다.

Herdr drops pane tokens when its server restarts, and after a reboot the
hcoord daemon can start minutes before Herdr, so its startup-only repair
failed for every child and left them roots. The daemon now reads each
route holding a child with one pane list on a timer (5 s local, 60 s
remote) and writes the tokens only to a live child that lost them.
After a reboot nothing starts Herdr, and hided only reads a missing
server as absent, so the app opened to an empty shell. Before each
connect the packaged host asks its bundled herdr for the server status
and starts herdr server detached when none is running, with a UTF-8
character type when Finder gave it no locale. A server that answers is
never touched, and development or override runs start nothing.
The start decision moves into ensureServer so its branches are tested
without Electron: a running server is left alone, an unreadable status
starts nothing, one start is made and waited for. The CLI and daemon
paragraph no longer says nothing starts a server, and the token doc
says a sessionless child is not linked again after a restart.
Herdr sets its own binary path and pane identity in every pane, so the
server the app starts no longer inherits the host's copies of them. A
status poll during the start wait may only use what is left of the wait,
so a hung call cannot hold up the connect.
@yansfil
yansfil merged commit cfdd368 into main Sep 29, 2026
8 checks passed
@yansfil
yansfil deleted the quick/herdr-restart-recovery branch September 29, 2026 06:36
@yansfil yansfil mentioned this pull request Sep 29, 2026
yansfil added a commit that referenced this pull request Sep 29, 2026
Related: PRD `agents/prd/device-parity/prd.md` · follows #257 (bundled
Herdr server start) and meets #255 (subtree close)

## Summary

- 지금까지 hide CLI 링크, Claude Code·Codex hook, 라벨 플러그인, hcoord는 기계마다 따로 맞춰야
했고 SSH 기기는 helper만 받았다.
- 이제 설치 kit 하나(`hide-kit`)가 같은 구성요소를 이 Mac에는 설치된 앱의 첫 실행에, 각 기기에는 연결 때
묻지 않고 설치한다.
- 업데이트, 운영자가 지운 구성요소(다시 설치 전까지 그대로), 기기 삭제(hcoord만 남김)가 이 Mac과 기기에서 같은
규칙이다.
- Settings > Devices는 기계마다 구성요소별 상태와 위치를 보이고, 문제가 있는 행에만 Reinstall이 있다.
Agents 탭은 기계별 hook 행을 보인다.
- 기기의 agent pane은 로컬과 같은 함수로 계측을 판정한다(그 pane의 hook token과 그 기기의 kit). 기기
Memory는 범위 밖이다.

![기기 행: 운영자가 지운 Claude Code hook은 이유와 함께 '지워짐'으로 남고, 문제가 있는 이 행에만
Reinstall이
생긴다](https://github.com/yansfil/pr-assets/blob/main/hide/device-parity/f3fac04/device-kit-removed-part.png?raw=true)

## Review

- **이번 머지의 동작**: 이 Mac의 kit는 실행 중인 앱 번들을 원본으로 쓴다. `/Applications` 위치 제한은
별도 보안 검토 대상으로 남긴다.
- **이번 머지의 동작**: 같은 계정에 다른 기기 등록이 있으면 kit를 유지하고 확인창에 이유를 표시한다. 마지막 등록을
지울 때 제거한다.
- **기존 결정 D-13**: 계약 2로 허용한 기기는 다음 연결에 kit 전체를 받는다. 과거 동의 문구에는 hook과 설정
변경이 없었다는 점은 Breaking change에 명시했다.
- **남은 제약**: 두 Mac이 같은 기기 계정에 kit를 적용하면 마지막으로 실행한 kit가 hook과 링크를 소유한다.
계정 lock은 동시 쓰기만 막는다.
- **조심해서 볼 파일**: `hide-kit/src/lib.rs` - 운영자 설정 파일과 LaunchAgent를 바꾸는 유일한
경로(계정 lock, private 폴더).
- **조심해서 볼 파일**: `hide-agent-hooks/src/install.rs` - 운영자 설정 파일 쓰기의
failure path(mode와 symlink 보존, 임시 파일).
- **조심해서 볼 파일**: `herdr-core/src/runtime/kit.rs` - runtime mutex 밖
worker, 늦은 응답, 기기 삭제 순서와 helper 연결 종료.
- **조심해서 볼 파일**: `herdr-core/src/remote/host.rs` - 한 계정에 두 연결이 동시에 올리는
경합과 private 폴더.
- **조심해서 볼 파일**: `herdr-core/src/runtime/device_catalog.rs` - regroup마다
lineage pass를 다시 돈다(#255와 만나는 곳, mutex 안의 일).
- **조심해서 볼 파일**: `desktop/src/main/host.ts` - hcoord 준비 제거(kit 소유), 창은
status page 로드가 끝난 뒤에 shell을 연다.
- **조심해서 볼 파일**: `herdr-core/src/model.rs`,
`contracts/snapshot-wire-enums.json` - snapshot wire의
`DeviceSnapshot.kit`.

## Evidence

- **확인한 것**: 격리 sshd(비루트, 세션마다 private HOME과 HCOORD_HOME)로 실제 SSH 연결: 연결
한 번에 다섯 구성요소가 설치됐다.
- **확인한 것**: 같은 연결에서 다른 도구의 hook과 설정 키가 그대로였고, 기기 pane의 설치된 SessionStart
hook이 Workspace 안내를 내고 Memory capsule은 없었다.
- **확인한 것**: 운영자가 지운 Claude hook은 '지워짐'으로 남았다가 Reinstall이 그것만 되살렸고, 삭제는
설정 파일을 원래 바이트로 돌리고 hcoord를 남겼다.
- **확인한 것**: 한 계정의 두 등록이 동시에 연결해 둘 다 설치됐고, 첫 삭제는 kit를
남기고(`device.kit_left`) 마지막 삭제가 걷어냈다.
- **확인한 것**: 패키지된 hide.app의 hided를 private HOME으로 실행하면 첫 실행에 다섯 개를 설치하고,
두 번째 실행은 설정 파일 mtime을 바꾸지 않았다(3회 반복).
- **확인한 것**: 전체 desktop e2e 26/26(merge 뒤), device-kit과 remote-workspace
3/3(검증 head), cargo test와 lint, verify-web, scripts, design contract 통과.
- **확인한 것**: 모든 실행에서 운영자의 hcoord daemon pid가 그대로였고, 실제 `~/.claude`,
`~/.codex`, `~/.local/bin`, `~/.hcoord`, `/Applications/hide.app`은 건드리지
않았다.
- **확인하지 못한 것**: mini가 계약 2 동의에서 kit로 올라가는 실제 연결(merge와 설치 뒤에 일어난다, 코어
테스트만 있다).
- **확인하지 못한 것**: Linux 기기(단위 테스트만, hcoord는 macOS에서만 설치), GitHub로 설치된 라벨
플러그인을 넘겨받는 경로(가짜 socket 단위 테스트만).
- **확인하지 못한 것**: 재부팅 뒤 hcoord daemon이 kit 첫 pass에서 올라오는 순서(#257과 만나는 곳),
`/Applications` 설치본 교체(운영자 소유라 하지 않았다).
- **확인하지 못한 것**: `github::tests`의 1초 deadline 테스트가 부하(load 9~13)에서 네 번
실패했다. 이 브랜치가 건드리지 않은 모듈이고 단독 실행은 통과했다.

<details><summary>추가 증거</summary>

![This Mac 행: 패키지된 앱의 hided가 격리 HOME에 첫 실행 kit 다섯 구성요소를 묻지 않고
설치했다](https://github.com/yansfil/pr-assets/blob/main/hide/device-parity/f3fac04/this-mac-kit.png?raw=true)

![Settings > Agents: 기계마다 hook 행, This Mac 먼저 그다음 기기 (이 캡처의 This Mac은 개발
빌드라 설치하지 않는 이유를
보인다)](https://github.com/yansfil/pr-assets/blob/main/hide/device-parity/f3fac04/agents-hooks-per-machine.png?raw=true)

![기기 삭제 확인: 기기에서 지울 항목과 남길 hcoord를 말하고, 버튼 이름이
결과다](https://github.com/yansfil/pr-assets/blob/main/hide/device-parity/f3fac04/device-remove-confirm.png?raw=true)

- 창 navigation 경합: status page 로드 10~30 ms 뒤에 shell을 열면 Electron 44가 빈
code로 실패를 보고했다(20번 중 8번, 3번). 창은 shell에 도착했지만 Playwright가 멈췄다. 지금은 한 번에
하나만 연다.
- 공유 머신 부하에서 remote-workspace의 hook 65회 반복 검사가 한 번 16번째에서 멈췄고, 단독 재실행은
통과했다(이 브랜치는 hook 버전 문자열만 바꿨다).

</details>

## Breaking change

- 설치된 앱은 실행마다 운영자 홈의 kit를 맞춘다. 전에 한 번 쓰던 hook(이제 v6)과 hcoord에 더해
`~/.local/bin/hide` 링크, Herdr 플러그인 `hide.agent-context-labels`,
`~/.hide/kit/`가 새로 생긴다.
- 예전 `~/.hide/agent-hooks/installed-once` 표시는 설치 기록으로 보지 않아서, Hide hook이
없는 기계는 다음 실행에 hook을 받는다.
- 같은 id로 GitHub에서 설치했거나 checkout에서 link한 라벨 플러그인은 kit 복사본으로 바뀐다(플러그인
config는 남는다).
- 동의가 있는 기기(계약 2 포함)는 다음 연결에 같은 kit를 받는다. helper protocol은 10이고 helper는
연결 때 스스로 바뀐다.
- 이 Mac의 kit를 한 번에 걷어내는 명령은 없다. 운영자가 지운 구성요소는 다시 설치하기 전까지 그대로 둔다.

**AI tooling**: 대부분 AI 도구. 사람이 손으로 대조한 것은 아직 없고, 이 PR의 리뷰가 그 대조다.

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

- PRD: `agents/prd/device-parity/prd.md` (sha256
f197c2cdf41e26a237da0d79a195e42f15cc67d6df57eed17cd63789b3d9a294)
- Base efb51d1 → head 755839b, verified 2026-09-29T10:00:10.099Z: PASS
- Verification report:
`agents/runs/device-parity/verification-report.json` and
`agents/runs/device-parity/verification-report.md`; source fingerprint
9e6c848822e7523665bf50ded685362f4e9d9c8df0e12c639c228a52a4e91239
- Suites:
  - S1: GREEN `bash scripts/verify-cargo.sh test` (exit 0)
  - S2: GREEN `bash scripts/verify-cargo.sh lint` (exit 0)
- Reviews: advisory, native subagents, six feature review sets through
f3fac04, plus Fidelity, Code and Security follow-up reviews on verified
merge head 755839b; no new actionable findings.
- Fidelity (afe113d): Fix now 1, removing one of two registrations of
one account kept the kit, a B23/D-16 departure; kept as a recorded
deviation with tests and e2e. Fix now 2, an unread device kit judged
hooks not installed; fixed 9a636c6, 749e095. Later heads: none.
- Code (afe113d): Fix now 1 unread kit judged not installed, fixed
9a636c6/749e0959; 2 concurrent uploads of one account, fixed 6069955,
17108b0, 91354b0; 3 a late answer brought back a removed device, fixed
749e095; 4 hcoord failed on Linux, fixed f5155fb. 5382042: Fix now 1,
a regrouped device session dropped its agents' lineage that #255's
subtree close waits on, fixed f3fac04 with a regression test. Other
heads: none.
- Security (afe113d): Fix now 1 hook file mode and symlink replaced,
fixed 0496815; 2 this Mac's kit runs from any app bundle, left for
human judgment (see Review); 3 kit folders not private, fixed 68f8bc9.
Later heads: none.
- Follow-ups (not in this PR): a lineage pass on every device regroup
even when nothing regrouped; a bounded status page wait; `.upload-*`
leftovers after a crash; contract-2 carry with an unbound identity;
hcoord shim ownership marker; relative PATH candidates; labels dev-link
undo; `process.rs` kill/join order; digest-only reuse and payload caps
before read; Herdr-down retry of labels; corrupt record healing; a lost
Reinstall not requeued; blocked rows offering Reinstall; removal dialog
default focus; two Macs sharing one device account; the `github::tests`
1 s deadlines under load.
- Evidence: 7 registered (4 screenshot, 3 log); paths are local to the
run directory
  - agents/runs/device-parity/evidence/this-mac-kit.png
  - agents/runs/device-parity/evidence/agents-hooks-per-machine.png
  - agents/runs/device-parity/evidence/device-kit-removed-part.png
  - agents/runs/device-parity/evidence/device-remove-confirm.png
  - agents/runs/device-parity/evidence/e2e-desktop-all-0ac13a23.log
  - agents/runs/device-parity/evidence/device-kit-daemon.jsonl
-
agents/runs/device-parity/evidence/device-kit-two-registrations-daemon.jsonl
- Changed paths: 172 (see Files changed)

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