Skip to content

Read every project's pull requests from the start and keep the last answer across restarts - #407

Merged
yansfil merged 2 commits into
mainfrom
fix/sidebar-pr-state-on-start
Oct 4, 2026
Merged

yansfil merged 2 commits into
mainfrom
fix/sidebar-pr-state-on-start

Conversation

@yansfil

@yansfil yansfil commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Closes #391 (part of #390). Rebased over #408 (two-call PR query, head-commit linking); this PR does not change the query or the linking rule.

Summary

After a daemon restart the sidebar drew every worktree as a plain branch until Overview or the palette asked for that project, because the core read GitHub only for the focused project and a memory-only set those screens filled, and kept nothing on disk.
Now the core reads GitHub for every local Git project on its own once a window is attached, asks again five minutes after a project's last answer, and saves the last successful answer to github-snapshot.json in the state folder.
A restart restores that file as stale, so the first frame already draws the previous run's pull requests, muted, until the first read replaces them.
A failed read still keeps the last value, now across a restart too.
No UI change: the same icons appear without the screens that used to be needed to ask for them.

before: restart -> rows show branch glyph (no answer, nothing on disk) until Overview / palette asks
after:  restart -> rows show pull request glyph, muted as stale; first read replaces it; gh down keeps it

Review

  • Please judge: the cap of 64 projects read (GITHUB_PROJECT_LIMIT). Past it the project in front is read first, then projects a screen named with github_request/overview_refresh, then the rest by path; the count is logged as projects.over_limit. A project left out shows no PR icon.
  • Please judge: the five minutes count from a project's answer, not from the ask. Counted from the ask, a pass over many slow projects would be overtaken by its own next ask (the answer is dropped when its request moved) and never land. A project whose ask is unanswered is not asked again.
  • Files to watch: herdr-core/src/github_store.rs - the file keeps what the wire omits (head_oid, cross_repository, created/closed times) so a settled pull request reconnects to its worktree after a restart; a new skip_serializing field on PullRequestSnapshot must be added there (the round-trip test builds the type literally, so it fails to compile). New off-lock writer: one thread, one pending slot, hide_platform::fs atomic replace, joined on drop; a file that is unreadable, damaged or of another schema version is discarded with a snapshot.discarded diagnostic.
  • Files to watch: herdr-core/src/runtime/projects.rs - github_request, reread_stale_github, ingest_github_answer. An empty answer to an empty request is ignored so a navigator that has not arrived cannot erase the restored answer or its file.
  • Files to watch: herdr-core/src/handle.rs - the file is read before the runtime lock is taken; no I/O under Mutex<Runtime> (check-capability-readers-off-lock.sh passes).
  • Cost review: no new thread besides the store's. Per coordinator wake the added work is a comparison of at most 64 instants under the lock, and one snapshot clone after an answer that changed something; a gh pass happens per due project every 5 minutes only while a window is attached (the reader stays in the UI-attached block). Ledger row added to docs/PERFORMANCE_TESTING.md.
  • Known gap: if a first answer lands while only part of the navigator exists, projects not yet there drop out of the saved file until their next read. Only a wholly empty request is guarded.

