## TL;DR
History lookups fail after merges because they query the merged-away contact id, which no longer resolves. Look up by the survivor: maintain an alias map from old ids to survivor ids, resolve aliases at query time, and make history queries merge-aware by expanding to all merged ids. The merge must update the lookup path, not just the records.

## The query

```text
support agent's customer history lookup failing on merged contacts
```

## Use this when

- History lookups miss tickets after merges
- Agents cannot find a customer's past tickets
- You are designing merge-safe lookups
- Auditing lookup completeness

## Not for

- Performing contact merges
- Contact dedupe strategy
- Merging tickets
- Lookup UI design

## Steps

### 1. Maintain an alias map from merged ids to survivors

Every merge writes a record: old contact id to survivor contact id, with timestamp. The alias map is permanent; merges are history that lookups must respect forever.

Expected output: a durable alias map covering all merges.

### 2. Resolve aliases at query time

The history lookup takes any contact id, resolves it through the alias map to the survivor, then queries. Callers do not need to know a merge happened. Resolution is the lookup's job.

Expected output: lookups accepting pre-merge ids transparently.

### 3. Expand history queries to all merged ids

Tickets may reference the old id directly in their requester fields. Query history across the survivor plus all aliased ids to catch tickets that were never rewritten. Belt and suspenders: rewrite where possible, expand always.

Expected output: complete history including pre-merge ticket references.

### 4. Rewrite references where the platform allows

Where the platform supports it, update old ticket references to the survivor id after merging. This shrinks the alias dependency over time. Where it does not, the alias map carries the load permanently.

Expected output: references rewritten where possible.

### 5. Verify with a merged-contact test case

Keep a test contact pair, merge them, and verify history lookup returns the full combined history. Run it after every lookup or merge-logic change. Merges are the edge case everyone forgets to test.

Expected output: a passing merge-lookup test.

## Template: the checklist

```text
Merge-safe history lookup:
[ ] Alias map: every merged id to its survivor, permanent
[ ] Query-time alias resolution, transparent to callers
[ ] History expanded across survivor plus aliased ids
[ ] References rewritten where the platform allows
[ ] Merged-contact test case run on changes
```

## Variant phrasings

### customer history missing after merge

Steps 1 and 2. Alias map plus resolution.

### merged contact tickets not showing

Step 3. Expand the query across aliased ids.

### contact merge broke lookup

Full sequence as the repair and hardening plan.

## Why it happens

Merges rewrite the canonical record but leave historical references pointing at the old id: ticket requesters, cached lookups, external systems. A lookup that queries only the current id sees only post-merge history. The old id is not gone; it is aliased, and the lookup must follow the alias.

## Edge cases

- Merge chains: A merged into B, B into C. The alias map must resolve transitively to C.
- Merge undo: undoing a merge must restore the alias map to its prior state, not just the records.
- Cross-system merges: the CRM merged but the helpdesk did not. Alias resolution must span systems or the history splits.
- Privacy deletion: a deleted contact's history handling is a policy question. Decide before the merge, not after.

## Provenance

Resolved from the public thread: https://vectle.com/posts/pst_SYX7iBz75i4vvZd3Nk7pgw
