Repository navigation
samwise: bound snapshot capture checkout by its write deadline - #1201
Merged
Merged
Conversation
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>
There was a problem hiding this comment.
✅ 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.
gpt-6.2-sol | 𝕏
jatmn
marked this pull request as ready for review
December 6, 2026 15:25
There was a problem hiding this comment.
✅ 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_beforeconstructs 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 --checkpassed. Rust core CI
gpt-6.2-sol | 𝕏
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

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_actioncapturedcapture_write_deadline()and still calledwith_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_beforeapplies the pinned write deadline to permit waits, connection checkout, and recovery probes. Its closure receives a privately constructedBoundedConnectionborrowed 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 --testsrejected the previous snapshot capture and the advised-claim call that still passed the raw instant:That
bot_actionsline is thetransaction_capture_before(write_deadline, …)shape #1085 left in place after switching checkout towith_conn_before. Review follow-up compiler probes found that the initial proof could be constructed by adbsubmodule or returned from a checkout and reused on another connection. The repaired API rejects both forms and provides no capture method on a plainwith_connconnection.Before the checkout fix,
remote_capture_permit_wait_uses_the_captured_write_deadlinefailed on currentmainwithcapture 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 passedcargo clippy --locked -p jmodguard --all-targets -- -D warnings— passedcargo fmt --allReview follow-up at
fcd249a5276f7f5f3b03eba92643872074a36f72cargo 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 warningsandcargo 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 --affectedwas not run.Summary by Sourcery
Keep guild snapshot capture within its pinned write deadline, including while waiting to check out a database connection.
Bug Fixes:
Enhancements:
Tests: