Files
buzz/desktop/scripts
npub1mn7jgtj4w2pd0g0zeuhxsa6jy6p0rewxz4kujt98my82ahfmp72sxjexk7andWill Pfleger a4d66205d7 fix(desktop): repair team-persona mismatch and deduplicate legacy imports
Teams created before PR 852 store the pack manifest ID (e.g.
com.wpfleger.sietch-tabr) in PersonaRecord.source_team but the sync and
delete predicates compared against TeamRecord.id (a UUID). Additionally
TeamRecord.source_dir was often null, so the sync gate never passed.

Introduces team_persona_key() as the single derivation used by sync,
delete-cascade, and import — extracts the directory name from source_dir
(the manifest ID), falling back to team.id for non-directory teams.

On launch, sync_team_personas runs a one-time idempotent repair:
1. Backfills source_dir by matching persona source_team values to
   directories under teams/
2. Deduplicates PersonaRecords sharing (source_team, slug) — keeps
   newest by updated_at desc / id asc, repoints TeamRecord.persona_ids
   and ManagedAgentRecord.persona_id to the winner
3. Self-healing scrub removes any dangling references that point to
   persona IDs not in the surviving set (crash-window recovery)

Saves are ordered reference-holders-first (teams, agents) before the
personas they point to, so a crash mid-repair leaves over-pointing
(harmless) rather than dangling references (permanent).

All repair logic — derivation, backfill, dedup, and the launch
orchestrator — lives in team_repair.rs, keeping teams.rs under the
base 1000-line file size limit without a per-file override.

Co-authored-by: Will Pfleger <pfleger.will@gmail.com>
Signed-off-by: Will Pfleger <pfleger.will@gmail.com>
2026-06-10 15:06:32 -04:00
..