The Loot Went to the Wrong Hero
On October 5, 2026, we merged PR #506. It fixes a bug that had been reviewed three times without being closed.
Here is the bug. Two heroes sit at one table: "Unnamed hero" and "Unnamed hero 2". A player replies. The Game Master (Claude) reads the table, narrates, and says the first hero finds a sword and spends a spell slot. While that reply is being written, the first hero's player renames their hero to "Mira".
The reply comes back. Our code looks up "Unnamed hero" by name, as the table is right now. Nobody has that name anymore. So the lookup falls back to a prefix match, and "Unnamed hero 2" is the closest thing. The sword, the spell slot, the level-up and the Inspiration all land on the wrong hero. Mira gets nothing.
Why it was hard to see
Nothing crashed. The narration was fine. The log said an item was granted. It was granted, to someone else.
The order of events was the problem. applyTurn lets go of the writing lease first, then processAllDirectives runs and resolves each named hero against the table at that moment. A rename can slip into that gap three ways: a player naming a stand-in after a blocked name, a player renaming through renameMine, or a host editing a hero. All three could fire it.
The fix
The Game Master wrote its reply about the roster it was shown. So the fix reads names in that roster, not in whatever the table has become.
processAllDirectives now takes the characters array the prompt was built from. Each directive's name is resolved once, against that array, to a character id, and the handler acts on the id. Items and spell slots got an optional characterId. Level-ups and Inspiration already wrote by id, so they just take the id from the roster.
Two edge cases got explicit answers. A hero who left play during the call gets nothing, and no namesake takes it over. A name nobody in the roster answered to (an NPC, a typo, a hero who joined during the call) still falls back to a name lookup, as before.
The inventory name rules (exact, prefix, substring, then the reverse match so "Thorin Oakenshield" finds "Thorin") moved into one function, findItemHolder, so the roster path and the fallback path can't drift apart. All four callers pass their roster: a player's reply, a roll's narration, the opener, and a paid continuation.
The test
A new block in convex/dm.test.ts seats both unnamed heroes. The mocked model call renames a hero before it returns, so the prompt was built from the old roster. Each case failed before its fix: the item, the spell slot, the level and the Inspiration all go to Mira, and "Unnamed hero 2" gets none of them.
What is still open
HP and conditions never had this gap, because they land by token id inside applyTurn. The roll request and the next-spotlight pick do not. They resolve by name inside applyTurn, while the lease is held, so a player's rename can't race them. A moderation verdict or a host rename during the model call still can.
We wrote that down in a comment on renameMine and moved on.
The roll request still looks up its hero by name, and the name can still change.
Written by StoryRoll
Founder of StoryRoll. Building AI-powered tabletop RPGs.
Related Posts
The Voice Cap That Never Reset
Our voice narration had a 50,000-character limit per session that never refilled. On November 27 we deleted it. Here is what replaced it.
The Game Master Copied Our Example of Nothing
About 950 turns, zero healing potions that worked. The likely cause: three example replies in our own prompt, and all three said null.
The Game Master Kept Its Dashes
We told our AI Game Master to stop using long dashes. The next opener had two in 227 words. So we stopped asking and wrote a filter.