Skip to content

buzz-db: move the audit log SQL behind an AuditLog store - #10090

Open
TheSentinel454 wants to merge 6 commits into
elrond/buzz-811-relay-db-boundaryfrom
elrond/buzz-811-audit-store
Open

TheSentinel454 wants to merge 6 commits into
elrond/buzz-811-relay-db-boundaryfrom
elrond/buzz-811-audit-store

Conversation

@TheSentinel454

@TheSentinel454 TheSentinel454 commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #10087. Merge that first.

Summary

buzz-audit ran its own SQL on a raw pool: the community admission guard, the chain lock, the head read, the insert, and the range reads. That SQL now lives in a buzz_db::AuditLog store, which owns the audit pool. buzz-audit keeps the chain logic: it builds and hashes each row and verifies ranges.

  • AuditLog::connect builds the audit pool (5 connections, audit role). The relay used to build it itself.
  • AuditLog::append runs one transaction: admission, chain lock, head read, then a closure that buzz-audit uses to build and hash the row, then the insert. The lock order and transaction scope are unchanged.
  • AuditService::new takes an AuditLog instead of a PgPool.
  • AuditError::Database holds a DbError instead of sqlx::Error. Only DbError::AccessDenied maps to Admission.
  • The relay's audit retry check uses the new DbError::is_lock_timeout and the existing is_statement_cancelled, instead of matching SQLSTATE codes on sqlx errors.
  • deletion::guard_community_write becomes crate-private. buzz-audit was its only outside caller.

This is the second of three steps that take raw pool access and SQL out of every crate except buzz-db. The first is #10087. The last moves the search pool and SQL.

What got simpler

  • buzz-audit has no SQL. It still depends on sqlx only because the datastore span trait (DatastoreSpanError::span_sqlx_error) names sqlx::Error; that dependency goes when the trait stops naming it.
  • The relay no longer builds the audit pool or matches driver error codes for audit retries.
  • AuditError no longer has two variants that can both hold the same database failure.
  • The ARCHITECTURE.md "sanctioned exception" now names one store handle instead of a deletion internals function.

Behavior

No behavior change. Retry classification is the same: a lock timeout (55P03) or statement cancel (57014) anywhere in the append retries; admission refusal is terminal.

Tests

  • New: audit_pool_installs_timeouts_and_bounds_advisory_lock_waits in buzz-db (moved from the relay, now through AuditLog::connect; also checks the pool size).
  • New: db_errors_split_into_admission_and_database pins the DbError → AuditError mapping the relay retry check depends on.
  • The existing buzz-audit Postgres tests (admission, chain links, per-community isolation, tamper detection) run unchanged through the new store.
  • Ran: fmt, clippy (-D warnings) on buzz-db, buzz-audit, buzz-relay; unit tests for those crates; the Postgres tests for buzz-audit, the new buzz-db test, and relay audit tests.

🤖 Generated with Claude Code

@github-actions github-actions Bot added the codex-security-review-current The posted Codex security review matches its recorded range. label Dec 1, 2026
@github-actions

github-actions Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

🔐 Codex Security Review

Status: review required for the current range.

The current range is 8c2530f1f7ade7b0c957622c01e800c82687e74d...23d48a388a16480e89821146136e57276fb1e65c.
A new review must complete for this exact range. When manual authorization
is required, a user with write access must comment exactly
@buzz-security-review 23d48a388a16480e89821146136e57276fb1e65c to authorize a new review.
Any previous review applies only to its recorded range.

@github-actions github-actions Bot removed the codex-security-review-current The posted Codex security review matches its recorded range. label Dec 1, 2026
@github-actions github-actions Bot added the codex-security-review-current The posted Codex security review matches its recorded range. label Dec 1, 2026
@TheSentinel454
TheSentinel454 force-pushed the elrond/buzz-811-audit-store branch from a810c87 to 23d48a3 Compare December 1, 2026 22:55
@github-actions github-actions Bot removed the codex-security-review-current The posted Codex security review matches its recorded range. label Dec 1, 2026
TheSentinel454 and others added 6 commits December 1, 2026 18:01
Two merges each added tracing-subscriber to buzz-db's dev-dependencies.
Cargo refuses a manifest with a duplicate key, so main does not build.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Luke Tornquist <tornquist@squareup.com>
…he pool

Production code outside buzz-db reached the writer pool through
Db::pool() in five places. Each now calls a named Db method:

- Db::insert_mentions (audio 48101 mentions)
- Db::enable_search_outbox (relay startup)
- Db::acquire_timeout (shared-read wait budget)
- Db::session_identity (buzz-admin partition-audit read-only check)
- the deletion worker clones its Db instead of rebuilding one from
  the pool

The free insert_mentions and search_outbox::enable become crate-private.
buzz-admin and buzz-deletion no longer use sqlx in production, so it
moves to their dev-dependencies.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Luke Tornquist <tornquist@squareup.com>
SessionIdentity::is_read_only holds the check buzz-admin runs before
partition-audit, with a table test of all four setting combinations.
The docs now call the flags session settings: they do not show what
the role is allowed to write.

The session_identity Postgres test uses the fixture database instead
of creating its own, so it needs no CREATEDB.

The feed module doc names both mention-indexing paths: in the event
transaction, and after commit for huddle mentions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Luke Tornquist <tornquist@squareup.com>
buzz-audit ran its own SQL on a raw pool: the admission guard, the
chain lock, the head read, the insert, and the range reads. That SQL
now lives in buzz_db::AuditLog, which owns the audit pool.

- AuditLog::connect builds the audit pool (5 connections, audit role),
  which the relay used to build itself.
- AuditLog::append takes a closure: buzz-audit builds and hashes the
  row from the chain head, inside the same transaction and locks.
- AuditService::new takes an AuditLog instead of a PgPool.
- AuditError::Database holds a DbError instead of sqlx::Error. Only
  AccessDenied maps to Admission.
- The relay's retry check uses DbError::is_lock_timeout and
  is_statement_cancelled instead of matching SQLSTATE codes.
- guard_community_write becomes crate-private: buzz-audit was its
  only outside caller.

buzz-audit no longer uses sqlx in production, so it moves to its
dev-dependencies. The audit pool GUC test moves from the relay to
buzz-db.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Luke Tornquist <tornquist@squareup.com>
Admission-step failures render a fixed message again, as they did
before the move. The inner DbError keeps its type, so a lock or
statement timeout on the admission lock is still retried.

AuditLog::append now checks that the row extends the locked head:
seq is one past the head's and prev_hash equals the head's hash.
A test holds the chain lock while a fenced append must still be
refused, which pins admission before the chain lock.

Signed-off-by: Luke Tornquist <tornquist@squareup.com>

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Luke Tornquist <tornquist@squareup.com>
Database errors render transparently now that admission failures have
their own fixed text. AuditAppendError documents that a connection
failure during commit can leave the outcome unknown.

Signed-off-by: Luke Tornquist <tornquist@squareup.com>

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Luke Tornquist <tornquist@squareup.com>
@TheSentinel454
TheSentinel454 force-pushed the elrond/buzz-811-audit-store branch from 23d48a3 to a626713 Compare December 2, 2026 00:10
@TheSentinel454
TheSentinel454 changed the base branch from main to elrond/buzz-811-relay-db-boundary December 2, 2026 00:11
@TheSentinel454
TheSentinel454 force-pushed the elrond/buzz-811-relay-db-boundary branch from f1e2577 to b2bfb90 Compare December 2, 2026 02:56

This branch was successfully deployed

1 active (outdated) deployment
codex-review — 23d48a38 Deployed Dec 1, 2026 by TheSentinel454 via Run Codex Security Review #19102
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant