fix(desktop): preserve cross-install agent identities
Summary
- enforce
one persona_id, one keypairat the central managed-agent key-generation boundary, covering Start, mention, channel-add, team-add, onboarding, and other creation surfaces - fail closed until the exact relay+owner kind:30177/deletion history has been completely fetched and durably reconciled; incomplete, failed, capped, or unpageable backfills cannot authorize a new keypair
- expose retained owner-authored kind:30177 persona links as a non-runnable, community-scoped identity index and reuse existing agents instead of minting duplicates
- make deletion of a relay-synced/bodyless definition local-only so a secondary install cannot publish a kind:5 tombstone for the shared kind:30175
- queue a NIP-IA kind:9035 archive request when deleting a locally owned agent body, allowing Desktop discovery to hide the retired identity from the relay's kind:13535 snapshot
- when a legitimate shared-definition tombstone arrives, snapshot linked local agents into standalone records, preserve their pubkeys/keypairs, and publish repaired kind:30177 projections
- add an edit-time relink path for already-orphaned agents so they can adopt an active definition without identity rotation
- make tombstone suppression delivery-order independent and exclude deleted retained identities from the reference index
Closes #3414. Closes #3440.
Testing
Rebased onto main at 4d47aa834; branch head 7433a135e.
- 3,839 desktop frontend tests passed
- 1,931 Desktop Tauri tests passed, 14 ignored; 3 diagnostics passed
- 1,019 Flutter tests passed, 1 skipped
- workspace Clippy passed with warnings denied
- desktop, web, and mobile formatting/static analysis passed
- desktop and web production builds passed
cargo checkfor Desktop Tauri passed- the macOS
desktop-tauri-clippyleg currently fails on three dead-code warnings in unchangedmainfiledesktop/src-tauri/src/linux_media.rs, introduced by merged PR #3607; #3441 does not modify that file - regression coverage asserts the key factory is never invoked when any identity already links the persona; it intentionally does not select which historical duplicate “wins”
- sync-readiness coverage for empty completed history, persistence-in-flight, fetch failure, and capped/unpageable tied timestamps
- deletion, archive-request, tombstone ordering, detach, and orphan relink regression coverage
Manual verification and the two review questions, updated after the branch fix.
I reproduced the ghost-key defect on shipped Buzz 0.5.2 from a secondary install with no local key for the persona. The failing sequence produced kind:30177 and kind:44100 in the same second, followed by a new kind:0 from a second pubkey. The negative control from the install that already held the key was clean. Which key remained active varied between reproductions, so that ordering is evidence of danger—not an invariant or a test expectation.
The invariant is now enforced at the backend key-generation boundary: one persona_id, one keypair. Every creation surface, including channel add, converges on create_managed_agent; persona-backed creation cannot invoke the key factory when either a local agent record or a retained account-scoped kind:30177 already links that persona. The regression test supplies both an original and a prior duplicate and asserts that the key factory is never called; it does not select a winner.
The empty-versus-unknown gap is also closed. Persona-backed creation fails closed until the exact relay+owner history backfill is complete and durably reconciled. Fetch failure, reconciliation failure, pagination cap, and an unpageable tied-timestamp boundary all leave the reference index unknown and key creation blocked.
Deletion behavior remains deliberately asymmetric: removing a relay-synced/bodyless definition is local-only and cannot tombstone the shared kind:30175; deleting a locally owned body also queues the NIP-IA kind:9035 archive request so Desktop discovery can hide the retired pubkey from the relay's kind:13535 snapshot. A foreign ghost that the install does not own is not guessed at or automatically archived.
The branch is rebased onto current main at 7433a135e. Validation after the rebase passed 3,839 desktop frontend tests, 1,931 Desktop Tauri tests, 3 Tauri diagnostics, and 1,019 Flutter tests, plus workspace Clippy, static checks, and desktop/web builds. The only local gate failure is macOS Tauri Clippy on three dead-code warnings in unchanged main file desktop/src-tauri/src/linux_media.rs, introduced by merged PR #3607; this branch does not modify that file.
Closing this. The bug it fixes is still there on main. This branch is no longer the way to fix it.
It is 389 commits behind and conflicts in six files: app_state.rs, commands/agent_models.rs, commands/agents.rs, personas/inbound.rs, useAgentsDataRefresh.ts, usePersonaSync.ts. #7131 rewrote most of those when it rebound explicit agent profiles to their exact key. Rebasing here means rewriting the change against code that moved, and this branch never drew a review to preserve anyway.
The problem itself: a second install of an agent mints a new keypair under the same display name, and there is no repair path once it happens. #5667 tracks that. #6997 asks for the owner-side attestation the fix needs. Those threads are live and this one is not.
The diff stays here if anyone wants the approach.