Agent Lineage: Why Merged Agents Looked Like Splits

Internal study - how dedup merges were rendered as splits, what archiving failed to record, and the fixes that shipped.

Generated: 2026-10-06 05:05 UTC

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 a candidate and 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)".

Real split Dedup merge (hourly sweep) _create_specialist_agent mutation_lifecycle.py creates new specialist agent lifecycle = candidate set_agent_parent run_dedup(commit=True) cosine >= 0.80, same tenant bucket loser weaker duplicate archive_agent(...) set_agent_parent parent = canonical (the survivor) agents. parent_agent_id the only lineage column reads list_child_agents + lineage_kind db.py BEFORE (admin page) Split into (6) all six were merges AFTER (children_split / children_merged) Split into (0) Merged into this (6) reason = dedup_merge
Figure 1. Two writers, one column, one label. The new 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.

Callers reason passed dedup_agents.py run_dedup dedup_merge + merged_into agent_cohesion.py sweep cohesion_quarantine mutation_lifecycle evaluate_experts archive_duplicate mutation_lifecycle gc_stale_agents archive_stale admin_agent_service (POST /archive) admin + actor = admin email archive_agent / archive_expert UPDATE agents SET lifecycle_state = 'archived', updated_at = now(), seed_metadata_json = (meta::jsonb || {"archive": {reason, actor, at, merged_into?}})::text existing keys preserved; one statement BEFORE: only lifecycle_state + updated_at. No reason, no audit row. commit and agents_archived > 0 one system_admin_notification per sweep kind = agent_dedup counts + up to 10 canonical ids, never one per row
Figure 2. Archiving now says why. Lifecycle stays 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.

agent_template_versions, status = active, newest right v1fast v2auto v3auto v4auto ... v9auto v10auto v11auto ids are question_direct:v3..v11, moved here by the merge in Figure 1 Selector Rule Picks Old admin label versionState (before) highest active version, agent-wide ignores speed_category v11 Pinned / recalled routing get_latest_active_template_version highest active version no speed filter: a fast request also gets v11 v11 Ranked retriever template_retriever.retrieve_and_rank similarity + EMAs + speed bonus bonus 1.0 if category matches or auto, else 0.2 varies NEW: current_by_speed (server-side, display only) for speed S, highest active version whose category is S or auto; exact category wins only on a tie fast -> v11 auto -> v11 deep -> v11 v1 (fast) is shadowed: v11 is higher and auto serves fast
Figure 3. Which version is "Current" depends on who is asking. The new label follows the pinned path, per speed mode, and says so on the page.

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.

Jun 1 Jul 1 Aug 1 Sep 1 children (global scope, no org) Jun 4 1 child Jul 1 2 children Jul 6 2 children Jul 9, 1 child parent created Jul 6 Jul 12 e7afc5183 preamble-name fix Jul 16 19:43 UTC: dedup sweep 40 agents, 12 parents, 3 seconds these 6 archived, parent_agent_id = lets_also_add_to_1 Aug 9: parent.updated_at inferred org capture via old upsert COALESCE parent now scoped to one organisation Aug 30 252a06a57 upsert no longer captures window in which a first org run could capture a global agent
Figure 4. When the parent changed hands. Dashed marks are inferred from timestamps and the fixed code path, not from a scope-history row, because none exists.

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_agent and archive_expert take reason, actor and
    merged_into and merge an archive block into seed_metadata_json in 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.py holds three pure helpers:
    lineage_kind_for_agent, partition_children_by_kind and
    current_template_by_speed.
  • GET /api/admin/agents/<id> adds lineage.children_split,
    lineage.children_merged, lineage.parent.relation and
    current_by_speed. All additive; the existing children list 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.py re-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 252a06a57 were 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_at is never written,
    and agents.current_version is 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-23 head 51554bcc.
  • The archive-reason write casts seed_metadata_json through jsonb. 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