Skip to content

fix(shared-state): remove race in dirty-read paths#83

Open
SH20RAJ wants to merge 1 commit intomofa-org:mainfrom
SH20RAJ:fix/22-dirty-read-race
Open

fix(shared-state): remove race in dirty-read paths#83
SH20RAJ wants to merge 1 commit intomofa-org:mainfrom
SH20RAJ:fix/22-dirty-read-race

Conversation

@SH20RAJ
Copy link
Copy Markdown

@SH20RAJ SH20RAJ commented Apr 1, 2026

Summary

  • fix race-prone dirty-read pattern in DirtyVec::read_if_dirty
  • fix same race-prone pattern in DirtyValue::read_if_dirty
  • fix same race-prone pattern in ChatState::read_if_dirty

Technical change

  • take read lock first
  • check dirty flag
  • clone snapshot while lock is held
  • clear dirty flag after snapshot is captured

This ordering avoids clearing dirty before data is observed, which could otherwise cause missed notifications under concurrent writers.

Issue

Fixes #22

Validation

I could not run cargo test in this environment because cargo is unavailable in PATH; the fix is localized to dirty-read methods and preserves existing public method signatures.

@SH20RAJ
Copy link
Copy Markdown
Author

SH20RAJ commented Apr 1, 2026

Quick follow-up: this patch changes dirty-read ordering to snapshot under read lock before clearing dirty flag in DirtyVec, DirtyValue, and ChatState. This targets missed-notification races under concurrent writers while preserving external method signatures.

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.

[bug ]: Race condition in DirtyVec::read_if_dirty and DirtyValue::read_if_dirty causes missed dirty notifications

1 participant