You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(wot): count one vote per follower and rebuild on settings change - #1294
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.
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.
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: 4
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
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
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
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.
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.
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%).
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
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.
Description
Two changes to
WotGraphService, from #1250:rebuild()added one to a candidate's follower count for every entrygetFollows()returned. On the Redis path the entries are already unique (they come from a set), but on the database pathextractFollowedPubkeysreturns theptags as they are, so a kind 3 that repeats oneptag counted several times.rebuild()now iterates over the unique follows of each account.wot.enabled,wot.seedPubkey,wot.maxDepthandwot.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()returnsundefinedwhen 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, andfollowerCountsadds one per entry. For F-008,getDistance()only checkedready, which stays true, so after a settings reload the olddistanceskept being served until something else triggered a rebuild.How Has This Been Tested?
test/unit/services/wot-graph-service.spec.ts: a repeatedptag counts once (cache path and database path), a changedminimumFollowerswithholds 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.pnpm run test:unit(3668 passing),pnpm lintandpnpm run build:check.Screenshots (if appropriate):
Types of changes
Checklist:
Summary by CodeRabbit