Repository navigation
test(dashboard): wait out the served file's handle before sweeping the old dist (#19164) - #19698
Conversation
UX Review (Opus 5.5) — ⏭️ skippedRevision |
First Principles Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Before merging, check that the next few [DESIGN-REVIEWED] 06920a2 Description read[DESCRIPTION-READ] d469c12d7a4ba0c7b0f22acd0123eec492a6301ae7144127e8a5e9de75c87eaf That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
Tier 1 auto-approve: test (1 files). Criteria: no conflict, no requested changes, security path denylist clean, design-doc gate clean, security checklist all-NO, no reviewer-lane findings, readiness signal fresh for this head SHA, declared category matches the diff. Category: test-only change: the dashboard dist sweep retries until the served file handle is released, with tests for both the late release and the never-released case.
Problem / Motivation
Goal:
test_handler_follows_a_re_pointed_diststops failing the Windows backend shard when the server closes the file it just served a moment after the test sweeps it.On the Windows runner,
TestWindowEntryHandler.test_handler_follows_a_re_pointed_distintermittently fails atshutil.rmtree(tmp_path / "old")withPermissionError: [WinError 32] The process cannot access the file because it is being used by another process. It was seen on at least five unrelated PRs (#18595, #9052, #18454, #11015 twice), each time the shard's only failure.Why it matters
The red lands on PRs that touch nothing near the dashboard server, so every hit costs an author a classification and a re-run, and it trains reviewers to ignore Windows backend reds.
Not a goal
_window_entry_handleror any production code: the route already follows the re-pointed link, which is what the test asserts.ignore_errors=True: a handle that is never released is a real leak and must still fail.What changed (motivation → approach → change)
board.html.web.FileResponsecloses the file it served on an executor thread after the response body has been sent. The client already holds the body, so the test moves on and sweepsoldwhile the server's handle can still be open, and Windows refuses to unlink a file any handle holds._sweep_once_released, which runsshutil.rmtreeunderasync_wait_until(..., ignoring=(PermissionError,), off_loop=True)fromkiro_crew.testing.wait(testing conventions D1: wait on the state, bounded, failing by name). Running off the loop leaves the loop free for the server's close. If the handle never clears, the wait raisesAssertionErrorchained to the lastPermissionError. The order of the test (serve old, re-point, sweep, serve new) and its assertions are unchanged. No existing helper intest/conftest.pydoes a bounded Windows-tolerantrmtree(its onlyrmtreeusesignore_errors=True), so none was reused.Backwards compatibility
Compatible: test-only change in one file; no product code, config or public helper changes.
Removes nothing: the diff only adds a test helper and two tests and replaces one call inside a test.
Tests
test_handler_follows_a_re_pointed_dist: now sweeps with_sweep_once_released. Forced condition (ashutil.rmtreepatched to raisePermissionErroron its first call): red with the old bareshutil.rmtreeline (PermissionError: [Errno 32] held), green with the fix.test_sweep_waits_out_a_handle_released_late(new):rmtreeraisesPermissionErrortwice, then succeeds; the tree is gone after three attempts. Reddens when the helper stops ignoringPermissionError.test_sweep_fails_by_name_when_the_handle_is_never_released(new):rmtreealways raises; the helper raisesAssertionErrorwhose__cause__is thePermissionError, and the directory is left in place. Reddens when the helper stops ignoringPermissionError, and when it swallows errors withignore_errors=True(DID NOT RAISE).src: whole file 40 passed at-n0;TestWindowEntryHandler20 of 20 at-n0; whole file 10 of 10 at-n 4.test_wait_discipline_ratchet.pyandtest_flake_pattern_ratchet.pypass. isort and flake8 clean on the file. A shuffled-order run was not done:pytest-randomlyis not installed on this host.Manual verification
N/A: the defect is a Windows-only handle race and this host is Linux. The Windows behaviour is verified by the
Backend Tests (Windows)CI shards only.Related Issues
Closes #19164
Pattern harvest
Rule candidate: review-prompt
Pattern: a test that serves a file through
web.FileResponseand then deletes it in the same breath must wait for the server to release the handle (Windows WinError 32), not delete immediately.Decision for the owner
The decision is how to stop this test from deleting a file the server may still hold open on Windows without hiding a real handle leak. This draft retries the sweep on
PermissionErrorunder the repository's boundedasync_wait_untiland fails by name if the handle never clears, rather than skipping the test on Windows or passingignore_errors=True.Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)Contribution License Agreement
Contributions are accepted under the project's Apache-2.0 license; see the Licensing section of CONTRIBUTING.md.