Skip to content

Fix race condition in dependency archive creation#76

Merged
obj-p merged 3 commits intomainfrom
fix/archive-race-condition
Apr 10, 2026
Merged

Fix race condition in dependency archive creation#76
obj-p merged 3 commits intomainfrom
fix/archive-race-condition

Conversation

@obj-p
Copy link
Copy Markdown
Owner

@obj-p obj-p commented Apr 10, 2026

Summary

Fixes intermittent CI failure: ld: library 'LocalDep' not found during CLI integration tests.

Root Cause

archiveDependencyTargets deleted libDep.a before recreating it with ar rcs. The CLI snapshot command and CLI variants command test suites run in parallel — when a snapshot test called detectAndBuild (which re-archives dependencies) while the variants test was between its first and second compileCombined calls, the linker saw the archive as missing during the delete-to-recreate window.

The race was exposed by #74's progress reporting, which adds small await pauses between operations, widening the timing window.

Fix

Write to a temp file (libDep.a.tmp) and atomically rename via FileManager.replaceItemAt, so the archive is never absent from the linker's perspective.

Test plan

  • swift build succeeds
  • previewsmcp variants --variant light --variant dark produces both images
  • CI should pass (race condition eliminated)

🤖 Generated with Claude Code

obj-p and others added 3 commits April 10, 2026 18:00
archiveDependencyTargets deleted libDep.a before recreating it with ar.
When two CLI tests ran concurrently (snapshot + variants suites), the
delete-then-recreate window allowed a concurrent compileCombined call
to see the archive as missing, causing "ld: library 'LocalDep' not found".

Fix: write to a temp file and atomically rename via replaceItemAt,
so the archive is never absent from the linker's perspective.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Address review feedback:
- UUID-based temp filename prevents collisions between concurrent callers
- replaceItemAt errors are propagated, with moveItem fallback for first build
- Removes stale-temp cleanup that could delete another caller's file

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@obj-p obj-p merged commit 46fef3a into main Apr 10, 2026
4 checks passed
@obj-p obj-p deleted the fix/archive-race-condition branch April 10, 2026 22:41
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.

1 participant