mirror of
https://github.com/block/buzz.git
synced 2026-11-28 12:12:04 +00:00
Three correctness fixes for the Phase A PR 4 pass-2 review findings.
## Fix 3: post-lock DB time sample
db_now is now sampled from clock_timestamp() inside commit_admission_body
and authorize_protected_use_body AFTER both advisory locks are acquired
(steps 3 and 3b), not before the transaction opens.
Previously transaction_timestamp() was sampled pre-lock in commit_kind9_inner
and passed through the call chain. A proof that was valid at tx-open but
expired before the lock was acquired could pass the deadline check on a slow
server. With clock_timestamp() post-lock, every deadline check (proof expiry,
policy dates, upstream assertion deadline, binding expiry) is made against a
time provably concurrent with the lock-held authoritative reads.
Removes db_now from commit_admission_in_tx, commit_admission_body,
authorize_protected_use_in_tx, and authorize_protected_use_body signatures.
## Fix 4: deterministic protected-use operation ID
Adds NS_PROTECTED_USE_OP namespace constant and
deterministic_protected_use_op_id(community_id, proof_event_id, signed_event_id)
to admission.rs. The re-fence receipt now uses this deterministic ID instead
of Uuid::new_v4(), making the receipt insert idempotent on retry.
Adds signed_event_id field to CommittedAuthorization so authorize_protected_use_body
can bind the use-operation ID to the exact signed event. Includes signed_event_id
in the use-request fingerprint hash for complete binding.
## Fix 8: three additional test witnesses
(a) orchestrator_pg_on_conflict_do_nothing_zero_row_same_conn: exercises the
step-13 ON CONFLICT DO NOTHING zero-row path explicitly. Same-conn reuse
with a pre-existing claim row → rows_affected() == 0 → function continues.
(b) orchestrator_pg_fresh_proof_duplicate_event_no_new_rows: fresh proof_event_id
with an already-persisted signed event → step 3c fires → DuplicateEvent.
Verifies receipt, admission-result, and replay-claim counts are all unchanged.
(c) orchestrator_pg_deterministic_op_id_mutation_evidence: shows that the
exact-replay-is-noop property (deterministic op_id idempotence) would break
under a UUID-v4 mutation by asserting the receipt count does not change on
replay. The assertion names the mutation explicitly so a red test identifies
the broken invariant.
Also fixes DbError → sqlx::Error conversion in the late-conflict reread async
block (begin_transaction() returns DbError, not sqlx::Error).
Co-authored-by: Will Pfleger <pfleger.will@gmail.com>
Signed-off-by: Will Pfleger <pfleger.will@gmail.com>