Skip to content

fix: avoid KeyError in DSTrace.get_sibling_exps for a node with several children - #1514

Open
Muhammad Usman Mateen (usmanmateen) wants to merge 1 commit into
microsoft:mainfrom
usmanmateen:fix/sibling-exps-shared-parent
Open

Muhammad Usman Mateen (usmanmateen) wants to merge 1 commit into
microsoft:mainfrom
usmanmateen:fix/sibling-exps-shared-parent

Conversation

@usmanmateen

@usmanmateen Muhammad Usman Mateen (usmanmateen) commented Oct 10, 2026 •

Copy link
Copy Markdown

Description

DSTrace.get_sibling_exps() collects the leaves of the trace DAG by adding every node to a set and removing each node's parents. It used set.remove(), so a node that is the parent of more than one child was removed twice and raised KeyError:

  • a committed node with two children (dag_parent = [(), (0,), (0,)]);
  • two uncommitted experiments expanding the same node, or a node with one committed and one uncommitted child.

Both removals now use set.discard(), so the result is the set of leaves in all of these cases. Nothing else changes.

Motivation and Context

Fixes #1430. DSProposalV2ExpGen calls trace.get_sibling_exps() when diversity injection is enabled, and parallel expansion of one node is a normal case there.

Gourav Singal (@GouravSingal-code) offered a fix in August, but no PR followed, so I'm sending this one. Happy to close it if theirs is ready.

How Has This Been Tested?

  • test/scenarios/data_science/test_trace_sibling_exps.py covers a node with two committed children, two uncommitted experiments with the same parent, and current_selection being left out. All three fail on main with KeyError and pass with this change.

Screenshots of Test Results (if appropriate):

  1. Your own tests:
$ pytest test/scenarios/data_science/test_trace_sibling_exps.py
main:      3 failed (KeyError: 0, KeyError: 1, KeyError: 0)
this PR:   3 passed

$ pytest test/scenarios/data_science
this PR:   15 passed

black -l 120 and isort pass on the changed files.

Types of changes

  • Fix bugs
  • Add new feature
  • Update documentation

📚 Documentation preview 📚: https://RDAgent--1514.org.readthedocs.build/en/1514/

…al children

get_sibling_exps() removed each node's parents from the set of leaves
with set.remove(), so a parent shared by two committed children, by two
uncommitted experiments, or by one of each raised KeyError. Use
set.discard() for both removals.

Fixes microsoft#1430
@usmanmateen

Copy link
Copy Markdown
Author

Hi XianBW (@XianBW), gentle ping on this small fix when you have a moment. Happy to adjust anything.

@usmanmateen

Copy link
Copy Markdown
Author

XianBW (@XianBW) Wanyi Chen (@wanyichen06) could one of you take a look at this small fix when you have time?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐛 Bug: DSTrace.get_sibling_exps crashes with KeyError when the trace DAG has any node with more than one child

1 participant