refactor(node/sync): tidy block cache and fix internal-node eviction - #1110
Merged
tcoratger merged 1 commit intoJun 17, 2026
Merged
Conversation
Clarity, modern Python, and one correctness fix in BlockCache. Documentation: - Trim the banner-essay module docstring, the PendingBlock class and field docstrings, and the verbose method Args/Returns to the project rules, keeping the genuine rationale (the >= capacity reason, the empty-set deletion, the slot-order example, FIFO attack-resistance). Structure: - Inline the single-use _evict_oldest into add and drop unmark_orphan, whose only caller was remove (folded its discard inline). mark_orphan stays: it has callers in two other modules plus internal use and guards the orphan set against phantom entries. - Make PendingBlock frozen; nothing mutates it. Eviction correctness fix: - Evicting an internal node left its cached children stranded: still cached, no longer linked to a present parent, never re-marked as orphans, so backfill never refetched the parent and orphan_count under-reported (which could flip the node to synced with stuck blocks). Eviction now re-marks the evicted block's still-cached children as orphans, with a regression test. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Clarity, modern-Python, and one correctness fix in
BlockCache(src/lean_spec/node/sync/block_cache.py). All sync tests pass.Documentation
PendingBlockclass + five multi-line field docstrings, and the verbose methodArgs/Returnsblocks to the project rules. Keep the genuine rationale (why>=in the capacity check, why empty parent-sets are deleted, the slot-order example, FIFO attack-resistance).Structure
_evict_oldestintoadd(single caller) and dropunmark_orphan(no external callers; its only caller wasremove, so its one-linediscardis now inline). Deleted its two now-redundant direct tests (the behavior stays covered by the remove-clears-orphan test).mark_orphan: it has callers inhead_syncandbackfill_syncplus internal use, and guards the orphan set against phantom entries — inlining would duplicate the guard and break the cache's encapsulation.PendingBlockis nowfrozen=True— nothing mutates it, matching the frozen-by-default convention.itertools.batchedfit here (no chunking), andOrderedDictstays (FIFO eviction needspopitem(last=False)).Eviction correctness fix
Evicting an internal node (a cached block that is itself a parent of other cached blocks) left its children stranded: they stayed cached, were no longer linked to a present parent, and were never re-marked as orphans — so backfill never refetched the parent and
orphan_countunder-reported. Sinceservice.pygates sync-completion onorphan_count, the node could flip to synced with stuck blocks. Eviction now re-marks the evicted block's still-cached children as orphans (keeping the parent-index link so they reconnect if the parent returns), with a regression test (test_eviction_remarks_orphaned_children).Deferred (noted): the dedup-keeps-deeper-
backfill_depthnit, and gating sync-completion on more thanorphan_count— both lower-severity, separate concerns.Testing
just checkpasses (ruff, format, ty, codespell, mdformat).uv run pytest tests/node/sync— 141 pass.🤖 Generated with Claude Code