Evidence

  • Confirmed: lint and test for the whole workspace pass on the rebased head (herdr-core lib 1267 passed); the capability-readers-off-lock, workstation-identity and harness-anchor gates pass; web lint, typecheck and build pass.

  • Confirmed: the 16 new Rust tests (runtime/tests/github_reads.rs, github_store.rs) ran 20 times in a row with no failure; they use injected Instants, a temp folder and no gh, network or sleep. One of them covers Read PR checks for open PRs only and attach settled PRs by commit #408's rule: a merged pull request plus a worktree on its head commit, saved, restored in a new runtime, attaches to the worktree, and stops attaching when the head moves. They cover the request set (local Git only, path order), the five-minute cycle including the unanswered-ask case, the cap, loading ending for a project the reader returns nothing for, restore as stale with last_success_at_unix_ms kept, a failed read keeping the restored value, and damaged or other-version files.

  • Confirmed: new web/e2e/sidebar-pr-start.spec.ts ran 20 times in a row, no failure, on an isolated pinned Herdr and hided with a fake gh that answers both of the reader's pr list calls (two repositories, neither the project in front). Each start resumes on a Workspace with the right panel on Explorer; no Overview, project Overview or palette opens, and the page's wire carries only terminal and usage-hint events, asserted as zero github_request and zero overview_refresh. Start 1: both rows draw their lifecycle. Start 2 (gh down): both draw muted as stale. Start 3 (gh back): both replace it, all without any screen asking. With the snapshot file deleted before the restart the spec fails.

  • Confirmed: the new cap-priority tests (project in front, screen-named project, a named project that is no longer registered) are part of the 20 repeated runs of the Rust tests, 10 in github_reads.rs, 5 in github_store.rs and 1 in runtime/tests/pull_requests.rs.

  • Not confirmed: real gh against this repository and a packaged app. The e2e uses a fake gh and an isolated daemon; /Applications/hide.app and the operator's daemon were not touched.

  • Not confirmed: a first pass over many slow projects publishes only when the whole pass finishes, so a large first pass can take a while to fill the sidebar; no timing was measured.

  • CI note: e2e/overview-modal.spec.ts:7 failed in the first CI run (toBeFocused after the Overview modal closes). Under the same CPU load (6 busy loops, 3 workers, --retries 0) origin/main failed 6/30 and this branch 7/30; an earlier smaller run was 1/15 on main and 3/15 here. Failures are focus-handoff steps (lines 92 and 100) and several failing pages show the shell reconnecting. It reproduces on main, so this change is not its cause; it is not fixed here.

  • hide-platform a_burst_is_bounded_and_ends_in_an_overflow_rather_than_silence and only_a_guarded_launch_returns_startup_proof failed in local full runs while other jobs loaded the machine; this PR does not touch hide-platform.

Verification record
  • Review subagent, Fix now: a re-read counted from the ask could starve a slow pass; per-project read state was never pruned; four doc sentences contradicted the code; a stale e2e comment. All fixed. Follow-up not done: a drop guard for a panicking save worker, an Arc instead of a clone under the lock, partial-navigator saves.

@yansfil
yansfil force-pushed the fix/sidebar-pr-state-on-start branch from 1dc521a to c46da25 Compare October 4, 2026 17:53
…every five minutes, and keep the last answer across restarts

The sidebar row's pull request state no longer waits for Overview or the
palette to ask for a project. The core reads all local Git projects (the
project in front and screen-named ones first, at most 64, past that is
logged), asks again five minutes after a project's last answer, saves the last
successful answer to github-snapshot.json in the state folder off the runtime
lock, and restores it as stale when the daemon starts.
@yansfil
yansfil force-pushed the fix/sidebar-pr-state-on-start branch from c46da25 to e22aedc Compare October 4, 2026 18:21
@yansfil
yansfil merged commit 16e4f7c into main Oct 4, 2026
32 checks passed
@yansfil
yansfil deleted the fix/sidebar-pr-state-on-start branch October 4, 2026 18:35
yansfil added a commit that referenced this pull request Oct 5, 2026
…522)

Related: #390 (PR 상태와 worktree 정리), #407, #411

## Summary

agent가 연 PR이 사이드바 체크아웃 행에 붙기까지 최대 5분이 걸렸습니다. 프로젝트의 GitHub 재조회가 직전 응답 5분
뒤에야 다시 돌기 때문입니다.
이제 label worker가 agent 대화 기록에서 이미 추출하던 PR 주소를 신호로 씁니다. core의 GitHub 응답에
없는 주소가 보이면, 그 PR을 소유한 프로젝트를 기존 reader의 generation bump로 곧바로 다시 읽습니다.
push 시점은 트리거로 쓰지 않았습니다. push가 `gh pr create`보다 먼저라서 그때 읽으면 PR이 아직 없습니다.
대화 기록은 agent 상태가 바뀔 때 읽히므로, 늦어도 그 agent의 턴이 끝날 때 반영됩니다.

화면 구성은 바뀌지 않습니다. 기존 PR 글리프가 더 일찍 붙을 뿐이고, 이 조회 동안에는 `loading`을 띄우지 않습니다.

