Reuse Check (Polar)
The handle is the diff. The evidence is new code that duplicates something the repo
already has, with the import that replaces it.
This is the most common substantive comment in Polar reviews: 84 of ~1,100 human review
comments from Feb to Aug 2026 point at an existing helper the author did not know about. It
is also the one category where grep beats a human reviewer, and it got worse once agents
started writing the code, because an agent that does not search first writes its own helper.
Scope
Run on any diff that adds a function, constant, Annotated type, validator, enum, model
property, repository method, React component, or hook. Skip deletions, renames, config and
lockfiles.
Owned elsewhere: agent noise → slop-check; API contract → api-surface-review; deploy
safety → ship-safety; billing behaviour → billing-review.
Method
For each new symbol:
- Name search —
rg -n "def <name>|<Name>\b" server/polar clients/packages, plus obvious
synonyms (normalize/sanitize/clean, fetch/get/load).
- Behaviour search — the distinctive part of the body: a regex literal, a library call
(
urlparse, pycountry, stdnum, slugify), a magic constant.
- Inventory — check the list below.
Report only when you can name the existing symbol and its import path. A hunch is not a
finding. Always show what you searched for, so a false positive is cheap to dismiss.
Inventory
| Home |
Holds |
polar/kit/schemas.py |
Schema, IDSchema, TimestampedSchema, EmptyStrToNone, SlugValidator, StripValidator, HttpsUrl, HttpUrlToStr, Int32, ClassName, MergeJSONSchema, SetSchemaReference, MultipleQueryFilter, *_ID_EXAMPLE |
polar/kit/http.py |
get_safe_return_url (open redirect), get_ip_address, add_query_parameters, get_content_disposition, is_localhost, SSRF-safe crawling (SSRFBlockedError, UnsafeCrawlableUrl, UrlReachability) |
polar/kit/currency.py, money.py, math.py |
get_currency_decimal_factor (zero-decimal currencies), get_minimum_currency_amount, get_maximum_currency_amount, format_currency, get_presentment_currency, get_cents_in_dollar_string, polar_round, non_negative_running_sum |
polar/kit/pagination.py |
ListResource, Pagination, PaginationParams, count_subquery |
polar/kit/repository/base.py |
get_base_statement, get_one_or_none, get_all, paginate, create, update, from_session, stream |
polar/kit/ (rest) |
address, anonymization, crypto, csv, db, email (EmailStrDNS), encryption, html, json, jwk, jwt, locale, metadata, operator, routing, services, sorting, time_queries, trial, utils, visibility |
server/scripts/helper.py |
run_batched_update |
polar/backoffice/forms.py |
Form builder classes. Pattern: polar/backoffice/orders/endpoints.py |
clients/packages/orbit/src/components |
Alert, Avatar, Box, Button, ButtonGroup, Checkbox, Grid, GridItem, InlineModal, Input, List, ListGroup, Modal, Pill, SegmentedControl, Select, Spinner, Status, Subnav, Switch, Tabs, Text, TextArea, Tooltip, Truncated, datatable |
| Libraries already in use |
stdnum (tax IDs), pycountry (country names), slugify, email_validator |
Also grep the model. A lot of duplicated logic is a property that already exists:
Organization.is_payout_ready, Organization.can_authenticate, ProductPrice.is_free,
Checkout.is_free_product_price, Payment.UNRECOVERABLE_DECLINE_CODES.
The ones people actually miss
- A hand-written "empty string means null" validator instead of
EmptyStrToNone.
- A keyset loop over UUIDs instead of
RepositoryBase.stream, which batches implicitly.
- Fetching rows only to count them, instead of an existence query.
- Hand-rolled cents conversion or currency rounding.
- A country-code table or slug regex instead of
pycountry / slugify.
- A hand-built HTMX form in a new backoffice view.
- A hand-styled div that duplicates an Orbit primitive.
Output
## Reuse
### 🟠 Should fix
- `file:line` — <what the new code does>. Fix: `from polar.kit.schemas import EmptyStrToNone`
(searched: `rg "empty_str|strip_to_none" server/polar`)
### 🟡 Question
- `file:line` — <question>
### Verdict
✅ Nothing reinvented | ❌ n duplicates
1---2name: reuse-check3description: Check a diff for code that reinvents something Polar already has — a kit helper, a shared Pydantic type, a repository method, an Orbit component, an existing model property. Use before opening a PR, when reviewing a diff, or when the user asks whether a new helper, validator, type or utility already exists in the codebase.4license: MIT5---67# Reuse Check (Polar)89The handle is the **diff**. The evidence is **new code that duplicates something the repo10already has**, with the import that replaces it.1112This is the most common substantive comment in Polar reviews: 84 of ~1,100 human review13comments from Feb to Aug 2026 point at an existing helper the author did not know about. It14is also the one category where grep beats a human reviewer, and it got worse once agents15started writing the code, because an agent that does not search first writes its own helper.1617## Scope1819Run on any diff that adds a function, constant, `Annotated` type, validator, enum, model20property, repository method, React component, or hook. Skip deletions, renames, config and21lockfiles.2223Owned elsewhere: agent noise → `slop-check`; API contract → `api-surface-review`; deploy24safety → `ship-safety`; billing behaviour → `billing-review`.2526## Method2728For each new symbol:29301. **Name search** — `rg -n "def <name>|<Name>\b" server/polar clients/packages`, plus obvious31 synonyms (`normalize`/`sanitize`/`clean`, `fetch`/`get`/`load`).322. **Behaviour search** — the distinctive part of the body: a regex literal, a library call33 (`urlparse`, `pycountry`, `stdnum`, `slugify`), a magic constant.343. **Inventory** — check the list below.3536Report only when you can name the existing symbol and its import path. A hunch is not a37finding. Always show what you searched for, so a false positive is cheap to dismiss.3839## Inventory4041| Home | Holds |42|---|---|43| `polar/kit/schemas.py` | `Schema`, `IDSchema`, `TimestampedSchema`, `EmptyStrToNone`, `SlugValidator`, `StripValidator`, `HttpsUrl`, `HttpUrlToStr`, `Int32`, `ClassName`, `MergeJSONSchema`, `SetSchemaReference`, `MultipleQueryFilter`, `*_ID_EXAMPLE` |44| `polar/kit/http.py` | `get_safe_return_url` (open redirect), `get_ip_address`, `add_query_parameters`, `get_content_disposition`, `is_localhost`, SSRF-safe crawling (`SSRFBlockedError`, `UnsafeCrawlableUrl`, `UrlReachability`) |45| `polar/kit/currency.py`, `money.py`, `math.py` | `get_currency_decimal_factor` (zero-decimal currencies), `get_minimum_currency_amount`, `get_maximum_currency_amount`, `format_currency`, `get_presentment_currency`, `get_cents_in_dollar_string`, `polar_round`, `non_negative_running_sum` |46| `polar/kit/pagination.py` | `ListResource`, `Pagination`, `PaginationParams`, `count_subquery` |47| `polar/kit/repository/base.py` | `get_base_statement`, `get_one_or_none`, `get_all`, `paginate`, `create`, `update`, `from_session`, `stream` |48| `polar/kit/` (rest) | `address`, `anonymization`, `crypto`, `csv`, `db`, `email` (`EmailStrDNS`), `encryption`, `html`, `json`, `jwk`, `jwt`, `locale`, `metadata`, `operator`, `routing`, `services`, `sorting`, `time_queries`, `trial`, `utils`, `visibility` |49| `server/scripts/helper.py` | `run_batched_update` |50| `polar/backoffice/forms.py` | Form builder classes. Pattern: `polar/backoffice/orders/endpoints.py` |51| `clients/packages/orbit/src/components` | `Alert`, `Avatar`, `Box`, `Button`, `ButtonGroup`, `Checkbox`, `Grid`, `GridItem`, `InlineModal`, `Input`, `List`, `ListGroup`, `Modal`, `Pill`, `SegmentedControl`, `Select`, `Spinner`, `Status`, `Subnav`, `Switch`, `Tabs`, `Text`, `TextArea`, `Tooltip`, `Truncated`, `datatable` |52| Libraries already in use | `stdnum` (tax IDs), `pycountry` (country names), `slugify`, `email_validator` |5354**Also grep the model.** A lot of duplicated logic is a property that already exists:55`Organization.is_payout_ready`, `Organization.can_authenticate`, `ProductPrice.is_free`,56`Checkout.is_free_product_price`, `Payment.UNRECOVERABLE_DECLINE_CODES`.5758### The ones people actually miss5960- A hand-written "empty string means null" validator instead of `EmptyStrToNone`.61- A keyset loop over UUIDs instead of `RepositoryBase.stream`, which batches implicitly.62- Fetching rows only to count them, instead of an existence query.63- Hand-rolled cents conversion or currency rounding.64- A country-code table or slug regex instead of `pycountry` / `slugify`.65- A hand-built HTMX form in a new backoffice view.66- A hand-styled div that duplicates an Orbit primitive.6768## Output6970```71## Reuse7273### 🟠 Should fix74- `file:line` — <what the new code does>. Fix: `from polar.kit.schemas import EmptyStrToNone`75 (searched: `rg "empty_str|strip_to_none" server/polar`)7677### 🟡 Question78- `file:line` — <question>7980### Verdict81✅ Nothing reinvented | ❌ n duplicates82```