fix(dsl): reject duplicate entity ids instead of splitting the scene - #104
Merged
bamdadd merged 1 commit intoAug 11, 2026
Merged
Conversation
build() merges _entities and _distractors into one spec list and keys frames_by_id by id, so the two share a namespace whether or not the API says so. A duplicate passed silently and left the scene inconsistent with itself: both entries reached scene.entities and the manifest, while frames_by_id kept only the last one written. Every id-keyed consumer downstream -- attachments, annotations, groups -- then read the survivor, so they saw one entity where a consumer parsing the manifest saw two. Guard in entity() and distractor() rather than in build(), as the issue suggests: at the call site the error can name the id and say what already holds it, which is the thing the caller can act on. At build() the origin is gone. The check spans both lists, so an entity() and a distractor() sharing an id are caught too -- the confusing case, since they land in different lists. randomize() is unaffected: its generated ids come from a per-builder counter, so its own calls cannot collide. A caller who hand-adds rand_distractor_0 and then calls randomize() now gets an error, which seems right -- that collision previously produced exactly the split described above. This changes existing public behaviour, from silent acceptance to ValueError. Nothing in the suite depended on it: 360 tests pass unchanged with the guard in place, and the 7 new ones cover both orders, both same-kind cases, the message naming the prior holder, and that a rejected call leaves no half-added spec behind. 6 of the 7 fail without the guard. Verified with `pytest`, `ruff check`, `ruff format --check` and `mypy src` all clean. tests/test_dsl_breadth.py, test_dsl_scene.py, test_mtmc.py, test_rig_heights.py and test_smoke.py could not be collected here -- they import multicam_occlusion, which is not part of this repo -- so those five are excluded from the 360/367 counts above and are on CI to check. Closes bamdadd#96 Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #96
Taking you up on the "happy to send it as its own PR" offer — and thanks for keeping it out of the #41 branch, that was the right call.
The fix
build()merges_entitiesand_distractorsinto one spec list and keysframes_by_idby id, so the two share a namespace whether or not the API says so. A duplicate left the scene inconsistent with itself: both entries reachedscene.entitiesand the manifest, whileframes_by_idkept only the last one written.Guarded in
entity()anddistractor()rather than inbuild(), as you suggested — at the call site the error can name the id and say what already holds it, which is the thing the caller can act on:The check spans both lists, so the
entity("obj2")/distractor("obj2")collision you noted is caught too.randomize()is unaffectedIts generated ids come from the per-builder counter, so its own calls can't collide. A caller who hand-adds
rand_distractor_0and then callsrandomize()now gets an error — which seems like the right outcome, since that collision previously produced exactly the split described above. Flagging it in case you'd ratherrandomize()skipped ids already taken.This is a public behaviour change
Silent acceptance →
ValueError, which is your call to make. Nothing in the suite depended on the old behaviour: 360 tests pass unchanged with the guard in place.7 new tests in
tests/test_entity_ids.py:build()after a caught error6 of the 7 fail without the guard. The 7th is the invariant test, which passes on
mainby construction.Verification
pytest,ruff check,ruff format --checkandmypy srcall clean.One caveat:
test_dsl_breadth.py,test_dsl_scene.py,test_mtmc.py,test_rig_heights.pyandtest_smoke.pycould not be collected in my environment — theyimport multicam_occlusion, which isn't part of this repo — so they're excluded from the counts above and CI is what checks them. If any of those builds a scene with a deliberately duplicated id, this will surface there and I'll fix it.🤖 Generated with Claude Code