Skip to content

Synchronize database lease and snapshot timing tests - #1195

Merged
jatmn merged 2 commits into
mainfrom
fix/queue-666-inherited-core-fixtures
Dec 5, 2026
Merged

jatmn merged 2 commits into
mainfrom
fix/queue-666-inherited-core-fixtures

Conversation

@jatmn

@jatmn jatmn commented Dec 5, 2026 •

Copy link
Copy Markdown
Owner

Changes

Addresses the core database portion of #666. The original compiler run reported 23 real-clock reads and four sleeps across 12 tests. Lease tests now advance the fixture’s clock and wait for a renewal to queue behind the actual provider writer. The cursor tests stall a real read, check the rollback and connection state, and verify that the lease renews before expiry. The production paths still read the monotonic clock for authority and Unix time for the stored lease fence.

The lease compare-and-swap still checks its deadline at admission, when the database operation runs, and after the response. The public renewal API and the flake allowlist are unchanged.

Verification

  • All 12 affected tests passed 20 serial and 12 contended runs each on the implementation snapshot, for 384 executions. Eight isolated fault injections produced all 12 expected failures.
  • A renewal that expired in the queue sent zero HTTP requests. An applied update that returned at its deadline was reported as late.
  • Rebased onto main at bf3a825. All 324 tests in the affected guild database, remote-stream and database-runtime modules passed on the initial PR revision. Formatting, root all-target Clippy with warnings denied, scoped Dylint and the contracts preflight passed. Dylint reported zero inherited core findings.
  • The remote tests use the real libSQL HTTP client against a loopback Hrana fixture with SQLite backing.

The direct and prepared snapshot tests now both stall the transaction’s actual SELECT 1 cursor. The renewal tests cover expiry before admission, expiry while queued with zero requests, and an applied SQLite update whose response arrives at the deadline. All 325 database module and runtime tests and 128 focused repetitions passed. Three fault injections independently broke the cursor selection, queue check and late-response check, and the corresponding tests caught all three.

Reviewed commit: c086c56415621ca7f9fd483efd14bc2d7b1f6c3e.

Summary by Sourcery

Make database lease and snapshot timing checks deterministic while preserving deadline enforcement.

Bug Fixes:

  • Use the lease runtime’s clock consistently when checking renewal authority and lease expiry, preventing timing checks from disagreeing across database operations.

Enhancements:

  • Replace wall-clock sleeps and elapsed-time assertions in lease and snapshot tests with controlled-clock advancement and explicit coordination around database contention.
  • Strengthen remote snapshot tests to verify cursor rollback, connection recovery, and lease renewal within the original TTL.

Tests:

  • Add coverage for queued renewals that expire before issuing a request and for renewals applied at the deadline being reported as late completion.

@jatmn
jatmn marked this pull request as ready for review December 5, 2026 22:33

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 2 issues

Sourcery assessment

Approval pending. 2 findings to address first.

Blocking findings: src/db_compat.rs:1069, src/db/tests/remote_stream.rs:3232


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread src/db_compat.rs Resolved
Comment thread src/db/tests/remote_stream.rs Resolved
pullfrog[bot]
pullfrog Bot previously approved these changes Dec 5, 2026

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ Two non-blocking test coverage findings.

Approach

Using a fixture clock and synchronizing on the provider’s writer semaphore addresses the timing races while retaining the real libSQL client and SQLite backing.

Reviewed changes

  • Lease clocks. Renewal uses the runtime clock for admission, the compare-and-swap budget, and the response deadline. Lease fences use the runtime’s Unix time.
  • Writer contention. The remote fixture holds a provider transaction until the renewal queues. The guild fixture holds the commit while it checks same-generation renewal.
  • Snapshot and reconnect tests. The remote tests exercise rollback, stream cleanup, and lease renewal after a stalled read or connection reset.

All 324 tests passed locally across the remote stream, guild data, and database compatibility modules.

Non-blocking

  • P2 · The direct snapshot test stalls during describe. The query_row case arms stall_owned before libSQL prepares the query. The transaction-scoped describe consumes the one-shot stall, so rollback and renewal assertions can pass without the direct query opening a cursor. Match the stall on /v3/cursor and SELECT 1 before signaling the test. Direct snapshot test · Provider stall predicate · Pinned libSQL preparation code
  • P2 · Two renewal deadline boundaries lack regression coverage. The zero-request test expires the clock before admission, and the stalled-snapshot test expires it after the CAS reaches the provider. Add deterministic cases for a renewal that expires while waiting for the dedicated connection and for an applied CAS whose response is observed at the deadline. Those cases would catch regressions in the worker and post-response checks. Admission test · Worker and response checks

Pullfrog  | Fix it ➔ | View workflow run | Using gpt-6.2-sol | 𝕏

@jatmn

jatmn commented Dec 5, 2026

Copy link
Copy Markdown
Owner Author

Addressed both findings in c086c56. Tracing the earlier head showed the direct snapshot test stalled during libSQL’s describe request. The direct and prepared tests now both reach the transaction’s SELECT 1 cursor. Matching a different cursor made the direct test fail at the read deadline assertion.

The lease cases now exercise both post-admission boundaries in the committed suite. A renewal that expires in the queue sends zero HTTP requests. When SQLite applies the CAS and the reply is observed exactly at the deadline, the caller receives a late-completion error and the test verifies the stored update. Disabling each boundary check made its corresponding test fail. All 325 database module and runtime cases and 128 focused repetitions passed.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

Reviewed commit c086c56 since the prior Pullfrog review.

  • Targeted the snapshot cursor. Both snapshot cases stall the transaction’s SELECT 1 cursor request and verify rollback and lease recovery.
  • Covered expiry in the connection queue. The fixture holds the dedicated lease connection through the deadline and verifies that the renewal sends zero HTTP requests.
  • Covered late completion. The fixture advances the clock at CAS operation entry and verifies that the caller reports late completion even though the update persists in SQLite.

I verified the changes by source inspection. The Rust core and remote database CI jobs were still running when I submitted this review. Rust core · Remote database

Pullfrog  | View workflow run | Using gpt-6.2-sol | 𝕏

@jatmn
jatmn merged commit cdb0dbd into main Dec 5, 2026
22 checks passed
@jatmn
jatmn deleted the fix/queue-666-inherited-core-fixtures branch December 5, 2026 23:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant