Building a Zero-Overhead Postgres WAL Verifier in Go

We built an out-of-band Postgres 18 replication listener using pglogrepl. Here is how logical decoding stream inspection runs without adding socket latency.

When an AI agent or clinical scribe writes to a database, developers assume that receiving an HTTP 200 OK or rows_affected: 1 means the physical database state matches what the agent authorized.

It does not. In our benchmarks across PostgreSQL 18.6 and FHIR R4 stores, application-layer responses frequently diverge from physical disk commits.

How we use Jackc’s pglogrepl to decode Postgres 18 logical replication slots with zero socket latency impact on live applications.

The empirical setup

We configured an isolated environment with a PostgreSQL 18.6 instance and an open FHIR store. A simulated autonomous agent was given scoped permissions to execute record updates.

Deedglass was attached as an out-of-band physical storage witness using PostgreSQL logical decoding (pglogrepl consuming the Write-Ahead Log) and a direct FHIR read-back verifier.

Code A settings file: the rules a tool reads before it acts.

# Deedglass evaluation rule
- id: check-record-integrity
  match: { tool: "postgres.execute" }
  when: >-
    sql.kind == "update" && sql.tables == ["patient_records"]
    && !sql.unbounded_write
  approval:
    required: 1
    roles: ["attending_physician"]
Deedglass reads what Postgres actually committed, not what the agent reported. In our demo a hidden trigger turned 1 row into 301; a person countersigned the undo and all 301 rows came back.

The observed divergence

The agent executed what appeared to be a single-field mutation. The HTTP layer immediately responded:

Code Data in JSON, the format software uses to pass records and settings.

{
  "status": 200,
  "message": "Resource successfully updated",
  "rows_affected": 1
}

However, inspecting the PostgreSQL Write-Ahead Log (WAL) revealed a completely different story:

  1. An unindexed foreign key trigger fired asynchronously.
  2. A cascading constraint modified auxiliary clinical attributes.
  3. The actual rows mutated on disk exceeded the authorized parameter boundary.

The agent’s self-report claimed success on one row. The database transaction log recorded a multi-row divergence.

Why gateways cannot see this

Pre-execution gateways (such as API proxies or MCP network filters) intercept the call before it reaches the database. They can parse the SQL abstract syntax tree (AST), but they terminate at the socket layer.

They have zero visibility into:

  • Asynchronous database triggers (AFTER UPDATE)
  • Cascade foreign key rules (ON DELETE CASCADE)
  • Storage engine lock aborts and partial rollbacks
  • Physical write serialization conflicts

A pre-call gateway answers only one question: “MAY this request be sent to the socket?” It cannot tell you what the storage engine actually committed to disk.

The generic fix without any vendor

You do not need Deedglass to begin fixing this today. Any engineering team can improve their write integrity using native database primitives:

  1. Strict Statement Timeouts: Enforce SET statement_timeout = '2s' on all agent database sessions.
  2. Postgres RLS (Row-Level Security): Lock down tables so agent credentials cannot access rows outside their immediate operational scope.
  3. Transaction Isolation: Run agent writes under SERIALIZABLE isolation if concurrent writes touch related records.
  4. Trigger Auditing: Audit all legacy triggers to ensure they do not silently alter sibling tables during automated updates.

What this doesn’t catch

Honesty about technical boundaries is essential:

  • Logical decoding verifies committed rows on disk; it does not evaluate the clinical wisdom or medical accuracy of a note written by a human doctor.
  • If an agent writes garbage text into a text field, and that write was fully authorized by an attending physician, Deedglass reports Matches because the committed bytes match the authorized change.
  • Deedglass is strictly administrative and data-integrity infrastructure. It operates under a strict Non-SaMD (Software as a Medical Device) boundary and never provides clinical diagnosis.

How to reproduce it in 10 seconds

You can run this exact test against a local throwaway container:

Code Commands typed in a terminal. The text around it says what happens.

git clone github.com/deedglass/deedglass

The test runner will simulate an agent update, capture the WAL diff, and show you the exact discrepancy between what the tool reported and what the storage engine committed.

Written with AI assistance and checked against our claims register.

The takeaway

Decoding replication slots out-of-band provides zero-overhead write visibility without modifying application database queries or connection pools.

Read nextYour AI agent said it updated 1 row. Postgres changed 301. Try it in your browser

Related on this site

More posts

Sources & Reference Citations (3)

Citations
  1. 1Deedglass Healthcare Integrity Architecture · deedglass.com · checked 22 November 2026
  2. 2The 82-Case Deedglass Attack Suite · deedglass.com · checked 22 November 2026
  3. 3AAP-H Open Provenance Specification · deedglass.com · checked 22 November 2026

Published 22 November 2026, sources last checked 22 November 2026. If something here is out of date, write to hello@deedglass.com.

Try it on your own setup

npx deedglass scan

Grades only your own setup. Nothing is uploaded.

Pricing