Vibe coding predictable services: from Coq to JavaScript
I think learning half of the halting problem does engineers a disservice.
We learn that no algorithm can always decide whether an arbitrary program halts on an arbitrary input. Somehow, that can turn into a much broader belief: proving useful things about software is a lovely academic exercise, but we have a service to ship.
That is asking rather a lot of the word “arbitrary”.
We can prove things about particular programs. We can choose structures that make those proofs practical. And we can generate executable code from the definitions we reasoned about.
So we tried it: a small distributed TV-pairing protocol, written in Coq, compiled to JavaScript, and integrated into a bounded, opt-in application pilot.
Yes, this started with trying to connect a tablet to a television. Apparently, that was enough distributed systems for one afternoon.
The television has received your request to become a research project
Consider this sequence:
- You start connecting to a TV.
- The connection takes too long.
- You retry.
- The new attempt progresses.
- A delayed message from the first attempt arrives.
Does that old message get to change the state of your new connection?
It should be a fairly boring question. Unfortunately, asynchronous systems have considerable enthusiasm for making it interesting.
There are related questions. What if cancellation reaches the backend before the request it cancels? What if the request arrives after the tablet has already timed out? Does opening the TV’s outer viewer mean the application is actually ready?
We built a candidate protocol to make those distinctions explicit.
This was a new design informed by inspected failure modes. We did not formally verify the old production JavaScript or establish the exact cause of a historical TV failure. Even a proof assistant has limits on retrospective storytelling.
Three participants, each with its own state
The protocol has three roles: tablet, backend and TV.
Each role has a pure handler. Give it its current state and an event; it returns a new state and any outgoing packets. Transport and persistence sit around those handlers.
Every connection attempt carries an increasing attempt number. Older messages cannot simply turn up and claim to be current.
The backend remembers cancellations, including ones that arrive before creation. Otherwise, a delayed request could resurrect an attempt the user had already abandoned.
We also found a useful trap while constructing the model: a timeout measured only from when the backend receives a request can grant a fresh lease to a request that spent most of its life delayed in the network.
The tablet may have given up ages ago. The backend has only just started being helpful.
We addressed that by carrying an absolute attempt deadline. The backend’s lease must fit within it. Duplicate requests reuse the existing lease deadline rather than extending it.
Readiness is explicit too. An acknowledgement from the outer viewer does not establish that the application has loaded. The protocol requires an application-prepared event before the backend can commit the connection.
That still does not prove a YouTube video is playing. Application readiness and media playback are separate facts. Naming them separately helps.
What we actually proved
The Coq model allows messages to be delayed, dropped, duplicated and reordered. It also includes role crashes and recovery.
Within that model, we proved properties including:
- Stale commits and rejections cannot overwrite a newer local attempt.
- A cancelled attempt cannot be reopened by a delayed request.
- Distinct backend lease windows cannot overlap.
- A connected state requires the corresponding application-prepared history.
- Expired requests are refused, and processing the relevant local ticks moves expired clients into a retry state.
These results quantify over arbitrary finite executions permitted by the model. They are not just statements about the scenarios we happened to test.
The main proof assumption reports were closed under the global context, with no admitted lemmas or newly introduced axioms.
There are still environmental contracts. The model assumes authenticated messages, durable state and a shared monotonic logical clock. Those assumptions matter when connecting the handlers to a real system.
There is also no promise that a connection eventually succeeds if the network drops every packet forever.
I would quite like that feature. We have not implemented a cooperative universe.
The recovery result is narrower: once deadlines have passed, the required local ticks can move the clients into retry without needing network delivery. The environment still has to process those ticks.
Where the vibe coding fits
The useful idea is to give AI-assisted development something more demanding than “that looks reasonable”.
We can ask for a protocol change, executable definitions and proofs of the properties we care about. The proof checker gives us a mechanical acceptance condition for those claims.
It does not decide whether we asked for the right properties.
A model can be beautifully proved and omit the exact behaviour the user needed. An assumption can make a difficult obligation disappear by quietly moving the difficulty somewhere else.
Someone still has to read the specification.
For this experiment, useful review questions included: can an old attempt affect a new one? Can cancellation be undone by message ordering? What exactly counts as ready? What happens when nothing arrives?
“Make it reliable” leaves quite a lot of room for creative interpretation.
We compiled the handlers we proved
The JavaScript path was:
Coq/Rocq definitions
↓
OCaml extraction
↓
OCaml bytecode
↓
js_of_ocaml
↓
JavaScript role handlers
The tablet, backend and TV entry points came from the same Gallina definitions used by the proofs. We did not write a second JavaScript state machine and hope it resembled the first one.
We also compiled those definitions through CertiRocq to WebAssembly and compared the two paths.
Both passed the same ten targeted scenarios, 27 malformed-input checks and 128 seeded fault schedules across Node, Bun and Chromium. We subsequently ran the comparison in a temporary WebView on the actual tablet and in private AWS Lambda experiments.
The JavaScript path was quite usable. For one backend request workload, its warm batch-average median was about 0.025 milliseconds on the tablet and 0.019 milliseconds in Lambda.
The current WebAssembly path was slower in those measurements. Its bridge creates a fresh instance and marshals its heap for each event; the JavaScript path reuses its generated runtime. Both retain unary natural numbers, which also affects cost as values grow.
Those are measurements of the implementations we built. They do not establish that JavaScript has defeated WebAssembly. That argument can find its own LinkedIn post.
Then we put a fence around the pilot
We integrated the generated JavaScript handlers into a deliberately short, opt-in connection pilot. Normal pairing remained the default.
The pilot uses bounded rooms and leases, with no renewal. An issued lease lasts at most 50 seconds, an attempt lasts 80 seconds, and the room lasts at most ten minutes. Expiry returns playback to the tablet and offers a fresh connection path.
Those limits suit the prototype’s bounded numeric interface. They are not an invitation to use it as an indefinitely running production clock.
The integration also has to preserve the core’s contracts: save state before emitting packets, authenticate participants, enforce lease validity and map real time into protocol ticks.
Those adapters have regression and integration evidence. They are not covered by an end-to-end formal proof.
Neither are the entire extraction and compilation chain, JavaScript engine, storage system or browser lifecycle.
The claim is specific: we proved properties of the protocol core, generated executable handlers from its definitions, and exercised the surrounding implementation.
That is already useful. It does not need to become “we proved the television”.
About that halting problem
A long-running service is usually supposed to keep running. Proving that the whole thing eventually stops would be an unusual product requirement.
Termination is one property. Preventing stale messages from changing a newer connection is another.
The engineering opportunity is to choose useful properties, make their assumptions explicit, and build software whose structure lets us establish them.
The halting problem rules out a universal decision procedure. It does not relieve us of thinking about the program in front of us.
We used Coq to make specific promises about a small protocol, then compiled its handlers to JavaScript.
The vibes can propose the change.
They still have proof obligations.