Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: sqliteai/sqlite-sync
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 1.1.4
Choose a base ref
...
head repository: sqliteai/sqlite-sync
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 1.2.0
Choose a head ref
  • 10 commits
  • 37 files changed
  • 4 contributors

Commits on Sep 22, 2026

  1. fix(sqlite): roll back a payload apply whose commit fails (#65)

    When cloudsync_payload_apply opened the transaction itself and its commit
    then failed (a deferred foreign key violated at commit, or SQLITE_BUSY on
    commit), the transaction stayed open. The uncommitted rows remained
    visible on the connection, the next BEGIN failed, and later writes on
    that connection silently joined a transaction that could not commit.
    
    Apply now sends every error through a single cleanup path. That path
    rolls back the transaction only when apply started it from autocommit
    mode, keeps the original error and SQLSTATE, and no longer counts
    rolled-back rows as applied. Groups already committed for earlier
    source versions are kept, and the receive checkpoint does not move, so
    redelivery applies the payload. A transaction or savepoint opened by the
    caller is left to the caller. A group savepoint that fails to open now
    stops the apply instead of writing without a rollback point, and
    database_pk_names no longer leaks its names array when the second
    schema scan fails.
    
    PostgreSQL does not need the rollback, since apply never owns the
    transaction there. The new test 62 pins that down: a deferred foreign key
    fails the caller's COMMIT with 23503 and rolls everything back together,
    and a failure inside a caller savepoint leaves the transaction usable
    for redelivery.
    
    An allocation failure mid-apply can still leave the transaction open,
    because SQLite refuses the cleanup ROLLBACK inside the running SQL
    function. This is tracked in #74; test/stress/payload_oom.c reproduces it.
    
    CI reliability:
    - Serialize the job that uses the shared chunked test tenant across
      branches.
    - Bootstrap syncs wait for the expected data with bounded polling; the
      offline integration_bootstrap test now runs in make unittest.
    - The chunked rowset and paths e2e tests fail on receive.error and report
      what arrived on timeout. They now allow 120 polls, because a fresh
      receiver first downloads the whole tenant history (~113k rows, ~25s).
    marcobambini authored Sep 22, 2026
    Configuration menu
    Copy the full SHA
    4534c21 View commit details
    Browse the repository at this point in the history
  2. fix(postgres): restore savepoint callers at any nesting depth (#66)

    Applying a payload read from a table inside 126 or more savepoints
    failed with "buffer pin ... is not owned by resource owner
    SubTransaction", and a caught error at that depth could abort an
    assertion-enabled server. cloudsync recorded the caller's resource
    owner and memory context in fixed 128-entry arrays indexed by nesting
    level. Its own internal savepoints count toward that depth, so past
    the array the record was silently skipped and never restored.
    
    Replace the arrays with a stack of frames allocated in
    TopTransactionContext, one per cloudsync subtransaction and keyed by
    subtransaction ID. Commit and rollback copy the frame before ending the
    subtransaction, then restore the caller's owner and context from the
    copy. Subtransaction callbacks pop a frame when its subtransaction
    commits or aborts, including aborts outside the wrappers, and a
    transaction callback clears the stack. The frame is allocated before
    the subtransaction opens, and only the outermost cloudsync savepoint
    still replaces the caller's snapshot. PostgreSQL's own resource limits
    still apply, but cloudsync no longer imposes a fixed depth cap.
    
    Test 63 applies from a heap scan at depths 1 through 2048, checks
    rollback, reapplies and commits, and recovers from 100 caught trigger
    errors at depth 256. A failed apply is reported as [FAIL] with its
    SQLSTATE instead of stopping full_test.sql. Against the old code it
    fails from depth 126 up.
    marcobambini authored Sep 22, 2026
    Configuration menu
    Copy the full SHA
    b195a31 View commit details
    Browse the repository at this point in the history
  3. fix(apply): keep a block column's row group atomic (#67)

    A received row carrying both ordinary and block columns could be applied
    in part. Writing a block column needs the row's ordinary columns in
    place, so the apply flushed them first — but that flush also closed the
    row's group savepoint. A block write that then failed (a trigger that
    raises, a constraint, a policy) left the ordinary columns and their sync
    metadata applied, with the block value missing or stale.
    
    The pre-block flush now writes the pending ordinary columns without
    closing the savepoint, which stays open until the real PK, table or
    source-version boundary. A failed block write therefore rolls back the
    whole row: ordinary columns, metadata, blocks and any resurrection
    changes. The receive checkpoint does not move, and delivering the
    payload again applies the row once the cause is fixed. Rows rolled back
    this way are no longer counted as applied.
    
    The audit regression covers 120 forced-failure cases: inserts, updates
    and resurrections, 3 to 10 blocks, rejection of the first, a middle and
    the last block, in autocommit and inside a caller's transaction. Each
    case compares data, metadata and blocks against their state before the
    apply, checks the checkpoint and the caller's transaction, then retries
    and replays. Against the old flush it fails 360 assertions.
    marcobambini authored Sep 22, 2026
    Configuration menu
    Copy the full SHA
    983853a View commit details
    Browse the repository at this point in the history
  4. fix(block): keep block metadata live when a row is rewritten in place (…

    …#46)
    
    Rewriting a row that holds a block column without changing its primary
    key — INSERT OR REPLACE, or any write that rewrites the same block
    positions — marked every rewritten block as deleted in the sync
    metadata, while its content stayed stored locally. The local row still
    read correctly, so nothing looked wrong, but peers received the blocks
    as deletions and dropped the row. The same flip could resurrect a row's
    deletion marker.
    
    The metadata upsert bumped col_version by 1 on conflict, and that
    version's parity is what records liveness: odd is live, even is a
    tombstone. Every rewrite therefore flipped the state, and only an even
    number of them ended up back where it started. On conflict the statement
    now adds 2 when the stored parity already matches the parity being
    written and 1 otherwise, so the row keeps the state its caller asked for
    while the version still increases. The same parity-preserving form was
    already used by the neighbouring bump statements.
    
    Tests: a SQL-only regression that replaces a synced row with INSERT OR
    REPLACE and checks the peer receives the new content, plus direct
    coverage of the metadata helpers for a repeated live mark and a repeated
    tombstone, and a multi-cycle delete/resurrect guard. All three parity
    tests fail against the previous statement.
    
    Also bind the debug PostgreSQL container to all interfaces, so psql
    reaches it from the host after a debug rebuild.
    andinux authored Sep 22, 2026
    Configuration menu
    Copy the full SHA
    20728c3 View commit details
    Browse the repository at this point in the history
  5. fix(block): retire the blocks a whole-row write leaves behind (#68)

    Deleting a row keeps the values of its block columns; only their
    metadata goes away. Writing the row again rewrites the column from its
    first position, so every block past the end of the new value stayed
    stored. On SQLite INSERT OR REPLACE also skips the old row's delete
    trigger while recursive_triggers is off, so those leftovers kept their
    live metadata and were delivered as content: replacing AAA\nBBB\nCCC
    with ZZZ left ZZZ\nBBB\nCCC on the peers and on a later local read. On
    PostgreSQL they carried no metadata, so peers were unaffected, but they
    stayed in the blocks table for the life of the row.
    
    local_block_update now reads the column's stored blocks on that path
    too. They stay out of the diff, since a whole-row write is not an edit
    of the previous value and positions are still assigned as before, and
    whatever the new value does not rewrite is tombstoned and its value
    removed. A failure there is reported like any other block write, so the
    enclosing statement rolls back instead of committing half a column. The
    parity-preserving metadata upsert from #46 is required, because the
    rewritten positions land on rows a previous write tombstoned.
    
    Tests: 120 replacement cycles with recursive triggers off and on, over
    shorter, longer, empty, NULL, duplicate-line and trailing-delimiter
    values, with fractional positions, duplicate delivery and an injected
    write failure; and test 64 on PostgreSQL, where a row recreated with
    fewer blocks and an upsert of the whole row must leave one stored block
    and deliver the shorter value to a peer. Both fail against the previous
    code.
    marcobambini authored Sep 22, 2026
    Configuration menu
    Copy the full SHA
    cf44ad0 View commit details
    Browse the repository at this point in the history

Commits on Sep 23, 2026

  1. fix(sqlite): seek to the positional resume point instead of replaying (…

    …#75)
    
    The positional cursor on cloudsync_payload_chunks stated its resume lower
    bound only inside (db_version>? OR (db_version=? AND seq>=?)). SQLite derives
    a range from a disjunction only when both arms compare against the same value,
    and these two arms carry distinct parameters, so it derived nothing:
    cloudsync_changes' xBestIndex got an upper bound and a site filter with
    nothing saying where to start. Every call re-read the window from the
    beginning, evaluating cloudsync_col_value() on each discarded row, making a
    full drain quadratic in the number of chunks. In production this stretched one
    tenant's change export to ~25 minutes.
    
    State db_version>=? explicitly alongside the disjunction. It is logically
    implied, so the same rows are selected; it exists so the constraint loop emits
    a lower bound and the (db_version) index can seek.
    
    On a ~1 GB window at the 5 MiB default chunk size (194 chunks), the drain goes
    from 186,058 ms to 6,115 ms, and per-chunk cost from 959 ms rising with
    position to 31.5 ms flat. The multiplier scales with window size, so the
    result to rely on is that per-chunk cost no longer depends on the window at
    all: O(N^2) -> O(N).
    
    PostgreSQL was never affected: it writes the same disjunction with $3 in both
    arms, and its planner handles OR'd range bounds natively.
    
    Adds test/chunk_bench.c and a chunk-bench target, which times a real drain per
    chunk index and replays the same resume points in the old and fixed spellings,
    asserting both select the identical row. CI builds it but never runs it.
    
    Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
    andinux and claude authored Sep 23, 2026
    Configuration menu
    Copy the full SHA
    b75146e View commit details
    Browse the repository at this point in the history

Commits on Sep 24, 2026

  1. fix(postgres): give every transaction its own db_version and restart …

    …seq (#78)
    
    * fix(postgres): give every transaction its own db_version and restart seq
    
    With more than one synced table, the query that reloads the cached
    db_version returned one row per meta table and only the first was read,
    so consecutive transactions writing another table shared one db_version.
    Wrap it in MAX() and include pre_alter_dbversion, as on SQLite.
    
    Close each transaction from a PostgreSQL transaction callback, as the
    SQLite commit/rollback hooks do: seq restarts at 0 and the next
    transaction takes a new db_version even while another session pins xmin.
    
    Inside one transaction, cloudsync_payload_apply now closes the local
    db_version at every source db_version boundary, so remote versions no
    longer collapse into duplicate (db_version, seq) pairs.
    
    Fixes #69
    
    Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
    
    * fix: keep an applied payload's db_versions apart from local writes
    
    Closing a payload group inside a transaction reused the commit hook,
    which copied an uncommitted version into the committed cache: a local
    write after the apply reused the last merged db_version with seq back
    at 0, and a rolled back apply left the cache ahead of the tables.
    
    A group now only marks the pending version closed, so the next change
    takes pending + 1 while the committed version stays untouched. The
    apply also closes it after the last group and around each fragment
    value.
    
    Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
    
    ---------
    
    Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
    andinux and claude authored Sep 24, 2026
    Configuration menu
    Copy the full SHA
    0c20064 View commit details
    Browse the repository at this point in the history

Commits on Sep 25, 2026

  1. feat(send): bound a send to a number of local database versions (#76)

    cloudsync_network_send_changes() sent the whole backlog as one batch. A send is
    all or nothing -- the server confirms the window only once every chunk has
    applied, and a failed batch is re-sent whole under a new id -- so after a long
    offline period or a bulk import that batch can be large enough to keep failing,
    re-uploading everything each attempt.
    
    The new 1-argument form sends at most that many local database versions, so the
    upload becomes several independently confirmed batches and a failure costs one
    bounded window instead of the backlog. The 0-argument form is unchanged, and
    cloudsync_network_sync() still calls the unbounded path.
    
    The argument counts local versions rather than naming an upper bound. db_version
    is shared with merges, so the local backlog is sparse in that space: a bound
    picked without knowing which versions hold local changes can cover a range with
    none of them, making no progress and giving the caller no way to know how much
    further to go. Counting keeps the window non-empty whenever anything is pending.
    
    A bounded call also reports the newest local version as send.localVersion, so
    send.status stays out-of-sync while changes remain past the window. Both that
    value and the window bound come from one pass over the metadata tables: local
    rows carry site_id 0 there and db_version > since seeks the (db_version) index,
    so the cost follows the pending backlog. Reading them from cloudsync_changes
    instead would hit its site_id-only plan, a full scan that materialises every
    value through cloudsync_col_value().
    
    Nothing advances the send checkpoint past a window that was never announced:
    later local writes are numbered below such a checkpoint and would be stranded,
    and the server builds its coverage from announced batches, so the skipped range
    would stay a permanent gap.
    
    Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
    andinux and claude authored Sep 25, 2026
    Configuration menu
    Copy the full SHA
    9c56e9a View commit details
    Browse the repository at this point in the history

Commits on Sep 28, 2026

  1. feat: bound what one cloudsync_payload_chunks() call prepares (#77)

    A single cloudsync_payload_chunks() call drained the whole window, so a large
    backlog produced one unbounded run of work -- the shape behind the prepare
    stall, where a job kept reaching its deadline before it finished.
    
    Two optional arguments now bound it, declared last so the existing positional
    arguments 1..7 keep their meaning:
    
      * max_window_bytes caps the uncompressed bytes one call prepares
      * resume_window_bytes carries the budget spent so far, for a stream fetched
        one chunk per call
    
    and two outputs report the outcome: window_capped, true when the scan stopped
    on the budget rather than because the window was drained, and window_bytes, the
    budget spent. Without max_window_bytes the function behaves exactly as before.
    
    A capped call always stops on a db_version boundary, so the receive checkpoint
    stays on a complete version, and fragment payloads count toward the budget.
    Continuation is the caller's job: nothing loops automatically, and the API docs
    qualify what receive.complete=true actually means (#83).
    
    Ships as 1.2.0, with the PostgreSQL migration cloudsync--1.1--1.2.sql. The
    migration drops the old 7-argument function before creating the new one:
    CREATE OR REPLACE cannot change a return type, and a defaulted new parameter
    would leave every 7-argument call ambiguous.
    
    Also pulls the Supabase base image from Docker Hub rather than public.ecr.aws.
    Both tags resolve to the same manifest digest, and CI already authenticates to
    Docker Hub, so the supabase image jobs stop failing on the shared anonymous
    ECR Public data quota.
    
    🤖 Generated with [Claude Code](https://claude.com/claude-code)
    andinux authored Sep 28, 2026
    Configuration menu
    Copy the full SHA
    35c0f50 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    285a139 View commit details
    Browse the repository at this point in the history
Loading