Repository navigation
dream(performance): #4214 RaftConsensus.awaitConsensus() busy-poll → event-driven (evaluated, ACCEPT) - #4215
Merged
Merged
Conversation
… event-driven RaftConsensus.awaitConsensus() polled this.proposals via setInterval(...,10) even though checkConsensus() already emits 'consensus.achieved' on every accept/reject transition. Raft is Ruflo's default hive-mind consensus algorithm, reachable from production via UnifiedSwarmCoordinator.proposeConsensus(). Third instance of a busy-poll bug class already fixed twice (UnifiedSwarmCoordinator #3378, MessageBus #3563). 4 new discriminating tests, stash-isolated baseline-fails/candidate-passes (3/4, 1 correct non-discriminating control), independently reproduced by an adversarial critic. Full @claude-flow/swarm suite 281/281 (277 existing + 4 new), tsc clean both ways. Standalone wall-clock probe: 3.639ms/30 poll-timers -> 0.058ms/0 timers (N=30). Also closes a 3-night research thread (10-09/10-10/10-14) on graph-analyzer.ts's dead native-acceleration detection: direct inspection shows ruvector's real minCut/louvainCommunities exports are plain JS, not native-accelerated, so wiring them in would not be a performance win (REJECT, with evidence). Co-Authored-By: RuFlo <ruv@ruv.net> Claude-Session: https://claude.ai/code/session_01MFLiva2zVEXr2n9UTK5YgU
Fill in the real PR number (was a placeholder pending PR creation) in tonight's ledger row, and note the 10-12/10-13/10-14 ledger-transcription gap per the established convention. Co-Authored-By: RuFlo <ruv@ruv.net> Claude-Session: https://claude.ai/code/session_01MFLiva2zVEXr2n9UTK5YgU
ruvnet
marked this pull request as ready for review
October 17, 2026 13:59
This was referenced Oct 18, 2026
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.
1. Hypothesis
2. Candidate
v3/@claude-flow/swarm/src/consensus/raft.ts'sRaftConsensus.awaitConsensus()— Ruflo's default hive-mind consensus algorithm (config.algorithm ?? 'raft'in bothConsensusEngineandUnifiedSwarmCoordinator), reachable from production via the publicUnifiedSwarmCoordinator.proposeConsensus()API — busy-polledthis.proposals.get(proposalId)every 10ms viasetIntervaleven thoughcheckConsensus()(called fromvote()) already emits'consensus.achieved'on every pending→accepted/rejected transition.UnifiedSwarmCoordinatoritself already listens to that exact event (unified-coordinator.ts:712) for an unrelated purpose. Third instance of a bug class the ledger has fixed twice before (UnifiedSwarmCoordinator#3378 ~487x,MessageBus#3563 ~96.5% idle-tick reduction).Fix: synchronous status check first (unknown proposal → immediate throw; already-resolved → immediate return), otherwise listen for
'consensus.achieved'filtered byproposalId, with a singlesetTimeoutas the expiry fallback instead of a poll. Constructor addsthis.setMaxListeners(0)since listeners are now 1:1 with in-flight proposals (unbounded is correct — they're always cleaned up on resolution). Diff: 1 source file (~28 insertions / 19 deletions) + 1 new test file.3. Evaluation Receipt
Real evaluator: Vitest 4.1.8, deterministic, $0, zero LLM calls.
New test file
raft-await-consensus-event-driven.test.ts(4 tests). Stash-isolated baseline (git stashon justraft.ts): 3/4 fail exactly as predicted (setIntervalobserved called when asserted not-called; immediate-return case measured 11ms ≥ the <10ms bound; expiry case shows 5setIntervalcalls); the 4th (unknown-proposal-id immediate rejection, pre-existing behavior) passes both ways — a correct non-discriminating control. Candidate: 4/4 pass. Full@claude-flow/swarmsuite: 281/281 passed, 19/19 files green (277 pre-existing + 4 new), zero regressions.tsc --noEmit: clean, 0 errors, both ways.Standalone wall-clock probe (30 trials, vote arriving 3–9ms after
awaitConsensus()starts — deliberately off the old 10ms poll grid): baseline mean 3.639ms / max 7.492ms vote→resolve latency, 30setIntervaltimers created (1 per call); candidate mean 0.058ms / max 0.346ms, 0 timers created.4. Baseline Comparison
setIntervaltimers created while waitingProposal <id> not found@claude-flow/swarmsuitetsc --noEmit5. Darwin Lineage
Skipped — binary correctness/wiring fix (listen to an already-emitted event instead of polling), no continuous/categorical parameter for Darwin's real interface (
npx ruvector harness darwin <config> --execute, confirmed available in STEP 0.5) to search over. Same skip class as nearly every accepted fix since 2026-08-18.6. Flywheel Evidence
No
.claude-flow/flywheel/state exists in this repo.npx ruvector harness flywheel gate <evidence>requires a signed LLM-task-corpus replay-evidence schema not applicable to this deterministic fix class. Evidence retained as: the 4 new discriminating tests, the stash-isolated comparison (reproduced independently twice), the standalone latency probe, the full adversarial critique transcript, issue #4214, and the committed gist.7. Reward Hack Check
Clean — independently checked twice (by the authoring session, and by a separate adversarial-critic subagent with no authoring context): no test/threshold weakened, no gold data touched, no cherry-picking, no evaluator exploitation, no cost increase, no seed manipulation, no hidden preprocessing, no error suppression, no undocumented cache.
checkConsensus()'s pending-only guard (if (!proposal || proposal.status !== 'pending') return;) structurally prevents a double-fire of'consensus.achieved'for the same proposal.8. Security Review
Not security-sensitive — pure in-process
EventEmitterrewiring, no new I/O/network/credential/filesystem surface. Independent adversarial critique (separate subagent, no authoring context): CONFIRMED, no blocking issues. Verified: the bug claim by reading the full diff; baseline-fails/candidate-passes via its own stash/pop cycle; 200 concurrentawaitConsensus()calls on 200 distinct proposals resolve correctly with zero listener leak (listenerCount() === 0after); a same-tick timeout-vs-vote race (5 runs) produces no crash/double-resolve/leak;this.proposals.get(proposalId) ?? proposalfallback confirmed harmless dead code (nothing ever calls.delete()on the map).9. Regression Analysis
Zero regressions: full
@claude-flow/swarmsuite failed-file set unaffected (281/281, 277 pre-existing + 4 new),tsc --noEmitclean both ways. Only callers ofawaitConsensus()areunified-coordinator.ts:499(production) and the package's own tests (grep-confirmed).10. ADR
Not created — scoped wiring/correctness fix to an already-decided mechanism (consensus resolution should follow the event the module already emits), not a new architectural decision. Matches repo convention for this fix class (#3357/#3539/#3562/#3929 — none created an ADR).
11. Research Gist
docs/dream-cycle/dream-gist-2026-10-15.md(this branch) — full SOTA report: 5-role parallel research fan-out (deep researcher, 2 scan researchers, competitor analyst, direct architecture inspection), graded 2026 sources (MAFBench arXiv:2602.03128 grade B, "The Orchestrator Bottleneck" ICML 2026 grade A, CP-WBFT arXiv:2511.10400 grade B), a 5-row competitor comparison table, and closes a 3-night research thread ongraph-analyzer.ts's dead native-acceleration detection with direct-evidence REJECT. Nogh gist create/gist-equivalent MCP tool reachable this session (same disclosed FALLBACK as every night since 2026-09-30) — full report embedded in issue #4214 instead.12. Issue
Closes #4214 — full 15-section report: ledger check with GitHub-verified fates for the trailing 7 nights (including the 10-12/10-13/10-14 ledger-transcription gap), prior-gist scoring (10/10), research, evaluation receipt, adversarial critique, reward-hack check, security review, security/hive-mind scan findings (settings-risk-scanner
enabledPluginsgap,DENYLISTED_ENV_NAMESgaps, dead duplicate Raft receiver,crdt/quorumCLI vaporware), competitor comparison, witness.13. Witness
Verifier: fetch
docs/dream-cycle/dream-gist-2026-10-15.mdfrom this branch, strip the Witness block's filled-in values back toPENDING, SHA-256 the file, concatenate with the session commit above, SHA-256 again — must equal the witness stamp.14. Merge Policy
Human review required. Do not self-merge. Do not autonomously promote Flywheel state. Independent adversarial critic verdict: CONFIRMED, no blocking issues.
🤖 Generated with RuFlo
https://claude.ai/code/session_01MFLiva2zVEXr2n9UTK5YgU
Generated by Claude Code