fix(postgres): commit authorized local writes optimistically#196
Open
marcus-pousette wants to merge 3 commits into
Open
fix(postgres): commit authorized local writes optimistically#196marcus-pousette wants to merge 3 commits into
marcus-pousette wants to merge 3 commits into
Conversation
2b4b0a8 to
ea21857
Compare
b19e907 to
e8e4ff9
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The PostgreSQL N-API client prepared a local operation inside a transaction and kept the document row lock while JavaScript authorization was awaited. A second synchronous write could block the JavaScript thread needed to finish that authorization.
The operation and its standard auth proof also lacked a shared commit boundary.
What changes
Authenticated local writes now use three phases:
NOWAIT, verifies the complete materialization revision, prepares the operation again, and requires an exact match with the authorized proposal.The operation, materialized state, metadata, and standard
treecrdt_sync_op_authproof row then commit atomically. The proof contains only the standard signature and optional proof reference.A real optimistic conflict reparses and reauthorizes a fresh proposal, up to four attempts. Policy, proof, codec, database, and callback failures remain terminal.
The direct path also creates the document revision row when a local write is the first action on a new document.
Why this is one PR
The Rust/native contract and TypeScript retry/auth bridge must land together. The native half alone exposes proposals the old client cannot commit correctly; the client half alone requires APIs and transaction semantics that do not yet exist.
The implementation is separated into commits for review, but it is one atomic merge unit.
Fast paths
localOpProofsretain proofless behavior.Tests
Stack
Stacked on #192. This is the PostgreSQL sibling of the SQLite #193–#195 chain.