Skip to content

fix(iOS): prevent UUID collision corrupting Pods project in spm_dependency - #57576

Closed
chrfalch wants to merge 1 commit into
mainfrom
chrfalch/spm-dependency-uuid-collision
Closed

chrfalch wants to merge 1 commit into
mainfrom
chrfalch/spm-dependency-uuid-collision

Conversation

@chrfalch

Copy link
Copy Markdown
Collaborator

Summary:

The first nightly containing the prebuilt/SwiftPM stack (0.88.0-nightly-20260716) broke the react-native-enriched-markdown job in react-native-community/nightly-tests: pod install succeeds, but xcodebuild cannot load the generated project:

-[XCRemoteSwiftPackageReference _setSavedArchiveVersion:]: unrecognized selector sent to instance
Failed to load container at path: .../Pods/Pods.xcodeproj — "The project 'Pods' is damaged and cannot be opened."

Root cause: spm_dependency injects XCRemoteSwiftPackageReference / XCSwiftPackageProductDependency objects from a post_install hook via project.new(...). CocoaPods' Pod::Project overrides UUID generation with a deterministic counter scheme (prefix + %07X counter + trailing 0) and deliberately skips collision checks, assuming the project is always freshly generated. When the generator counters are out of sync with the loaded object graph, the first generated UUID collides with an existing object — in the observed failure the root PBXProject's own UUID (46EB2E00000000). The injected package reference silently overwrites the root object entry in objects_by_uuid, so the saved pbxproj's rootObject points at the package reference, and Xcode's loader sends PBXProject-only messages to it. The bug is latent in spm_dependency since its introduction; the recently grown Pods object graph merely exposed it.

Fix: route object creation through a new_object helper that keeps the deterministic counter scheme but probes generate_uuid forward past any UUID already present in objects_by_uuid. Uniqueness is guaranteed against the live object table regardless of project size/state; generate_uuid's counter is strictly monotonic, so the probe terminates and never repeats within a run. Repeated pod installs stay idempotent via the existing find-before-create dedup guards.

Changelog:

[IOS] [FIXED] - Fix "The project 'Pods' is damaged and cannot be opened" when a library uses spm_dependency and the generated UUID collides with an existing Pods project object

Test Plan:

  • New standalone test scripts/cocoapods/__tests__/spm-test.rb (runs via ruby scripts/cocoapods/__tests__/spm-test.rb, uses the real Pod::Project):
    • fresh-project injection (passes before and after — fresh counters don't collide, isolating the trigger),
    • injection after counter reset (reproduces the corruption against the previous code as NoMethodError: undefined method 'product_ref_group' for ... XCRemoteSwiftPackageReference on reload — the Ruby analog of Xcode's crash; passes with the fix),
    • global UUID uniqueness + clean Xcodeproj::Project.open round-trip.
  • 3 tests, 10 assertions, 0 failures with the fix.
  • E2E: to be confirmed with a spm_dependency library (e.g. react-native-enriched-markdown) in prebuilt mode.

🤖 Generated with Claude Code

…dency

spm_dependency injects XCRemoteSwiftPackageReference /
XCSwiftPackageProductDependency objects into the Pods project from a
post_install hook via project.new(...). CocoaPods' Pod::Project
overrides UUID generation with a deterministic counter scheme
(prefix + %07X counter + trailing 0) and deliberately skips collision
checks, assuming the project is always freshly generated. When the
generator counters are out of sync with the loaded object graph, the
first generated UUID can collide with an existing object — in the
observed failure, the root PBXProject's own UUID (46EB2E00000000). The
injected package reference then silently overwrites the root object
entry, and the saved pbxproj's rootObject points at the package
reference. Xcode fails to load the project:

  -[XCRemoteSwiftPackageReference _setSavedArchiveVersion:]:
  unrecognized selector
  "The project 'Pods' is damaged and cannot be opened."

This broke the react-native-enriched-markdown job in nightly-tests on
0.88.0-nightly-20260716 after the Pods graph grew with the prebuilt
pods; the bug itself is latent and independent of that change.

Fix: route object creation through a new_object helper that keeps the
deterministic counter scheme but probes generate_uuid forward past any
UUID already present in objects_by_uuid. Uniqueness is guaranteed
against the live object table regardless of project size or state, and
repeated pod installs remain stable via the existing find-before-create
dedup guards.

Adds a standalone test (scripts/cocoapods/__tests__/spm-test.rb)
covering fresh-project injection, the reload/collision regression, and
global UUID uniqueness.

Co-Authored-By: Claude Fable 5 <[email protected]>
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jul 16, 2026
@chrfalch
chrfalch requested a review from cipolleschi July 16, 2026 11:34

@cipolleschi cipolleschi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the fix

@facebook-github-tools facebook-github-tools Bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Jul 16, 2026
@meta-codesync

meta-codesync Bot commented Jul 16, 2026

Copy link
Copy Markdown

@cipolleschi has imported this pull request. If you are a Meta employee, you can view this in D112320831.

@meta-codesync meta-codesync Bot closed this in 1cdf784 Jul 16, 2026
@meta-codesync meta-codesync Bot added the Merged This PR has been merged. label Jul 16, 2026
@meta-codesync

meta-codesync Bot commented Jul 16, 2026

Copy link
Copy Markdown

@cipolleschi merged this pull request in 1cdf784.

react-native-bot pushed a commit that referenced this pull request Jul 16, 2026
…dency (#57576)

Summary:
The first nightly containing the prebuilt/SwiftPM stack (`0.88.0-nightly-20260716`) broke the `react-native-enriched-markdown` job in [react-native-community/nightly-tests](https://github.com/react-native-community/nightly-tests/actions/runs/29476835418/job/87551590732): `pod install` succeeds, but xcodebuild cannot load the generated project:

```
-[XCRemoteSwiftPackageReference _setSavedArchiveVersion:]: unrecognized selector sent to instance
Failed to load container at path: .../Pods/Pods.xcodeproj — "The project 'Pods' is damaged and cannot be opened."
```

**Root cause:** `spm_dependency` injects `XCRemoteSwiftPackageReference` / `XCSwiftPackageProductDependency` objects from a `post_install` hook via `project.new(...)`. CocoaPods' `Pod::Project` overrides UUID generation with a deterministic counter scheme (`prefix + %07X counter + trailing 0`) and deliberately skips collision checks, assuming the project is always freshly generated. When the generator counters are out of sync with the loaded object graph, the first generated UUID collides with an existing object — in the observed failure the root `PBXProject`'s own UUID (`46EB2E00000000`). The injected package reference silently overwrites the root object entry in `objects_by_uuid`, so the saved pbxproj's `rootObject` points at the package reference, and Xcode's loader sends `PBXProject`-only messages to it. The bug is latent in `spm_dependency` since its introduction; the recently grown Pods object graph merely exposed it.

**Fix:** route object creation through a `new_object` helper that keeps the deterministic counter scheme but probes `generate_uuid` forward past any UUID already present in `objects_by_uuid`. Uniqueness is guaranteed against the live object table regardless of project size/state; `generate_uuid`'s counter is strictly monotonic, so the probe terminates and never repeats within a run. Repeated `pod install`s stay idempotent via the existing find-before-create dedup guards.

## Changelog:

[IOS] [FIXED] - Fix "The project 'Pods' is damaged and cannot be opened" when a library uses `spm_dependency` and the generated UUID collides with an existing Pods project object

Pull Request resolved: #57576

Test Plan:
- New standalone test `scripts/cocoapods/__tests__/spm-test.rb` (runs via `ruby scripts/cocoapods/__tests__/spm-test.rb`, uses the real `Pod::Project`):
  - fresh-project injection (passes before and after — fresh counters don't collide, isolating the trigger),
  - injection after counter reset (reproduces the corruption against the previous code as `NoMethodError: undefined method 'product_ref_group' for ... XCRemoteSwiftPackageReference` on reload — the Ruby analog of Xcode's crash; passes with the fix),
  - global UUID uniqueness + clean `Xcodeproj::Project.open` round-trip.
- 3 tests, 10 assertions, 0 failures with the fix.
- E2E: to be confirmed with a `spm_dependency` library (e.g. react-native-enriched-markdown) in prebuilt mode.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Reviewed By: fabriziocucci

Differential Revision: D112320831

Pulled By: cipolleschi

fbshipit-source-id: de190f6492abff2cc6dbd94347e5346d11b50a41
gbirch-stripe added a commit to stripe/stripe-react-native that referenced this pull request Aug 31, 2026
… and guard Pods UUID integrity

Two hardening changes ported from react-native-firebase's post-launch
fixes:

- User-project mutations (the embed-frameworks phase add/remove) now run
  from run_podfile_post_integrate_hooks — after CocoaPods has integrated
  and saved the user's project — with a post_install fallback for
  CocoaPods < 1.10. Pods-project work (linkage fail-fast, package-ref
  check, Onramp product linking) stays at post_install, while
  Pods.xcodeproj is still unwritten. Our target discovery never depended
  on integration state (unlike RNFB's, which broke single-pass Expo
  prebuild installs), but post_integrate is where CocoaPods documents
  user-project mutation belongs, and it keeps the phase ordered after the
  [CP] phases on fresh projects.

- pod install is now guarded against the spm_dependency UUID-collision
  corruption (react/react-native#57576, fixed upstream only in
  RN >= 0.88): Pod::Project mints deterministic UUIDs with no collision
  check, so a project.new from a post_install hook can silently overwrite
  an existing object — including the root PBXProject, leaving
  Pods.xcodeproj unopenable. The counter's high-water mark is raised past
  every existing counter-format UUID before hooks run (soft: warns if
  CocoaPods internals change), and rootObject integrity is verified after
  them (hard: aborts the install before a corrupt project is written).

Committed-By-Agent: claude
Orbit-Session-Id: 3ff97f9d-face-47e8-8b2e-bb7277bd868b
gbirch-stripe added a commit to stripe/stripe-react-native that referenced this pull request Aug 31, 2026
The full pipeline passed on the hardening push's first run, and the Expo
job's install log shows the new UUID guard actively preventing the
react/react-native#57576 corruption on a stock Expo SDK 54 install:
the counter was raised past index 10523 and RN's package reference was
minted at exactly the first post-guard index. The RNTA-based jobs never
trip this (fresh in-process Pods generation keeps the counter in sync),
so the guard and the first CI configuration able to expose the bug
shipped in the same push.

Committed-By-Agent: claude
Orbit-Session-Id: 3ff97f9d-face-47e8-8b2e-bb7277bd868b
chrfalch added a commit to expo/expo that referenced this pull request Oct 2, 2026
…e post_install objects (#50946)

# Why

Fixes #50794.

`pod install` can write a `Pods.xcodeproj` that Xcode cannot open ("The
project 'Pods' is damaged"). A new object gets a UUID that an existing
object already has, and replaces it. In the worst case the root
`PBXProject` is replaced. EAS builds then fail with only `no such module
'Expo'`. It depends on the project's object count, so a routine
dependency bump can trigger it.

The cause:

- CocoaPods hands out sequential UUIDs with no collision check.
`stabilize_target_uuids` runs on every install and restarts that counter
near zero.
- Expo's guard from #44436 was installed in
`perform_post_install_actions`, after the Podfile `post_install`.
Objects that React Native's `spm.rb` (or any user hook) creates there
were not protected.
- The guard only replaced how new batches of UUIDs are made. The current
batch, which already holds used UUIDs, stayed in place. So Expo's own
`[Expo] Remove duplicate codegen output` phase could still take a used
UUID.

The second point also affects `main`: React Native 0.87+
(react/react-native#57576) protects its own objects, but leaves the
stale batch behind for Expo's objects.

### Previous fixes

This is the third fix for the same CocoaPods counter problem:

- #40572 found that a build phase Expo added in
`run_podfile_post_install_hooks` could collide with the root
`PBXProject`. It moved that phase to `perform_post_install_actions`.
This avoided the collision for that one phase, but did not protect
objects created later.
- #44436 added the random-UUID guard in `perform_post_install_actions`.
It protects new batches, but not the current batch, and not objects
created in the Podfile `post_install`. This PR replaces that guard. The
other part of #44436, the stale podspec cache cleanup in
`precompiled_modules.rb`, is not changed.

This PR wraps `run_podfile_post_install_hooks` again, but only to
install the UUID check. The wrapper creates no objects, so the problem
that #40572 fixed does not come back. Objects that Podfile hooks create
are now protected too.

# How

In `expo-modules-autolinking/scripts/ios/cocoapods/installer.rb`:

- `Expo::CollisionSafeUUIDs#generate_uuid` asks for another UUID while
the current one is already in `objects_by_uuid`. This is the same check
React Native's `spm.rb` uses.
- It is applied to `pods_project` in a new
`run_podfile_post_install_hooks` wrapper, before the original hooks run,
and again in `perform_post_install_actions` (`extend` makes the second
call a no-op). The wrapper creates no objects and does not change
existing UUIDs (see #40572). It is a no-op when `pods_project` is nil
(`skip_pods_project_generation`).
- The old random-UUID replacement of `generate_available_uuid_list` is
removed. The check in `generate_uuid` covers both cases, and new UUIDs
stay predictable from one install to the next.

Not covered, as before this change: sub-projects created with the
CocoaPods `generate_multiple_pod_projects` option.

# Test Plan

**End-to-end**, with the reporter-provided repro
https://github.com/lionel-fodina/expo-ui-ios-repro (expo 57.0.25,
react-native 0.86.3, `@clerk/expo`, expo-modules-autolinking 57.0.13).
CocoaPods 1.16.2, Xcode 27.1 beta, `pod install` then a Release
simulator `xcodebuild`. The fix was applied as the same change ported to
the published 57.0.13 `installer.rb` (that file lacks the nil check that
`main` has).

| Case | `PBXProject` in Pods project | Collision | Build |
|---|---|---|---|
| No patches | 0, root replaced by `XCSwiftPackageProductDependency`
(`ClerkKitUI`) | root UUID | FAILED, `no such module 'Expo'` |
| React Native #57576 only (same `spm.rb` logic as `main`) | 1 |
`46EB2E000000B0`: `ClerkExpo` group vs `[Expo] Remove duplicate codegen
output` | FAILED, `no such module 'Expo'` |
| React Native #57576 + this fix | 1 | none | SUCCEEDED, 154 targets |
| This fix only | 1 | none | SUCCEEDED, 154 targets |

**Local Ruby test** (not committed; the repository runs no Ruby tests):
it drives the real CocoaPods `Pod::Project`, `TargetUUIDGenerator`,
Podfile `post_install` hooks and React Native 0.88 `spm.rb` through this
`installer.rb`, with 0 to 3 spare UUIDs. Before the fix: 5 of 10 tests
fail (both cases above). After the fix: `10 runs, 6435 assertions, 0
failures`.

# Checklist

- [x] I added a changeset (`.changeset/pods-uuid-collision.md`).
- [ ] Docs: not applicable.
- [x] Conforms with the [Documentation Writing Style
Guide](https://github.com/expo/expo/blob/main/guides/Expo%20Documentation%20Writing%20Style%20Guide.md)
chrfalch added a commit to expo/expo that referenced this pull request Oct 6, 2026
…m Podfile post_install objects (#50946) (#50953)

# Why

Cherry-pick of #50946 onto `sdk-57`. Fixes #50794 for SDK 57 apps.

On SDK 57, `pod install` can write a `Pods.xcodeproj` that Xcode cannot
open, because a new object takes a UUID that an existing object already
has. In the worst case the root `PBXProject` is replaced, and the build
fails with only `no such module 'Expo'`. Users hit this after routine
patch upgrades (see the comments on #50794). SDK 57 pins React Native
0.86.3, which does not have react/react-native#57576, so both the
React Native objects and Expo's own build phase can collide.

# How

The same change as #50946: in
`expo-modules-autolinking/scripts/ios/cocoapods/installer.rb`, Pods
project UUID generation skips any UUID already in the project. It is
applied before the Podfile `post_install` hooks run, and again in
`perform_post_install_actions`. It replaces the old random-UUID guard
from #44436.

The cherry-pick had one conflict. On `sdk-57` the old guard has no
`pods_project` nil check, which `main` added later. I resolved it by
removing the old guard in its `sdk-57` form. The new code includes the
nil check. The `.changeset` file from #50946 is replaced by a
`CHANGELOG.md` entry, because `sdk-57` does not use changesets.

# Test Plan

The resulting `installer.rb` is byte-identical to the file used in this
end-to-end test. That test used the reporter-provided repro
https://github.com/lionel-fodina/expo-ui-ios-repro (expo 57.0.25,
react-native 0.86.3, `@clerk/expo`, expo-modules-autolinking 57.0.13,
whose `installer.rb` is identical to `sdk-57`'s). The test ran with
CocoaPods 1.16.2, Xcode 27.1 beta, `pod install` then a Release
simulator `xcodebuild`:

| Case | Pods project | Build |
|---|---|---|
| No patches | Root `PBXProject` replaced by
`XCSwiftPackageProductDependency` | FAILED, `no such module 'Expo'` |
| React Native #57576 only | `[Expo] Remove duplicate codegen output`
phase takes the UUID of the `ClerkExpo` group | FAILED, `no such module
'Expo'` |
| React Native #57576 + this fix | no collision | SUCCEEDED, 154 targets
|
| This fix only | no collision | SUCCEEDED, 154 targets |

A local Ruby test (not committed) runs the real CocoaPods classes and
React Native 0.88 `spm.rb` through this branch's `installer.rb`: `10
runs, 6435 assertions, 0 failures`.

# Checklist

- [x] I added a `CHANGELOG.md` entry.
- [ ] Docs: not applicable.
- [x] Conforms with the [Documentation Writing Style
Guide](https://github.com/expo/expo/blob/main/guides/Expo%20Documentation%20Writing%20Style%20Guide.md)
tvinhas pushed a commit to tvinhas/react-native-macos that referenced this pull request Oct 21, 2026
…dency (react#57576)

Summary:
The first nightly containing the prebuilt/SwiftPM stack (`0.88.0-nightly-20260716`) broke the `react-native-enriched-markdown` job in [react-native-community/nightly-tests](https://github.com/react-native-community/nightly-tests/actions/runs/29476835418/job/87551590732): `pod install` succeeds, but xcodebuild cannot load the generated project:

```
-[XCRemoteSwiftPackageReference _setSavedArchiveVersion:]: unrecognized selector sent to instance
Failed to load container at path: .../Pods/Pods.xcodeproj — "The project 'Pods' is damaged and cannot be opened."
```

**Root cause:** `spm_dependency` injects `XCRemoteSwiftPackageReference` / `XCSwiftPackageProductDependency` objects from a `post_install` hook via `project.new(...)`. CocoaPods' `Pod::Project` overrides UUID generation with a deterministic counter scheme (`prefix + %07X counter + trailing 0`) and deliberately skips collision checks, assuming the project is always freshly generated. When the generator counters are out of sync with the loaded object graph, the first generated UUID collides with an existing object — in the observed failure the root `PBXProject`'s own UUID (`46EB2E00000000`). The injected package reference silently overwrites the root object entry in `objects_by_uuid`, so the saved pbxproj's `rootObject` points at the package reference, and Xcode's loader sends `PBXProject`-only messages to it. The bug is latent in `spm_dependency` since its introduction; the recently grown Pods object graph merely exposed it.

**Fix:** route object creation through a `new_object` helper that keeps the deterministic counter scheme but probes `generate_uuid` forward past any UUID already present in `objects_by_uuid`. Uniqueness is guaranteed against the live object table regardless of project size/state; `generate_uuid`'s counter is strictly monotonic, so the probe terminates and never repeats within a run. Repeated `pod install`s stay idempotent via the existing find-before-create dedup guards.

## Changelog:

[IOS] [FIXED] - Fix "The project 'Pods' is damaged and cannot be opened" when a library uses `spm_dependency` and the generated UUID collides with an existing Pods project object

Pull Request resolved: react#57576

Test Plan:
- New standalone test `scripts/cocoapods/__tests__/spm-test.rb` (runs via `ruby scripts/cocoapods/__tests__/spm-test.rb`, uses the real `Pod::Project`):
  - fresh-project injection (passes before and after — fresh counters don't collide, isolating the trigger),
  - injection after counter reset (reproduces the corruption against the previous code as `NoMethodError: undefined method 'product_ref_group' for ... XCRemoteSwiftPackageReference` on reload — the Ruby analog of Xcode's crash; passes with the fix),
  - global UUID uniqueness + clean `Xcodeproj::Project.open` round-trip.
- 3 tests, 10 assertions, 0 failures with the fix.
- E2E: to be confirmed with a `spm_dependency` library (e.g. react-native-enriched-markdown) in prebuilt mode.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Reviewed By: fabriziocucci

Differential Revision: D112320831

Pulled By: cipolleschi

fbshipit-source-id: de190f6492abff2cc6dbd94347e5346d11b50a41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. p: Expo Partner: Expo Partner Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants