Skip to content

buzz-db: drop the five single-table guard triggers (BUZZ-318 phase 2) - #9398

Merged
TheSentinel454 merged 5 commits into
mainfrom
elrond/drop-single-table-guards
Nov 17, 2026
Merged

TheSentinel454 merged 5 commits into
mainfrom
elrond/drop-single-table-guards

Conversation

@TheSentinel454

@TheSentinel454 TheSentinel454 commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Note

Rollout: #8320 (app guards + catalog expand) is deployed, so the hold is lifted. With autoMigrate=true, 0096 runs at startup under a 5s lock timeout, and a failure stops startup. With BUZZ_AUTO_MIGRATE=false, deploy this binary first and then run buzz-admin migrate. Both orders are safe because the expand tolerates the objects being present or absent.

What

The required stop for 0096 is in docs/trigger-retirement-deployment.md (from #9622): a relay build at or after #8320 (ec778bff). A build older than that needs the tombstone trigger at startup and readiness.

Migration 0096_drop_single_table_guards.sql drops five triggers and their functions. #8320 moved each invariant into the application writers:

Trigger (table) Function
trg_channels_community_id_immutable (channels) channels_community_id_immutable()
communities_deletion_tombstone (communities) enforce_community_tombstone()
community_deletion_request_retargeting_guard (community_deletion_requests) prevent_community_deletion_request_retargeting()
community_deletion_approval_removal_guard (community_deletion_approvals) prevent_community_deletion_approval_removal()
community_deletion_manifest_keys_guard (community_deletion_manifest_keys) protect_community_deletion_manifest_keys()

Desired state (schema/) drops the five functions and four trigger files, plus the channels trigger declaration. The universal write fence on channels stays. Both boot paths stay catalog-equivalent: the pgschema-vs-migration parity check now also compares columns, key and FK shapes, and the remaining triggers on all five tables.

Executor GUCs stay because assert_community_write_allowed still reads them through the universal write fence. transition_community and every phase-1 app guard are byte-identical to #8320. scripts/reconcile-schema-after-pgschema.sql has no entries for these objects.

Tests

  • buzz-db: enforce five single-table guards in app writers (phase 1) #8320's six single_table_guard_*_without_trigger PG tests no longer need to disable a trigger. They are now plain app-path tests with the same assertions.
  • New per-test regressions for the desired-template and migration boot paths assert that none of the ten objects exist, including disabled triggers and function overloads.
  • Deleted assertions that only exercised raw SQL against the triggers: retarget, rewrite and approval mutation, frozen-manifest rewrite, and tombstone DELETE. The app-path coverage for each remains.
  • The expand regression in buzz-db: enforce five single-table guards in app writers (phase 1) #8320 migrates through 0086, validates serving, readiness and the deletion lifecycle, drops the five guards, then validates again.
  • Rebased onto main b568d9bf after Retire the 0032 roster trigger in migration 0095 #8696 took 0095; renumbered to 0096. Blox gate at 7bda1f45: fmt, clippy and buzz-db --lib pass; the PostgreSQL lane ran 219 tests, all pass.
  • Gate at c8bc061c (on main 051dd2d7, then numbered 0095, docs: name the required stop for migration 0096 #9622 folded in): on Blox, cargo fmt --check, clippy and the buzz-db --lib tests pass. The PostgreSQL lane (migrations, single-table guards, floor retirement, fence and deletion) ran 208 tests: all pass.
  • Earlier gate at 0840ba49: CI was green, and the Blox PostgreSQL lane passed 840 of 841 (the one failure, media_reference_full_query_plans, is a timing check that fails the same way on main on that host).
  • The rebase updates main's fence-retirement tests to expect the tombstone trigger gone.

What got simpler

Ten database behavior objects and nine desired-state files are gone (about 150 lines). Each rule has a single owner, the application writer.

buzz-review-completed

🤖 Generated with Claude Code

@TheSentinel454
TheSentinel454 force-pushed the elrond/single-table-guards-app branch from cdc88ed to ac0fab9 Compare November 12, 2026 15:55
@TheSentinel454
TheSentinel454 force-pushed the elrond/drop-single-table-guards branch from 726659b to 1c2a638 Compare November 12, 2026 15:55
@TheSentinel454
TheSentinel454 force-pushed the elrond/single-table-guards-app branch from ac0fab9 to c1ebef5 Compare November 17, 2026 01:17
TheSentinel454 added a commit that referenced this pull request Nov 17, 2026
…8320)

> **Also carries the catalog expand** (`cdc88edd`) for phase 2 (#9398).
`validate_serving_catalog`, used at boot and readiness, no longer
requires the `communities_deletion_tombstone` trigger, only
`community_deletion_lock_key(uuid)`. Without this, a pod would fail boot
after `0090` drops the guards. Regression:
`migration_schema_single_table_guards_are_optional_for_serving_and_deletion`
migrates through `0086`, validates serving, readiness and the deletion
lifecycle, drops the five guards, and validates again. No schema change.

## What

This is phase 1 of 2 for retiring five single-table guard triggers
(BUZZ-318). Their invariants now hold in the application writers. **All
five triggers and their functions stay** for mixed-version pods. A later
PR drops them.

| Trigger / function | App-side enforcement |
|---|---|
| `trg_channels_community_id_immutable` | **By construction.** Inserts
bind the tenant once. No production `UPDATE channels` assigns
`community_id`, and `ChannelUpdate` has no community field. A source
policy pins this. |
| `communities_deletion_tombstone` / `enforce_community_tombstone()` |
**One state machine.** `begin_quiescing`, `fence`, `purge_postgres` and
`abort` all go through `transition_community`, using a `FOR UPDATE` row
snapshot in the caller's transaction (quiesce, fence and abort also hold
the community deletion advisory lock; purge does not, and its tombstone
transition fails if a concurrent abort won). Allowed transitions:
active→quiescing (plus a quiescing retry); quiescing→fenced, which
increments the generation; fenced→tombstone at the same generation, with
a one-way `deleted_at`; active/quiescing/fenced→active on abort, which
also increments the generation. Every transition rejects an
already-deleted row. The UPDATE is conditioned on the snapshot's state
and generation. `set_community_icon` updates only an active, undeleted
row and returns `AccessDenied` otherwise. Archive and unarchive lock an
active row, and their UPDATEs also carry `deletion_state = 'active'`, so
every non-lifecycle `communities` UPDATE or upsert carries the active
predicate (policy-pinned: a non-active row is immutable outside the
state machine). No production `DELETE FROM communities` exists, and the
policy forbids adding one. Executor GUCs are unchanged. |
| `community_deletion_request_retargeting_guard` | **Mostly by
construction, plus predicates.** No production UPDATE assigns target
identity or provenance (policy-pinned). Both initial inventory freezes
(`freeze_inventory`, `complete_owner_preparation`) require `stage =
'submitted' AND blocked_at IS NULL AND inventory_frozen_at IS NULL` in
their UPDATE. Every request UPDATE that assigns an inventory column must
carry `inventory_frozen_at IS NULL`, and one that assigns
`destructive_storage_*` must carry the frozen-or-equal guard
(policy-pinned). The destructive-manifest freeze now also refuses a row
that is marked frozen but is missing its manifest JSON. |
| `community_deletion_approval_removal_guard` | **By construction.**
Approvals are insert-only (`approve`, `complete_owner_preparation`). The
policy forbids any production UPDATE, `ON CONFLICT … DO UPDATE` upsert
or DELETE. |
| `community_deletion_manifest_keys_guard` | **One shared check.**
Append, pre-freeze clear and verified cleanup each lock the request row
and check its stage and freeze status through
`guard_manifest_chunk_write`. Chunk content is never updated: the policy
rejects every chunk UPDATE or conflict upsert except
`mark_manifest_chunk_deleted`, the only writer that stamps `deleted_at`.
That stamp must be the function's only chunk write, a plain UPDATE of
exactly `SET deleted_at = now()`, with `request_id = $1`, `chunk_no =
$2` and `deleted_at IS NULL` as plain conjuncts (no `OR`, no subquery),
so it stays one-way. |

**The app is stricter than the triggers, not equivalent to them.**
`enforce_community_tombstone()` admits any change when the executor GUC
matches, before it looks at lifecycle columns, so the transition graph
above lives only in `transition_community`. The chunk DELETE trigger
also allows cleanup when the parent request is missing or unfrozen,
while `guard_manifest_chunk_write` allows only fenced-and-unfrozen or
verified cleanup. Every current caller already runs at those stages.

Writer inventory: I searched every production writer of these tables and
columns across all crates, excluding `#[cfg(test)]`. That covers
buzz-db, buzz-deletion, buzz-relay handlers, side effects and
operator/admin APIs, and buzz-audit. Relay, operator and executor entry
points all call the store methods above. No other crate writes these
tables directly.

## Tests

The six PG tests are in `store::deletion::postgres_tests`. Each disables
**only** its own trigger, then checks that the app path rejects the
forbidden mutation and permits the allowed one:
- `single_table_guard_channels_remain_tenant_bound_without_trigger`
-
`single_table_guard_community_lifecycle_rejects_deleted_row_without_trigger`:
icon refused while quiescing; fence refused on a deleted row; then the
full fence→tombstone sequence; abort after tombstone fails.
- `single_table_guard_abort_invalidates_generation_without_trigger`:
abort from quiescing and from fenced, for unarchived and pre-archived
communities; asserts active state, community and request generation =
previous + 1, restored `archived_at`, null `deleted_at`.
-
`single_table_guard_request_inventory_freeze_is_one_way_without_trigger`:
re-freeze is refused on both the operator and owner-preparation paths.
The owner path leaves no approval evidence behind. Owner request-ID
retargeting is refused, and a frozen manifest with missing JSON can't be
filled in.
- `single_table_guard_approval_evidence_is_append_only_without_trigger`:
asserts the exact error.
- `single_table_guard_manifest_chunks_stop_at_freeze_without_trigger`

The source policy lives in
`crates/buzz-db/tests/observability_source.rs`
(`every_production_single_table_guard_writer_preserves_its_invariants`).
It scans every crate's `src` directory and reuses the file's existing
cfg-test stripping, comment and literal masking, function slicing and
SQL normalization. Each rule is checked per function. A minimum count of
discovered writers per table makes the test fail if discovery stops
matching, and exact sets of production functions hit by each rule
(lifecycle exemption, stamp exemption, chunk-guard callers,
active-community writers, request-freeze writers) make it fail if a
parser stops matching. The parser handles `ON CONFLICT … DO UPDATE SET`
(with or without a space before `(`), tuple `SET (a, b) =`, and rejects
column-less community inserts. A guard counts only as a plain conjunct
of the statement's own WHERE: it must follow the WHERE start or an `AND`
(optionally table-qualified, never `NOT`), with no whole-word `OR`
outside the frozen-or-equal groups and no subquery, and every
`destructive_storage_*` assignment must preserve a frozen value with
`COALESCE`. Negative and accept fixtures cover every rule. The shared
source filter now also skips `test_support.rs`, which is compiled only
under `cfg(test)`.

Each check was confirmed to fail when its fix is removed. Seven mutants
each failed on an assertion: the `inventory_frozen_at` predicate removed
from each of the two freeze paths, and each of the five policy rules
disabled. Review rework also falsified the injected `SET icon = NULL`
writer, an unguarded inventory/destructive-storage writer, abort keeping
the old generation, and the stamp without `deleted_at IS NULL`; every
new fixture test fails against the previous policy. Round 1 also
falsified the lifecycle `deleted_at` check, the manifest append guard,
the icon predicate and the destructive-manifest predicate.

## What got simpler

The four lifecycle UPDATE statements, each with its own generation
arithmetic and its own GUC setup, are now one transition function with
one SQL writer. Both manifest removal modes share one admission check.
For inventory freeze, the check lives in the existing atomic UPDATE,
with no new helper or transaction. Channel immutability and approval
append-only behavior stay construction rules, not duplicated runtime
checks. The source-policy scans now share one Rust crate walker, which
this PR extracted into `collect_production_rs_files`.

**Known policy limits:** the policy is a textual check of Rust source,
not a SQL parser or a control-flow analysis. None of these gaps hides an
unsafe writer today, but phase-2 reviewers should not read the policy as
more than that:
- Only `INSERT`, `UPDATE` and `DELETE` statements are recognized,
including CTE and `ON CONFLICT` forms. `MERGE` and `TRUNCATE` are not.
`UPDATE ONLY <table>` and `DELETE FROM ONLY <table>` are not recognized
either, because the table name must follow the verb directly.
- A guard negated *after* itself (`deletion_state = 'active' IS FALSE`,
`… = false`) is not caught.
- A SQL comment inside the literal (`-- AND deletion_state = 'active'`)
can supply the guard text.
- The frozen-or-equal `OR` text is removed before the `OR` check without
checking how it is grouped.
- `guard_manifest_chunk_write(` is checked for presence in the writing
function only. The policy does not show the result is awaited and
propagated, or that the guard runs in the same transaction as the write.
With the trigger disabled,
`single_table_guard_manifest_chunks_stop_at_freeze_without_trigger`
shows append and pre-freeze clear refusing after freeze; verified
cleanup has no trigger-disabled test.
- Function discovery uses a fixed list of signature prefixes, and
dynamic SQL is recognized only in known shapes such as `set_parts.push`.
- The shared source filter skips files named `test_support.rs` by name.
Both such files are compiled only under `cfg(test)` today.

**Phase 2 (not here):** a forward migration plus a desired-state change
will drop only these five triggers and functions and update
`validate_serving_catalog_on` and the schema assertions. It ships after
every serving and executor pod runs these writers.

**Identified debt (pre-existing, outside this diff):** purge can take
the request-row FK lock (checkpoint insert) before the community lock,
while abort locks community then request (`deletion.rs` purge vs abort).
PostgreSQL detects that as a deadlock and cancels one side, which fails
closed; the order is unchanged from the base.
`runtime::postgres_tests::writer_pool_rejects_non_read_committed_database_default`
hangs until its 120 s bound on clean `177551dda` as well. Some test-only
fallbacks still hardcode `localhost:5432`, and one relay test helper
hardcodes Redis 6379.

## Verification (Blox, byte-identical tree to this commit)

| Gate | Result |
|---|---|
| `cargo fmt --all -- --check` | pass |
| `cargo clippy --workspace --all-targets -- -D warnings` | pass |
| `cargo nextest run -p buzz-db --lib` | 166/166 |
| `cargo nextest run -p buzz-db --test observability_source` | 30/30 |
| `scripts/test-postgres-test-discovery.sh` | pass |
| `scripts/postgres-test-run.sh -p` buzz-admin / audit / deletion /
push-gateway / relay / search / workflow | all rc 0 (4, 7, 11, 11, 402,
20, 2) |
| `scripts/postgres-test-run.sh -p buzz-db` | 515 pass, 1 fail: the
pre-existing hang above |

The new PG tests are selected by the `postgres-ci` filter
`(test(/postgres_tests::/) or binary(/^postgres_/)) and not
test(/(^|::)external_infra[^:]*::/)`. The policy tests run in `just
test-unit` (`--test observability_source`).

---------

Signed-off-by: Elrond <28d6302a099e5225b02c4155ac4236e4912603df2ab08dbfc2f4fef08ce598c8@buzz.block.builderlab.xyz>
Signed-off-by: Luke Tornquist <tornquist@squareup.com>
Co-authored-by: Elrond <28d6302a099e5225b02c4155ac4236e4912603df2ab08dbfc2f4fef08ce598c8@buzz.block.builderlab.xyz>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Base automatically changed from elrond/single-table-guards-app to main November 17, 2026 03:08
@TheSentinel454
TheSentinel454 force-pushed the elrond/drop-single-table-guards branch from 1c2a638 to 421d48c Compare November 17, 2026 03:15
TheSentinel454 added a commit that referenced this pull request Nov 17, 2026
… functions (contract) (#9598)

## Summary

Phase 2 of retiring the two remaining plain SQL functions. Phase 1 moved
their work into the relay:

- #9396 builds the community deletion lock key in Rust
(`deletion::community_deletion_lock_key`, locked with
`hashtextextended($1, 0)`).
- #9397 reads profile names with inline SQL (`PROFILE_NAME_FIELDS` in
`buzz-search`).

No relay at or after #9397's merge (`279a31da`) calls either function.
This PR drops them:

- **Migration 0093** runs `DROP FUNCTION
community_deletion_lock_key(UUID)` and `DROP FUNCTION
profile_name_fields(TEXT)` under a 5s `lock_timeout`, with no `IF
EXISTS` and no `CASCADE`. If anything still depends on a function, the
migration fails instead. Migrations 0029 and 0064 stay frozen. No
database function calls either one any more: 0090 dropped the fence
functions, which were the only SQL callers of the lock key.
- **Desired state:** removes both `schema/functions/` files and their
`schema.sql` includes. Both boot paths stay catalog-equivalent
(`admin_schema_parity_between_desired_state_and_migrations`).
- **Tests:**
- New `migration_0093_drops_plain_sql_functions`. It migrates to 0092,
checks that both functions exist and that serving and deletion catalog
validation pass, then runs 0093 and checks that both functions are gone
and that validation still passes. This covers new code on either side of
the drop.
- The migration listing test pins 0093's statements and that it has no
`CASCADE`.
- `desired_state_catalog_has_no_universal_fence_and_still_boots` now
asserts that both functions are absent.
- Replaces the Rust-vs-SQL lock key parity test with
`community_deletion_lock_key_bytes_are_fixed`, a unit test that maps
fixed UUIDs (nil, max, and one with hex letters) to their exact keys.
Older replicas and the repair-script key in `docs/database.md` build the
same string, so a changed prefix or UUID format must fail a test.
- Removes two relay test-schema wrappers (`bridge.rs`, `ingest.rs`) that
forwarded `community_deletion_lock_key` to `public`. Writers no longer
call it, and the wrapper's `CREATE FUNCTION` would fail once the
function is gone.
- **Docs:** `docs/trigger-retirement-deployment.md` gets a `0093`
section with the required stop.

## Deploy gate

**Required stop:** any relay build at or after `279a31da` (#9397's
merge, which follows #9396). `relay-v0.3.0` does not contain it. A relay
older than that which still serves after 0093 fails every write and
deletion that takes the community deletion lock, with `42883
community_deletion_lock_key(uuid) does not exist`, and its profile name
search fails with `42883 profile_name_fields(text) does not exist`. 0093
takes no table locks and needs no cleanup.

Migration number: #8696 and #9398 also propose `0093`. Whichever lands
second renumbers.

## Review-Proven Rules

- **RPR #2 (every path):** I checked every reference on `main` and at
the stop build `279a31da`. At both, only test code reads either
function: no boot, readiness, catalog or runtime query depends on them.
Serving and deletion catalog validation pass before and after 0093, in
the new test.
- **RPR #3 (falsifiable):** removing the `profile_name_fields` drop from
0093 turns `migration_0093_drops_plain_sql_functions` red.
- **RPR #3 (lock key bytes):** a changed prefix, `.simple()` UUID
formatting, or uppercase formatting each turns
`community_deletion_lock_key_bytes_are_fixed` red.

## What got simpler

Two database functions, their desired-state files, a cross-language
parity test and two test-only SQL wrappers are gone. After this PR, the
only functions left in `schema/functions/` are trigger functions.

## Validation

Blox gate at `95ac71c8`:

- `cargo fmt --all --check`, and `cargo clippy -p buzz-db -p buzz-relay
--all-targets -D warnings`.
- `buzz-db --lib` unit tests: 216/216, including the migration listing
test.
- `buzz-db` Postgres tests (`migration::`, `deletion::`,
`nip_fi_binding::` postgres_tests): 130/130. These include
`migration_0093_drops_plain_sql_functions`,
`admin_schema_parity_between_desired_state_and_migrations` and
`deletion_surface_parity_between_migration_0029_and_schema_sql`.
- `buzz-search` `profile_names*` Postgres tests: 4/4, on a fully
migrated database where `profile_name_fields` no longer exists.
- The two relay tests whose test-schema wrapper this PR removes: 2/2.
- Must-fail check: with the `profile_name_fields` drop removed from
0093, `migration_0093_drops_plain_sql_functions` fails.

Second Blox gate at `e1b5513a` (the lock key vector test):

- `cargo fmt --all --check`, and `cargo clippy -p buzz-db --all-targets
-D warnings`.
- `buzz-db --lib` unit tests: 217/217.
- Must-fail checks: a changed prefix, `.simple()` and uppercase UUID
formatting each fail `community_deletion_lock_key_bytes_are_fixed`.

The first gate run found that
`deletion_surface_parity_between_migration_0029_and_schema_sql` still
expected `community_deletion_lock_key` in `schema.sql`. The second
commit fixes that.

🤖 Generated with [Claude Code](https://claude.com/claude-code)



buzz-review-completed

---------

Signed-off-by: Luke Tornquist <tornquist@squareup.com>
Co-authored-by: Elrond <28d6302a099e5225b02c4155ac4236e4912603df2ab08dbfc2f4fef08ce598c8@buzz.block.builderlab.xyz>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
@TheSentinel454
TheSentinel454 force-pushed the elrond/drop-single-table-guards branch from 0840ba4 to 5a0db4a Compare November 17, 2026 19:35
@TheSentinel454
TheSentinel454 marked this pull request as ready for review November 17, 2026 19:40
@TheSentinel454
TheSentinel454 requested a review from a team as a code owner November 17, 2026 19:40
@github-actions github-actions Bot added the codex-security-review-current The posted Codex security review matches its recorded range. label Nov 17, 2026
@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

🔐 Codex Security Review

Note: This is an automated, security-focused review generated by Codex.
Use it as a supplement to human review; false positives are possible.

Scope

  • Exact PR diff: b568d9bf955e9a1a329c94f7c0c792d2f53d586c...7bda1f45a39cd5d958e58f7bd944922c023ac433
  • Model: gpt-6.1-sol

💡 Click "edited" above to see earlier reviews for this PR.


Review Summary

Overall Risk: NONE

No concrete security, correctness, or reliability regressions found in the authorized PR range.

Findings

No concrete security, correctness, or reliability findings were identified.

Notes

  • Read-only inspection; builds, tests, and migrations were not executed.
  • Trigger retirement depends on the documented prerequisite writer deployment across all pods and jobs.

Generated by Codex Security Review |
Requested by: @TheSentinel454 |
Workflow run

@brow brow left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 The pre-review recommends landing this with one small fix: #9622 0096 required stop doc. Without it, docs/trigger-retirement-deployment.md names no required stop for 0096 and still accepts a 0094 stop build older than #8320. A relay that old requires the tombstone trigger at startup and on every readiness check, so after 0096 it goes not ready and cannot restart or be rolled back to.

Please merge the fix into your branch (it needs no approval there). This PR is then approved on Tom's go-ahead.

@TheSentinel454
TheSentinel454 force-pushed the elrond/drop-single-table-guards branch from d12d447 to c8bc061 Compare November 17, 2026 21:32
@github-actions github-actions Bot removed the codex-security-review-current The posted Codex security review matches its recorded range. label Nov 17, 2026
@TheSentinel454

Copy link
Copy Markdown
Contributor Author

🤖 Merged #9622 into this branch (squashed as 0efc42e4). The branch is now rebased on main and no longer stacked on #9610, so the migration is 0095. The required-stop doc text now says 0095. Head is c8bc061c.

@github-actions github-actions Bot added the codex-security-review-current The posted Codex security review matches its recorded range. label Nov 17, 2026
TheSentinel454 and others added 3 commits November 17, 2026 16:57
Migration 0095 drops trg_channels_community_id_immutable,
communities_deletion_tombstone, community_deletion_request_retargeting_guard,
community_deletion_approval_removal_guard and
community_deletion_manifest_keys_guard with their functions. Application
writers own each rule since #8320, and catalog checks tolerate their
absence since that release.

Remove them from desired state, keep catalog parity between both boot
paths, convert the six trigger-disabled app regressions into plain app
tests, and delete assertions that only exercised the triggers.

Co-authored-by: Elrond <28d6302a099e5225b02c4155ac4236e4912603df2ab08dbfc2f4fef08ce598c8@buzz.block.builderlab.xyz>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Luke Tornquist <tornquist@squareup.com>
Main's fence-retirement tests asserted that communities_deletion_tombstone
still exists. Migration 0095 drops it, so they now assert it is absent.

Co-authored-by: Elrond <28d6302a099e5225b02c4155ac4236e4912603df2ab08dbfc2f4fef08ce598c8@buzz.block.builderlab.xyz>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Luke Tornquist <tornquist@squareup.com>
Adds a "Single-table guards (\`0096\`)" section to
\`docs/trigger-retirement-deployment.md\` for #9398, as
\`docs/database.md\` Rule 5 requires.

Without it, the only stop the doc names is the \`0094\` one
(\`279a31da\` or later), which predates #8320. A relay that old requires
the community tombstone trigger at startup and on every readiness check,
so once \`0096\` drops it the relay goes not ready and cannot restart,
with auto-migration on or off. The new section names \`ec778bff\` (the
merge of #8320) as the required stop and rollback floor, lists the five
dropped triggers and functions with their application replacements, and
describes the locks \`0096\` takes.

### Validation

- Docs only. Checked each stated fact against the tree: \`279a31da\` is
an ancestor of \`ec778bff\`, which is an ancestor of the \`0094\` merge
(\`4e8f8365\`); \`git tag --contains ec778bf\` lists no relay release;
the error string and the unconditional startup and readiness catalog
checks at \`ec778bff^\`; the trigger and function names in \`0096\`.

### Regressions

None: one documentation file, no code or migration change.

Signed-off-by: Tom Brow <tomb@squareup.com>
Co-authored-by: Tom Brow <tomb@squareup.com>
Co-authored-by: studio <dc2fc481343672df31a689840c09299972e704dac592e0da6f18486646a7ee3e@buzz.block.builderlab.xyz>
TheSentinel454 and others added 2 commits November 17, 2026 16:58
Rebased off #9610 onto main, which ends at 0094, so the drop is 0095.
A build between #9363 and #9615 is not a valid 0094 stop, so the shared
stop must also satisfy 0094's rule, not only come before it.

Co-authored-by: Elrond <28d6302a099e5225b02c4155ac4236e4912603df2ab08dbfc2f4fef08ce598c8@buzz.block.builderlab.xyz>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Luke Tornquist <tornquist@squareup.com>
Main now has 0095 for the roster trigger drop (#8696). Move this drop to
0096 and name 0096 in the chart's required-stop note.

Co-authored-by: Elrond <28d6302a099e5225b02c4155ac4236e4912603df2ab08dbfc2f4fef08ce598c8@buzz.block.builderlab.xyz>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Luke Tornquist <tornquist@squareup.com>
@TheSentinel454
TheSentinel454 force-pushed the elrond/drop-single-table-guards branch from c8bc061 to 7bda1f4 Compare November 17, 2026 21:59
@github-actions github-actions Bot removed the codex-security-review-current The posted Codex security review matches its recorded range. label Nov 17, 2026
@github-actions github-actions Bot added the codex-security-review-current The posted Codex security review matches its recorded range. label Nov 17, 2026
@TheSentinel454
TheSentinel454 enabled auto-merge (squash) November 17, 2026 22:04
@TheSentinel454
TheSentinel454 merged commit 3876720 into main Nov 17, 2026
93 checks passed
@TheSentinel454
TheSentinel454 deleted the elrond/drop-single-table-guards branch November 17, 2026 22:30
wpfleger96 added a commit that referenced this pull request Nov 18, 2026
…c-spec-mobile

* origin/main: (37 commits)
  buzz-db: drop the five single-table guard triggers (BUZZ-318 phase 2) (#9398)
  push-gateway: lock expired installations before reaping (#9627)
  Retire the 0032 roster trigger in migration 0095 (#8696)
  fix(db): hard-delete superseded relay-signed lists (#9586)
  Add community-scoped user and agent profile cleanup (#9580)
  fix(sdk): timestamp channel messages with millisecond offsets (#9548)
  Check product_feedback's community in the writing transaction (#9608)
  buzz-db: stop calling the dropped lock-key function in SQL (#9615)
  Clean up account records and refresh member lists (#9364)
  perf(mobile): save own thread interest once per unread catch-up (#9614)
  buzz-db: fix main (renumber the function drop to 0094, update_channel test call) (#9616)
  feat(relay): name the agent whose add policy refuses a DM (#9601)
  buzz-db: drop the community_deletion_lock_key and profile_name_fields functions (contract) (#9598)
  fix(deps): clear chrono, humantime and zip advisories from the dependency policy (#9609)
  docs: define mobile diagnostic reporting (#9600)
  build(mobile): link iOS plugins through Swift Package Manager (#9597)
  feat(push-gateway): enroll Android installations and send FCM wakes (#9560)
  perf(mobile): cache and animate custom emoji in the iOS picker (#9479)
  fix(ios): end each bold or strikethrough run at its first closing marker (#9559)
  Apply the private-to-open rule in update_channel too (#9581)
  ...

Signed-off-by: Will Pfleger <wpfleger@block.xyz>
wpfleger96 added a commit that referenced this pull request Nov 18, 2026
…e-recovery

* origin/main:
  feat(cli)!: consistent channels list/get/search output (type, visibility, labels, real created_at) (#9617)
  ci(docker): publish the push gateway only when its inputs change (#9658)
  feat(mobile): reply to a message from its iOS notification (#9439)
  fix(mobile): stop reporting saved images as failed on iOS (#9599)
  perf(db): stop per-id planning of wide #e reads (#9591)
  [buzz] fix(ci): link relay image indexes to their source (#9637)
  feat(push-gateway): verify Android Key Attestation (#9562)
  fix(relay): remove an owner's agents with the owner (#9575)
  relay: refuse a reaction or deletion whose h names another channel (#9006)
  buzz-db: drop the five single-table guard triggers (BUZZ-318 phase 2) (#9398)
  push-gateway: lock expired installations before reaping (#9627)
  Retire the 0032 roster trigger in migration 0095 (#8696)
  fix(db): hard-delete superseded relay-signed lists (#9586)
  Add community-scoped user and agent profile cleanup (#9580)
  fix(sdk): timestamp channel messages with millisecond offsets (#9548)
  Check product_feedback's community in the writing transaction (#9608)
  buzz-db: stop calling the dropped lock-key function in SQL (#9615)

Signed-off-by: Will Pfleger <wpfleger@block.xyz>
TheSentinel454 added a commit that referenced this pull request Nov 19, 2026
## Summary

Retire the last foreign key in the push gateway schema:
`push_gateway_delegations.installation_id →
push_gateway_installations(id)`. This follows `docs/database.md` Rule 2
and the relay FK retirement work (#9399, #9404).

- **Gateway migration 0008** drops the constraint.
- **Relay migration 0101** drops the relay's legacy copy (Rule 4:
gateway schema changes go in both).
`schema/tables/public/push_gateway_delegations.sql` loses the inline
`REFERENCES`.

## Required stop

Every gateway and rollback target must run #9627 (`44cdd9fe`) or later
before this merges and deploys. #9627 makes the reaper lock expired
installations before it deletes their delegations. Without the FK, an
older reaper can leave an orphaned delegation. This is step 2 of the
Rule 5 retirement sequence; #9627 is step 1.

## Why the app already enforces the reference

| Path | Check |
|---|---|
| `upsert_delegation` (only delegation insert) | Locks the installation
`FOR UPDATE` in the same transaction; rejects a missing or revoked one.
|
| `create_installation` (replaces expired installations) | Locks the
matching installations `FOR UPDATE`, deletes their delegations, then the
installations. |
| `reap_expired` | Locks expired installations `FOR UPDATE`, deletes
their delegations, then the installations (#9627). |
| `authorize_delivery` | Reads the installation through the delegation;
a missing installation is `Rejected`. |
| `revoke_delegation` | Updates the delegation only; an orphan has no
effect. |
| `revoke_installation`, `rotate_endpoint`, `advance_assertion_counter`
| Update the installation; they never delete it. |

The relay never reads or writes the `push_gateway_*` tables (the gateway
requires its own database), so dropping the relay copy changes no relay
behavior.

## Tests

The gateway tests run against the migrated schema, which no longer has
the FK, so they prove the app check.

- `migrated_schema_has_no_foreign_keys` (new): the gateway schema has no
foreign keys after migrations. It fails if gateway migration 0008 is
removed.
- `delegation_for_missing_installation_is_rejected` and
`reaper_deletes_delegation_committed_while_it_waits` (from #9627) now
run without the FK.
- `reaper_retains_revocation_tombstones_until_authority_expiry`: its
hand-built schema drops the FK too.
- Relay: `push_gateway_delegations` joins the constraint parity check in
`admin_schema_parity_between_desired_state_and_migrations`, and the
migration count test covers 0101.

## Validation

Blox at `33f7df90` (before the rename to 0101; CI covers the rebased
head):

- `cargo fmt --check`, clippy (`buzz-push-gateway`, `buzz-db`, all
targets), gateway unit tests, `buzz-db` migration unit tests: pass.
- `scripts/postgres-test-run.sh -p buzz-push-gateway --lib --tests`:
16/16 pass.
- `buzz-db` Postgres tests for migrations, parity, push, floor
retirement and retained guards: 56/56 pass, including
`admin_schema_parity_between_desired_state_and_migrations`.
- Must-fail check: with gateway migration 0008 removed,
`migrated_schema_has_no_foreign_keys` fails (1 foreign key vs 0).

## Coordination

- On main after #8696, #9398 and #9710 (relay 0095–0100). #9627 shipped
this PR's reaper fix and tests separately, so this PR is the schema drop
only.
- Renumbered to relay 0101 after #9710 took 0098–0100 (rename only; file
contents unchanged). #9690 and #9621 also add a relay 0098; whichever
merges second renumbers.
- #8328 adds the gateway's declarative schema with the inline FK.
Whichever PR merges second removes it there.

## What got simpler

One fewer database object. Every gateway reference check now lives in
one place: the gateway's own transactions.

buzz-review-completed

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Signed-off-by: Luke Tornquist <tornquist@squareup.com>
Co-authored-by: Elrond <28d6302a099e5225b02c4155ac4236e4912603df2ab08dbfc2f4fef08ce598c8@buzz.block.builderlab.xyz>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

This branch was previously deployed

1 inactive deployment
codex-review — 7bda1f45 Deployed Nov 17, 2026 by TheSentinel454 via Run Codex Security Review #15847
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

codex-security-review-current The posted Codex security review matches its recorded range.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants