Skip to content

fix: track size_of reads in optimistic transactions - #346

Merged
marvin-j97 merged 1 commit into
fjall-rs:mainfrom
Mike-Animal-Counseling:codex/fix-optimistic-size-of-read-tracking
Nov 3, 2026
Merged

marvin-j97 merged 1 commit into
fjall-rs:mainfrom
Mike-Animal-Counseling:codex/fix-optimistic-size-of-read-tracking

Conversation

@Mike-Animal-Counseling

@Mike-Animal-Counseling Mike-Animal-Counseling commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Readable::size_of on an optimistic write transaction reads a snapshot without registering the key in the read set. Two transactions can each read the other key's size, write their own key, and both commit, admitting write skew. Reads returning None also carry an existence dependency.

Register successful size_of reads with the existing conflict manager, matching get and contains_key. Keep the snapshot/overlay lookup so values are not loaded just to measure their length.

Add deterministic tests for write skew with existing, empty and missing values, concurrent deletion, rejected writes remaining unpublished, and unrelated keys/keyspaces still committing (including read-your-own-write).

The tests fail at the expected conflict assertions before the fix (2 failed, 1 control passed) and all pass afterward. No public API, dependency or disk-format changes. Affected transactions now return the existing Conflict result and must be retried.

Validation on Windows:

  • Rust 1.98: cargo fmt --all -- --check, cargo clippy, cargo test --features lz4 --all-targets (130 passed, 1 ignored), cargo test --doc (86 passed).
  • All 8 combinations of lz4/bytes_1/metrics build; cargo build --all-features also passes.
  • Rust 1.90: cargo +1.90.0 test --lib (75 passed, 1 ignored), cargo +1.90.0 build --all-features.
  • cargo test --all-features --lib tx_ssi_size_of (3 passed); basic example prints OK.
  • Whitebox command exits successfully, but both matching tests are already ignored.

Additional checks expose existing upstream failures, reproduced on unchanged main with the same Cargo.lock: cargo clippy --all-targets reports 25 errors in existing tests; cargo test --no-default-features --lib tx_ssi_size_of cannot compile src/keyspace/options.rs:709 (missing Some). The no-default library builds. Linux/macOS and nextest were not run locally.

No directly matching issue found. Related #299 adds explicit untracked reads; this fixes the default tracked transaction without adding that API.

Summary by CodeRabbit

  • Bug Fixes
    • Size checks now detect conflicts when another transaction changes a queried key, preventing inconsistent commits.
    • Concurrent updates to unrelated keys or keyspaces can still commit successfully.

@coderabbitai

coderabbitai Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: ace3337f-383e-4a87-9e49-0593c8bb7555
Commits

Reviewing files that changed from the base of the PR and between cfcdce3 and 43e4fbd.

Files selected for processing: 1
  • src/tx/optimistic/write_tx.rs

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

Walkthrough

WriteTransaction::size_of now records queried keys as reads for conflict detection. Tests cover conflicts after concurrent changes to queried keys and successful commits when concurrent writes affect unrelated keys or keyspaces.

Changes: Size Query Conflict Tracking

Layer / File(s) Summary
Record and test size-query reads
src/tx/optimistic/write_tx.rs
size_of marks the queried key as read. Tests cover write skew, deletion conflicts, pending writes, and unrelated writes.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: marvin-j97

Merge Risk: Minimal · up to 43e4f

Size reads now participate in conflict detection. No merge-blocking issue is established.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: tracking size_of reads in optimistic transactions.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 4 functions across 1 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Oct 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@mikebuilds6

Copy link
Copy Markdown

Thanks for the review!

I investigated the Windows failure in write_buffer_size_blob (tests/write_buffer_size.rs:55, expected 0, got 140). On unchanged upstream main at cfcdce3, using the same Cargo.lock, I reproduced the identical assertion failure on the 15th repeated execution of that test. All three new size_of regression tests passed in the Windows CI job.

This appears to be a pre-existing intermittent failure. Could you rerun the failed/cancelled Windows jobs when convenient?

@marvin-j97

Copy link
Copy Markdown
Collaborator

For some reason I've seen Windows CI failing multiple times, always with 140; I'm not sure why...

@marvin-j97
marvin-j97 merged commit 75afff3 into fjall-rs:main Nov 3, 2026
20 of 22 checks passed
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.

3 participants