Skip to content

feat: admit submissions and carry out review decisions - #37

Merged
mattdjenkinson merged 5 commits into
mainfrom
feat/crd-submissions
Nov 18, 2026
Merged

mattdjenkinson merged 5 commits into
mainfrom
feat/crd-submissions

Conversation

@mattdjenkinson

Copy link
Copy Markdown
Contributor

Part of #8. Stacked on #34. Attachments come in the next PR, with the upload service.

Admission

  • submission runs on creates.
    • The email must be verified.
    • Each user may send at most --submission-limit (default 5) per --submission-window (default 10m), counted from the operator's cache through a spec.userRef.name index. Over the limit, the answer is 429 with how long to wait.
    • Submissions with attachments are refused until uploads exist.
  • submissionreview runs on creates and updates. A Merged decision must name a post that exists, isn't hidden and isn't merged. It reuses the vote check's post lookup.

Reconcilers

  • submission creates the SubmissionReview with the same name, owned by the submission. Milo runs the garbage collector, so deleting a submission deletes its review. It also sets the phase to PendingReview.
  • submission-review carries out the decision:
    • Rejected: sets phase Rejected and copies the reason the submitter sees.
    • Merged: the submitter follows the post (reason: merged) and votes on it, with the submission's client as the vote source. The submission becomes Merged with postRef.
    • Approved: sets phase Approved and waits with Applied=False, WaitingForPost. feedback-sync creates the GitHub issue and annotates the post it syncs with feedback.miloapis.com/submission: <submission>. The reconciler watches posts by that annotation. Once the post appears, it links the submission and has the submitter follow (reason: submitted) and vote.
    • MoveToSecurity: left to the security reports PR.
  • A follow or vote the admission webhook refuses (the post was hidden or merged since the decision) is logged and skipped; the decision still stands.

Other changes

  • Field indexes move to internal/index, so webhooks and reconcilers share them.
  • task generate now points the generated webhook config at feedback-operator-webhook.feedback-system, the way billing does. Before, each webhook needed a kustomize patch by index.
  • gofmt fixes in two files from feat: feedback CRDs and operator scaffold #32.

Not in this PR

  • Triage (similar posts, draft issue, fraud score) and review-outcome digest events. They'll come with the triage and notifications work.

Tests

  • SubmissionCheck: the third submission in ten minutes gets a 429 with the wait time; others' submissions don't count; unverified email is refused; attachments are refused without uploads; a limit of 0 disables it.
  • ReviewCheck: merging into a visible post is allowed; hidden or missing posts are refused; rejecting doesn't look up a post.
  • Envtest with the reconcilers:
    • new submissions get PendingReview and a review owned by the submission;
    • rejected submissions;
    • merged submissions get the follow (reason merged) and a vote with source portal;
    • approved submissions wait, then link and grant when the annotated post appears.
  • task test, go vet ./..., and task generate with no diff

Submissions need a verified email and are limited per user (5 per 10
minutes by default, counted from the cache). Each submission gets a
SubmissionReview owned by it. The review reconciler carries out Rejected,
Merged and Approved decisions: merges and approvals give the submitter a
follow and a vote, and approvals link the submission once feedback-sync
syncs a post annotated with its name. Merged decisions must name a
visible, unmerged post.

Field indexes move to a shared package, and generation now points the
webhook config at the operator's Service.

Copy link
Copy Markdown

Non-blocking follow-up: the submission limit is a soft limit, not a strict one. Parallel requests can all read the same cached count and be accepted. Please document that trade-off, or enforce the limit with a shared atomic counter if it needs to resist abuse. The workflow otherwise looks good; this PR still depends on the merge fix in #34.

The limit counted submissions in the operator's cache, so parallel
requests could all read the same count and be admitted. Each replica
now also remembers what it admitted until the cache shows it, deciding
one request at a time, so a burst to one replica gets at most the limit.

Document that the limit is still soft across replicas (replicas x limit
per window at worst), and why that's acceptable: submissions are never
published without staff review.
creationTimestamp has whole seconds, so a submission created in the
same second as its admission looked older than the admission, and both
counted towards the limit: users got 429 after 3 or 4 of 5. Count
instead how many of this replica's admissions the cache already shows
since the oldest one, rounded down to the second.
# Conflicts:
#	internal/controller/setup.go
@mattdjenkinson

Copy link
Copy Markdown
Contributor Author
  • Per-replica guard (9c615b3): each replica now counts the submissions it has admitted but its cache hasn't seen yet, so a burst of parallel requests to one replica gets at most the limit through. There's a race test for this.
  • Documentation: SubmissionCheck documents the trade-off. Requests spread across replicas can still get the limit through on each, so a determined user could send replicas × limit per window. That seems acceptable, since submissions are never published without a staff review and the limit protects the review queue. A strict limit would need a shared counter written on every submission.
  • Fix found in kind (b93190a): the e2e tests in test: end-to-end tests in kind against a real Milo #42 showed the guard counted a submission twice when it was created in the same second it was admitted, so the limit admitted 3 or 4 instead of 5. That's fixed, with a regression test.

@scotwells scotwells 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.

The new rate-limit guard still counts one submission twice when admission crosses a second boundary (internal/webhook/submission.go, unseen). The API server can stamp the object at 12:00:00 and call the webhook at 12:00:01.020; the cached object then fails the time-based match. We reproduced this with a limit of two: the second submission was refused after only one had been created.

Please match pending admissions to cached objects by the submission's UID rather than timestamps, and add a regression test across a second boundary. Also skip recording dry-run requests so they don't consume real quota.

The documented soft limit across replicas is fine; this is a separate bug that rejects legitimate submissions too early.

The submission limit matched the admissions it remembered to cached
submissions by time. creationTimestamp is set before admission and has
whole seconds, so an admission at 12:00:01.020 for a submission stamped
12:00:00 counted twice, and the next submission was refused early.

The webhook validates after the API server sets the UID, so pending
admissions are now matched to cached submissions by UID. Also:

- Dry runs are limited but not recorded, so they don't use up the limit.
- An admission the cache never shows (the create failed later) stops
  counting after a minute instead of the whole window.
- The same create admitted twice counts once.

Tests cover a second boundary, dry runs, failed creates and repeated
admissions. The second-boundary, dry-run and repeated-admission tests fail
without this change.
@mattdjenkinson

Copy link
Copy Markdown
Contributor Author

Thanks, you're right: matching by time can't work when creationTimestamp falls in an earlier second than the admission. Fixed in 56a86c6:

  • Matched by UID: the webhook validates after the API server sets the submission's UID. It now records the UIDs it admits and matches them to cached submissions by UID, with no timestamps involved.
  • Dry runs: they're still checked against the limit but never recorded, so they don't use up quota.
  • Failed creates: an admission whose submission never shows up in the cache (the create failed after admission) stops counting after a minute instead of the whole window.
  • Repeated admission: the same create admitted twice counts once.

Tests cover admission across a second boundary (your 12:00:00 / 12:00:01.020 case, limit 2), a same-second case, dry runs, failed creates and repeated admission. The second-boundary, dry-run and repeated-admission tests fail on the previous code. The kind e2e suite in #42 passes with this change.

scotwells
scotwells previously approved these changes Nov 18, 2026

@scotwells scotwells 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.

The UID-based matching fixes the reproduced double-counting bug. Dry runs no longer consume quota, and failed/repeated admissions are handled. Reviewed the change and ran the submission tests ten times with the race detector on this head and the updated stack; tests and vet passed. The earlier change request is resolved.

Base automatically changed from feat/crd-votes to main November 18, 2026 14:42
@mattdjenkinson
mattdjenkinson dismissed scotwells’s stale review November 18, 2026 14:42

The base branch was changed.

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

2 participants