Skip to content

fix(python): use wrapping_add(1) in seqlock_begin_write for overflow consistency - #2866

Merged
trunk-io[bot] merged 1 commit into
dora-rs:mainfrom
SaitejaKommi:fix/seqlock-wrapping-add
Jul 28, 2026
Merged

fix(python): use wrapping_add(1) in seqlock_begin_write for overflow consistency#2866
trunk-io[bot] merged 1 commit into
dora-rs:mainfrom
SaitejaKommi:fix/seqlock-wrapping-add

Conversation

@SaitejaKommi

Copy link
Copy Markdown
Contributor

Summary

Use wrapping_add(1) in seqlock_begin_write to provide consistent overflow handling for the seqlock generation counter.

Fixes #2865

Root Cause

In apis/python/node/src/lib.rs, seqlock_begin_write incremented the generation counter using pre_write_gen + 1, while seqlock_end_write already used pre_write_gen.wrapping_add(2).

Using normal integer addition can panic on u64 overflow in debug builds or when overflow checks are enabled, resulting in inconsistent overflow behavior between the begin and end write paths.

Solution

  • Replaced pre_write_gen + 1 with pre_write_gen.wrapping_add(1) in seqlock_begin_write.
  • Align the overflow behavior with seqlock_end_write, ensuring the generation counter wraps consistently without panicking.

Testing

  • cargo fmt --all -- --check
  • cargo check -p dora-node-api-python

Scope

This PR is intentionally limited to apis/python/node/src/lib.rs and changes a single arithmetic operation to ensure consistent overflow handling. No functional APIs or runtime behavior were otherwise modified.

@trunk-io

trunk-io Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

😎 Merged successfully - details.

Copy link
Copy Markdown
Collaborator

Automated review by Claude — this is a fully automated review; no human has vetted it.

No issues found. Using wrapping_add(1) here makes the begin path consistent with seqlock_end_write's wrapping_add(2) and avoids a potential debug-build overflow panic on the u64 generation counter. The wrap boundary behaves identically to the end path, so seqlock parity semantics are preserved.


Generated by Claude Code

@trunk-io
trunk-io Bot merged commit ffa6fd1 into dora-rs:main Jul 28, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use wrapping_add(1) in seqlock_begin_write for overflow consistency

2 participants