Skip to content

Record who holds a folder when its set-aside rename is refused on Windows - #611

Merged
yansfil merged 4 commits into
mainfrom
fix/flaky-484-holder
Oct 6, 2026
Merged

yansfil merged 4 commits into
mainfrom
fix/flaky-484-holder

Conversation

@yansfil

@yansfil yansfil commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

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 Flaky test: a dirty worktree with an unmerged branch and an agent is deleted once both boxes are ticked #484.

…used

On Windows a refused rename names no one (os error 32 or 5). The record of
set_aside_refused now carries the open handles the system lists on the folder
or inside it, with the owning process and this process's id beside them, so a
refusal says whether the holder is hided itself or another process.

Refs #484
A handle of some kinds can block the questions the holder scan asks, so the
scan no longer runs where the removal waits: it runs on its own thread, one
at a time, and writes its own set_aside_holders line with the refusal's
attempt id; a scan still running makes the next record scan_busy. The scan
also duplicates only handles of the file object type, found from a file this
process holds open, instead of every handle of every process.

Refs #484
Spawned::Started carries the scan thread's JoinHandle, so a test joins it and then reads the slot rather than waiting on a count of yields.
The product drops the handle.
A system other than Windows no longer writes a holders line, since it has nothing to report.

Refs #484
@yansfil
yansfil merged commit 0f86989 into main Oct 6, 2026
19 checks passed
@yansfil
yansfil deleted the fix/flaky-484-holder branch October 6, 2026 04:56
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.

Flaky test: a dirty worktree with an unmerged branch and an agent is deleted once both boxes are ticked

1 participant