Skip to main content
← All Posts

A bug in my render code was logging people out

Thin month on ForgeSheets — 33 commits — and more than a third of them were one bug cluster. Features first, since they’re the part you can see.

Parent rows roll up now. Put a date, number or percent column on a tree and the parent works out its own value from its children: earliest start, latest finish, sum, weighted average, with no formula to write. That’s what people expect from a hierarchical grid, and until now you had to spell it out per cell.

Gantt bars drag. Move them, resize them, draw a new one, snapped to days, escape to cancel. The maths behind it is a pure module — work out the result, then commit the writes — which meant I could test every drag case without touching a mouse.

Multi-cell edits became one operation instead of a storm, too. Paste into forty cells and you used to get forty undo steps and forty messages to every collaborator. Now it’s one of each.

Three bugs, one sign-out

Users were getting signed out of brand-new sessions. Sign in, work, come back, signed out. Three separate causes stacked on top of each other and they had to be peeled apart in order.

First: our identity provider only issues a refresh token during a consent interaction. Without explicitly asking for consent, a fresh sign-in got no refresh token at all, so the very first attempt to refresh had nothing to refresh with. Every new session was built to expire and never renew.

Second: once that was fixed and tokens started being issued, the refresh request was listing a resource URL among the scopes it asked for, which the grant didn’t hold. So refreshes came back as a 400. One fixed bug exposing the next is a good sign you’re going in the right direction, and it doesn’t feel like one at the time.

Third is the one worth the post. My sign-in routine wrapped its work in a try/catch, and the catch cleared the stored refresh token — sensible, if a refresh has genuinely failed. But the try block extended past the refresh, over the callback that renders the app.

So any exception thrown while drawing the interface — a display bug, a missing field, a typo in a formatter — got caught by a handler that interprets everything as “authentication failed” and threw away a perfectly valid session.

The fix is moving the render call outside the try. Two lines, and the whole bug is about scope: the catch was correct for the thing it was written for, and the try block had grown past it since. That drift is invisible in a diff, because nobody edits the catch. They just add a line before the closing brace.

Four changes that never left the room

The other cluster. Collapsing a row group, renaming a column, resizing a column, renaming a sheet — all four changed the local document directly without going through the operations pipeline, so collaborators didn’t hear about them until somebody reconnected.

All four come from the same thing: the code to change local state is right there and easy to call, and routing it through the pipeline is one extra step you have to remember. Making that structurally impossible beats remembering it, which is roughly what the autumn turned into.

The deploy stamp that didn’t change

One more. Cached assets get busted with a version stamp, and that stamp was computed from the modification time of one file — app.js.

Deploy a change to any other script or stylesheet and the stamp came out identical, so returning browsers kept serving the old files for up to four hours. The cache busting worked perfectly for one file and not at all for the rest, which is worse than having none, because I believed it was working.

It hashes the contents of every script and stylesheet now.

Also this month: per-subject rate limiting on creates, invites and redemptions, and refresh-token rotation that survives several tabs doing it at once. The limiter has a mutation score of 98.61%, which for a security control is the number I want to see. Rollups went from 77.55% to 87.24%.

Tests ended the month at 1,725. Half of August was fixing things July’s sprint broke, which is a fair description of what happens when you ship real-time collaboration in a day.

— Bruno