Skip to content

fix: a node answers a PING flood exactly once - #196

Merged
JarbasAl merged 2 commits into
devfrom
fix/ping-flood-single-identity
Aug 3, 2026
Merged

fix: a node answers a PING flood exactly once#196
JarbasAl merged 2 commits into
devfrom
fix/ping-flood-single-identity

Conversation

@JarbasAl

@JarbasAl JarbasAl commented Aug 3, 2026

Copy link
Copy Markdown
Member

The bug

A node that has an upstream runs two protocol objects at the same time:
this HiveMindListenerProtocol, serving its downstream clients, and a
HiveMindSlaveProtocol (hivemind-bus-client) holding the connection to its
upstream. They are two halves of one node.

Each half kept its own flood_id cache — self._seen_flood_ids here,
hive_mapper.check_flood_id there — so a single PING flood got two answers
from one node. Worse, the two answers carried different identities: the
slave answers as name::session_id, this side as its public key. The
originator recorded two nodes where there was one, and every node with an
upstream added a phantom entry to the map.

What the spec says

HIVEMIND-NODE-1 §4: a PING fans out across the mesh, "each recipient replies
with its own PING carrying the same flood_id, and nodes drop messages whose
flood_id they have already seen (HIVEMIND-MSG-1 §4)". The subject is the
node, not the connection.

The change

One flood cache per node. bind_upstream already wires the two halves
together, so that is where they are given one shared cache
(slave.bind_flood_cache(self._seen_flood_ids)). The first half to see a
flood_id now suppresses the other. _seen_flood_ids becomes a
FloodIdCache — still set-like (in, .add(), len()), so every existing
caller and test is unaffected, and it now bounds itself by FIFO eviction
instead of set.pop(), which evicted an arbitrary entry.

A node with no upstream never reaches bind_upstream and still answers
exactly once, through the listener. This is not "one side stops responding".

One identity per node. The responsive PING now carries public_key. The
slave half already sent it; without it here, a master-only node had no stable
identity in the payload at all, so a consumer could not tell whether two
peer labels named one node or two.

On the peer field itself: it stays the connection-level label. Keying the
mapper on public_key instead was considered and rejected — a PEM blob is a
poor map key, and it would not have merged anything here anyway, because the
two halves of a node are separate identities with separate keys. The fix that
actually holds is the shared cache, which means only one identity is ever
announced per node per flood; public_key on both sides then makes that one
announcement self-describing.

Landing order

hivemind-bus-client PR #161 must land first. This PR imports
FloodIdCache, calls bind_flood_cache, and pins
hivemind_bus_client>=0.11.0a2.

Verification

Live, on a real three-node socket mesh (master 6678 ← middle 6680 ← leaf),
one real PING flood:

Before (origin/dev):

middle upstream bound; shares one flood cache with listener=False
total answers for this flood: 3
  answered 1x  peer='middle::8d60ade6-...'
  answered 1x  peer='-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkq...'   <-- same node
  answered 1x  peer='leaf::aff819a7-...'
node count: 3

After:

middle upstream bound; shares one flood cache with listener=True
total answers for this flood: 2
  answered 1x  peer='middle::a1a9c6b8-...'  pubkey~MIIBIjANBgkqhkiG9w0BAQEFAA
  answered 1x  peer='leaf::e92e8ef5-...'    pubkey~MIIBIjANBgkqhkiG9w0BAQEFAA
node count: 2

