fix(dpmodel): release merged LMDB cache references - #5797
Conversation
Balance each source environment acquired by merge_lmdb through the refcount-aware cache close path, including exceptions. Add a regression proving merge preserves shared readers and leaves the cache reference count unchanged. Coding-Agent: Codex Codex-Version: codex-cli 0.144.1 Model: gpt-5.6-sol Reasoning-Effort: xhigh
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthrough
ChangesLMDB cache lifecycle
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #5797 +/- ##
==========================================
- Coverage 79.85% 78.31% -1.54%
==========================================
Files 1022 1049 +27
Lines 117351 120651 +3300
Branches 4313 4351 +38
==========================================
+ Hits 93706 94490 +784
- Misses 22101 24598 +2497
- Partials 1544 1563 +19 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Release the retained readers with del so finalizers run without assignments that CodeQL flags as unused. Coding-Agent: Codex Codex-Version: codex-cli 0.144.4 Model: gpt-5.6-sol Reasoning-Effort: xhigh
|
Possible reviewers based on changed lines, exact file history, and exact-file review history:
No review request was made automatically. Coding agent: Codex |
Coding-Agent: Codex Codex-Version: codex-cli 0.144.6 Model: gpt-5.6-sol Reasoning-Effort: xhigh
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
Suppressed comments (1)
source/tests/pt/test_lmdb_dataloader.py:1112
- The test cleanup relies on
del ...+gc.collect()to trigger__del__finalizers, which is nondeterministic and can be flaky across Python implementations. SinceLmdbDataReaderexposes an idempotent.close(), prefer explicitly closing readers infinallyto release the LMDB cache refs deterministically (you can keepgc.collect()as a belt-and-suspenders if desired).
finally:
# Drop both strong references so their finalizers release the
# cache entries before the cleanup assertion below.
del existing_reader, new_reader
gc.collect()
njzjz-bot
left a comment
There was a problem hiding this comment.
Three independent full reviews were completed against this exact head. No concrete actionable findings were identified, so no artificial inline comment was added. The effective diff is a focused regression test that verifies merge-time LMDB cache leases remain balanced while active and newly created readers keep sharing the same valid environment. The PR currently has merge conflicts, which must be resolved separately.
The Codex quota is close to resetting, so I am concentrating the remaining token budget on these reviews.
Coding agent: Codex
Codex version: codex-cli 0.144.6
Model: gpt-5.6-sol
Reasoning effort: xhigh
Summary
merge_lmdb()through the refcount-aware LMDB cache pathfinallyso malformed metadata or copy failures also balance the merge's temporary referenceRoot cause and fix
_open_lmdb()caches readonly environments by resolved path because python-lmdb does not permit independently opening the same path multiple times in one process. Every acquisition increments a cache refcount, and_close_lmdb()is the matching release operation.merge_lmdb()acquired each source through_open_lmdb(), but calledsrc_env.close()directly. If a reader already shared that cached environment, the merge invalidated its live handle while the cache still retained it. A later reader could then receive the same closed object.The source loop now pairs
_open_lmdb(src_path)with_close_lmdb(src_path)infinally. This releases only the reference owned by the merge; existing readers retain their references and environment. Thefinallyscope covers metadata parsing, source/destination transactions, frame copying, and system-ID offset updates.Why existing tests missed this
Existing merge tests opened readers only after the merge and did not keep a source reader alive across the operation. They therefore never exercised the cache-sharing condition that makes a direct
Environment.close()unsafe.The new regression:
LmdbDataReaderand records its cached environment/refcount;On the previous implementation, the existing reader fails deterministically with:
lmdb.Error: Attempt to operate on closed/deleted/dropped object.Validation performed:
TestMergeLmdbSystemIdsgroup: 4 passedruff format --check .ruff check .git diff --checkCloses #5635.
Coding agent: Codex
Codex version: codex-cli 0.144.1
Model: gpt-5.6-sol
Reasoning effort: xhigh
Summary by CodeRabbit
Bug Fixes
Tests