Skip to content

Recover Herdr connections without replaying read work - #115

Merged
yansfil merged 4 commits into
mainfrom
fix/herdr-restart-recovery
Sep 20, 2026
Merged

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

Conversation

@yansfil

@yansfil yansfil commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Hide no longer dispatches the persisted pane restore against the initial disconnected snapshot, so relaunching does not present the internal "Waiting for the first herdr connection attempt" refusal as an operator modal.
The shell now probes the selected socket with the bundled Herdr CLI, starts one bundled server when needed, and retries recovery with a bounded five-attempt backoff after the server exits or the socket becomes unreachable.
The child server inherits the same Herdr session, config, state, and socket routing as the core.

Read records now survive a Herdr restart without turning every previously reviewed completion back into Done.
Eviction follows authoritative pane topology rather than the temporarily incomplete agent list, and a saved record is rebased only when the process-local sequence moved backwards while session identity, demand, and activity still match.

Review focus

  • 사람이 판단할 것: 이전 형식의 read record에는 session id가 없으므로, 최초 재연결 때 역행한 sequence와 동일한 demand/activity를 같은 세션의 충분한 증거로 보는 호환 정책이 적절한지 봐 주세요.
  • 위험한 파일: macos/Sources/HerdrMacOS/CoreBridge.swift의 복구 태스크 수명과 herdr-core/src/sidebar.rs의 read record 재조정 조건이 핵심입니다.
  • 리뷰어에게 묻는 것: 응답 중인 공유 Herdr 서버는 앱 종료 때 끄지 않고, 앱이 직접 띄운 서버가 비정상 종료한 경우에만 다시 보장하는 현재 소유 경계가 맞는지 확인해 주세요.

Risk surface

  • Runtime mutex: 연결 직후 read record 비교와 topology 기반 prune만 메모리에서 수행합니다. Herdr 상태 probe와 process launch는 runtime mutex 밖, Swift main actor 밖에서 실행합니다.
  • Snapshot wire: 기존 persisted UI state의 pane_read_records에 optional session_id를 추가합니다. 이전 state는 기본값으로 그대로 읽히며 새 wire 채널은 없습니다.
  • Ownership: Herdr가 pane topology와 agent session을 계속 소유합니다. shell은 연결 가능한 로컬 서버를 보장하고, core는 자신의 pane-level read axis만 재조정합니다.
  • Herdr contract: pinned 0.9.1 CLI의 status server --json만 추가로 호출합니다. socket API method나 generated schema field는 추가하지 않았습니다.
  • Failure path: protocol mismatch나 malformed responding server는 자동 교체하지 않습니다. 시작과 probe 실패는 기존 startup status와 structured launch trace에 남고, 복구는 최대 5회 뒤 멈춥니다.
  • High-frequency path: 입력당 추가 작업은 없습니다. read reconciliation은 fresh connection마다 한 번 시작되고 persisted ledger 크기로 제한되며, 서버 복구 태스크는 하나와 5회 시도만 허용합니다.

Evidence

  • 확인한 것: 최신 origin/main을 반영한 PR head 3108966에서 check-hide-full.sh가 통과했습니다. Rust workspace 577 passed, 0 failed, 6 ignored. Swift 496 passed, 0 failed. 필수 저장소 게이트, design contract 7개, script suite 38개, pinned Herdr 0.9.1 schema/full contract를 모두 통과했습니다.
  • 확인한 것: 기능 head 8246616의 격리 bundle 0.0.0-dev+8246616로 saved pane selection이 있는 cold launch를 실행했습니다. 앱 PID 98424가 private server PID 98476을 시작했고, 화면은 modal 없이 Connected to Herdr였습니다. PID 98476 종료 뒤 같은 앱 PID가 PID 7947을 시작해 다시 연결됐습니다. 앱 종료와 server SIGKILL로 실제 stale Unix socket을 남긴 뒤 재실행했을 때 앱 PID 11392가 server PID 11425를 시작했고, 다시 modal 없이 연결됐습니다. 운영 앱 PID 6282와 기본 Herdr 서버는 변경하지 않았습니다. 이후 합친 main의 21개 변경 경로는 이 PR의 18개 변경 경로와 겹치지 않았습니다.
  • 확인하지 못한 것과 그 이유: 실제 운영 세션의 기존 Done 18개를 대상으로 한 destructive restart는 사용자의 현재 panes를 건드리므로 실행하지 않았습니다. 대신 delayed agent detection, backwards sequence rebase, replacement session refusal, legacy record migration을 deterministic core tests로 검증했습니다. 최신 main 반영 뒤 native 시나리오는 경로가 겹치지 않아 다시 실행하지 않았고, 현재 head의 전체 build와 test로 통합 상태를 확인했습니다. /Applications/hide.app 설치와 release archive 검증도 이 PR에서는 실행하지 않았습니다.
  • 화면 증거: 아래 이미지는 기능 head 8246616의 isolated bundle과 private Herdr session입니다.

Cold launch with saved pane selection

Cold launch connects without the startup modal

Automatic reconnect after the private server exits

The same app process reconnects after replacing its private server

Relaunch with a real stale Unix socket

A stale socket is recovered without showing the startup modal

AI tooling

  • 사람이 직접 작성 - [ ] 일부를 AI 도구로 작성 - [x] 대부분을 AI 도구로 작성

손으로 확인한 것: 공식 Herdr CLI와 socket 계약, 최종 diff, 정확한 앱/server PID, 세 번의 native 화면 상태, 운영 앱과 기본 서버의 보존을 직접 대조했습니다.

@yansfil
yansfil merged commit eb78a0e into main Sep 20, 2026
5 checks passed
@yansfil
yansfil deleted the fix/herdr-restart-recovery branch September 20, 2026 02:55
yansfil added a commit that referenced this pull request Oct 29, 2026
…lakes (#1819)

Closes with-hide/hide-private#304
Closes with-hide/hide-private#305

## Summary

부하에서 가끔 깨지던 Rust 테스트 두 건의 원인을 고칩니다. 같은 묶음의 나머지 세 건은 이슈별로 아래에 적었습니다.

- **#304 OpenCode 사용량 읽기**: 읽기가 10 ms 시간 예산을 첫 행을 읽기 전에도 검사해서, DB를 여는 데
그 시간을 넘기면 행을 하나도 읽지 않고 끝났습니다. 이제 예산은 둘째 행부터 검사합니다(줄 파일 읽기와 같은 규칙). 그래서
읽기는 언제나 전진합니다. 테스트는 시간 예산이 자를 수 있는 정확한 개수(첫 읽기 2행) 대신, 읽기마다 scan total
이하(3 MiB 행 2개), 더 남은 읽기는 1행 이상, 전체 4행을 단언합니다.
- **#305 늦게 세션을 보이는 자식의 bind**: 테스트가 session sync 대신 lineage writer를
관찰시키는데, 세션이 보인 뒤 한 번만 관찰시킵니다. writer는 이전 batch가 아직 worker에게 넘어가지 않았으면 그
관찰을 다음 관찰에서 처리하므로, 부하에서 worker가 늦으면 bind가 계획되지 않았습니다. 테스트가 이제 at-rest
batch를 worker가 가져간 뒤에 세션을 보이게 합니다.
- **#174** links_store_busy: main의 1a90d50(#1567)가 이미 고쳤고 그 뒤 재발이 없어
근거와 함께 닫았습니다.
- **#134** agy signed in: 그 lane은 ff9b090(운영자 결정 10-27)로 CI에서 빠졌고, 남은
agy contract는 세 OS 모두 통과해 닫았습니다.
- **#115** perf topology 'Build the web shell': main에서도 다시 실패합니다(원인: 웹
타입검사 시간이 catalog와 함께 커짐). 고치는 방식을 conductor에게 묻는 중이라 이 PR에는 아직 없습니다.

스크린샷 없음: 화면을 바꾸지 않는 테스트와 읽기 경로 변경입니다.

## Review

- **판단해 주세요**: #305를 제품이 아니라 테스트에서 고친 판단. 운영에서는 subscription이 살아 있는 동안
session sync가 1초마다 `agent.list`를 묻고 답마다 `writer.observe`를
부릅니다(`session_sync/coordinator.rs` 318-322행, 825-836행). 미뤄진 관찰은
`pending_retry`로 남아 다음 관찰이 바뀐 것 없이도
계획하고(`a_full_pending_batch_is_retried_without_duplicating_in_flight_patches`),
재연결은 `changed=true`로 다시 관찰합니다. 그래서 운영에서 미룬 관찰을 잃지 않고, 관찰을 한 번만 하는 쪽은
테스트였습니다.
- **판단해 주세요**: #304 테스트의 기대값 변경. 요구(scan total을 넘는 행은 다음 읽기가 읽는다)는
그대로이고, 시간 예산이 자를 수 있는 정확한 개수를 단언하던 테스트가 요구를 잘못 표현했던 것입니다. 시간 예산(10 ms)은
바꾸지 않았습니다.
- **조심해서 볼 파일**: `hide-session/src/usage/opencode.rs` - 사용량 읽기
경로(high-frequency path). 행마다 하는 일은 그대로이고, 첫 행에서 시간 검사 하나를 건너뜁니다.
- **조심해서 볼 파일**: `herdr-core/src/coordination/lineage.rs` - 테스트
전용(`#[cfg(test)]`) 조회 하나만 더했습니다.

## Evidence

- **확인한 것**: #305는 worker가 batch를 가져가기 전에 300 ms 지연을 심어 이슈와 같은 실패(`timed
out waiting for the core binds the late child`)를 재현했고, 수정한 테스트는 같은 지연에서
통과했습니다. 지연은 되돌렸습니다.
- **확인한 것**: #304는 scan total을 끄는 결함을 심으면 새 테스트가 `read 1 took 4 rows`로
실패하는 것을 확인하고 되돌렸습니다.
- **확인한 것**: `scripts/verify-cargo.sh nextest -p hide-session -p
herdr-core` 3796개 통과, `scripts/verify-cargo.sh lint`(fmt, clippy 전체) 통과.
로컬 load average 15-80, 디스크 98%.
- **확인한 것**: `nightly.yml` lane=agy를 main 047d0944d에서 dispatch, agy
contract와 agent trust contract 6개 job 모두 통과(run 40803128207).
- **확인하지 못한 것**: `perf.yml` dispatch(run 40803125317)는 main에서 'Build the
web shell'이 5분을 넘겨 실패합니다(#115, 위). 이 PR은 그 lane을 고치지 않았습니다.
- **확인하지 못한 것**: #304의 "첫 행은 항상 읽는다"는 시계를 주입할 수 없어 결정적인 테스트가 없습니다. 부하에서만
새 단언(더 남은 읽기는 1행 이상)이 그 결함을 잡습니다.

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

- base 047d094, head 7feb3b2

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