8000 fix: queries see whole transactions and one state per query (#554, #555) by adityamukho · Pull Request #559 · project-minigraf/minigraf · GitHub
[go: up one dir, main page]

Skip to content

fix: queries see whole transactions and one state per query (#554, #555) - #559

Merged
adityamukho merged 1 commit into
mainfrom
fix/554-555-backport
Oct 11, 2026
Merged

adityamukho merged 1 commit into
mainfrom
fix/554-555-backport

Conversation

@adityamukho
@adityamukho adityamukho 8000 commented Oct 11, 2026
Copy link
Copy Markdown
Collaborator

v2.x backport of #556 (#554) and #557 (#555). Refs #554, #555. Both are data-integrity issues, so they stay open until a release ships the fix.

#554: a query can see part of a committed transaction

execute transact/retract (since v0.6.0) and WriteTransaction::commit (since v0.5.0) added facts with one load_fact call each, each under its own write lock. FactStorage::load_facts appends the batch under one lock. It works out the new facts and their slots before changing anything, so a slot past u32::MAX fails the whole batch, not part of it (Codex finding; v3's version has no fallible step in its loop). Used by:

  • execute
  • WriteTransaction::commit
  • WAL replay
  • BrowserDb's commit

#555: patterns of one query read different states

selective_fact_fetch ran each lookup under its own read lock. The bodies of get_facts_by_entity, get_facts_by_entity_attribute_indexed and get_facts_by_attribute move unchanged into free functions over &FactData. FactStorage::get_facts_for_lookups runs a list of them under one read guard. get_facts_by_attribute's no-index fallback now reads through that guard instead of releasing it and calling get_all_facts. The three old methods remain for tests only (#[cfg(test)]).

Tests

tests/snapshot_atomicity_test.rs, ported from v3 without its checkpoint test:

Two unit tests: load_facts_appends_a_batch_and_skips_duplicates and facts_for_lookups_concatenates_each_lookup_in_order.

1240 passing, 9 ignored. fmt and clippy clean; the wasm32 browser build checks.

Codex review: the partial-batch finding above is fixed; it also noted the races are probabilistic.

🤖 Generated with Claude Code

https://claude.ai/code/session_012wXxZguv7PgKQjMMH4yJ5h

Backport of the v3 fixes (PRs #556, #557) to v2.x.

#554: commits added a transaction's facts to FactStorage one load_fact
call at a time, each under its own write lock, so a query on another
thread could see part of the transaction. FactStorage::load_facts
appends a batch under one lock; execute, WriteTransaction::commit, WAL
replay and BrowserDb's commit use it.

#555: selective_fact_fetch read each entity/attribute lookup under its
own read lock, so a commit between two lookups was seen by some
patterns and not others. The three lookup bodies become functions over
&FactData and FactStorage::get_facts_for_lookups runs them all under one
read guard. The old methods remain for tests only.

The file-backed #555 reproducer disables checkpoints: on v2.x a query
that runs during a checkpoint can lose committed facts, a separate bug.

Refs #554, #555

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012wXxZguv7PgKQjMMH4yJ5h
@codecov
codecov Bot commented Oct 11, 2026
Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.60714% with 15 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/graph/storage.rs 85.43% 15 Missing ⚠️

📢 Thoughts on this report? Let us know!

@adityamukho
adityamukho merged commit aaf9168 into main Oct 11, 2026
22 checks passed
@adityamukho
adityamukho deleted the fix/554-555-backport branch October 11, 2026 18:23
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.

1 participant

0