Skip to content

test(dashboard): wait out the served file's handle before sweeping the old dist (#19164) - #19698

Merged
buluoray merged 1 commit into
mainfrom
fix/window-entry-test-windows-sweep-19164
Oct 13, 2026
Merged

buluoray merged 1 commit into
mainfrom
fix/window-entry-test-windows-sweep-19164

Conversation

@buluoray

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: test_handler_follows_a_re_pointed_dist stops 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_dist intermittently fails at shutil.rmtree(tmp_path / "old") with PermissionError: [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

  • No change to _window_entry_handler or any production code: the route already follows the re-pointed link, which is what the test asserts.
  • No Windows skip and no ignore_errors=True: a handle that is never released is a real leak and must still fail.

What changed (motivation → approach → change)

  • Symptom: the sweep of the old dist raises WinError 32 on board.html.
  • Root cause: web.FileResponse closes 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 sweeps old while the server's handle can still be open, and Windows refuses to unlink a file any handle holds.
  • Change: the test sweeps through a new module helper, _sweep_once_released, which runs shutil.rmtree under async_wait_until(..., ignoring=(PermissionError,), off_loop=True) from kiro_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 raises AssertionError chained to the last PermissionError. The order of the test (serve old, re-point, sweep, serve new) and its assertions are unchanged. No existing helper in test/conftest.py does a bounded Windows-tolerant rmtree (its only rmtree uses ignore_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 (a shutil.rmtree patched to raise PermissionError on its first call): red with the old bare shutil.rmtree line (PermissionError: [Errno 32] held), green with the fix.
  • test_sweep_waits_out_a_handle_released_late (new): rmtree raises PermissionError twice, then succeeds; the tree is gone after three attempts. Reddens when the helper stops ignoring PermissionError.
  • test_sweep_fails_by_name_when_the_handle_is_never_released (new): rmtree always raises; the helper raises AssertionError whose __cause__ is the PermissionError, and the directory is left in place. Reddens when the helper stops ignoring PermissionError, and when it swallows errors with ignore_errors=True (DID NOT RAISE).
  • Runs on Linux, importing this worktree's src: whole file 40 passed at -n0; TestWindowEntryHandler 20 of 20 at -n0; whole file 10 of 10 at -n 4. test_wait_discipline_ratchet.py and test_flake_pattern_ratchet.py pass. isort and flake8 clean on the file. A shuffled-order run was not done: pytest-randomly is 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.FileResponse and 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 PermissionError under the repository's bounded async_wait_until and fails by name if the handle never clears, rather than skipping the test on Windows or passing ignore_errors=True.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

Contribution License Agreement

Contributions are accepted under the project's Apache-2.0 license; see the Licensing section of CONTRIBUTING.md.

@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Oct 13, 2026
@github-actions

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision 06920a2a42178ef86877d6184b9967de93c1ea13 touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Advisory — does not block merge.

@github-actions

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ⏭️ skipped

Revision 06920a2a42178ef86877d6184b9967de93c1ea13 ships no reviewable capability (docs, tests or generated files only), so there is nothing to inventory. Advisory — does not block merge.

@github-actions

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of 06920a2a42178ef86877d6184b9967de93c1ea13 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Design-Verdict: PASS

Before merging, check that the next few Backend Tests (Windows) runs stay green with this fix. That CI shard is the only proof the race is gone.

[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 .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 06920a2a42178ef86877d6184b9967de93c1ea13 — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 06920a2

Verdict parsed from the review's SHA-scoped output markers for commit 06920a2a42178ef86877d6184b9967de93c1ea13.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 06920a2a42178ef86877d6184b9967de93c1ea13: <one-sentence reason>

@github-actions

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 06920a2a42178ef86877d6184b9967de93c1ea13 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 06920a2

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 06920a2a42178ef86877d6184b9967de93c1ea13: <one-sentence reason>

@buluoray
buluoray marked this pull request as ready for review October 13, 2026 06:34
@buluoray
buluoray requested review from a team and KiroCrewCaptain as code owners October 13, 2026 06:34
@buluoray
buluoray requested a review from mbriones98 October 13, 2026 06:34
@buluoray
buluoray enabled auto-merge (squash) October 13, 2026 06:34
@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Oct 13, 2026

@KiroCrewCaptain KiroCrewCaptain left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@buluoray
buluoray merged commit be6eb73 into main Oct 13, 2026
103 checks passed
@buluoray
buluoray deleted the fix/window-entry-test-windows-sweep-19164 branch October 13, 2026 07:10
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Oct 13, 2026
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_handler_follows_a_re_pointed_dist (test_dashboard_server_coverage.py:236) sweeps a dist the server still holds open on Windows (WinError 32)

2 participants