Skip to content

Pick an offspring's square first and reuse the attack's square on death - #163

Merged
dmccoystephenson merged 1 commit into
mainfrom
feature/reproduce-death-edge-cases
Nov 8, 2026
Merged

dmccoystephenson merged 1 commit into
mainfrom
feature/reproduce-death-edge-cases

Conversation

@dmccoystephenson

Copy link
Copy Markdown
Member

Summary

  • Actor#reproduce now picks the offspring's square before the offspring is created. When the world has no grid, an error is logged and nothing is created, so no unplaced actor, entity record, child UUID or parent relation is left behind. Placement goes through a new PersistentData#placeIntoEnvironment(World, Square, Actor) overload, which the existing two-argument version now delegates to.
  • Actor#checkForDeath now receives the square attack already resolved, instead of looking up victim.getSquare() again, which is null if the victim is unplaced during the attack and would have thrown out of LocalTimeService#run.

Test plan

  • mvn -B test: 202 tests run, 0 failures
  • ActorTest.testReproduceLeavesNoOffspringWhenItsWorldHasNoGrid fails with the fix stashed (expected:<2> but was:<101>) and passes with it restored
  • ActorTest.testDeathLeavesFoodOnTheSquareOfTheAttackWhenTheVictimWasUnplacedMeanwhile fails with the fix stashed (NullPointerException in createFoodItemAt) and passes with it restored

Deferred issues

Closes #162

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

reproduce created the offspring before placing it, so a world without a
grid left an unplaced actor in persistent data, with an entity record
and an entry in both parents' children and relations, on every attempt.
The square is now picked first, and no offspring is created when there
is none.

checkForDeath looked the victim's square up again, which is null if a
console delete or wipe unplaces the victim during the attack, and the
resulting NullPointerException would end the time thread. It now uses
the square attack already resolved.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@dmccoystephenson

Copy link
Copy Markdown
Member Author

Self-review rubric (an inline self-review, not an independent review):

  • Scope: PASS. Only Actor.java, PersistentData.java and ActorTest.java are modified, and each change maps to one of the two bullets in Actor#reproduce keeps a failed offspring, and checkForDeath does not handle a null square #162.
  • Tests-new: PASS. The new placeIntoEnvironment(World, Square, Actor) overload is run by both new tests through reproduce and placeOnSameSquare, and by every existing caller of the two-argument version that now delegates to it.
  • Tests-fix: PASS. Confirmed by stash-and-run. With the fix stashed, the gridless-reproduce test failed (expected:<2> but was:<101>) and the unplaced-victim test threw NullPointerException in createFoodItemAt. With the fix restored, both pass.
  • Sibling structure / sibling renames: PASS. No new files and no renames.
  • Docs: PASS. README, HelpCommand and the build files describe none of the changed behavior.
  • Issue resolution: PASS. Both surfaces named in Actor#reproduce keeps a failed offspring, and checkForDeath does not handle a null square #162 (reproduce and checkForDeath) are changed.
  • Build+test anchor: PASS. Locally, mvn -B test ran 202 tests with 0 failures, and the Browser build CI check passed on the PR head.
  • No singleton reintroduction / help-commands parity / license header: PASS / not applicable / not applicable.

Observations:

  • src/main/java/dansapps/interakt/objects/Actor.java:365: the return value of placeIntoEnvironment is ignored. It can only be false for a null square, which was already ruled out, or for an actor that is already in a world, which a newly created offspring never is. So it cannot fail here, but nothing checks that.
  • src/main/java/dansapps/interakt/objects/Actor.java:359: a narrow race is still possible. A console delete of the world could land between picking the birthplace and placing the offspring, and the offspring would then be placed in a deleted world. This window already existed before the change, the change does not widen it, and it is the same class of thread race as the checkForDeath one. It is left as is.

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 32fea59 into main Nov 8, 2026
1 check passed
@dmccoystephenson
dmccoystephenson deleted the feature/reproduce-death-edge-cases branch November 8, 2026 04:29
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.

Actor#reproduce keeps a failed offspring, and checkForDeath does not handle a null square

1 participant