Skip to content

Keep ids of entities still placed elsewhere when a location is removed - #76

Merged
dmccoystephenson merged 3 commits into
masterfrom
feature/remove-location-keeps-placed-entities
Nov 6, 2026
Merged

dmccoystephenson merged 3 commits into
masterfrom
feature/remove-location-keeps-placed-entities

Conversation

@dmccoystephenson

@dmccoystephenson dmccoystephenson commented Nov 6, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Grid::removeLocation previously reset the ids of every entity in the removed location, even one also stored in another location. Such an entity stayed present with "N/S" and -1 ids, and a directional move on it threw. It now keeps its grid id, and if its location id named the removed location, that id now names a location still holding it. An entity left in no location is detached as before.
  • Grid::getLocation and Grid::getLocationByCoordinates errors now name the id or coordinates requested and the grid's id, matching Environment::getEntity. The exception type is unchanged.
  • The README "Entity Identity" and "Errors" sections are updated. The class table is unaffected.

Design choice

The new check compares addresses, unlike the library's usual id matching. With id matching, a same-id twin elsewhere in the grid would have kept a genuinely detached entity's ids alive, which would have been a regression. Test 74 pins this. When an entity remains in several locations, its location id is set to the first of them in grid order.

Test plan

  • CI "Library tests" failed on the tests-only commit a723e09, aborting on the Test 72 assertion entity.getGridId() == 5 (exit 134)
  • CI "Library tests" failed on the removeLocation commit 6ec604f, with Tests 72-75 passing and Test 76 aborting on its first assertion (exit 134)
  • CI "Library tests" passed on the final commit e14728c, with 76 of 76 registered tests reporting success, and the CMake ctest step passed
  • Test 73 was not observed red on its own, because assert aborted at Test 72 first. On the old code it would fail on the same grid id reset.
  • run_tests_asan.sh was not run: CI has no AddressSanitizer job (tracked in CI does not run run_tests_asan.sh, so AddressSanitizer failures are not caught on PRs #75), and local execution is denied. The change copies a vector of pointers and alters no allocation or entity lifetime.

Local execution of tests_executable is denied in this session, so CI is the test anchor.

Skipped

#75 was left for a later cycle. Its fix edits .github/workflows/ci.yml, which is on the do-not-auto-merge list, so it needs human review and is independent of this change.

Closes #73
Closes #74

This PR description was drafted during a Gardener session (https://github.com/Stephenson-Software/gardener).

🤖 Generated with Claude Code


drafted by Claude on behalf of Daniel Stephenson

dmccoystephenson and others added 3 commits November 6, 2026 04:08
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dmccoystephenson

Copy link
Copy Markdown
Member Author

Self-review rubric (head e14728c). This is a same-session review anchored on CI, not an independent one.

Findings folded in from the diff:

  • src/grid.cpp:66 — the pointer vector is copied before erase because the element is destroyed by it. updateIdsOfDetachedEntity then runs against the remaining locations, so another location sharing the id is seen on the first pass and handled on its own later pass (Test 75).
  • src/grid.cpp:81 — this is an address comparison, unlike the id matching used elsewhere. It was chosen deliberately so that a twin does not keep a detached entity's ids alive (Test 74). Flagged as a judgment call, not as blocking.
  • Judgment call: when an entity remains in several locations, the first in grid order is named. The README describes this only as "a location that still holds it", so the order is not promised.

Gaps: run_tests_asan.sh was not run, since CI has no AddressSanitizer job (tracked in #75) and local execution is denied. The change adds a local copy of a pointer vector and alters no allocation or entity lifetime, but the sanitizer result remains unverified.

Merge-gate check: no changed path matches the do-not-auto-merge list. No workflow file or Makefile was changed, and no single file lost more than 50 lines.

This comment was drafted during a Gardener session (https://github.com/Stephenson-Software/gardener).


drafted by Claude on behalf of Daniel Stephenson

@dmccoystephenson
dmccoystephenson merged commit b5fde18 into master Nov 6, 2026
3 checks passed
@dmccoystephenson
dmccoystephenson deleted the feature/remove-location-keeps-placed-entities branch November 6, 2026 11:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant