Skip to content

spirv_metal_set0: publish assembled output atomically - #8882

Open
Barbital11111 wants to merge 3 commits into
ItsNotRexed:mainfrom
Barbital11111:fix/metal-spirv-atomic-output
Open

Barbital11111 wants to merge 3 commits into
ItsNotRexed:mainfrom
Barbital11111:fix/metal-spirv-atomic-output

Conversation

@Barbital11111

Copy link
Copy Markdown
Contributor

Summary

When the assembler writes part of a module and exits with an error, the wrapper can leave the existing destination truncated. An in-place conversion also loses its input.

Assemble into a private directory on the destination volume and replace the destination after a successful assembly. Preserve direct output for stdout and special files, symlink targets, and permission bits.

Depends on: #8730

Coordination claim

Validation

  • Windows 11, CPython 3.14.3: 50 passed and 6 skipped across the focused unit and pytest suites. The new failure injection reproduces truncation against the prior code for both in-place and separate existing destinations.
  • WSL Ubuntu, CPython 3.12.3, SPIRV-Tools v2023.6: 27 unit tests passed. A hand-written module passed spirv-val after conversion to a separate file and in place through a symlink. Stdout bytes and the default output matched the separate file. The output kept its original permission bits.
  • git diff --check and the changed-file no-game-data check passed. CPU only.

AI-assisted (Codex). Synthetic inputs only.

@catminou4

Copy link
Copy Markdown

Tested on Apple M1 Max, macOS 27.2.1 arm64, Python 3.12.16: 1 failure — a real portability bug in the new staging assertions, not a flake.

python -I tests/test_spirv_metal_set0_extra.py → 27 tests, 1 FAIL:

FAIL: test_synthetic_spv_out_of_place_and_in_place_binary_round_trip
AssertionError: '/private/var/folders/.../dir-é-☃' != '/var/folders/.../dir-é-☃'

Root cause: the tool resolves destination = os.path.realpath(output) (line ~194), so the staged temp file lands under the realpath'd directory. On macOS /var → /private/var, the staged path's grandparent is /private/var/... while the test compares against os.path.abspath(unicode_dir) which keeps the /var/... spelling. The new assertions at lines ~895-896 (and the sibling at ~918) will fail on macOS — including the repo's macos CI job — while passing on Linux/Windows where the two spellings coincide.

Suggested fix: compare against os.path.realpath(unicode_dir) instead of os.path.abspath(unicode_dir) (or wrap the staged side in os.path.realpath), matching how the tool resolves the destination. The staging behaviour itself is correct — spirv-as writes to a temp sibling and the rename publishes atomically; only the test's path spelling is wrong.

No game files. AI-assisted (Devin).

@Barbital11111

Copy link
Copy Markdown
Contributor Author

Fixed in 5414565. Both staging assertions now compare with the resolved destination directory, matching the path the tool uses.

With TMPDIR pointing at a directory symlink on WSL Ubuntu, the previous head failed the round-trip test with the alias/physical-path mismatch. At the new head all 27 tests passed under the same TMPDIR. The 27 tests also passed on native Windows. This run did not use macOS. AI-assisted (Codex).

Review report

@ne1i

ne1i commented Nov 23, 2026

Copy link
Copy Markdown

Tested 1076257c on Linux, CPython 3.14, CPU only, synthetic inputs, merged onto main 867d922f: pass

  • python -I tests/test_spirv_metal_set0_extra.py: Ran 27 tests, OK. With only the non-test files reverted to main: FAILED (errors=11), so the new tests exercise the change.
  • compileall and scripts/check_no_game_data.py on the changed files: clean.

Same atomic-publication trade-off as #8918, and the failed write names the staging file rather than the requested output.

Independent check (not the author). Run by an AI agent (DeepSeek V4.1 Flash) and re-run by the orchestrating session (Claude Code) before posting.

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.

3 participants