refactor(sync): collapse SyncState to enum plus single non-trivial property#729
Merged
tcoratger merged 1 commit intoMay 18, 2026
Merged
Conversation
…operty SyncState was 163 lines for a 3-state enum. Most of the surface was trivial `state == SyncState.X` wrappers and a state-machine helper whose only caller was sync service. Net change: -225 lines across 4 files, zero behavior change. Changes: - states.py drops `is_idle`, `is_syncing`, `is_synced` properties (trivial == wrappers), `can_transition_to` (one caller), and the module-level `_VALID_TRANSITIONS` table. Keeps the enum and `accepts_gossip`, the only property doing real work. - service.py drops `SyncService.is_syncing` and `is_synced` public wrappers (zero external callers). Replaces three call sites that used the removed enum properties with direct comparisons. - service.py rewrites `_transition_to` to inline the validity check. The original 5-edge transition table becomes two invariants: no self-transitions, no IDLE -> SYNCED shortcut. Same semantics verified case-by-case against the original table. - test_states.py shrinks to cover the surviving surface (enum identity and accepts_gossip). The `_transition_to` invariants now have coverage in test_service.py, including a new self-transition test to replace the parametrized test that lived on `can_transition_to`. Co-Authored-By: Claude Opus 4.7 (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
SyncStatewas 163 lines for a three-state enum. Most of the surfacewas trivial
state == SyncState.Xwrappers and a state-machine helperwith one caller. Collapses to the enum plus a single non-trivial
property, with the transition logic inlined where it actually runs.
Net: -225 lines across 4 files, zero behavior change.
What changed
states.py— 163 -> 32 linesRemoved:
is_idle,is_syncing,is_syncedproperties — each wrapped aone-line
==comparison. Zero clarity gain, extra API surface.can_transition_to(target)method — used at exactly one call site._VALID_TRANSITIONSdict — only fed the helper above.etc.).
Kept:
accepts_gossip— the only property that does real work(
self in {SYNCING, SYNCED}), used at 3 call sites.service.py— small net reductionRemoved
SyncService.is_syncingandis_syncedpublic properties.Grep confirmed zero callers outside the file itself. Anyone needing
them can write
service.state == SyncState.X.Updated 3 call sites that used the removed enum properties:
self._state.is_syncing->self._state == SyncState.SYNCING(x2)self._state.is_idle->self._state == SyncState.IDLE(x1)Rewrote
_transition_toto inline the validity check now thatcan_transition_tois gone. The original 5-edge transition tablebecomes two invariants:
Verified case-by-case against the original table — same semantics.
test_states.py— 135 -> 47 linesDropped tests for removed methods (
can_transition_to,is_X).Kept and tightened tests for the enum and
accepts_gossip.test_service.py— +10 linesAdded
test_self_transition_raises_value_errorto maintain coverageof the no-self-transition invariant, replacing the parametrized test
that lived on
can_transition_to. The IDLE -> SYNCED forbidden casewas already covered by an existing test.
Test plan
ruff check,ruff format --check,ty checkall passpytest tests/lean_spec/subspecs/sync tests/lean_spec/subspecs/networking/test_network_service.py-> 166 passed
transition table
Out of scope
The original review flagged other sync-layer items:
_SyncStoreViewadapter,
make_default_block_processorfactory, and themarketing-tone docstring on
SyncService. Those stay queued forfollow-up PRs.
🤖 Generated with Claude Code