Repository navigation
Load Apple's ADI library once per process, instead of once per caller - #137
Merged
Merged
Conversation
wanderdev0
temporarily deployed
to
Android Build
August 22, 2026 15:16 — with
GitHub Actions
Inactive
wanderdev0
temporarily deployed
to
Android Build
August 22, 2026 15:16 — with
GitHub Actions
Inactive
Three whole-suite aborts today, each naming different tests. All the same
native crash:
signal 11 (SIGSEGV) in tid RxCachedThreadS
libstoreservicescore.so <- NativeAdi.callWithPath <- AdiLibrary.initialise
<- LocalAnisette.load <- ensureReady <- AnisetteStatus.of
`ensureReady()` is `synchronized` and guards with `this.adi != null`, which
looks like it covers this. It does not: `AppDependencies.anisette` is
`LocalAnisette::new`, so every caller gets a fresh instance with its own lock
and its own null field. The guard never fired and the lock excluded nothing.
Two threads reaching it at once is the ordinary expired-session path - the map
restores on one, the restore fails, the login screen it redirects to asks on
another - and the log shows both unpacking the same file before dlopening it:
2419 AdiLibraryFetcher: libstoreservicescore.so: 2.39 MB unpacked
2570 AdiLibraryFetcher: libstoreservicescore.so: 2.39 MB unpacked
Now held in a process-wide `LoadedOnce`, covering the download and the unpack
as well as the initialise, because the race starts at the file writes.
Two things that came out of writing it:
- **The identity is cached with the library.** `loadOrCreateIdentity` *creates*
one when there is none, so two threads on a fresh install could mint two and
register this app twice on somebody's Apple account. Rule 11 says there is one
identity; nothing had noticed this route to breaking that.
- **A failed load is not cached.** One flat network moment must not mean
Anisette never loads again until restart - and since the fallback is a remote
server, nothing would look broken enough to investigate.
**Testable, which it would not have been inline.** Exercising this in place
means downloading Apple's libraries and running their native code, which the
suite deliberately avoids - so the rule is extracted to `LoadedOnce` and tested
with twenty threads released at once. Verified it catches the real bug: dropping
`synchronized` from `get()`, which is the shape LocalAnisette had, turns exactly
that test red.
Evidence the app fix works, not just the tests: this branch has none of the
test-side Anisette fakes, so the classes that were aborting runs still load the
real library here. 569 tests, no failures, no abort.
Closes #135
Co-Authored-By: Claude Opus 5 <[email protected]>
wanderdev0
force-pushed
the
fix/load-apples-adi-once
branch
from
August 22, 2026 15:34
40bc23d to
f71d4c6
Compare
wanderdev0
temporarily deployed
to
Android Build
August 22, 2026 15:34 — with
GitHub Actions
Inactive
wanderdev0
temporarily deployed
to
Android Build
August 22, 2026 15:34 — with
GitHub Actions
Inactive
saamdotexe
pushed a commit
to saamdotexe/OpenTagViewer
that referenced
this pull request
Oct 22, 2026
…di-once Load Apple's ADI library once per process, instead of once per caller
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Three whole-suite aborts today, each naming different tests, all the same native crash. The
logcat artefact added in #130 is what made it findable.
The guard that guarded nothing
That reads like "load it once". It is not, because of one line elsewhere:
Every caller gets a fresh instance — so its
adifield is always null, and its lock isalways uncontended. The guard never fired and the
synchronizedexcluded nothing, while thething being guarded — a shared object loaded into the process, and ADI's own internal state — is
per-process.
Two at once is the ordinary case, not a corner
It is what an expired session does:
MapsActivitystarts restoring and asks for Anisette on an Rx thread.AppleLoginActivitycallsAnisetteStatus.of(AppDependencies.anisette(...))— while thefirst is still working.
Both then unpack the same files to the same path before loading them:
The fix
Apple's library is held in a process-wide
LoadedOnce, and the lock covers the download andunpack as well as the initialise — the race starts at the file writes, not at ADI.
Two things surfaced while writing it:
loadOrCreateIdentitycreates one when there isnone, so two threads on a fresh install could mint two different identities and register this
app twice on somebody's Apple account. Rule 11 is emphatic that there is one identity;
nothing had noticed this route to breaking it.
again until restart — and because the fallback is a remote server, nothing would look broken
enough to investigate.
Making it testable, which inline it was not
Exercising this in place means downloading Apple's libraries and running their native code, which
the instrumented suite deliberately avoids. Left inline, the one property that matters would have
been verified by reading it.
So the rule is a small class,
LoadedOnce, with a JVM test that releases twenty threads atonce and asserts the supplier ran exactly once — plus that a failure is retried rather than
remembered, and that
forget()works, which a futureADIProvisioningErasewill need.Verified it catches the real bug: dropping
synchronizedfromget()— literally the shapeLocalAnisettehad — turns exactly that test red and nothing else.Evidence the app is fixed, not just the tests
The iCloud PR removed the trigger from four test classes by faking Anisette. That was a
workaround and was described as one.
This branch has none of those fakes. The classes that were aborting runs still load Apple's
real library here — and the suite completes: 569 tests, no failures, no abort, where three
runs earlier today stopped at 335, 374 and 489.
Not proof that every abort had this cause, but it is the only one anybody has a stack trace for,
and the trigger is an ordinary user state rather than a test artefact.
Closes #135
🤖 Written by Claude Code