Skip to content

[Issue #707] Implement Byzantine-Resistant Quorum - #710

Merged
fallofpheonix merged 1 commit into
mainfrom
feature/707-byzantine-resistant-quorum-clean
May 21, 2026
Merged

fallofpheonix merged 1 commit into
mainfrom
feature/707-byzantine-resistant-quorum-clean

Conversation

@fallofpheonix

@fallofpheonix fallofpheonix commented May 21, 2026

Copy link
Copy Markdown
Owner

Problem

The Nexus lacks a mechanism to prevent swarm-wide self-DoS (Byzantine swarm poisoning) by compromised nodes.

Changes

  • Created agents/internal/swarm/reputation.go for node reputation tracking.
  • Created phoenix_os/arbiter/consensus.go for weighted quorum voting logic.
  • Implemented EvaluateQuorum based on reputation-weighted confidence.

Tests

  • unit tests passed in agents/internal/swarm
  • unit tests passed in phoenix_os/arbiter

Risk

Medium

Closes #707

Summary by Sourcery

Introduce a reputation-weighted consensus mechanism to harden swarm quorum decisions against compromised nodes.

New Features:

  • Add swarm ReputationStore for tracking and updating node trust scores.
  • Add arbiter ConsensusEngine that computes quorum decisions based on reputation-weighted votes.

Tests:

  • Add unit tests for ReputationStore behavior and reputation updates.
  • Add unit tests validating consensus outcomes with differing node reputations.

Copilot AI review requested due to automatic review settings May 21, 2026 14:22
@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.

@fallofpheonix
fallofpheonix merged commit 5e67ef9 into main May 21, 2026
2 checks passed
@sourcery-ai

sourcery-ai Bot commented May 21, 2026

Copy link
Copy Markdown

Reviewer's Guide

Introduces a reputation-backed consensus mechanism where quorum decisions are weighted by node trust scores, implementing a ReputationStore for node reputation and a ConsensusEngine that uses those scores and per-vote confidence to evaluate quorum, along with unit tests and module wiring.

Sequence diagram for EvaluateQuorum using ReputationStore

sequenceDiagram
    participant Arbiter
    participant ConsensusEngine
    participant ReputationStore

    Arbiter->>ConsensusEngine: SubmitVote(vote)
    ConsensusEngine-->>Arbiter: (ack)

    Arbiter->>ConsensusEngine: EvaluateQuorum()
    loop for each vote
        ConsensusEngine->>ReputationStore: GetReputation(nodeID)
        ReputationStore-->>ConsensusEngine: reputation
        Note over ConsensusEngine: accumulate weightedTotal
    end
    ConsensusEngine-->>Arbiter: quorumReached(bool)
Loading

File-Level Changes

Change Details Files
Add in-memory, concurrency-safe node reputation store used by swarm and arbiter components.
  • Introduce ReputationStore struct with RWMutex and map-backed storage of nodeID to float64 reputation values.
  • Implement UpdateReputation to atomically adjust reputation deltas while clamping at zero to avoid negative scores.
  • Implement GetReputation with read-locking for concurrent-safe reads.
  • Add basic unit test validating that reputation updates are persisted and readable.
  • Add go.mod for the swarm internal module to declare its module path.
agents/internal/swarm/reputation.go
agents/internal/swarm/reputation_test.go
agents/internal/swarm/go.mod
Implement a reputation-weighted consensus engine that computes quorum based on trusted votes.
  • Define Vote struct capturing node ID, boolean decision, and a confidence weight.
  • Add ConsensusEngine struct with mutex, attached ReputationStore, in-memory vote slice, and configurable threshold.
  • Implement NewConsensusEngine constructor wiring in the reputation store and initializing internal state.
  • Implement SubmitVote to append votes under lock for thread-safe accumulation.
  • Implement EvaluateQuorum to compute a reputation- and confidence-weighted ratio of true votes, defaulting zero-reputation nodes to minimal weight and comparing the normalized score against the configured threshold.
  • Introduce unit test that ensures high-reputation nodes can outweigh low-reputation dissenters when evaluating quorum.
  • Adjust arbiter module metadata by simplifying go.mod contents.
phoenix_os/arbiter/consensus.go
phoenix_os/arbiter/consensus_test.go
phoenix_os/arbiter/go.mod

Assessment against linked issues

Issue Objective Addressed Explanation
#707 Implement a node reputation tracking mechanism in the swarm subsystem to support reputation-weighted decisions.
#707 Implement a reputation-weighted quorum consensus mechanism in the Phoenix Arbiter (L7 Nexus) to provide Byzantine-resistant quorum evaluation and mitigate swarm-wide self-DoS.

Possibly linked issues


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 51 minutes and 51 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: d33b5f35-5e44-4a4d-bfdf-10ef46c22df3

📥 Commits

Reviewing files that changed from the base of the PR and between cef3a28 and 058c5b6.

📒 Files selected for processing (6)
  • agents/internal/swarm/go.mod
  • agents/internal/swarm/reputation.go
  • agents/internal/swarm/reputation_test.go
  • phoenix_os/arbiter/consensus.go
  • phoenix_os/arbiter/consensus_test.go
  • phoenix_os/arbiter/go.mod
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/707-byzantine-resistant-quorum-clean

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.

@fallofpheonix
fallofpheonix deleted the feature/707-byzantine-resistant-quorum-clean branch May 21, 2026 14:23

@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 left some high level feedback:

  • In ConsensusEngine, EvaluateQuorum never clears or time-bounds votes, so decisions will accumulate all historical votes and the slice will grow unbounded; consider either resetting votes after evaluation or scoping them to a particular round/epoch.
  • The combination of ReputationStore.GetReputation defaulting to 0 and EvaluateQuorum treating rep == 0 as a missing value (and forcing it to 1.0) makes it impossible to distinguish unknown nodes from nodes explicitly driven to zero reputation; consider adding explicit defaults in the store or returning presence information so zero-rep can be meaningfully represented.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `ConsensusEngine`, `EvaluateQuorum` never clears or time-bounds `votes`, so decisions will accumulate all historical votes and the slice will grow unbounded; consider either resetting `votes` after evaluation or scoping them to a particular round/epoch.
- The combination of `ReputationStore.GetReputation` defaulting to `0` and `EvaluateQuorum` treating `rep == 0` as a missing value (and forcing it to `1.0`) makes it impossible to distinguish unknown nodes from nodes explicitly driven to zero reputation; consider adding explicit defaults in the store or returning presence information so zero-rep can be meaningfully represented.

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.

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.

Pull request overview

Implements a reputation-weighted quorum mechanism intended to make Nexus/Arbiter consensus more Byzantine-resistant by weighting votes based on node reputation and vote confidence.

Changes:

  • Added a new ReputationStore for tracking per-node reputation.
  • Added a new ConsensusEngine with vote submission and quorum evaluation.
  • Added unit tests for both reputation tracking and quorum evaluation.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
phoenix_os/arbiter/go.mod Removes the module go directive; currently leaves the module without explicit Go version/deps.
phoenix_os/arbiter/consensus.go Introduces the weighted quorum voting engine.
phoenix_os/arbiter/consensus_test.go Adds a unit test for the quorum evaluation behavior.
agents/internal/swarm/reputation.go Adds a reputation store for tracking node trust values.
agents/internal/swarm/reputation_test.go Adds a unit test for the reputation store.
agents/internal/swarm/go.mod Introduces a nested Go module for the new swarm reputation package.
Comments suppressed due to low confidence (2)

phoenix_os/arbiter/go.mod:2

  • Removing the go directive from this go.mod makes the module’s language/version semantics implicit and inconsistent with the other Go modules in this repo (and with the root go.work’s go 1.26). Re-add an explicit go version (matching the workspace/toolchain) to avoid surprising module behavior.
module phoenix/arbiter

phoenix_os/arbiter/go.mod:2

  • consensus.go introduces a non-stdlib import, but this go.mod currently has no require entries. Even with go.work, the arbiter module will need a require on the module that provides the imported package (with the workspace supplying the local replacement), otherwise go test/go build will report “no required module provides package …”.
module phoenix/arbiter


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +3 to +8
import (
"sync"
"time"

"phoenix/agents/internal/swarm"
)
Comment on lines +48 to +51
if v.Decision {
weightedTotal += rep * v.Confidence
}
totalReputation += rep
Comment on lines +31 to +35
func (e *ConsensusEngine) SubmitVote(v Vote) {
e.mu.Lock()
defer e.mu.Unlock()
e.votes = append(e.votes, v)
}
Comment on lines +4 to +9
"phoenix/agents/internal/swarm"
"testing"
)

func TestConsensusEngine(t *testing.T) {
rep := swarm.NewReputationStore()
Comment on lines +8 to +23
func TestConsensusEngine(t *testing.T) {
rep := swarm.NewReputationStore()
rep.UpdateReputation("node1", 10.0) // High trust
rep.UpdateReputation("node2", 1.0) // Low trust

engine := NewConsensusEngine(rep, 0.5)

// High trust node votes true
engine.SubmitVote(Vote{"node1", true, 0.9})
// Low trust node votes false
engine.SubmitVote(Vote{"node2", false, 0.9})

if !engine.EvaluateQuorum() {
t.Error("Expected quorum to be true based on high trust node")
}
}
@@ -0,0 +1 @@
module phoenix/swarm
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-Resistant Quorum

2 participants