·StoryRoll

The Flag That Never Cleared

On September 28 I opened a session and the composer was locked. The Game Master's reply was sitting right there in the story column. The typing indicator was still on anyway, and nothing I did would turn it off.

The bug was mine. It was also boring, which is the worst kind.

One flag, one client

While a turn is in flight, session.state.dmThinking is true. It locks the composer for every player at the table, so two people can't talk over the Game Master at once. The client set it before the turn. The client cleared it in a finally block when the turn ended.

That works until the client dies. A closed tab. A phone that went to sleep for the 21 seconds the turn took. The reply still landed, because the server doesn't care whether anyone is watching. But the finally never ran, so the flag stayed on forever.

I checked production. Of the last 48 active sessions, 3 were stranded exactly like mine. Two of them had been stuck since the 27th.

Lock versus lease

A lock needs its owner to come back and let go. A lease expires on its own. We needed the second thing, and we needed the server to own the clock, since a client timer would compare a device clock against a server timestamp and every future reader of that code would have to remember why.

So every writer now stamps dmThinkingSince beside the flag and schedules a release two minutes later. The release only clears the flag if the stamp is still its own, which means a newer turn's lease is left alone. And applyTurn clears the flag in the same transaction that delivers the reply, so the two minutes only matter on the failure paths.

The review changed the design twice. The first draft expired the flag client-side, which the review rejected for the clock reason above. It also found that player A's finally could clear player B's lease, and B's live narration row with it, if B acted while A's turn was finishing. The client's release now carries its stamp, and the server ignores a stamp it no longer owns.

One more thing came out of it: the model itself could have written dmThinking through its state patch. Both keys are now server-owned and the sanitizer drops them.

The test I trust most is the applyTurn one. It clears a client-set flag with no client involved, even when the model's patch tries to pin it, and it fails against the code it replaced.

The cost

Two minutes is a guess. A turn that legitimately runs past it, say during an Anthropic slowdown, will unlock the other players early. The sender stays locked through local state, and I decided that was a fair trade against a permanent lock. I'd make the same call again.

The three stranded sessions needed a one-time sweep, because rows stuck before the deploy have no scheduled release. That was a migration with a dry run first, and it needs a human to run it against production.

A follow-up fixed a smaller version of the same mistake in the opener lock a day later, where a failed run could release someone else's lock. Same shape, same lesson: whoever lets go has to prove it is the one who took hold.

The roll flag has the same strand risk. The client reads rollResolution with no sense of age, and the only code that clears a stale one lives inside a function a locked composer can't reach.

Nothing clears the roll flag if its client dies, and I have not fixed that yet.

S

Written by StoryRoll

Founder of StoryRoll. Building AI-powered tabletop RPGs.

Share:Share on X

Related Posts