refactor(store): install_meta_belief → INSERT OR IGNORE for atomic idempotence (#772) - #773
Conversation
There was a problem hiding this comment.
Sorry @robotrocketscience, you have reached your weekly rate limit of 500000 diff characters.
Please try again later or upgrade to continue using Sourcery
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
✨ 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 |
|
[claim:review:curie:2026-05-14T01:41:31Z] |
|
Review (LGTM, adding Diff matches issue #772 exactly: SELECT-then-check → Idiom alignment: 10 existing Test: Verification:
Minor observation, non-blocking: |
|
[release:review:curie:2026-05-14T01:43:33Z] |
|
merge-train: merged b9f7c0d → |
Closes #772. Follow-up to #755 (PR #771) per the disposition in #772.
What this PR does
Refactors
MemoryStore.install_meta_belieffrom a SELECT-then-INSERTidempotency check to the project's established
INSERT OR IGNORE+rowcountidiom (10 existing call sites instore.py). Eliminates theTOCTOU window between SELECT and INSERT.
Surface
src/aelfrice/store.py—install_meta_beliefbody. Validation(
ValueErrorraises for invalidstatic_default/half_life_seconds/ unknown signal classes) runs unchanged before the INSERT. Net
reduction: 11 lines → 8 lines, one fewer SQLite round-trip.
tests/test_meta_beliefs.py— new testtest_install_concurrent_race_returns_false_not_raisesexercises therowcount == 0return path: second install on the same key returnsFalse, does not raise
sqlite3.IntegrityError. Single-threaded(deterministic); the existing
test_install_meta_belief_is_idempotent_returns_false_on_reinstallcovers the no-race idempotency case.
Behaviour deltas
IntegrityErrorraised on loserValueErrorValueError(unchanged)Acceptance mapping (#772)
install_meta_beliefswitches toINSERT OR IGNORE+rowcountcheckstore.pybody (commit 55e5764)test_install_meta_belief_is_idempotent_returns_false_on_reinstallstill passespytest tests/test_meta_beliefs.py→ 20 passedtest_install_rejects_invalid_configstill passes (validation order unchanged)test_install_concurrent_race_returns_false_not_raises(commit b9f7c0d)Verification
uv run pytest tests/test_meta_beliefs.py— 20 passed.git log --format='%h %G? %s' github/main..HEAD— both commits signed (G).git merge-base --is-ancestor github/main HEAD— FF ongithub/main.Out of scope
BEGIN IMMEDIATEforupdate_meta_belief's read-decay-write cycle.Per refactor(store): install_meta_belief → INSERT OR IGNORE for atomic idempotence (post-#755) #772 disposition: single-writer federation rule (v3.0 design decision: federation write model — multi-writer CRDT vs read-only #661,
d0c5ecdebb3f0f4d) makes the race not manifest, and no otherstore.pymethod usesBEGIN IMMEDIATE. Consistency over localfix.
encode_signal_weightscanonicality (int vs float bytes). Separatefollow-up if surfaced.