Skip to content

Commit 6b15cb4

Browse files
author
Hayt
committed
Merge remote-tracking branch 'origin/main' into hayt/nip-fi-stateless-enforcement
* origin/main: Automate owner deletion preparation (#7830) Signed-off-by: Hayt <211b96e6a2b7f45fd4047988976c7bbbeeda0c15f3ae7b32eec20834b5a55118@buzz.block.builderlab.xyz>
2 parents aa58414 + bba75a7 commit 6b15cb4

8 files changed

Lines changed: 1672 additions & 62 deletions

File tree

‎ARCHITECTURE.md‎

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ Deployment-root community management uses operator-signed NIP-98 HTTP requests.
1818
`POST /operator/communities/delete` accepts only an exact normalized, archived
1919
community whose asserted pubkey is still its owner. The caller supplies the
2020
request UUID as the stable correlation/idempotency identity; the durable row
21-
records owner intent, mediating operator, and acknowledgement version. Admission
22-
returns `202` at the `submitted` stage and performs no inventory, approval,
21+
records operator-attested owner intent, mediating operator, and acknowledgement
22+
version. Admission returns `202` at the `submitted` stage and performs no
23+
inventory, approval,
2324
quiescing, object-store access, or deletion execution synchronously. While that
2425
non-aborted request exists, unarchive and ownership transfer conflict and owner
2526
management lists suppress the archived row. Replaying the same UUID converges
@@ -45,6 +46,19 @@ on the row. Owner provenance pins `requested_by` to `owner_pubkey`, so passing
4546
the operator's own pubkey does not converge — it conflicts with the existing
4647
one-active-request invariant instead.
4748

49+
The privileged one-shot `buzz-admin deletions drain` process gives already-
50+
approved work priority. When none is ready, it may claim only an
51+
operator-attested owner-origin `submitted` request under the same durable
52+
generation lease used for execution, inventory it with lease-loss cancellation,
53+
and atomically freeze the inventory plus a digest-bound `owner_automatic`
54+
approval. The mediating operator remains the approval actor; the owner
55+
acknowledgement is pre-inventory
56+
intent, not a claim that the owner reviewed the digest. The retained lease then
57+
enters the unchanged approved-request executor. Operator-origin requests never
58+
auto-progress and still require explicit inventory and approval. Owner
59+
admission still has no owner-facing cancellation or grace period; the
60+
privileged abort described above remains the recovery path.
61+
4862
Ownership is mutable only while a community is active. Archiving freezes the
4963
current owner. Normal transfer and deployment-root legacy convergence take the
5064
same community-row lock as owner-deletion admission, then reject archived,
@@ -762,6 +776,10 @@ Postgres/Redis clients and S3 client; it does not call relay HTTP. Durable
762776
requests, leases, retry timing, and checkpoints in Postgres are the handoff and
763777
execution authority, so Kubernetes uses `Forbid` concurrency and zero Job
764778
retries rather than introducing a second retry system.
779+
The same drain first claims runnable approved work and, only when none exists,
780+
may prepare one owner-origin submission. Inventory, automatic approval, and
781+
execution share one generation lease and the existing retry/block/checkpoint
782+
records; there is no preparation worker, command, queue, or retry authority.
765783
766784
---
767785

‎crates/buzz-db/src/runtime/migration.rs‎

Lines changed: 75 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -705,9 +705,12 @@ mod postgres_tests {
705705
let mut migrations: Vec<_> = MIGRATOR.iter().collect();
706706
migrations.sort_by_key(|migration| migration.version);
707707

708-
assert_eq!(migrations.len(), 52);
708+
assert_eq!(migrations.len(), 53);
709709
assert_eq!(migrations[48].version, 49);
710+
assert_eq!(migrations[49].version, 50);
710711
assert_eq!(migrations[50].version, 51);
712+
assert_eq!(migrations[51].version, 52);
713+
assert_eq!(migrations[52].version, 53);
711714
assert!(migrations[48]
712715
.sql
713716
.as_str()
@@ -716,6 +719,11 @@ mod postgres_tests {
716719
.sql
717720
.as_str()
718721
.contains("community_deletion_owner_provenance"));
722+
assert!(migrations[52].sql.as_str().contains("approval_origin"));
723+
assert!(migrations[52]
724+
.sql
725+
.as_str()
726+
.contains("community_deletion_requests_owner_preparable"));
719727
assert_eq!(migrations[0].version, 1);
720728
assert_eq!(&*migrations[0].description, "initial schema");
721729
assert!(migrations[0]
@@ -1722,6 +1730,34 @@ mod postgres_tests {
17221730
);
17231731
}
17241732

1733+
#[test]
1734+
fn owner_deletion_auto_approval_migration_matches_desired_schema() {
1735+
let migration = MIGRATOR
1736+
.iter()
1737+
.find(|migration| migration.version == 53)
1738+
.expect("embedded migration 0053")
1739+
.sql
1740+
.as_ref()
1741+
.to_ascii_lowercase();
1742+
let workspace_root = std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
1743+
.parent()
1744+
.and_then(std::path::Path::parent)
1745+
.expect("workspace root");
1746+
let schema = std::fs::read_to_string(workspace_root.join("schema/schema.sql"))
1747+
.expect("read schema/schema.sql")
1748+
.to_ascii_lowercase();
1749+
1750+
for sql in [&migration, &schema] {
1751+
assert!(sql.contains("approval_origin text not null default 'operator'"));
1752+
assert!(sql.contains("approval_origin in ('operator', 'owner_automatic')"));
1753+
assert!(sql.contains("'submitted', 'approved', 'fenced'"));
1754+
assert!(sql.contains("community_deletion_requests_owner_preparable"));
1755+
assert!(sql.contains("request_origin = 'owner'"));
1756+
assert!(sql.contains("stage = 'submitted'"));
1757+
}
1758+
assert!(migration.contains("set local lock_timeout = '5s'"));
1759+
}
1760+
17251761
/// Structural parity between migration 0029's deletion surface and the
17261762
/// desired-state bootstrap schema (`schema/schema.sql`).
17271763
///
@@ -1866,13 +1902,50 @@ mod postgres_tests {
18661902
.tables
18671903
.get(table)
18681904
.unwrap_or_else(|| panic!("schema.sql is missing deletion table {table}"));
1869-
if table != "community_deletion_requests" {
1905+
if table != "community_deletion_requests" && table != "community_deletion_approvals" {
18701906
assert_eq!(
18711907
in_schema, definition,
18721908
"schema.sql definition of {table} drifted from migration 0029"
18731909
);
18741910
}
18751911
}
1912+
let migration_approval_table = migration
1913+
.tables
1914+
.get("community_deletion_approvals")
1915+
.expect("0029 approval table");
1916+
let schema_approval_table = schema
1917+
.tables
1918+
.get("community_deletion_approvals")
1919+
.expect("schema.sql approval table");
1920+
for invariant in [
1921+
"inventory_digest bytea not null check (length(inventory_digest) = 32)",
1922+
"foreign key (request_id, community_id, inventory_digest) references community_deletion_requests(id, community_id, inventory_digest) on delete restrict",
1923+
] {
1924+
assert!(
1925+
migration_approval_table.contains(invariant),
1926+
"0029 deletion approvals are missing {invariant}"
1927+
);
1928+
assert!(
1929+
schema_approval_table.contains(invariant),
1930+
"schema.sql deletion approvals are missing {invariant}"
1931+
);
1932+
}
1933+
let migration_request_table = migration
1934+
.tables
1935+
.get("community_deletion_requests")
1936+
.expect("0029 deletion request table");
1937+
for request_table in [
1938+
migration_request_table,
1939+
schema
1940+
.tables
1941+
.get("community_deletion_requests")
1942+
.expect("schema.sql deletion request table"),
1943+
] {
1944+
assert!(
1945+
request_table.contains("unique (id, community_id, inventory_digest)"),
1946+
"deletion requests must expose the exact composite approval target"
1947+
);
1948+
}
18761949
for (function, definition) in &migration.functions {
18771950
let in_schema = schema
18781951
.functions

‎crates/buzz-db/src/runtime/tests/thread_window_postgres_tests.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ async fn migration_schema_thread_window_prebuild_does_not_queue_behind_writer()
311311
production_result.is_ok(),
312312
"production migrator must preserve ingestion progress: {production_result:?}"
313313
);
314-
assert_eq!(version, 52);
314+
assert_eq!(version, 53);
315315
assert_eq!(final_oid, oid, "prebuild must not be replaced");
316316
assert_eq!(count, 4, "all writer witnesses must persist");
317317
}

0 commit comments

Comments
 (0)