Agent Lineage: Why Merged Agents Looked Like Splits
Internal study - October 6, 2026
Summary
An operator opened a production agent, lets_also_add_to_1, and found six
agents listed under it as "Split into", all archived. Nothing on the page said
why. This study traces the cause, the gaps it exposed, the three design
decisions it forced, and the fix that shipped.
The six agents were never split from the parent. They were near-duplicates
that the hourly auto-dedup sweep folded into it. The sweep archives the
weaker copy and then records the survivor as parent_agent_id, which is the
same column a real specialist split writes. The admin page read that column
alone, so a merge and a split were indistinguishable. Three of the six
"children" were created before the parent existed, which no split can
produce.
| Finding | Status |
|---|---|
| Six "split" children were dedup merges, archived in one 3-second sweep on 2026-07-16 | Confirmed from production data |
agents had no archive reason, timestamp, audit row or notification |
Confirmed; fixed |
| The admin "Current" template label ignored speed mode and did not match routing | Confirmed; label fixed, routing unchanged by decision |
| Parent is org-scoped while its merged children are global | Confirmed; cause identified; left as-is by decision |
| The scheduled dedup is a lossy fork of the ops consolidation tool | Confirmed; converging them is open |
All fixes described here landed in commit 51554bcc on dev-23. No routing
behaviour changed.
1. The mechanism
Two code paths write agents.parent_agent_id:
- A real split.
MutationLifecycleManager._create_specialist_agent
carves a focused specialist out of a catch-all generalist and sets the
generalist as parent. The child starts as acandidateand accrues its own
runs. - A dedup merge.
backend/scripts/dedup_agents.py, run hourly by the
expert-split scheduler, groups agents whose embeddings have cosine
similarity of 0.80 or higher within one tenant bucket. It keeps the
highest-quality agent, moves the others' runs, feedback and template
versions onto it, archives them, and then sets the survivor as their
parent "so the merge is visible as lineage".
Both land in the same column. The admin endpoint returned every
parent_agent_id child under one children list, and the page rendered that
list under "Split into (N)".
lineage_kind classifier separates them before the page renders.Evidence from production
| Signal | Observation |
|---|---|
| Parent | lets_also_add_to_1, active, org-scoped, created 2026-07-06, quality score 0.889, one run |
| Children | Six agents, all archived, all global (no org), quality 0.60 to 0.84, 0 to 9 runs each |
| Creation order | Three children predate the parent (2026-06-04, 2026-07-01, 2026-07-01) |
| Archive timing | All six archived between 19:43:02.9 and 19:43:03.3 UTC on 2026-07-16 |
| Batch context | 40 agents under 12 parents archived within 3 seconds in that sweep |
| Names | Three children named "Recent Conversation History (Oldest First):", the parent's own problem signature. These are broker-preamble clones from before the fix in e7afc5183 |
| Templates | None of the six children retained a template version; the parent carries their moved versions |
| Chain variants | Eleven variants under the archived children still active; the sweep never touches that table |
| Audit trail | No notification, audit row or canary outcome anywhere referenced the archival |
The canonical-selection rule (keep the highest quality score) matches the
data exactly: the parent's 0.889 beats every child. Stale-agent collection,
expert-duplicate archiving, the consolidation ops tool and the cohesion sweep
were each ruled out by their thresholds or by the state they write.
2. Archiving recorded nothing
AdaptiveAgentDB.archive_agent set lifecycle_state = 'archived' and bumped
updated_at. That was the whole write. Five callers used it: the dedup
sweep, the cohesion sweep, expert duplicate detection, stale-agent collection
and the admin console. None of them left a reason, an actor or a timestamp
beyond updated_at. Template versions already carried archived_at and an
archive_reason in their mutation metadata, so the pattern existed one table
over.
archived, so the nine readers that filter on it are untouched; the reason lives in metadata and is what the classifier in Figure 1 reads.3. "Current" depended on who was asking
The same page listed eleven template versions for a second agent,
get_the_links_for_1, as "Superseded" with no "Current" in the same speed
mode. The operator expected one current version per speed mode. The code had
never had that concept.
The label was a frontend guess: the highest active version number agent-wide
was "Current" and every other active version was "Superseded". No backend
code writes a "superseded" state. The runtime, meanwhile, has two selection
paths that disagree with each other:
| Selector | Rule | Honours speed category |
|---|---|---|
| Old admin label | Highest active version, agent-wide | No |
Pinned and recalled routing (get_latest_active_template_version) |
Highest active version | No |
Ranked retriever (retrieve_and_rank) |
Similarity, EMAs, recency and a speed bonus of 1.0 for a matching or auto category, 0.2 otherwise |
Yes, as a bonus |
The eleven versions were also not one lineage. Their ids were
question_direct:v3 to v11 and 5x5_1:v2: the merged duplicates' own
template rows, moved onto the canonical agent by the sweep in Figure 1 with
their ids unchanged. One version was fast, ten were auto.
4. When the parent changed hands
The dedup sweep buckets agents by tenant and never groups across buckets.
Yet the parent is scoped to one organisation while all six merged children
are global. For the merge to have happened, the parent must have been global
at the time.
The cause is a since-fixed write. Until commit 252a06a57 on 2026-08-30, the
agent upsert resolved scope with COALESCE(existing, incoming), so the first
organisation-scoped run against a global agent captured it for that
organisation. The parent's updated_at of 2026-08-09 falls inside that
window. No scope-history row exists, so the capture is inferred from the
timestamps and the fixed code path rather than read from a record.
5. Three decisions
Each gap admitted a conservative option (A) and a deeper one (B). The owner
chose A for all three. The trade-offs are recorded here so the B options can
be revisited without re-deriving them.
Decision 1: what state does a merged duplicate end up in?
A: keep archived, add a reason |
B: adopt merged, as the ops tool does |
|
|---|---|---|
| Reader changes | None; every != 'archived' filter keeps working |
Nine SQL sites must become NOT IN ('archived','merged') or merged rows re-enter dedup and are archived again |
| Meaning | Lives in seed_metadata_json.archive; state alone cannot tell merge from retirement |
The state carries meaning; reversibility comes with the existing agent_merge snapshot |
| Admin UI | Existing archived pill and "Unarchive" button; "Unarchive" on a merged row would resurrect a duplicate whose runs were moved away | New pill, new "Unmerge" action |
| Backfill | None needed; 570 archived agents stay as they are | Must guess which archived rows were merges |
| Chosen | Yes | Deferred |
Decision 2: should routing honour speed category, or only the label?
| A: label fix, computed server-side | B: make pinned and recalled routing speed-aware | |
|---|---|---|
| Runtime change | None | get_latest_active_template_version gains a speed filter; mutations, canaries and adaptive persistence fork per speed |
| What the page shows | Which version each fallback path would actually pick, per speed | The same, and routing agrees with it |
| Risk | None to live traffic | Changes which prompt real users get; needs a fallback order when a category has no template, and a latency A/B |
| Effort | A day, one endpoint test and one browser walk | A product change owned by orchestration |
| Chosen | Yes | Deferred |
Decision 3: the organisation-captured parent
| A: keep as-is | B: un-adopt back to global, per row, owner-confirmed | |
|---|---|---|
| Disruption | None; the organisation keeps using the agent if it does | The agent vanishes from that organisation's matching the moment it flips |
| Isolation | An org-scoped agent whose history spans tenants remains an audit smell | Restores the pre-capture truth; dedup bucketing works as designed again |
| Evidence needed | None | Whether the organisation's own runs reference it (here: one run, zero global runs) |
| Chosen | Yes | Deferred, with an audit script proposed first |
6. What shipped
Commit 51554bcc on dev-23, 10 files, 394 insertions, tested and walked
in a local browser:
archive_agentandarchive_experttakereason,actorand
merged_intoand merge anarchiveblock intoseed_metadata_jsonin the
same UPDATE, preserving every existing key. All five callers pass a reason.- The dedup sweep emits one admin notification per committed run that
archived anything. - A new
backend/services/agent_lineage.pyholds three pure helpers:
lineage_kind_for_agent,partition_children_by_kindand
current_template_by_speed. GET /api/admin/agents/<id>addslineage.children_split,
lineage.children_merged,lineage.parent.relationand
current_by_speed. All additive; the existingchildrenlist is kept.- The admin agent page renders "Merged into this (N)" separately from
"Split into (N)", labels the parent "Merged into" when the viewed agent was
absorbed, and shows "Current (fast, auto, deep)" labels with a note that
routing may still differ by path.
Verification: 31 backend tests pass, the frontend typecheck is clean, and a
throwaway local fixture (parent with a fast v1 and an auto v2, archived
child with dedup_merge metadata) rendered "Merged into this (1)",
v2 Current (fast, auto, deep) and v1 Superseded.
7. Open items
- The scheduled dedup is a lossy fork.
scripts/dedup_agents.py
re-points four tables and hard-deletes colliding template versions;
ops/consolidate_duplicate_agents.pyre-points seventeen, blends EMAs and
stores a reversible snapshot. Converging both on one merge service is the
real fix for the orphaned chain variants and the foreign template ids. - Decision 1B and 2B stand as recorded above.
- Scope-capture audit. Rows captured before
252a06a57were never
repaired. A read-only audit listing agents whose scope disagrees with their
lineage or run history is the prerequisite for any un-adopt. - Dead columns.
agent_template_versions.activated_atis never written,
andagents.current_versionis never reconciled with the versions table. - Boilerplate names. Rows named after the leaked broker preamble were
never renamed; archived rows are safe to backfill, the active parent needs
care because its problem signature feeds recall.
Method notes
- Production facts come from read-only queries against the production
database on 2026-10-05; no production row was modified. - Code paths are cited as they stood at
dev-23head51554bcc. - The archive-reason write casts
seed_metadata_jsonthroughjsonb. A
row holding invalid JSON text in that column would fail to archive; every
row inspected held{}or valid JSON.
(c) 2026 Elis AI. All rights reserved. tryelisai.com