So I let a language model write to my Postgres tables, and then I spent three months making sure it couldn’t do anything I hadn’t signed off on. Turns out that second part is most of the job.
In July I wrote about pg_synapse, the agent runtime that lives inside the database and gets called like a stored procedure. That post described a kernel and a promise. This one is what happened when I tried to keep the promise. The repo is at 0.2.0 now, and the project page links every doc.
The agent was running as a superuser#
I’ll start with the embarrassing one. In the first version, an agent could run with more privilege than the person who called it. On August 31 I fixed that. Agents now run as the role that invoked them, so whatever SQL the model dreams up is capped by that role’s grants. Read-only role, read-only agent.
The same day I added encryption for stored secrets, with the key kept outside the database. A day after that I found the key was still readable by anyone who could run an agent. One load earlier than I’d checked. That fix broke compatibility, and I’d rather break your install than leave that open, so if you built an early version, update.
The threat model doc says what’s defended and what isn’t. Prompt injection is contained, not solved. A tool that talks to the outside world leaves the database’s protections behind. A superuser caller still gets a superuser’s agent. Read that list before you deploy, not after. Two smaller guards ride along: the http tool takes a host allowlist so a hijacked agent can’t mail your data to a stranger, and a row can now name the run that wrote it.
An agent that can say no#
My favorite trick is the inline trigger. Attach an agent to a table in inline mode and it runs inside the writing transaction, sees the uncommitted row, and can kill it:
SELECT synapse.attach_agent_trigger(
'public.orders', 'order_screener', 'inline', 'INSERT', NULL, 'NEW::text');
INSERT INTO orders (note) VALUES ('...');
-- ERROR: synapse inline trigger rejected: <the agent's reason>That INSERT never happened. Rolled back, same as a constraint violation. A cron job can’t do that, because by the time it wakes up the row is committed, other sessions have seen it, and downstream triggers have fired. It can apologize, but it can’t prevent. I wrote the full argument up as Why not a Python script on a cron?, including a section on what cron does better. (Most of the boring stuff. Be honest with yourself about your use case.)
pg-one: a sentence in, an app out#
The app builder is called pg-one. You type “an app that tracks gym visits, with a note per session,” and a while later you have a schema with real tables, an agent that knows them, and sample rows so it isn’t empty.
“A while” deserves a number. Builds on my reference stack took 21 to 81 seconds, and they don’t all finish. Of six I watched, four completed, one hit its turn cap, and one timed out. That’s why the builder registers the agent before seeding data, and why there’s a Revise button and an Activity page that shows the failures. Apps can run on a schedule, get deleted, or be exposed over MCP so another agent can call one as a tool.

Runs that outlive your terminal#
Since September 2, a background worker keeps a run going after the session that started it disconnects. There’s a cap on runs in flight, a wall-clock budget a host can set per agent, and a guard that refuses a tool call the model has already made twice (models love to repeat themselves). A run that times out now keeps its trajectory instead of vanishing, which matters when you’re trying to figure out why it timed out.
The tuner#
The newest piece landed October 19 to 22: harness components, a trajectory renderer, lessons, and a Propose-Probe-Compose tuner. It reads an agent’s own message history, proposes edits to the prompt, memory and tool hints, tries each in a fresh database, and adopts the winner. Every adopted edit cites the execution it came from, and synapse.trajectory(id) shows the exact moment.
I borrowed the idea from Google’s harness2 and rebuilt it inside Postgres. The next post, on Plexus, runs it end to end, including the runs where it lost.
What’s still rough#
The sidecar, the HTTP host for managed Postgres where you can’t load an extension, has no authentication on its run surface. The docs say so in plain words, and the threat model calls its posture weaker than the extension’s. Put something in front of it or don’t use it.
Want to poke at it? The compose file now includes the sidecar, and there’s a containerized demo on localhost:8080. You bring the LLM, and it has to support function calling. First build compiles the Rust extension inside the database image, so go get coffee (10 to 25 minutes cold). Then tell me what broke.
