Uh oh!
There was an error while loading. Please reload this page.
Conversation
…t peer and connection discorvery
Signed-off-by: Tonic <joseph.pollack@emle.eu>
Josephrp
commented
Mar 15, 2026
@greptileai , comprehensively review this pr : |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> Signed-off-by: Tonic <joseph@legml.ai>
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> Signed-off-by: Tonic <joseph@legml.ai>
Josephrp
commented
Mar 16, 2026
@greptileai , comprehensively update your review based on the changes above : |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Josephrp
commented
Mar 16, 2026
@greptileai comprehensively update your review based on the above : |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Josephrp
commented
Mar 16, 2026
@greptileai , comprehensively update your review based on the latest changes and the entire PR accordingly : |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Josephrp
commented
Mar 16, 2026
@greptileai : comprehensively review your assessment of this PR . this PR introduces a lot of changes , some may seem out of scope but they are included in this PR , review them as if they are in scope. review every touched file . review every intent and method and corresponding datamodel. review out of diff and within diff changes. assess the quality of this PR . comprehensively update your assessment of this PR , produce a complete assessment of this PR : |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Josephrp
commented
Mar 16, 2026
@greptileai : comprehensively review your assessment of this PR . this PR introduces a lot of changes , some may seem out of scope but they are included in this PR , review them as if they are in scope. review every touched file . review every intent and method and corresponding datamodel. review out of diff and within diff changes. assess the quality of this PR . comprehensively update your assessment of this PR , produce a complete assessment of this PR : |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Josephrp
commented
Mar 16, 2026
@greptileai : comprehensively review your assessment of this PR . this PR introduces a lot of changes , some may seem out of scope but they are included in this PR , review them as if they are in scope. review every touched file . review every intent and method and corresponding datamodel. review out of diff and within diff changes. assess the quality of this PR . comprehensively update your assessment of this PR , produce a complete assessment of this PR , double check your work to assure you are not missing false positives , review this PR comprehensively : |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Josephrp
commented
Mar 16, 2026
@greptileai : comprehensively review your assessment of this PR . this PR introduces a lot of changes , some may seem out of scope but they are included in this PR , review them as if they are in scope. review every touched file . review every intent and method and corresponding datamodel. review out of diff and within diff changes. assess the quality of this PR . comprehensively update your assessment of this PR , produce a complete assessment of this PR , double check your work to assure you are not missing false positives , review this PR comprehensively : |
1 similar comment
Josephrp
commented
Mar 16, 2026
@greptileai : comprehensively review your assessment of this PR . this PR introduces a lot of changes , some may seem out of scope but they are included in this PR , review them as if they are in scope. review every touched file . review every intent and method and corresponding datamodel. review out of diff and within diff changes. assess the quality of this PR . comprehensively update your assessment of this PR , produce a complete assessment of this PR , double check your work to assure you are not missing false positives , review this PR comprehensively : |
| self.udp_tracker_client: Optional[Any] = None | ||
| # Queue manager for priority-based torrent scheduling | ||
| self.queue_manager: Optional[Any] = None | ||
| self.key_manager: Optional[Any] = None |
There was a problem hiding this comment.
key_manager parameter silently overwritten with None
self.key_manager = key_manager is assigned from the constructor parameter at line 3490, but then unconditionally overwritten with None at this line — discarding whatever was passed in.
Because key_manager is used in _build_xet_node_id, _ensure_xet_discovery_graph (XET allowlist creation), and XetAllowlist instantiation, any caller that passes a live key manager (e.g., the daemon startup) will silently get no signing/identity capability.
| self.key_manager: Optional[Any] =None | |
| self.key_manager=self.key_managerorNone# preserved from __init__ param |
Or simply remove this line — the assignment at line 3490 is sufficient.
| msg = "Cryptography library not available for signing" | ||
| raise RuntimeError(msg) | ||
| # Build message to sign: salt + seq + v (data) | ||
| # BEP 44: sig = sign(salt + seq + v) | ||
| message = salt + seq.to_bytes(8, "big") + data | ||
| # Build message to sign per BEP 44: bencoded-style buffer (salt + seq + v) |
There was a problem hiding this comment.
BEP 44 signature format change breaks all previously stored mutable data
The old signing message was salt + seq.to_bytes(8, "big") + data — a non-standard raw concatenation. The new format is the correct BEP 44 bencoded buffer (4:salt<len>:<salt>3:seqi<seq>e1:v<len>:<v>).
While the new format is spec-compliant, this is a backward-incompatible change: any mutable DHT record written by a previous build will fail verify_mutable_data_signature after this update because the signing message they were signed with no longer matches. Nodes that have not yet upgraded will also reject signatures from upgraded nodes and vice-versa.
There is no migration path in this PR. Consider either:
- Bumping the mutable store version/salt so old records are naturally discarded, or
- Adding a fallback verification attempt with the legacy format during a transition window.
| if peer_manager.is_peer_xet_authorized(peer_id, None): | ||
| return True | ||
| return False | ||
| async def start(self) -> None: | ||
| """Start the sync manager.""" | ||
| if self._running: | ||
| return | ||
| if self.sync_mode == SyncMode.CONSENSUS: | ||
| self.logger.warning( | ||
| "Consensus mode is not transport-backed yet; downgrading to best_effort" | ||
| ) | ||
| self.sync_mode = SyncMode.BEST_EFFORT | ||
| self.set_last_error( | ||
| "Consensus mode is disabled until transport-backed RPCs exist" | ||
| ) | ||
| elif self.sync_mode == SyncMode.BROADCAST: | ||
| if not self._has_healthy_propagation_backend(): | ||
| self.logger.warning( | ||
| "Broadcast mode has no healthy propagation backend; downgrading to best_effort" | ||
| ) | ||
| self.sync_mode = SyncMode.BEST_EFFORT | ||
| self.set_last_error( | ||
| "Broadcast mode requires at least one healthy propagation backend" |
There was a problem hiding this comment.
DESIGNATED mode always downgrades to BEST_EFFORT on first start
_has_verified_designated_source() checks peer_manager.is_peer_xet_authorized() across all active torrent sessions. When a workspace is first opened — which happens before any peer connections are established — self.session_manager.torrents will be empty (or contain sessions with uninitialized peer managers). The check therefore always returns False, and every DESIGNATED-mode workspace silently downgrades to BEST_EFFORT at startup, regardless of configuration.
The last_error is set to a string that implies a legitimacy problem with the peers, which would be confusing to operators.
Consider deferring this authorization check to the first sync cycle (inside _sync_loop) rather than enforcing it as a hard prerequisite in start(). The downgrade should only happen if the peers remain unverifiable after a configurable warm-up period.
* adds initial systems * adds ci docs fix * adds ci docs fix 2 * fix documentation blog error / bug * fix documentation blog error / bugs * fix docs monkey patch * fix docs import path * fix import path with import lib * attempts Inline patch script for GitHub CI * attempts docs fix * use extend for i18nfiles * use extend for i18nfiles * adds refactor , docs , translations , pre commit , lints , tests , session , xet, ipfs , benchmarks , bug fixes , peer , piece , executor , daemon , cli , config, and more * adds refactor , docs , translations , pre commit , lints , tests , session , xet, ipfs , benchmarks , bug fixes , peer , piece , executor , daemon , cli , config, and more * adds uv docs fix * solves test failures , lint checks , ci docs build , main / dev branch ci separation , adds fixes for bugs identified while testing , refactors tests , and more ! * solves test failures , lint checks , ci docs build , main / dev branch ci separation , adds fixes for bugs identified while testing , refactors tests , and more ! * solves test failures , lint checks , ci docs build , main / dev branch ci separation , adds fixes for bugs identified while testing , refactors tests , and more ! * solves test failures , lint checks , ci docs build , main / dev branch ci separation , compatibility tests, adds missing deps * Addssessionrefactor (#6) * solves test failures , lint checks , ci docs build , main / dev branch ci separation , adds fixes for bugs identified while testing , refactors tests , and more ! * solves test failures , lint checks , ci docs build , main / dev branch ci separation , compatibility tests, adds missing deps * improves ci/cd workflows , permissions , and so on * adds docs fixes * adds docs fixes , compatibility fixes , lint , ci , precommit improvements * adds docs fixes , compatibility fixes , lint , ci , precommit improvements * Addscom (#8) * adds docs fixes , compatibility fixes , lint , ci , precommit improvements * Addsci (#21) * adds cheaper ci and adds lints * adds BEP 44 server , client , bugfix , swarm * adds bugfixes , xet, tests , lints * Solves Tests Timeouts and Fails (#22) * Addscli (#23) * adds bugfixes , xet, tests , lints * adds improvements * adds reactive ui (#25) * init * initial release * adds initial systems * adds ci docs fix * adds ci docs fix 2 * fix documentation blog error / bug * fix documentation blog error / bugs * fix docs monkey patch * fix docs import path * fix import path with import lib * attempts Inline patch script for GitHub CI * attempts docs fix * use extend for i18nfiles * use extend for i18nfiles * adds refactor , docs , translations , pre commit , lints , tests , session , xet, ipfs , benchmarks , bug fixes , peer , piece , executor , daemon , cli , config, and more * adds refactor , docs , translations , pre commit , lints , tests , session , xet, ipfs , benchmarks , bug fixes , peer , piece , executor , daemon , cli , config, and more * adds uv docs fix * solves test failures , lint checks , ci docs build , main / dev branch ci separation , adds fixes for bugs identified while testing , refactors tests , and more ! * solves test failures , lint checks , ci docs build , main / dev branch ci separation , adds fixes for bugs identified while testing , refactors tests , and more ! * solves test failures , lint checks , ci docs build , main / dev branch ci separation , adds fixes for bugs identified while testing , refactors tests , and more ! * solves test failures , lint checks , ci docs build , main / dev branch ci separation , compatibility tests, adds missing deps * Addssessionrefactor (#6) * solves test failures , lint checks , ci docs build , main / dev branch ci separation , adds fixes for bugs identified while testing , refactors tests , and more ! * solves test failures , lint checks , ci docs build , main / dev branch ci separation , compatibility tests, adds missing deps * improves ci/cd workflows , permissions , and so on * adds docs fixes * adds docs fixes , compatibility fixes , lint , ci , precommit improvements * adds docs fixes , compatibility fixes , lint , ci , precommit improvements * adds docs fixes , compatibility fixes , lint , ci , precommit improvements * adds docs fixes , compatibility fixes , lint , ci , precommit improvements * adds docs fixes , compatibility fixes , lint , ci , precommit improvements * solves failing tests and timeouts, adds testing fixtures * adds docs fixes , compatibility fixes , lint , ci , precommit improvements * solves failing tests and timeouts, adds testing fixtures * adds rebase * Addscom (#8) * adds docs fixes , compatibility fixes , lint , ci , precommit improvements * adds cheaper ci and adds lints * adds streaming media / vlc , adds xet implementation , adds bugfix dht peer and connection discorvery * Update .gitignore * Update .github/workflows/release.yml * solves review comments * adds BEP 44 server , client , bugfix , swarm * adds code quality * adds dht guards * solves review comments * solves review comments * solves review comments * adds bugfixes , xet, tests , lints * solves failing tests and some warnings * adds improvements * adds solutions * adds changes * adds transaction , peer , piece , recovery , tests * adds resilience , swarm health , monitoring * adds swarm health, metrics , resilience logic * adds refactors , tests , docs , removes dead code paths * adds ssl , tls , per-peer logic , handshakes , encryption , docs, lints, tests , xet , fixes * adds benchs * adds language, docs , bugfix , transactions, swarms , metrics, interface * adds peer selection , partially solves dht and swarm health bugs * adds tests, bugfixes, queues, config parity , peer discovery, adaptations, profiles, docs lints, and tests * adds bugfix, hydration , pools , connections, tests, and more * adds reactive ui , and connection improvements * fixes bench * adds bench to outside commits --------- * Adds compatibility checks (#26) * init * initial release * adds initial systems * adds ci docs fix * adds ci docs fix 2 * fix documentation blog error / bug * fix documentation blog error / bugs * fix docs monkey patch * fix docs import path * fix import path with import lib * attempts Inline patch script for GitHub CI * attempts docs fix * use extend for i18nfiles * use extend for i18nfiles * adds refactor , docs , translations , pre commit , lints , tests , session , xet, ipfs , benchmarks , bug fixes , peer , piece , executor , daemon , cli , config, and more * adds refactor , docs , translations , pre commit , lints , tests , session , xet, ipfs , benchmarks , bug fixes , peer , piece , executor , daemon , cli , config, and more * adds uv docs fix * solves test failures , lint checks , ci docs build , main / dev branch ci separation , adds fixes for bugs identified while testing , refactors tests , and more ! * solves test failures , lint checks , ci docs build , main / dev branch ci separation , adds fixes for bugs identified while testing , refactors tests , and more ! * solves test failures , lint checks , ci docs build , main / dev branch ci separation , adds fixes for bugs identified while testing , refactors tests , and more ! * solves test failures , lint checks , ci docs build , main / dev branch ci separation , compatibility tests, adds missing deps * Addssessionrefactor (#6) * solves test failures , lint checks , ci docs build , main / dev branch ci separation , adds fixes for bugs identified while testing , refactors tests , and more ! * solves test failures , lint checks , ci docs build , main / dev branch ci separation , compatibility tests, adds missing deps * improves ci/cd workflows , permissions , and so on * adds docs fixes * adds docs fixes , compatibility fixes , lint , ci , precommit improvements * adds docs fixes , compatibility fixes , lint , ci , precommit improvements * adds docs fixes , compatibility fixes , lint , ci , precommit improvements * adds docs fixes , compatibility fixes , lint , ci , precommit improvements * adds docs fixes , compatibility fixes , lint , ci , precommit improvements * solves failing tests and timeouts, adds testing fixtures * adds docs fixes , compatibility fixes , lint , ci , precommit improvements * solves failing tests and timeouts, adds testing fixtures * adds rebase * Addscom (#8) * adds docs fixes , compatibility fixes , lint , ci , precommit improvements * adds cheaper ci and adds lints * adds streaming media / vlc , adds xet implementation , adds bugfix dht peer and connection discorvery * Update .gitignore * Update .github/workflows/release.yml * solves review comments * adds BEP 44 server , client , bugfix , swarm * adds code quality * adds dht guards * solves review comments * solves review comments * solves review comments * adds bugfixes , xet, tests , lints * solves failing tests and some warnings * adds improvements * adds solutions * adds changes * adds transaction , peer , piece , recovery , tests * adds resilience , swarm health , monitoring * adds swarm health, metrics , resilience logic * adds refactors , tests , docs , removes dead code paths * adds ssl , tls , per-peer logic , handshakes , encryption , docs, lints, tests , xet , fixes * adds benchs * adds language, docs , bugfix , transactions, swarms , metrics, interface * adds peer selection , partially solves dht and swarm health bugs * adds tests, bugfixes, queues, config parity , peer discovery, adaptations, profiles, docs lints, and tests * adds bugfix, hydration , pools , connections, tests, and more * adds reactive ui , and connection improvements * fixes bench * adds bench to outside commits * adds compatibility tests and checks --------- * Adds Compatibility and Improvements (#27) Remove frozen+slots dataclass combo that broke test collection on all Python versions, add dedup.aclose() to satisfy SLF001, commit dev/scripts by un-ignoring that directory, and fix integration tests uncovered by pre-commit. * Fix SwarmTimeoutSignals dataclass and XET shutdown lint on addscompat1. Remove broken frozen+slots decorators that blocked all CI imports, use dedup.aclose() for SLF001, and stabilize MSE loopback handshake timeout under pre-commit load. * Split CI test matrix into shards with 90-minute job timeouts. Shard pytest across four path groups, raise per-test timeout to 600s in CI, merge coverage on ubuntu 3.11, and fix hangs plus stale test stubs for discovery config, pool warmup, and tracker quarantine tiers. * Fix CI failure patterns across shards and Windows patch targets. Remove missing unit-rest shard path, expose peer/config submodules for unittest.patch, fix IPC daemon fixtures, peer connect test isolation, resume TorrentParser mock, UTP socket_manager attribute, and coverage combine when shards produce no data. * solves additional compatibility tests and checks * Fix package import shadowing that broke unittest.patch across CI. Stop ccbt top-level imports from binding peer/config submodules over packages, expose patch targets on package __init__ modules, harden conftest registration, and fix peer/UTP/MSE test flakes seen in run 29068108885. * Fix unittest.patch targets for CLI and config mocks in CI tests. Stop ccbt.cli.main from being shadowed by the main() export, patch get_config where production code imports it, and harden peer connect tests against stray background tasks that caused Linux CI timeouts. * Fix remaining CI timeouts and CLI config test assertions. Disable connection pool warmup in swarm-recovery peer tests, simplify global stats coverage to mock sessions, skip flaky XET manifest test on GitHub Actions, and align config exception tests with config show behavior. * Fix py3.9 loop, Windows timing, and flaky CI test failures. Use pytest_asyncio fixtures for asyncio queue/event tests, rewrite MSE RC4 handshake with real TCP, skip IP_RECVTOS checks on older Python, relax disk batch timing on Windows, and skip slow XET metadata tests in GitHub Actions. * adds improvements * adds downloads , peer and torrent logic and interface * adds swarm health improvements * improves swarm health --------- * Prepare 0.1.0 release: green CI tests and version gate. (#28) Align failing tests/fixtures with current peer, scrape, magnet, and config behavior; bump to 0.1.0 with changelog; harden benchmark CI against older main configs. Normalize flat announce_list in get_torrent_info and stabilize session/MSE unit tests that blocked local pre-commit. * Fix remaining PR #3 CI failures after merge to dev. (#29) Align session/DHT/tracker/MSE tests with current code, stop FakePeerManager from leaking across tests, and resolve base benchmark config against the base worktree so older main's docs/examples path is not overwritten by HEAD docs/en. * Fix remaining PR #3 CI flakes and base benchmark JSON (#30) Fix remaining PR #3 CI flakes and base benchmark JSON. Isolate XET temp stores, harden MSE/timeout tests, and overlay HEAD bench harness onto older main worktrees so hash_verify emits CI artifacts. * Fix remaining PR #3 CI failures after #30 (#31) Fix remaining PR #3 CI failures after #30 merge. Rebind XET DB locks per event loop for py3.9, skip real UDP binds in test_mode, stabilize scrape/progress mocks, and fall back to legacy --output-dir for base benchmarks instead of overlaying HEAD harnesses. * Fix flaky download-rate assertion under CI load. (#32) Freeze wall clock in TestDownloadRate so elapsed time is exact instead of depending on scheduling skew. * Fix MSE false-positive legacy type detection on modern frames. (#33) * Wait for Test/CI before docs and publish-dev gates (#34) * Wait for Test and CI before docs/publish validation gates. * Track .github/scripts wait helper for validation gates. * Document validation wait behavior for docs and publish-dev. * Fix MSE wrong-type coverage tests after legacy detection change (#35) Align MSE wrong-type coverage tests with legacy-only detection. Short transcript frames no longer trip Expected RKEYE/SKEYE/CRYPTO after #33; use full DH-sized legacy payloads so unit-rest stays green.
Greptile Summary
This PR wires up the XET ("scientific") workspace transport layer: it introduces per-workspace
XetFolderRuntimeownership, a_xet_transport_registryon the session manager, a shared XET discovery graph (CAS client, bloom filter, catalog, LPD, multicast, gossip, flooding),MediaStreamManagerintegration, and canonical internal status models (CanonicalTorrentStatus/CanonicalGlobalStats). It also ships several correctness fixes: BEP 44 mutable-signing now uses the spec-compliant bencoded buffer, DHT index decoding is fixed,XetDeduplication.close()is made idempotent,_cache_infono longer races the dedup connection with a rawsqlite3.connect(),tonic?:URI parsing is corrected, and inline debug log blocks are removed fromsession.py.key_managersilently discarded:AsyncSessionManager.__init__assignsself.key_manager = key_managerfrom the parameter at line 3490, then unconditionally overwrites it withself.key_manager: Optional[Any] = Noneat line 3565. Any caller that passes a live key manager (e.g., the daemon startup path) will have it silently replaced withNone, breaking XET identity, allowlist loading, and node-ID generation.salt + seq.to_bytes(8, "big") + data) to the correct BEP 44 bencoded buffer. This is spec-correct, but all mutable data stored by previous builds will fail signature verification after upgrade. There is no migration or fallback path.DESIGNATEDmode always downgrades at start:XetSyncManager.start()calls_has_verified_designated_source()before any peer connections exist. The check iterates active torrent peer managers, which are empty at workspace-open time, and always returnsFalse— causing everyDESIGNATED-mode workspace to silently downgrade toBEST_EFFORTon startup.Confidence Score: 2/5
ccbt/session/session.py(key_manager double assignment),ccbt/discovery/dht_storage.py(BEP 44 migration),ccbt/session/xet_sync_manager.py(DESIGNATED mode startup check)Important Files Changed
key_managerparameter is overwritten withNonelater in__init__, silently breaking XET identity and signing.Sequence Diagram
Comments Outside Diff (1)
ccbt/session/session.py, line 154-155 (link)Silent DHT behavior change: now initializes for every
.torrentfile whenenable_dht=TruePreviously DHT only initialized when the caller passed
--enable-dhtexplicitly or the torrent was a magnet link. The guarddht_explicitly_requested or is_magnet_linkhas been removed, so now every.torrentfile download starts a DHT client whenconfig.discovery.enable_dht=True(the default).For users who have
enable_dht=Truein config (the default) and are downloading many.torrentfiles, this will:The commit message and inline comment describe this as an intentional change ("allow DHT as fallback for all torrents"), but the default config value
enable_dht=Truemeans all users get this behavior change transparently. If the intent is to allow opt-in, consider introducing a separateenable_dht_for_regular_torrentsconfig key, or document the intentional change in the PR description so it can be deliberately reviewed.Last reviewed commit: 4290693