Skip to content

merge-plans never shows the surviving entity of an assertion/steward merge #838

Done

Description

@athvin

Found by: #802's pg_merge_group e2e (review merge dialog bundle)

What is wrong

GET /v1/orgs/{org}/datasets/{ds}/merge-plans shows nothing for the entity that
survives a steward/assertion merge — the exact entity a steward just pinned a
master on. After resolving a review as "match" (or merging a group via
POST /merges), the plans list stays empty of the merged result.

Mechanism

er_golden::merge_plans_sql scopes the read with

affected AS (SELECT DISTINCT entity_id FROM entity_events
             WHERE event_type IN ('merged','member_added'))

keyed on the entity_id the event names. In er-reconcile::reconcile_plan:

  • a merged event is recorded on the absorbed entity id (the one that
    leaves entity_membership), with the survivor named only in
    details.merged_into — which no read follows;
  • member_added fires on the survivor only for records that had no prior
    entity (!entity_of_record.contains_key(m)). An assertion merge combines
    records that were all already clustered, so joined is empty and the
    survivor earns no event at all.

The absorbed ids then drop out of plan_groups (no members left), so the net
result is an empty plans list for the merge that just happened. The same shape
likely hides pure recluster moves (a split event names the receiver, but
split is not in the CTE).

pg_protect_master never hit this because its organic merge arrives with a
brand-new bridging record, which does earn the survivor a member_added.

Where the fix lives

rust/crates/er-golden/src/master.rs (merge_plans_sql, a governed generator
with plan-vector coverage in er-sql-check) and/or
rust/crates/er-reconcile/src/reconcile.rs (emit an event on the claimant when
it absorbs an entity — e.g. follow merged_into in affected, or record
member_added for members whose entity changed, not only for previously
unclustered records). Decide which layer owns the invariant before patching;
the event ledger is user-visible via write-back/webhooks.

Reproduce

DEDUPE_E2E_DUCKLAKE=1 ER_TEST_PG_DSN=... cargo test -p er-server --test main pg_merge_group
with a plan_master assertion against the merged survivor (the assertion this
ticket removed from that test, with a comment pointing here).


Product context (2026-11-26)

Why this matters for the API product: this affects results and merge-gate trust. GET …/merge-plans is in the public contract (viewer), and it is the read that tells a customer which record survives a merge. Because of this bug, the read is empty right after the customer's own merge through POST …/merges or reviews/{id}/resolve. Both of those are public, steward-level calls.

Current state: still unfixed on main.

  • er-golden/src/master.rs:206-208 still keys affected on event_type IN ('merged','member_added'). er-golden/src/master.rs has not changed since chore(docs): remove the docs/ directory, moving each record to the skill that owns it #786.
  • er-reconcile/src/reconcile.rs:362-376 still records merged only on the absorbed id, with the survivor named in details.merged_into.
  • The workaround comment is still in place at er-server/tests/pg_merge_group.rs:309.
  • The ticket's mention of write-back and webhooks needs updating. Salesforce writeback is pruned. Webhooks (/v1/orgs/{org}/webhooks) and runs/{id}/entity-events are public, so the event ledger is still customer-visible.

Definition of done: as above, plus:

  • the plan_master assertion is restored in pg_merge_group;
  • a split/recluster case is covered;
  • the er-sql-check plan vector is updated.

Dependencies / sequencing: none blocking. Fix it at the read layer by following merged_into in affected. That leaves the public event ledger unchanged, which avoids a contract change to entity-events.

Size: about 0.5 engineer-weeks.

Activity

  1. added
    followup
    on Nov 8, 2026
  2. self-assigned this
    on Nov 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

followup

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions