Repository navigation
Wait for a closed pane's processes to end before its worktree folder is removed - #523
Merged
Merged
Conversation
…is removed Herdr confirms a pane closed before its shell or agent has exited, and on Windows a running process holds its working folder, so the folder could not be moved aside and Git removed it in place. Closing now reads each pane's shell and foreground pids before closing any, and after the panes are confirmed gone waits within the close timeout until those processes have ended, failing with their pids otherwise. A refused move aside is logged, and the delete e2e names the dialog phase when no result arrives.
yansfil
added a commit
that referenced
this pull request
Oct 6, 2026
…dows (#611) Refs #484 ## Summary After #523's wait for the pane's processes, the worktree delete still fails on Windows now and then: the rename into `hide-removed` is refused with os error 32, and the error names no one. This only adds to the log. When that rename is refused on Windows, a second line, `set_aside_holders` (same `attempt` as `set_aside_refused`), lists the open handles on the folder or inside it, with the owning process, the path, the access and this process's own id, so the next failure says whether the holder is hided or another process. Nothing on screen or in behavior changes: the refusal still falls back to Git's in-place removal as before, and the removal does not wait for the scan. ## Review - **조심해서 볼 파일**: `hide-platform/src/fs/holders.rs` - reads the system handle table (`NtQuerySystemInformation`) and duplicates only handles of the file object type (its number is read off a file this process holds open), still skipping the access masks of synchronous pipes; the one place with `unsafe`. - **조심해서 볼 파일**: `hide-host/src/worktrees.rs` - `spawn_exclusive` and `record_holders`: the scan runs on its own thread, one at a time; the removal goes straight to Git's fallback and never waits. A blocked handle costs one thread and later records say `scan_busy`; the slot is freed when the thread ends, a panic included. - **비용 검토**: only on the refused-rename path, off the removal's thread and not under `Mutex<Runtime>`; one scan thread at most, at most 256 matches kept, table buffer capped at 256 MiB, and `scan_ms` in the record shows the real cost. - **질문**: Is a scan of every process's handles acceptable on that path? The alternative, the Restart Manager, failed with access denied and cannot see folder handles (tried in CI). ## Evidence - **확인한 것**: A Windows contract test (`the_process_holding_a_folder_or_a_file_in_it_is_listed_with_its_id`) passed in the `os contract (windows)` lane: this process is listed for an open file inside a folder and for the open folder, and not once both are closed. - **확인한 것**: `holder_scan_tests` (2): a scan that blocks holds the slot and nothing waits for it, a second call answers busy without running, a panicking scan frees the slot. The blocking itself is not reproduced with a real Windows handle: one that blocks cannot be arranged on a runner, so the test shows the property that matters, that the caller returns at once. - **확인한 것**: 80 Windows runs of the delete spec with this record in place passed and logged no refusal, so the record's holder fields have not yet been seen on a real refusal. - **확인하지 못한 것**: Who holds the folder. The refusal did not reproduce in CI (80 runs idle; a loaded run is pending), so this PR gives the next natural failure its answer and does not fix #484.
HyunjunJeon
pushed a commit
to HyunjunJeon/hide
that referenced
this pull request
Nov 9, 2026
…ore (with-hide#2149) Closes with-hide/hide-private#561 Closes with-hide/hide-private#495 Closes with-hide/hide-private#564 Closes with-hide/hide-private#605 ## Summary e2e 픽스처가 두 번째 에이전트를 너무 일찍 시작해서, 코어가 "다른 시작이 아직 진행 중"이라며 거절하고 픽스처는 30초를 기다리다 실패했습니다. 코어는 시작 하나가 끝나기 전에는 새 시작을 받지 않는데, 첫 에이전트의 행은 그 시작이 끝나기 전에 먼저 보입니다. 이제 테스트는 행이 아니라 코어가 그 시작에 준 답(시작 패널이 읽는 것과 같은 영수증, `task_operation`)을 기다렸다가 다음 시작을 보냅니다. 거절되면 30초를 기다리지 않고 코어의 이유로 바로 실패합니다. 화면 변경 없음: 테스트 코드와 문서만 바뀝니다. ## Review - **조심해서 볼 파일**: `web/e2e/daemon-actions.ts` `startAgentInCheckout` - 코어의 task slot 규칙(`herdr-core/src/runtime/session.rs:3994-4003`)을 그대로 읽는지, `started` 외의 답은 모두 실패로 끝나는지. - **조심해서 볼 파일**: `web/e2e/engine-fixture.ts` - 첫 시작이 끝난 뒤에야 두 번째 시작(또는 family의 spawn)이 나갑니다. 기다림은 코어 신호뿐이고 timeout·sleep·retry는 늘리지 않았습니다. - **원인이 다른 것**: with-hide#444 with-hide#445 with-hide#459 with-hide#479 with-hide#496 은 픽스처가 아니라 spec 안의 기다림에서 실패하고 로그에 거절이 없어 이 PR에서 다루지 않습니다. - **Herdr 레인에서만 난 것**: with-hide#260 with-hide#489 with-hide#502 with-hide#510 with-hide#511 with-hide#519 with-hide#533 은 `*-herdr-*` 레인에서만 났고 그 레인은 #2069로 지워졌습니다. #2069와 아래 반복 run을 적은 댓글로 닫습니다. - **열어 두는 것**: with-hide#490 with-hide#492 with-hide#523 with-hide#529 with-hide#532(`agent_pane_required`)는 이 PR이 끝내지 않습니다. 원인은 with-hide/hide-private#630에서 따로 다룹니다. ## Evidence - **확인한 것**: own engine으로 바뀐 뒤 "second fixture agent" 실패 6건 중 5건(#561 x2, with-hide#495, with-hide#564, with-hide#605; Linux·Windows)의 setup snapshot과 hided 로그를 봤습니다. 모두 두 번째 시작의 request id로 `task_operation.busy` 거절이 남아 있습니다. 나머지 1건(#561, run 42076071271)은 로그를 받지 않았고 오류 줄만 같습니다. - **확인한 것**: 실패 로그 순서는 tab.create 완료 -> busy 거절 -> 첫 시작의 `agent.started`, 통과한 실행은 tab.create 몇 ms 뒤 `agent.started` -> 두 번째 시작입니다. - **확인한 것**: `web`·`desktop` typecheck, lint(e2e 크기 검사 포함) 통과. - **확인한 것**: a79a97b, run 42202678411의 Linux 전체 e2e(6 shard)와 Windows `@platform` e2e를 3번 돌렸습니다. 닫는 11개 제목은 매번 통과했고 재시도도 없었습니다. - attempt 1: Linux 6/6, Windows 1/1 통과. 재시도 후 통과: `desk-lane` "Desk is off on a new install"(Linux 4/6), with-hide#444 close-subtree(Linux 6/6) - attempt 2: Linux 6/6, Windows 1/1 통과, 재시도 없음 - attempt 3: Linux 6/6, Windows 1/1 통과. 재시도 후 통과: `desk-lane` 같은 테스트(Linux 4/6) - **범위 밖**: #444가 attempt 1에서 재시도 후 통과한 것과 `desk-lane`이 두 번 재시도 후 통과한 것은 픽스처 원인이 아닙니다. 이 노드 범위 밖이고 따로 묶여 있습니다. - **확인하지 못한 것**: 로컬 e2e는 돌리지 않았습니다(Rust debug 빌드 디스크 부족). macOS 웹 e2e는 PR CI에 없어 반복하지 않았고, 이 묶음의 21개 이슈 중 macOS에서 난 것은 없습니다.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs #484
Summary
Herdr confirms a pane closed before its shell or agent has exited, and on Windows a running process holds its working folder.
The folder then cannot be moved into
hide-removed, Git removes it in place, and the delete can run past the dialog's 60 s wait.Closing a worktree's panes now reads each pane's shell and foreground pids (
pane.process_info) before closing any pane.After Herdr's snapshot confirms the panes gone it waits, inside the existing 5 s close timeout, until those processes have ended (pid plus start time, through
hide_platform::process).A process still running at the timeout fails the close with its pid, and the worktree is not touched.
A refused move aside is logged as
set_aside_refused, and the delete e2e names the dialog phase and text when no result arrives.Review
herdr-core/src/worktree_control.rs- failure path of the close shared by worktree deletion and reviewed cleanup.ProcessWait::for_folder_removal); on macOS and Linux a held working folder does not block a rename, so waiting could only add failures.foreground_processes; if Flaky test: a dirty worktree with an unmerged branch and an agent is deleted once both boxes are ticked #484 recurs, walking descendants is the next step.Evidence
herdr-coreclose tests (44, including: a pane that cannot be read closes none, pids 0/1 are never watched, a process running at the deadline fails naming its pid, the wait pauses while the child runs and ends when it ends, the skip never asks for processes); clippy-D warningsonhide-platform,herdr-core,hide-host,hided;weblint, size budget and typecheck.hide-platform/tests/process.rsa_folder_that_is_a_running_processes_working_folder_moves_once_it_has_ended: on Windows the rename of a child's working folder is refused, and it succeeds oncestart_timesays the child ended; it runs in the os contract lane.windows-e2eon this PR is the only evidence the cause was right, and one pass proves little at this flake rate; the next failure will carry the phase text and theset_aside_refusedline. The Windows build of the new unit tests was not compiled locally.