---
id: w5/m9/t003
title: Safety acceptance — writes rejected, timeout, not-found, no value leakage
worker: worker5
status: done
estimate: 20m
depends_on: [w5/m9/t001]
---

## Objective

Adversarially exercise the safety rails against a real managed database on the mock cluster: every write shape is refused, the timeout and row cap hold, unknown databases 404, and neither logs nor error messages ever contain query text or data values.

## Context

- Stand up a `Database` CR via `POST /v1/postgres` (docs/ADR009-postgresql-management.md) on the mock cluster; run the MCP tool against it.
- Write shapes to try: `INSERT`, `UPDATE`, `DELETE`, `CREATE TABLE`, `COPY`, `SET transaction_read_only=off; INSERT …` (multi-statement escape), `SELECT … FOR UPDATE`.

## Steps

1. Deploy a managed Postgres; seed a table via `psql` (connection-info).
2. Run the write-shape matrix through the MCP tool — all must fail read-only.
3. Verify `pg_sleep` timeout, row-cap truncation flag, unknown-id not-found; grep bex-api logs for query text/values (must be absent).

## Files

- Test notes/fixtures under the milestone; any fixes back into `lego/backend/internal/postgres/`.

## Acceptance criteria

- [ ] Entire write-shape matrix rejected, including the multi-statement escape.
- [ ] Timeout, cap, and not-found behave as specified; logs are clean.

## Out of scope

- Load/perf testing; pooler behavior.
