Skip to content

[P2] feat(swarm): Implement Byzantine Swarm Protection - #614

Closed
fallofpheonix wants to merge 3 commits into
mainfrom
feature/issue-128-byzantine-protection
Closed

fallofpheonix wants to merge 3 commits into
mainfrom
feature/issue-128-byzantine-protection

Conversation

@fallofpheonix

@fallofpheonix fallofpheonix commented May 21, 2026

Copy link
Copy Markdown
Owner

Resolves #128. Implemented Proof-of-Authority consensus with weighted reputation quorum for swarm node agreement.

Summary by Sourcery

Introduce a reputation-weighted consensus module for swarm node agreement using quorum thresholds.

New Features:

  • Add ConsensusModule for managing node reputations and evaluating proposals against a weighted quorum.
  • Introduce configurable quorum weight for Proof-of-Authority style swarm consensus.

Tests:

  • Add unit test validating consensus behavior for proposals under and over the configured quorum weight.

Copilot AI review requested due to automatic review settings May 21, 2026 13:20
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@sourcery-ai

sourcery-ai Bot commented May 21, 2026

Copy link
Copy Markdown

Reviewer's Guide

Implements a new consensus module providing proof-of-authority style weighted reputation quorum for swarm node agreement, along with unit tests validating quorum behavior.

Sequence diagram for node proposal using ConsensusModule.Propose

sequenceDiagram
    participant Node
    participant ConsensusModule

    Node->>ConsensusModule: Propose(nodeID, reputation)
    activate ConsensusModule
    ConsensusModule->>ConsensusModule: NodeReputation[nodeID] = reputation
    ConsensusModule->>ConsensusModule: [calculate totalWeight]
    ConsensusModule-->>Node: bool (quorum and authority decision)
    deactivate ConsensusModule
Loading

File-Level Changes

Change Details Files
Introduce a PoA-style consensus module with weighted reputation quorum for swarm nodes.
  • Add ConsensusModule struct encapsulating node reputation map, quorum threshold, and concurrency protection via RWMutex
  • Provide constructor NewConsensusModule to initialize consensus module with configurable quorum weight and empty reputation store
  • Implement Propose method that updates a node’s reputation, recalculates total reputation weight, and approves proposals when node reputation and overall quorum thresholds are met
phoenix_os/agents/internal/swarm/consensus.go
Add unit tests to validate quorum behavior for the consensus module.
  • Create TestConsensus to assert that proposals fail when total reputation weight is below quorum despite sufficient individual reputation
  • Extend TestConsensus to assert that proposals succeed once cumulative reputation meets or exceeds the configured quorum weight
phoenix_os/agents/internal/swarm/consensus_test.go

Assessment against linked issues

Issue Objective Addressed Explanation
#128 Implement a Proof-of-Authority consensus mechanism using node reputation scores and a weighted quorum for swarm node agreement
#128 Introduce a node reputation scoring mechanism to influence consensus decisions
#128 Add governance-related tests covering consensus, reputations, and quorum behavior The PR adds a basic unit test for quorum behavior in consensus_test.go, but it does not include any explicit governance-related tests (e.g., tests for governance rules, authority assignments, or reputation governance workflows) as implied by the issue scope of “governance tests.”

Possibly linked issues

  • [P2] [Phoenix Arbiter] Implement Byzantine Swarm Protection #128: PR implements PoA, node reputation, and weighted quorum consensus with tests, matching the issue’s Byzantine Swarm Protection scope.
  • #INTEGRATION Arbiter: PR implements the reputation-weighted quorum consensus mechanism requested by the Arbiter integration issue.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai

coderabbitai Bot commented May 21, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@fallofpheonix has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 50 minutes and 50 seconds before requesting another review.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 251c269e-6817-4414-853e-e2ff4a6008a1

📥 Commits

Reviewing files that changed from the base of the PR and between 955720d and 0ec116a.

⛔ Files ignored due to path filters (6)
  • agents/surface/orchestrator/__pycache__/api.cpython-313.pyc is excluded by !**/*.pyc
  • agents/surface/orchestrator/__pycache__/github_cli.cpython-313.pyc is excluded by !**/*.pyc
  • agents/surface/orchestrator/__pycache__/minimal_brain.cpython-313.pyc is excluded by !**/*.pyc
  • agents/surface/orchestrator/__pycache__/minimal_brain_test.cpython-313-pytest-9.0.3.pyc is excluded by !**/*.pyc
  • agents/surface/orchestrator/__pycache__/service.cpython-313.pyc is excluded by !**/*.pyc
  • go.work is excluded by !**/*.work
📒 Files selected for processing (25)
  • 02_docs/architecture/23-sentinel_game_features.md
  • 02_docs/architecture/24-cloud-distributed_features.md
  • 02_docs/architecture/25-cyber_micro_features.md
  • 02_docs/architecture/26-brain_architecture.md
  • 02_docs/validation/architecture_health.md
  • 02_docs/validation/dependency_graph.md
  • 02_docs/validation/doc_change_log.md
  • 02_docs/validation/feasibility_report.md
  • 02_docs/validation/idea_validation.md
  • 02_docs/validation/implementation_order.md
  • 02_docs/validation/project_status.md
  • 02_docs/validation/risk_register.md
  • 02_docs/validation/validation_summary.md
  • 06_ai/importance_scoring/scorer.go
  • 06_ai/importance_scoring/scorer_test.go
  • 20_brain/README.md
  • agents/surface/orchestrator/README.brain.md
  • agents/surface/orchestrator/brain_cli.py
  • agents/surface/orchestrator/minimal_brain.py
  • agents/surface/orchestrator/minimal_brain_test.py
  • phoenix_os/agents/internal/swarm/agent/swarm_agent.go
  • phoenix_os/agents/internal/swarm/consensus.go
  • phoenix_os/agents/internal/swarm/consensus_test.go
  • phoenix_os/common/scoring.go
  • swarm
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/issue-128-byzantine-protection

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 and usage tips.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 2 issues, and left some high level feedback:

  • The consensus rule currently hardcodes a proposer reputation threshold of 0.5; consider making this configurable or derived from QuorumWeight to avoid embedding policy in code and to support different PoA configurations.
  • The Propose method both mutates node reputation state and evaluates consensus in one step; consider separating state updates (e.g., UpdateReputation) from proposal evaluation to clarify intent and make the module easier to reuse and test.
  • Node reputations are appended to the NodeReputation map and never pruned, which can cause unbounded growth in long-running swarms; consider adding a lifecycle strategy (e.g., eviction, decay, or explicit removal) for inactive or outdated nodes.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The consensus rule currently hardcodes a proposer reputation threshold of 0.5; consider making this configurable or derived from `QuorumWeight` to avoid embedding policy in code and to support different PoA configurations.
- The `Propose` method both mutates node reputation state and evaluates consensus in one step; consider separating state updates (e.g., `UpdateReputation`) from proposal evaluation to clarify intent and make the module easier to reuse and test.
- Node reputations are appended to the `NodeReputation` map and never pruned, which can cause unbounded growth in long-running swarms; consider adding a lifecycle strategy (e.g., eviction, decay, or explicit removal) for inactive or outdated nodes.

## Individual Comments

### Comment 1
<location path="phoenix_os/agents/internal/swarm/consensus.go" line_range="36" />
<code_context>
+	// Propose evaluates a proposal based on weighted reputation quorum.
</code_context>
<issue_to_address>
**issue (bug_risk):** Guard against invalid or unexpected reputation values

Currently any `reputation` value is accepted, including negatives or very large values, which can distort `totalWeight` and undermine the quorum check (e.g., from a misconfigured node). If the scale is meant to be bounded (such as [0,1] or [0,100]), validate or clamp `reputation` before using it, and consider rejecting proposals when values are out of range.
</issue_to_address>

### Comment 2
<location path="phoenix_os/agents/internal/swarm/consensus_test.go" line_range="15-16" />
<code_context>
+		t.Error("Proposal should fail due to insufficient quorum")
+	}
+
+	// Node 2 joins
+	if !cm.Propose("node-2", 1.0) {
+		t.Error("Proposal should pass with sufficient quorum")
+	}
</code_context>
<issue_to_address>
**suggestion (testing):** Add a test for repeated proposals and reputation updates for the same node

Because `Propose` overwrites `NodeReputation[nodeID]`, please add a test that calls `Propose` multiple times for the same `nodeID` with different reputations to confirm quorum calculations update correctly and don’t double-count or miss updated weights.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

}

// Agreement reached if proposer has sufficient reputation and total quorum is met
if reputation > 0.5 && totalWeight >= cm.QuorumWeight {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): Guard against invalid or unexpected reputation values

Currently any reputation value is accepted, including negatives or very large values, which can distort totalWeight and undermine the quorum check (e.g., from a misconfigured node). If the scale is meant to be bounded (such as [0,1] or [0,100]), validate or clamp reputation before using it, and consider rejecting proposals when values are out of range.

Comment on lines +15 to +16
// Node 2 joins
if !cm.Propose("node-2", 1.0) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (testing): Add a test for repeated proposals and reputation updates for the same node

Because Propose overwrites NodeReputation[nodeID], please add a test that calls Propose multiple times for the same nodeID with different reputations to confirm quorum calculations update correctly and don’t double-count or miss updated weights.

@fallofpheonix

Copy link
Copy Markdown
Owner Author

Closing: The Byzantine Swarm Protection module has been superseded by the PhoenixOS architectural pivot. The speculative agents/internal/swarm/ module has been deleted as part of the Phase 1 consolidation. PhoenixOS Axiom #6 states: 'Never scale instability — single-node stability must be achieved before distributed scaling.' Distributed consensus belongs to Phase 3+ (L7: Swarm Coordination). The underlying concepts will be re-evaluated once deterministic single-node replay is proven and real eBPF telemetry is operational.

@fallofpheonix
fallofpheonix deleted the feature/issue-128-byzantine-protection branch May 21, 2026 23:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[P2] [Phoenix Arbiter] Implement Byzantine Swarm Protection

2 participants