## Review

- **판단해 주세요**: 프로젝트는 같은 `owner/name`의 PR을 가진 프로젝트로 고릅니다. 그런 프로젝트가 없으면
주소를 출력한 pane의 프로젝트(다른 저장소의 PR이 없을 때만)를 씁니다. fork 체크아웃에서 upstream으로 연 PR은
다시 읽지 않습니다.
- **판단해 주세요**: 주소 하나당 추가 조회는 출력 후 15분 안에 한 번만 합니다. 200개 목록 밖의 PR이나 다른
저장소의 PR 때문에 같은 조회가 반복되지 않게 하려는 것입니다.
- **조심해서 볼 파일**: `herdr-core/src/runtime/projects.rs` - failure path.
응답을 아직 받지 못한 조회(5분 주기, 새로고침, request view, 앞선 sighting)가 있으면 앞질러 읽지
않습니다. 그 응답이 PR을 담고 있지 않을 때만 한 번 더 읽고, 연속 실패 중인 프로젝트는 읽지 않습니다. 앞질러 읽으면
`publish_github`가 진행 중이던 응답을 통째로 버립니다.
- **조심해서 볼 파일**: `herdr-core/src/session_sync/coordinator.rs` - runtime
mutex. `exchange_pull_requests`는 lock 구간 하나로 sighting을 넘기고 PR 시각을 받아
옵니다. 시각은 lock 밖에서 읽고, sighting이 없으면 하는 일이 새로 생기지 않습니다.
- **비용 검토**: sighting이 있을 때만 lock 안에서 메모리 작업이 늘어납니다(주소당 맵 조회와 프로젝트 1회
스캔). 상한은 worker 대기 32개(초과 시 `read.sighted_capped`)와 기억 주소 64개(초과 시
`read.sighted_over_limit`)입니다. 소유자가 없는 주소는 자리를 차지하지
않습니다(`read.sighted_unowned`). `docs/PERFORMANCE_TESTING.md` GitHub 행을
갱신했습니다.
- **질문**: 메뉴 PR 새로고침과 request view의 check 재조회도 진행 중인 조회를 앞지를 수 있습니다(같은
응답 폐기). 이번 범위 밖이라 그대로 뒀는데, 이슈로 남길까요?

## Evidence

- **확인한 것**: runtime 테스트로 다음을 확인했습니다.
  - 소유 프로젝트 매핑과 첫 PR 매핑.
  - 응답을 기다리는 조회가 있으면 앞지르지 않음(첫 조회, 새로고침, 처리 전 응답, 앞선 sighting 조회).
  - 응답 후 PR이 없을 때만 1회 조회.
  - 실패 backoff 중이면 조회하지 않음.
  - 15분이 지났거나 시계가 앞선 기록은 아무것도 일으키지 않음.
  - 64개 상한과 소유자 없는 주소 70개.
- **확인한 것**: label worker 테스트로 실제 transcript 읽기를 통한 추출, 최신 32개 유지,
device worker는 sighting을 보관하지 않음을 확인했습니다.
- **확인한 것**: 핵심 테스트마다 해당 코드를 빼서 실패하는 것을 확인했습니다(mutation 확인). 대상은 앞지르기
방지, 응답 후 재조회, 신선도 정리, 시계 앞섬 상한, device 차단입니다.
- **확인한 것**: `verify-cargo.sh lint` 통과, `nextest -p herdr-core`
1428/1428 통과. 별도 리뷰 3회의 Fix-now를 모두 반영했습니다.
- **확인하지 못한 것**: worker에서 `exchange_pull_requests`를 거쳐 runtime까지 한 번에
지나가는 테스트는 없습니다. coordinator 테스트 fixture로는 로컬 Git 프로젝트를 만들 수 없어서, 이 연결부(약
10줄)는 코드 리뷰로만 확인했습니다.
- **확인하지 못한 것**: 실제 `gh`로 agent가 PR을 여는 라이브 확인은 하지 않았습니다. CI e2e도 이 경로를
지나지 않습니다.
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.

데몬 재시작 뒤 Overview나 ⌘K를 열기 전까지 사이드바 행에 PR 상태가 없다

1 participant