Skip to content

samwise: bound snapshot capture checkout by its write deadline - #1201

Merged
jatmn merged 2 commits into
mainfrom
cursor/samwise-bounded-capture-checkout-4ed9
Dec 6, 2026
Merged

jatmn merged 2 commits into
mainfrom
cursor/samwise-bounded-capture-checkout-4ed9

Conversation

@jatmn

@jatmn jatmn commented Dec 6, 2026 •

Copy link
Copy Markdown
Owner

Guild snapshot capture pinned a write deadline for the transaction, then checked out a connection with Db::with_conn, so a full permit pool could hold that checkout past the deadline.

This is the same miss fixed for advised bot-action promotion in #1085 (4e5863c): claim_advised_bot_action captured capture_write_deadline() and still called with_conn. #1044, #1048, and #1039 were earlier rounds of the same deadline not surviving checkout or promotion. Snapshot capture (GuildDataStore::capture) kept the old shape.

Db::with_conn_before applies the pinned write deadline to permit waits, connection checkout, and recovery probes. Its closure receives a privately constructed BoundedConnection borrowed from that checkout. Capture opens through that connection, using the same instant for transaction work. Remote capture requires a write deadline.

Proof the check catches the old code

During the initial implementation, before the call sites were updated, cargo check -p jmodguard --tests rejected the previous snapshot capture and the advised-claim call that still passed the raw instant:

src/db/guild_data/snapshots.rs:517:74: error[E0308]: mismatched types: expected `BoundedWriteDeadline`, found `Option<Instant>`
src/db/guild_data/snapshots.rs:526:67: error[E0308]: mismatched types: expected `BoundedWriteDeadline`, found `Option<Instant>`
src/db/bot_actions.rs:523:41: error[E0308]: mismatched types: expected `BoundedWriteDeadline`, found `Option<Instant>`
src/db/tests/remote_stream.rs:2007:58: error[E0308]: mismatched types: expected `BoundedWriteDeadline`, found `Option<Instant>`

That bot_actions line is the transaction_capture_before(write_deadline, …) shape #1085 left in place after switching checkout to with_conn_before. Review follow-up compiler probes found that the initial proof could be constructed by a db submodule or returned from a checkout and reused on another connection. The repaired API rejects both forms and provides no capture method on a plain with_conn connection.

Before the checkout fix, remote_capture_permit_wait_uses_the_captured_write_deadline failed on current main with capture still waiting at the captured write deadline (both pool permits held, write clock advanced to the captured deadline, SQL never started). After the fix that test passes, along with the existing advised-claim permit test and the capture promotion tests.

Validation

  • cargo test --locked -p jmodguard -- remote_capture_permit_wait_uses_the_captured_write_deadline capture_promotes_after_the_read_deadline_within_the_write_budget expired_capture_cannot_prepare_growth_or_reclaim_receipts advised_claim_promote_permit_wait_uses_the_captured_write_deadline — 4 passed
  • cargo clippy --locked -p jmodguard --all-targets -- -D warnings — passed
  • cargo fmt --all

Review follow-up at fcd249a5276f7f5f3b03eba92643872074a36f72

  • cargo test --locked -p jmodguard --lib -- capture snapshot advised_claim --test-threads=6 — 74 passed, including rejection before SQL when a remote capture has no checkout deadline.
  • cargo clippy --locked -p jmodguard --all-targets -- -D warnings and cargo fmt --all --check — passed.

The new test uses a local SQLite-backed Hrana fixture and a manual clock. It does not prove a live remote libSQL deployment. Full scripts/ci-preflight.sh --affected was not run.

Open in Web Open in Cursor 

Summary by Sourcery

Keep guild snapshot capture within its pinned write deadline, including while waiting to check out a database connection.

Bug Fixes:

  • Ensure guild snapshot captures fail at their pinned write deadline if connection-pool permits are unavailable, rather than waiting past the deadline.

Enhancements:

  • Require remote capture transactions to use a connection checkout bounded by the write deadline, preventing capture from starting through an unbounded checkout.

Tests:

  • Add coverage for snapshot capture timing out while waiting for pool permits and for rejecting remote capture without a checkout deadline.

Capture transactions now require a BoundedWriteDeadline minted only by
Db::with_conn_before, so permit waits and connection checkout share the
deadline pinned for the transaction. Guild snapshot capture was still
checking out through Db::with_conn after that deadline was captured.

Co-authored-by: JATMN <jatmn@users.noreply.github.com>
pullfrog[bot]
pullfrog Bot previously approved these changes Dec 6, 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.

✅ No new issues found.

Approach — Reusing deadline-aware checkout keeps permit waits, connection checkout, and the capture transaction on the same write budget.

Reviewed changes

  • Snapshot capture. The deferred attempt and the retry after SQLite reports busy use the deadline captured before the first checkout.
  • Transaction entry points. Capture transactions take the deadline supplied by with_conn_before. Advised bot-action claims carry the same deadline through promotion and fallback.
  • Regression coverage. All five focused tests passed, covering permit saturation, promotion, and the deadline through retry and commit with the SQLite-backed Hrana fixture.

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

@jatmn
jatmn marked this pull request as ready for review December 6, 2026 15:25
@jatmn jatmn self-assigned this Dec 6, 2026

@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 1 issue

Sourcery assessment

Approval pending. 1 finding to address first.

Blocking findings: src/db.rs:48


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

Comment thread src/db.rs Resolved

@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.

Sourcery assessment

Approved.

@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.

Approach — A borrowed BoundedConnection ties capture to the connection and deadline used for checkout.

Reviewed changes

  • Bound capture to checkout. Only Db::with_conn_before constructs the capture-capable view. Snapshot capture retains the original deadline on its SQLite busy retry.
  • Preserved the advised-claim budget. Promotion and the fallback primary read and immediate write take their deadline from the checked-out view.
  • Added remote deadline coverage. The Hrana fixture verifies that an absent deadline prevents the capture transaction from opening. All 74 focused tests and cargo fmt --all --check passed. Rust core CI

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

@jatmn
jatmn merged commit 87e1dfe into main Dec 6, 2026
22 checks passed
@jatmn
jatmn deleted the cursor/samwise-bounded-capture-checkout-4ed9 branch December 6, 2026 16:07
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.

2 participants