Skip to content

fix(sqlite): add an optimistic local commit protocol#193

Open
marcus-pousette wants to merge 1 commit into
fix/auth-stage-verified-proofsfrom
fix/sqlite-optimistic-local-commit
Open

fix(sqlite): add an optimistic local commit protocol#193
marcus-pousette wants to merge 1 commit into
fix/auth-stage-verified-proofsfrom
fix/sqlite-optimistic-local-commit

Conversation

@marcus-pousette

@marcus-pousette marcus-pousette commented Jul 11, 2026

Copy link
Copy Markdown
Collaborator

Problem

SQLite authorization is asynchronous. Holding a savepoint while application auth runs can let unrelated same-connection work enter that savepoint and be rolled back by an auth rejection.

What changes

The native local-write functions expose two paths:

  1. Immediate commit for unauthenticated writes.
  2. Read-only prepare followed by a short optimistic commit for authenticated writes.

Prepare returns the exact proposal and a token bound to the document, clean materialization revision, and complete operation body. Commit takes the writer lock, rebuilds the operation, and returns an explicit conflict if state changed or the lock is busy.

The native layer rejects optimistic use inside a caller-owned transaction and rolls back every post-savepoint failure.

Fast paths

  • Unauthenticated writes remain one direct SQL/UDF call.
  • No transaction or lock is held while authorization runs.
  • Hashing, retries, and the extra SQL round trip exist only on the authenticated path.

Tests

  • prepare is read-only
  • fresh prepare commits the exact proposal
  • stale revision and WAL contention return conflicts
  • caller-owned transactions are rejected
  • rollback failures do not leak transaction state
  • immediate writes retain the direct path

Stack

Stacked on #192. #194 adds the mandatory proof-bearing commit and #195 adds the TypeScript retry bridge.

@marcus-pousette marcus-pousette added bug Something isn't working area:sqlite SQLite extension, sqlite-node, wa-sqlite persistence, and migrations area:auth Authorization, capabilities, proofs, signatures, crypto, and privacy labels Jul 12, 2026
@marcus-pousette
marcus-pousette force-pushed the fix/auth-stage-verified-proofs branch from 2b4b0a8 to ea21857 Compare July 12, 2026 12:34
@marcus-pousette
marcus-pousette force-pushed the fix/sqlite-optimistic-local-commit branch from 416b21e to 644b31d Compare July 12, 2026 12:44
@marcus-pousette
marcus-pousette force-pushed the fix/auth-stage-verified-proofs branch from ea21857 to 9122bce Compare July 13, 2026 14:07
@marcus-pousette
marcus-pousette force-pushed the fix/sqlite-optimistic-local-commit branch from 644b31d to 32bb026 Compare July 13, 2026 14:07
@marcus-pousette
marcus-pousette force-pushed the fix/auth-stage-verified-proofs branch from 9122bce to e4e2f30 Compare July 13, 2026 14:12
@marcus-pousette
marcus-pousette force-pushed the fix/sqlite-optimistic-local-commit branch from 32bb026 to fd77168 Compare July 13, 2026 14:12
@marcus-pousette
marcus-pousette force-pushed the fix/auth-stage-verified-proofs branch from e4e2f30 to e4c5386 Compare July 13, 2026 15:14
@marcus-pousette
marcus-pousette force-pushed the fix/sqlite-optimistic-local-commit branch from fd77168 to 729a743 Compare July 13, 2026 15:14
@marcus-pousette
marcus-pousette force-pushed the fix/auth-stage-verified-proofs branch from e4c5386 to 54dab36 Compare July 13, 2026 15:22
@marcus-pousette
marcus-pousette force-pushed the fix/sqlite-optimistic-local-commit branch 2 times, most recently from 0e2e6e4 to f50f698 Compare July 13, 2026 15:30
@marcus-pousette
marcus-pousette force-pushed the fix/auth-stage-verified-proofs branch from 54dab36 to 56bb9bb Compare July 13, 2026 15:30
@marcus-pousette
marcus-pousette force-pushed the fix/auth-stage-verified-proofs branch from 56bb9bb to c911521 Compare July 13, 2026 15:51
@marcus-pousette
marcus-pousette force-pushed the fix/sqlite-optimistic-local-commit branch from f50f698 to afa49f6 Compare July 13, 2026 15:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:auth Authorization, capabilities, proofs, signatures, crypto, and privacy area:sqlite SQLite extension, sqlite-node, wa-sqlite persistence, and migrations bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant