Skip to content

fix: correct LMDB has() logic inversion#21780

Merged
PhilWindle merged 1 commit into
nextfrom
claudebox/fix-lmdb-has-logic
Mar 24, 2026
Merged

fix: correct LMDB has() logic inversion#21780
PhilWindle merged 1 commit into
nextfrom
claudebox/fix-lmdb-has-logic

Conversation

@AztecBot

@AztecBot AztecBot commented Mar 19, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fixes a logic error in LMDBStoreWrapper::has() where std::find result was compared against values->begin() instead of values->end(), causing inverted existence checks.

Bug: std::find returns end() when not found, but the code compared against begin():

  • Value found at position 0: begin() != begin()false (wrong)
  • Value not found: end() != begin()true (wrong)

Fix: Changed != values->begin() to != values->end().

Refactor: Moved the has() logic from the NAPI wrapper (LMDBStoreWrapper) down to LMDBStore so it can be tested without Node.js. The wrapper now delegates to _store->has().

Tests: Added 7 new tests covering:

  • Missing key → false
  • Existing key (key-only check) → true
  • Value present → true
  • Value missing → false
  • All-of semantics (all requested values must be present)
  • Mixed entries in a single call
  • Duplicate key deduplication

All 47 lmdblib tests pass (40 existing + 7 new).

Fix A-846 A-847

@AztecBot AztecBot added ci-draft Run CI on draft PRs. claudebox Owned by claudebox. it can push to this PR. labels Mar 19, 2026
@alexghr

alexghr commented Mar 19, 2026

Copy link
Copy Markdown
Contributor

Good find. This shows there was not test for this code path but also it's dead code as it's not used anywhere.

@PhilWindle PhilWindle marked this pull request as ready for review March 24, 2026 10:53
@PhilWindle PhilWindle enabled auto-merge March 24, 2026 10:54
## Summary

Fixes a logic error in `LMDBStoreWrapper::has()` where `std::find` result was compared against `values->begin()` instead of `values->end()`, causing inverted existence checks.

**Bug**: `std::find` returns `end()` when not found, but the code compared against `begin()`:
- Value found at position 0: `begin() != begin()` → **false** (wrong)
- Value not found: `end() != begin()` → **true** (wrong)

**Fix**: Changed `!= values->begin()` to `!= values->end()`.

**Refactor**: Moved the `has()` logic from the NAPI wrapper (`LMDBStoreWrapper`) down to `LMDBStore` so it can be tested without Node.js. The wrapper now delegates to `_store->has()`.

**Tests**: Added 7 new tests covering:
- Missing key → false
- Existing key (key-only check) → true
- Value present → true
- Value missing → false
- All-of semantics (all requested values must be present)
- Mixed entries in a single call
- Duplicate key deduplication

All 47 lmdblib tests pass (40 existing + 7 new).

Resolves https://linear.app/aztec-labs/issue/A-846/claude-lmdb-logic-error
@AztecBot AztecBot force-pushed the claudebox/fix-lmdb-has-logic branch from 25f768a to 227895e Compare March 24, 2026 10:55
@PhilWindle PhilWindle added this pull request to the merge queue Mar 24, 2026
Merged via the queue into next with commit 6b12e5e Mar 24, 2026
19 checks passed
@PhilWindle PhilWindle deleted the claudebox/fix-lmdb-has-logic branch March 24, 2026 11:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci-draft Run CI on draft PRs. claudebox Owned by claudebox. it can push to this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants