Skip to content

feat: reconcile votes, follows, totals and merges - #34

Merged
mattdjenkinson merged 2 commits into
mainfrom
feat/crd-votes
Nov 18, 2026
Merged

mattdjenkinson merged 2 commits into
mainfrom
feat/crd-votes

Conversation

@mattdjenkinson

Copy link
Copy Markdown
Contributor

Closes #7. Stacked on #33.

Votes and follows as CRDs: admission checks, plus the operator's reconcilers for what the Postgres version did in one transaction.

Admission

The vote validating webhook runs on creates of votes and subscriptions.

  • The post must exist, must not be hidden, and must not be merged. A hidden post answers "not found"; a merged one names its target.
  • Votes need a verified email (iam.miloapis.com/emailVerified). Milo's own gate does this too, but it's behind a feature gate.

It reads posts from the operator's cache, which sees hidden posts because the operator has posts/hidden.

Reconcilers

Reconciler Watches Does
vote votes; posts created or deleted Follows the post for each new voter (reason: voted), then sets status.subscribed, so a follow the voter deletes isn't recreated. Records organizations and linked GitHub username; these Milo lookups are best effort. Marks votes on a deleted post with feedback.miloapis.com/orphaned-at and deletes them after 30 days unless the post returns.
post-votes posts, votes Tallies from the cache, indexed by spec.postRef.name. Applies status.votes.{total,datum,linked,trendingScore} with server-side apply as feedback-operator, and skips the write when nothing changed. Re-queues hourly while a post has a trending score.
merge posts with status.mergedInto, plus their votes and follows Creates the vote or follow on the target unless the user has one, then deletes the old one with a UID precondition. A merged target moves them on again.

All steps use deterministic names (<post>.<user>) and treat AlreadyExists and NotFound as done, so retries and crashes are safe.

Behaviour changes from the Postgres version

  • The total isn't updated in the same request. It catches up within one reconcile. The vote and the follow are created at once, so UIs can show the user's own vote straight away.
  • feedback-sync must write post status with server-side apply under its own field manager. A plain status update would wipe the operator's fields. This will be in sync's own PR.

Milo RBAC

The operator also lists organizationmemberships and useridentities in Milo, for the voter lookups.

Tests

  • Tally unit test: linked people counted once, the cap at the 👍 count, trending weights.
  • VoteCheck unit tests: missing, hidden and merged posts; unverified email blocks votes but not follows.
  • Envtest with the reconcilers running:
    • a vote creates the follow and fills its status, and a deleted follow isn't recreated;
    • totals count linked people once and leave sync's fields alone;
    • votes and follows move off a merged post, and a user who already voted on the target keeps one vote;
    • orphaned votes are marked, then deleted after the retention period.
  • The webhook envtest now creates a post before voting.
  • task test, go test -race -count=3 on the reconciler tests, go vet ./..., and task generate with no diff

Votes and follows are admitted only on posts that exist, aren't hidden
and aren't merged; votes need a verified email. The vote reconciler
follows the post for each new voter once, records their organizations
and GitHub username, and deletes votes whose post has been gone for 30
days. The post-votes reconciler applies the vote totals and trending
score with server-side apply, leaving sync's GitHub fields alone, and
re-tallies hourly. The merge reconciler moves votes and follows off a
merged post.

Copy link
Copy Markdown

Please fix before merging: votes and follows get stuck when a post is merged into an already-merged or hidden post. The controller tries to create them on that target, its own webhook rejects them, and it retries indefinitely. This was reproduced with the controllers and webhooks running together.

Follow the merge chain to a valid final target, handle unavailable targets explicitly without losing user intent, and add a test with admission webhooks enabled. The existing controller-only tests miss this interaction.

…e targets

Follow status.mergedInto to the first post that isn't merged before moving
votes and follows, so they never land on a post the vote webhook refuses.
When the chain ends at a missing or hidden post, loops, or is too long,
keep them on the merged post and record a VotesMoved=False condition
instead of retrying; changes to posts in the chain requeue the posts merged
into them. Adds an envtest that runs the reconcilers and admission webhooks
together.
@mattdjenkinson

Copy link
Copy Markdown
Contributor Author

Fixed in d47ce42.

  • Merge chains: the controller now follows the chain to the final target, for up to 10 hops.
  • Unavailable targets: if the final target is hidden, or the chain loops or runs past 10 hops, votes and follows stay on the source post. The post gets a VotesMoved=False condition with reason TargetUnavailable, MergeCycle or MergeChainTooLong, so nobody's vote is lost. Fixing the target moves them, and there's no retry loop in the meantime.
  • Tests: merge_webhook_test.go runs the controllers and admission webhooks together in envtest. The merge-chain test in test: end-to-end tests in kind against a real Milo #42 covers the same cases against a real Milo.

scotwells
scotwells previously approved these changes Nov 18, 2026
Base automatically changed from feat/identity to main November 18, 2026 04:16
@mattdjenkinson
mattdjenkinson dismissed scotwells’s stale review November 18, 2026 04:16

The base branch was changed.

@mattdjenkinson
mattdjenkinson requested a review from a team as a code owner November 18, 2026 04:16
@mattdjenkinson
mattdjenkinson merged commit 7d7f8c9 into main Nov 18, 2026
6 checks passed
@mattdjenkinson
mattdjenkinson deleted the feat/crd-votes branch November 18, 2026 14:42
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.

Vote and Subscription

2 participants