Skip to content

Comment routing: one conversation's weights built once, and a one-call draw that returns the chosen comment and its chance (dormant) - #3502

Draft
colinmegill wants to merge 5 commits into
routing/plan-adapterfrom
routing/plan-build
Draft

colinmegill wants to merge 5 commits into
routing/plan-adapterfrom
routing/plan-build

Conversation

@colinmegill

Copy link
Copy Markdown
Member

What this is

The plan build and the one-call draw in queue-rs/polis-routing-plan, stacked on PR #3501. Nothing calls the crate, so nothing a person can observe changes.

  • No schema change. No route, no database, no switch, nothing under queue-rs/polis-api/.
  • No rule or parameters are chosen here, and nothing here is a statement about speed.

What it adds

  • Plan::build: one conversation's weights, computed once from the adapter's frames for a named rule and its parameters (RuleConfig: stored-weights/1, uniform/1, and symmetric-gic-floor/2 over symmetric-gic/2).
  • Plan::draw: one call that leaves out the comments a participant has voted on and the ones the plan excludes, chooses the next comment with the random input it is given, and returns a PlanDraw holding the chosen comment's id and the chance it had. The comment to fetch is always that id, never a position in a filtered list.
  • One implementation. The draw calls the equation library's own draw; for every supported rule it gives the same choice and the same reported chance as the library does on the same inputs.
  • Fall back, closed. Every refusal from the library is mapped by name to a Fallback (a caller then uses today's draw); the mapping cannot gain a wildcard arm, and no refusal carries a comment id. A fall back's chance is never reported as the plan's.
  • Bounds. With meta comments excluded, a conversation over 10,000 comments is refused (it keeps today's draw) while the cost of exclusion at that size is open; the number of candidates is bounded too. charged_bytes and draw_reservation give upper bounds on what a plan holds and on a draw's scratch.

Checks

Passed locally at this head: make check-polis-routing-plan (61 tests, formatting, clippy, the source scan, the dependency rule), make check-polis-routing-equation (157 tests; today's equation still 1,386 of 1,386 grid cases and 3,257 of 3,257 replayed cells bit for bit against the Python formula) and make check-vote-sign-lint. Reviewed by the second reviewer, whose own 1,892 constructed draw and refusal cases matched the library's receipts and probability bits; its one correction is the last commit.

All fixtures are constructed; no real conversation's data is used.

🤖 Generated with Claude Code

colinmegill and others added 5 commits November 27, 2026 03:31
… check)

A plan is one conversation's weights for a configured rule (stored-weights/1,
uniform/1, or symmetric-gic-floor/2 over symmetric-gic/2 weights), built once
from one read's frames. Its draw takes today's candidate ids and the caller's
unit: the bound before any copy, checked id conversion, the plan's own
exclusion under meta_policy = exclude, one library draw, and the receipt's
comment id as the comment to fetch. Every refusal maps to a closed reason
with no comment id. The plan's charge and the draw's scratch bound are pure,
checked upper bounds, tested with a counting allocator. Nothing calls it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…le fix found on mm5)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…m the read

The plan keeps its own copy of the meta set, which can name comments in no
other key; its size is now taken from the frames rather than from the
weights' sets.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ne-call draw

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
From review. Every library refusal was already named in the mapping to
a fall back, but a wildcard as its last arm kept today's outputs and
passed the check, so a refusal added to the library later could be
swallowed. The function now denies clippy's wildcard lints, and that
mutation fails the check. No behaviour changes.

This branch has not been deployed

No deployments
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.

1 participant