fix(mac): document the main-queue serialization and harden the deadlock test cleanup

The lock no longer covers the defaults write, so the main-queue hop is
what keeps the read-modify-write atomic; say so where the next reader
would be tempted to make it async. The regression test now cleans up its
observer and defaults domain on every exit and waits up to 5 seconds, so
a loaded runner cannot fake a deadlock.
This commit is contained in:
iamtoruk 2026-09-01 04:58:16 -07:00
parent da20fd0f42
commit c436787239
2 changed files with 13 additions and 5 deletions

View file

@ -214,6 +214,12 @@ enum CapacityDockProviderCredentialPresence {
object: nil
)
}
// The lock only covers the compute above; releasing it before the
// defaults write is what breaks the reentrancy deadlock. What keeps the
// read-modify-write atomic across concurrent callers is that every
// mutation runs serialized on the main queue, so this must stay a
// synchronous hop: switching it to async reintroduces lost updates and
// breaks read-after-write (see CredentialKeychainContinuityTests).
if Thread.isMainThread {
update()
} else {

View file

@ -128,21 +128,23 @@ struct ProviderSettingsEditorStateTests {
_ = CapacityDockProviderCredentialPresence.contains("kimi", defaults: defaultsBox.value)
callbackFinished.setCompleted()
}
defer {
NotificationCenter.default.removeObserver(observer)
defaults.removePersistentDomain(forName: suiteName)
}
DispatchQueue.global(qos: .userInitiated).async {
CapacityDockProviderCredentialPresence.set(true, for: "kimi", defaults: defaultsBox.value)
writeFinished.setCompleted()
}
for _ in 0..<50 where !writeFinished.isCompleted {
// A deadlocked write never completes, so the bound only needs to be
// generous enough that a loaded CI runner cannot fake one.
for _ in 0..<500 where !writeFinished.isCompleted {
try await Task.sleep(for: .milliseconds(10))
}
#expect(callbackFinished.isCompleted)
#expect(writeFinished.isCompleted)
if writeFinished.isCompleted {
NotificationCenter.default.removeObserver(observer)
defaults.removePersistentDomain(forName: suiteName)
}
}
@Test("credential mutations await their real Keychain completion")