Skip to content

BUG: Archive files open for writing in the Windows cache archive - #321

Merged
hjmjohnson merged 1 commit into
InsightSoftwareConsortium:mainfrom
dzenanz:windows-7zip-warnings
Nov 27, 2026
Merged

hjmjohnson merged 1 commit into
InsightSoftwareConsortium:mainfrom
dzenanz:windows-7zip-warnings

Conversation

@dzenanz

@dzenanz dzenanz commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

Summary

Pass -ssw to 7-Zip so the Windows cache archive includes files another process holds open for writing. Until now, such a file made 7-Zip exit 1, and build_tarball replaced the 7z archive with the zip fallback. Any other 7-Zip warning still goes to the fallback, and logs are no longer cached.

How it showed up

The release-wheels output was redirected to run2.log inside the ITKPythonPackage checkout, which is one of the archived folders. 7-Zip could not read that open file. It wrote the rest of the archive, warned, and exited 1. The build then wrote the Python zip fallback over it.

Checked on Windows with a file held open by [IO.File]::Open(path, 'Append', 'Write', 'Read'): without -ssw, 7-Zip skips it and exits 1; with -ssw, it archives it and exits 0.

Type of Change

  • Bug fix
  • New feature / enhancement
  • Refactor / cleanup
  • Docs / CI only

Checklist

  • Pre-commit hooks pass locally (pre-commit run --all-files)
  • Tested wheel build on affected platform(s) (Linux / macOS / Windows)
  • Docs updated if behavior changed (docs/)
  • Commit messages use ITK prefixes (BUG:, COMP:, DOC:, ENH:, PERF:, STYLE:)

Platform(s) Tested

  • Linux x86_64 (manylinux)
  • Linux aarch64 (manylinux)
  • macOS arm64
  • Windows x86_64 (test suite: 501 passed, 6 skipped)
AI assistance
  • Tool: Claude Code (claude-opus-5-5)
  • Role: diagnosed the fallback from the build log and the archive on disk, and wrote the fix and its tests

🤖 Generated with Claude Code

@dzenanz
dzenanz requested a review from hjmjohnson November 26, 2026 13:58

@hjmjohnson hjmjohnson left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

To answer the question you raised: I'd rather not accept exit code 1. -ssw fixes the incident you hit, and exit 1 can stand for several worse failures than a skipped log.

7-Zip documents exit code 1 as "Warning (Non fatal error(s)) ... one or more files were locked by some other application, so they were not compressed". Without -sse, it also skips input files it cannot open. So exit 1 covers all of these:

  • a file another process holds open for writing (your run2.log): harmless;
  • a .lib, .pyd, or header under build/ that an indexer, antivirus scan, or leftover compiler process holds: the module build fails much later, far from the cause;
  • access denied on a directory: the whole subtree is missing;
  • a file deleted between 7-Zip's scan and its read;
  • a missing archive root (ITK/, build/, or the IPP checkout): 7-Zip warns that it cannot find the file, and the archive is missing that whole root.

With this change, every one of these publishes an incomplete cache and step 07 still reports "completed". The old fallback had the right content. It read run2.log because Python's open() on Windows shares write access and 7-Zip by default does not. The fallback's only cost was a bigger zip.

Why a file was open at all: the build finishes compiling before step 07, and none of the scripts write a log into the archived folders. Your run2.log was the output of this same build, redirected into the checkout, which is one of the archive roots. So the archive step was reading its own log while it was still being written. A log doesn't belong in the build cache in any case, so I'd also add "*.log" to ARCHIVE_EXCLUDES (scripts/windows_build_python_instance.py:18), or note in the docs that redirected output should go outside the checkout. Other ways to hit this (a second build in the same tree, an editor or indexer holding a file) are rare, and they are the cases worth hearing about.

Suggested direction, with details inline:

  1. Add -ssw ("compresses files open for writing by another applications") and keep == 0. This fixes the case in the PR body.
  2. To find out what a warning was, keep 7-Zip's output: call run_command(..., stream=True) directly or let echo_check_call return the CompletedProcess, then print the WARNING: lines before falling back. _run_streaming already keeps every line, but echo_check_call throws them away.

Not run on Windows: the 7-Zip exit codes and -ssw come from the 7-Zip docs, and the file-sharing difference and the missing-root warning are reasoned from the code. A Windows check that would settle it: hold a file open with $f=[IO.File]::Open('C:\\P\\IPP\\x.log','Append','Write','Read'), then run 7z a with and without -ssw.

Also, the PR body says pre-commit passes "except prettier"; AGENTS.md asks that pre-commit run --all-files pass on the pushed tip.

Comment thread tests/test_windows_wheel_builder.py Resolved
Comment thread tests/test_windows_wheel_builder.py Resolved
@hjmjohnson
hjmjohnson marked this pull request as draft November 26, 2026 21:11
@dzenanz
dzenanz force-pushed the windows-7zip-warnings branch from 5ac0eae to 906b441 Compare November 27, 2026 16:01
@dzenanz dzenanz changed the title Keep the 7-Zip cache archive when 7-Zip only warns BUG: Archive files open for writing in the Windows cache archive Nov 27, 2026
@dzenanz

dzenanz commented Nov 27, 2026

Copy link
Copy Markdown
Member Author

Thanks. All points are addressed in 906b441, and *.log is now in ARCHIVE_EXCLUDES. pre-commit run --all-files passes fully, prettier included (run in an LF checkout; on a Windows core.autocrlf checkout, mixed-line-ending and shellcheck flag the CRLF files).

When the release-wheels output was redirected to a log inside the
ITKPythonPackage checkout, 7-Zip could not read that open file, warned,
and exited 1. build_tarball then replaced the 7z archive with the slower
Python zip fallback.

Pass -ssw so 7-Zip also reads files another process holds open for
writing. Any other warning can mean a file is missing from the archive,
such as an unreadable file or directory, so exit code 1 still goes to the
zip fallback. Logs are excluded from the cache, where they do not belong.
@dzenanz
dzenanz force-pushed the windows-7zip-warnings branch from 906b441 to a189805 Compare November 27, 2026 16:07
@dzenanz

dzenanz commented Nov 27, 2026

Copy link
Copy Markdown
Member Author

The second force push is a plain rebase.

@dzenanz
dzenanz marked this pull request as ready for review November 27, 2026 16:07
@dzenanz
dzenanz requested a review from hjmjohnson November 27, 2026 16:17
@hjmjohnson
hjmjohnson merged commit 381c5e8 into InsightSoftwareConsortium:main Nov 27, 2026
5 checks passed
@dzenanz
dzenanz deleted the windows-7zip-warnings branch November 27, 2026 18:24
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.

2 participants