Tests

  • tests/test_ping_flood_dedup.py — 9 new tests: bind_upstream shares the
    cache, suppression in both directions, a node without an upstream still
    answers exactly once, malformed PING never answered, cache stays bounded,
    and both halves announce the same public key.
  • Fail-on-old (git stash of hivemind_core/, new bus-client in place):
    6 of 9 failthe two halves of one node must share one flood cache,
    both suppression assertions, and KeyError: 'public_key' twice. The 3 that
    pass are the no-upstream cases, confirming that path is unchanged.
  • Full unit suite: 215 passed, 1 skipped.
  • hivemind-test-harness (PR feat:encrypted_json_db #20 branch): the 5 documented PING regressions now
    pass. Full in-process protocol layer 203 passed / 8 failed, and all 8 are
    the other documented open regression (PROPAGATE/BROADCAST of
    THIRDPRTY asserting in the bus client) — untouched by this PR.
  • Spec-MUST gate: 11 passed / 1 xfailed, unchanged.

🤖 Generated with Claude Code

A node that has an upstream runs two protocol objects at the same time:
this HiveMindListenerProtocol, serving its downstream clients, and a
HiveMindSlaveProtocol holding the connection to its upstream. They are
two halves of one node.

Each half kept its own flood_id cache, so a single PING flood got two
answers from one node. Worse, the two answers carried different
identities: the slave answers as its connection peer, the listener as
its public key. The originator recorded two nodes where there was one,
and every node with an upstream added a phantom entry to the map.

HIVEMIND-NODE-1 §4 gives the node, not the connection, exactly one part
in a flood. bind_upstream already wires the two halves together, so it
is also where they are given one shared cache: the first half to see a
flood_id now suppresses the other. A node with no upstream never gets
there and still answers exactly once.

The responsive PING also carries public_key now. The slave half already
sent it; without it on this side, a master-only node had no stable
identity in the payload at all, and a consumer could not tell whether
two peer labels named one node or two.

Needs hivemind_bus_client>=0.11.0a2 for FloodIdCache and
bind_flood_cache.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@JarbasAl, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 11 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: d23e081a-3380-43fb-aac7-800d3bc4857c

📥 Commits

Reviewing files that changed from the base of the PR and between fb923e3 and 9852a2a.

📒 Files selected for processing (3)
  • hivemind_core/protocol.py
  • pyproject.toml
  • tests/test_ping_flood_dedup.py

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added the fix label Aug 3, 2026
@github-actions

github-actions Bot commented Aug 3, 2026

Copy link
Copy Markdown

The results are in! Let's see how your PR is doing. 📊

I've aggregated the results of the automated checks for this PR below.

📋 Repo Health

Ensuring the repo is staying active (aka commit frequency). 🏃‍♂️

✅ All required files present.

Latest Version: 4.11.1a3

hivemind_core/version.py — Version file
README.md — README
LICENSE — License file
pyproject.toml — pyproject.toml
⚠️ setup.py — setup.py
CHANGELOG.md — Changelog
hivemind_core/version.py has valid version block markers

📊 Coverage

Mapping the landscape of your tests. 🗺️

31.7% total coverage

Per-file coverage (9 files)
File Coverage Missing lines
hivemind_core/__init__.py 0.0% 2
hivemind_core/__main__.py 0.0% 24
hivemind_core/database.py 0.0% 66
hivemind_core/scripts.py 0.0% 430
hivemind_core/service.py 0.0% 164
hivemind_core/version.py 0.0% 5
hivemind_core/config.py 46.0% 27
hivemind_core/protocol.py 48.9% 557
hivemind_core/policy.py 50.0% 66

Full report: download the coverage-report artifact.

🏷️ Release Preview

Ensuring our release announcement is ready for prime time. 📺

Current: 4.11.1a3Next: 4.11.2a1

Signal Value
Label fix
PR title fix: a node answers a PING flood exactly once
Bump build

✅ PR title follows conventional commit format.


🚀 Release Channel Compatibility

Predicted next version: 4.11.2a1

Channel Status Note Current Constraint
Stable Not in channel -
Testing Compatible hivemind-core>=4.0.0,<5.0.0
Alpha Compatible hivemind-core>=4.11.0a1

🔍 Lint

The automated report has been generated. 🖨️

ruff: issues found — see job log

🔨 Build Tests

I've checked the welds on your new features. 👨‍🏭

✅ All versions pass

Python Build Install Tests
3.10
3.11
3.12
3.13

🔒 Security (pip-audit)

I've checked the security of our API endpoints. 🌐

✅ No known vulnerabilities found (78 packages scanned).

⚖️ License Check

Double-checking the fine print for any surprises. 🔍

✅ No license violations found.

Policy: Apache 2.0 (universal donor). StrongCopyleft / NetworkCopyleft / WeakCopyleft / Other / Error categories fail. MPL allowed.


Your 24/7 automated code reviewer 🌙

@JarbasAl
JarbasAl marked this pull request as ready for review August 3, 2026 23:13
@JarbasAl
JarbasAl merged commit 69dc247 into dev Aug 3, 2026
13 checks passed
@JarbasAl
JarbasAl deleted the fix/ping-flood-single-identity branch August 3, 2026 23:13
JarbasAl added a commit that referenced this pull request Aug 3, 2026
…_flood attrs

handle_ping_message now reads self.ping_flood_interval and self._last_ping_flood
(added by the ping-flood rate limiter); the object.__new__-constructed test
double in test_ping_flood_dedup.py (owned by #196, already on dev) predates
those attributes and needs them set explicitly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant