Skip to content

fix(wot): count one vote per follower and rebuild on settings change - #1294

Merged
cameri merged 2 commits into
cameri:mainfrom
Priyanshubhartistm:fix/wot-graph-follow-votes
Nov 30, 2026
Merged

cameri merged 2 commits into
cameri:mainfrom
Priyanshubhartistm:fix/wot-graph-follow-votes

Conversation

@Priyanshubhartistm

@Priyanshubhartistm Priyanshubhartistm commented Nov 29, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Two changes to WotGraphService, from #1250:

  • One vote per follower. rebuild() added one to a candidate's follower count for every entry getFollows() returned. On the Redis path the entries are already unique (they come from a set), but on the database path extractFollowedPubkeys returns the p tags as they are, so a kind 3 that repeats one p tag counted several times. rebuild() now iterates over the unique follows of each account.
  • The graph remembers the settings it was built for. The graph keeps a key made of wot.enabled, wot.seedPubkey, wot.maxDepth and wot.minimumFollowers. ensureBuilt() rebuilds when the key no longer matches the current settings, and checks again after a rebuild that was already in flight for the old settings. getDistance() returns undefined when the graph still does not match, for example because the rebuild failed, instead of answering from the old graph.

Not in this PR: the third finding in #1250 (F-010), where only the worker that received a contact list rebuilds its graph. It needs an invalidation that every worker checks, which is a larger change, so I kept it separate.

Related Issue

Partly addresses #1250 (F-005 and F-008). F-010 is not covered, so this does not close it.

Motivation and Context

Both findings end in a proof-of-work discount for an account that should not have it. CodeRabbit's scan did not establish reachability, so I checked the code. For F-005, the database path of getFollows() returns duplicates, and followerCounts adds one per entry. For F-008, getDistance() only checked ready, which stays true, so after a settings reload the old distances kept being served until something else triggered a rebuild.

How Has This Been Tested?

  • Four new tests in test/unit/services/wot-graph-service.spec.ts: a repeated p tag counts once (cache path and database path), a changed minimumFollowers withholds the old distance until the graph is rebuilt for it, and a failed rebuild after a settings change answers nothing. All four fail without the change.
  • The other tests in that file still pass.
  • pnpm run test:unit (3668 passing), pnpm lint and pnpm run build:check.

Screenshots (if appropriate):

Types of changes

  • Non-functional change (docs, style, minor refactor)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my code changes.
  • I added a changeset, or this is docs-only and I added an empty changeset.
  • All new and existing tests passed.

Summary by CodeRabbit

  • Bug Fixes
    • Duplicate follows from the same account are now counted only once when determining follower thresholds, preventing inflated trust-graph results.
    • Trust-graph distances now reflect current settings after changes, including whether the graph is enabled, the selected seed, depth, and follower threshold. When a graph needs rebuilding, distance lookups wait for the updated graph; if it cannot be rebuilt, outdated distances are not shown.

Signed-off-by: Priyanshubhartistm <bhartipriyanshustm@gmail.com>
@changeset-bot

changeset-bot Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: c01aa45

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
nostream Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai

coderabbitai Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

WotGraphService now counts each account once toward minimumFollowers and records the settings used to build each graph. Distance lookups reject graphs built under different settings. ensureBuilt makes up to two passes to build for current settings. Tests cover duplicate tags and settings changes, including failed rebuilds.

Changes: Trust graph behavior

Layer / File(s) Summary
Track graph settings and rebuilds
src/services/wot-graph-service.ts, test/unit/services/wot-graph-service.spec.ts, .changeset/wot-graph-votes-and-settings-key.md
The service records the settings used to build a graph. Distance lookups return no distance when those settings differ from the current settings. ensureBuilt makes up to two passes to build for current settings. Tests cover changes to minimumFollowers and maxDepth, including a failed rebuild. The changeset describes these fixes.
Deduplicate follower votes
src/services/wot-graph-service.ts, test/unit/services/wot-graph-service.spec.ts
Repeated follow tags from one account count as one vote toward minimumFollowers. Tests cover cached lists and lists loaded from database events.

Estimated code review effort: 2 (Simple) | ~12 minutes

Change: Bug fix

Possibly related issues

  • cameri/nostream#1250 — The PR addresses F-005 and F-008, which this issue tracks. The issue also tracks F-010, which the PR does not address.
  • cameri/nostream#1019 — The PR addresses the report’s F-005 and F-008 findings.
Merge Risk: Minimal · up to c01aa

The change counts each follower once toward the minimum-followers threshold. It also stops the trust graph from serving distances built under old settings. No concrete risk was found in the changed code, and the new tests cover both fixes. Cross-worker invalidation is deliberately left out, as the PR states.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the two main changes in the PR: counting one vote per follower, and rebuilding the trust graph when WoT settings change. Both match the changeset, the file summaries, and the stated ob…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the two main changes in the PR: counting one vote per follower, and rebuilding the trust graph when WoT settings change. Both match the changeset, the file summaries, and the stated objectives. The title is specific and concise, and it follows the conventional commit style.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

A rabbit checks each follower’s name,
No doubled votes can sway the count.
New settings guide the graph’s rebuild,
Old distances wait until it’s sound.
Two patient passes make the match,
Then trails of trust appear again.

Recent review info

Automatic approval policy

Commit: c01aa45dee44.

Setting Effective value Source
Automatic approvals Enabled Global configuration
Merge risk Minimal Global configuration
Security risk Not set Global configuration

Not set means no limit was configured after inheritance. Use @coderabbitai configuration to inspect the resolved settings and their sources.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2d5d28c9-abe5-4c2a-bd92-f5da4911f276
Commits

Reviewing files that changed from the base of the PR and between 76fa452 and c01aa45.

Files selected for processing: 1

  • test/unit/services/wot-graph-service.spec.ts

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 1 remain after this review.

@greptile-apps

greptile-apps Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Confidence Score: 5/5 · The PR appears safe to merge, with the requested test now included.RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge, with the requested test now included.

Summary

The PR counts each follower once and rebuilds the trust graph when its settings change.

  • Each follower counts once toward a trust threshold.
  • Trust-graph distances now match the current settings.

Reviews (2) · Last reviewed commit: "test(wot): cover a lookup that joins a r..." · Reviewed by Greptile

coderabbitai[bot]
coderabbitai Bot previously approved these changes Nov 29, 2026
@coveralls

coveralls commented Nov 29, 2026 •

Copy link
Copy Markdown
Collaborator

Coverage Report for CI Build 46316135137

Warning

No base build found for commit c14342e on main.
Coverage changes can't be calculated without a base build.
If a base build is processing, this comment will update automatically when it completes.

Coverage: 80.871%

Details

  • Patch coverage: 1 uncovered change across 1 file (12 of 13 lines covered, 92.31%).

Uncovered Changes

File Changed Covered %
src/services/wot-graph-service.ts 13 12 92.31%

Coverage Regressions

Requires a base build to compare against. How to fix this →


Coverage Stats

Coverage Status
Relevant Lines: 15449
Covered Lines: 12995
Line Coverage: 84.12%
Relevant Branches: 8557
Covered Branches: 6419
Branch Coverage: 75.01%
Branches in Coverage %: Yes
Coverage Strength: 714.5 hits per line

💛 - Coveralls

Signed-off-by: Priyanshubhartistm <bhartipriyanshustm@gmail.com>
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.

3 participants