Build log · week ending 30 November 2026
A clock read twice, and a button pressed twice
By Tim
Each week I write up what we built on Noisy Brood: what broke, how we fixed it, and what I learned along the way.
A push that looked older than the step
A sync step in Brood has to know whether a push notification arrived while it was working. If one did, it should read the mailbox again straight away. One test for this failed once in a full run. It passed in 40 runs alone and 40 runs of its whole file.
The old code read the database’s clock when the step began. Afterwards it asked whether the stored time of the last push was at or after that reading. That is two clock readings on two connections. If the clock steps back between them, a push that did land reads as earlier than the step, and its follow-up read waits for the next scheduled pass. A virtual machine under load can have its clock stepped, and the test database runs in one.
I could not prove that was the cause. I did rule out rounding, over 2,000 reads. So I changed the check to need no clock at all. It reads the last push time as text before the step, then asks the database afterwards whether the value is distinct from what it saw. Text keeps the microseconds that a JavaScript Date would round away.
const before = await lastNotice(sql, ref);
// ... the step runs ...
if (await noticeChanged(sql, ref, before)) {
await advanceAccount(sql, ref, (on) => deps.open(on, ref));
}
// in noticeChanged:
SELECT last_notification_at IS DISTINCT FROM ${before}::text::timestamptz
AS changed
A null that stays null counts as unchanged, and a null that becomes a time counts as a push. The new tests write a push timed an hour before the step began. They fail on the old code and pass on the new.
A button only the page hid
“Ask it to stop” sends a sender an unsubscribe request. Pressing it a second time from a stale tab, or after going Back, sent a second request, because only the page hid the button. The server never checked. A page that hides a control is not a check: a stale form or a direct request goes around it. A Server Action has to hold the rule itself.
The rule now lives in one function, and the action calls it before anything is read or sent:
export const SETTLED_ANSWERS = ["accepted", "redirected", "refused"] as const;
// in askToStop:
if (await askedRecently(sql, userId, senderId, new Date()))
return none("already_asked");
A 503 from the sender is not in that list, since a failed request is no answer and may be asked again. Before, it read as “too soon to tell” and held the sender back until the deadline passed.
Two presses at the same instant can still both send. The window is one request and the cost is one extra unsubscribe, so I accepted it in the pull request rather than hold a lock across the sender’s reply.
Why it matters
When you use Brood, a sender is asked to stop once, and a push during a sync is read promptly instead of at the next pass.
Noisy Brood files away the mail that doesn’t need you, so the mail that does can find you. We write up what we build each week because every fix like this one is meant to make that a little more reliable. It isn’t open to everyone yet. If you’d like to hear when it can take you, join the list.