Skip to content

Add terminal sync cancellation - #27

Draft
tszymczyszyn-shopify wants to merge 1 commit into
mainfrom
ae-task-166-implement-libsql-cooperative-terminal-sy
Draft

Add terminal sync cancellation#27
tszymczyszyn-shopify wants to merge 1 commit into
mainfrom
ae-task-166-implement-libsql-cooperative-terminal-sy

Conversation

@tszymczyszyn-shopify

@tszymczyszyn-shopify tszymczyszyn-shopify commented May 26, 2026

Copy link
Copy Markdown

Summary

POS terminal cleanup needs a way to stop an in-flight v1 remote-replica sync without dropping the future and racing local replica deletion against libsql cleanup. This adds a cooperative cancellation path that returns through libsql's normal rollback and settlement flow.

Approach

  • Track the active foreground sync with a per-sync cancellation token stored outside the replicator mutex.
  • Thread cancellation through the replication state machine, remote waits, snapshot streaming, and SQLite injection.
  • Interrupt and then join blocking SQLite injection work before returning cancellation.
  • Preserve underlying injector errors that race with cancellation unless they are the expected SQLite interrupt/cancellation path.
  • Re-check cancellation after successful injection/commit and before frame/snapshot loops return success, so terminal cancellation is not swallowed when SQLite finishes at the same time.
  • Expose Database::cancel_current_sync_for_shutdown() for terminal shutdown callers.
  • Treat shutdown cancellation as a retryable server replica event for the legacy libsql-server background replicator.
  • Keep extension-test dependency resolution compatible with the Rust 1.85 CI toolchain.
  • Add coverage for active public API cancellation, frame-fetch cancellation, snapshot request/pending/stream cancellation, injection rollback, and real SqliteInjector cancellation-await behavior.

CI follow-up

  • Added tokio-util to the libsql replication feature so cargo udeps --manifest-path libsql/Cargo.toml --no-default-features --features replication can resolve the cancellation token dependency.
  • Handled SyncCancelledForShutdown in the libsql-server replica loop to keep the new replicator error exhaustive in server builds.
  • Pinned the standalone extension-test suite's transitive URL/idna dependency family to Rust 1.85-compatible releases after crates.io updates made fresh resolution select Rust 1.86+ crates.

Validation

  • cargo fmt --all --check
  • cargo check -p libsql_replication -p libsql --features replication
  • cargo check -p libsql --no-default-features --features replication
  • cargo check -p libsql-server
  • cargo test -p libsql_replication cancellation_
  • cargo test -p libsql_replication replicator
  • cargo test -p libsql_replication sqlite_injector
  • cargo test -p libsql_replication
  • cargo test -p libsql --features replication cancel_current_sync_for_shutdown
  • cargo test -p libsql --features replication
  • (cd libsql-sqlite3/test/rust_suite && CMAKE_POLICY_VERSION_MINIMUM=3.5 cargo +1.85.0 test --features=extensions extensions --no-run)
  • cargo clippy -p libsql_replication --tests --no-deps -- -D warnings -A clippy::needless-lifetimes -A clippy::suspicious-open-options -A clippy::nonminimal-bool

Strict cargo clippy -p libsql_replication --tests -- -D warnings and cargo clippy -p libsql --features replication --tests -- -D warnings remain blocked by pre-existing clippy warnings in libsql, libsql-ffi, and vendored code unrelated to this patch.

Co-authored-by: Claude noreply@anthropic.com
Orchestrated-by: ae noreply@shopify.com

@tszymczyszyn-shopify tszymczyszyn-shopify added the #gsd:48518 GSD project 48518 label May 26, 2026
@tszymczyszyn-shopify
tszymczyszyn-shopify force-pushed the ae-task-166-implement-libsql-cooperative-terminal-sy branch 2 times, most recently from cd656fa to d84cef2 Compare May 27, 2026 08:34
## Summary

POS terminal cleanup needs a way to stop an in-flight v1 remote-replica sync without dropping the future and racing local replica deletion against libsql cleanup. Add a cooperative cancellation path that returns through libsql's normal rollback and settlement flow.

## Approach

- Track the active foreground sync with a per-sync cancellation token stored outside the replicator mutex.
- Thread cancellation through the replication state machine, remote waits, snapshot streaming, and SQLite injection.
- Interrupt and then join blocking SQLite injection work before returning cancellation.
- Expose Database::cancel_current_sync_for_shutdown() for terminal shutdown callers and add coverage for cancellation rollback and the no-active-sync API case.

Co-authored-by: Claude <noreply@anthropic.com>
Orchestrated-by: ae <noreply@shopify.com>
@tszymczyszyn-shopify
tszymczyszyn-shopify force-pushed the ae-task-166-implement-libsql-cooperative-terminal-sy branch from d84cef2 to ce82c96 Compare May 27, 2026 08:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

#gsd:48518 GSD project 48518

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant