After an agent deleted their CRM leads, dev ships a trusted merge layer for Postgres

Antique-Willow-5841 · reddit · 2026-10-17

After an AI agent with CRM write access deleted all their lead lists, the author set out to replace Postgres with a branch-per-run database — but community feedback ("the branch is easy, the merge is what must be trusted"; "nobody's moving their CRM") pivoted the first release to a sidecar beside your existing Postgres.

Each agent run gets its own branch of copied tables; merges write back in one transaction only after: verifying every changed row is unchanged (row and read-set checks for concurrent edits), running your SQL checks on the merged result, and applying rules like no deletes without a human, max-row limits and mandatory-review tables — with limits counted across the whole run so split deletes can't bypass them. Failed merges wait with reasons; Postgres is untouched.

Build lessons: the hard part was making "is this row still the same?" never false-alarm across timezones/float formats/triggers (let Postgres do the comparing); serial ids collide so ids are reserved from your own sequence; PgBouncer in transaction mode breaks session-state assumptions, so every setting must be per-transaction. Honest status: one-person beta for staging copies, no external real agents yet.

Related event: Developer Builds Git-Style Branched Postgres After AI Agent Wipes CRM Data(3 posts)→

Original post →

More from coding & agent

coding & agent channel →