Implicit state machines hide bugs that line-by-line review approves QuickReview, an open-source AI code reviewer built by its developer, added a state-machine review mode after Steve Ruiz, founder of tldraw, posted a one-line prompt on 31 October telling coding agents to "find all of the implicit state machines in my app." On 34 pull requests the new mode found 85% of known state bugs versus 71% for the default review at the same cost, after the default QuickReview build on GPT-6.1 Sol caught only 12 of the 29 state defects in Qodo's public review benchmark. The developer published every review comment and label behind the numbers along with a script that recomputes them. TL;DR At the end of October a one-line prompt for finding implicit state machines spread through developer feeds. I liked the idea, and these were bugs my AI code reviewer often missed, so I built it into QuickReview as a state-machine review and measured it. On 34 pull requests it found 85% of the known state bugs, against 71% for my default review, at the same cost. It is part of QuickReview now, and you can run it on your own pull requests. Every review comment and label behind these numbers is public, with a script that recomputes them. On 31 October Steve Ruiz, the founder of tldraw, posted a one-line prompt https://x.com/steveruizok/status/2116552016218710389 for coding agents, “find all of the implicit state machines in my app”. Within a week developers were pasting it into their agents and posting what came back, and surveys for implicit state machines began to appear in public issue trackers. One project’s survey listed about 100 implicit state machines https://github.com/Irys-xyz/irys/issues/1790 in its production code. Another, the week after, found four bugs https://github.com/TagCopperLight/gripsou/issues/91 , one of them a bank connection that a sync could claim while the user was still setting it up, which left the connection broken. I recognised the bugs in those threads from my own reviewer’s misses. What an implicit state machine is Take an upload button. The handler sets uploading to true, asks the server for an upload URL, sends the file, and sets uploading back to false. The button is disabled while uploading is true. A pull request adds one sensible line, an early return for when the server gives back no URL. js async function upload file: File { setUploading true ; const url = await getUploadUrl file.name ; if url return; await putFile url, file ; setUploading false ; } Every line is fine, and the new check is good defensive code. The first time the server hands back nothing, the button stays disabled until the user reloads the page. The upload button has a state machine. It is idle, then uploading, then done or failed. Nobody wrote that down. It lives in one boolean and in the order of four calls, and the early return added a way out of “uploading” that never goes back to idle. That is an implicit state machine. It is behaviour that depends on which state a thing is in, where the states and the moves between them are never written in one place. The state hides in flags like isLoading and isSaving , in nullable fields, in a status string or a database column, in a lifecycle phase, in the order calls must come in. As statecharts.dev puts it, “The code you’re writing today is already saturated with state machines and/or statecharts.” Most of the time they work. When one breaks, you get a spinner that stays on after an error, an order marked paid twice because the payment webhook arrived twice, or a job that a cancel leaves in “processing” forever. None of these shows up on the changed line, because each needs several events in a particular order. Stripe’s webhook documentation says why the second one happens. “Webhook endpoints might occasionally receive the same event more than once,” and Stripe “doesn’t guarantee the delivery of events in the order that they’re generated.” A handler that marks an order paid and sends a receipt is correct for the first delivery and wrong for the second. These were the bugs my reviewer missed I build QuickReview, an open-source AI reviewer for code changes and pull requests. A reviewer that reads a diff line by line approves this kind of bug, so I checked how mine did on them. On Qodo’s public review benchmark, the QuickReview build behind my published benchmark scores, on GPT-6.1 Sol, found 12 of the 29 state defects in it, fewer than half. Over all the benchmark’s functional bugs it found more than half. Twenty-nine is a small sample, and the state labels came from AI agents that no person has checked. I think the reason is how a review reads. A reviewer, human or AI, looks at each changed line and asks whether it is right. A state bug needs a different question, about what happens to this state on every path through the code, including the paths the change did not touch. When my reviewer did find a state bug, a reviewer looking for something else found it. None of them was pointed at state. I also wanted to know how much these bugs matter. I have found no measurement behind the claim that most bugs are state bugs, and in the benchmarks I run, state defects are about one real defect in eleven. They are a minority. The shape they share, a sequence of events the code did not plan for, is behind many of the worst failures that field studies record. Ding Yuan and colleagues studied 198 user-reported failures in Cassandra, HBase, HDFS, MapReduce and Redis OSDI 2014 . The study has no state-machine category, but 77% of the failures needed more than one input event to happen, and 92% of the catastrophic ones came from mishandling a non-fatal error the software had already signalled. One case they quote has the same shape as the upload button. MapReduce jobs hang after a rare restart, because the error handler held a TODO and the fix was to clean up. The October 2025 DynamoDB outage in AWS’s us-east-1 region had the same shape. A delayed process checked once that its DNS plan was newer than the one live, then applied it. AWS writes that the check “was stale by this time due to the unusually high delays in Enactor processing.” A clean-up then deleted that older plan, leaving “an incorrect empty DNS record for the service’s regional endpoint.” The check was made in one state and the action was taken in another. Why I did not stop at the prompt The quick way to act on this was to paste the prompt into a coding agent and read the answer. The prompt works well as a survey. It reads a whole codebase once and returns an inventory of state machines. An inventory is hard to act on. The issue that lists about 100 machines now carries the labels “not-important” and “not-urgent”. One write-up https://agenticfeed.io/one-line-prompt-finds-implicit-state-machines/ that covered the prompt says no peer-reviewed study backs the claim that it reduces production bugs, and another https://eraofminds.com/blog/implicit-state-machines-prompt/ notes that a model asked to find all of something will also list booleans that were always meant to be independent. Nothing checks what the agent claims. A reviewer that comments on every pull request needs something narrower. I could have narrowed the prompt myself and pasted “review this diff for implicit state machine bugs” into the agent. That would fix the scope, but nothing would check the claims, and I would have no way to tell whether a rewording found more bugs or fewer. So I set three requirements. The review should report only what this change made worse. Each claim should be checked before a person reads it. And I had to be able to measure how many real state bugs it finds, so that I could tell whether a change to it helped. Eight reviewers, each hunting one kind of state bug QuickReview already reads a change through narrow reviewers it calls lenses, each looking for one kind of problem. I added eight, one per kind of state bug. - Impossible states. Flags and fields that can combine into a state that must never exist, with code that writes it and code that mishandles it. - Unchecked transitions. A status changed without checking which status it is leaving, or a guard removed. - Unhandled states. A new state added, and a switch , list, map or filter that was never updated. - Stuck states. Loading, processing or locked, left set by an error, an early return, a timeout or a cancel. - Event order. An event that arrives twice, late, out of order, or while the last one is still in flight. - Stale copies. A cached or derived value that one writer of the source forgets to update. - Lifecycle order. Use before init, use after close, a teardown that never runs. - Stored state. A persisted shape changed with no migration, a state write and its side effect that can come apart, a crash halfway through, old data meeting new code. Then a validator takes every claimed bug and replays its sequence step by step against the code, looking for the guard the lens may have missed. A sequence that falls apart on replay is dropped before you see it. A lens’s finding has to name the state, the event that arrives, the sequence from an entry point with a file and line for each step, and the line that acts without a check. The validator replays that sequence. The comment that reaches the pull request tells the same sequence in a few sentences and cites the lines it rests on. For the upload button it would read roughly like this the wording is mine . Reset uploading when the upload URL is missing. After a click on Upload UploadButton.tsx:18 , setUploading true runs upload.ts:2 . If getUploadUrl returns null upload.ts:3 , the new early return at upload.ts:4 exits before setUploading false , so the button, which is disabled while uploading is true UploadButton.tsx:21 , stays disabled until the page is reloaded. QuickReview reads your code and runs none of it. It comments only on what the change made worse, so it neither lists your state machines nor suggests rewriting working code as one. The first version lost to the review I already had To test it I took 34 AACR-Bench pull requests from the benchmark data I publish, which hold 45 state defects. AI agents made the state labels, and no person has checked them. GPT-6.1 Sol was both the reviewer and the judge, the model that decides whether a posted comment matches a labelled defect. The costs are at list prices, and each configuration ran once. The first version ran four of the eight lenses on every change and added the others when the diff showed a signal. Alone, it found 26 of the 45 for $0.79 a pull request. The default review, with no state lens in it, found 36 for $2.77. Running all eight lenses on every change raised that to 31. Giving them more reasoning effort raised it to 33 for $2.36. The review I already had was still ahead. The default review had an edge in this test. The answer key is the list of labelled defects a review is scored against, and 32 of the 45 got onto it because an earlier run of the default review had reported them. On the 13 that came from other sources, the default review and the eight lenses at the higher effort each found 7. The lenses opened the right code and reported nothing I traced every miss of the first version through the review’s plan, the lens transcripts and the record of candidate findings. Of its 19 misses, 5 belonged to a lens that was never started, which was the cost of running only four. In 11 a lens opened the right place in the code and reported nothing. In 2 it reported a different problem at the same place. One labelled defect turned out not to be real. In this test, no miss was a finding that the validator dropped or that the judge failed to credit. A later audit of about 1,400 candidate findings from the state lenses across four runs found that the validator removed four of them, and none because it had disproved the sequence. One of the four was a labelled defect, cut by the rule that keeps a state-only review to state findings. So the validator cost almost no bugs in these runs, and it filtered almost nothing either. Nearly every missed bug was lost inside the lens. The defects that every configuration missed were absences. A field was added to a stored shape with no migration. A write sat outside its transaction. A clean-up call was moved into one branch of a loop and was missing from the other exits. A diff shows the lines that were added, and it has no line for the thing that should have been added and was not. What I changed, and the second test I made three changes. - All eight lenses run on every code change, at the higher effort. The four-lens version was cheap and missed whole kinds of bug. - The lenses got a read-only lookup tool. It lists where a state is written and read across the repository, and it points at places where something may be missing, such as a clean-up present at one exit of a function and absent at another, a stored shape changed with no migration, or a group of writes with no transaction around them. - The instructions no longer accept a bare “nothing found”. A lens that reports nothing has to list what it checked. After it reports one problem at a place, it reads the place again for a second, independent one. A new stored field with no migration counts as a finding by itself. I then ran the new build alone on the 13 pull requests that held the defects the eight lenses had missed. Those hold 18 labelled state defects. The earlier build found 4 of them at normal effort and 7 at the higher effort. The new build found 10, the same number as the default review, for $2.75 a pull request. The lenses called the lookup tool in 104 of their 117 runs on those pull requests. Those pull requests were picked for the misses, so part of that gain is luck, and it is one run. A second round of fixes followed from the validator audit and from tracing seven state defects that both the new build and the default review had missed. It teaches the lookup tool to flag a write that skips the save call its sibling functions make, and a per-item write in a loop with no transaction, and it makes a lens decide every lead, as a finding or as cleared, citing the line that settles it. The merged build, on all 34 pull requests After the changes were merged I ran the merged build, the code the release ships, alone on all 34 pull requests, with GPT-6.1 Sol as reviewer and judge. It cost $2.78 a pull request at list prices. First I checked the answer key itself. The 45 state labels came from AI agents, and a second labeller had already disagreed on some of them. So two AI readers went through all 186 defects in the answer key for these 34 pull requests, without seeing any earlier label, and a third settled their disagreements. A defect counted as a state bug only if it needs a named state and an event or sequence, so that a single call with fresh state would behave correctly. That gave 56 state bugs. Thirty-five of the original 45 met that rule, two were borderline and eight did not, and 21 defects that were not on the list did. One of the 56 cannot happen in the code as merged, which leaves 55. On those 55, the merged build found 44 and the default review 45. Every one the state review found, the default review found too. The one it missed and the default review caught is in immich. Removing a queued job can now throw an error, and the code that adds assets to an album does not catch it, so the remaining recipients get no notification. The state lenses commented on the same lines, about a crash rather than about that error. I traced the 11 real misses through the lens transcripts again. All eight lenses ran on every pull request, and no finding was lost to the validator or the posting step. In 5 a lens read the right code and reported nothing, and in 6 it reported a different problem at the same place. In most of them the lookup tool had pointed the lens at the spot. The remaining gap is in how a lens reasons about a lead, for example clearing it because one path re-derives the value, or reading a local copy as a write to shared state. The answer key lists half of the state bugs An answer key holds the defects its authors wrote down. Both reviews also posted comments about real state bugs that it does not list, so I counted those too. For every comment from either review that matched nothing in the key, AI agents decided whether it describes a state bug and read the code to check that the bug is real. They merged comments that describe the same bug, then went through every comment of both reviews to see which review found each one. A sceptical reader then checked every bug again, and the 25 bugs that only one review found were checked once more, blind to which review had posted what. All 25 held. That added 50 real state bugs, for 105 in all. Of the 105, the state-machine review found 89 and the default review 75. The two cost the same per pull request, and the state review posted 4.7 comments a pull request against 11.7. The two runs together found 95. The difference sits outside the answer key. Of the 50 bugs found there, 20 were found only by the state review and 5 only by the default review. Some of the 20 are these. - gemini-cli. While a slash command waits for an MCP server to return its prompt, the client has not yet marked itself busy, so a second message can start its own response stream, and Escape then cancels only the newer one. - mpv. The pull request defers option callbacks until after the current batch of commands. Three of the 20 come from it. A seek sent right after set hwdec or set play-direction is now replaced by the refresh seek those options queue, and a filter command sent right after set af fails, because the new filter is not installed yet. - n8n. Archiving a folder works from a list of workflow ids taken once at the start. A workflow that another request moves out of the folder while the archive runs is still archived, and it is moved out of its new folder to the project root. - ClickHouse. A disk checker adds to the readonly and broken disk gauges, and nothing takes its share back when the checker stops. A config reload that fails partway can leave a count for a disk that no longer exists. By kind, the state review’s lead comes mostly from event order 7 more and lifecycle order 4 more , with smaller leads on stale copies, unhandled states and impossible states. The default review found more of the stored-state bugs, such as a persisted shape changed with no migration, and the two tie on stuck states and unchecked transitions. It is not yet a state-only review. The state-machine review is meant to post state findings and nothing else. Of its 159 comments, 96 are clearly state bugs, 31 are borderline, and 32 are about other things, such as a missing null check after an allocation or a hardcoded transport argument. The judge rated 28 of those 32 correct, but a reader who asked for a state review should not have to sort them out. Tightening that filter is the next fix. Before the merge, I also ran the state-machine review on its own pull request. I ran the state-machine review on the change that adds it, on GPT-6.1 Sol. It cost $4.89 and reported five state bugs in its own code. Four were real, and I fixed them. A second run after the fixes cost $4.36 and found one more. A state-only review saved its checkpoint over the full review’s, so a later full review of the same commit answered that there was nothing new to review. Every comment and label is public Every comment both reviews posted on the 34 pull requests, every judge verdict with the judge’s reasoning, and each review’s cost and time are in the state machines folder of QuickReview’s benchmark dataset on Hugging Face https://huggingface.co/datasets/quickchatai/quickreview-bench/tree/main/state machines DOI 10.57967/hf/11598 https://doi.org/10.57967/hf/11598 , under the Apache-2.0 licence and with no login. The folder also holds the state label of each of the 186 answer-key defects with both readers’ votes, the 105 known state bugs with the comments of each review that found them, the state or not-state label of each comment, and the cause of each miss. A script in the QuickReview repository https://github.com/quickchatai/quickreview/blob/main/bench/aacr/recompute/state machines.py recomputes every number in this post from those tables, without a model call, so you can check them or count them your own way. What the review has that a pasted prompt does not I have not run the bare one-line prompt against the same bugs, so I cannot say the review finds more of them. The review differs from a pasted prompt in three ways. It looks at one change and reports only what that change made worse. Each lens has to support a finding with a sequence that has a file and line for each step, and a validator replays it before it is posted. It has also been scored, at 89 of the 105 known state bugs on these pull requests, and I used the earlier scores to find what it missed and to fix it. The lenses and their instructions are in the QuickReview repository to read and change. Which review to run The numbers above give three choices, all on GPT-6.1 Sol and one run each. | Review | Known state bugs found of 105 | Cost per pull request | Comments per pull request | |---|---|---|---| | State-machine review alone | 89 85% | $2.78 | 4.7 | | Default review | 75 71% | $2.77 | 11.7 | | Both runs together | 95 90% | $5.56 | 16.4 | The state-machine review alone finds the most state bugs for the money, and it is the short review. Use it on changes where state is the risk, such as event handlers, retries and webhooks, async UI flows, caches, background jobs and lifecycle code. It is meant to look only at state, though today about one comment in five is still about another kind of bug, and it misses bugs that are not about state. Make it a repository’s whole review by setting review profile = "state-machines" in QuickReview’s config.toml , or, in the pi coding agent, run it on one change with /qcr-review state-machines . The default review is the everyday review. In this test it ran with its automatic state lens switched off, and it found 71% of the known state bugs and 161 of the 186 answer-key defects of every kind on the same pull requests. As shipped it adds a state lens on its own when a change shows a strong signal, such as a new member of an existing enum, or a loading state entered in code that handles no failure. I have not measured that setting. Both runs together found 90% of the known state bugs for twice the cost and 16.4 comments a pull request, against 11.7 for the default review alone. That is for changes where a missed state bug is expensive, such as payments, sync, migrations and job queues. The qcr:state-machines label, an @yourbot state-machines comment and qcr review --state-machines add the eight state lenses to the normal review in one run. I measured that mode only on an earlier build and only on the answer key, where it found 46 of the 55, one more than the default review. Try it QuickReview is open source under the MIT licence and in beta. The state-machine review ships in QuickReview 1.5.0 and later. In a terminal, these lines install it and review your branch with the state lenses added. npm i -g @quickchatai/quickreview qcr login once, to sign in to a model provider qcr review --state-machines --preview the plan and the price, starts nothing qcr review --state-machines your branch, the normal review plus the state lenses A review with the state lenses added can cost more than the default limit of two dollars, and qcr asks before it starts a review whose estimate is over your limit. In pi, pi install npm:@quickchatai/pi-quickreview , then /qcr-review state-machines for a state-only review or /qcr-review --state-machines to add it to the normal one. In Claude Code, run npx @quickchatai/quickreview plugin install --to claude , restart Claude Code or run /reload-plugins , then type /qcr:review and ask it to check the state handling. The code, the docs and the benchmark are at github.com/quickchatai/quickreview https://github.com/quickchatai/quickreview . Limits - AI agents made the answer key, the state labels and the checks of the bugs outside the key, and no person has checked them. - The 105 are the state bugs known on these pull requests. A state bug that neither review found and the answer key does not list cannot be counted, so the shares are of the known bugs and overstate true recall. - The answer-key part was scored by GPT-6.1 Sol as judge, and the part outside the key by AI agents reading the code. - Each configuration ran once. A repeat of one of them differed by one defect. - The default review ran on the build before the merge, with its automatic state lens switched off. The merge did not change its other lenses. - The reviewer and the judge are the same model, GPT-6.1 Sol. - Part of the answer key entered it through the default review’s own earlier comments, which favours the default review on the key. - The 34 pull requests were chosen because they hold labelled state bugs, so state bugs are more common in them than in ordinary pull requests. Frequently asked questions What is an implicit state machine? It is behaviour that depends on which state a thing is in, where nobody wrote the states and the moves between them down in one place. The state hides in boolean flags such as isLoading, in nullable fields, in a status string or a database column, in a lifecycle phase, or in the order calls must come in. Ordinary application code has many of them. Is this different from pasting “find all of the implicit state machines in my app” into a coding agent? Yes. The prompt surveys a whole codebase in one pass and returns an inventory, and nothing checks what the agent claims. QuickReview’s state-machine review looks at one change through eight focused reviewers and reports only what the change made worse. Each reviewer has to give a bug as a sequence of events with a file and line for each step, and a validator replays that sequence before the comment is posted. On 34 pull requests it found 89 of the 105 state bugs known in them. I have not run the bare prompt against those bugs, so I have no score for it. Why do code reviewers miss state bugs? A state bug is a sequence of events, and a review reads lines. Each line of the change can be correct while a click, then an error, then a retry reaches a state the code mishandles. On Qodo’s public review benchmark, the QuickReview build behind my published scores, on GPT-6.1 Sol, found 12 of the 29 state defects, fewer than half, while it found more than half of the benchmark’s functional bugs overall. The sample is small, and its state labels were made by AI agents. What does QuickReview’s state-machine review look for? Eight kinds of state bug, each with its own focused reviewer. It looks for combinations of flags that must never exist, state changes that never check the state they leave, a new state that a switch or a list does not handle, and loading or processing states that an error or early return leaves set. It also looks for events that arrive twice, late or out of order, cached or derived values that go stale, calls made before init or after close, and stored state changed with no migration or written without a transaction. A validator then replays each claimed sequence against the code and drops what does not hold. How do I ask QuickReview for a state-machine review? On a pull request, add the label qcr:state-machines or comment “@yourbot state-machines” as an owner, member or collaborator. Both add the state review to the normal one. In a terminal, qcr review —state-machines does the same for your branch. In pi, /qcr-review —state-machines adds it to the normal review and /qcr-review state-machines runs it alone. To make it a repository’s whole review, set review profile = “state-machines” in QuickReview’s config.toml. In Claude Code and the other coding-agent plugins, ask the review in words to check the state handling. Should I run the state-machine review alone or on top of the normal review? On 34 AACR-Bench pull requests with GPT-6.1 Sol as reviewer and judge, 105 real state bugs are known. The state-machine review alone found 89 of them 85% for $2.78 a pull request and 4.7 comments a pull request. The default review found 75 71% for $2.77 and 11.7 comments, and it also covers every other kind of bug. The two runs together found 95 90% . Run it alone when state is the risk in a change, such as event handlers, async flows, caches or stored data. Run the default review for everyday review, and both when a missed state bug is expensive. Each was one run. How common are state-machine bugs? In the benchmarks I run, about one real defect in eleven is a state bug, so they are a minority. The shape they share, a sequence of events the code did not plan for, is behind many of the worst failures that field studies record. In a study of 198 failures in five distributed data systems, 77% needed more than one input event to happen, and 92% of the catastrophic ones came from mishandling a non-fatal error the software had already signalled. That study counted event sequences and error handling, and it had no state-machine category. On Qodo’s benchmark, QuickReview found fewer than half of the state defects, against more than half of the functional bugs overall. Does QuickReview run my code to find state bugs? No. It reads the code and runs none of it. Each state reviewer has to support a finding with the sequence of events that reaches the bug, with a file and line for each step, and a validator replays that sequence against the code before anything is posted. The posted comment tells the sequence in a few sentences and cites the lines it rests on.