Commits
The approval circuit: MCP phase 2, step by step and race-tested
Model, atomic reservation, diff with preconditions, and execution service: everything an agent needs to touch a site without anyone having approved it. The door remains closed.
Phase 2 of the MCP is the delicate part: mutations. Before an agent can touch a site, everything has to go through an approval circuit where a human has the final say.
The circuit, starting from the database
I started with the model and the service: the preview, approval (only an administrator), the atomic reservation, the witness, and the result. The key piece is the reservation: it happens before any external effect and consists of a single conditional statement. If two executions try it at the same time, PostgreSQL locks the row and the second one is left without a witness: losing the race is not an error; it simply is not granted.
What CI and Linus kept catching
The PostgreSQL job in CI broke twice. First, because the test inserted a site with a fixed ID and collided with the one from conftest: locally it passed because the test is skipped, while in the place that mattered it was broken. Then, because comparing dates between SQLite and PostgreSQL blew up—one does not store the time zone and the other does—and, along the way, it uncovered that the approval performed a flush without committing and was lost when the session was closed.
Linus's reviews prevented us from building on sand. Approving cannot resurrect an approval: it is now a conditional statement, and whoever loses the race receives an error. Dates are compared in the database, not in Python. And each transition opens its own session and commits only its own changes, so that one commit never takes unrelated changes down with it.
The diff Javi approves
The diff is the preview that a person approves, and its rule is that it must state what it does not describe and when the supporting data is from. Linus found two holes in the preconditions: they did not inspect the target version—so a version that no one had approved could end up being installed—and they compared values without validating them, so two reads with no data appeared to match. There is now an explicit notion of a comparable value: a missing datum is not the same as a datum that holds a value.
Executing, with the door closed
The preview, listing, and approval endpoints are now available over HTTP, with per-site scoping in the listing (another finding from the same family: the role was checked, the scope was not). The execution service follows this sequence: reserve, verified copy, recheck, and apply. It fails closed: without both versions matching, there is no installation, and if there is no proof that the action did not reach the target, the result is unknown.
Along the way, Javi deployed the credentials UI on fxserver, and we left the runbook with both rollback plans tested: the image-based one, which is instantaneous, and the reconstruction one, which returns the previous code even though not the bytes. The mutations switch remains closed: it opens with the entire circuit.