01 Windows focus tool

CodeLock

A Windows focus timer you earn your way out of: when time is up, solve a coding problem to unlock your screen.

The real desktop app, on a local test server. The wait is cut, typing is sped up, and the voice is synthetic.
What happens in the film

A 15-minute focus block starts from the dashboard. When the timer reaches zero, the desktop app takes over the whole screen with a programming problem, Two Sum. The first attempt is typed and submitted; it fails three of five tests, so the lock stays. The fix passes every test within the 162 ms speed budget, and the screen is released.

Music: “Envision” by Kevin MacLeod (incompetech.com), CC BY 4.0. Click: Kenney, CC0.

The problem

Every focus app I tried had a dismiss button, and the person it was meant to stop could always reach it.

What it does

When the timer ends, the desktop app takes the screen and serves a coding problem. Every test must pass, within a time budget for its language. A correct but slow answer keeps you locked.

One decision

At first the app decided its own unlock, so anything that could talk to it could fake a pass. Now only the server can unlock, with a signed note for that one session, checked where the lock screen can't reach. Against a live lock, a forged note and an empty one were both rejected.

Engineering notesMaking “fast enough” fair · The double-click bug

Making “fast enough” fair

Languages start up at different speeds, so each problem carries a budget per language rather than one number. The limit is the known good time plus 35 percent, with a fixed 40 milliseconds on top, and you get the better of two runs. The fixed margin keeps a very quick problem measuring your code rather than timing noise.

Correctness and speed are checked separately, so a wrong answer is never told it was merely slow.

The double-click bug

Ending a session used to read the state, check it, then write. Two requests arriving together both passed the check: a double-click could spend two skips, or push a paused deadline forward twice. Each ending path is now a single database write that names the state it expects, so the database decides who wins.