go-oversync

Advanced Concepts

This page describes the supported bundle-based sync model.

Authoritative state

Registered business tables are the source of truth. Sync metadata is derived from committed business-table effects rather than projected afterward from a separate authoritative log.

Bundles

A bundle is the smallest durable sync unit.

Structured keys

Rows are identified by structured sync keys, not by an implicit single pk field on the wire. In the current supported envelope, each registered table still exposes exactly one visible sync key column, but that column may be uuid or text. Visible sync key values are strings on the wire, and UUID-valued keys must use canonical dashed lowercase UUID text.

Row state

sync.row_state stores the authoritative per-row replicated state for conflict detection, idempotent replay, and snapshot rebuilds.

Timestamp encoding

For syncable business rows, timestamp columns should be stored as SQLite TEXT using UTC RFC3339 or RFC3339Nano values. This keeps payloads portable across SQLite, JSON transport, and Go resolver code.

Canonical JSON and numeric columns

Canonical protocol bytes use RFC 8785 JCS. Oversync does not extend JCS with arbitrary-precision JSON numbers. Instead, schema discovery and client numericColumns metadata define the wire type:

Exact strings are rejected before business or SQLite mutation if their grammar, range, or declared affinity is unsupported. bundle_hash authenticates server-committed rows. The separately stored canonical_request_hash proves that an ambiguous already_committed response belongs to the client’s frozen original request even when legitimate server mutation changed committed payloads.

Push

Push is all-or-nothing at bundle level.

Structured conflict recovery

The supported client/runtime contract includes structured push_conflict recovery.

Administrative reset and TRUNCATE protection

Oversync does not provide an in-place migration, canonicalization fallback, hash-version negotiation, compatibility alias, or mixed-version mode for incompatible database state. To reset a deployment, stop all server and client processes, recreate PostgreSQL and every Oversqlite client database, deploy compatible versions together, and reinitialize from authoritative business data. This procedure discards bundle history, staged sessions, outboxes, checkpoints, hashes, retry state, and offline work.

TRUNCATE fails closed on registered tables and current partitions. A rejection uses SQLSTATE 55000 and preserves business rows, row state, bundles, hashes, source watermarks, pull, and snapshots. Normal runtime has no reset endpoint. Privileged trigger disabling and later managed-table DDL remain unsupported administrative risks.

The sync schema is reserved for Oversync, and startup validates its complete semantic layout instead of trusting marker rows alone. A healthy restart performs no managed DDL. Drift returns a typed managed sync layout mismatch and is never repaired silently. Keep all server instances stopped while restoring the exact object, then retry; if exact repair is unsafe, use the coordinated server/client recreation procedure above. Do not mix versions during diagnosis or repair. These startup checks do not change wire messages, checkpoints, snapshots, bundles, or client local state.

Pull

Pull is frozen to a stable ceiling.

Snapshot rebuilds

Chunked snapshot sessions return the full current after-image at one exact frozen bundle sequence.

Use it for:

Clients durably set the rebuild gate before authoritative checkpoint recovery. Normal sync resumes that recovery automatically after restart. Pending local work is frozen and uploaded first when it can be reconciled safely; otherwise recovery returns an actionable blocker and preserves the app row, outbox, checkpoint, and rebuild gate. The checkpoint changes only in the final atomic snapshot apply. Rebuild remains an optional explicit control, not a required resume step.

When rebuild requires source rotation:

Fail-closed contract

The supported envelope is intentionally strict.

Supported envelope

The current contract is designed to be reliable for:

Unsupported shapes must fail at bootstrap rather than degrade into partial runtime behavior.