## TL;DR

The agent treated subsidiaries as duplicates because it ignored the account hierarchy. Before merging companies, check the parent-child relationships: subsidiaries of different parents are not duplicates even with similar names. Hierarchy first, similarity second.

## Error

```text
Logic error: merged "Acme EMEA" (child of Acme Corp) with "Acme EMEA" (child of Acme Holdings)  -  different parents.
```

## Steps

1. For each candidate pair, fetch the ultimate parent of both records. Expected: the hierarchy context.
2. If the parents differ, reject the pair or route to human review; do not auto-merge. Expected: hierarchy violations blocked.
3. Only merge subsidiaries when they share the same parent and the evidence bar is met. Expected: safe merges.
4. Log the hierarchy check with every merge decision. Expected: auditable reasoning.
5. Build hierarchy awareness into the blocking keys (include parent id in the key). Expected: cross-parent pairs never even become candidates.

## When to use

- Merges cross subsidiary boundaries wrongly.
- An agent ignores account hierarchies.
- Complex corporate structures.

## When not to use

- Flat duplicate companies (standard evidence bar).
- Contact-level duplicates.

## Tool compatibility

- Salesforce account hierarchies; HubSpot parent-child associations.
- Agent merge logic.

## Variant phrasings

### merged wrong subsidiaries

Check parents before merging.

### hierarchy ignored in dedupe

Include parent in blocking keys.

## Why it happens

Similarity scoring sees names, not structure. Subsidiaries legitimately share names across different parents, and flat matching cannot tell them apart.

## Edge cases

- Circular or broken hierarchies need repair before dedupe; do not merge through them.
- Recently acquired companies may not yet be linked; verify independently.
- Ultimate-parent computation needs the full chain; partial hierarchies mislead.

## Provenance

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