Kinopy
devlog
Play today's puzzle

Local storage is king

Tile moves on a phone kept undoing themselves. The fix was a rule about which copy of a board wins.

In the two days after the accounts epic merged, the sync showed me two bugs, and both of them were mine. This post is about what they looked like, what they had in common, and the one rule that fixed the first and shaped the fix for the second. It builds on the outbox from the last sync post, so skim that first if the word is new to you.

The symptom

On 20 October 2026 I filed issue #87 at 17:12. A signed-in player lost each tile move a few seconds after making it, and the board rebuilt itself behind the “Growing a puzzle” line that the game shows while it loads. Signed out, the move stayed where you put it. The bug showed on a phone while the same account was open on a second device.

The cause

Two rules met in the wrong way, and I wrote both of them.

The first rule was about pushing. Every tile move queued the day for the account, and the runner pushed the board 3 seconds later. The second rule was about pulling. A pull replaced any local day that had no pending change with the server copy, because the server copy was assumed to be the newer one. That assumption held when the two copies disagreed about guesses. It did not hold when both copies had the same submitted guesses and differed only in where the tiles sat. In that case the pull swapped in the other device’s tile positions, and the second device on the account overwrote the board in play.

Before #88After #88
A tile move or a linkQueues the day, pushes 3 s laterSaves on the device and nothing else
A submitted guessQueues the dayQueues the day
A pull, same guesses on both sidesThe server copy winsThe local board stays
A pull, more guesses on the accountThe server copy winsThe server copy wins
A pull, a finished board on the accountThe server copy winsThe server copy wins

The rule

The issue already held the fix in one line: local storage becomes the authority. The tile moves and the links stay on the device, and the account hears about a daily only when you submit a guess or the board ends. A pull may replace a local board only when the account holds more submitted guesses or a finished board.

Before the fix, a tile move pushed to the account three seconds later and a pull could swap the board. After the fix, a tile move stays on the device and only a guess reaches the account.BEFOREMovePushPullany move3 s laterswaps the boardAFTERMoveDeviceGuessAccount
The path of a move before the fix and after it. Only a guess travels to the account now.

In code the change is two small pieces. The session now queues a daily only when a submission adds a row or the board ends, where a row is one submitted guess:

const submitted = game.status !== 'playing'
  || game.rows.length > (prev?.puzzle.id === game.puzzle.id ? prev.rows.length : 0)

And the pull gets a name for the case it used to get wrong:

function sameProgress(local: DayState, r: RemoteDay): boolean {
  return local.status === 'playing' && r.status === 'playing'
    && local.guesses === r.guesses && local.game !== null
}

When that is true, the two boards differ only in tile moves and links, and local storage keeps those.

The fix has a cost, and the PR said so in its notes for reviewers. Moves that no guess has used yet no longer follow you to another device. The next submission carries them.

The fix merged on 20 October at 17:27, fifteen minutes after the issue went up. At that PR (#88) 724 tests passed, and 30 emulator tests ran against the real security rules.

The second bug

The next day, 21 October, the same idea turned up from a different side. Two tabs on one account share one local store, but each tab keeps its own copy of the progress in memory and re-reads the store only when the storage event of the other tab arrives. An older tab could push or pull before that event reached it. It then settled a day using its own stale copy and took the day out of the outbox, so the change that the newer tab had queued never reached the account.

That was my bug too, and it was the same mistake as the first one in a different place: two copies, and the wrong one treated as the truth.

The fix, in the commit 683b37530, reads the stored progress before the sync saves the outbox. A day whose stored copy differs from the copy in the tab stays queued, for the tab that holds the change:

const newer = settled.filter(key => {
  const theirs = localDay(stored, key)
  const mine = localDay(before, key)
  return theirs !== null && (mine === null || !sameDay(theirs, mine))
})
return newer.reduce(withOutbox, next)

The tests open two tabs over one store, run the older tab’s push and pull before the storage event arrives, and check that the newer tab’s day is still in the outbox and later reaches the account with its two guesses. The PR says the tab tests failed before the fix.

That commit landed on main inside a tidy-up PR (#140) that fixed six loose ends and renamed the first board to the Rootlet. It merged on 21 October, and the suite held 1,385 passing tests.

Looking back

Both bugs came from the same place, a second copy of a board that was allowed to overwrite the first. The fix for the first named the copy that wins, which is the one on your device, and the fix for the second applied that rule between two tabs of the same browser.

The next post is about words that look like two words glued together, and a game that did not know the difference.

Play today’s daily at kinopy.day and rearrange as many tiles as you like. They will stay where you put them!