BYOK owner decisions: silent key wipe on upgrade is undocumented; activeBYOKSnapshot/hasTranscriptionBYOK disagree on Deepgram enrollment
Two BYOK owner-decision findings from the #12276 diagnosis: silent key wipe on upgrade (undocumented), and a Deepgram-inclusion predicate mismatch
Found while root-causing #12276 (stale BYOKPaywallTests/AgentRuntimeProcessTests). Neither blocks that fix or the pipeline behind it — routing both here for whoever owns BYOK to decide on, not fixing myself.
Finding A: every pre-existing BYOK user's stored keys are silently wiped on first launch after upgrade, undocumented
APIKeyService.bindBYOKOwner (desktop/macos/Desktop/Sources/APIKeyService.swift:263):
nonisolated static func bindBYOKOwner(_ uid: String?) {
guard let uid, !uid.isEmpty else { return }
let last = UserDefaults.standard.string(forKey: DefaultsKey.byokOwnerUid.rawValue)
if last != uid {
// Unowned pre-upgrade keys (last == nil) are unsafe to inherit: the next
// signed-in account would otherwise enroll someone else's credentials.
clearPersistedBYOKKeys()
UserDefaults.standard.set(uid, forKey: DefaultsKey.byokOwnerUid.rawValue)
}
}
Called from reconcileBYOKActivation(), which runs on both AuthService sign-in paths (AuthService.swift:583, :1091) — effectively every app launch/session-restore for a signed-in user.
byok_owner_uid was introduced in 95e87c3f9e ("fix(macos): bind BYOK keys to the signed-in owner and persist after enroll"), which predates #11454. Any user who configured BYOK keys before that commit has no byok_owner_uid stored — last reads nil, nil != uid is true, and clearPersistedBYOKKeys() wipes their stored keys (and, post-#11454, their enrollment fingerprints) on the very next reconciliation. This is deliberate per the comment — the alternative (silently inheriting unowned keys into whichever account signs in next) is worse — but it means every user who configured BYOK before 95e87c3f9e shipped had their keys cleared once, with no re-entry prompt beyond falling back to the paywall/trial gate until they notice and re-enter.
The changelog does not mention this. The user-facing note for this line of work — desktop/macos/changelog/unreleased/20260812-byok-provider-menu.json (landed in 1dfe35f5e0, later consolidated into desktop/macos/changelog/releases/0.12.222.json) — reads only:
Added a simpler BYOK provider menu with OpenRouter chat routing and separate transcription setup
Nothing about existing keys being cleared. #11454 compounds the blast radius by adding the fingerprint-enrollment requirement on top: a wiped user isn't just missing their raw keys, they also need a fresh activateBYOK reconciliation round-trip (validate → enroll) before BYOK reactivates, which the current UI doesn't specifically prompt for beyond the ordinary "add your key" flow.
Not asserting this needs a code change — the safety rationale in the comment is sound — but a fleet-wide implicit credential-reset with no changelog disclosure and no user-facing "we cleared your BYOK keys, please re-enter" surface seems worth a deliberate decision rather than a side effect of comment-only intent.
Finding B: activeBYOKSnapshot and hasTranscriptionBYOK disagree on what "the Deepgram key is usable" means
APIKeyService.activeBYOKSnapshot (APIKeyService.swift:324) includes Deepgram whenever a raw key is present:
if let key = byokKey(.deepgram) {
snapshot[.deepgram] = (key, byokFingerprint(key))
}
APIKeyService.hasTranscriptionBYOK (APIKeyService.swift:249) requires the enrolled fingerprint to match:
nonisolated static var hasTranscriptionBYOK: Bool {
guard selectedBYOKLLMProvider != nil, let key = byokKey(.deepgram) else { return false }
return enrolledFingerprints()["deepgram"] == byokFingerprint(key)
}
So usableBYOKEnvironment() (Chat/AgentRuntimeProcess.swift:2780), which builds its candidate set from activeBYOKSnapshot, can attach a Deepgram key that was never enrolled/validated — the same raw-presence-only gap #11454 closed for the selected LLM provider (isByokActive) but not for Deepgram specifically. testHasTranscriptionBYOKRequiresEnrolledDeepgramFingerprint (already in the suite) proves hasTranscriptionBYOK itself is correct; it's activeBYOKSnapshot's independent, looser Deepgram inclusion that disagrees with it.
Backend validates BYOK keys server-side on use, so this is not an entitlement bypass — an unvalidated or rotated-and-rejected Deepgram key sent this way would still be rejected upstream. Flagging the inconsistency because it means the same raw-presence bug class #11454 explicitly fixed for one predicate still exists for a different one that reads the same underlying key.
What I have not done
- Not proposed a fix for either — both are product/security-adjacent calls (what should happen to a wiped user's session; whether Deepgram should require the same enrollment strength as the selected LLM provider) that belong with whoever owns BYOK.
- Not touched any BYOK code.
Hi @josancamon19 @kodjima33 — I’m haotvko. I’d like to offer a focused fix for Finding B for US$15, subject to approval under the contribution guide’s bounty process.
My scope would make Deepgram inclusion in activeBYOKSnapshot use the same enrolled-fingerprint contract as hasTranscriptionBYOK, preserve the current selected-LLM behavior, and add regression coverage for enrolled, missing, rotated, and rejected fingerprints. I would also trace the snapshot’s consumers to verify that an unvalidated Deepgram key cannot be attached to a runtime environment through another path. Finding A and its product decision about upgrade messaging/key clearing would remain outside this PR.
Please confirm whether this bounded scope and fee are acceptable and point me to the current cash-payout terms before work starts. No implementation, completed validation, assignment, or approved reward is claimed yet. Thank you.
Implemented both findings in #13989.
- Owner binding remains fail-closed, but clearing legacy unowned or different-account keys now persists an owner-scoped explanation and presents a one-time re-entry notice through the existing non-blocking sheet queue. The notice survives relaunch until acknowledgement and cannot cross account boundaries.
- Validation candidates are now separate from runtime-active credentials. Selected LLM and Deepgram keys can still be validated/enrolled, while transcription, realtime relay, HTTP, and agent-runtime consumers receive only current keys whose fingerprints are enrolled. Never-enrolled and rotated keys are excluded.
Regression proof: 25 focused Swift tests pass, covering legacy/different/same-owner behavior, notice persistence and acknowledgement, owner isolation, raw/enrolled/rotated fingerprints, request headers, and downstream agent-runtime forwarding. The full local PR preflight also passed all 25 selected repository checks, including pinned formatting, SwiftLint (1,705 files, zero violations), changelog, test-quality, invariant, and failure-class contracts.